<template>
  <div class="growth-invist">
    <div class="contentMain">
      <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_table">
        <a-table
          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"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.dataIndex === 'select'">
              <a
                :style="{
                  color: selectId == record.id ? '#999' : null,
                }"
                @click="confirm(record)"
                >选择</a
              >
            </template>
          </template>
        </a-table>
      </div>
    </div>
  </div>
</template>
<script setup lang="jsx">
import { defineEmits, defineProps, ref, computed } from "vue";
import { Form, message } from "ant-design-vue";
import { useResetRef } from "@/utils/useCommon";
// import { useRouter } from "vue-router";
import { useRowsPage } from "@/api/request";
import { ASSESSMENT_PAGE } from "@/api/apis";
const emit = defineEmits(["confirm"]);
const props = defineProps({
  selectId: Number,
});
const initParams = {
  assessmentName: "",
  pageNo: 1,
  pageSize: 10,
  releaseStatus: 2,
};
// const router = useRouter();
const params = ref(initParams);
const { data, loading, total, fetch } = useRowsPage(
  ASSESSMENT_PAGE,
  params.value
);
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();
};

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

function reset() {
  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");
};
const columns = ref([
  {
    title: "选择",
    dataIndex: "select",
    key: "select",
    width: "100px",
    align: "center",
  },
  {
    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,
  },
]);

async function confirm(record) {
  emit("confirm", record);
}
</script>
<style lang="scss">
.ant-table-striped :deep(.table-striped) td {
  background-color: #fafafa !important;
}
.growth-invist > .ant-drawer-content-wrapper {
  min-width: 1300px !important;
  width: 1300px !important;
}
.growth-invist {
  .contentMain {
    .main_item {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
      margin-top: 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: #ffffff;
        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/reset1.png");
          background-size: 100% 100%;
        }

        .btnText {
          font-size: 14px;
          font-weight: 400;
          color: #4ea6ff;
          line-height: 36px;
          margin-left: 5px;
        }
      }
    }
  }
  .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;
    }
  }
}
</style>
