<template>
  <basic-container>
    <el-drawer
      title="比对人才库"
      append-to-body
      :visible.sync="drawer"
      size="65%"
      class="drawer"
    >
      <avue-crud
        :option="personListOption"
        :table-loading="loading"
        :data="data"
        :page.sync="page"
        ref="crud"
        :permission="permissionList"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        class="customPage"
        
      >
        <!--/自定义按钮-->
      </avue-crud>
      <!-- <Resume ref="resume"></Resume> -->
      <div style="float:right;font-size:18px;">
        <el-button type="primary" size="small" @click="submitContrastBtn()">提交比对</el-button>
        <el-button size="small" @click="resetBtn">重置</el-button>
      </div>
    </el-drawer>
     <NoEmployed ref="noEmployed" v-show="false"></NoEmployed>
  </basic-container>
</template>

<script>
import {personCountList} from "@/api/tenant/postzp";
import { mapGetters } from "vuex";
import NoEmployed from "../Dialog/noEmployed"
export default {
  data () {
    return {
      isIndeterminate: false,
      checkAll: false,
      checked: false,
      missionId: "",
      missionTitle: "",
      stime: "",
      drawer: false,
      selectionList: [],
      loading: false,
      query: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      personListOption: {
        dialogWidth: "50%",
        align: "center",
        menuAlign: "center",
        rowKey: "id",
        tip: false,
        menu: false,
        addBtn: false,
        columnBtn: false,
        searchBtn: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchLabelWidth: 45,
        menuPosition: "center",
        labelPosition: "right",
        border: true,
        index: true,
        indexLabel: "序号",
        selection: true,
        viewBtn: false,
        dialogType: "dialog",
        dialogClickModal: false,
        column: [
          {
            label: "分组名称",
            prop: "groupName",
            search: false,
            span: 24,
          },
          {
            label: "人数",
            prop: "sumNum",
            search: false,
            span: 24,
          },
        ],
      },
      excelBox: false,
      data: [],
    };
  },
  components: {
    // Resume,
    NoEmployed
  },
  watch: {
    
  },
  computed: {
    ...mapGetters(["userInfo", "permission"]),
    ids () {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    //提交对比
    submitContrastBtn(){
      if(this.selectionList.length > 0){
        this.$refs.noEmployed.openDialog(this.missionId,this.ids);
      }else{
        this.$message({
            type: "error",
            message: "请选择要比对的人才库!",
          });
      }
      
    },
    //重置
    resetBtn(){
      this.onLoad();
    },
    /*打开drawer*/
    openDialog (row) {
      this.missionId = row.missionNo;
      this.missionTitle = row.missionTitle;
      this.stime = row.stime;
      if (this.$refs.crud) {
        this.$refs.crud.searchReset();
      } else {
        this.query = {};
        this.onLoad();
      }
      this.drawer = true;
    },
    searchReset () {
      this.query = {};
      this.onLoad();
    },
    searchChange (params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad();
      done();
    },
    selectionChange (list) {
      this.selectionList = list;
    },
    selectionClear () {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange (currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad();
    },
    sizeChange (pageSize) {
      this.page.currentPage = 1;
      this.page.pageSize = pageSize;
      this.onLoad();
    },
    refreshChange () {
      this.onLoad();
    },
    onLoad () {
      this.loading = true;
      personCountList().then((res) => {
        const data = res.data.data;
        this.data = data;
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>