<!--
  @description: 供应商信息弹框
  @Modifier：sunxinman
  @routerPath:
  @date: 2020-1-7 20:39:17
-->
<template>
  <el-dialog
    :visible.sync="dialogTableVisible"
    :close-on-click-modal="false"
    :lock-scroll="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="supplierNo"
        >
          <el-input
            v-model.trim="searchForm.supplierNo"
            placeholder="供应商编号"
            style="width: 220px"
          />
        </el-form-item>
        <el-form-item
          label="供应商名称"
          prop="supplierName"
        >
          <el-input
            v-model.trim="searchForm.supplierName"
            placeholder="供应商名称"
            style="width: 220px"
          />
        </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="supplierInfoTable"
        v-loading="loading"
        :row-key="getRowKeys"
        :data="agencyData"
        size="mini"
        @selection-change="handleParameterCurrentChange"
      >
        <el-table-column
          :reserve-selection="true"
          type="selection"
        />
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="60"
        />
        <el-table-column
          label="供应商编号"
          prop="supplierNo"
          align="center"
          width="200"
        />
        <el-table-column
          label="供应商名称"
          prop="supplierName"
        />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialogTableVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getQualificationListByLogicsIds } from '@/api/bidding/bidCalibration'
import pagination from '@comp/common/pagination/pagination'
import { filterObj } from '@/assets/js/utils'
import { ListMixin } from '@/mixins/ListMixin'
export default {
  name: 'SubsidiaryOrganDialog',
  components: {
    pagination
  },
  mixins: [ListMixin],
  data() {
    return {
      loading: true,
      // 获取row的key值
      getRowKeys(row) {
        return row.id
      },
      dialogTableVisible: false, // 弹框是否打开
      // 查询参数
      searchForm: {
        purcatalogCateoryCode: '', // 物料编码
        supplierNo: '', // 供应商编码
        supplierName: '' // 供应商名称
      },
      agencyCurrentRow: [], // 已选供应商列表
      agencyData: [] // 渲染代理机构弹框表格
    }
  },
  methods: {
    // 点击选择所属机构
    handleParameterCurrentChange(val) {
      /* 转换为要存储字段*/
      val.map((item) => {
        item.registeredCapital = item.regcapital // 注册资本金
        item.legalRepresentative = item.corporation // 法定代表人
        item.registeredAddress = item.areaValue // 注册地址
        item.enterpriseNature = item.entPrpt // 企业性质
      })
      this.agencyCurrentRow = val
    },
    // 打开弹框获取数据
    showBuyersDialog(ids, biddingMaterialGroupId) {
      this.searchForm.purcatalogCateoryCode = biddingMaterialGroupId // 物料编码
      this.searchForm.supplierNo = '' // 打开弹框清空
      this.searchForm.supplierName = '' // 打开弹框清空
      this.searchForm.ids = ids
      this.dialogTableVisible = true
      if (this.agencyCurrentRow.length > 0) {
        this.$refs.supplierInfoTable.clearSelection()// 取消勾选
      }
      // 加载数据
      this.loadData()
    },
    // 选择所属机构列表弹框获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      getQualificationListByLogicsIds(params).then(response => {
        this.loading = false
        this.agencyData = response.data.results
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 选择所属机构重置
    resetForm() {
      this.paginationData.page = 1
      this.paginationData.pageSize = 10
      this.searchForm.supplierNo = '' // 打开弹框清空
      this.searchForm.supplierName = '' // 打开弹框清空
      this.loadData()
    },
    // 选择所属机构 搜索
    search() {
      this.paginationData.page = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 所属机构信息确定按钮
    ensure() {
      if (this.agencyCurrentRow.length > 0) {
        this.$emit('buyersInfo', this.agencyCurrentRow)
        this.dialogTableVisible = false
      } else {
        this.$message({
          message: '必须选中一条记录',
          type: 'warning'
        })
      }
    }
  }
}
</script>

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