<!--
  @description:采购立项-项目管理-采购文件-设置评标步骤
  @Modifier:yf
  @routerPath:/procurement/procurementDrive/procurementDocumentsPurchase/setEvaluationSteps
  @date:2020/7/-13:27
-->
<template>
  <div class="main">
    <div style="margin-bottom:10px">
      <gx-button :code="'001_004_001'" type="primary" @click="addStep">
        新增步骤
      </gx-button>
      <gx-button :code="'001_004_002'" type="primary" @click="stepUp('00')">
        步骤上移
      </gx-button>
      <gx-button :code="'001_004_003'" type="primary" @click="stepUp('01')">
        步骤下移
      </gx-button>
      <p style="display: inline-block">
        当前所有步骤总分为：<span class="red-star">{{ totalScore }}</span>分
      </p>
    </div>
    <section>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        @current-change="currentChange"
      >
        <el-table-column
          type="index"
          label="序号"
          width="100px"
          align="center"
        />
        <el-table-column
          label="评审步骤名称"
          align="center"
          prop="procedureName"
        />
        <el-table-column
          label="评审类型"
          align="center"
          prop="procedureType"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in reviewTypeList"
              v-if="scope.row.procedureType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="分数统计方式/通过条件"
          align="center"
          prop="scoreStatisticsWay"
        >
          <template slot-scope="scope">
            <template v-if="scope.row.procedureType === '00'">
              {{ filterDictText(summarizingWayList, scope.row.summaryWay) }}
              <!-- <span v-if="scope.row.summaryWay === '00'">少数服从多数</span>
              <span v-if="scope.row.summaryWay === '01'">全票通过</span> -->
            </template>
            <template v-else>
              {{ filterDictText(flosWayList, scope.row.scoreStatisticsWay) }}
              <!-- <span v-if="scope.row.scoreStatisticsWay === '00'">取平均值</span>
              <span v-if="scope.row.scoreStatisticsWay === '01'">去除最高最低取平均值</span> -->
            </template>
          </template>
        </el-table-column>
        <el-table-column
          label="分数"
          align="center"
          prop="procedureScore"
        />
        <el-table-column
          label="权重（%）"
          align="center"
          prop="procedureWeight"
        />
        <el-table-column
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <gx-link :code="'001_004_004'" type="primary" @click.stop="edit(scope.row)">
              [编辑]
            </gx-link>
            <gx-link v-if="scope.row.procedureType!=='00'" :code="'001_004_005'" type="primary" @click.stop="del(scope.row.id)">
              [删除]
            </gx-link>
          </template>
        </el-table-column>
      </el-table>
    </section>
    <div>
      <p class="red-star">
        提示：
      </p>
      <!-- <p class="red-star">
        1、评审顺序的数字意为专家进行评审步骤的顺序，选中步骤点击上移/下移可更换评审顺序。
      </p> -->
      <p class="red-star">
        1、完成评审步骤设置后，需点击下一步为各步骤添加评审点。
      </p>
      <p class="red-star">
        2、请在评标前完成评审指标设置，否则无法进行评标。
      </p>
    </div>
    <!-- 底部按钮 -->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <gx-button :code="'001_004_006'" type="primary" size="medium" @click="nextStep">
            下一步
          </gx-button>
        </div>
      </div>
    </div>
    <!-- 设置评标步骤组件弹框 -->
    <evaluationStepDialog :key="new Date()*1" :dialog-data="dialogData" :get-tender-base="getTenderBase" @watchChild="watchChild" />
  </div>
</template>

<script>
/* api*/
import { queryBidEvaluationProcedureListByPackId, deleteBidEvaluationProcedureListById, mobileSteps
} from '@/api/procurement/procurementProtdoc'
import { qryProtProjectProcurementIsChangeStatus
} from '@/api/procurement/procurementEvaluation'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 公共参数方法*/
import { procurementDocumentsGroupMixin } from
  '@/views/procurement/procurementDocuments/mixins/procurementDocumentsGroupMixin'// 立项采购-字典
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 组件*/
import evaluationStepDialog from './procurementEvaluationSteps-dialog'
export default {
  components: {
    evaluationStepDialog
  },
  inject: ['getTenderBase'],
  mixins: [ListMixin, procurementDocumentsGroupMixin],
  props: {

  },
  data() {
    return {
      loading: true,
      tableData: [],
      dialogData: { // 设置评标步骤弹框
        dialog: false,
        serialNumber: 0,
        totalScore: '0', // 当前总分
        id: '', // id存在时编辑 为空时新增
        procedureType: '' // 评审类型
      },
      totalScore: 100, // 总分
      currentData: [], // 当前选中的行数据
      getTenderBase: this.getTenderBase() // 获取项目基本信息
    }
  },
  created() {
    // 查询数据字典
    // this.inEvalStepCodes()
    this.queryBidEvaluationProcedureListByPackId()
  },
  methods: {
    filterDictText,
    // 根据标段id获取评标步骤集合
    queryBidEvaluationProcedureListByPackId() {
      const packId = this.getTenderBase.packId
      queryBidEvaluationProcedureListByPackId(packId).then(res => {
        this.loading = false
        this.tableData = res.data.bidEvaluationProcedureList
        this.totalScore = res.data.totalScore
        this.dialogData.totalScore = res.data.totalScore
        this.dialogData.serialNumber = res.data.bidEvaluationProcedureList.length
      }).catch(() => {
        this.loading = false
      })
    },
    // 新增
    addStep() {
      // 判断是否可变更数据
      this.canChangeData().then(res => {
        if (res.data) {
          // 清空id
          this.dialogData.id = ''
          this.dialogData.dialog = true
        }
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
      })
    },
    // 监听子组件是否添加或是更改成功，从而刷新列表
    watchChild(val) {
      if (val) {
        this.queryBidEvaluationProcedureListByPackId()
      }
    },
    // 编辑
    edit(row) {
      // 判断是否可变更数据
      this.canChangeData().then(res => {
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
        if (res.data) {
          // 评审id
          this.dialogData.id = row.id
          // 评审类型
          this.dialogData.procedureType = row.procedureType
          this.dialogData.dialog = true
        }
      })
    },
    // 删除
    del(id) {
      // 判断是否可变更数据
      this.canChangeData().then(res => {
        if (res.data) {
          this.$confirm('删除本步骤，将同步删除本步骤下的评审指标。是否确认删除？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            deleteBidEvaluationProcedureListById(id, this.getTenderBase.packId).then(res => {
              if (res.header.ret === '0') {
                this.queryBidEvaluationProcedureListByPackId()
              }
            })
          })
        }
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
      })
    },
    // 勾选数据
    currentChange(val) {
      this.checkData = val
    },
    // 步骤上/下移
    stepUp(status) {
      // 判断是否可变更数据 返回布尔值 true允许步骤上移下移 false不可
      this.canChangeData().then(res => {
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
        if (res.data && this.checkData) {
          // 判断选中的数据是不是第一条
          if (status === '00' && this.checkData.serialNumber === '1') {
            this.$message.warning('第一条数据不能上移')
            return
          }
          // 判断数据是不是最后一条
          const dataLength = this.tableData.length.toString()
          if (status === '01' && this.checkData.serialNumber === dataLength) {
            this.$message.warning('最后一条数据不能下移')
            return
          }
          // 判断选中的数据
          if (this.checkData.id) {
            const params = {
              id: this.checkData.id,
              serialNumber: this.checkData.serialNumber,
              status: status
            }
            mobileSteps(params).then(res => {
              this.queryBidEvaluationProcedureListByPackId()
            })
            return
          }
        } else {
          this.$message.warning('请选择一条数据')
        }
      })
    },
    // 下一步
    nextStep() {
      // 判断是否设置了评审步骤
      if (!this.tableData.length) {
        this.$message.warning('至少设置一条评审步骤')
        return
      }
      // 判断是否只设置了符合性评审
      const tableArr = this.tableData.filter(item => {
        return item.procedureType !== '00'
      })
      if (tableArr.length) {
        // 校验当前总分
        if (this.totalScore !== 100) {
          this.$message.warning('评审步骤总分应为100分')
          return
        }
      }
      this.$router.push({
        path: '/procurement/procurementDrive/procurementDocumentsPurchase/reviewIndicator'
      })
    },
    // 是否可以变更数据
    canChangeData() {
      return qryProtProjectProcurementIsChangeStatus(this.getTenderBase.packId)
    }
  }
}
</script>

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

