<!--
  @description: 组建评标委员会-选择招标人代表列表-弹框
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020年3月28日16:14:33
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    title="招标人代表信息"
    width="1080px"
    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="name">
          <el-input v-model="searchForm.name" placeholder="姓名" />
        </el-form-item>
        <el-form-item label="工作单位" prop="workCompany">
          <el-input v-model="searchForm.workCompany" placeholder="工作单位" />
        </el-form-item>
        <el-form-item label="职称" prop="technicalTitle">
          <el-select
            v-model="searchForm.technicalTitle"
            style="width: 228px"
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in titleList"
              :key="index"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </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"
        height="396"
        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
          align="center"
          label="姓名"
          width="120px"
          prop="name"
        />
        <el-table-column
          header-align="center"
          min-width="200px"
          label="工作单位"
          prop="workCompany"
        />
        <el-table-column
          align="center"
          min-width="80px"
          label="职称"
          prop="technicalTitle"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, index) in titleList"
              v-if="item.typecode === scope.row.technicalTitle"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          min-width="80px"
          label="证件类型"
          prop="cardType"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, index) in cardTypeList"
              v-if="item.typecode === scope.row.cardType"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          min-width="150px"
          label="证件号"
          prop="idCard"
        />
      </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 {
  queryRepresentsPages,
  saveOrUpdateRepresentInfo
} from '@/api/intensiveeval/intensiveeval'
/* 公用方法*/
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: 'AgentTendererSelectDialog',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin, groupMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {}
    }
  },
  data() {
    return {
      confirmLoading: false, // 确定Loding
      // 搜索信息
      searchForm: {
        name: '', // 姓名
        workCompany: '', // 工作单位
        technicalTitle: '' // 职称
      },
      list: [], // 列表数据
      selectionData: [] // 当前选择的信息
    }
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 当前选择的信息
    selectionChange(val) {
      this.selectionData = val
    },
    // 加载数据
    loadData() {
      const params = this.getParams() // 查询条件
      queryRepresentsPages(params)
        .then(response => {
          this.list = response.data.records
          this.paginationData.total = response.data.total
        })
        .catch(() => {})
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.stageId = this.$store.getters.groupId.stageId // 阶段Id
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param) // 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.selectionData.length > 0) {
        this.confirmLoading = true
        const data = []
        this.selectionData.forEach(item => {
          data.push({
            ...this.$store.getters.groupId, // 项目Id 包id 阶段Id
            representId: item.id, // 招标人代表Id
            useStatus: '00'// 使用状态 00 临时 01 正式
          })
        })
        saveOrUpdateRepresentInfo(cloneObject(data)).then(res => {
          this.$emit('agentTendererSelectInfo', cloneObject(this.selectionData))
          this.$refs.singleTable.clearSelection()
          this.selectionData = []// 清空已选择
          this.$message({
            type: 'success',
            message: '添加成功'
          })
          this.confirmLoading = false
          this.dialogData.dialog = false
        }).catch(() => {
          this.confirmLoading = 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>
