<!-- 同行人展示列表 -->
<template>
  <el-dialog title="供应商列表" :visible.sync="dialogVisible" width="800px" :before-close="handleCancel">
    <el-table v-loading="loading" style="max-height:50vh" stripe border :data="tableList" width="100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" :selectable="(row) => row.selectable"></el-table-column>
      <el-table-column label="企业名称" align="center" prop="companyAme" />
      <el-table-column label="供应商编码" align="center" prop="companyNumber" />
      <el-table-column label="企业性质" align="center" prop="companyType">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.BS_ENTERPRISEL_TYPE" :value="scope.row.companyType" />
        </template>
      </el-table-column>
      <el-table-column label="法人代表" align="center" prop="legalPerson" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="统一社会信用代码" align="center" prop="creditCode" />
      <el-table-column label="银行户名" align="center" prop="bankName" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :autoScroll="false" :total="total" :page.sync="queryParams.pageNo" :pageSizes="[1000,2000]" :limit.sync="queryParams.pageSize" @pagination="getList" />
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getSupplierCompanyPage } from "@/api/procurement/supplierMsg";
export default {
  name: '',
  props: {
    isOpen: Boolean,
    userList: Array,
    selectIds: Array
  },
  data() {
    return {
      dialogVisible: false,
      loading: false,
      tableList: [],
      selectArr: [],
      total: 0,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10000,
      },
    }
  },
  watch: {
    isOpen: {
      handler(val) {
        this.dialogVisible = val
        if (val) {
          this.handleInit()
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    handleSelectionChange(arr) {
      this.selectArr = arr
    },
    getList() {
      this.loading = true;
      // 执行查询
      getSupplierCompanyPage(this.queryParams).then(response => {
        this.tableList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
        this.tableList = (response.data.list || []).map(item => {
          if (this.selectIds.includes(item.id)) {
            return {
              ...item,
              selectable: false
            }
          } else {
            return {
              ...item,
              selectable: true
            }
          }
        })
      });
    },
    handleCancel() {
      this.$emit('onCancel')
    },
    handleConfirm() {
      this.$emit('onConfirm', this.selectArr)
    },
    handleInit() {
      this.queryParams.pageNo = 1
      this.queryParams.pageSize = 1000
      this.getList()
    },
  }
}

</script>
<style lang='scss' scoped>
</style>