<!--
  @description:立项-相关机构-挑选所属公司
  @Modifier: haofengxian
  @routerPath:
  @date: 2020-5-29-10:51
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="visibleDialog"
    :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="orgCode">
          <el-input
            v-model="searchForm.orgCode"
            placeholder="机构编号"
            style="width: 180px"
            @keyup.enter.native="search"
          />
        </el-form-item>
        <el-form-item label="机构名称" prop="departName">
          <el-input
            v-model="searchForm.departName"
            placeholder="机构名称"
            style="width: 180px"
            @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>
    <!--查询列表-->
    <section>
      <el-table
        ref="singleTable"
        :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="orgCode" align="center" width="200" />
        <el-table-column label="机构名称" prop="departName" />
      </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="visibleDialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
// import { getDepartList } from '@/api/intensiveeval/intensiveeval'// 屏蔽单位选择
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: 'SubsidiaryOrganDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  data() {
    return {
      visibleDialog: false,
      buyersIndex: '', // 多招标人当前选择索引
      moreTenderType: '', // 是否多招标人
      // 搜索信息
      searchForm: {
        departRoleName: '10', // 10采购人 11代理机构(项目经理)
        orgCode: '', // 编号
        departName: ''// 名称
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 打开弹框加载数据
    openShowDialog(index, type) {
      this.searchForm.orgCode = '' // 打开弹框清空
      this.searchForm.departName = '' // 打开弹框清空
      /* =============多招标人添加===============*/
      this.buyersIndex = index // 多招标人赋值索引
      this.moreTenderType = type // 是否多招标人
      /* ================多招标人添加=============*/
      this.visibleDialog = true // 打开弹框
      this.loadData()
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getDepartListByDepartRoleName(params).then(response => {
        this.list = response.data.results
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    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) {
        this.$emit('subsidiaryOrganDataInfo', this.currentData, this.buyersIndex, this.moreTenderType)
        this.visibleDialog = 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>
