  <!--
  @description: 选择供应商弹框
  @Modifier: qink
  @routerPath:procurement/procurementProject/procurementProject
  @date: 2020-2-25 13:20:35
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    title="选择供应商弹框"
    width="700px"
    custom-class="el-dialog__body-p0"
    top="calc((100vh - 611px) / 2)"
  >
    <section style="margin-bottom:20px;padding:0 15px;margin-top:10px;">
      <el-table
        ref="multipleTable"
        :data="list"
        tooltip-effect="dark"
        :row-class-name="tableRowClassName"
        :row-style="selectedHighlight"
        style="width: 100%"
        highlight-current-row
        @row-click="rowClick"
      >
        <el-table-column
          type="index"
          label="序号"
          width="50"
        />
        <el-table-column
          prop="supplyDepartName"
          label="供应商"
        />
        <el-table-column
          prop="supplyUnified"
          label="统一社会信用代码"
          min-width="110"
          align="left"
        />
      </el-table>
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">{{ language.Determine }}</el-button>
      <el-button @click="dialogData.dialog = false">{{ language.cancel }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
// import { bidSelectWinnerSupplierInfo } from '@/api/bidding/bidCalibration'// 获取供应信息
import { selectWinnerSupplierInfo } from '@/api/procurement/procurementResult'// 获取供应信息

/* 公用方法*/
// import { filterObj } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
/* 组件*/
import { mapGetters } from 'vuex'
export default {
  name: 'ContractBuyerUnitDialog',
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {

      }
    },
    contractSource: { // 合同来源00采购01招标
      type: String,
      default: ''
    }
  },
  data() {
    return {
      list: [], // 列表数据
      currentData: []// 当前选择的信息
    }
  },
  computed: {
    ...mapGetters(['language'])
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    rowClick(val) {
      this.currentData = val
    },
    // 给选中的一行添加样式
    tableRowClassName({ row, rowIndex }) {
      if (this.getIndex === rowIndex) {
        return 'procurement_pith_on'
      }
    },
    // 获取表格内每一行下标
    selectedHighlight({ row, rowIndex }) {
      row.index = rowIndex
    },
    // 加载数据
    loadData() {
      const params = {
        tenderId: this.dialogData.tenderId,
        selectedSupplierId: this.dialogData.selectedSupplierId
      }
      if (this.contractSource === '01') {
        params.packId = this.dialogData.packId
        // 招标
        /*      bidSelectWinnerSupplierInfo(params).then(response => {
          this.list = response.data
        }).catch(() => {

        })*/
      } else if (this.contractSource === '00') {
        // 采购
        selectWinnerSupplierInfo(params).then(response => {
          this.list = response.data
        }).catch(() => {

        })
      }
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData) {
        this.$emit('callBack', this.currentData)
        this.dialogData.dialog = false
      } else {
        this.$message({
          message: '请选择',
          type: 'warning'
        })
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
