<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-12-19 15:23:58
 * @LastEditors: 纪泽龙 jizelong@qq.com
 * @LastEditTime: 2022-12-25 16:47:17
 * @FilePath: /danger-manage-web/src/views/educationPlanExam/textPaper/components/Lesson-table.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <el-table
      v-loading="loading"
      :data="nameList"
      height="305"
      @select="select"
      @select-all="all"
      ref="multipleTable"
    >
      <el-table-column type="selection"></el-table-column>
      <el-table-column label="负责人" align="center" prop="name">
      </el-table-column>
      <el-table-column
        label="手机号"
        align="center"
        prop="phone"
        :formatter="formatter"
      >
      </el-table-column>
      <el-table-column
        label="所属单位"
        align="center"
        prop="contractorName"
        :formatter="formatter"
      >
      </el-table-column>
    </el-table>
    <!-- <div> -->
    <el-pagination
      :layout="'prev, pager, next'"
      v-show="total > 0"
      :total="total"
      :current-page="queryParams.pageNum"
      :page-sizes="[queryParams.pageSize]"
      @current-change="currentChangeClick"
    />
    <!-- </div> -->
  </div>
</template>

<script>
import { listStaff } from "@/api/safetyManagement/staff";
import { listContractorPerson } from "@/api/contractor/contractorPerson";
export default {
  name: "",
  props: {
    selectNameList: {
      type: Array,
    },
  },
  created() {
    // this.listStaff();
  },
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractorId: null,
        name: null,
      },
      total: 0,
      nameList: [],
      loading: false,
    };
  },
  methods: {
    listStaff() {
      this.loading = true;
      listContractorPerson(this.queryParams).then((res) => {
        console.log('res',res)
        this.total = res.total;
        this.nameList = res.rows;
        this.$nextTick((item) => {
          this.selectNameList.forEach((item) => {
            this.toggleSelection(item.id, true);
          });
          this.loading = false;
        });
      });
    },
    // toggleSelection(rows) {
    //   if (rows) {
    //     rows.forEach((row) => {
    //       this.$refs.multipleTable.toggleRowSelection(row);
    //     });
    //   } else {
    //     this.$refs.multipleTable.clearSelection();
    //   }
    // },
    select(all, row) {
      this.$emit("selectOne", all, row);
    },
    all(all) {
      console.log(all);
      // true是全选,false是全清
      let allSelect = false;
      if (all.length == 0 || (all.length == 1 && [0] == undefined)) {
        allSelect = false;
      } else if (all.length > 1) {
        allSelect = true;
      }
      this.$emit("selectAll", this.nameList, allSelect);
    },
    // 切换选项
    toggleSelection(id, SeclctFlag = false) {
      const item = this.nameList.find((item) => {
        return item.id == id;
      });
      this.$refs.multipleTable.toggleRowSelection(item, SeclctFlag);
    },

    currentChangeClick(val) {
      this.queryParams.pageNum = val;
      this.listStaff();
    },
    formatter(row, column, cellValue, index) {
      // console.log(row, column, cellValue, index);
      if (!cellValue) return "-";
      else return cellValue;
    },
  },
};
</script>
<style lang="scss" scoped>
</style>