  <!--
  @description: 选择供应商弹框
  @Modifier: qink
  @routerPath:procurement/procurementProject/procurementProject
  @date: 2020-2-25 13:20:35
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.consignContractVisible"
    :close-on-click-modal="false"
    title="选择供应商弹框"
    width="700px"
    custom-class="el-dialog__body-p0"
    top="calc((100vh - 611px) / 2)"
  >
    <section class="tools p0-16 pt16 clearfix">
      <p style="margin-bottom:10px;border-bottom:2px solid blue;width:62px;">
        查询条件
      </p>
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="供应商" prop="supplierName">
          <el-input
            v-model="searchForm.supplierName"
            placeholder=""
          />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="businesslicence">
          <el-input
            v-model="searchForm.businesslicence"
            placeholder=""
          />
        </el-form-item>
        <el-form-item class="fr">
          <!-- 查询 -->
          <el-button
            type="primary"
            icon="iconfont icon-search"
            @click="search('searchForm')"
          >
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </section>
    <section style="margin-bottom:20px;padding:0 15px;margin-top:10px;">
      <p style="margin-bottom:10px;border-bottom:2px solid blue;width:62px;">
        查询结果
      </p>
      <el-table
        ref="multipleTable"
        :row-key="getRowKey"
        :data="list"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="currentChange"
      >
        <el-table-column
          type="selection"
          width="50"
        />
        <el-table-column
          type="index"
          label="序号"
          width="50"
        />
        <el-table-column
          prop="supplierName"
          label="供应商"
        />
        <el-table-column
          prop="businesslicence"
          label="统一社会信用代码"
          min-width="110"
          align="left"
        />
        <el-table-column
          prop="linkerName"
          label="联系人"
        />
        <el-table-column
          prop="linkerTel"
          label="联系方式"
        />
      </el-table>
    </section>
    <pagination :pagination-data="paginationData" @change="loadData" />
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">{{ language.Determine }}</el-button>
      <el-button @click="dialogData.consignContractVisible = false">{{ language.cancel }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { getDeclarationByCommonQuerySupplier } from '@/api/procurement/commonSupplier'// 获取供应信息
/* 公用方法*/
// import { filterObj } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import { mapGetters } from 'vuex'
export default {
  name: 'ConsignContractSelectDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {

      }
    }
  },
  data() {
    return {
      title: '项目类型',
      paginationData: {},
      // 搜索信息
      searchForm: {
        businesslicence: '', // 统一社会信用代码
        departId: '', // 审核单位id
        supplierName: '', // 供应商名称
        excludeSupplierIds: ''
      },
      list: [], // 列表数据
      currentData: []// 当前选择的信息
    }
  },
  computed: {
    ...mapGetters(['language'])
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.consignContractVisible'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 指定一个key标识这一行的数据
    getRowKey(row) {
      return row.id
    },
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getDeclarationByCommonQuerySupplier(params).then(response => {
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getParams() {
      this.searchForm.departId = this.dialogData.departId
      this.searchForm.excludeSupplierIds = this.dialogData.excludeSupplierIds
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      // return filterObj(param)// 过滤空的key
      return param
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData) {
        this.$emit('consignContractInfo', this.currentData)
        this.dialogData.consignContractVisible = false
      } else {
        this.$message({
          message: `请选择${this.title}`,
          type: 'warning'
        })
      }
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
