<!--
  @description: 项目信息-选择屏蔽单位
  @Modifier: 肖文龙
  @routerPath:
  @date: 2019-12-20 09:36:14
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :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="title+'编号'" prop="orgCode">
          <el-input
            v-model="searchForm.orgCode"
            :placeholder="title+'编号'"
            style="width: 180px"
          />
        </el-form-item>
        <el-form-item :label="title+'名称'" prop="departname">
          <el-input
            v-model="searchForm.departname"
            :placeholder="title+'名称'"
            style="width: 180px"
          />
        </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="title+'编号'" prop="orgCode" align="center" width="200" />
        <el-table-column :label="title+'名称'" 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="dialogData.dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

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

      }
    }
  },
  data() {
    return {
      title: '机构', // 标题
      // 搜索信息
      searchForm: {
        juryId: this.$route.query.juryId, // 评委会id
        orgCode: '', // 编号
        departname: ''// 名称
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getDepartList(params).then(response => {
        this.list = response.data.records
        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) {
        const data = {
          name: this.currentData.departname,
          code: this.currentData.orgCode,
          id: this.currentData.id
        }
        this.$emit('shieldingUnitSelectInfo', data)
        this.dialogData.dialog = 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>
