<!--
  @description: 专家完善信息---任职经历--选择工作单位弹框
  @Modifier: 徐媛媛
  @routerPath:
  @date: 2020/8/10-13:27
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="organizationDialog"
    :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 label="单位名称" prop="comName">
          <el-input v-model.trim="searchForm.comName" placeholder="单位名称" @keyup.enter.native="search" />
        </el-form-item>
        <el-form-item label="统一社会信用编码" prop="comCode">
          <el-input v-model.trim="searchForm.comCode" placeholder="统一社会信用编码" @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>
    </section>
    <!--查询列表-->
    <div>
      <el-table
        ref="singleTable"
        v-loading="loading"
        :data="list"
        class="pointer"
        highlight-current-row
        size="mini"
        @current-change="currentChange"
      >
        <el-table-column type="index" label="序号" align="center" width="80" />
        <el-table-column label="单位名称" prop="comName" />
        <el-table-column label="统一社会信用编码" prop="comCode" width="200" align="center" />
      </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="organizationDialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { getAlreadyExistExpertComName } from '@/api/expert/expertscloud'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils' // 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
export default {
  name: 'BidSelectworkunit',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin],
  data() {
    return {
      loading: true,
      organizationDialog: false, // 弹框打开状态
      // 搜索信息
      searchForm: {
        comCode: '',
        comName: ''
      },
      list: [], // 列表数据
      currentData: {} // 当前选择的信息
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 打开弹框
    openOrganizationDialog() {
      this.searchForm.comName = '' // 打开弹框清空
      this.searchForm.comCode = '' // 打开弹框清空
      this.organizationDialog = true // 打开弹框
      this.loadData()
    },
    // 加载数据
    loadData() {
      const data = {
        ...this.searchForm
      }
      const params = this.getParams() // 查询条件
      getAlreadyExistExpertComName(params, data)
        .then(response => {
          this.loading = false
          this.list = response.data.records
          this.paginationData.total = response.data.total
        })
        .catch(() => {
          this.loading = true
        })
    },
    // 查询条件
    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) {
        const currentData = this.currentData
        this.$emit('dialogDataBuyersInfo', currentData, this.buyersIndex)
        this.organizationDialog = false
      } else {
        this.$message({
          message: `请选择工作单位`,
          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>
