<!--
  @description: 修改规则
  @Modifier: haofengxian
  @routerPath: /serviceConfig/bidBulletinTenderStageRuleUpdate
  @date: 2020-11-4-17:13
-->
<template>
  <div>
    <div class="title p0-16 clearfix">
      <div class="title-back pointer" @click="back">
        <i class="iconfont icon-fanhui mr10" />规则配置标段信息列表
      </div>
    </div>
    <section class="p0-16">
      <el-form
        ref="formBidderData"
        :model="formData"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item label="标段（包）名称" prop="packName" />
            </td>
            <td>{{ formData.packName }}</td>
            <td>
              <el-form-item label="标段（包）编号" prop="packNo" />
            </td>
            <td>{{ formData.packNo }}</td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="isTwoBidOpening" label="开标方式" prop="isTwoBidOpening" />
            </td>
            <td>
              <el-radio-group v-model="formData.isTwoBidOpening">
                <el-radio v-for="(item,index) in openingMethodList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td>
              <el-form-item ref="bidDocumentDecryptionMethod" label="投标文件解密方式" prop="bidDocumentDecryptionMethod" />
            </td>
            <td>
              <el-radio-group v-model="formData.bidDocumentDecryptionMethod">
                <el-radio v-for="(item,index) in decryptionMethodList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="tenderDocumentReceiveTime" label="标书获取时间" prop="tenderDocumentReceiveTime" />
            </td>
            <td>
              <el-date-picker
                v-model="formData.tenderDocumentReceiveTime[0]"
                :clearable="false"
                :format="elValueFormat"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="开始日期"
                style="width: 220px"
                @change="documentReceiveTimeChange"
              />
              至
              <el-date-picker
                v-model="formData.tenderDocumentReceiveTime[1]"
                :clearable="false"
                :format="elValueFormat"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="结束日期"
                style="width: 220px"
                @change="documentReceiveTimeChange"
              />
            </td>
            <td>
              <el-form-item ref="acceptAnsweringQuestionsEndTime" label="接受答疑截止时间" prop="acceptAnsweringQuestionsEndTime" />
            </td>
            <td>
              <el-date-picker
                v-model="formData.acceptAnsweringQuestionsEndTime"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                :clearable="false"
                :format="elValueFormat"
                type="datetime"
                placeholder="选择日期时间"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item ref="submitEndTime" label="投标截止时间" prop="submitEndTime" />
            </td>
            <td colspan="3">
              <el-date-picker
                v-model="formData.submitEndTime"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                :format="elValueFormat"
                type="datetime"
                style="width: 220px"
                placeholder="选择日期时间"
              />
            </td>
          </tr>
          <tr v-if="formData.isTwoBidOpening==='00'">
            <td>
              <el-form-item ref="openBidStartTime" label="开标时间" prop="openBidStartTime" />
            </td>
            <td colspan="3">
              <el-date-picker
                v-model="formData.openBidStartTime"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                :format="elValueFormat"
                type="datetime"
                style="width: 220px"
                placeholder="选择日期时间"
              />
            </td>
          </tr>
          <tr v-if="formData.isTwoBidOpening==='01'">
            <td>
              <el-form-item ref="technicalOpenBidStartTime" label="商务技术标开标时间（两步开标）" prop="technicalOpenBidStartTime" />
            </td>
            <td>
              <el-date-picker
                v-model="formData.technicalOpenBidStartTime"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                :format="elValueFormat"
                type="datetime"
                placeholder="选择日期时间"
              />
            </td>
            <td>
              <el-form-item ref="economicOpenBidStartTime" label="经济标开标时间（两步开标）" prop="economicOpenBidStartTime" />
            </td>
            <td>
              <el-date-picker
                v-model="formData.economicOpenBidStartTime"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                :format="elValueFormat"
                type="datetime"
                placeholder="选择日期时间"
              />
            </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="saveUpdateTenderStageRuleInfo">
              生 效
            </el-button>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
/* 接口*/
import { getTenderStageBizRuleAndTimeRuleByStageId, updateTenderStageRuleInfo } from '@api/bidding/bidBulletin'
import { tenderBulletinInitGroupMixin } from '../mixins/tenderBulletinInitGroupMixin'
import { formatTimeSecond } from '@/assets/js/utils' // 保存时间初始化00秒
export default {
  name: 'TenderStageRuleExpandUpload',
  mixins: [tenderBulletinInitGroupMixin],
  data() {
    return {
      confirmLoading: false,
      formData: {
        packName: '', // 标段名称
        packNo: '', //  标段编号
        tenderDocumentReceiveTime: [], // 标书获取时间 =》前端展示，不需要传给后端
        acceptAnsweringQuestionsEndTime: '', // 接受答疑截止时间
        bidDocumentDecryptionMethod: '', // 投标文件解密方式 00:投标人解密 01:服务端集中解密
        economicOpenBidStartTime: '', // 经济标开标时间(两步开标)
        isSubmitBidPrice: '', // 是否需要投标报价(两步开标时，第一阶段投标规则) 00:否 01:是
        isTwoBidOpening: '', // 是否两步开标 00:否 01:是
        openBidStartTime: '', // 开标时间
        stageId: '', // 阶段id
        submitEndTime: '', // 投标截止时间
        technicalOpenBidStartTime: '', // 技术标开标时间(两步开标)
        tenderDocumentReceiveEndTime: '', // 标书获取截止时间
        tenderDocumentReceiveStartTime: '' // 标书获取开始时间
      }
    }
  },
  created() {
    this.getTenderStageBizRuleAndTimeRule()
    // 获取开标方式字典初始化信息
    this.getBulletinOpenInitInfo()
  },
  methods: {
    // 保存组装数据
    assemblyData() {
      const data = {
        ...this.formData,
        stageId: this.$route.params.stageId
      }
      // 标书获取开始时间
      if (data.tenderDocumentReceiveStartTime) {
        data.tenderDocumentReceiveStartTime = formatTimeSecond(data.tenderDocumentReceiveStartTime)
      }
      // 标书获取截止时间
      if (data.tenderDocumentReceiveEndTime) {
        data.tenderDocumentReceiveEndTime = formatTimeSecond(data.tenderDocumentReceiveEndTime)
      }
      // 开标时间
      if (data.openBidStartTime) {
        data.openBidStartTime = formatTimeSecond(data.openBidStartTime)
      }
      // 技术标开标时间(两步开标)
      if (data.technicalOpenBidStartTime) {
        data.technicalOpenBidStartTime = formatTimeSecond(data.technicalOpenBidStartTime)
      }
      // 接受答疑截止时间
      if (data.acceptAnsweringQuestionsEndTime) {
        data.acceptAnsweringQuestionsEndTime = formatTimeSecond(data.acceptAnsweringQuestionsEndTime)
      }
      // 经济标开标时间(两步开标)
      if (data.economicOpenBidStartTime) {
        data.economicOpenBidStartTime = formatTimeSecond(data.economicOpenBidStartTime)
      }
      delete data.tenderDocumentReceiveTime // 标书获取截止时间
      return data
    },
    // 选择标书获取时间
    documentReceiveTimeChange() {
      // 标书获取开始时间
      this.formData.tenderDocumentReceiveStartTime = this.formData.tenderDocumentReceiveTime[0] && this.$Moment(this.formData.tenderDocumentReceiveTime[0]).format(this.momentSaveFormat)
      // 标书获取截止时间
      this.formData.tenderDocumentReceiveEndTime = this.formData.tenderDocumentReceiveTime[1] && this.$Moment(this.formData.tenderDocumentReceiveTime[1]).format(this.momentSaveFormat)
    },
    // 根据阶段id获取阶段业务规则和时间规则及规则扩展信息
    getTenderStageBizRuleAndTimeRule() {
      const stageId = this.$route.params.stageId
      getTenderStageBizRuleAndTimeRuleByStageId(stageId).then(res => {
        this.formData = Object.assign(this.formData, res.data)
        // 标书获取时间
        this.formData.tenderDocumentReceiveTime = [
          this.formData.tenderDocumentReceiveStartTime, // 开始时间
          this.formData.tenderDocumentReceiveEndTime // 结束时间
        ]
      }).catch(() => {
      })
    },
    // 保存修改规则信息
    saveUpdateTenderStageRuleInfo() {
      this.$confirm('确认生效吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.confirmLoading = true
        const paramsData = this.assemblyData()
        updateTenderStageRuleInfo(paramsData).then(res => {
          this.$message.success(res.header.msg)
          this.confirmLoading = false
          this.back()
        }).catch(() => {
          this.confirmLoading = false
        })
      }).catch(() => {
      })
    },
    back() {
      this.$router.push('/serviceConfig/bidBulletinTenderStageRule')
    }
  }
}
</script>

<style scoped>

</style>
