<!--
  @description:沿用投标人弹框
  @Modifier: haofengxian
  @routerPath:
  @date: 2020-5-18-9:28
-->
<template>
  <div>
    <el-dialog
      v-dialogDrag
      :visible.sync="supplierSelectVisible"
      :close-on-click-modal="false"
      title="选择供应商"
      width="840px"
      custom-class="el-dialog__body-p8 el-dialog_table"
    >
      <!--搜索-->
      <section class="clearfix">
        <el-form ref="searchForm" :model="searchForm" inline>
          <el-form-item label="供应商名称" prop="departName">
            <el-input
              v-model="searchForm.departName"
              placeholder="供应商名称"
            />
          </el-form-item>
          <el-form-item class="fr">
            <el-button
              type="primary"
              @click="search('searchForm')"
            >
              搜 索
            </el-button>
            <el-button
              plain
              type="info"
              @click="resetForm('searchForm')"
            >
              重 置
            </el-button>
          </el-form-item>
        </el-form>
      </section>
      <!--查询列表-->
      <section>
        <el-table
          ref="multipleTable"
          :data="supplierList"
          size="mini"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
          />
          <el-table-column
            type="index"
            label="序号"
            width="60"
            align="center"
          />
          <el-table-column
            prop="supplierName"
            label="供应商名称"
          />
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitClick">
          确 定
        </el-button>
        <el-button @click="cancelClick">
          取 消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
/* 接口*/
import { getContinueToUseSupplier } from '@api/bidding/rebiddingRecord'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'FollowBidderDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  data() {
    return {
      supplierSelectVisible: false, // 弹框
      searchForm: {
        supplierIds: '', // 已选择供应商(逗号隔开)
        stageId: '' // 阶段id
      },
      packIndex: '', // 沿用投标人标段下标
      selectSupplierListData: [], // 已选供应商列表
      supplierList: [] // 供应商列表
    }
  },
  methods: {
    openDialog(row) {
      this.searchForm.stageId = row.stageId // 阶段id
      this.packIndex = row.packIndex
      this.supplierSelectVisible = true// 弹框展示状态
      this.searchForm.supplierIds = row.supplierIds// 去重供应商Id
      this.loadData()
    },
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      getContinueToUseSupplier(params).then(response => {
        this.paginationData.total = response.data.total
        this.supplierList = response.data.records
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 选择供应商
    handleSelectionChange(val) {
      this.selectSupplierListData = val
    },
    // 判断是否选择投标人
    submitClick() {
      if (this.selectSupplierListData.length > 0) {
        // 传给父组件已选中的供应商列表 packIndex 标段下标
        this.$emit('supplierSelect', this.selectSupplierListData, this.packIndex, '01')
        this.supplierSelectVisible = false
      } else {
        this.$message({
          message: '请选择投标人',
          type: 'warning'
        })
      }
    },
    // 取消邀请
    cancelClick() {
      this.supplierSelectVisible = false // 关闭弹框
      this.selectSupplierListData = [] // 已选供应商列表
      this.$refs.multipleTable.clearSelection()
    },
    // 搜索重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped>

</style>
