<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>
        <el-table
          :border="true"
          stripe
          fit
          size="mini"
          :max-height="tableMaxHeight"
          ref="multipleSelection"
          :data="tableData"
          :row-key="rowKey"
          v-loading="loading"
          @selection-change="handleSelectionChange"
          @row-dblclick="handleDetail"
        >
          <el-table-column type="selection" min-width="20%" align="center">
          </el-table-column>
          <el-table-column
            prop="qualificationCode"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="资质编码"
            resizable
          >
          </el-table-column>
          <el-table-column
            prop="qualificationName"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="资质名称"
            resizable
          >
          </el-table-column>

          <el-table-column
            prop="qualificationTypeName"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="资质类别名称"
            resizable
          >
          </el-table-column>
          <el-table-column
            prop="qualificationForm"
            min-width="10%"
            label="资质来源"
            align="center"
            resizable
          >
            <template slot-scope="scope">
              <div>
                <span v-if="scope.row.qualificationForm == 1">企业</span>
                <span v-if="scope.row.qualificationForm == 2">专家</span>
                <span v-if="scope.row.qualificationForm == 3">个人</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="qualificationAcquisitionDate"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="取得日期"
            resizable
          >
          </el-table-column>
          <el-table-column
            prop="expiryDate"
            show-overflow-tooltip
            min-width="10%"
            align="center"
            label="有效截止期"
            resizable
          >
          </el-table-column>
        </el-table>
        <div style="float:right;margin-top:10px">
          <el-pagination
            ref="paginationPanel"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryParam.pageBean.page"
            :page-sizes="[20, 30, 40, 50]"
            :page-size="queryParam.pageBean.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="queryParam.pageBean.total"
          >
          </el-pagination>
        </div>
      </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 basicData from '@/api/basicData'
import procurementManagement from '@/api/procurementManagement'
export default {
  name: 'CmgtSaftyDangerCheckplanFormDialogTroubleshooting', // 排查计划明细
  props: {
    qualificationList: Array
  },
  mixins: [TableMixin],
  data() {
    return {
      showTroubleshooting: false, // 控制弹层显示与隐藏
      multipleSelection: [],
      selectedValue: [],
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'preparedOrgName',
          relation: 'AND',
          value: ''
        }
      ],
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        }
      },
      loading: false
    }
  },
  mixins: [TableMixin],
  created() {
    this.getData()
  },
  methods: {
    rowKey(row) {
      return row.id
    },
    //搜索
    handleSearch() {
      this.getData()
    },
    //重置
    handleReset() {
      this.querys[0].value = ''
      this.getData()
    },
    loadData() {},
    //显示弹框
    add() {
      this.showTroubleshooting = true
      this.qualificationList.forEach(item => {
        let that = this
        this.$nextTick(() => {
          that.tableData.forEach(data => {
            if (data.id == item.id) {
              that.$refs.multipleSelection.toggleRowSelection(data, true) //这样就可以了
            }
          })
        })
      })
      
    },
    // 获取list
    getData() {
      this.loading = true
      this.tableData = []
      this.queryParam.querys = []
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }
      basicData.bizQualificationLabelQuery(this.queryParam).then(res => {
        this.queryParam.pageBean.total = res.value.total
        this.tableData = res.value.rows
        this.loading = false
      })
    },
    tableSelect(rows, row) {
      let selected = rows.length && rows.indexOf(row) !== -1
      if (!selected) {
        this.selectedValue = rows
      } else {
        this.selectedValue = []
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 点击关闭按钮
    handleClose() {
      this.$refs.multipleSelection.clearSelection()
      this.showTroubleshooting = false
    },
    // 保存按钮
    handleSave() {
      let list = []
      list = this.multipleSelection
      this.$emit('refundData', list)
      this.handleClose()
    },
    handleCurrentChange(page) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, page}
      this.getData()
    },
    handleSizeChange(pageSize) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
      this.getData()
    }
  }
}
</script>

<style scoped lang="scss">
.dialog-footer {
  width: 100%;
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
</style>
