<template>
  <div id="collegePlan">
    <search-box :formList="formList" @search="search" @init="init" />
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      @addClick="addClick"
      :loading="loading"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="userInfos(props.scope.row)"
          >学生信息</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="pageSize"
      :currentPage="currentPage"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <user-info ref="child"></user-info>
  </div>
</template>

<script>
import searchBox from "@/components/searchBox";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
import userInfo from "@/components/userInfoS";
export default {
  components: { searchBox, tableList, pagination, userInfo },
  data() {
    return {
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "学员考试安排",
        index: 0,
        ch: "条",
        num: true,
        choice: true,
        addHide: true,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      tableSet: [
        {
          label: "姓名",
          prop: "realname",
          hidden: true,
        },
        {
          label: "身份证号",
          prop: "idCard",
          hidden: true,
        },
        {
          label: "考试类型",
          prop: "examType",
          hidden: true,
        },
        {
          label: "专业",
          prop: "major",
          hidden: true,
        },
        {
          label: "考试期次",
          prop: "examArrangementTimeVo",
          hidden: true,
          scope: "TimeVoBtn",
        },
        {
          label: "考试地点",
          prop: "examAdress",
          hidden: true,
        },
        {
          label: "备注",
          prop: "remarks",
          hidden: true,
        },
      ], //表头信息
      tableData: [], //表单数据
      total: 0, //一共多少条
      pageSize: 10, //每页多少条数据
      currentPage: 1, //当前页码
      formList: [
        {
          label: "考试类型",
          prop: "examTypeId",
          scope: "cascader",
          placeholder: "选择考试类型",
          options: [],
          props: {
            label: "categoryName",
            value: "categoryId",
          },
        },
        {
          label: "考试时间",
          prop: "TimeList",
          scope: "datePicker",
        },
        {
          label: "考试期次",
          prop: "examPeriod",
          placeholder: "请输入考试期次",
        },
        {
          label: "姓名",
          prop: "realname",
          placeholder: "请输入姓名",
        },
        {
          label: "身份证号",
          prop: "idCard",
          placeholder: "请输入身份证号",
        },
      ], //搜索
      // optionsTion: [],
    };
  },
  mounted() {
    this.search();
    this.initCascader();
  },
  methods: {
    userInfos(option) {
      this.$refs.child.getInfos(option.userId);
    },
    totalScores() {},
    search(v) {
      if (v === undefined) {
        v = {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
        };
      }
      var data = {
        examTypeId: v.examTypeId,
        examPeriod: v.examPeriod,
        startTime: v.TimeList ? (v.TimeList[0] / 1000).toFixed(0) : "",
        endTime: v.TimeList ? (v.TimeList[1] / 1000).toFixed(0) : "",
        realname: v.realname,
        idCard: v.idCard,
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      };
      this.loading = true;
      this.$api.examarrangementlistExamUser(data).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.navText.index = res.total;
      });
      this.loading = false;
    },
    init() {
      this.search();
    },
    del() {},
    addClick(v, int) {},
    submit() {},
    close() {
      this.$confirm("是否关闭该窗口", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {})
        .catch(() => {});
    },
    handleSizeChange(v) {
      this.pageSize = v;
      this.currentPage = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.currentPage = v;
      this.search();
    },
    //级联选择器数据
    initCascader() {
      this.$api
        .inquireProfessionClassification()
        .then((res) => {
          this.arrayChangeType(res.rows);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 接口数据转换级联类型
    arrayChangeType(options) {
      let result = [];
      if (!Array.isArray(options)) {
        return result;
      }
      options.forEach((item) => {
        delete item.children;
      });
      let map = {};
      options.forEach((item) => {
        map[item.categoryId] = item;
      });
      options.forEach((item) => {
        let parent = map[item.pid];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      result = result.sort(this.sortBy("sort", true));
      result.forEach((item, index) => {
        if (item.children) {
          item.children.sort(this.sortBy("sort", true));
        }
      });
      this.formList.forEach((item, index) => {
        if (item.prop === "examTypeId") {
          item.options = result;
          // this.optionsTion = result;
        }
      });
      return result;
    },
    sortBy(attr, rev) {
      //第二个参数没有传递 默认升序排列
      if (rev == undefined) {
        rev = 1;
      } else {
        rev = rev ? 1 : -1;
      }

      return function (a, b) {
        a = a[attr];
        b = b[attr];
        if (a < b) {
          return rev * -1;
        }
        if (a > b) {
          return rev * 1;
        }
        return 0;
      };
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
</style>
