<!--
 @description: 组件委员会-未对接专家库
 @author: 肖文龙
 @date: 2020-7-21
 @routerPath:
-->
<template>
  <div class="main">
    <div>
      <template v-if="!isChange">
        <!-- isCanOperate: true可以操作 false不可以查看只有查看权限  00:否 01:是 -->
        <el-button v-if="tenderBase.isCanOperate" size="small" type="primary" @click="addExpert">
          添加专家
        </el-button>
        <!--<el-button type="primary" @click="addExpertLeader">设定组长</el-button>-->
        <!-- <el-upload
          ref="uploads"
          :on-success="handleSuccess"
          :on-error="handleError"
          :show-file-list="false"
          :action="action"
          :data="actionData"
          :headers="importHeaders"
          multiple
          style="display: inline-block;margin:0 10px"
        >
          <el-button size="small" type="primary" plain >导入专家</el-button>
        </el-upload> -->
        <!-- <el-button size="small" type="primary" plain @click="downloadTemp">下载模板</el-button> -->
      </template>
      <!-- <el-button size="small" type="primary" plain @click="checkoutExpert">导出名单</el-button> -->
    </div>
    <!-- 专家列表 -->
    <section class=" mt10">
      <el-table
        ref="multipleTable"
        v-loading="loading"
        :data="tableData"
        @select="selectChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" label="序号" min-width="60" align="center" />
        <el-table-column label="姓名" min-width="100" prop="name" header-align="center" align="left" />
        <el-table-column label="专家身份证号" min-width="160" prop="idCard" align="center" />
        <el-table-column label="联系方式" min-swidth="110" prop="mobilePhone" align="center" />
        <el-table-column label="性别" min-width="60" prop="sex" align="center">
          <template slot-scope="scope">
            {{ filterDictText(sexList,scope.row.sex) }}
          </template>
        </el-table-column>
        <el-table-column label="专家类型" min-width="100" prop="type" align="center">
          <template slot-scope="scope">
            {{ filterDictText(personTypeList,scope.row.type) }}
          </template>
        </el-table-column>
        <el-table-column label="专家类别" min-width="100" prop="expertType" align="center">
          <template slot-scope="scope">
            {{ filterDictText(expertTypeList,scope.row.expertType) }}
          </template>
        </el-table-column>
        <el-table-column label="组长" min-width="60" prop="isLeader" align="center">
          <template slot-scope="scope">
            {{ filterDictText(leaderStatus,scope.row.isLeader) }}
          </template>
        </el-table-column>
        <!-- <el-table-column
          label="专家状态"
          min-width="60"
          prop="expertStatus"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, index) in expertStatus"
              v-if="item.typecode===scope.row.expertStatus"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column> -->
        <el-table-column v-if="!isChange" label="操作" min-width="100" align="center">
          <template slot-scope="scope">
            <el-link type="primary" @click="addExpert(scope.row)">
              [编辑]
            </el-link>
            <el-link type="primary" @click="deleteRow(scope.row)">
              [删除]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
    <!-- 底部按钮 -->
    <!-- isCanOperate: true可以操作 false不可以查看只有查看权限  00:否 01:是 -->
    <div v-if="tenderBase.isCanOperate" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button v-if="isChange" type="primary" size="medium" @click="changeBtn">
            变更
          </el-button>
          <el-button v-if="!isChange" type="primary" size="medium" @click="saveData">
            生效
          </el-button>
        </div>
      </div>
    </div>
    <!-- 添加专家弹框 -->
    <expert-add :dialog-data="dialogData" @change="onSearch" />
  </div>
</template>

<script>
/* api*/
import {
  queryExpertListByStageId, // 专家录入模块-根据阶段id获取专家信息列表
  deleteExpertInfo, // 删除专家
  settingLeader, // 设置组长
  updateExpertUseStatus // 生效
  // downloadTemplate, // 模板下载
  // downProcurementExpertdrawOffList // 导出专家
} from '@/api/bidding/bidCommittee.js'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { bidCommitteeMixin } from './../mixins/bidCommitteeMixin'// 组建评标委员会-公共方法
import { bidCommitteeGroupMixin } from './../mixins/bidCommitteeGroupMixin'// 组建评标委员会-字典信息
/* 公用方法*/
import { filterObj, filterDictText } from '@/assets/js/utils'// 常用方法
// import { getToken } from '@/assets/js/utils/auth'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页组件
import bidExpertDialog from './bidExpertAdd-dialog.vue'// 添加专家弹框
export default {
  name: 'BidCommitteeAdd',
  components: {
    'expert-add': bidExpertDialog, // 添加专家弹框
    pagination // 分页组件
  },
  mixins: [ListMixin, bidCommitteeMixin, bidCommitteeGroupMixin],
  data() {
    return {
      loading: true, // loading效果
      isChange: true, // 是否已生效 true 是 false 否
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      packInfo: this.$store.getters.packInfo, // 标包信息-当前
      // // 导入专家上传文件地址
      // action: '',
      // // 导入专家上传的请求头
      // importHeaders: {
      //   'X-AUTH-TOKEN': getToken()
      // },
      // // 导入专家上传接口参数
      // actionData: {
      //   stageId: this.$store.getters.packInfo.stageId // 阶段
      // },
      //  添加专家-弹框
      dialogData: {
        dialog: false, // false 关闭 true 打开
        rowData: {}// 专家信息
      },
      tableData: [], // 委员会-专家
      selectData: [] // 选择的数据
    }
  },
  created() {
    this.loadData()// 获取数据
  },
  methods: {
    filterDictText,
    // 获取数据
    loadData() {
      // 清空已选择的专家
      this.selectData = []
      // 查询参数值
      const params = this.getQueryParams()// 查询条件
      queryExpertListByStageId(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
        // 传递给父节点列表数据
        this.$emit('bidCommitteeTableData', this.tableData)
        // 是否已生效
        if (this.tableData[0] && this.tableData[0].useStatus === '01') { // 已生效
          this.isChange = true
        } else { // 未生效
          this.isChange = false
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getQueryParams() {
      const param = {
        stageId: this.packInfo.stageId, // 阶段id
        expertSource: '00' // 专家来源 00是外部专家库,也就是直接录入的那种,  01是抽取
      }
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 编辑/新增
    addExpert(row) {
      this.dialogData = {
        dialog: true,
        rowData: row// 专家信息
      }
    },
    //  删除
    deleteRow(row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.loading = true
        deleteExpertInfo(row.expertPackId).then(res => {
          this.loading = false
          this.loadData()
        }).catch(() => {
          this.loading = false
        })
      })
    },
    // 选择专家
    selectChange(val) {
      this.selectData = val
    },
    // 设定组长
    addExpertLeader() {
      if (this.selectData.length === 1) {
        const data = {
          stageId: this.packInfo.stageId, // 阶段id
          expertId: this.selectData[0].id// 专家id
        }
        this.loading = true
        settingLeader(data).then(res => {
          this.$message.success('设定组长成功')
          this.$refs.multipleTable.clearSelection()
          this.loadData()
        }).catch(() => {
          this.loading = false
        })
      } else {
        this.$message.warning('请选择一位专家')
      }
    },
    // // 下载模板
    // downloadTemp() {
    //   downloadTemplate().then(res => {
    //     download(res, '组建委员会.xls')
    //   })
    // },
    // // 导入成功后的回调
    // handleSuccess(response, file, fileList) {
    //   this.$message.success('导入成功')
    //   this.onSearch()
    // },
    // // 导入失败后的回调
    // handleError(response, file, fileList) {
    //   this.$message.error(response.header.msg)
    // },
    // // 导出专家
    // checkoutExpert() {
    //   downProcurementExpertdrawOffList(this.packInfo.packId).then(res => {
    //     download(res, '【' + this.tenderBase.tenderName + '】专家列表.xls')
    //   })
    // },
    // 变更
    changeBtn() {
      this.$confirm('确定变更专家吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.updateExpert('00')
      })
    },
    //  生效
    saveData() {
      this.$confirm('确定生效专家吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.updateExpert('01')
      })
    },
    // 变更/生效
    updateExpert(useStatus) {
      this.loading = true
      const data = {
        stageId: this.packInfo.stageId, // 阶段id
        useStatus: useStatus// 有效状态 00:临时(草稿) 01:有效 02:作废）
      }
      updateExpertUseStatus(data).then(res => {
        this.loading = false
        this.onSearch()
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
