<template>
  <!-- 账号禁用审核 -->
  <div class="recheck-wrapper height100">
    <div class="search-container">
      <el-form :inline="true" :model="form">
        <el-form-item>
          <el-input
            v-model="form.name"
            placeholder="请输入账号名称或提交人"
            suffix-icon="el-icon-search"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="form.status"
            placeholder="请选择账号状态"
            clearable
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <div class="btn-group">
            <el-button type="primary" @click="handleSubmit">查询</el-button>
            <el-button @click="handleReset">重置</el-button>
          </div>
        </el-form-item>
      </el-form>
      <div class="page-tip">
        <span class="page-tip-title">页面说明:</span>
        <span class="page-tips"
          >展示所有禁用账号的申请，审核通过后，该账号状态为禁用，无法在系统中使用</span
        >
      </div>
    </div>
    <div class="table-content">
      <check-table
        class="noAdd"
        :feildList="feildList"
        :list="list"
        @action="handleAction"
        :currentPage="page._index"
      />
      <party-pagination :page="page" @changePage="handleChangeCurrent" />
    </div>
    <reject-dialog ref="rejectDialog" @success="getPageList()" />
  </div>
</template>
<script>
import { partyPagination } from "@/components/index";
import checkTable from "./components/checkTable";
import { rejectDialog } from "./checkDialog/index";
import { loginOut } from "@/config/loginOut";
export default {
  data() {
    return {
      form: {
        name: "",
        status: "",
      },
      options: [
        { label: "待初审", value: "TBC" },
        { label: "驳回", value: "REFUSED" },
        { label: "待复审", value: "TBCA" },
        { label: "通过", value: "APPROVED_FINAL" },
      ],
      feildList: [
        { prop: "content", label: "账号名称" },
        { prop: "orgName", label: "所在机构" },
        { prop: "userName", label: "提交人" },
        { prop: "createTime", label: "提交日期" },
        { prop: "status", label: "审核状态" },
        { prop: "", label: "操作", isEdit: true, width: 240 },
      ],
      list: [],
      activeRow: {},
      page: {
        _index: 1,
        _size: 10,
        total: 0,
      },
      type: "ACCOUNT",
      passStatus: "APPROVED_FINAL",
      //待初审 TBC, 驳回 REFUSED, 待复审 TBCA, 通过APPROVED_FINAL
    };
  },
  components: { partyPagination, checkTable, rejectDialog },
  mounted() {
    this.getFirstPageList();
  },
  methods: {
    // 查询数据
    handleSubmit() {
      this.getPageList();
    },
    handleReset() {
      this.form.name = "";
      this.form.status = "";
      this.getFirstPageList();
    },

    // 获取第一页数据列表
    getFirstPageList() {
      this.page._index = 1;
      this.getPageList();
    },
    getPageList() {
      let requestParams = {};
      requestParams._index = this.page._index;
      requestParams._size = this.page._size;
      requestParams.name = this.form.name;
      requestParams.status = this.form.status;
      this.$https(
        {
          method: "get",
          url: "audit/getUserList",
          authType: this.backToken,
        },
        requestParams
      )
        .then((res) => {
          if (res.status != 200) {
            this.getResWithOutData();
          } else {
            if (res.data.resultCode == 200) {
              this.list = res.data.data.records;
              this.page._size = res.data.data.size;
              this.page.total = res.data.data.total;
            } else {
              this.getResWithOutData();
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 页面返回值为空
    getResWithOutData() {
      this.list = [];
      this.page = {
        _index: 1,
        _size: 10,
        total: 0,
      };
    },
    handleAction(params) {
      this.activeRow = params.row;
      switch (params.type) {
        case "reject":
          this.handleRject();
          break;
        case "pass":
          this.handlePass();
          break;
        default:
          break;
      }
    },
    // 驳回
    handleRject() {
      this.$refs.rejectDialog.activeRow = this.activeRow;
      this.$refs.rejectDialog.dialogVisible = true;
    },
    // 通过
    handlePass() {
      let params = {};
      let _this = this;
      params.id = this.activeRow.id;
      params.status = this.passStatus;
      params.type = this.type;
      params.refItemId = this.activeRow.refItemId;
      params.level = this.activeRow.status;

      this.$https(
        {
          method: "put",
          url: "audit/update",
          authType: this.backToken,
        },
        params
      )
        .then((res) => {
          if (res.status == 200) {
            if (res.data.resultCode == 200) {
              this.$message({
                type: "success",
                message: res.data.message,
              });
               debugger;
              if (_this.activeRow.status === "TBCA") {
                _this.$message({
                  message: "5s之后该账号退出登录",
                  type: "warning",
                });
                setTimeout(() => {
                  _this.logoutUser(params.refItemId);
                }, 5000);
              }
              this.getPageList();
             
            } else {
              this.$message.error(res.data.message);
            }
          } else {
            this.$message.error(res.data);
          }
        })
        .catch((err) => {
          console.log(res);
        });
    },
    // 复审通过之后 调用退出
    logoutUser(id) {
      let _this = this;
      _this.$https({
        method: "get",
        url: `logoutUser?id=${id}`,
        authType: this.backToken,
      });
    },
    // 翻页
    handleChangeCurrent(val) {
      this.page._index = val;
      this.getPageList();
    },
  },
};
</script>
<style lang="less" scoped>
</style>