<!--
  @description: 添加保函-选择投标人弹框
  @Modifier: sunxinman
  @routerPath:
  @date: 2020/03/30-15:10
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.bidderVisible"
    :close-on-click-modal="false"
    :title="title"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--搜索-->
    <section class="pt16 clearfix">
      <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 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="singleTable"
        v-loading="loading"
        :data="list"
        class="pointer"
        size="mini"
        highlight-current-row
        @current-change="currentChange"
      >
        <el-table-column type="index" label="序号" align="center" width="80" />
        <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="dialogData.bidderVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

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

      }
    }
  },
  data() {
    return {
      loading: true,
      title: '选择投标人', // 标题
      packId: this.$route.params.packId, // 包组ID
      // 搜索信息
      searchForm: {
        payStatus: '00', // 支付状态00未支付01已支付02待退款
        supplierName: '', // 供应商名称
        accountNo: '', // 虚拟账户
        stageId: '', // 阶段ID
        supplierId: '', // 供应商id
        tenderId: '' // 项目id
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.bidderVisible'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      queryDepositAccountList(params).then(response => {
        this.list = response.data.records
        this.loading = false
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.packId = this.packId
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData.supplierName) {
        const data = {
          supplierName: this.currentData.supplierName,
          supplierId: this.currentData.supplierId
        }
        this.$emit('bidderInfo', data)
        this.dialogData.bidderVisible = false
      } else {
        this.$message({
          message: `请选择${this.title}`,
          type: 'warning'
        })
      }
    },
    // 搜索重置
    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 lang="less">

</style>
