<!-- 评估列表 -->
<template>
  <div class="main_item">
    <div class="fi_input">
      <a-input
        v-model:value="params.assessmentName"
        style="width: 424px; height: 40px; border-radius: 8px"
        placeholder="请输入评估名称"
        maxlength="20"
      />
    </div>
    <div class="btns" @click="search">
      <div class="search"></div>
      <div class="btnText">搜索</div>
    </div>
    <div class="btnsn" @click="reset">
      <div class="search"></div>
      <div class="btnText">重置</div>
    </div>
    <div class="btnsn" @click="reset">
      <div class="search"></div>
      <div class="btnText">刷新</div>
    </div>
  </div>

  <div class="main_item">
    <button class="xkbtn" style="margin: 0" @click="goResearchmanage">
      新建评估
    </button>
  </div>

  <div class="main_notice" style="display: none">
    <div class="mntc_left">
      <div class="notice_icon"></div>
    </div>
  </div>
  <div class="main_table">
    <a-table
      :customRow="customRow"
      class="ant-table-striped"
      :row-class-name="(_, index) => (index % 2 === 1 ? 'table-striped' : null)"
      row-key="id"
      :columns="columns"
      :data-source="data"
      :loading="loading"
      :pagination="pagination"
      :row-selection="rowSelection"
    />
  </div>
</template>
<script setup>
import { computed, defineEmits, defineProps, ref, watch } from "vue";
// import { useRouter } from "vue-router";
import { useRowsPage } from "@/api/request";
import { ASSESSMENT_PAGE } from "@/api/apis";

const props = defineProps({
  id: String,
  name: String,
});
const emit = defineEmits([]);
const columns = ref([
  {
    title: "名称",
    dataIndex: "assessmentName",
    key: "assessmentName",
    width: "40%",
    ellipsis: true,
  },
  {
    title: "题数",
    dataIndex: "num",
    key: "num",
    width: "20%",
    align: "center",
    ellipsis: true,
    customRender: (text) => {
      return (
        <div class="racona">
          <span>
            {" "}
            {text.record.essayQuestionVoList.length +
              text.record.multipleStemVoList.length +
              text.record.scoringQuestionVoList.length +
              text.record.singleStemVoList.length}
          </span>
        </div>
      );
    },
  },
  {
    title: "创建人",
    dataIndex: "createName",
    key: "createName",
    width: "20%",
    align: "center",
    ellipsis: true,
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    key: "createTime",
    width: "20%",
    align: "center",
    ellipsis: true,
  },
]);
const initParams = {
  assessmentName: "",
  pageNo: 1,
  pageSize: 10,
  releaseStatus: 2,
};
// const router = useRouter();
const params = ref(initParams);

const rowSelectKeys = ref([]);
const selectsData = ref([]);

const { data, loading, total, fetch } = useRowsPage(
  ASSESSMENT_PAGE,
  params.value
);
console.log(data);
watch(
  () => props.id,
  () => {
    if (props.id) {
      rowSelectKeys.value = [props.id];
      selectsData.value = [{ id: props.id, assessmentName: props.name }];
    } else {
      rowSelectKeys.value = [];
      selectsData.value = [];
    }
  }
);

const customRow = (record) => ({
  onClick: () => {
    rowSelectKeys.value = [record.id];
    selectsData.value = [record];
    emit("update:id", selectsData.value[0].id);
    emit("update:name", selectsData.value[0].assessmentName);
  },
});

const pagination = computed(() => ({
  total: total.value,
  showSizeChanger: false,
  current: params.value.pageNo,
  pageSize: params.value.pageSize,
  onChange: changePagination,
}));

const changePagination = (e) => {
  params.value.pageNo = e;
  fetch();
};
const rowSelection = computed(() => ({
  type: "radio",
  columnWidth: 20,
  selectedRowKeys: rowSelectKeys.value,
  onChange: onSelectChange,
  preserveSelectedRowKeys: true,
  getCheckboxProps: getCheckboxProps,
}));
const getCheckboxProps = () => ({
  // 某几项默认禁止选中(R: 当state等于1时)
  disabled: false,
});

function onSelectChange(e, l) {
  rowSelectKeys.value = e;
  selectsData.value = l;
  emit("update:id", selectsData.value[0].id);
  emit("update:name", selectsData.value[0].assessmentName);
}

function search() {
  params.value.pageIndex = 1;
  fetch();
}

function reset() {
  rowSelectKeys.value = [];
  selectsData.value = [];
  params.value.pageIndex = 1;
  params.value.keyWord = "";
  params.value.assessmentName = "";
  fetch();
}

const goResearchmanage = () => {
  // router.push({ path: "/researchmanage" });
  window.open(process.env.VUE_APP_BASE + "/researchmanage?openCreate=true");
};
</script>
<style lang="scss">
.xkbtn {
  cursor: pointer;
  width: 130px;
  height: 40px;
  margin-top: 32px;
  margin-bottom: 32px;
  background: #4ea6ff;
  border-radius: 8px;
  border: 0;
  margin-right: 8px;
  color: #fff;
}

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

.addinvistDrawer {
  .drawerMain {
    .header {
      height: 73px;
      border-bottom: 1px solid #e8e8e8;
      display: flex;
      justify-content: space-between;
      align-items: center;

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

    .contentMain {
      .main_left {
        padding-right: 30px;
        margin-top: 32px;

        .main_item {
          display: flex;
          align-items: center;
          margin-top: 20px;
          margin-bottom: 20px;

          .fi_input {
            margin-right: 20px;
          }

          .btns {
            margin-right: 20px;
            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 {
              width: 15px;
              height: 17px;
              background-image: url("../../assets/images/courseManage/search0.png");
              background-size: 100% 100%;
            }

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

          .btnsn {
            padding: 0px 26px 0px 26px;
            height: 38px;
            background: rgba(64, 158, 255, 1) !important;
            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 {
              width: 16px;
              height: 18px;
              background-image: url("../../assets/images/courseManage/reset0.png") !important;
              background-size: 100% 100%;
            }

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

        .main_item2 {
          .pa {
            width: 100%;
            margin: 15px auto;
            display: flex;
            justify-content: center;
          }
        }
      }
    }

    .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>
