<!--
  @description: 供应商-提出问题
  @Modifier: 杨胜国
  @routerPath: /procurement/procurementDriveSupplier/procClarificationQuestionSupplier/procObjectionAdd
  @date: 2021-02-08 10:48:06
-->
<template>
  <div>
    <el-form
      ref="form"
      :rules="rules"
      :inline-message="true"
      :model="formData"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="问题内容" prop="questionDescribe" />
          </td>
          <td colspan="3">
            <gx-input
              v-model="formData.questionDescribe"
              gx-maxlength="varchar1000"
              type="textarea"
              placeholder="请输入"
            />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="上传问题文件" prop="clarificationAttachment" />
          </td>
          <td colspan="3">
            <upload
              ref="clarificationAttachment"
              :on-change="clarificationAttachmentFile"
              :data="clarificationAttachment"
              :auto-delete="true"
              :auto-upload="true"
              :file-size="200"
              title=""
              accept=".doc, .docx, .pdf, .png, .jpg, .zip;.jpeg;.txt;.xlsx;. xls;.ppt;.pptx;.rar"
              tip-text="上传附件格式（*.doc;*.docx;*.pdf;*.png;*.jpg;*.zip;*.jpeg;*.txt;*.xlsx;*.xls;*.ppt;*.pptx;*.rar）单个文件不得超过200M"
              file-ref="fileRef"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" type="primary" @click="saveQuestion('form')">
          提出问题
        </el-button>
        <el-button @click="back">
          返 回
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { getClarificationVesionNumber, saveQuestionInfo } from '@/api/procurement/procurementProject'// 澄清
/* 常用方法*/
import { randomData } from '@/assets/js/utils/index'
import { characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* 混合开发方法-参数字段*/
import { clarificationMixin } from '../mixins/clarificationMixin'// 澄清质疑-公用参数
/* 组件*/
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'ClarificationQuestionAdd',
  components: {
    upload
  },
  mixins: [clarificationMixin],
  data() {
    return {
      confirmLoading: false, // 控制按钮重复点击Loding
      formData: {
        packInfoDto: {
          packId: this.$route.params.packId,
          packName: this.$route.params.packName,
          packNo: this.$route.params.packNo
        },
        questionId: '', // 附件Id
        questionDescribe: '', // 标题
        tenderId: '', // 澄清回执id
        status: '01', // 00 保存 01 提交
        clarificationAttachment: '' // 澄清附件
      },
      rules: {
        questionDescribe: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 标题
        clarificationAttachment: [{ required: true, message: '请上传', trigger: 'blur' }] // 澄清附件
      },
      // 澄清附件
      clarificationAttachment: {
        bizId: '',
        fileType: 'procurement_question_content'
      }
    }
  },
  created() {
    // 问题Id
    this.formData.tenderId = this.$route.params.tenderId
    // 随机生成ID
    // this.formData.clarificationId = randomData()
    this.clarificationContent.bizId = this.clarificationAttachment.bizId = this.formData.questionId = randomData()
    // 采购人-新增时获取澄清版本
    // this.getClarificationVesionNumber()
  },
  methods: {
    // 营业执照扫描件
    clarificationContentFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'clarificationContent', 'true')// 上传了
      } else {
        this.$set(this.formData, 'clarificationContent', '')// 未上传
      }
    },
    // 营业执照扫描件
    clarificationAttachmentFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'clarificationAttachment', 'true')// 上传了
      } else {
        this.$set(this.formData, 'clarificationAttachment', '')// 未上传
      }
    },
    // 采购人-新增时获取澄清版本
    getClarificationVesionNumber() {
      const params = {
        packId: this.$route.params.packId
      }
      getClarificationVesionNumber(params).then(response => {
        this.formData.versionNumber = response.data.versionNumber
      }).catch(() => {
      })
    },
    // 提出问题
    saveQuestion(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm('是否确认提出问题?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            delete this.formData.clarificationContent
            delete this.formData.clarificationAttachment
            this.confirmLoading = true
            saveQuestionInfo(this.formData).then(response => {
              this.confirmLoading = false
              this.$message.success(response.header.msg)
              // 返回
              this.$router.push({
                name: 'procObjectionList'
              })
            }).catch(() => {
              this.confirmLoading = false
            })
          }).catch(() => {
          })
        }
      })
    },
    back() {
      this.$router.push({
        name: 'procObjectionList'
      })
    }
  }
}
</script>

<style scoped>
</style>
