<!--
  @description: 项目信息-添加专家
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020年3月9日16:44:54
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    title="选择指定专家"
    width="1080px"
    append-to-body
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--搜索-->
    <section class="pt16 clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="专家姓名" prop="expertName">
          <el-input v-model="searchForm.expertName" placeholder="专家姓名" @keyup.enter.native="search" />
        </el-form-item>
        <el-form-item label="工作单位" prop="workCompany">
          <el-input v-model="searchForm.workCompany" 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>
    <!--查询列表-->
    <section>
      <el-table
        ref="singleTable"
        :data="list"
        class="pointer"
        size="mini"
        highlight-current-row
        @selection-change="selectionChange"
      >
        <el-table-column type="selection" width="45" />
        <el-table-column type="index" label="序号" width="45" align="center" />
        <el-table-column
          header-align="center"
          label="专家姓名"
          width="100px"
          prop="name"
        />
        <el-table-column
          align="center"
          width="150px"
          label="身份证号"
          prop="idCard"
        />
        <el-table-column
          header-align="center"

          min-width="200px"
          label="工作单位"
          prop="hereCompany"
        />
        <el-table-column
          align="center"
          width="100px"
          label="手机号"
          prop="mobilePhone"
        />
        <el-table-column

          header-align="center"
          min-width="110px"
          label="职称"
          prop="technicalTitle"
        />
        <el-table-column
          header-align="center"
          min-width="200px"
          label="所属地区"
          prop="extractNumber"
        >
          <template slot-scope="scope">
            <!--省，市，区-->
            <span>{{ scope.row.province }}{{ scope.row.city }}{{ scope.row.county }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" :loading="confirmLoading" @click="ensure">确 定</el-button>
      <el-button @click="dialogData.dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { saveExpertInfoStatus } from '@/api/bidding/evaluation' // 专家选择
import { getExpertListPage } from '@/api/bidding/evaluation' // 专家选择
/* 公用方法*/
import { filterObj, cloneObject } from '@/assets/js/utils' // 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { groupMixin } from '@/views/intensiveeval/mixins/intensiveevalGroupMixin' // 字典信息
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
export default {
  name: 'SpecifyEpertSelectDialog',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin, groupMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {}
    }
  },
  data() {
    return {
      confirmLoading: false, // 确定Loding
      title: '机构', // 标题
      // 搜索信息
      searchForm: {
        expertName: '', // 专家姓名
        workCompany: '' // 工作单位
      },
      list: [], // 列表数据
      selectionData: [], // 当前选择的信息
      // 评标时间
      evaluationTime: {
        evaluationStartTime: '', // 评标开始时间
        evaluationEndTime: '' // 评标结束时间
      }
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  beforeDestroy() {
    this.$bus.$off('on-checkTime')
  },
  created() {
    // 接收评标开始时间/评标结束时间
    this.$bus.$on('on-checkTime', evaluationTimeData => {
      this.evaluationTime = evaluationTimeData
    })
  },
  methods: {
    // 当前选择的信息
    selectionChange(val) {
      this.selectionData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams() // 查询条件
      getExpertListPage(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.evaluationTime.evaluationStartTime && this.evaluationTime.evaluationEndTime) {
        if (this.selectionData.length > 0) {
          this.confirmLoading = true
          this.selectionData.forEach(item => {
            item.expertId = item.eid // 专家表id
            item.juryId = this.$route.query.juryId// 评委会Id
            item.pwhid = this.$route.query.batchNumber// 批次号
            item.bidstartdate = this.evaluationTime.evaluationStartTime// 评标开始时间
            item.bidenddate = this.evaluationTime.evaluationEndTime// 评标结束时间
          })
          saveExpertInfoStatus(cloneObject(this.selectionData)).then(res => {
            this.$emit('specifyEpertSelectInfo')
            this.$refs.singleTable.clearSelection()
            this.selectionData = []// 清空已选择
            this.dialogData.dialog = false
            this.confirmLoading = false
          }).catch(() => {
            this.confirmLoading = false
          })
        } else {
          this.$message({
            message: `请选择专家`,
            type: 'warning'
          })
        }
      } 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>
