<!--
@description: ysg多轮报价开启新伦次弹框组件
@Modifier: ysg
procurementEvalutionNewRounds-dialog
@date: 2020-10-11 19:15
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    append-to-body
    title="开启新轮次"
    custom-class="el-dialog_table_open_man"
  >
    <section class="p8">
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table" style="margin-bottom:30px;">
          <tr>
            <td v-if="dialogData.tenderMethod==='13'">
              <el-form-item label="报价截止时间" prop="EndTime" />
            </td>
            <td v-if="dialogData.tenderMethod==='13'">
              <el-date-picker
                v-model="formData.EndTime"
                :value-format="elValueFormat"
                :format="elValueFormat"
                :disabled="dialogData.tenderMethod!=='13'"
                :picker-options="disabledPickerOptions"
                :default-time="defaultTimeDateTime"
                type="datetime"
                placeholder="选择结束时间"
              />
            </td>
            <td>
              <el-form-item ref="isLast" label="是否为最终轮次" prop="isLast" />
            </td>
            <td>
              <el-radio-group v-model="formData.isLast">
                <el-radio
                  v-for="(item) in ifAtlastRoundList"
                  :key="item.typecode"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <tr class="heauto">
            <td>
              <span>入围供应商</span>
            </td>
            <td colspan="3">
              <span>{{ nextWinningName }}</span>
            </td>
          </tr>
          <tr class="heauto">
            <td>
              <span>报价说明文件</span>
            </td>
            <td colspan="3">
              <upload
                ref="upload"
                class="upload-manage fl"
                :title="''"
                :on-change="principalFile"
                :data="procurementFile"
                :file-list="principalList"
                :file-size="200"
                :auto-delete="true"
                :auto-upload="true"
                :success="successList"
                tip-text="上传附件格式（*.doc;*.docx;*.pdf;*.png;*.jpg;*.zip;*.jpeg;*.txt;*.xlsx;*.xls;*.ppt;*.pptx;*.rar）单个文件不得超过200M"
                accept=".doc,.docx,.pdf,.png,.jpg,.zip,.jpeg,.txt,.xlsx,.xls,.ppt,.pptx,.rar"
                file-ref="fileRef"
                but-text="上传文件"
                :show-file-list="true"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button
        :loading="confirmLoading"
        type="primary"
        @click="ensure('form')"
      >{{ language.Determine }}</el-button>
      <el-button @click="dialogData.dialog = false">{{
        language.cancel
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
// vuex
import { mapGetters } from 'vuex'
// 公共方法
import { procurementOfferGroupMixin } from '../../procurementOffer/mixins/procurementOffGroupMixin'
import upload from '@comp/common/updownload/upload' // 附件上传组件
export default {
  name: 'ProcurementEvalutionNewRoundsDialogVue',
  components: {
    upload
  },
  mixins: [procurementOfferGroupMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {}
    },
    nextWinningName: {
      type: String,
      default: function() {
        return ''
      }
    },
    driveInfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      confirmLoading: false,
      // 开起结束时间
      formData: {
        EndTime: '', // 开启新伦次截止时间
        isLast: '' // 是否为最终轮次 00 否01 是
      },
      // 校验规则
      rules: {
        EndTime: [{ required: true, message: '请选择', trigger: 'blur' }], // 结束时间
        isLast: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      principalList: [],
      procurementFile: {
        bizId: '', // 业务主键Id
        fileType: 'prot_procurement_stage_remark_file_base' // 文件类型
      } // 附件信息
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.dialog'(val) {
      if (val) {
        // 弹框已打开
        // 清空元数据
        this.procurementFile.bizId = this.dialogData.offerStageId
        this.confirmLoading = false
        this.clearData()
      }
    }
  },
  created() {
    // this.procurementFile.bizId = this.nextRoundlist.offerStageId
  },
  methods: {
    // 选择信息-确定
    ensure(formName) {
      this.confirmLoading = true
      this.$refs[formName].validate((valid, field) => {
        if (valid) {
          // 获取开启徐黁次选择的数据
          const openNewRoundData = {
            EndTime: this.dialogData.tenderMethod === '13' ? this.$Moment(this.formData.EndTime).format(this.momentSaveFormat) : '', // 开启新伦次截止时间保留到s
            isLast: this.formData.isLast // 是否开启新伦次字段
          }
          this.$emit('consignContractInfo', openNewRoundData)
          // this.dialogData.dialog = false
        } else {
          this.confirmLoading = false
          return false
        }
      })
    },
    // 清楚时间
    clearData() {
      this.formData.EndTime = ''
      this.formData.isLast = ''
      this.$nextTick(() => {
        this.$refs.form.resetFields()
      })
    },
    // =============以下是附件==============

    // 预览
    preview(row) {
      this.isPreview = true
      // 拼接pdf的url路径
      const url = this.readImageUrl + row.pdfUrl
      // 加密处理
      this.pdfUrl = encodeURIComponent(url)
    },
    // 附件上传
    principalFile(file, fileList) {
      this.principalList = fileList
    },
    // 附件上传成功的回调
    successList(file) {
      this.loading = false
    }
  }
}
</script>

<style lang='less' scoped>
/deep/.el-dialog_table_open_man{
  width: 60%;
}
.heauto{
  height: 80px;
}
</style>
