<!--
  @description:招标-招标公告-新版招标公告
  @Modifier: 张慢慢
  @routerPath: /bidding/projectDrive/bulletin/newTenderBulletin-detail
  @date: 2021/05/20-09:16
-->
<template>
  <div>
    <div class="main">
      <el-form
        ref="form"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <!--公告标题-->
          <tr>
            <td>
              <el-form-item
                ref="title"
                placeholder="最多允许输入200个字符"
                show-word-limit
                label="公告标题"
                prop="title"
              />
            </td>
            <td colspan="3">
              <gx-input v-model.trim="formData.title" gx-maxlength="varchar200" placeholder="公告标题" />
            </td>
          </tr>
          <tr>
            <td>
              <!--标段划分情况-->
              <el-form-item
                ref="buyersLinkerAddress"
                label="标段划分情况"
                prop="buyersLinkerAddress"
              />
            </td>
            <td colspan="3">
              <!--isPack===01 分包-->
              <span v-if="tenderBase.isPack==='01'">本项目有{{ formData.projectPackageNum }}个标段（包）</span>
              <span v-else>本项未划分标段（包）</span>
            </td>
          </tr>
          <tr v-if="tenderBase.isPack==='01'">
            <td>
              <!--标段划分情况-->
              <el-form-item
                ref="bulletinPublishMethod"
                label="本次招标标段"
                prop="bulletinPublishMethod"
              />
            </td>
            <td colspan="3">
              <el-radio-group v-model="formData.bulletinPublishMethod" :disabled="formData.bulletinPublishMethodChange==='00'">
                <el-radio v-for="(item,index) in publishMethodList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <!--
            选择标段（包）
            按标段发布时展示 bulletinPublishMethod==='01'
          -->
          <tr v-if="formData.bulletinPublishMethod==='01'">
            <td>
              <el-form-item
                required
                label="选择标段（包）"
              />
            </td>
            <td colspan="3">
              <packComponent ref="packComp" :selet-pack-list="seletPackList" :bulletin-type="tenderBase.bulletinType" @seletPackInfo="seletPackInfo" />
            </td>
          </tr>
          <!--项目资金-->
          <tr>
            <td>
              <el-form-item
                ref="projectMoney"
                label="项目资金"
                prop="projectMoney"
              />
            </td>
            <td colspan="3">
              <money :thousands="true" :unit-stust="true" :great="true" :money-value="formData" name="projectMoney" />
            </td>
          </tr>
          <!--标书获取时间-->
          <tr>
            <td>
              <el-form-item
                ref="tenderDocumentReceiveEndTime"
                :label="dict.tenderDocumentReceiveTimeLabel"
                prop="tenderDocumentReceiveEndTime"
              />
            </td>
            <td colspan="3" class="tenderDocumentReceiveTime">
              <el-date-picker
                v-model="formData.tenderDocumentReceiveStartTime"
                :clearable="false"
                :picker-options="disabledPickerOptions"
                :format="elValueFormat"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="开始日期"
                @change="documentReceiveTimeChange('start')"
              />
              至
              <el-date-picker
                v-model="formData.tenderDocumentReceiveEndTime"
                class="defaultTimeDateTime"
                :clearable="false"
                :picker-options="disabledPickerOptions"
                :format="elValueFormat"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="结束日期"
                @change="documentReceiveTimeChange('end')"
              />
              <span style="padding-left: 10px;">共
                <span v-if="tenderDocumentReceiveDays===''" style="padding-left: 16px" />
                <span style="padding: 0 4px">{{ tenderDocumentReceiveDays }}</span>天
              </span>
            </td>
          </tr>
          <!--是否需要报名-->
          <!-- biddingbulletinIsShowNeedSingup 00不显示 01显示 根据配置判断是否需要显示 是否需要报名字段 -->
          <tr v-if="biddingbulletinIsShowNeedSingup === '01'">
            <td>
              <el-form-item ref="isNeedSignup" label="是否需要报名" prop="isNeedSignup" />
            </td>
            <td colspan="3">
              <!--是否需要报名-->
              <el-radio-group v-model="formData.isNeedSignup">
                <el-radio v-for="(item,index) in isNeedSignupList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <!--报名时间-->
          <!--
            * 1、先判断 biddingbulletinIsShowNeedSingup 01显示 || biddingbulletinIsNeedSingup 01显示
            * 2、再根据项目判断非依法需要显示 其它条件不显示(isLegalTender 00非依法必招) isNeedSignup 00不需要 01需要
          -->
          <tr v-if="biddingbulletinIsShowNeedSingup === '01' || biddingbulletinIsNeedSingup === '01'">
            <template v-if="legalLimitData.isLegalTender === '00' && formData.isNeedSignup === '01'">
              <td>
                <el-form-item

                  ref="signupStartTime"
                  label="报名时间"
                  prop="signupStartTime"
                />
              </td>
              <td colspan="3" class="tenderDocumentReceiveTime">
                <el-date-picker
                  v-model="formData.signupStartTime"
                  :clearable="false"
                  :picker-options="disabledPickerOptions"
                  :format="elValueFormat"
                  :default-time="defaultTimeDateTime"
                  :value-format="elValueSaveFormat"
                  type="datetime"
                  placeholder="开始日期"
                  @change="signupStartTimeChange"
                />
                至
                <el-date-picker
                  v-model="formData.signupEndTime"
                  :clearable="false"
                  :picker-options="signupTimeDisabled"
                  :format="elValueFormat"
                  :default-time="defaultTimeDateTime"
                  :value-format="elValueSaveFormat"
                  type="datetime"
                  placeholder="结束日期"
                />
                <span style="padding-left: 10px;">共
                  <span v-if="signupDays===''" style="padding-left: 16px" />
                  <span style="padding: 0 4px">{{ signupDays }}</span>天
                </span>
              </td>
              <template />
            </template>
          </tr>
          <tr>
            <td>
              <el-form-item
                ref="acceptAnsweringQuestionsEndTime"
                label="接收答疑截止时间"
                prop="acceptAnsweringQuestionsEndTime"
              />
            </td>
            <td colspan="">
              <el-date-picker
                v-model="formData.acceptAnsweringQuestionsEndTime"
                :picker-options="disabledPickerOptions"
                :clearable="false"
                :format="elValueFormat"
                :value-format="elValueSaveFormat"
                :default-time="defaultTimeDateTime"
                type="datetime"
                placeholder="选择日期时间"
                @change="acceptAnsweringQuestionsEndTimeChange('acceptAnsweringQuestionsEndTime')"
              />
            </td>
            <td>
              <el-form-item
                ref="submitEndTime"
                :label="dict.submitEndTimeLabel"
                prop="submitEndTime"
              />
            </td>
            <td colspan="">
              <el-date-picker
                v-model="formData.submitEndTime"
                :picker-options="disabledPickerOptions"
                :value-format="elValueSaveFormat"
                :default-time="defaultTimeDateTime"
                :clearable="false"
                :format="elValueFormat"
                type="datetime"
                placeholder="选择日期时间"
                @change="acceptAnsweringQuestionsEndTimeChange('submitEndTime')"
              />
            </td>
          </tr>
          <tr>
            <!--标书解密方式-->
            <td>
              <el-form-item
                ref="bidDocumentDecryptionMethod"
                :label="dict.bidDocumentDecryptionMethodLabel"
                prop="bidDocumentDecryptionMethod"
              />
            </td>
            <td>
              <el-radio-group v-show="isShowDecryptMethod" 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>
            <!--开标方式-->
            <!--tenderBase.stageType 00资审 01后审-->
            <td>
              <el-form-item
                v-if="tenderBase.stageType==='01'"
                ref="isTwoBidOpening"
                label="开标方式"
                prop="isTwoBidOpening"
              />
            </td>
            <td>
              <el-radio-group v-if="tenderBase.stageType==='01'" 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>
          </tr>
          <!-- tenderBase.stageType === '00'资审 formData.isTwoBidOpening==='00'一步开标 -->
          <tr v-if="formData.isTwoBidOpening==='00' || tenderBase.stageType === '00'">
            <td>
              <el-form-item
                ref="openBidStartTime"
                :label="dict.kbsj"
                prop="openBidStartTime"
              />
            </td>
            <td>
              <el-date-picker
                v-model="formData.openBidStartTime"
                :picker-options="disabledPickerOptions"
                :default-time="defaultTimeDateTime"
                :value-format="elValueSaveFormat"
                :clearable="false"
                :format="elValueFormat"
                type="datetime"
                placeholder="选择日期时间"
                @change="openBidStartTimeChange"
              />
            </td>
            <td />
            <td />
          </tr>
          <tr v-if="formData.isTwoBidOpening==='01'">
            <td>
              <!--第一阶段投标规则-->
              <el-form-item
                ref="isSubmitBidPrice"
                label="第一阶段投标规则"
                prop="isSubmitBidPrice"
              />
            </td>
            <td>
              <el-radio-group v-model="formData.isSubmitBidPrice">
                <el-radio v-for="(item,index) in isSubmitBidPriceList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td>
              <!--商务技术开标时间-->
              <el-form-item
                ref="technicalOpenBidStartTime"
                label="商务技术开标时间"
                prop="timeData"
              />
            </td>
            <td>
              <el-date-picker
                v-model="formData.technicalOpenBidStartTime"
                :picker-options="disabledPickerOptions"
                :clearable="false"
                :default-time="defaultTimeDateTime"
                :format="elValueFormat"
                :value-format="elValueSaveFormat"
                type="datetime"
                placeholder="选择日期时间"
                @change="openBidStartTimeChange"
              />
            </td>
          </tr>
          <tr>
            <td>
              <!--标书获取方式-->
              <el-form-item
                ref="tenderDocumentReceiveMethod"
                :label="dict.tenderDocumentReceiveMethodLabel"
                prop="tenderDocumentReceiveMethod"
              />
            </td>
            <td>
              <el-radio-group v-model="formData.tenderDocumentReceiveMethod">
                <el-radio v-for="(item,index) in receiveMethodList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td>
              <!--支付方式-->
              <el-form-item
                v-show="formData.tenderDocumentReceiveMethod === '00'"
                required
                label="支付方式"
              />
            </td>
            <td>
              <el-checkbox-group
                v-show="formData.tenderDocumentReceiveMethod === '00'"
                v-model="formData.payModeCode"
                style="display: inline-block;margin-right:16px;"
              >
                <el-checkbox
                  v-for="(item) in paytypeList"
                  :key="item.id"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-checkbox>
              </el-checkbox-group>
            </td>
          </tr>
          <tr>
            <td style="border-bottom:none">
              <el-form-item
                ref="tenderDocumentSaleMethod"
                :label="dict.tenderDocumentSaleMethodLabel"
                prop="tenderDocumentSaleMethod"
              />
            </td>
            <td style="background: #fff;border-right: none;border-bottom: none">
              <el-radio-group v-model="formData.tenderDocumentSaleMethod" :disabled="formData.tenderDocumentSaleMethodChange==='00'">
                <el-radio v-for="(item,index) in documentMethodList" :key="index" :label="item.typecode" :disabled="tenderBase.isPack==='00' && item.typecode === '00'">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td colspan="2" style="background: #fff;border-left: none;padding-left: 0;border-bottom: none">
              <money
                v-if="formData.tenderDocumentSaleMethod==='01'"
                :unit-stust="true"
                :money-value="formData"
                name="documentPrice"
                style="display: inline-block"
              />
              <el-button
                size="mini"
                style="color: red;margin-left: 16px"
                type="text"
              >
                注：金额为0或不填即为免费
              </el-button>
            </td>
          </tr>
          <tr style="width: 100%">
            <td colspan="4" style="background: #fff;border: none;padding: 0">
              <el-form-item v-if="formData.tenderDocumentSaleMethod==='00'" class="form_item_table">
                <div>
                  <el-table :data="formData.tenderDocumentPriceInfoDto">
                    <el-table-column type="index" label="序号" width="60" align="center" />
                    <el-table-column header-align="center" width="200px" label="标段编号" prop="packNo" align="center" />
                    <el-table-column header-align="center" label="标段名称" prop="packName" />
                    <el-table-column header-align="center" width="220px" prop="documentPrice" :label="dict.documentPriceTitle">
                      <template slot-scope="scope">
                        <money :money-value="scope.row" name="documentPrice" />
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <el-button
                  size="mini"
                  class="fr"
                  type="text"
                  style="padding-top: 20px;padding-bottom: 10px"
                  @click="msetKeyMoney"
                >
                  批量设置金额
                </el-button>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>
              <!--发布媒介-->
              <el-form-item
                ref="mediaPartners"
                label="发布媒介"
                prop="mediaPartners"
              />
            </td>
            <td colspan="3">
              <el-checkbox-group v-model="formData.mediaPartners">
                <el-checkbox
                  v-for="(item) in mediaPartnersList"
                  :key="item.typecode"
                  :label="item.typecode"
                  :disabled="item.typecode === '00'"
                >
                  {{ item.typename }}
                </el-checkbox>
              </el-checkbox-group>
            </td>
          </tr>
          <!--保证金收取方式 资审不展示-->
          <tr v-if="tenderBase.bulletinType==='01'">
            <td>
              <el-form-item
                ref="bailCollectMode"
                label="保证金收取方式"
                prop="bailCollectMode"
              />
            </td>
            <td colspan="3">
              <el-radio-group v-model="formData.bailCollectMode">
                <el-radio v-for="(item,index) in bailPriceModeList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <!-- 资审不展示 -->
          <tr v-if="tenderBase.bulletinType==='01'">
            <td style="border-bottom:none">
              <el-form-item
                ref="receiveBailPriceMethod"
                label="保证金设置"
                prop="receiveBailPriceMethod"
              />
            </td>
            <td style="background: #fff;border-right: none;border-bottom: none">
              <el-radio-group
                v-model="formData.receiveBailPriceMethod"
                :disabled="formData.receiveBailPriceMethodChange==='00'"
              >
                <el-radio v-for="(item,index) in bailPriceMethodList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
            <td colspan="2" style="background: #fff;border-left: none;padding-left: 0;border-bottom: none">
              <money
                v-if="formData.receiveBailPriceMethod==='01'"
                :unit-stust="true"
                :money-value="formData"
                name="bailPrice"
                style="display: inline-block"
              />
              <el-button
                size="mini"
                style="color: red;margin-left: 16px"
                type="text"
              >
                注：金额为0或不填即为免费
              </el-button>
            </td>
          </tr>
          <!-- 资审不展示 -->
          <tr v-if="tenderBase.bulletinType==='01'" style="width: 100%">
            <td colspan="4" style="background: #fff;border: none;padding: 0">
              <el-form-item v-if="formData.receiveBailPriceMethod==='00'" class="form_item_table">
                <div>
                  <el-table :data="formData.tenderBailPriceInfoDto">
                    <el-table-column type="index" label="序号" width="60" align="center" />
                    <el-table-column header-align="center" width="200px" label="标段编号" prop="packNo" align="center" />
                    <el-table-column header-align="center" label="标段名称" prop="packName" />
                    <el-table-column header-align="center" width="220px" label="保证金（元）" prop="bailPrice">
                      <template slot-scope="scope">
                        <money :money-value="scope.row" name="bailPrice" />
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <el-button
                  size="mini"
                  class="fr"
                  type="text"
                  style="padding-top: 20px;padding-bottom: 10px"
                  @click="msetKeyMoney2"
                >
                  批量设置金额
                </el-button>
              </el-form-item>
            </td>
          </tr>
        </table>
      </el-form>
    </div>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" :loading="confirmLoading" @click="save('form')">
            保存
          </el-button>
          <el-button type="primary" @click="openToolsUrl">
            使用工具制作{{ bulletinTitle }}
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* api*/
import {
  queryBaseTenderBulletinSimpleInfo, // 获取招标公告信息（简易版）
  saveBaseTenderBulletinSimpleInfo, // 招标公告保存（简易版）
  getOpenToolsUrl, // 获取工具url
  queryBaseTenderBulletinInfo, // 查询是否公告提交
  listUnmarkedBulletinPackage // 获取标段
} from '@/api/bidding/bidBulletin'
import { listIsTwoBidOpeningByStageIds } from '@/api/bidding/biddingProject'
import { getSystemConfigValueByConfigType } from '@/api/common/systemConfigCenter'
/* 组件*/
import cascader from '@comp/common/cascader'// 地区三级联动
import packComponent from '@comp/bidding/packComponent/packComponent'
import money from '@comp/common/money/money'
/* 混合开发方法-参数字段*/
import { tenderBulletinInitGroupMixin } from './../mixins/tenderBulletinInitGroupMixin'// 字典信息
import { newTenderBulletinInitGroupMixin } from './../mixins/newTenderBulletinInitGroupMixin' // 简易版招标获取字典信息和校验时间方法
import { tenderStageTimeRule } from './../mixins/tenderStageTimeRule'// 招标公告时间规则
import { openInfoDecryptMethodConfig } from '../mixins/openInfoDecryptMethodConfig' // 解密方式配置
/* 公用方法*/
import { characters1_auto, validateInput, moneyRegular } from '@/assets/js/validate'// 校验输入内容
export default {
  name: 'BidProjectBase',
  components: {
    cascader, // 地区三级联动
    packComponent,
    money
  },
  mixins: [tenderBulletinInitGroupMixin, newTenderBulletinInitGroupMixin, tenderStageTimeRule, openInfoDecryptMethodConfig],
  data() {
    return {
      confirmLoading: false, // 暂存Loding
      // 项目基本信息
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      tenderId: this.$route.query.id, // 项目Id
      bulletinId: this.$route.query.bulletinId, // 公告Id
      tenderDocumentReceiveDays: '', // 标书获取开始时间-标书获取截止时间时间差 天数
      signupDays: '', // 报名开始时间-报名截止时间时间差 天数
      formData: {
        tenderId: '', // 项目Id
        tenderName: '', // 项目名称
        title: '', // 公告标题
        projectPackageNum: '', // 项目标段数量
        bulletinPublishMethod: '01', // 本次招标标段  00:按项目发布 01:按标段发布
        bulletinPublishMethodChange: '01', // 本次招标标段是否可以修改 01 可以修改 00 不可以修改
        listMarkedBulletinPackage: [], // 已选标段（包）列表=》前端展示，不需要传给后端
        packIds: [], // 已选标段（包）Id=》存储时才使用
        projectMoney: '', // 项目资金
        tenderDocumentReceiveStartTime: '', // 标书获取开始时间
        tenderDocumentReceiveEndTime: '', // 标书获取截止时间
        acceptAnsweringQuestionsEndTime: '', // 接收答疑截止时间
        bidDocumentDecryptionMethod: '', // 标书解密方式 00 投标人解密 01 服务器集中解密
        isTwoBidOpening: '00', // 开标方式 00 一步开标法 01两步开标法
        isSubmitBidPrice: '00', // 第一阶段投标规则 00 需要投标报价 01 不需要投标报价
        twoBidOpeningMethod: '00', // 两步法开标顺序 00 先开商务技术后经济 01 先经济后商务技术
        openBidStartTime: '', // 开标时间
        technicalOpenBidStartTime: '', // 商务技术开标时间
        economicOpenBidStartTime: '', // 经济开标时间
        tenderDocumentReceiveMethod: '00', // 标书获取方式 00 电子招标 01 线下招标
        payModeCode: [], // 支付方式编码信息
        accountNumber: '', // 中金卡号
        accountNumberId: '', // 中金卡号ID
        tenderDocumentSaleMethodChange: '01', // 标书售卖方式 是否可以变更 01:可以变更 00:不可以变更
        tenderDocumentSaleMethod: '', // 标书金额设置 00 按标段售卖 01 按项目售卖
        documentPrice: '', // 按項目售卖金额-标书费
        mediaPartners: ['00', '01'], // 发布媒介 00 门户网站 01 中国公共服务平台 全选
        bailPriceMethod: '00', // 保障金收取方式
        receiveBailPriceMethodChange: '01', // 是否可以变更 01:可以变更 00:不可以变更
        receiveBailPriceMethod: '', // 保证金设置 00 按标段售卖 01 按项目售卖
        tenderBailPriceInfoDto: [], // 保证金集合
        tenderDocumentPriceInfoDto: [], // 标书费集合
        isNeedSignup: '', // 是否需要显示报名
        signupStartTime: '', // 报名开始时间
        signupEndTime: '' // 报名截止时间
      },
      seletPackList: [], // 获取的已选择的标段（包）
      // 校验输入内容
      rules: {
        title: [{ required: true, validator: validateInput, trigger: 'blur' }], // 公告标题
        bulletinPublishMethod: [{ required: true, message: '请选择', trigger: 'change' }], // 本次招标标段
        projectMoney: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 项目资金
        tenderDocumentReceiveEndTime: [{ required: true, message: '请选择', trigger: 'change' }], // 标书获取时间
        acceptAnsweringQuestionsEndTime: [{ required: true, message: '请选择', trigger: 'change' }], // 接收答疑截止时间
        submitEndTime: [{ required: true, message: '请选择', trigger: 'change' }], // 投标截止时间
        bidDocumentDecryptionMethod: [{ required: true, message: '请选择', trigger: 'change' }], // 标书解密方式
        isSubmitBidPrice: [{ required: true, message: '请选择', trigger: 'change' }], // 第一阶段投标规则
        openBidStartTime: [{ required: true, message: '请选择', trigger: 'change' }], // 开标时间
        technicalOpenBidStartTime: [{ required: true, message: '请选择', trigger: 'change' }], // 商务技术开标时间
        economicOpenBidStartTime: [{ required: true, message: '请选择', trigger: 'change' }], // 经济开标时间
        receiveBailPriceMethod: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 保证金设置
        // buildAddress: [{ required: true, message: '请选择', trigger: 'change' }], // 建设地点
      },
      bulletinInterval: '', // 定时器-公告预览
      signupTimeDisabled: {
        // 报名结束时间限制
        disabledDate: time => {
          const beginVal = Date.parse(new Date(this.formData.signupStartTime))
          if (beginVal) {
            return time.getTime() < beginVal
          }
        }
      },
      biddingbulletinIsShowNeedSingup: '00', // 系统配置是否显示 是否需要报名 00不显示 01显示
      biddingbulletinIsNeedSingup: '00' // 是否显示报名时间 00不展示 01展示
    }
  },
  watch: {
    // 标书获取时间
    'formData.tenderDocumentReceiveStartTime'(val) {
      if (val && this.formData.tenderDocumentReceiveEndTime) {
        this.tenderDocumentReceiveDays = this.momentDiff('days', val, this.formData.tenderDocumentReceiveEndTime)// 时间差
      } else {
        this.tenderDocumentReceiveDays = ''
      }
    },
    // 标书获取时间
    'formData.tenderDocumentReceiveEndTime'(val) {
      if (val && this.formData.tenderDocumentReceiveStartTime) {
        this.tenderDocumentReceiveDays = this.momentDiff('days', this.formData.tenderDocumentReceiveStartTime, val)// 时间差
      } else {
        this.tenderDocumentReceiveDays = ''
      }
    },
    // 两步法开标顺序
    'formData.twoBidOpeningMethod'() {
      this.initTimeRule()// 设置开标时间和投标截止时间相同
    },
    // 开标方式
    'formData.isTwoBidOpening'() {
      this.initTimeRule()// 设置开标时间和投标截止时间相同
    },
    // 投标截止时间
    'timeRuleInfo.submitEndTime'() {
      this.initTimeRule()// 设置开标时间和投标截止时间相同
    },
    // 监听 招标标段
    'formData.bulletinPublishMethod'(val) {
      if (val === '00') {
        // 获取所有标段
        this.initPackList()
      } else {
        this.seletPackInfo(this.seletPackList)
      }
      this.$forceUpdate() // 数据强制刷新
    },
    // 报名截止时间 signupDays
    'formData.signupEndTime'(val) {
      if (val && this.formData.signupStartTime) {
        this.signupDays = this.momentDiff('days', this.formData.signupStartTime, val)// 时间差
      } else {
        this.signupDays = ''
      }
    }
  },
  created() {
    this.initDictionary() // 初始化字典信息
    this.initData() // 初始化数据
    this.getSystemConfigValueByConfigType() // 系统配置是否显示 是否需要报名
    this.getSystemConfigNeedSignup() // 系统配置是否显示 报名时间字段
  },
  destroyed() {
    clearInterval(this.bulletinInterval)// 清除定时器
  },
  methods: {
    // 初始化字典信息
    initDictionary() {
      this.getBulletinAllDictionariesInitInfo()// 所有字典数据
    },
    // 初始化
    initData() {
      const params = {
        bulletinId: this.bulletinId, // 公告Id
        tenderId: this.tenderId, // 项目Id
        bulletinType: this.tenderBase.bulletinType // 公告类型 21资审文件 01 招标公告
      }
      // 获取详情
      queryBaseTenderBulletinSimpleInfo(params).then((res) => {
        this.formData = res.data
        // 当标题为空时
        if (!this.formData.title) {
          if (this.tenderBase.bulletinType === '01') {
            this.formData.title = `【${this.formData.tenderName}】招标公告`// 公告标题
          } else if (this.tenderBase.bulletinType === '21') {
            this.formData.title = `【${this.formData.tenderName}】资审公告`// 公告标题
          }
        }
        this.seletPackList = this.formData.listMarkedBulletinPackage || [] // 获取的已选择的标段（包）
        if (!this.formData.bulletinPublishMethod) {
          // 为空时设置默认
          this.formData.bulletinPublishMethod = '00' // 本次招标标段  00:按项目发布 01:按标段发布
        }
        // 开标方式
        if (!this.formData.isTwoBidOpening) {
          // 根据标段id集合获取是否两步开标-华能项目
          this.getIsTwoBidOpening()
        }
        // 第一阶段投标规则
        if (!this.formData.isSubmitBidPrice) {
          this.formData.isSubmitBidPrice = '00'
        }
        if (!this.formData.tenderDocumentReceiveMethod) {
          // 为空时设置默认
          this.formData.tenderDocumentReceiveMethod = '00'// 标书获取方式 00 电子招标 01 线下招标
        }
        if (!this.formData.tenderDocumentSaleMethod) {
          // 为空时设置默认 根据是否分包控制默认值 isPack 00 不分包
          if (this.tenderBase.isPack === '00') {
            this.formData.tenderDocumentSaleMethod = '01'
          } else {
            this.formData.tenderDocumentSaleMethod = '00'// 标书金额设置 00 按标段售卖 01 按项目售卖
          }
        }
        // 保证金收取方式
        if (!this.formData.bailCollectMode) {
          this.formData.bailCollectMode = '00'
        }
        // 保证金设置
        if (!this.formData.receiveBailPriceMethod) {
          this.formData.receiveBailPriceMethod = '00'
        }
        // 标书解密方式
        this.getSystemDecryptMethod()
        // 文件获取方式
        if (!this.formData.tenderDocumentReceiveMethod) {
          this.formData.tenderDocumentReceiveMethod = '00'
        }
        // 支付方式
        if (!this.formData.payModeCode) {
          this.formData.payModeCode = ['01']
        } else { // 非空时
          this.formData.payModeCode = this.formData.payModeCode.split(',')
        }
        // 发布媒介
        if (!this.formData.mediaPartners) { // 为空时
          this.formData.mediaPartners = ['00', '01'] // 发布媒介 00 门户网站 01 中国公共服务平台 全选
        } else { // 非空时
          this.formData.mediaPartners = this.formData.mediaPartners.split(',')
        }
        /*   数组赋值   */
        this.formData.tenderDocumentPriceInfoDto = this.formData.tenderDocumentPriceInfoVo || []// 标书
        this.formData.tenderBailPriceInfoDto = this.formData.tenderBailPriceInfoVo || []// 保证金
        // 判断不分包情况获取所有标段数据 isPack 00不分包 或者招标标段bulletinPublishMethod 00按项目发布
        if (this.tenderBase.isPack === '00' || this.formData.bulletinPublishMethod === '00') {
          this.initPackList()
        }
      })
    },
    // 初始化获取标段数据（不分包情况）
    initPackList() {
      const data = {
        bulletinId: this.bulletinId, // 公告Id
        tenderId: this.tenderId, // 项目Id
        bulletinType: this.bulletinType // 招标类型
      }
      listUnmarkedBulletinPackage(data).then(res => {
        if (this.formData.tenderDocumentPriceInfoDto.length === 0 || this.formData.bulletinPublishMethod === '00') {
          this.formData.tenderDocumentPriceInfoDto = JSON.parse(JSON.stringify(res.data)) // 标书费列表
          // 判断如果标书费金额是null 默认赋值标书费金额为空字符串（解决批量设置金额问题）
          this.formData.tenderDocumentPriceInfoDto.map((v) => {
            if (!v.tenderId) v.tenderId = this.tenderId
            if (!v.documentPrice) v.documentPrice = ''
          })
        }
        if (this.formData.tenderBailPriceInfoDto.length === 0 || this.formData.bulletinPublishMethod === '00') {
          this.formData.tenderBailPriceInfoDto = JSON.parse(JSON.stringify(res.data)) // 保证金
          // 判断如果保证金金额是null 默认赋值保证金金额为空字符串（解决批量设置金额问题）
          this.formData.tenderBailPriceInfoDto.map((v) => {
            if (!v.tenderId) v.tenderId = this.tenderId
            if (!v.bailPrice) v.bailPrice = ''
          })
        }
        this.$forceUpdate() // 数据强制刷新
      })
    },
    // 根据标段id集合获取是否两步开标-华能项目
    getIsTwoBidOpening() {
      this.$store.dispatch('getSystemSourceConfig').then(() => {
        const systemSource = this.$store.getters.systemConfigSourceVo.systemSource
        // 系统来源 00:新产品 01:华能 02:能交
        if (systemSource === '01') {
          listIsTwoBidOpeningByStageIds(this.stageId).then((response) => {
            this.formData.isTwoBidOpening = response.data
          })
        } else {
          this.formData.isTwoBidOpening = '00'
        }
      })
    },
    /* 获取是否显示 是否需要报名字段 00不显示 01显示  */
    getSystemConfigValueByConfigType() {
      getSystemConfigValueByConfigType('BIDDINGBULLETIN_IS_SHOW_NEED_SINGUP').then((res) => {
        this.biddingbulletinIsShowNeedSingup = res.data
        // 如果需要报名 是否需要报名字段默认选中 01需要
        if (this.biddingbulletinIsShowNeedSingup === '01') {
          this.formData.isNeedSignup = '01'
        } else {
          this.formData.isNeedSignup = ''
        }
      })
    },
    /* 获取是否显示 报名时间字段 00不显示 01显示 */
    getSystemConfigNeedSignup() {
      getSystemConfigValueByConfigType('BIDDINGBULLETIN_IS_NEED_SIGNUP').then((res) => {
        this.biddingbulletinIsNeedSingup = res.data
      })
    },
    // 报名开始时间改变
    signupStartTimeChange() {
      this.formData.signupEndTime = ''
    },
    // 获取要移除的标段id集合
    getPackIds() {
      const packIds = []
      this.seletPackList.map(item => {
        packIds.push(item.packId)
      })
      return packIds
    },
    // 获取已选标段
    seletPackInfo(data) {
      const seletPackInfo = JSON.parse(JSON.stringify(data)) // 保证金列表
      if (data.length > this.formData.tenderDocumentPriceInfoDto.length) { // 判断已选标段是新增还是减少
        this.formData.tenderDocumentPriceInfoDto = this.getNoArrEqual(this.formData.tenderDocumentPriceInfoDto, seletPackInfo) // 标书费
        // 判断如果标书费金额是null 默认赋值标书费金额为空字符串（解决批量设置金额问题）
        this.formData.tenderDocumentPriceInfoDto.map((v) => {
          if (!v.tenderId) v.tenderId
          if (!v.documentPrice) v.documentPrice = ''
        })
        this.formData.tenderBailPriceInfoDto = this.getNoArrEqual(this.formData.tenderBailPriceInfoDto, seletPackInfo) // 保证金
        // 判断如果保证金金额是null 默认赋值保证金金额为空字符串（解决批量设置金额问题）
        this.formData.tenderBailPriceInfoDto.map((v) => {
          if (!v.tenderId) v.tenderId
          if (!v.bailPrice) v.bailPrice = ''
        })
      } else {
        this.formData.tenderDocumentPriceInfoDto = this.getArrEqual(this.formData.tenderDocumentPriceInfoDto, seletPackInfo) // 标书费
        this.formData.tenderBailPriceInfoDto = this.getArrEqual(this.formData.tenderBailPriceInfoDto, seletPackInfo) // 保证金
      }
    },
    // 保存
    save(formName) {
      // 校验个人信息是否已完善
      this.$store.dispatch('findUserRule').then(() => {
        // 校验输入内容
        this.$refs[formName].validate((valid, field) => {
          if (valid) { // 校验通过
            this.saveData('00')
          }
        })
      })
    },
    // 保存组装数据
    assemblyData() {
      const data = {
        ...this.formData
      }
      // 通过资审和后审判断来源
      if (this.tenderBase.stageType === '00') {
        data.requestSource = '00'// 资审公告
      } else if (this.tenderBase.stageType === '01') {
        data.requestSource = '01'// 招标公告
      }
      data.bulletinId = this.bulletinId // 招标公告id
      data.tenderId = this.tenderId// 项目Id
      data.bulletinType = this.tenderBase.bulletinType// 21资审公告 01招标公告
      data.packIds = [...this.getPackIds()] // 要存储的标段id集合
      // 指定媒体 将数组转成字符串
      data.mediaPartners = data.mediaPartners.join(',')
      // 支付方式 Code码
      data.payModeCode = this.formData.payModeCode.join(',')
      // 删除不需要的参数
      delete data.listMarkedBulletinPackage// 标段（包）信息
      delete data.bulletinPublishMethodChange // 本次招标标段是否可以修改
      delete data.tenderDocumentSaleMethodChange // 标书售卖方式是否可以修改
      delete data.receiveBailPriceMethodChange // 保证金收取方式是否可以修改
      delete data.tenderDocumentPriceInfoVo// 公告已制作标段包
      delete data.tenderBailPriceInfoVo // 保证金
      return data
    },
    // 保存数据接口
    saveData(type) {
      const isVali = this.documentReceiveTimeChange()// 标书获取时间规则校验
      if (!isVali) return
      this.confirmLoading = true// btnLoding
      const data = this.assemblyData()// 保存组装数据
      saveBaseTenderBulletinSimpleInfo(data).then(response => {
        this.bulletinId = response.data.id// 招标公告Id
        // type 00保存 01工具制作公告
        if (type === '01') {
          getOpenToolsUrl(response.data.id).then(res => {
            window.open(`${res.data}`, '_self') // 调用工具使用
            this.previewInterval()// 定时器-制作公告状态
          })
        } else {
          this.initData()// 获取招标信息
          this.$message.success(response.header.msg)
        }

        this.confirmLoading = false// btnLoding
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 使用工具端制作公告
    openToolsUrl() {
      clearInterval(this.invitationInterval)// 清除定时器
      // 校验个人信息是否已完善
      this.$store.dispatch('findUserRule').then(() => {
        // 校验输入内容
        this.$refs.form.validate((valid, field) => {
          if (valid) { // 校验通过
            this.saveData('01')
          }
        })
      })
    },
    // 定时器-公告预览
    previewInterval() {
      this.queryBulletinStatus()
      this.bulletinInterval = setInterval(() => {
        this.queryBulletinStatus()
      }, 2000)
    },
    // 查询公告是否提交
    queryBulletinStatus() {
      const data = {
        tenderId: this.tenderId, // 项目Id
        bulletinId: this.bulletinId// 公告Id
      }
      queryBaseTenderBulletinInfo(data).then((res) => {
        const { auditStatus } = res.data
        // 审核状态
        if (auditStatus === '00' || auditStatus === '01') { // 00审核中,01通过
          clearInterval(this.invitationInterval)// 清除定时器
          // 携带参数
          const query = {
            ...this.$route.query,
            bulletinId: this.bulletinId// 公告Id
          }
          this.$router.push({ path: '/bidding/projectDrive/bulletin/newTenderBulletin-detail', query: query })
        }
      })
    },
    // 分标段时-批量设置金额
    msetKeyMoney() {
      this.$prompt('批量设置金额（元）', '批量设置' + this.dict.documentPriceTitle, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        inputPattern: moneyRegular,
        inputErrorMessage: '请输入正确的金额'
      }).then(({ value }) => {
        // value 标书金额
        this.formData.tenderDocumentPriceInfoDto.map(item => {
          item.documentPrice = value
        })
      }).catch(() => {
      })
    },
    // 分标段时-批量设置金额
    msetKeyMoney2() {
      this.$prompt('批量设置金额（元）', '批量设置保证金', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        inputPattern: moneyRegular,
        inputErrorMessage: '请输入正确的金额'
      }).then(({ value }) => {
        // value 标书金额
        this.formData.tenderBailPriceInfoDto.map(item => {
          item.bailPrice = value
        })
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="less" scoped>
/deep/.show-word-limit-padding{
  .el-input__inner{
    padding-right: 70px;
  }
}
/deep/.tenderDocumentReceiveTime {
  .el-input{
    width: auto;
    display:inline-block;
  }
  .defaultTimeDateTime{
    margin-left: 5px;
  }
}
.textAlign-center{
  text-align: center !important;
}
.fontBlod{
  font-weight: bold !important;
}
.bgW{
  background: #fff !important;
}
.bg-F5F7F9{
  background-color: #F5F7F9 !important;
}
/deep/.tableData{
  .form_item_table td{
    border-right: none;
    border-top: none;
    background-color: #fff !important;
  }
}
/deep/.from_table{
  .form_item_table tr td:nth-child(odd) {
    background: none;
  }
  .form_item_table td{
    border-right: none;
    border-top: none;
    // background-clor: #fff !important;
  }
}
/deep/.tableData{
  .form_item_table th{
    border-top: none;
  }
}
/deep/.from_table{
  .form_item_table th{
    border-top: none;
  }
}
/deep/.from_table{
  .form_item_table td:first-child{
    border-left: none;
  }
}
/deep/.tableData{
  .form_item_table td:first-child{
    border-left: none;
  }
}
</style>

