<!--
  @description: 生成报告弹框
  @Modifier：ysg
  @date2020-11-19- 14:20
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    :lock-scroll="false"
    title="选择模板"
    width="840px"
    custom-class="el-dialog__body-p4 el-dialog_table_ct"
  >
    <el-form
      ref="fromData"
      :rules="rules"
      :model="formData"
      :inline-message="true"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item ref="batchNumber" prop="batchNumber" label="模板名称" />
          </td>
          <td colspan="3">
            <el-form-item
              ref="batchNumber"
              label=""
              prop="batchNumber"
            >
              <!-- batchNumber评审报告模板名称字典 01:评审报告.doc 02暂时隐藏-->
              <el-radio-group v-model="formData.batchNumber">
                <el-radio
                  v-for="(item) in reviewReportList"
                  :key="item.typecode"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </td>
        </tr>
      </table>
    </el-form>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" :loading="confirmLoading" @click="ensure('fromData')">
            确 定
          </el-button>
          <el-button @click="dialogData.dialog = false">
            取 消
          </el-button>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import {
  generateProcurementReportContentToWord // 平台端生成word评审报告

} from '@/api/procurement/procurementEvaluation'
/* 公共方法*/
import { download } from '@/assets/js/utils/index'

export default {
  name: 'SignatureSealDialog',
  inject: ['getTenderBase'],
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return
      }
    }
  },
  data() {
    return {
      confirmLoading: false,
      formData: {
        batchNumber: '01' // 评审办法 01:综合评估法 02:有效最低价
      },
      // 评审报告模板字典
      reviewReportList: [
        { typecode: '01', typename: '评审报告.doc' }
        // { typecode: '02', typename: '最低价法评审报告.doc' }
      ],
      getTenderBase: this.getTenderBase(), // 项目基本信息
      // 校验
      rules: {
        batchNumber: [{ required: true, message: '请选择', trigger: 'change' }] // 用途
      }
    }
  },
  watch: {
    'dialogData.dialog'(val) {
      if (val) {
        this.confirmLoading = false
      }
    }
  },
  methods: {
    // 确定提交
    ensure(formName) {
      this.confirmLoading = true
      this.$refs[formName].validate((valid, field) => {
        if (valid) {
          this.exportReviewReport(this.getTenderBase.packId) // 调用导出评审报告方法
        } else {
          this.confirmLoading = false
          return false
        }
      })
    },
    /*
    * 导出评审报告方法
    * @params {packId 项目标段id}
    * return word的文件流
    */
    exportReviewReport(packId) {
      const data = { packId }
      generateProcurementReportContentToWord(data).then(res => {
        download(res, '【' + this.getTenderBase.tenderName + '】评审报告.doc')
        this.$message.success({ message: '下载成功' })
        this.confirmLoading = false
        this.dialogData.dialog = false
      })
    }

  }
}
</script>

<style lang="less">
.el-dialog_table_ct{
  .el-dialog__body {
    height: 40vh;
    overflow: auto;
    padding: 8px;
  }
}
</style>
