<template>
  <div id="classHours">
    <div style="margin-bottom: 10px">
      <el-button
        :size="size"
        :type="active === 1 ? 'primary' : ''"
        @click="changeActive(1)"
        >班级学员</el-button
      >
      <el-button
        :size="size"
        :type="active === 2 ? 'primary' : ''"
        @click="changeActive(2)"
        >学时管理</el-button
      >
    </div>
    <div class="dis__s">
      <div>
        <span style="font-size: 15px; color: #666">审核状态：</span
        ><el-button
          :type="activeBtn === 3 ? 'primary' : ''"
          :size="size"
          @click="changeBTN(3)"
          >全部</el-button
        ><el-button
          :type="activeBtn === 2 ? 'primary' : ''"
          :size="size"
          @click="changeBTN(2)"
          >待审核
          <i
            class="el-icon-warning-outline"
            :style="
              reviewListNums >= 200
                ? 'color:red;'
                : reviewListNums < 200 && reviewListNums > 99
                ? 'color:green'
                : reviewListNums < 100
                ? 'color:block;'
                : ''
            "
            style="font-weight: bold"
          ></i>
          <!-- <i
            class="el-icon-warning-outline"
            :style="
              reviewListNums >= 3
                ? 'color:red;'
                : reviewListNums < 3 && reviewListNums > 1
                ? 'color:green'
                : reviewListNums <= 1
                ? 'color:block;'
                : ''
            "
            style="font-weight: bold"
          ></i> --> </el-button
        ><el-button
          :type="activeBtn === 0 ? 'primary' : ''"
          :size="size"
          @click="changeBTN(0)"
          >不通过</el-button
        ><el-button
          :type="activeBtn === 1 ? 'primary' : ''"
          :size="size"
          @click="changeBTN(1)"
          >已通过</el-button
        >
      </div>
      <div>
        <el-button
          size="small"
          v-if="statusShow.indexOf(2) !== -1"
          @click="uploadXS"
          >官方学时推送</el-button
        >
        <span
          style="font-size: 14px; margin: 0px 6px"
          v-if="statusShow.indexOf(2) !== -1"
          >已推送：{{gfNum}}/{{total}}</span
        >
      </div>
    </div>
    <table-list
      ref="tableList"
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      @addClick="addClick"
      :loading="loading"
      @editInfo="editInfo"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="addClick(props.scope.row, 2)"
          >学时审核</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="formData.pageSize"
      :currentPage="formData.pageNum"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <el-dialog
      :visible.sync="dialogVisible"
      width="560px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">
          {{ stice == 1 ? "批准结业" : stice == 3 ? "移除学员" : "" }}
        </div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Close@2x.png"
            alt=""
            @click="dialogVisible = false"
          />
        </div>
      </div>
      <div>
        <ul>
          <li
            v-for="(item, index) in allCheckList"
            :key="index"
            class="btnLists"
          >
            {{ item.realName }}
            <i class="el-icon-close btnIcon" @click="clearStudent(index)"></i>
          </li>
          <div style="clear: both"></div>
          <p>
            {{
              stice == 1
                ? "所选学员已完成学习，批准结业！"
                : stice == 3
                ? "是否移除所选中的学员？"
                : ""
            }}
          </p>
        </ul>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
import { mapGetters } from "vuex";
export default {
  // name: "ClassHours",
  components: { tableList, pagination },
  data() {
    return {
      reviewListNums: 0,
      statusShow: "", //1无官方接口按钮 2只有官方推送 3都有
      size: "medium",
      active: 2,
      activeBtn: 3,
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "学时管理：",
        index: 0,
        ch: "条",
        num: false,
        border: true,
        choice: true,
        addHide: true,
        gfxsStatus: false,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      formData: {
        gradeId: this.$route.query.id,
        status: "0,1",
        pageSize: 10,
        pageNum: 1,
      },
      // 表单
      tableSet: [
        {
          label: "学员编码",
          prop: "studentCode",
          hidden: true,
          width: "180px",
        },
        {
          label: "学员姓名",
          prop: "realName",
          hidden: true,
        },
        {
          label: "学员身份证",
          prop: "idCard",
          hidden: true,
          width: "180px",
        },
        {
          label: "绑定手机号码",
          prop: "telPhone",
          hidden: true,
          width: "130px",
        },
        {
          label: "所购商品",
          prop: "goodsName",
          hidden: true,
          width: "280px",
        },
        {
          label: "所在班级",
          prop: "className",
          hidden: true,
          width: "160px",
        },
        {
          label: "班级有效期",
          prop1: "classStartTime",
          prop2: "classEndTime",
          hidden: true,
          scope: "TimeLists",
          width: "260px",
        },
        {
          label: "学时",
          prop: "classHours",
          hidden: true,
        },
        {
          label: "视频学习进度（节）",
          prop1: "stuAllNum",
          prop2: "secAllNum",
          hidden: true,
          scope: "computer",
          width: "160px",
        },
        {
          label: "做题进度（章卷）",
          prop1: "recordNum",
          prop2: "examNum",
          hidden: true,
          scope: "computer",
          width: "160px",
        },
        {
          label: "学习开始时间",
          prop: "startTime",
          hidden: true,
          scope: "aTimeList",
          width: "160px",
        },
        {
          label: "学习结束时间",
          prop: "endTime",
          hidden: true,
          scope: "aTimeList",
          width: "160px",
        },
        {
          label: "学习有效期",
          prop1: "studyStartTime",
          prop2: "studyEndTime",
          hidden: true,
          scope: "TimeLists",
          width: "310px",
        },
        {
          label: "填写资料审核状态",
          prop: "profileStatus",
          hidden: true,
          scope: "isOptions",
          width: "160px",
          options: [
            {
              label: "审核通过",
              value: 1,
            },
            {
              label: "待审核",
              value: 2,
            },
            {
              label: "审核不通过",
              value: 3,
            },
          ],
        },
        {
          label: "学时审批状态",
          prop: "allStatus",
          hidden: true,
          scope: "statusPeriod",
          width: "130px",
        },
        {
          label: "待重修(视频节和题卷)",
          prop: "waitRebuildNum",
          prop1: "rebuildNum",
          hidden: true,
          scope: "againStudent",
          width: "160px",
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
      gfNum: 0, //学时数量
      dialogVisible: false,
      allCheckList: [], //多选数组
      stice: 0,
    };
  },
  computed: { ...mapGetters(["reviewStatus"]) },
  async mounted() {
    await this.getStatus();
    this.search();
    this.getInitList();
  },
  activated() {
    this.getStatus();
    this.search();
    this.getInitList();
  },
  methods: {
    uploadXS() {
      if (!this.$refs.tableList.allCheckData.length) {
        this.$message.warning("请勾选需要学时信息推送的学员");
        return;
      }
      let arr = this.$refs.tableList.allCheckData.map((item) => {
        return {
          userId: item.userId,
          gradeId: this.$route.query.id,
        };
      });
      this.$api.editGradeUsereditpushPeriod(arr).then((res) => {
        if (res.code === 200) {
          if (!res.msg) {
            this.$message.success("推送成功");
          } else {
            this.$message.error(res.msg);
          }
          this.search();
          this.$refs.tableList.clearMoreActive();
        }
      });
    },
    changeBTN(int) {
      this.activeBtn = int;
      this.search(6);
    },
    getStatus() {
      return new Promise((resolve, reject) => {
        this.$api
          .inquireGradegradelistselectButton({
            gradeId: parseInt(this.$route.query.id),
          })
          .then((res) => {
            this.statusShow = res.data;
            if (res.data.indexOf(2) !== -1) {
              this.navText.gfxsStatus = true;
            } else {
              this.navText.gfxsStatus = false;
            }
            resolve();
          });
      });
    },
    submitTable() {},
    submit() {
      let ars = [];
      this.allCheckList.map((item) => {
        ars.push(item.id);
      });
      let data = {
        id: ars,
      };
      if (this.stice === 1) {
        data.finishStatus = 1;
      }
      if (this.stice === 3) {
        data.status = 0;
      }
      this.$api.editGradeUserGradegrade(data).then((res) => {
        this.dialogVisible = false;
        this.$message.success("修改成功");
        this.search();
      });
    },
    clearStudent(index) {
      this.allCheckList.splice(index, 1);
    },
    editInfo(v) {
      this.addClick(v, 2);
    },
    addClick(v, int) {
      // int = 2详情 3学员管理
      if (v === undefined) {
        // 添加班级
        // this.$router.push({
        //   path: "addClass",
        // });
      } else {
        if (int === 2) {
          //学员详情
          this.$router.push({
            path: "classHoursReview",
            query: {
              id: v.gradeId,
              userId: v.userId,
              goodsId: v.goodsId,
            },
          });
        }
        if (int === 3) {
          // 学员管理
          // this.$router.push({
          //   path: "studentMenu",
          //   query: {
          //     id: v.gradeId,
          //   },
          // });
        }
      }
    },
    changeActive(int) {
      if (int == this.active) {
        return;
      } else {
        if (int === 1) {
          const jump = () => {
            this.$router.push({
              path: "studentMenu",
              query: {
                id: this.$route.query.id,
                goodsId: this.$route.query.goodsId,
              },
            });
          };
          const statusPage = this.$store.state.tagsView.visitedViews.some(
            (item) => {
              return item.name == "StudentMenu";
            }
          );
          if (statusPage) {
            this.$store
              .dispatch("tagsView/delCachedView", {
                name: "StudentMenu",
              })
              .then((res) => {
                jump();
              });
          } else {
            jump();
          }
          // this.active = int;
        }
      }
    },
    search(int) {
      this.loading = true;
      if (int === 1) {
        this.formData.pageNum = 1;
      }
      if (int === 2) {
        this.formData = {
          gradeId: this.$route.query.id,
          status: "0,1",
          pageSize: 10,
          pageNum: 1,
        };
      }
      if (int === 6) {
        if (this.activeBtn == 3) {
          this.formData = {
            gradeId: this.$route.query.id,
            status: "0,1",
            pageSize: 10,
            pageNum: 1,
          };
        } else {
          this.formData = {
            periodStatus: this.activeBtn,
            gradeId: this.$route.query.id,
            status: "0,1",
            pageSize: 10,
            pageNum: 1,
          };
        }
      }
      this.$api
        .inquireGradegradelistUserPeriod(this.formData)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
          if (this.navText.gfxsStatus) {
            this.$api
              .inquireGradegradeofficialPeriodCount({
                gradeId: this.$route.query.id,
              })
              .then((res) => {
                this.gfNum = res.data;
              });
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * 待审核数量
     */
    getInitList() {
      this.$api
        .inquireGradegradelistUserPeriod({
          periodStatus: 2,
          gradeId: this.$route.query.id,
          status: "0,1",
        })
        .then((res) => {
          this.reviewListNums = res.rows.length;
        });
    },
    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>
.dis__s {
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btnLists {
  float: left;
  border: 1px solid #333;
  padding: 0px 10px;
  margin-right: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
  height: 30px;
  line-height: 30px;
  .btnIcon {
    cursor: pointer;
    transition: all 0.2s;
    &:hover {
      color: blue;
    }
  }
}
/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;
  }
}
/deep/.radioTables > .el-radio__label {
  display: none;
}
</style>
