 <!--
  @description: 抽取专家-专家审核/查看申请详情
  @Modifier: 徐媛媛
  @routerPath:/extractExpert/extractReview/--专家审核
  /extractExpert/extractApplyDetail--查看申请详情
  @date: 2020/8/26-13:27
-->
<template>
  <div class="leave_container p0-16">
    <section class="title title_border clearfix pointer">
      <template>
        <!-- 抽取申请 -->
        <div>
          <i class="el-icon-s-home" />
          抽取申请
        </div>
      </template>
    </section>
    <el-scrollbar class="all_extract">
      <el-form ref="allData" :model="allData" label-width="160px">
        <div class="page-title">
          1 抽取项目
        </div>
        <div>
          <el-table :data="extractProject" class="tableLimit">
            <el-table-column type="index" label="序号" width="60" align="center" />
            <el-table-column header-align="center" min-width="200" align="left">
              <template slot="header" prop="tenderName">
                <span>项目名称</span>
              </template>
              <template slot-scope="scope">
                <span>{{ scope.row.tenderName }}</span>
              </template>
            </el-table-column>
            <el-table-column header-align="center" min-width="200" align="left">
              <template slot="header" prop="tenderNo">
                <span>项目编号</span>
              </template>
              <template slot-scope="scope">
                <span>{{ scope.row.tenderNo }}</span>
              </template>
            </el-table-column>
            <el-table-column header-align="center" min-width="200" align="left">
              <template slot="header" prop="packName">
                <span>标段名称</span>
              </template>
              <template slot-scope="scope">
                <span>{{ scope.row.packName }}</span>
              </template>
            </el-table-column>
            <el-table-column header-align="center" align="left">
              <template slot="header" prop="pakNo">
                <span>标段编号</span>
              </template>
              <template slot-scope="scope">
                <span>{{ scope.row.pakNo }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <el-form ref="form" label-width="160px">
        <div class="page-title">
          <span>2 抽取申请</span>
        </div>
        <div>
          <table class="from_table">
            <!--抽取申请编号--->
            <tr>
              <td>
                <el-form-item label="抽取申请编号" prop="applyCode" />
              </td>
              <td colspan="3">
                {{ extractApply.applyCode }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="评标阶段" prop="stageType" />
              </td>
              <td>
                {{ extractApply.stageType=='00'?"资格预审":"资格后审" }}
              </td>
              <td>
                <el-form-item label="专家确定方式" prop="rakeType" />
              </td>
              <td>
                {{ extractApply.rakeType=='00' ? '随机抽取':"直接指定" }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="评标开始时间" prop="startTime" />
              </td>
              <td>
                {{ extractApply.startTime }}
              </td>
              <td>
                <el-form-item label="评标结束时间" prop="endTime" />
              </td>
              <td>
                {{ extractApply.endTime }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="专家人数" prop="expertNum" />
              </td>
              <td>
                {{ extractApply.expertNum }}
              </td>
              <td>
                <el-form-item label="招标代表人数" prop="ownerNum" />
              </td>
              <td>
                {{ extractApply.ownerNum }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item ref="area" label="评标地点" prop="area" />
              </td>
              <td colspan="3">
                {{ extractApply.proviceName + extractApply.cityName + extractApply.areaName }}
                {{ extractApply.adress }}
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="抽取回避" />
              </td>
              <td colspan="3">
                {{ extractApply.attendDay }}天内参加过评标的专家不再抽取 一个月内参加过{{ extractApply.attendCount }}次评标的专家不再抽取
              </td>
            </tr>
          </table>
        </div>
      </el-form>
      <el-form ref="form" label-width="160px">
        <div class="page-title">
          <span>3 设置抽取条件</span>
        </div>
        <div>
          <el-table :data="tableData" class="tableLimit" border>
            <el-table-column type="index" label="序号" width="60" align="center" />
            <el-table-column label="评标专业" align="center" prop="specialName" />
            <el-table-column label="抽取人数" align="center" prop="expertNum" />
            <el-table-column label="抽取专家地区" align="center" prop="cityName" />
            <el-table-column label="备选专业" align="center" prop="spareMajorName" />
            <el-table-column label="抽取级别" align="center" prop="extractLevel">
              <template slot-scope="scope">
                <!-- <div v-if="scope.row.extractLevel === '01'">
                  一级
                </div>
                <div v-if="scope.row.extractLevel === '02'">
                  二级
                </div>
                <div v-if="scope.row.extractLevel === '03'">
                  三级
                </div> -->
                {{ filterDictText(extractLevelList, scope.row.extractLevel) }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <el-form ref="form" label-width="160px">
        <div class="page-title">
          <span>4 录入招标方代表</span>
        </div>
        <div>
          <el-table :data="alltableData" class="tableLimit" border>
            <el-table-column type="index" label="序号" width="60" align="center" />
            <el-table-column label="姓名" align="center" prop="purchaserName" />
            <el-table-column label="身份证号" align="center" prop="idCard" />
            <el-table-column label="手机号" align="center" prop="mobilePhone" />
            <el-table-column label="性别" align="center" prop="sex">
              <template slot-scope="scope">
                <span v-if="scope.row.sex==='00'">男</span>
                <span v-if="scope.row.sex==='01'">女</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <el-form ref="form" label-width="160px">
        <div class="page-title">
          <span>5 设置回避单位</span>
        </div>
        <div>
          <el-table :data="companyList" class="tableLimit" border>
            <el-table-column type="index" label="序号" width="60" align="center" />
            <el-table-column label="机构名称" align="center" prop="avoidCompany" />
            <el-table-column label="机构代码" align="center" prop="avoidOrgcode" />
            <el-table-column label="回避原因" align="center" prop="reason" />
          </el-table>
        </div>
      </el-form>
      <el-form ref="form" label-width="160px">
        <div class="page-title">
          <span>6 回避专家</span>
        </div>
        <!-- 回避专家 -->
        <div>
          <el-table :data="expertList" class="tableLimit" border>
            <el-table-column type="index" label="序号" width="60" align="center" />
            <el-table-column label="专家姓名" align="center" prop="expertName" />
            <el-table-column label="身份证号" align="center" prop="certificateCode" />
            <el-table-column label="手机号" align="center" prop="mobile" />
          </el-table>
        </div>
      </el-form>
      <el-form v-if="isShow" ref="form" label-width="160px">
        <div class="page-title">
          <span>审核意见</span>
          <div>
            <table class="from_table" border>
              <tr>
                <td>
                  <el-form-item label="审核意见" prop="otherDesc" align="center" />
                </td>
                <td colspan="3">
                  <el-input
                    v-model.trim="auditExpertApplyForm.otherDesc"
                    type="textarea"
                    maxlength="50"
                    style="width: 100%;"
                    placeholder="审核意见"
                    class="show-word-limit-padding"
                  />
                </td>
              </tr>
            </table>
          </div>

          <div style="text-align:center;margin:8px auto">
            <el-button type="primary" @click="auditExpertApply('01')">
              审核通过
            </el-button>
            <el-button @click="auditExpertApply('02')">
              审核不通过
            </el-button>
          </div>
        </div>
      </el-form>
    </el-scrollbar>
  </div>
</template>

<script>
/* 公用方法*/
import {
  getExtractExpertDetailById, getExpertList, adminAuditExtractApply } from '@/api/expert/expertscloud'
/* 方法*/
import { filterDictText } from '@/assets/js/utils'
export default {
  data() {
    return {
      formData: {
        otherDesc: '' // 审核意见
      },
      expertList: [],
      companyList: [],
      extractApply: {},
      extractProject: [],
      tableData: [],
      alltableData: [],
      departList: [],
      expertStore: '',
      isShow: false,
      type: '',
      status: '',
      applyID: '',
      addExpertVisible: false,
      expertSearch: {
        expertName: '',
        certificateCode: '',
        expertIds: [],
        page: 1,
        pageSize: 10
      },
      allData: {
        adress: '', // 详细地址
        applyCode: '', // 申请编号
        areaCode: '', // 评标地点（区编号）
        areaName: '', // 评标地点（区名称）
        attendCount: '', // 一个月内参加过几次的专家不在被抽
        attendDay: '', // 几天内参加过评标的专家不再被抽取
        auditStatus: '', // 00审核中,02驳回,01通过
        cityCode: '', // 评标地点（市编号）
        cityName: '', // 评标地点（市名称）
        endTime: '', // 评标结束时间
        expertNum: '', // 专家人数
        id: '', // 申请id
        operationType: '', // 操作类型：00是保存 01是提交
        ownerNum: '', // 业主代表人数
        proviceCode: '', // 评标地点（省编号）
        proviceName: '', // 评标地点（省名称）
        rakeType: '01', // 指定抽取方式 00随机抽取 01直接指定
        reason: '', // 审核意见
        resultStatus: '',
        stageType: '01', // 评标阶段 00 资审 01 后审
        startTime: '', // 评标开始时间
        useStatus: '',
        extractApplyDetailList: [], // 招标项目详情
        extractConditionList: [], // 抽取条件详情
        extractAvoidCompanyList: [], // 回避单位详情
        extractAvoidExpertList: [], // 回避专家详情
        extractResultList: [], // 指定专家详情
        desc: ''
      },
      expertTotal: 0,
      rakeType: '01', // 指定抽取方式 00随机抽取 01直接指定
      expertData: [],
      addExpertList: [], // 添加专家变量
      checkedExpert: [],
      auditExpertApplyForm: {
        otherDesc: ''
      }
    }
  },
  watch: {
    '$route.path': {
      immediate: true,
      handler(val) {
        if (val === '/expert/extractApplyAudit-detail') {
          this.isShow = true
        } else {
          this.isShow = false
        }
      }
    }
  },
  mounted() {
    // 字典信息
    this.initGroup()
    const id = this.$route.query.id ? this.$route.query.id : ''
    this.applyID = id
    this.type = this.$route.query.type ? this.$route.query.type : ''
    // 根据id回显数据
    this.getExtractExpertDetailById(id)
    if (this.type === '00') {
      // this.getDetailExpertAvoidDepartList(id)
      // this.getDetailExpertCompanyList(id)
    }
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 获取字典方法
    initGroup() {
      const data = [
        'extractLevel' // 抽取等级
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    getExtractExpertDetailById(id) {
      getExtractExpertDetailById(id).then(res => {
        this.extractApply = res.data.apply
        // this.extractApply = this.$Moment(this.extractApply.startTime).format(this.momentSaveFormat)
        // this.extractApply = this.$Moment(this.extractApply.endTime).format(this.momentSaveFormat)
        this.extractProject = res.data.applyDetailList
        this.companyList = res.data.companyList
        this.alltableData = res.data.purchaserList
        this.type = res.data.apply.rakeType
        if (this.type === '00') {
          this.expertList = res.data.avoidExpertList
          res.data.condionList.forEach(val => {
            const everyData = {}
            everyData.type = val.con.type // 类别
            everyData.specialName = val.con.specialName // 抽取专业
            everyData.specialCode = val.con.specialCode // 抽取专业code
            everyData.cityName = val.con.cityName // 抽取专家地区
            everyData.cityCode = val.con.cityCode // 抽取专家地区
            everyData.expertNum = val.con.expertNum // 抽取人数
            everyData.spareMajorName = val.specialNameList.join(',')// 备选专业
            everyData.spareMajorCode = val.specialCodeList.join(',')
            this.tableData.push(everyData)
          })
        } else {
          this.expertList = res.data.expertList
        }
      }).catch(() => {

      })
    },
    auditExpertApply(type) {
      this.auditExpertApplyForm.auditStatus = type
      this.auditExpertApplyForm.id = this.$route.query.id
      if (type === '02' && !this.auditExpertApplyForm.otherDesc) {
        this.$message({
          type: 'warning',
          message: '审核意见不能为空'
        })
        return false
      }
      const text = type === '01' ? '确认审核通过？' : '确认审核不通过？'
      this.$confirm(text, '提示', {
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning'
      }).then(() => {
        adminAuditExtractApply(this.auditExpertApplyForm).then(res => {
          this.$router.replace('/expert/extractApplyAudit-list')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    // 获取专家列表
    getExpertList() {
      this.expertSearch.expertIds = []
      this.expertList.forEach(item => {
        this.expertSearch.expertIds.push(item.id)
      })
      getExpertList(this.expertSearch).then(res => {
        this.expertData = res.data.returnData
        this.expertTotal = res.data.rows * 1
      })
    }
  }
}
</script>

<style lang="less" scoped>
.page-title{
  margin: 16px 0;
}
//设置取消按钮向右浮动，左magin为10px，即与确定按钮间距为10px
/deep/.el-message-box__btns .btn-custom-cancel {
  float: right;
  margin-left: 10px;
}
</style>
