<!--
  @description: 评审指标入口
  @author: sxm/yf
  @routerPath: /procurement/procurementDrive/procurementDocumentsPurchase/reviewIndicator
  @date: 2020-9-22 17:28:58
-->
<template>
  <div class="proc_review">
    <el-tabs v-model="activeName" class="main" style="margin-top:0">
      <el-tab-pane v-for="(item,index) in tabList" :key="item.id" :label="item.procedureName" :name="index+''">
        <priceReviewAdd v-if="item.procedureType=='04'" :get-tender-base="getTenderBase" :refresh-price="refreshPrice" :procedure-id="item.id" @getPriceReview="getPriceReview" />
        <reviewIndicatorAdd v-else :procedure-type="item.procedureType" :get-tender-base="getTenderBase" :procedure-id="item.id" @getIndicatorData="getIndicatorData" />
      </el-tab-pane>
    </el-tabs>
    <!-- 底部按钮 -->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" size="medium" @click="lastStep">
            上一步
          </el-button>
          <el-button :loading="loading" type="primary" size="medium" @click="submit">
            生效
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* api接口*/
import {
  getEvaluationProcedureListByPackId,
  saveOrUpdateEvaluationFactor
} from '@/api/procurement/procurementProtdoc'
import {
  effectiveProcurementEvalFactorByPackId,
  getProjectDrawOffEntityId
} from '@/api/procurement/procurementEvaluation'

/* 公用方法*/
// import { characters1_50, linkerName, checkLinktel, email } from '@/assets/js/validate'// 校验输入内容
import { procurementProjectGroupMixin } from
  '@/views/procurement/procurementProject/mixins/procurementProjectGroupMixin'// 立项采购-字典
/* 组件*/
import priceReviewAdd from './procurementPriceReview/procurementPriceReview-add' // 价格评审
import reviewIndicatorAdd from './procurementReviewIndicator-add' // 符合商务经济评审
// vuex
// import { mapGetters } from 'vuex'
export default {
  name: 'ReviewIndicator',
  inject: ['getTenderBase', 'getDriveTask'],
  components: {
    // conformityReviewAdd,
    priceReviewAdd,
    reviewIndicatorAdd
    // technicalReviewAdd
  },
  mixins: [procurementProjectGroupMixin],
  data() {
    return {
      loading: false,
      activeName: '0', // 默认高亮
      getTenderBase: this.getTenderBase(), // 项目基本信息
      indicatorData: [], // 商务、商务技术、技术、符合评审数据
      businessCurrentScore: '', // 商务评审当前最高分
      businessTotalScore: '', // 商务评审总分
      technologyCurrentScore: '', // 技术评审当前最高分
      technologyTotalScore: '', // 技术评审总分
      procedureType: '', // 指标类型 00-符合 01-商务 02-技术 03-商务技术
      priceReviewData: {}, // 价格评审数据
      tabList: [], // tab列表
      refreshPrice: false // 刷新价格评审数据
    }
  },
  computed: {

  },
  watch: {
  },
  mounted() {
    if (this.getTenderBase.packId) {
      this.getEvaluationProcedureListByPackId(this.getTenderBase.packId)
    }
  },
  methods: {
    // 点击评审指标（二级驱动节点）获取评审步骤
    getEvaluationProcedureListByPackId(packId) {
      getEvaluationProcedureListByPackId(packId).then(res => {
        if (res.header.ret === '0') {
          this.tabList = [...res.data]
        }
      })
    },
    // 生效
    submit() {
      this.loading = true // laoding
      // 循环tab
      let isPassVerification = true
      // 判断评审步骤内有没有评审点，评审点之和是否等于本步骤总分
      this.tabList.forEach(item => {
        // 00符合性评审 01商务 02技术 03商务技术 04价格
        // 是否设置评审点 商务技术设置的评审点最高分之和是否等于步骤的总分
        if (item.procedureType === '00' && !this.indicatorData.length) {
          this.$message.warning('符合性评审步骤至少设置一条评审点')
          isPassVerification = false
          this.loading = false
          return
        }
        if ((item.procedureType === '01' || item.procedureType === '01') && !this.indicatorData.length) {
          this.$message.warning('商务评审步骤至少设置一条评审点')
          isPassVerification = false
          this.loading = false
          return
        }
        if (item.procedureType === '02' && !this.indicatorData.length) {
          this.$message.warning('技术评审步骤至少设置一条评审点')
          isPassVerification = false
          this.loading = false
          return
        }
      })
      // 判断商务技术评审当前最高分是否等于指标总分
      if (this.procedureType === '01') {
        if (this.businessCurrentScore !== this.businessTotalScore) {
          this.$message.warning('商务评审设置评审点最高分不等于商务评审步骤总分，请修改！')
          isPassVerification = false
          this.loading = false
        }
      }
      if (this.procedureType === '03') {
        if (this.businessCurrentScore !== this.businessTotalScore) {
          this.$message.warning('商务技术评审设置评审点最高分不等于商务技术评审步骤总分，请修改！')
          isPassVerification = false
          this.loading = false
        }
      }
      if (this.procedureType === '02') {
        if (this.technologyCurrentScore !== this.technologyTotalScore) {
          this.$message.warning('技术评审设置评审点最高分不等于技术评审步骤总分，请修改！')
          isPassVerification = false
          this.loading = false
        }
      }
      if (isPassVerification) {
        // 判断有没有价格评审
        if (this.priceReviewData.evaluationName) {
          // 保存价格评审接口
          saveOrUpdateEvaluationFactor(this.priceReviewData).then(res => {
            this.refreshPrice = true
            // 生效保存生效记录方法
            this.saveGetProjectDrawOffEntityId()
          }).catch(() => {
            this.loading = false
          })
          return
        }
        // 生效保存生效记录方法
        this.saveGetProjectDrawOffEntityId()
      }
    },
    // 上一步
    lastStep() {
      this.$router.push({
        path: '/procurement/procurementDrive/procurementDocumentsPurchase/setEvaluationSteps'
      })
    },
    // 指标数据
    getIndicatorData(data, type, currentScore, totalScore) {
      this.indicatorData = data
      this.procedureType = type
      // businessCurrentScore 商务评审当前最高分 businessTotalScore 商务评审总分 technologyCurrentScore 技术评审当前最高分 technologyTotalScore 技术评审总分
      // type 01 商务 02技术 03商务技术
      if (type === '01' || type === '03') {
        this.businessCurrentScore = currentScore
        this.businessTotalScore = totalScore
      }
      if (type === '02') {
        this.technologyCurrentScore = currentScore
        this.technologyTotalScore = totalScore
      }
    },
    // 价格评审数据
    getPriceReview(val, id) {
      this.priceReviewData = val
    },
    /*
    * 保存评审方式评审办法后端保存记录
    * @params packId 项目标段id
    */
    saveGetProjectDrawOffEntityId() {
      getProjectDrawOffEntityId(this.getTenderBase.packId).then(res => {
        // 指标生效方法
        this.effectiveIndicator()
      }).catch(() => {
        this.loading = false
      })
    },
    /*
    * 指标生效方法
    * @params packId 项目标段id
    */
    effectiveIndicator() {
      // 生效接口
      effectiveProcurementEvalFactorByPackId(this.getTenderBase.packId).then(res => {
        this.loading = false
        this.getDriveTask()// 刷新驱动开启下一节点
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style lang="less" scoped>
  /deep/.el-tabs__header {
    position: relative;
    margin: 0 0 15px;
    padding: 0 16px;
  }
  .proc_review /deep/.el-tabs__header{
   position: relative;
   padding: 0;
   margin-bottom: 10px;
  }
</style>
