<!--
  @description: 招标项目-归档-添加归档目录-文件模版弹框
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020-12-05
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialog"
    :close-on-click-modal="false"
    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="模版名称'" prop="contractNo">
          <el-input
            v-model.trim="searchForm.contractNo"
            placeholder="模版名称"
            @keyup.enter.native="search"
          />
        </el-form-item>
        <el-form-item
          label="模版类型"
          prop="qualificationMethod"
        >
          <el-select v-model="searchForm.qualificationMethod" placeholder="请选择" style="width: 220px">
            <el-option
              v-for="item in archivedTmpList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </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="模版编号" prop="contractNo" align="center" width="200" />
        <el-table-column label="模版名称" prop="contractName" header-align="center" />
        <el-table-column label="模版类型" prop="contractName" align="center">
          <template slot-scope="scope">
            {{ filterDictText(archivedTmpList, scope.row.packStatus) }}
          </template>
        </el-table-column>
        <el-table-column label="模版状态" prop="contractName" align="center">
          <template slot-scope="scope">
            {{ filterDictText(archivedTmpList, scope.row.packStatus) }}
          </template>
        </el-table-column>
      </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="dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { getContractByPageSelet } from '@/api/purchasePlan/taskplan'// 委托合同选择
/* 公用方法*/
import { filterObj, filterDictText } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页/* 混入-字典信息 */
import { bidArchiveddGroup } from './../mixins/bidArchivedGroupMixin'// 字典信息
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'ConsignContractSelectDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  data() {
    return {
      loading: true,
      /* 字典信息-start */
      ...bidArchiveddGroup,
      archivedTmpList: [], // 模版类型
      /* 字典信息-end */
      dialog: false, // 弹框打开状态
      // 搜索信息
      searchForm: {
        contractNo: '', // 模版名称
        contractName: ''// 名称
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  created() {
    // 获取字典方法
    this.initGroup()
  },
  methods: {
    filterDictText,
    // 获取字典方法
    initGroup() {
      const data = ['']
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 打开弹窗
    open() {
      this.dialog = true
      // 弹框已打开
      // 加载数据
      this.searchForm.contractNo = ''
      this.searchForm.contractName = ''
      this.loadData()
    },
    // 当前选择的信息
    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 = {
          code: this.currentData.contractNo // 文档模版编号
        }
        this.$emit('call-back', data)
        this.dialog = false
      } else {
        this.$message({
          message: `请选择文档模版`,
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.search()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
