<!--
  @description: 项目信息-选择委托合同
  @Modifier: haoFx/肖文龙
  @routerPath:
  @date: 2019-12-17 20:14:35
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.consignContractVisible"
    :close-on-click-modal="false"
    :title="title+'选择'"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--搜索-->
    <div class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item :label="title+'编号'" prop="contractNo">
          <el-input
            v-model.trim="searchForm.contractNo"
            :placeholder="title+'编号'"
            @keyup.enter.native="search"
          />
        </el-form-item>
        <el-form-item :label="title+'名称'" prop="contractName">
          <el-input
            v-model.trim="searchForm.contractName"
            :placeholder="title+'名称'"
            @keyup.enter.native="search"
          />
        </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>
    </div>
    <!--查询列表-->
    <div>
      <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="title+'编号'" prop="contractNo" align="center" width="200" />
        <el-table-column :label="title+'名称'" prop="contractName" />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialogData.consignContractVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

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

      }
    }
  },
  data() {
    return {
      loading: true,
      title: '委托合同', // 标题
      // 搜索信息
      searchForm: {
        contractNo: '', // 编号
        contractName: ''// 名称
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.consignContractVisible'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.searchForm.contractNo = ''
        this.searchForm.contractName = ''
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getContractByPageSelet(params).then(response => {
        this.loading = false
        this.list = response.data.records
        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.status = '02' // 有效委托合同状态
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData.contractName) {
        const data = {
          name: this.currentData.contractName,
          code: this.currentData.contractNo,
          id: this.currentData.id,
          chargeValue: this.currentData.chargeValue, // 委托合同费用比例
          chargeType: this.currentData.chargeType // 招标代理服务费收取方式
        }
        this.$emit('consignContractInfo', data)
        this.dialogData.consignContractVisible = 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>
