<!--
  @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"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--搜索-->
    <section class="p0-16 pt16 clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="用户名" prop="userName">
          <el-input
            v-model="searchForm.userName"
            placeholder="用户名"
          />
        </el-form-item>
        <el-form-item label="联系人姓名" prop="realName">
          <el-input
            v-model="searchForm.realName"
            placeholder="联系人姓名"
          />
        </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="45"
        />
        <el-table-column
          label="用户名"
          prop="userName"
          min-width="150"
        />
        <el-table-column
          label="联系人姓名"
          prop="realName"
          min-width="150"
        />
        <el-table-column
          label="所属部门"
          prop="departName"
          min-width="150"
        />
      </el-table>
    </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 { queryTenderManagerByDepartIdAndBatchNumber } from '@/api/intensiveeval/intensiveeval'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
export default {
  name: 'LeadProjectManagerSelectDialog',
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {
      }
    },
    // 查询牵头人列表参数
    leadDepartment: {
      type: Object,
      default: function() {
      }
    }
  },
  data() {
    return {
      // 搜索信息
      searchForm: {
        batchNumber: '', // 批次号
        departId: '', // 部门id
        realName: '', // 联系人姓名
        userName: ''// 用户名
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      queryTenderManagerByDepartIdAndBatchNumber(params).then(response => {
        this.list = response.data
      }).catch(() => {

      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.batchNumber = this.$route.query.batchNumber // 批次号
      param.departId = this.leadDepartment.id // 牵头人部门Id
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData) {
        this.$emit('leadProjectManagerInfo', this.currentData)
        this.dialogData.dialog = false
      } else {
        this.$message({
          message: `请选择${this.title}`,
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 搜索
    search() {
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
