  <!--
  @description: 采购单-选择关联订单订单弹窗
  @Modifier: 王俊楠
  @routerPath:
  @date: 2021-2-3 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="orderName"
          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>
/* api接口*/
import { listCommonSupplierProcurementOrderPages } from '@/api/procurement/procurementContract'
/* 公用方法*/
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: 'ProcurementOrderDialog',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: () => {
        return {
          departid: '' // 供应商主键id,
        }
      }
    }
  },
  data() {
    return {
      list: [], // 列表数据
      currentData: [], // 当前选择的信息
      searchForm: {
        orderName: '', // 订单名称
        winningDepartId: '' // 供应商主键id,
      }
    }
  },
  computed: {
    ...mapGetters(['language'])
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      listCommonSupplierProcurementOrderPages(params).then(response => {
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getParams() {
      this.searchForm.winningDepartId = this.dialogData.departid // 供应商id
      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('callBack', 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>
