<template>
  <div class="fullHeight">
    <el-form :inline="true" size="medium" :model="searchForm" ref="searchForm">
      <el-form-item label="" prop="enterpriseId">
        <el-select
          v-model="searchForm.enterpriseId"
          :placeholder="$t('message.laborDev.allCompany')"
          filterable
          clearable @change="getTeamList"
        >
          <el-option
            :label="item.enterpriseName"
            :value="item.id"
            v-for="(item, index) in enterpriseListData"
            :key="index"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="teamId">
        <el-select
          v-model="searchForm.teamId"
          :placeholder="$t('message.laborDev.allGroup')"
          filterable
          clearable
        >
          <el-option
            :label="item.teamName"
            :value="item.id"
            v-for="(item, index) in teamListData"
            :key="index"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="workerName">
            <el-input v-model="searchForm.workerName" :placeholder="$t('message.laborDev.searchWorker')" clearable></el-input>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" plain @click="getTableData">
          {{ $t("message.personnelPosition.beaconManage.query") }}
        </el-button>
      </el-form-item>
    </el-form>
    <el-table
      ref="multipleTable"
      class="tables"
      :data="tableListData"
      tooltip-effect="dark"
      style="width: 100%;"
      height="600"
      @selection-change="handleSelectionChange" :empty-text="'请选择条件进行查询'"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column :label="$t('message.laborMange.compellation')">
        <template slot-scope="scope">{{ scope.row.workerName }}</template>
      </el-table-column>
      <el-table-column prop="sex" :label="$t('message.laborMange.sex')">
          <template slot-scope="scope">{{ scope.row.sex==1?$t('message.laborMange.man'):$t('message.laborMange.female') }}</template>
        </el-table-column>
      <el-table-column prop="idCard" :label="$t('message.laborMange.IdNumber')">
      </el-table-column>
      <el-table-column prop="teamName" :label="$t('message.laborMange.team')">
      </el-table-column>
      <el-table-column prop="age" :label="$t('message.laborMange.age')">
      </el-table-column>
      <!-- <el-table-column prop="address" :label="$t('message.laborMange.companies')">
      </el-table-column> -->

    </el-table>
    <div class="dialog-footer">
        <el-button
                class="cancleBtn"
                @click="closeFn"
                icon="el-icon-circle-close"
                size="medium"
        >{{$t('message.personnelPosition.cancel')}}
        </el-button>
        <el-button
                type="primary"
                icon="el-icon-circle-check"
                @click="submitData"
                size="medium"
        >{{$t('message.laborDev.add2')}}({{multipleSelection.length}})
        </el-button>
    </div>
  </div>
</template>
<script>
import {
  getEnterpriseInfoList,
  getWorkerInfoList,getTeamInfoList
} from "@/assets/js/api/laborPerson";
export default {
    // props:['personType','selectWorkerDialog'],
    props:{
      personType:Number,
      selectWorkerDialog:Boolean,

    },
  data() {
    return {
      enterpriseListData: [],
      searchForm: {
        personType: 1,
        workerName: "",
        teamId: "",
        pageNo: 1,
        pageSize: 2000,
        enterpriseId: "",
        projectSn: this.$store.state.projectSn
      },
      tableListData: [],
      multipleSelection: [],
      teamListData: [],
      projectSn: "",
    };
  },
  mounted() {
    this.searchForm.personType = this.personType
    this.searchForm.personType = ''
    this.projectSn = this.$store.state.projectSn;
    this.getProjectList();
    this.getTeamList();
    this.getTableData()
  },
  methods: {
    //获取企业 || 劳务公司 列表
    getProjectList() {
      let data = {
        projectSn: this.projectSn,
        enterpriseName: "",
      };
      getEnterpriseInfoList(data).then((res) => {
        this.enterpriseListData = res.result;
      });
    },
    getTableData() {
      getWorkerInfoList(this.searchForm).then((res) => {
          this.multipleSelection=[]
        this.tableListData = res.result.records;
      });
    },
    //获取企业的 - 班组列表
    getTeamList() {
      let data = {
        enterpriseId: this.searchForm.enterpriseId,
        projectSn: this.projectSn,
      };
      getTeamInfoList(data).then((res) => {
        this.teamListData = res.result.list;
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    closeFn(){
        this.$emit('close',false)
    },
    submitData(){
        this.$emit('getData',this.multipleSelection)
        this.multipleSelection=[]
        this.tableListData = []
        console.log('selectWorkerDialog',this.selectWorkerDialog)
         this.$emit('close',false)
    },
  },
};
</script>

