<template>
  <div @click="openDrawer()">
    <slot></slot>
  </div>
  <a-drawer
    :visible="visible"
    class="drawerStyle growth-line-course"
    width="1400"
    title="添加在线"
    placement="right"
  >
    <a-spin :spinning="spinning" wrapperClassName="spin">
      <div class="drawerMain">
        <div class="header">
          <div class="headerTitle">
            {{ selectData.id ? "编辑" : "添加" }}在线
          </div>
          <img
            style="width: 29px; height: 29px; cursor: pointer"
            src="../../assets/images/basicinfo/close.png"
            @click="closeDrawer"
          />
        </div>
        <iframe
          id="iframe"
          style="width: 100%; height: 100%; border: none"
          :src="`${iframeUrl}/course/manages?f=choose&refId=${
            props.id
          }&refType=${14}&courseIds=&projectId=${props.growId}`"
          name="myframe"
          security="restricted"
          sandbox="allow-forms allow-downloads allow-scripts allow-same-origin allow-popups"
        ></iframe>
      </div>
    </a-spin>
  </a-drawer>
</template>
<script setup lang="jsx">
import { computed, defineEmits, defineProps, ref, watch, onMounted } from "vue";
import { message } from "ant-design-vue";
import { saveTask } from "@/api/growthpath";
import { iframeUrl } from "@/api/method";
import dialog from "@/utils/dialog";
const props = defineProps({
  type: Number,
  id: Number,
  growId: String,
  // 选秀2 必修1
  activeKey: String,
});
const visible = ref(false);
const selectData = ref({});
const emit = defineEmits({});
const closeDrawer = () => {
  visible.value = false;
  selectData.value = {};
};
const spinning = ref(false);
async function confirm(row) {
  console.log(row);

  dialog({
    content: "确定选择该案例吗？",
    ok: async () => {
      // 新增
      spinning.value = true;
      if (!selectData.value?.id) {
        saveTask({
          growthId: props.growId,
          taskName: row.name,
          taskType: props.type,
          taskId: row.id,
          type: props.activeKey,
        })
          .then((res) => {
            message.success("添加成功");
            closeDrawer();
            emit("refresh");
          })
          .finally(() => {
            spinning.value = false;
          });
      } else {
        // 编辑
        selectData.value.taskName = row.name;
        selectData.value.taskId = row.id;
        saveTask(selectData.value)
          .then((res) => {
            message.success("编辑成功");
            closeDrawer();
            emit("refresh");
          })
          .finally(() => {
            spinning.value = false;
          });
      }
    },
  });
}

function selectCourse(row) {
  confirm(row);
}
function openDrawer(row) {
  window.selectCourse = selectCourse;
  row && (selectData.value = row);
  visible.value = true;
}

defineExpose({ openDrawer, selectCourse });
</script>
<style lang="scss">
.growth-line-course > .ant-drawer-content-wrapper {
  min-width: 1400px !important;
  width: 1400px !important;
}

.ant-table-striped :deep(.table-striped) td {
  background-color: #fafafa !important;
}

.spin {
  height: 100%;
  .ant-spin-container {
    height: 100%;
  }
}
.growth-line-course {
  .drawerMain {
    .title {
      display: flex;
      flex-wrap: wrap;
      .select {
        margin-left: 16px;
        margin-top: 16px;
      }
      .btn {
        padding: 0px 26px 0px 26px;
        height: 38px;
        background: #4ea6ff;
        border-radius: 8px;
        //border: 1px solid rgba(64, 158, 255, 1);
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 14px;
        flex-shrink: 0;
        cursor: pointer;

        .search {
          background-size: 100%;
        }

        .btnText {
          font-size: 14px;
          font-weight: 400;
          color: #ffffff;
          line-height: 36px;
          margin-left: 5px;
        }
      }

      .btnn1 {
        padding: 0px 26px 0px 26px;
        height: 38px;
        background: rgba(64, 158, 255, 1);
        border-radius: 8px;
        border: 1px solid rgba(64, 158, 255, 1);
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 14px;
        flex-shrink: 0;
        cursor: pointer;

        .search {
          background-size: 100%;
        }

        .btnText {
          font-size: 14px;
          font-weight: 400;
          color: #fff;
          line-height: 36px;
          margin-left: 5px;
        }
      }

      .btn1 {
        .search {
          width: 15px;
          height: 17px;
          background-image: url("../../assets/images/courseManage/search0.png");
        }
      }

      .btn2 {
        .search {
          width: 16px;
          height: 18px;
          background-image: url("../../assets/images/courseManage/reset0.png");
        }
      }
    }
    .header {
      height: 73px;
      border-bottom: 1px solid #e8e8e8;
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-shrink: 0;

      .headerTitle {
        font-size: 18px;
        font-weight: 600;
        color: #333333;
        line-height: 25px;
        margin-left: 24px;
      }
    }

    .contentMain {
      padding-right: 12px;

      .main_items {
        display: flex;

        margin-top: 32px;
        margin-bottom: 12px;
        flex-wrap: wrap;

        .mi_ipts {
          display: flex;
          margin-bottom: 20px;

          .mii_ipt {
            display: flex;
            align-items: center;
            margin-right: 24px;

            .ipt_name {
              white-space: nowrap;
            }
          }
        }

        .mi_btns {
          display: flex;
          margin-left: 38px;
          margin-bottom: 20px;
          cursor: pointer;

          .btn {
            padding: 0px 26px 0px 26px;
            height: 38px;
            border-radius: 8px;
            border: 1px solid rgba(64, 158, 255, 1);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 14px;
            flex-shrink: 0;

            .search {
              background-size: 100%;
            }

            .btnText {
              font-size: 14px;
              font-weight: 400;
              line-height: 36px;
              margin-left: 5px;
            }
          }

          .btn1 {
            background: rgb(64, 158, 255);

            .search {
              width: 15px;
              height: 17px;
              background-image: url("@/assets/images/coursewareManage/search0.png");
            }

            .btnText {
              color: rgb(255, 255, 255);
            }
          }

          .btn2 {
            background: rgb(255, 255, 255);

            .search {
              width: 15px;
              height: 17px;
              background-image: url("@/assets/images/coursewareManage/reset1.png");
            }

            .btnText {
              color: rgb(64, 158, 255);
            }
          }

          .btn1:hover {
            background: rgb(255, 255, 255);

            .search {
              background-image: url("@/assets/images/courseManage/search1.png");
            }

            .btnText {
              color: #4ea6ff;
            }
          }

          .btn2:hover {
            background: rgba(64, 158, 255, 1);

            .search {
              background-image: url("@/assets/images/courseManage/reset0.png");
            }

            .btnText {
              color: #ffffff;
            }
          }
        }
      }

      .main_notice {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 3px;
        height: 40px;
        background-color: #e9f6fe;

        .mntc_left {
          display: flex;
          align-items: center;

          .notice_icon {
            width: 14px;
            height: 14px;
            margin-right: 9px;
            margin-left: 9px;
            background-image: url(@/assets/images/coursewareManage/gan.png);
            background-size: 100% 100%;
          }
        }

        .mntc_right {
          cursor: pointer;
        }
      }

      .main_table {
        position: relative;
        padding-bottom: 80px;

        .ant-checkbox-wrapper {
          align-items: center;
          margin-top: -2px;
        }

        .ant-table-selection-column {
          padding: 0px !important;
          padding-left: 5px !important;
        }

        .ant-table-thead > tr > th {
          background-color: rgba(239, 244, 252, 1);
        }

        th.h {
          background-color: #eff4fc !important;
        }

        .ant-table-tbody
          > tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected)
          > td {
          background: #f6f9fd;
        }

        .pa {
          left: 0;
          width: 100%;
          display: flex;
          justify-content: center;
          position: absolute;
          bottom: 20px;
        }
      }
    }

    .main_btns {
      height: 72px;
      width: 100%;
      bottom: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0px 1px 35px 0px rgba(118, 136, 166, 0.16);

      .btn1 {
        width: 100px;
        height: 40px;
        border: 1px solid #4ea6ff;
        border-radius: 8px;
        color: #4ea6ff;
        background-color: #fff;
        cursor: pointer;
      }

      .btn2 {
        cursor: pointer;
        width: 100px;
        height: 40px;
        background: #4ea6ff;
        border-radius: 8px;
        border: 0;
        margin-left: 15px;
        color: #fff;
      }
    }
  }
}
</style>
