<!--
  @description: 录入委员会信息
  @author:肖文龙
  @routerPath:
  @date: 2020年3月6日00:05:09
-->
<template>
  <div>
    <!--基本信息-->
    <div class="page-title">
      1. 基本信息
    </div>
    <!--可编辑-->
    <basicInformationAdd v-if="isEdit" ref="info" :data="formData" />
    <!--不可编辑-->
    <basicInformationDetail v-else ref="info" :data="formData" />
    <!--
        评委会组建方式为随机抽取时
         juryBuildType=== '00'
        -->
    <template v-if="formData.juryBuildType==='00'">
      <!--抽取条件-->
      <extractCondition :data="formData" />
      <!--屏蔽单位-->
      <shieldingUnit />
    </template>
    <!--
        评委会组建方式为直接指定
         juryBuildType=== '01'
        -->
    <template v-if="formData.juryBuildType==='01'">
      <!--指定专家-->
      <specifyEpert ref="specifyEpert" :is-extracting-results="false" />
    </template>
  </div>
</template>

<script>
/* api*/
import { saveOrUpdateJuryInformationInfo, checkIsSaveRepresentByGroupId } from '@/api/intensiveeval/intensiveeval'
import { queryExxpertExtractResultList, saveExpertExtractInfo, checkExpertNumAndConditionNumTotal } from
  '@/api/bidding/evaluation'
/* 混合开发*/
import { intensiveEvaluationMixin } from '@/views/intensiveeval/mixins/intensiveevalMixin.js'// 集约化评标-公共参数
/* 组件*/
import basicInformationAdd from '../basicInformation/basicInformation-add'// 基本信息
import basicInformationDetail from '../basicInformation/basicInformation-detail'// 基本信息-查看
import extractCondition from '../extractCondition/extractCondition-editView'// 抽取条件
import shieldingUnit from '../shieldingUnit/shieldingUnit-editView'// 屏蔽单位
import specifyEpert from '../specifyEpert/specifyEpert-editView'// 指定专家
export default {
  name: 'FormEvalCommitteeContentEditView',
  components: {
    basicInformationAdd,
    basicInformationDetail,
    extractCondition,
    shieldingUnit,
    specifyEpert
  },
  mixins: [intensiveEvaluationMixin],
  data() {
    return {
      isEdit: this.$route.meta.isEdit, // 是否可编辑 布尔值
      judgesStatus: this.$route.query.judgesStatus // 评委会状态02为抽取失败
    }
  },
  methods: {
    /*
    * 保存组装数据
    * status 提交状态 00 保存 02 提交
    * */
    assemblyData() {
      const data = {
        ...this.$refs.info.assemblyData()// 基本信息
      }
      return data
    },
    /*
    * 保存
    * status 提交状态 00 保存 01提交 04补抽
    * */
    submitForm(status) {
      const data = this.assemblyData(status)// 保存组装数据
      data.submitType = status// 提交状态
      saveOrUpdateJuryInformationInfo(data).then(response => {
        let statusText = ''
        if (status === '00') { // 保存
          statusText = '保存成功'
        } else if (status === '01') { // 提交
          statusText = '提交成功'
          this.$router.push({ path: '/intensiveeval/intensiveevalCommittee-list' })
        }
        this.$message({
          message: statusText,
          type: 'success'
        })
      }).catch(() => {

      })
    },
    /*
  * 生效
  * */
    submit() {
      const isValid = this.$refs.info.submit()// 基本信息是否通过校验
      if (isValid) {
        this.$confirm('是否确定生效？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.checkIsSaveRepresent()
        })
      }
    },
    // 校验是否添加招标人代表
    checkIsSaveRepresent() {
      const groupId = this.$route.query.groupId
      checkIsSaveRepresentByGroupId(groupId).then(response => {
        // 评委会组建方式为直接指定
        if (this.formData.juryBuildType === '01') {
          this.submitExpertExtractInfo()
        }
        // 评委会组建方式为随机指定
        if (this.formData.juryBuildType === '00') {
          const data = this.assemblyData()// 保存组装数据
          data.submitType = '01'// 提交状态
          this.numberExpertsCheck(data)
        }
      }).catch(() => {
      })
    },
    // 随机抽取专家人数校验
    numberExpertsCheck(data) {
      checkExpertNumAndConditionNumTotal(data).then(response => {
        this.submitExxpertExtractResultList(data)
      }).catch(() => {
      })
    },
    // 指定专家-添加专家信息
    submitExpertExtractInfo() {
      const assemblyData = this.assemblyData() // 基本信息数据
      assemblyData.submitType = '01'// 提交状态
      const data = this.$refs.specifyEpert.assemblyData()// 指定专家信息集合
      data.map(item => {
        item.batchNumber = assemblyData.batchNumber
        item.saveJuryInfomationInfoDto = assemblyData
      })
      saveExpertExtractInfo(data).then(response => {
        this.$message({
          message: '提交成功',
          type: 'success'
        })
        this.$router.push({ path: '/intensiveeval/intensiveevalCommittee-list' })
      }).catch(() => {
      })
    },
    // 随机抽取-获取抽取结果并给专家分配账号
    submitExxpertExtractResultList(data) {
      queryExxpertExtractResultList(data).then(response => {
        this.$message({
          message: '提交成功',
          type: 'success'
        })
        this.$router.push({ path: '/intensiveeval/intensiveevalCommittee-list' })
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>

