<!--
  @description: 采购员选择供应商弹框
  @Modifier：ysg
  @date2020-09-22- 11:20
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    :lock-scroll="false"
    title="选择供应商"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--选择供应商-->
    <div>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        class="tableLimit pointer"
        @selection-change="handleSelectionChange"
      >
        <el-table-column v-if="dialogData.type!=='invite'" type="selection" width="55px" />
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="60"
        />
        <el-table-column
          prop="supplierName"
          label="供应商名称"
          align="center"
          width="160"
        />
        <el-table-column
          prop="linker"
          label="联系人"
          header-align="center"
          align="center"
          min-width="110"
        />
        <el-table-column
          prop="linkerTel"
          label="联系电话"
          min-width="150"
          header-align="center"
          align="center"
        />
        <el-table-column
          v-if="dialogData.type==='invite'"
          prop="isInvitationMeetRoom"
          label="邀请状态"
          width="125"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(isInvitationMeetRoom, scope.row.isInvitationMeetRoom) }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="dialogData.type==='invite'"
          prop="isInvitationMeetRoom"
          label="操作"
          width="110"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-link
              v-if="scope.row.isInvitationMeetRoom==='00' || scope.row.isInvitationMeetRoom==='02' "
              :underline="false"
              size="mini"
              type="primary"
              @click="invite(scope.row,'01')"
            >
              [发起邀请]
            </el-link>
            <el-link
              v-if="scope.row.isInvitationMeetRoom==='01'"
              :underline="false"
              size="mini"
              type="primary"
              @click="invite(scope.row,'02')"
            >
              [取消邀请]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <span v-if="dialogData.type!=='invite'" slot="footer" class="dialog-footer">
      <el-button type="primary" @click="signatureConfirm">确 定</el-button>
      <el-button @click="dialogData.dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* api接口*/
import { getRoomSupplierList, saveInvitationStatus } from '@/api/procurement/procurementOffer'
import {
  exchangeEvalReportToExpertOrSupplier
} from '@/api/procurement/procurementEvaluation'
/* 公共参数方法*/
import { ListMixin } from '@/mixins/ListMixin'
import { filterDictText } from '@assets/js/utils'// 常用方法
import { commonMxin } from '@/mixins/commonMxin'
/* 混合开发方法-参数字段*/
import { procurementSelectMixin } from './mixins/procurementSelectMixin' // 公共方法
export default {
  name: 'SelectSupplierDialog',
  mixins: [ListMixin, commonMxin, procurementSelectMixin],
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return
      }
    },
    multipleFileSelect: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      purchaserType: '00', // 00采购员  01采购执行人
      loading: false,
      date: '',
      tableData: [],
      implementPurchaseList: '', // 自行采购选中集合
      multipleSupplier: [] // 选择的table供应商
    }
  },
  watch: {
    'dialogData.dialog'(val) {
      // 打开弹框加载数据
      if (val) {
        // 根据项目信息选择的采购方式来动态改变数据
        this.loadData()
      }
    }
  },
  created() {
    // 查询字典
    // this.inCodes()
    // this.loadData()
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 加载数据
    loadData() {
      this.loading = true
      const params = { packId: this.dialogData.packId } // 查询条件
      getRoomSupplierList(params)
        .then(response => {
          this.loading = false
          this.tableData = response.data
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 发起邀请、取消邀请
    invite(row, val) {
      const params = { id: row.id, roomId: this.dialogData.dataId, isInvitationMeetRoom: val }
      saveInvitationStatus(params).then(res => {
        if (res.header.ret === '0') {
          this.loadData()
        }
      })
    },
    // table 选择事件
    handleSelectionChange(val) {
      this.multipleSupplier = val
    },
    // 确定供应商按钮
    signatureConfirm() {
      const tempList = []
      // 文件id 以数组传递
      this.multipleFileSelect.forEach(item => {
        tempList.push(item.id)
      })
      var temStr = tempList.join(',')
      const supplierList = []
      this.multipleSupplier.forEach(item => {
        supplierList.push({
          linker: item.linker,
          linkerTel: item.linkerTel,
          supplierId: item.supplierId,
          supplierName: item.supplierName
        })
      })
      const params = { packId: this.dialogData.packId, reportIds: temStr, taskNo: this.dialogData.taskNo,
        suppliers: supplierList }
      exchangeEvalReportToExpertOrSupplier(params).then(res => {
        if (res.header.ret === '0') {
          this.loadData()
          this.dialogData.dialog = false// 关闭弹窗
          this.$message({
            message: res.header.msg,
            type: 'success'
          })
          this.$emit('uplaodData', 'up')
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
</style>
