<!--
  @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="title+'编码'" prop="orgCode">
          <el-input
            v-model.trim="searchForm.orgCode"
            :placeholder="title+'编码'"
            @keyup.enter.native="search"
          />
        </el-form-item>
        <el-form-item :label="title+'名称'" prop="departName">
          <el-input
            v-model.trim="searchForm.departName"
            :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="orgCode" align="center" width="200" />
        <el-table-column :label="title+'名称'" prop="departName" />
      </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 { getDepartListByDepartRoleName } from '@/api/common/user'
/* 公用方法*/
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],
  data() {
    return {
      loading: true,
      /* 字典信息-end */
      dialog: false, // 弹框打开状态
      title: '', // 标题
      // 搜索信息
      searchForm: {
        departRoleName: '', // 10采购人 11代理机构(项目经理)
        orgCode: '',
        departName: ''
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  // created() {
  //   // 获取字典方法
  //   this.initGroup()
  // },
  methods: {
    // 打开弹窗
    open(departRoleName) {
      // 加载数据
      this.searchForm.orgCode = '' // 打开弹框清空
      this.searchForm.departName = '' // 打开弹框清空
      this.searchForm.departRoleName = departRoleName // 10采购人 11代理机构 12投标人
      this.loadData()
      if (departRoleName === '12') {
        this.title = '投标人'
      } else if (departRoleName === '10') {
        this.title = '招标人'
      } else if (departRoleName === '11') {
        this.title = '代理机构'
      }
      this.dialog = true
    },
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getDepartListByDepartRoleName(params).then(response => {
        this.loading = false
        this.list = response.data.results
        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
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData.id) {
        this.$emit('call-back', this.currentData)
        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>
