<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      title="选择评标人员"
      :visible.sync="showTroubleshooting"
      width="60%"
      :close-on-press-escape="false"
      :before-close="handleClose"
      top="10vh"
    >
      <template>
        <div class="bbsl-table-search">
          <el-form v-model="queryParam" :inline="true">
            <el-form-item label="专家编号">
              <el-input
                size="small"
                v-model="querys[0].value"
                clearable
                placeholder="请输入专家编号"
              ></el-input>
            </el-form-item>
            <el-form-item label="专家名称">
              <el-input
                size="small"
                v-model="querys[1].value"
                clearable
                placeholder="请输入专家名称"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                size="small"
                type="danger"
                icon="el-icon-search"
                @click="handleSearch"
                >搜索</el-button
              >
              <el-button
                size="small"
                icon="el-icon-refresh"
                @click="handleReset"
                >重置</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <el-table
          ref="multipleSelection"
          v-loading="loading"
          size="mini"
          row-key="id"
          :data="tableData"
          :style="{width: '100%'}"
          :max-height="tableMaxHeight"
          :cell-style="{'text-align': 'center'}"
          :header-cell-style="{'text-align': 'center'}"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            :reserve-selection="true"
            type="selection"
            width="55"
          />
          <el-table-column
            prop="userNumber"
            min-width="10%"
            label="专家编号"
            align="center"
            resizable
          >
          </el-table-column>
          <el-table-column
            prop="fullname"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="专家名称"
            resizable
          >
          </el-table-column>
          <el-table-column
            prop="mobile"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="联系方式"
            resizable
          >
          </el-table-column>
        </el-table>
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSave">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {TableMixin} from '@/mixins/tableMixin'
// import nineLittlePlaceApi from '@/views/Manage/saftyDanger/api/nineLittlePlaceApi'
export default {
  name: 'CmgtSaftyDangerCheckplanFormDialogTroubleshooting', // 排查计划明细
  props: {
    bidOpening: {
      type: Array,
      default: '',
    },
  },
  data() {
    return {
      tableMaxHeight: 400,
      showTroubleshooting: false, // 控制弹层显示与隐藏
      tableData: [],
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'unit_name_',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'small_place_area_',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'type_',
          relation: 'AND',
          value: '',
        },
      ],
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
        },
      },
      sorter: [
        {
          direction: 'DESC',
          property: 'createTime',
        },
      ], // 排序数据
    }
  },
  mixins: [TableMixin],
  created() {},
  methods: {
    //搜索
    handleSearch() {
      // this.getData()
    },
    //重置
    handleReset() {
      // this.getData()
    },
    //显示弹框
    add() {
      this.showTroubleshooting = true
      this.getData()
      if (this.bidOpening.length !== 0) {
        this.$nextTick(() => {
          this.bidOpening.forEach((item) => {
            if (this.tableData.some((data) => data.idCard === item.idCard)) {
              this.$refs.multipleSelection.toggleRowSelection(item, true) //这样就可以了
            } else {
              this.$refs.multipleSelection.toggleRowSelection(item, true) //这样就可以了
            }
          })
        })
      }
    },
    // 获取list
    getData(page) {
      if (page) {
        this.queryParam.pageBean.page = page
      }
      // 不分页
      this.queryParam.pageBean.pageSize = -1
      this.loading = true
      this.tableData = []
      this.queryParam.querys = []
      this.queryParam.sorter = this.sorter
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }
      if (this.querys[1].value) {
        this.queryParam.querys.push(this.querys[1])
      }
      if (this.querys[2].value) {
        this.queryParam.querys.push(this.querys[2])
      }

      this.$http
        .post('${portal}/bizExpertDatabase/v1/query', this.queryParam)
        .then((res) => {
          console.log(res, 'resss')
          // this.total = res.data.value.total
          this.tableData = res.data.rows
          this.$set(this.tableData)
          this.loading = false
        })
    },
    // 重置
    clearQuerys() {
      this.querys[0].value = ''
      this.querys[1].value = ''
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 点击关闭按钮
    handleClose() {
      this.$refs.multipleSelection.clearSelection()
      this.showTroubleshooting = false
    },
    // 保存按钮
    handleSave() {
      let list = []
      list = this.multipleSelection
      if(list.length<3){
        this.$message.warning('请至少选择三位评标人')
        return
      }
      if(list.length % 2 ==0){
        this.$message.warning('请选择奇数位评标人')
        return
      }
      this.$emit('addDetail', list)
      this.handleClose()
    },
  },
}
</script>

<style scoped lang="scss">
/deep/.el-tabs__item:nth-of-type(n + 3):after {
  height: 0;
}
</style>
