  <!--
  @description: 选择供应商
  @Modifier: qink/haofengxian
  @routerPath:
  @date: 2020-4-8 13:20:35
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    title="选择供应商"
    width="840px"
    append-to-body
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <section class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item prop="supplierName" label="供应商名称">
          <el-input v-model="searchForm.supplierName" />
        </el-form-item>
        <el-form-item class="fr">
          <el-button type="primary" @click="search">
            查询
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </section>
    <section>
      <el-table
        ref="singleTable"
        :data="list"
        class="pointer"
        highlight-current-row
        size="mini"
        @current-change="currentChange"
      >
        <el-table-column
          type="index"
          label="序号"
          width="50"
          align="center"
        />
        <el-table-column
          prop="supplierName"
          label="供应商名称"
        />
      </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.dialog = false">{{ language.cancel }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { listSupplierRepositoryPagesByAll } from '@/api/supplier/declaraTionrecord'
/* 公用方法*/
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: 'SupplierListDialog',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {}
    }
  },
  data() {
    return {
      list: [], // 列表数据
      currentData: [], // 当前选择的信息
      searchForm: {
        supplierName: '', // 供应商名称
        selectType: '00' // 通用选择表示供应商选择
      }
    }
  },
  computed: {
    ...mapGetters(['language'])
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      listSupplierRepositoryPagesByAll(params).then(response => {
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (JSON.stringify(this.currentData) !== '{}') {
        this.$emit('call-back', this.currentData)
        this.dialogData.dialog = false
      } else {
        this.$message({
          message: '请选择供应商',
          type: 'warning'
        })
      }
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
