<template>
  <div class="record-warp">
    <div class="record-main">
      <el-row>
        <el-col :span="24">
          <div class="search-head">
            <el-input v-model="planName" clearable placeholder="请输入计划名称"></el-input
            >&nbsp;&nbsp;&nbsp;&nbsp;
            <!-- 
            <el-date-picker
              :clearable="false"
              v-model="planTime"
              type="date"
              format="yyyy-MM-dd"
              placeholder="选择创建日期"
            >
            </el-date-picker> -->
            <!-- <el-cascader
              v-show="userInfo.roleType == '5'"
              placeholder="请选择组织架构"
              v-model="group"
              :options="groupData"
              :props="{ checkStrictly: true }"
              clearable
            ></el-cascader>
            <el-cascader
              v-show="userInfo.roleType == '4'"
              placeholder="请选择组织架构"
              v-model="group"
              :options="groupData"
              clearable
            ></el-cascader> -->
            &nbsp;&nbsp;&nbsp;&nbsp;
            <el-select v-model="planStatus" placeholder="请选择计划状态">
              <el-option
                :label="item.name"
                :value="item.id"
                v-for="item in channelList"
                :key="item.id"
              ></el-option>
            </el-select>
            <!-- &nbsp;&nbsp;&nbsp;&nbsp;
            <div style="display: flex; flex-direction: row; align-items: center">
              <span
                style="
                  font-size: 16px;
                  margin-right: 10px;
                  line-height: 20px;
                  min-width: 40px;
                "
                >测评对象:</span
              >
              <el-radio v-model="planType" label="1">教师</el-radio>
              <el-radio v-model="planType" label="0">学生</el-radio>
            </div> -->
            &nbsp;&nbsp;&nbsp;&nbsp;
            <el-button type="primary" round icon="el-icon-search" @click="searchTarget"
              >搜索</el-button
            >
            <el-button type="info" round @click="clearSearch">清空</el-button>
          </div>
        </el-col>
      </el-row>
      <div class="table-content">
        <el-table
          height="100%"
          :data="tableData"
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '5px' }"
          :header-cell-style="{ background: '#F8F8F8', color: '#606266' }"
        >
          <!-- <el-table-column prop="name" label="姓名" align="center" width=""  show-overflow-tooltip>
          </el-table-column> -->
          <el-table-column
            :show-overflow-tooltip="true"
            prop="planName"
            label="计划名称"
            align="center"
            min-width="200px"
          >
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            :show-overflow-tooltip="true"
            align="center"
            width=""
          >
          </el-table-column>
          <el-table-column
            prop="planEndTime"
            label="结束时间"
            :show-overflow-tooltip="true"
            align="center"
            width=""
          >
          </el-table-column>
          <el-table-column
            :show-overflow-tooltip="true"
            prop="planOrgName"
            label="所属组织架构"
            align="center"
            width=""
          >
          </el-table-column>
          <!-- <el-table-column prop="userNo" label="测试人数" align="center" width="">
          </el-table-column> -->
          <el-table-column prop="createUserName" label="创建人" align="center" width="">
          </el-table-column>
          <el-table-column
            prop="planStatus"
            label="状态"
            :formatter="forMaPlan"
            align="center"
            width=""
          >
            <template slot-scope="scope">
              <div
                style="display: flex; justify-content: center; align-items: center"
                v-if="scope.row.planStatus == '3'"
              >
                <img
                  style="width: 16px"
                  src="../../../assets/img/home/isCom.png"
                  alt=""
                />&nbsp;&nbsp;
                <div style="color: #00955e">已完成</div>
              </div>
              <div
                style="display: flex; justify-content: center; align-items: center"
                v-if="scope.row.planStatus == '2'"
              >
                <img
                  style="width: 16px"
                  src="../../../assets/img/home/isRun.png"
                  alt=""
                />&nbsp;&nbsp;
                <div style="color: #f6cb00">进行中</div>
              </div>
              <div
                style="display: flex; justify-content: center; align-items: center"
                v-if="scope.row.planStatus == '1'"
              >
                <img
                  style="width: 16px"
                  src="../../../assets/img/home/isNo.png"
                  alt=""
                />&nbsp;&nbsp;
                <div style="color: #d52121">未开始</div>
              </div>
            </template>
          </el-table-column>
          <!-- extractCode -->
          <el-table-column label="报告密码" align="center" width="180px">
            <template slot-scope="scope">
              <div style="display: flex; align-items: center; justify-content: center">
                <!-- {{ scope.row.extractCode}} -->
                <span
                  v-show="
                    scope.row.isShow &&
                    scope.row.extractCode != null &&
                    scope.row.extractCode != ''
                  "
                  >{{ scope.row.extractCode }}&nbsp;&nbsp;</span
                >
                <div
                  style="
                    display: inline-block;
                    vertical-align: middle;
                    width: auto;
                    height: 0px;
                    line-height: 9px;
                  "
                  v-show="
                    !scope.row.isShow &&
                    scope.row.extractCode != null &&
                    scope.row.extractCode != ''
                  "
                >
                  ******&nbsp;&nbsp;
                </div>
                <i
                  style="color: #00bf78"
                  v-show="
                    scope.row.isShow &&
                    scope.row.extractCode != null &&
                    scope.row.extractCode != ''
                  "
                  @click="scope.row.isShow = !scope.row.isShow"
                  class="el-icon-view"
                ></i>
                &nbsp;&nbsp;
                <i
                  v-clipboard:copy="scope.row.extractCode"
                  v-clipboard:success="copySuc"
                  v-clipboard:error="copyFail"
                  title="复制文本"
                  v-show="
                    scope.row.isShow &&
                    scope.row.extractCode != null &&
                    scope.row.extractCode != ''
                  "
                  class="el-icon-copy-document"
                ></i>
                <i
                  v-show="
                    !scope.row.isShow &&
                    scope.row.extractCode != null &&
                    scope.row.extractCode != ''
                  "
                  @click="scope.row.isShow = !scope.row.isShow"
                  class="el-icon-view"
                ></i>
                &nbsp;&nbsp;
                <i
                  v-clipboard:copy="scope.row.extractCode"
                  v-clipboard:success="copySuc"
                  v-clipboard:error="copyFail"
                  title="复制文本"
                  v-show="
                    !scope.row.isShow &&
                    scope.row.extractCode != null &&
                    scope.row.extractCode != ''
                  "
                  class="el-icon-copy-document"
                ></i>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="250px" align="center">
            <template slot-scope="scope">
              <div
                class="detail_button_out"
                v-if="
                  (userInfo.roleType == '5' && scope.row.planStatus == '3') ||
                  (scope.row.planStatus == '3' && scope.row.enable == '1')
                "
              >
                <div class="detail_button" @click="addUser(scope.row)">
                  <img src="../../../assets/img/table/search.png" />
                  <span> 查看报告</span>
                </div>
                <div class="detail_button" @click="downloadButton(scope.row)">
                  <img src="../../../assets/img/table/xiafa1.png" />
                  <!-- <img src="../../../assets/img/table/xiafaz.gif" /> -->
                  <span> 下载报告</span>
                </div>
              </div>
              <div
                class="detail_button_out_dis"
                v-if="
                  !(
                    (userInfo.roleType == '5' && scope.row.planStatus == '3') ||
                    (scope.row.planStatus == '3' && scope.row.enable == '1')
                  )
                "
              >
                <div class="detail_button_dis" :title="titleFormatter(scope.row)">
                  <img src="../../../assets/img/table/search_dis.png" />
                  <span> 查看报告</span>
                </div>
                <div class="detail_button_dis" :title="titleFormatter(scope.row)">
                  <img src="../../../assets/img/table/xiafa1_dis.png" />
                  <span> 下载报告</span>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- small -->
      <el-pagination
        class="pag_class"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageNum"
        layout="total, sizes, prev, pager, next"
        :page-size="pageSize"
        :page-sizes="[10, 20, 50, 100]"
        :total="total"
      >
      </el-pagination>
      <!-- <el-pagination small background layout="total prev, pager, next" :total="36">
      </el-pagination> -->
    </div>
    <PlanReport ref="register" @search="searchTarget" />
    <!-- 弹出框---选择问题需要下载的组织架构 -->
    <div class="radius_dia">
      <el-dialog
        title=""
        :visible.sync="downloadVisible"
        width="40%"
        :before-close="handleClose"
        center
      >
        <div slot="title">
          <p style="text-align: center; margin-bottom: 20px; font-weight: 700">
            报告下载
          </p>
          <!-- <div style="text-align: left; margin-left: 10%; color: #333333">
            选择下载范围
          </div> -->
          <el-form
            :inline="true"
            class="demo-form-inline form-plan"
            style="
              margin-top: 20px;
              display: flex;
              flex-direction: row;
              align-items: center;
              justify-content: space-between;
              padding: 0 10%;
            "
          >
            <!-- <el-form-item label="">
              <el-select v-model="dimensionality" placeholder="请选择下载范围">
                <el-option
                  v-for="item in dimensionalityOption"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <!-- <el-form-item label="" v-show="dimensionality == '1'">
              <el-select v-model="grade" placeholder="请选择年级">
                <el-option
                  v-for="item in gradeList"
                  :key="item.id"
                  :label="item == -1 ? '教师组' : item + '级'"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <!-- <el-form-item label="" v-show="dimensionality == '2'">
              <el-select multiple v-model="orgName" placeholder="请选择班级">
                <el-option
                  v-for="item in orgList"
                  :key="item.id"
                  :label="item.orgName"
                  :value="item.orgNo"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <!-- <el-form-item label="" v-show="dimensionality == '0'">
              <el-button
                type="success"
                style="border-radius: 20px"
                v-show="dimensionality == '0'"
                @click="downloadFun"
              >
                下载
              </el-button>
            </el-form-item> -->
          </el-form>
          <div style="display: flex; width: 100%; justify-content: center">
            <el-button
              type="success"
              style="border-radius: 20px"
              v-show="dimensionality == '1'"
              @click="downloadFun"
            >
              下载已选年级
            </el-button>
            <el-button
              type="success"
              style="border-radius: 20px"
              v-show="dimensionality == '2'"
              @click="downloadFun"
            >
              下载已选班级
            </el-button>
            <el-button
              type="success"
              style="border-radius: 20px"
              v-show="dimensionality == '2'"
              @click="downloadAllFun"
            >
              下载全部班级
            </el-button>
          </div>
        </div>
        <div style="margin-left: 10%;margin-right: 10%; color: #333333; margin-bottom: 20px ;display:flex;justify-content: space-between;align-items: center;">
          <span>待下载列表</span> <el-button
                type="success"
                style="border-radius: 20px"
                v-show="dimensionality == '0'"
                @click="downloadFun"
              >
                下载
              </el-button>
        </div>
        <el-table
          :data="downList"
          style="width: 80%; margin-left: 10%"
          max-height="250"
          :header-cell-style="{ background: '#F8F8F8', color: '#606266' }"
        >
          <el-table-column type="index" align="center" label="序号"> </el-table-column>
          <el-table-column
            prop="filePath"
            :formatter="fileNameFormatter"
            align="center"
            label="报告名称"
          >
          </el-table-column>
          <el-table-column prop="createTime" align="center" label="生成时间">
          </el-table-column>

          <el-table-column fixed="right" align="center" label="操作" width="60px">
            <template slot-scope="scope">
              <el-button @click="downNewFun(scope.row)" type="text" size="small">
                下载
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer"> </span>
      </el-dialog>

      <el-dialog
        class="dig_update ts_li"
        :visible.sync="resetVisible"
        width="30%"
        center
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :before-close="closeResetFun"
        style="border-radius: 40px"
      >
        <div slot="title">
          <div class="demo-ruleForm">
            <p class="dig_title">提示</p>
            <!-- <img src="../../../assets/img/report/downN.png" alt=""> -->
            <p align="center">
              <img
                style="width: 60px"
                src="../../../assets/img/table/xiafaz.gif"
                alt=""
              />
            </p>

            <p style="margin-bottom: 40px; margin-top: 20px">正在下载中，请勿操作</p>
          </div>
        </div>
      </el-dialog>
      <el-dialog
        class="dig_update ts_li"
        :visible.sync="verifyVisible"
        width="30%"
        center
        style="border-radius: 40px"
      >
        <div slot="title">
          <div class="demo-ruleForm">
            <p class="dig_title">提示</p>
            <!-- <img src="../../../assets/img/report/downN.png" alt=""> -->
            <p style="margin-bottom: 40px; margin-top: 20px">确定离开吗？</p>
            <div class="dig_button">
              <el-button type="info" round @click="cancleFun()">取消</el-button>
              <el-button
                type="success"
                round
                @click="
                  verifyVisible = false;
                  resetVisible = false;
                "
                >确定</el-button
              >
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { oSessionStorage } from "../../../utils/utils";
import planReport from "../../../components/PlanReport.vue";
import { basePath } from "../../../utils/http";
import { Loading } from "element-ui";
export default {
  name: "userManage",
  components: {
    PlanReport: planReport,
  },
  data() {
    return {
      basePath: basePath,
      //上传文件的弹出款的标志
      fileVisible: false,
      //判断点击的是重置密码还是点击删除
      isDelete: false,
      //重置密码需要调用个userId
      userId: "",
      //充值密码使用userName
      userName: "",
      //重置密码弹出框
      resetVisible: false,
      //个人用户---确认标志
      verifyVisible: false,
      //根据名称搜索
      name: "",
      //搜索的用户编号
      studentNumber: "",
      //搜索的组织架构
      // 搜索需要的性别
      sex: "",
      planType: "1",

      planName: "",
      planTime: "",
      planStatus: "",
      group: "",

      ppData: [],
      groupData: [],
      options: [
        {
          value: "1",
          label: "选项1",
          children: [
            {
              value: "11",
              label: "选项11",
              children: [{ value: "111", label: "选项111" }],
            },
          ],
        },
      ],

      centerDialogVisible: false,
      editUserFlag: false,
      startTime: "",
      endTime: "",
      value1: null,
      total: 0,
      pageSize: 10,
      pageNum: 1,
      keyword: "",
      tableData: [],
      userInfo: {}, //用户信息

      invitationCode: "",
      roleType: "0",
      type: 0,
      view: {
        name: "",
        studentNumber: "",
        sex: "",
        orgName: "",
      },

      channelList: [
        { name: "未开始", id: "1" },
        { name: "进行中", id: "2" },
        { name: "已完成", id: "3" },
      ],
      //下载报告标志
      downloadVisible: false,
      //当前下载的计划需要点击需要下
      //组织架构列表
      orgList: [],
      //组织编号name
      orgName: [],
      //下载报告  测试计划ID
      planId: "",
      dimensionality: 0,
      dimensionalityOption: [
        { id: 0, name: "学院" },
        { id: 1, name: "年级" },
        { id: 2, name: "班级" },
      ],
      //院的编号
      courtNum: "",
      grade: "",
      gradeList: [],
      optionsLoad: {
        lock: true,
        text: "努力下载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      },
      loadingInstance: null,
      downList: [],
      timeFlag: null,
    };
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));

    this.getChannel();
    if (!this.userInfo) {
      //如果用户信息不存在跳转登陆页
      this.$router.push({ path: "/" });
    }
    this.searchTarget();
    let a = sessionStorage.getItem("individualTendency");

    if (a != null) {
      let user = JSON.parse(a);
      if (user.isBack) {
        user.isBack = false;
        // let user = JSON.parse(sessionStorage.getItem("individualTendency"));
        sessionStorage.setItem("individualTendency", JSON.stringify(user));
        this.addRegisterUser(user);
      }
    }
  },

  destroyed() {
    clearInterval(this.timeFlag);
  },
  methods: {
    //点击确认开始关闭定时器
    fileNameFormatter(val) {
      if (val.filePath == null) {
        return;
      } else {
        let nameTmp = val.filePath;
        //开始截取字符串
        let lastIndex = nameTmp.lastIndexOf("/");
        // console.log(nameTmp.slice(lastIndex+1, 0));
        return nameTmp.slice(lastIndex + 1, nameTmp.length);
      }
    },
    closeResetFun() {
      //关闭
      // this.resetVisible = false;
      this.verifyVisible = true;
    },
    cancleFun() {
      this.verifyVisible = false;
      this.resetVisible = true;
    },

    copySuc() {
      this.$message.success("复制成功");
    },

    copyFail() {
      this.$message.success("复制失败");
    },
    onCopy(row) {
      if (navigator.clipboard && window.isSecureContext) {
        navigator.clipboard.writeText(row.extractCode).then(() => {
          this.$message.success("复制成功");
        });
      } else {
        const textArea = document.createElement("textarea");
        textArea.value = val;
        // 使text area不在viewport，同时设置不可见
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();
        this.$message.success("复制成功");
        return new Promise((res, rej) => {
          // 执行复制命令并移除文本框
          document.execCommand("copy") ? res() : rej();
          textArea.remove();
        });
      }
    },
    titleFormatter(val) {
      if (val.planStatus == "1") {
        return "计划未开始";
      } else if (val.planStatus == "2") {
        return "计划进行中";
      }

      if (val.enable == "0") {
        return "当前计划未授权";
      }
    },
    handleClose() {
      clearInterval(this.timeFlag);
      this.downloadVisible = false;
    },
    //根据计划查询院
    queryCourt() {
      this.$http.get(`/planOrg/findPlanParentOrg?planId=${this.planId}`, {}, (res) => {
        if (res && res.code == 200) {
          this.courtNum = res.data[0].orgNo;
          // this.orgName = [res.data[0].orgNo];
          // this.orgList = res.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //根据计划下班级
    queryGrade() {
      this.$http.get(`/planOrg/findPlanGrade?planId=${this.planId}`, {}, (res) => {
        if (res && res.code == 200) {
          this.grade = res.data[0];
          this.gradeList = res.data;
          // this.orgName = [res.data[0].orgNo];
          // this.orgList = res.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //下载报告
    downloadFun() {
      // dimensionality: 0,
      // dimensionalityOption: [
      //   { id: 0, name: "学院" },
      //   { id: 1, name: "年级" },
      //   { id: 2, name: "班级" },
      // ],
      //在这里调用接口
      //判断当前选择是院还是届--还是班级
      let params = {};
      if (this.dimensionality == 0) {
        //调用接口
        params = {
          planId: this.planId,
          orgNo: this.courtNum,
          flag: 0,
        };
      } else if (this.dimensionality == 1) {
        //调用班级接口
        params = {
          planId: this.planId,
          orgNo: this.courtNum,
          flag: 1,
          grade: this.grade,
        };
      } else if (this.dimensionality == 2) {
        if (this.orgName.length == 0) {
          this.$message.error("请选择班级");
          return;
        }
        params = {
          planId: this.planId,
          orgNo: this.courtNum,
          flag: 2,
          classIds: this.orgName,
        };
      }
      this.downloadVisible = false;
      this.resetVisible = true;
      //需要传输

      //开始不调用测试了
      clearInterval(this.timeFlag);

      this.$http.post(`/generate/report/v2`, params, (res) => {
        if (res && res.code == 200) {
          // this.currentDownFun(res.data);
          let a = document.createElement("a");
          document.body.appendChild(a);
          a.setAttribute("href", basePath + `/plan/download?recordId=${res.data.id}`);
          a.click();
          this.$nextTick(() => {
            // 以服务的方式调用的 Loading 需要异步关闭
            this.resetVisible = false;
          });
        } else {
          this.resetVisible = false;
          this.$message.error(res.msg);
        }
      });
    },
    //开始下载
    currentDownFun(val) {
      this.$http.getImg(`/plan/download?path=${val}`, {}, (res) => {
        if (res && res.code == 200) {
          // this.grade = res.data[0];
          // this.gradeList = res.data;
          // this.orgName = [res.data[0].orgNo];
          // this.orgList = res.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //下载全部班级
    downloadAllFun() {
      clearInterval(this.timeFlag);
      //下载全部班级
      //循环班级列表拿到
      let params = {};
      let orgNameList = [];
      for (let i = 0; i < this.orgList.length; i++) {
        orgNameList.push(this.orgList[i].orgNo);
      }
      params = {
        planId: this.planId,
        orgNo: this.courtNum,
        flag: 2,
        classIds: orgNameList,
      };
      this.downloadVisible = false;
      this.resetVisible = true;
      // Loading.service(options);
      this.$http.post(`/plan/generate/report/v2`, params, (res) => {
        if (res && res.code == 200) {
          let a = document.createElement("a");
          document.body.appendChild(a);
          a.setAttribute("href", basePath + `/plan/download?recordId=${res.data.id}`);
          a.click();
          this.$nextTick(() => {
            // 以服务的方式调用的 Loading 需要异步关闭
            this.resetVisible = false;
          });
          // this.currentDownFun(res.data);
        } else {
          this.resetVisible = false;
          this.$message.error(res.msg);
        }
      });
    },
    downNewFun(val) {
      //返回这个路径要如何用
      let a = document.createElement("a");
      document.body.appendChild(a);
      a.setAttribute("href", basePath + `/plan/download?recordId=${val.id}`);
      a.click();
      //开始调用刷新按钮
      // clearInterval(this.timeFlag);
      // this.timeFlag = setInterval(() => {
      //   this.getPlanFileList();
      // }, 3000);
    },
    //组织架构选择--
    getOrgList() {
      this.$http.get(`/planOrg/findAllByPlanId?planId=${this.planId}`, {}, (res) => {
        if (res && res.code == 200) {
          // this.orgName = [res.data[0].orgNo];
          this.orgList = res.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //下载标志
    downloadButton(row) {
      // dimensionality: 0,
      // dimensionalityOption: [
      //   { id: 0, name: "学院" },
      //   { id: 1, name: "年级" },
      //   { id: 2, name: "班级" },
      // ],
      this.dimensionality = 0;
      if (row.planType == "1") {
        this.dimensionalityOption = [{ id: 0, name: "学院" }];
      } else {
        this.dimensionalityOption = [
          { id: 0, name: "学院" },
          { id: 1, name: "年级" },
          { id: 2, name: "班级" },
        ];
      }

      //在这里记录一下---数据
      //当查看报告时--如果显示的是
      if (this.userInfo.roleType != 5) {
        if (row.enable == "0") {
          //提示暂未授权
          this.$message({
            message: "正在下载中",
            type: "warning",
          });
          return;
        }
      }
      this.planId = row.id;
      this.downloadVisible = true;
      this.getOrgList();
      this.queryCourt();
      this.queryGrade();
      clearInterval(this.timeFlag);

      this.getPlanFileList();
      this.timeFlag = setInterval(() => {
        this.getPlanFileList();
      }, 2000);
      //调用接口
      //查询下载计划的列表
    },
    //查询计划列表
    getPlanFileList() {
      this.$http.get(`/downRecord/findDownRecord?planId=${this.planId}`, {}, (res) => {
        //  this.$toast.success({message:'成功'});
        if (res && res.code == 200) {
          //将值赋值给list
          this.downList = res.data;
          // this.channelList = res.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    forMaPlan(val) {
      if (val.planStatus == "1") {
        return "未开始";
        //
      } else if (val.planStatus == "2") {
        //
        return "进行中";
      } else if (val.planStatus == "3") {
        //
        return "已完成";
      }
    },
    //文件上传成功
    fileSuccess(res) {
      if (res.code == 200) {
        this.searchTarget();
        this.$message({
          message: res.msg,
          type: "success",
        });
      } else {
        this.$message({
          message: res.msg,
          type: "error",
        });
      }
      //查询列表
    },
    //文件上传失败
    fileError() {
      this.$message({
        message: "上传失败",
        type: "error",
      });
    },
    cancle() {
      this.resetVisible = false;
    },
    //提交文本
    submitCom() {
      //判断当前是否是
      if (this.isDelete) {
        this.deleteUser();
        //调用删除方法
      } else {
        this.resetFun();
        // 调用重置密码方法
      }
    },
    //性别---
    genderFun(val) {
      let sex = val.gender;
      if (sex == "1") {
        return "男";
      } else if (sex == "0") {
        return "女";
      } else {
        return sex;
      }
    },
    //每页多少条
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchTarget();
    },
    //获取组织架构方法--------------------开始-----------------------
    getChannel() {
      this.$http.get(
        `/org/findAllOrgByPOrgNo?orgNo=${this.userInfo.orgNo}`,
        {},
        (res) => {
          //  this.$toast.success({message:'成功'});
          if (res && res.code == 200) {
            //将值赋值给list
            if (res.data.length > 0) {
              let resAdd = this.addPro(res.data);
              this.ppData = JSON.parse(JSON.stringify(resAdd));
              let forRes = this.arrToTree(resAdd);

              let resultRes = this.deleteChildren(forRes);
              this.groupData = resultRes[0].children;
            } else {
              this.groupData = [];
            }
            // this.channelList = res.data;
          } else {
            this.$message.error(res.msg);
          }
        }
      );
    },
    //z增加
    addPro(val) {
      let data = JSON.parse(JSON.stringify(val));
      for (let i = 0; i < val.length; i++) {
        data[i].value = val[i].orgNo;
        data[i].label = val[i].orgName;
      }
      return data;
    },
    //非递归方式：将平铺数据转换为树形结构数据
    arrToTree(arr) {
      let data = arr.filter((item) => {
        item.children = arr.filter((e) => {
          return item.orgNo === e.parentOrgNo;
        });
        return this.userInfo.orgNo == item.orgNo;
        // return !item.parentOrgNo;
      });
      return data;
    },
    //去除转换树形结构数据后存在的空children
    deleteChildren(arr) {
      let childs = arr;
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            this.deleteChildren(childs[i].children);
          } else {
            delete childs[i].children;
          }
        }
      }
      return arr;
    },
    //获取组织架构方法--------------------结束-----------------------
    formatterDelete(row) {
      if (row.state == 0) {
        return "已删除";
      } else {
        return "正常";
      }
    },
    resetUser(flag, val) {
      this.resetVisible = true;
      this.isDelete = flag;
      this.userId = val.id;
      this.userName = val.userName;
      //当前用户id

      //重置密码
    },
    editUser(row) {
      this.editRegisterUser(row);
    },
    viewUser(row) {
      this.view.name = row.userName;
      this.view.studentNumber = row.userNo;
      this.view.sex = row.gender == "0" ? "女" : "男";
      this.view.orgName = row.orgName;
      this.centerDialogVisible = true;
    },
    addUser(val) {
      if (this.userInfo.roleType != "5") {
        if (val.enable == "0") {
          this.$message({
            type: "error",
            message: "暂未授权",
          });
          return;
        }
      }
      this.addRegisterUser(val);
    },
    clearSearch() {
      this.planName = "";
      this.planTime = "";
      this.group = "";
      this.planStatus = "";
      this.planType = "1";
      this.searchTarget();
    },

    formatterTime(val) {
      let date = new Date(val);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      month = this.formatterMon(month);
      let day = date.getDate();
      day = this.formatterMon(day);
      return year + "-" + month + "-" + day;
    },
    formatterMon(val) {
      if (val < 10) {
        return "0" + val;
      } else {
        return val;
      }
    },
    addRegisterUser(val) {
      let obj = {
        planType: val.planType,
        id: val.id,
        planName: val.planName,
        rouName: "planReport",
        isBack: false,
        userNo: "",
      };
      this.$refs.register.open(obj);
    },
    editRegisterUser(val) {
      // debugger;
      this.$refs.register.edit(val);
    },
    resetFun() {
      this.$http.get(`/user/resetPassword?userId=${this.userId}`, {}, (res) => {
        //  this.$toast.success({message:'成功'});
        if (res && res.code == 200) {
          this.resetVisible = false;
          this.$message.success("重置成功");
          this.searchTarget();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    deleteUser() {
      this.$http.get(`/user/delete?userId=${this.userId}`, {}, (res) => {
        //  this.$toast.success({message:'成功'});
        if (res && res.code == 200) {
          this.$message.success("删除成功");
          this.resetVisible = false;
          this.searchTarget();
        } else {
          this.$message.error("删除失败");
        }
      });
    },

    handleCurrentChange(val) {
      this.pageNum = val;
      this.searchList();
    },
    //根据现有情况进行搜索
    searchList() {
      let time = "";
      if (this.planTime != "") {
        time = this.formatterTime(this.planTime);
      }

      let gp = "";
      if (this.group != "") {
        gp = this.group[this.group.length - 1];
      }

      let url = `/plan/findListByPage?pageSize=${this.pageSize}&pageNum=${this.pageNum}${
        gp == "" ? `&orgNo=${this.userInfo.orgNo}` : `&orgNo=${gp}`
      }${time == "" ? "" : `&createDate=${time}`}${
        this.planStatus == "" ? "" : `&planStatus=${this.planStatus}`
      }${this.planName == "" ? "" : `&planName=${this.planName}`}${
        this.planType == "" ? "" : `&planType=${this.planType}`
      }`;
      this.$http.get(url, {}, (res) => {
        if (res && res.code == 200) {
          let aa = [];
          for (let i = 0; i < res.data.content.length; i++) {
            aa.push({ ...res.data.content[i], isShow: false });
          }
          this.tableData = aa;
          this.total = res.data.totalElements;
        } else {
          // this.$toast.fail(res.msg);
          this.$message.error(res.msg);
        }
      });
    },
    searchTarget() {
      this.pageNum = 1;
      this.searchList();
    },
    //跳转首页
    goHome() {
      this.$router.push({ path: "/home" });
    },
    //跳转记录页
    goRecord() {
      this.$router.push({ path: "/record" });
    },
    //退出登陆
    logout() {
      oSessionStorage.removeItem("userInfo");
      oSessionStorage.removeItem("token");
      this.$router.push({ path: "/" });
    },

    //点击获取月出勤次数
    getTimes(param) {
      this.monthTimes = param;
    },
  },
};
</script>
<style scoped>
.ts_li >>> .el-dialog__body {
  padding: 0px !important;
}
.form-plan >>> .el-form-item__label {
  width: 100px !important;
}
.radius_dia >>> .el-dialog {
  border-radius: 20px !important;
}
</style>
<style lang="less" scoped>
@import "../../../styles/theme.less";
.pag_class {
  text-align: end;
}

.pag_class /deep/.el-input__inner {
  width: 100% !important;
}
.pag_class /deep/.el-pagination--small span:not([class*="suffix"]) {
  height: 22px;
  line-height: 28px !important;
}

.record-warp {
  width: 100%;
  height: 80vh;

  position: relative;

  .record-main {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    display: flex;
    flex-direction: column;

    .search-head {
      width: 100%;
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;

      .zc-title {
        color: #606266;
        font-size: 14px;
      }
    }

    .table-content {
      margin: 10px 0;
      flex: 1;
      overflow-y: auto;
    }
  }
}

.add_user_class {
  margin-top: 10px;
}

.user_out {
  display: flex;
  width: 100%;
  align-items: center;
  border: 1px solid #eeeeef;
  line-height: 50px;
  margin-top: 10px;
}

.user_out_sub {
  flex: 1;
  background-color: #fafafa;
  text-align: center;
  // color:#ffffff
}

.user_out_subNext {
  padding-left: 10px;
  flex: 3;
}
.detail_button_out {
  display: flex;
  justify-content: flex-start;
  .detail_button {
    margin-left: 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    letter-spacing: 2px;
    img {
      width: 15px;
      margin-right: 5px;
    }
    span {
      color: #00bf78;
      // font-weight: 600;
    }
  }
}

.detail_button_out_dis {
  display: flex;
  justify-content: flex-start;
  .detail_button_dis {
    margin-left: 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    letter-spacing: 2px;
    img {
      width: 15px;
      margin-right: 5px;
    }
    span {
      color: #d1d1d1;
      // font-weight: 600;
    }
  }
}

//弹出框样式

.dig_update /deep/.el-cascader {
  position: relative;
  font-size: 14px;
  line-height: 40px;
  width: 100%;
}
.dig_update /deep/.el-dialog {
  box-shadow: none !important;
  // background: transparent !important;
}
.demo-ruleForm /deep/ .el-form-item {
  margin-right: 10px;
  vertical-align: top;
  display: flex !important;
  flex-direction: column;
}
.demo-ruleForm /deep/.el-dialog__header {
  background-color: #ffffff;
  padding-left: 140px !important;
}
.demo-ruleForm /deep/.el-form-item__label {
  text-align: left;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.demo-ruleForm /deep/.el-input {
  width: 100% !important;
}

.demo-ruleForm /deep/.el-input__inner {
  width: 100% !important;
  background-color: #f7f7f7;
  border: 0px;
}

.dig_button {
  margin-top: 40px;
  display: flex;
  width: 100%;
  justify-content: space-around;
}

.demo-ruleForm {
  background-color: #ffffff;
  // border-radius: 20px;
  margin-right: -10px;
  margin-top: -10px;
  padding-right: 100px;
  padding-left: 100px;
  border-radius: 20px;
  padding-top: 20px;
  padding-bottom: 20px;
  .dig_title {
    margin-bottom: 30px;
    text-align: center;
    font-weight: 700;
  }
}
</style>
