<!--
  @description: 新增澄清
  @Modifier: 郝定康
  @routerPath:/procurement/procurementDrive/procClarification/procClarificationReleaseAdd
  @date: 2021-02-09 13:41:28
-->
<template>
  <div>
    <el-form
      ref="fromData"
      :rules="rules"
      :inline-message="true"
      :model="formData"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="澄清标题" prop="clarificationTitle" />
          </td>
          <td colspan="3">
            <el-form-item prop="clarificationTitle">
              <gx-input
                v-model="formData.clarificationTitle"
                gx-maxlength="varchar200"
                type="text"
                placeholder="澄清标题"
              />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="澄清版本号" />
          </td>
          <td colspan="3">
            {{ formData.versionNumber }}
          </td>
          <!-- <td>
            <el-form-item label="是否变更时间" prop="isChangeTime" />
          </td>
          <td>
            <el-radio-group v-model="formData.isChangeTime">
              <el-radio
                v-for="(item,index) in isChangeTimeList"
                :key="index"
                :label="item.typecode"
              >
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </td> -->
        </tr>
        <!--是否变更时间 01-->
        <tr v-show="formData.isChangeTime==='01'">
          <td>
            <el-form-item label="报价截止时间" prop="quoteEndTime" />
          </td>
          <td>
            <el-date-picker
              v-model="formData.quoteEndTime"
              :format="elValueFormat"
              :clearable="false"
              :value-format="elValueSaveFormat"
              type="datetime"
              placeholder="选择日期时间"
            />
          </td>
          <td>
            <el-form-item label="报价有效期" prop="quoteValidity" />
          </td>
          <td>
            <el-date-picker
              v-model="formData.quoteValidity"
              :format="elValueFormat"
              :value-format="elValueSaveFormat"
              :clearable="false"
              type="datetime"
              placeholder="选择日期时间"
            />
          </td>
        </tr>
        <!-- <tr>
          <td>
            <el-form-item label="澄清内容文件" prop="clarificationContent" />
          </td>
          <td colspan="3">
            <upload
              ref="clarificationContent"
              :on-change="clarificationContentFile"
              :data="clarificationContent"
              :auto-delete="true"
              :auto-upload="true"
              :file-size="200"
              title=""
              accept=".doc,.docx,.pdf,.png,.jpg,.zip,.jpeg,.txt,.xls,.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> -->
        <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">
        <!--工作流进入不显示返回-->
        <gx-button :code="'001_013_002'" :loading="confirmLoading" type="primary" @click="saveClarificationInfo()">
          发布澄清
        </gx-button>
        <gx-button :code="'001_013_003'" @click="back">
          返 回
        </gx-button>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import { getClarificationVesionNumber, saveClarificationInfo } from '@/api/procurement/procurementProject'// 澄清
/* 公用方法*/
import { validateInput, characters1_50 } from '@/assets/js/validate'// 校验输入内容
import { randomData } from '@/assets/js/utils/index'
/* 混合开发方法-参数字段*/
import { clarificationGroupMixin } from '../../mixins/clarificationGroupMixin'// 澄清质疑-公用参数
import { clarificationMixin } from '../../mixins/clarificationMixin'// 澄清质疑-公用参数
/* 组件*/
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'ClarificationAdd',
  components: {
    // packComponent
    upload
  },
  inject: ['getTenderBase'],
  mixins: [clarificationMixin, clarificationGroupMixin],
  data() {
    return {
      tenderBase: this.getTenderBase(), // 项目信息
      confirmLoading: false,
      formData: {
        clarificationId: '', // 澄清id
        isChangeTime: '00', // 是否变更时间 00:否 01:是 补疑时有值
        clarificationType: '01', // 澄清类型 00答疑 01补疑 补疑时有值
        quoteEndTime: '', // 报价截止时间
        quoteValidity: '', // 报价有效期
        clarificationTitle: '', // 澄清标题
        status: '01', // 00 保存 01 提交
        tenderId: '', // 项目id
        versionNumber: '', // 版本号
        packInfoDto: {
          packId: '', // 标段id
          packName: '', // 标段名称
          packNo: '' // 标段编号
        },
        clarificationContent: '', // 澄清内容文件
        clarificationAttachment: '' // 澄清附件
      },
      // 校验
      rules: {
        clarificationTitle: [{ required: true, validator: characters1_50, trigger: 'blur' }, { validator: validateInput, trigger: 'blur' }], // 澄清标题
        isChangeTime: [{ required: true, message: '请选择', trigger: 'change' }], // 是否变更时间
        clarificationContent: [{ required: true, message: '请上传', trigger: 'blur' }], // 澄清内容文件
        clarificationAttachment: [{ required: true, message: '请上传', trigger: 'blur' }] // 澄清附件
      }
    }
  },
  created() {
    this.clarificationContent.bizId = this.clarificationAttachment.bizId = this.formData.clarificationId = randomData()
    this.formData.packInfoDto = {
      packId: this.tenderBase.packId, // 标段id
      packName: this.tenderBase.packName, // 标段名称
      packNo: this.tenderBase.packNo // 标段编号
    }
    this.formData.tenderId = this.tenderBase.tenderId
    // 新增时获取澄清版本
    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', '')// 未上传
      }
    },
    // 返回
    back() {
      this.$router.push({
        name: 'procClarificationList'
      })
    },
    // 新增时获取澄清版本
    getClarificationVesionNumber() {
      const data = {
        packId: this.$route.params.packId
      }
      getClarificationVesionNumber(data).then(res => {
        this.formData.versionNumber = res.data.versionNumber// 澄清版本号
      })
    },
    /*
    * 发布澄清
    * */
    saveClarificationInfo() {
      this.$refs.fromData.validate((valid, field) => {
        if (valid) { // 校验通过
          delete this.formData.clarificationContent
          delete this.formData.clarificationAttachment
          this.confirmLoading = true// btnLoding
          saveClarificationInfo(this.formData).then(response => {
            this.confirmLoading = false// btnLoding
            this.$message({
              message: '发布成功',
              type: 'success'
            })
            this.back()
          }).catch(() => {
            this.confirmLoading = false// btnLoding
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
