<!--
  @description: 新增标中澄清
  @Modifier: 郝定康
  @routerPath:/procurement/procurementDrive/procEvaluateClarify/procEvaluateClarifyAdd
  @date: 2021-02-09 17:33:00
-->
<template>
  <div>
    <el-form
      ref="fromData"
      :rules="rules"
      :inline-message="true"
      :model="formData"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="澄清标题" prop="bidClarificationTitle" />
          </td>
          <td colspan="3">
            <el-form-item prop="bidClarificationTitle">
              <gx-input
                v-model="formData.bidClarificationTitle"
                gx-maxlength="varchar200"
                type="text"
                placeholder="澄清标题"
              />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="澄清回复截止时间" prop="clarificationEndTime" />
          </td>
          <td>
            <el-date-picker
              v-model="formData.clarificationEndTime"
              :format="elValueFormat"
              :clearable="false"
              :value-format="elValueSaveFormat"
              type="datetime"
              :picker-options="disabledPickerOptions"
              placeholder="选择日期时间"
            />
          </td>
        </tr>
        <!-- <tr>
          <td>
            <el-form-item label="澄清内容文件" prop="bidClarificationContent" />
          </td>
          <td colspan="3">
            <upload
              ref="bidClarificationContent"
              :on-change="bidClarificationContentFile"
              :data="bidClarificationContent"
              :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="bidClarificationAttachment" />
          </td>
          <td colspan="3">
            <upload
              ref="bidClarificationAttachment"
              :on-change="bidClarificationAttachmentFile"
              :data="bidClarificationAttachment"
              :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>
      <div class="mt10 mb10" style="font-size: 14px;">
        选择需澄清供应商
      </div>
      <el-table
        :data="supplierList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          label="供应商名称"
          align="center"
          prop="supplierName"
        />
      </el-table>
    </el-form>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <!--工作流进入不显示返回-->
        <gx-button :code="'001_014_003'" :loading="confirmLoading" type="primary" @click="saveBidClarificationInfo()">
          发布澄清
        </gx-button>
        <gx-button :code="'001_014_004'" @click="back">
          返 回
        </gx-button>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import { listSignUpSupplierList, saveBidClarificationInfo } 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,
      supplierList: [],
      formData: {
        packId: '', // 标段id
        packName: '', // 标段名称
        packNo: '', // 标段编号
        tenderId: '', // 项目id
        bidClarificationId: '', // 澄清id
        bidClarificationTitle: '', // 澄清标题
        clarificationEndTime: '', // 澄清截止时间
        bidClarificationContent: '', // 澄清内容文件
        bidClarificationAttachment: '', // 澄清附件
        bidClarificationSupplierInfoDtoList: [], // 需要澄清的供应商列表
        status: '01' // 00 保存 01 提交
      },
      // 校验
      rules: {
        bidClarificationTitle: [{ required: true, validator: characters1_50, trigger: 'blur' }, { validator: validateInput, trigger: 'blur' }], // 澄清标题
        isChangeTime: [{ required: true, message: '请选择', trigger: 'change' }], // 是否变更时间
        bidClarificationContent: [{ required: true, message: '请上传', trigger: 'blur' }], // 澄清内容文件
        bidClarificationAttachment: [{ required: true, message: '请上传', trigger: 'blur' }] // 澄清附件
      }
    }
  },
  created() {
    this.listSignUpSupplierList()
    this.bidClarificationContent.bizId = this.bidClarificationAttachment.bizId = this.formData.bidClarificationId = randomData()
    this.formData.packId = this.tenderBase.packId // 标段id
    this.formData.packName = this.tenderBase.packName // 标段名称
    this.formData.packNo = this.tenderBase.packNo // 标段编号
    this.formData.tenderId = this.tenderBase.tenderId // 项目id
  },
  methods: {
    listSignUpSupplierList() {
      const params = {
        packId: this.tenderBase.packId
      }
      listSignUpSupplierList(params).then(response => {
        this.supplierList = response.data
      }).catch(() => {
      })
    },
    handleSelectionChange(val) {
      this.formData.bidClarificationSupplierInfoDtoList = []
      val.forEach(item => {
        this.formData.bidClarificationSupplierInfoDtoList.push({
          supplierId: item.supplierId,
          supplierName: item.supplierName
        })
      })
    },
    // 澄清内容文件
    bidClarificationContentFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'bidClarificationContent', 'true')// 上传了
      } else {
        this.$set(this.formData, 'bidClarificationContent', '')// 未上传
      }
    },
    // 澄清附件
    bidClarificationAttachmentFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'bidClarificationAttachment', 'true')// 上传了
      } else {
        this.$set(this.formData, 'bidClarificationAttachment', '')// 未上传
      }
    },
    // 返回
    back() {
      this.$router.push({
        name: 'procEvaluateClarifyList'
      })
    },
    /*
    * 发布接口
    * */
    saveBidClarificationInfo() {
      if (this.formData.bidClarificationSupplierInfoDtoList.length === 0) {
        this.$message({
          message: '至少选择一家需要澄清的供应商',
          type: 'warning'
        })
        return false
      }
      this.$refs.fromData.validate((valid, field) => {
        if (valid) { // 校验通过
          delete this.formData.bidClarificationContent
          delete this.formData.bidClarificationAttachment
          this.confirmLoading = true// btnLoding
          saveBidClarificationInfo(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>
