<!--
  @description: 发起交通费报销-发放明细-选择专家弹框
  @Modifier: sunxinman/肖文龙
  @routerPath:
  @date: 2020/06/17-15:33
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    :title="title"
    width="1000px"
    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="专家姓名">
          <el-input v-model="searchForm.expertName" />
        </el-form-item>
        <!-- 工作单位 -->
        <el-form-item label="工作单位">
          <el-input v-model="searchForm.workUnit" />
        </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
          header-align="center"
          label="专家姓名"
          prop="expertName"
          min-width="160"
        />
        <el-table-column
          header-align="center"
          label="身份证号"
          prop="idCard"
          width="180"
        />
        <el-table-column
          label="工作单位"
          prop="workUnit"
          header-align="center"
          min-width="200"
        />
        <el-table-column
          label="手机号"
          prop="monile"
          align="center"
          width="150"
        />
        <el-table-column
          header-align="center"
          label="职称"
          prop="jobName"
          width="80"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in titleList"
              v-if="scope.row.jobName===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属地区" prop="areaName" header-align="center" min-width="200" />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="paginData" />
    </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 { getBiddingExpertAuditInfoPageList, getByMeetingIdStageIds } from '@/api/intensiveeval/intensiveeval'//
/* 公用方法*/
import { filterObj, restoreInitialValue, paging } from '@assets/js/utils'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { groupMixin } from '@views/intensiveeval/mixins/intensiveevalGroupMixin'// 集约化评标-字典信息
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'ChooseExpertDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, groupMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {

      }
    }
  },
  data() {
    return {
      title: '选择专家', // 标题
      stageIds: [], // 阶段id
      // 搜索信息
      searchForm: {
        stageIds: [], // 阶段ID
        expertName: '', // 专家姓名
        workUnit: ''// 工作单位
      },
      allList: [], // 全部列表数据
      list: [], // 展示的列表数据
      currentData: {}// 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      } else {
        this.currentData = {}
      }
    }
  },
  created() {
    this.GetByMeetingIdStageId()// 获取阶段id
  },
  methods: {
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 获取阶段id
    GetByMeetingIdStageId() {
      getByMeetingIdStageIds(this.$route.query.meetingId).then(res => {
        this.stageIds = res.data// 阶段id
        this.loadData()// 加载数据
      })
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getBiddingExpertAuditInfoPageList(params).then(res => {
        this.allList = res.data
        this.paginData()// 分页
      }).catch(() => {

      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.stageIds = this.stageIds// 阶段id
      return filterObj(param)// 过滤空的key
    },
    // 分页
    paginData() {
      const searchForm = { ...this.searchForm }
      delete searchForm.stageIds
      this.list = paging(searchForm, this.allList, this.paginationData)// 分页功能
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData) {
        const data = {
          name: this.currentData.expertName,
          id: this.currentData.expertId
        }
        this.$emit('chooseExpertInfo', data)
        this.dialogData.dialog = false
      } else {
        this.$message({
          message: `请选择${this.title}`,
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm() {
      restoreInitialValue(this.searchForm)// 搜索重置
      this.search()// 搜索
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.paginData()// 分页
    }
  }
}
</script>

<style scoped lang="less">

</style>
