<!--
  @description:采购立项-项目管理-采购文件-评审指标之商务评审
  @Modifier:sxm/yf
  @routerPath:
  @date:2020/9/23-9:49
-->
<template>
  <div>
    <div class="magin_b">
      <gx-button :code="'001_004_009'" type="primary" @click="addStep">
        新增评审点
      </gx-button>
      <gx-button :code="'001_004_010'" @click="downloadTem(procedureType)">
        下载模板
      </gx-button>
      <el-upload
        ref="uploads"
        :on-success="handleSuccess"
        :limit="1"
        :show-file-list="false"
        :headers="importHeaders"
        :action="action"
        multiple
        style="display: inline-block;margin-left: 10px"
      >
        <gx-button :code="'001_004_011'">
          导入指标
        </gx-button>
      </el-upload>
      <p v-if="procedureType !== '00'" style="display: inline-block">
        本步总分 <span class="red-star">{{ totalScore }}</span> 分，当前最高分之和  <span class="red-star">{{ currentHighestSum }}</span> 分
      </p>
    </div>
    <section>
      <el-table
        ref="smallTable"
        :data="tableData"
        height="404"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          label="评审点名称"
          align="center"
          prop="evaluationName"
        />
        <el-table-column
          v-if="procedureType !== '00'"
          label="最低分"
          align="center"
          prop="minScore"
        />
        <el-table-column
          v-if="procedureType !== '00'"
          label="最高分"
          align="center"
          prop="maxScore"
        />
        <el-table-column
          v-if="procedureType !== '00'"
          label="打分方式"
          align="center"
          prop="scoringMethod"
        >
          <template slot-scope="scope">
            {{ filterDictText(scoreWayList, scope.row.scoringMethod) }}
          </template>
        </el-table-column>
        <el-table-column
          label="评审标准"
          align="left"
          min-width="300"
          header-align="center"
          prop="evaluationStandard"
        />
        <el-table-column
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <gx-link :code="'001_004_012'" type="primary" @click.stop="edit(scope.row)">
              [编辑]
            </gx-link>
            <gx-link :code="'001_004_013'" type="primary" @click.stop="del(scope.row.id)">
              [删除]
            </gx-link>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <!-- <pagination :pagination-data="paginationData" @change="qryEvaluationFactorListByProcedureId" /> -->
    </section>
    <!-- 设置评标步骤组件弹框 -->
    <reviewPointDialog v-if="dialogData.dialog" :dialog-data="dialogData" :procedure-id="procedureId" :procedure-type="procedureType" @watchChild="watchChild" />
  </div>
</template>

<script>
/* api*/
import { downloadTemplate } from '@/api/procurement/datacenterDangtfz'
import { queryEvaluationFactorListByProcedureId, deleteEvaluationFactor, getBidEvaluationProcedureById } from '@/api/procurement/procurementProtdoc'
import { qryProtProjectProcurementIsChangeStatus
} from '@/api/procurement/procurementEvaluation'
/* 混合开发方法-参数字段*/
import { procurementDocumentsGroupMixin } from
  '@/views/procurement/procurementDocuments/mixins/procurementDocumentsGroupMixin'// 立项采购-字典
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { download } from '@/assets/js/utils/index'
import Cookies from 'js-cookie'
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 组件*/
import reviewPointDialog from './procurementReviewPoint-dialog'
// import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  components: {
    reviewPointDialog
    // pagination
  },
  mixins: [ListMixin, procurementDocumentsGroupMixin],
  props: {
    procedureId: {
      type: String,
      default: function() {
        return ''
      }
    },
    procedureType: {
      type: String,
      default: function() {
        return ''
      }
    },
    getTenderBase: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      tableData: [],
      dialogData: { // 设置评审点弹框
        id: '',
        dialog: false, // 是否显示
        lineTallGrade: '', // 当前点击行的最高分 默认0
        totalPoints: '' // 当前步骤的总积分

      },
      paginationData: {
        pageNo: null,
        pageSize: null,
        total: null
      },
      paginationDataId: {},
      action: `/bidprocurement/procurement-protdoc/procurementEvaluationFactor/importEvaluationFactorInfoList?procedureId=${this.procedureId}&procedureType=${this.procedureType}`,
      importHeaders: {},
      currentHighestSum: 0, // 当前最高分之和
      totalScore: 100 // 本步总分
    }
  },
  created() {
    // 查询数据字典
    // this.inEvalStepCodes()
    this.importHeaders['X-AUTH-TOKEN'] = Cookies.get('X-AUTH-TOKEN')
    this.qrtEvaluationFactorTotal()
  },
  methods: {
    filterDictText,
    // 新增评审点
    addStep() {
      // 判断专家是否已经下达评标指令
      this.canChangeData().then(res => {
        if (res.data) {
          this.dialogData.id = ''
          this.dialogData.totalPoints = this.currentHighestSum // 获取当前步骤的总积分
          this.dialogData.lineTallGrade = 0
          this.dialogData.dialog = true
        }
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
      })
    },
    // 根据评标步骤查询评审指标
    qryEvaluationFactorListByProcedureId(paginationData) {
      paginationData.procedureId = this.procedureId
      // 初始化当前最高分
      this.currentHighestSum = 0
      queryEvaluationFactorListByProcedureId(paginationData).then(res => {
        if (res.header.ret === '0') {
          this.tableData = [...res.data]
          // 分页注释
          // this.paginationData.total = res.data.total
          // 设置当前最高分之和
          this.tableData.forEach(item => {
            this.currentHighestSum += item.maxScore * 1
          })
          this.$emit('getIndicatorData', this.tableData, this.procedureType, this.currentHighestSum, this.totalScore)
        }
      })
    },
    // 查询本步骤总分
    qrtEvaluationFactorTotal() {
      getBidEvaluationProcedureById(this.procedureId, '100').then(res => {
        // 设置步骤总分
        this.totalScore = res.data.procedureScore || res.data.totalScore
        this.dialogData.totalScore = this.totalScore
        // 根据评标步骤查询评审指标
        this.qryEvaluationFactorListByProcedureId(this.paginationDataId)
      })
    },
    // 编辑
    edit(row) {
      // 判断专家是否已经下达评标指令
      this.canChangeData().then(res => {
        if (res.data) {
          this.dialogData.id = row.id
          if (row.maxScore) {
            this.dialogData.lineTallGrade = row.maxScore // 当前最高分
            this.dialogData.totalPoints = this.currentHighestSum // 获取当前步骤的总积分
          }
          this.dialogData.dialog = true // 打开弹框
        }
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
      })
    },
    // 删除
    del(id) {
      // 判断专家是否已经下达评标指令
      this.canChangeData().then(res => {
        if (!res.data) {
          this.$message.warning('已经下达评标指令，不允许更改评委名单、评审步骤和评审指标。')
        }
        if (res.data) {
          this.$confirm('是否确认删除本条评审指标？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            deleteEvaluationFactor(id, this.procedureId).then(res => {
              if (res.header.ret === '0') {
                this.$message({
                  type: 'success',
                  message: '删除成功'
                })
                this.qryEvaluationFactorListByProcedureId(this.paginationDataId)
              }
            })
          })
        }
      })
    },
    // 监听子组件变化
    watchChild(val) {
      if (val) {
        this.qryEvaluationFactorListByProcedureId(this.paginationDataId)
      }
    },
    // 下载模板
    downloadTem(type) {
      if (this.procedureType !== '00') {
        const data = {
          templateType: 'P_T_P_EVALUATION_DFXPSZBTEMPLATE'
        }
        downloadTemplate(data).then(res => {
          if (type === '01') {
            download(res, '商务评审.xlsx')
          }
          if (type === '02') {
            download(res, '技术评审.xlsx')
          }
          if (type === '03') {
            download(res, '商务技术评审.xlsx')
          }
        })
        return
      }
      const data = {
        templateType: 'P_T_P_EVALUATION_FHXPSZBTEMPLATE'
      }
      downloadTemplate(data).then(res => {
        download(res, '符合性评审.xlsx')
      })
    },
    // 模板上传成功时触发
    handleSuccess(response, file, fileList) {
      if (response.header.ret === '0') {
        this.$message.success('导入成功')
        this.$refs.uploads.clearFiles()
        this.qryEvaluationFactorListByProcedureId(this.paginationDataId)
      } else {
        this.$refs.uploads.clearFiles()
        this.$message.error(response.header.msg)
        this.qryEvaluationFactorListByProcedureId(this.paginationDataId)
      }
    },
    // 是否可以变更数据
    canChangeData() {
      return qryProtProjectProcurementIsChangeStatus(this.getTenderBase.packId)
    }
  }
}
</script>

<style lang="less" scoped>
  .magin_b{
    margin-bottom: 10px;
  }
</style>

