<template>
  <div id="listOfhoursToBeReviewed">
    <div style="margin-bottom: 10px">
      <span style="font-size: 15px; color: #666">审核状态：</span
      ><el-button
        :type="formData.periodStatus === 2 ? 'primary' : ''"
        :size="size"
        @click="changeBTN(2)"
        >初审（{{ reviewListNums }}）
        <!-- <i
          class="el-icon-warning-outline"
          :style="
            reviewListNums >= 200
              ? 'color:red;'
              : reviewListNums < 200 && reviewListNums >= 100
              ? 'color:green'
              : reviewListNums < 100
              ? 'color:block;'
              : ''
          "
          style="font-weight: bold"
        ></i> --> </el-button
      ><el-button
        :type="formData.periodStatus === 3 ? 'primary' : ''"
        :size="size"
        @click="changeBTN(3)"
        >复审（{{ underReiviewNums }}）
        <!-- <i
          class="el-icon-warning-outline"
          :style="
            underReiviewNums >= 200
              ? 'color:red;'
              : underReiviewNums < 200 && underReiviewNums >= 100
              ? 'color:green'
              : underReiviewNums < 100
              ? 'color:block;'
              : ''
          "
          style="font-weight: bold"
        ></i> --> </el-button
      ><el-button
        :type="formData.periodStatus === 0 ? 'primary' : ''"
        :size="size"
        @click="changeBTN(0)"
        >不通过（{{ failNums }}）</el-button
      ><el-button
        :type="formData.periodStatus === 1 ? 'primary' : ''"
        :size="size"
        @click="changeBTN(1)"
        >已通过</el-button
      ><el-button
        :type="formData.periodStatus === -1 ? 'primary' : ''"
        :size="size"
        @click="changeBTN(-1)"
        >不可审核</el-button
      >
    </div>
    <search-box-new
      ref="searchBox"
      :formData="formData"
      :formList="formList"
      @search="search"
      @init="init"
    />
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      :loading="loading"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="jumpPage(props.scope.row)"
          >学时审核</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="formData.pageSize"
      :currentPage="formData.pageNum"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </div>
</template>

<script>
import searchBoxNew from "@/components/searchBoxNew";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  name: "ListOfhoursToBeReviewed",
  components: { searchBoxNew, tableList, pagination },
  data() {
    return {
      size: "small",
      reviewListNums: 0,
      underReiviewNums: 0,
      failNums: 0,
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "学时审核管理",
        index: 0,
        ch: "条",
        num: false,
        border: true,
        choice: true,
        addHide: true,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      //搜索
      formList: [
        {
          prop: "educationTypeId",
          placeholder: "教育类型",
          scope: "educationType",
        },
        {
          prop: "businessId",
          placeholder: "业务层次",
          scope: "businessLevel",
          edu: "educationTypeId",
        },
        {
          prop: "schoolId",
          placeholder: "院校",
          scope: "schoolList",
          edu: "educationTypeId",
        },
        {
          prop: "majorId",
          placeholder: "专业",
          scope: "Professional",
          edu: "educationTypeId",
        },
        {
          prop: "profileStatus",
          placeholder: "填写资料审核状态",
          scope: "select",
          options: [
            {
              label: "通过",
              value: 1,
            },
            {
              label: "不通过",
              value: 3,
            },
            {
              label: "待审核",
              value: 2,
            },
          ],
        },
        {
          prop1: "classStartTime",
          prop2: "classEndTime",
          placeholder1: "班级有效期开始时间",
          placeholder2: "班级有效期结束时间",
          scope: "moreDataPicker",
          Diszing: true,
        },
        {
          prop: "searchKey",
          placeholder: "请输入姓名/身份证",
        },
        {
          prop1: "periodStartTime",
          prop2: "periodEndTime",
          placeholder1: "审核通过开始时间",
          placeholder2: "审核通过结束时间",
          scope: "moreDataPicker",
          Diszing: true,
        },
        {
          prop: "className",
          placeholder: "所在班级",
        },
      ],
      formData: {
        profileStatus: "",
        periodStatus: 2,
        status: 1,
        pageSize: 10,
        pageNum: 1,
      },
      // 表单
      tableSet: [
        {
          label: "学员编码",
          prop: "studentCode",
          hidden: false,
        },
        {
          label: "学员姓名",
          prop: "realName",
          hidden: true,
        },
        {
          label: "学员身份证",
          prop: "idCard",
          hidden: true,
        },
        {
          label: "绑定手机号码",
          prop: "telPhone",
          hidden: false,
        },
        {
          label: "所购商品",
          prop: "goodsName",
          hidden: true,
        },
        {
          label: "所在班级",
          prop: "className",
          hidden: true,
        },
        {
          label: "班级有效期",
          prop1: "classStartTime",
          prop2: "classEndTime",
          hidden: false,
          scope: "TimeLists",
        },
        {
          label: "学时",
          prop: "classHours",
          hidden: false,
        },
        {
          label: "视频学习进度（节）",
          prop1: "stuAllNum",
          prop2: "secAllNum",
          hidden: false,
          scope: "computer",
        },
        {
          label: "做题进度（章卷）",
          prop1: "recordNum",
          prop2: "examNum",
          hidden: false,
          scope: "computer",
        },
        {
          label: "学习开始时间",
          prop: "startTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "学习结束时间",
          prop: "endTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "学习服务期",
          prop1: "serviceStartTime",
          prop2: "serviceEndTime",
          hidden: false,
          Diszing: true,
          scope: "TimeLists",
        },
        {
          label: "七大员继教年份",
          prop: "sevenYear",
          hidden: true,
        },
        {
          label: "填写资料审核状态",
          prop: "profileStatus",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "审核通过",
              value: 1,
            },
            {
              label: "待审核",
              value: 2,
            },
            {
              label: "审核不通过",
              value: 3,
            },
          ],
        },
        {
          label: "学时审批状态",
          prop: "periodStatus",
          hidden: true,
          scope: "statusPeriod",
        },
        {
          label: "审核通过时间",
          prop: "periodTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "待重修(视频节和题卷)",
          prop: "waitRebuildNum",
          prop1: "rebuildNum",
          hidden: false,
          scope: "againStudent",
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
    };
  },
  mounted() {
    if (
      this.$route.params.educationId &&
      this.$route.params.businessId &&
      this.$route.params.type
    ) {
      this.$set(
        this.formData,
        "educationTypeId",
        this.$route.params.educationId
      );
      this.$set(this.formData, "businessId", this.$route.params.businessId);
      this.$set(this.formData, "periodStatus", this.$route.params.type);
      this.$refs.searchBox.changeEducationType(
        this.$route.params.educationId,
        true
      );
      this.$refs.searchBox.changeBusinessLevel(this.$route.params.businessId);
    }
    console.log(
      this.$methodsTools.timestampConvert(this.$route.params.timeType)[0]
    );
    console.log(
      this.$methodsTools.timestampConvert(this.$route.params.timeType)[1]
    );
    if (this.$route.params.timeType >= 0) {
      this.$set(
        this.formData,
        "classStartTime",
        this.$methodsTools.timestampConvert(this.$route.params.timeType)[0]
      );
      this.$set(
        this.formData,
        "classEndTime",
        this.$methodsTools.timestampConvert(this.$route.params.timeType)[1]
      );
    }
    this.search();
    this.getInitList();
    this.getInitUnderList();
    this.getFailList();
  },
  activated() {
    this.search();
    this.getInitList();
    this.getInitUnderList();
    this.getFailList();
  },
  methods: {
    changeBTN(int) {
      this.formData.periodStatus = int;
      this.search(6);
    },
    /**
     * 待审核数量
     */
    getInitList() {
      this.$api
        .inquireGradegradelistUserPeriod({
          periodStatus: 2,
          status: 1,
        })
        .then((res) => {
          this.reviewListNums = res.rows.length;
        });
    },
    /**
     * 审核中数量
     */
    getInitUnderList() {
      this.$api
        .inquireGradegradelistUserPeriod({
          periodStatus: 3,
          status: 1,
        })
        .then((res) => {
          this.underReiviewNums = res.rows.length;
        });
    },
    /**
     * 不通过数量
     */
    getFailList() {
      this.$api
        .inquireGradegradelistUserPeriod({
          periodStatus: 0,
          status: 1,
        })
        .then((res) => {
          this.failNums = res.rows.length;
        });
    },
    jumpPage(v) {
      this.$api
        .inquireGradegradelockPeriodStatus({
          gradeId: v.gradeId,
          userId: v.userId,
          goodsId: v.goodsId,
        })
        .then((res) => {
          if (res.msg) {
            this.$message.warning(res.msg + "正在操作");
            return;
          } else {
            let data = {
              userId: v.userId,
              realName: v.realName,
              id: v.gradeId,
              className: v.className,
              goodsId: v.goodsId,
              goodsName: v.goodsName,
              orderGoodsId: v.orderGoodsId,
              keyId: `${v.userId}-${v.goodsId}-${v.gradeId}-${v.orderGoodsId}`,
            };
            this.checkSession(data)
              .then(() => {
                //学员详情
                this.$router.push({
                  path: "classHoursReview",
                });
              })
              .catch(() => {
                this.$message.error("存在异常,请联系开发人员");
              });
          }
        });
    },
    search(int) {
      this.loading = true;
      if (int === 1) {
        this.formData.pageNum = 1;
      }
      if (int === 2) {
        this.formData = {
          profileStatus: "",
          periodStatus: this.formData.periodStatus,
          status: 1,
          pageSize: 10,
          pageNum: 1,
        };
      }
      if (int === 6) {
        this.formData.pageSize = 10;
        this.formData.pageNum = 1;
      }
      var data = JSON.parse(JSON.stringify(this.formData));
      if (this.formData.classStartTime) {
        data.classStartTime = parseInt(data.classStartTime / 1000);
      }
      if (this.formData.classEndTime) {
        data.classEndTime = parseInt(data.classEndTime / 1000);
      }
      if (this.formData.periodStartTime) {
        data.periodStartTime = parseInt(data.periodStartTime / 1000);
      }
      if (this.formData.periodEndTime) {
        data.periodEndTime = parseInt(data.periodEndTime / 1000);
      }
      this.$api
        .inquireGradegradelistUserPeriods(data)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    init() {
      this.search(2);
    },
    handleSizeChange(v) {
      this.formData.pageSize = v;
      this.formData.pageNum = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.formData.pageNum = v;
      this.search();
    },
  },
};
</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>
