<!--
  @description:招标-招标公告-新版招标公告(邀请)
  @Modifier: 张慢慢
  @routerPath: /bidding/projectDrive/invitation/newTenderInvitation-add
  @date: 2021/05/25-13: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">
              <el-input v-model.trim="formData.title" maxlength="200" 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="invitationPublishMethod"
                label="本次招标标段"
                prop="invitationPublishMethod"
              />
            </td>
            <td colspan="3">
              <el-radio-group v-model="formData.invitationPublishMethod" :disabled="formData.invitationPublishMethodChange==='00' || !zsInvitationStageType">
                <el-radio v-for="(item,index) in publishMethodList" :key="index" :label="item.typecode">
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <!--
                选择标段（包）
                按标段发布时展示 invitationPublishMethod==='01'
              -->
          <tr v-if="formData.invitationPublishMethod==='01'">
            <td>
              <el-form-item
                required
                label="选择标段（包）"
              />
            </td>
            <td colspan="3">
              <packComponent ref="packComp" :selet-pack-list="seletPackList" :invitation-type="tenderBase.invitationType" @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>
          <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 v-if="tenderBase.stageType==='01'">
              <el-form-item
                ref="isTwoBidOpening"
                label="开标方式"
                prop="isTwoBidOpening"
              />
            </td>
            <td v-if="tenderBase.stageType==='01'">
              <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>
          </tr>
          <tr v-if="formData.isTwoBidOpening==='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">
                  {{ 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>
            <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>
            <td>
              <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 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 table_method">
                <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>
        <!--分标段-->
        <packageInvitationSupplierInfoAdd v-if="tenderBase.isPack==='01'" :package-list-info="packageList" @invitedSupplierTableData="invitedSupplierTableData" />
        <!--不分标段-->
        <noPackageInvitationSupplierInfoAdd v-else :package-list-info="packageList" @invitedSupplierTableData="invitedSupplierTableData" />
      </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">
            使用工具制作邀请函
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* api*/
import {
  queryBaseTenderInvitationInfo, // 查询是否邀请函提交
  listUnmarkedInvitationPackage, // 标段（包）列表-公共
  queryBaseTenderInvitationSimpleInfo, // 获取详情信息
  saveBaseTenderInvitationSimpleInfo // 保存
} from '@/api/bidding/bidInvitation'
import {
  listIsTwoBidOpeningByStageIds // 根据标段id集合获取是否两步开标-华能项目
} from '@/api/bidding/biddingProject'
import { getOpenToolsUrl } from '@/api/bidding/bidInvitation' // 获取工具url
// import { getPaycenterCommonPayAndSettlementConfig } from '@/api/bidding/payCenter'
/* 组件*/
import packComponent from '../packComponent/invitationPackComponent'// 选择标段（包）
import money from '@comp/common/money/money'
import packageInvitationSupplierInfoAdd from './tenderInvitationSupplier/packageInvitationSupplierInfo-add'
import noPackageInvitationSupplierInfoAdd from './tenderInvitationSupplier/noPackageInvitationSupplierInfo-add'
/* 混合开发方法-参数字段*/
import { tenderInvitationInitGroupMixin } from './../mixins/tenderInvitationInitGroupMixin'// 字典信息
import { newTenderInvitationInitGroupMixin } from './../mixins/newTenderInvitationInitGroupMixin' // 新版获取字典信息
import { tenderStageTimeRule } from '@/views/bidding/bulletin/mixins/tenderStageTimeRule.js'// 招标公告-时间规则
import { openInfoDecryptMethodConfig } from '@/views/bidding/bulletin/mixins/openInfoDecryptMethodConfig.js' // 解密方式配置
/* 公用方法*/
import { characters1_auto, validateInput, moneyRegular } from '@/assets/js/validate'// 校验输入内容
export default {
  name: 'BidProjectBase',
  components: {
    packComponent,
    money,
    packageInvitationSupplierInfoAdd,
    noPackageInvitationSupplierInfoAdd
  },
  mixins: [tenderInvitationInitGroupMixin, newTenderInvitationInitGroupMixin, tenderStageTimeRule, openInfoDecryptMethodConfig],
  data() {
    return {
      confirmLoading: false, // 暂存Loding
      /* 字典信息-start */
      bidTypeList: [], // 招标方式
      /* 字典信息-end */
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      tenderId: this.$route.query.id, // 项目Id
      packId: this.$store.getters.groupId.packId, // 标段
      invitationId: this.$route.query.invitationId, // 邀请函Id
      stageId: this.$store.getters.groupId.stageId, // 阶段Id
      tenderDocumentReceiveDays: '', // 标书获取开始时间-标书获取截止时间时间差 天数
      payModeList: [], // 支付方式信息
      settlementConfigVoList: [], // 中金卡号数据
      cardNumberShowsStatus: '', // 中金卡号显示状态 01：显示  00 不显示
      formData: {
        title: '', // 邀请函标题
        projectPackageNum: '', // 项目标段数量
        invitationPublishMethodChange: '00', // 本次招标标段是否可以修改 01 可以修改 00 不可以修改
        invitationPublishMethod: '00', // 本次招标标段  00:按项目发布 01:按标段发布
        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
        packIds: [], // 已选标段（包）Id=》存储时才使用
        tenderDocumentSaleMethodChange: '01', // 标书售卖方式 是否可以变更 01:可以变更 00:不可以变更
        tenderDocumentSaleMethod: '', // 标书金额设置 00 按标段售卖 01 按项目售卖
        documentPrice: '', // 按項目售卖金额-标书费
        mediaPartners: ['00', '01'], // 发布媒介 00 门户网站 01 中国公共服务平台 全选
        bailCollectMode: '00', // 保障金收取方式
        receiveBailPriceMethodChange: '01', // 是否可以变更 01:可以变更 00:不可以变更
        receiveBailPriceMethod: '', // 保证金设置 00 按标段售卖 01 按项目售卖
        tenderBailPriceInfoDto: [], // 按标段售卖金额
        tenderDocumentPriceInfoDto: []
      },
      seletPackList: [], // 获取的已选择的标段（包）
      // 校验输入内容
      rules: {
        title: [{ required: true, validator: validateInput, trigger: 'blur' }], // 邀请函标题
        invitationPublishMethod: [{ 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' }], // 标书解密方式
        isTwoBidOpening: [{ required: true, message: '请选择', trigger: 'change' }], // 开标方式
        isSubmitBidPrice: [{ required: true, message: '请选择', trigger: 'change' }], // 标书解密方式
        twoBidOpeningMethod: [{ 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' }], // 保证金设置
        tenderDocumentSaleMethod: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 标书金额设置
        // 计
        tenderingArea: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 招标范围
      },
      zsInvitationStageType: true, // 是否资审阶段
      invitationInterval: '', // 定时器-公告预览
      packageList: [], // 邀请名单列表
      invitationSupplierInfoDtos: [] // 不分包邀请函列表
    }
  },
  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.invitationPublishMethod'(val) {
      if (val === '00') {
        // 获取所有标段
        this.initPackList()
      } else {
        this.seletPackInfo(this.seletPackList)
      }
      this.$forceUpdate() // 数据强制刷新
    }
  },
  created() {
    // 初始化
    this.init()
  },
  destroyed() {
    clearInterval(this.invitationInterval)// 清除定时器
  },
  methods: {
    // 初始化
    init() {
      this.getInvitationAllDictionariesInitInfo() // 所有字典信息
      this.initData()// 获取邀请函信息
    },
    // 获取详情信息
    initData() {
      const data = {
        invitationType: this.tenderBase.invitationType, // 邀请函类型
        tenderId: this.tenderId, // 项目Id
        invitationId: this.invitationId, // 邀请函Id
        requestSource: '' // 来源 00:资审公告 01:招标公告 02:资格预审通知书 03:资审邀请函 04:后审邀请函
      }
      // 通过资审和后审判断来源
      if (this.tenderBase.stageType === '00') {
        data.requestSource = '03'// 资审邀请函
      } else if (this.tenderBase.stageType === '01') {
        data.requestSource = '04'// 后审邀请函
      }
      queryBaseTenderInvitationSimpleInfo(data).then((res) => {
        this.formData = res.data
        // 设置标题
        if (!this.formData.title) {
          this.formData.title = `【${this.formData.tenderName}】邀请函`// 邀请函标题
        }
        this.seletPackList = this.formData.listMarkedInvitationPackage || []// 获取的已选择的标段（包）
        this.getSystemDecryptMethod() // 获取系统配置-解密方式
        // 招标标段
        if (!this.formData.invitationPublishMethod) {
          // 为空时设置默认
          this.formData.invitationPublishMethod = '00' // 本次招标标段  00:按项目发布 01:按标段发布
        }
        // 资格审查方式 00资格预审,01 资格后审 && 后审01
        if (this.tenderBase.qualificationMethod === '00' && this.tenderBase.stageType === '01') {
          this.zsInvitationStageType = false // 是否资审阶段
          this.formData.invitationPublishMethod = '01' // 本次招标标段  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.payModeCode) {
          this.formData.payModeCode = ['01']
        } else { // 非空时
          this.formData.payModeCode = this.formData.payModeCode.split(',')
        }
        // 标书金额设置
        if (!this.formData.tenderDocumentSaleMethod) {
          // 为空时设置默认
          this.formData.tenderDocumentSaleMethod = '00'// 标书金额设置 00 按标段售卖 01 按项目售卖
        }
        // 保证金收取方式
        if (!this.formData.bailCollectMode) {
          this.formData.bailCollectMode = '00'
        }
        // 保证金设置
        if (!this.formData.receiveBailPriceMethod) {
          this.formData.receiveBailPriceMethod = '00'
        }
        // 发布媒介
        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不分包 invitationPublishMethod 00按项目发布
        if ((this.tenderBase.isPack === '00' || this.formData.invitationPublishMethod === '00') && !this.formData.invitationId) {
          this.initPackList()
        }
      })
    },
    // 初始化获取标段数据（不分包情况）
    initPackList() {
      const data = {
        invitationId: this.invitationId, // 邀请函Id
        tenderId: this.tenderId, // 项目Id
        invitationType: this.invitationType // 招标类型
      }
      listUnmarkedInvitationPackage(data).then(res => {
        if (this.formData.tenderDocumentPriceInfoDto.length === 0 || this.formData.invitationPublishMethod === '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.invitationPublishMethod === '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 = ''
          })
        }
        if (this.invitationSupplierInfoDtos.length === 0 || this.formData.invitationPublishMethod === '00') {
          this.packageList = JSON.parse(JSON.stringify(res.data))
          this.packageList.map((v) => {
            if (!v.supplierSize) v.supplierSize = 0
            if (!v.suppliersList) v.suppliersList = []
          })
        }
        this.$forceUpdate() // 数据强制刷新
      })
    },
    // 根据标段id集合获取是否两步开标-华能项目
    getIsTwoBidOpening() {
      this.$store.dispatch('getSystemSourceConfig').then(() => {
        const systemSource = this.$store.getters.systemConfigSourceVo.systemSource
        // 系统来源 00:新产品 01:华能 02:能交
        if (systemSource === '01' && this.requestSource === '03') {
          listIsTwoBidOpeningByStageIds(this.stageId).then((response) => {
            this.formData.isTwoBidOpening = response.data
          })
        } else {
          this.formData.isTwoBidOpening = '00'
        }
      })
    },
    // 获取要移除的标段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 = ''
        })
        /** *******************邀请供应商列表逻辑*********************** */
        this.packageList = this.getNoArrEqual(this.packageList, seletPackInfo) // 邀请名单标段
        this.packageList.map((v) => {
          if (!v.supplierSize) v.supplierSize = 0
        })
      } else {
        this.formData.tenderDocumentPriceInfoDto = this.getArrEqual(this.formData.tenderDocumentPriceInfoDto, seletPackInfo) // 标书费
        this.formData.tenderBailPriceInfoDto = this.getArrEqual(this.formData.tenderBailPriceInfoDto, seletPackInfo) // 保证金
        this.packageList = this.getArrEqual(this.packageList, seletPackInfo) // 邀请供应商列表
      }
    },
    // 获取分包不分包已选供应商
    invitedSupplierTableData(data) {
      this.invitationSupplierInfoDtos = [...data]
    },
    // 保存
    save(formName) {
      // 校验个人信息是否已完善
      this.$store.dispatch('findUserRule').then(() => {
        // 校验输入内容
        this.$refs[formName].validate((valid, field) => {
          if (valid) { // 校验通过
            this.saveData('00')
          }
        })
      })
    },
    // 保存组装数据
    assemblyData() {
      const data = {
        ...this.formData,
        tenderId: this.tenderId, // 项目Id
        bizId: this.invitationId, // 邀请函id
        invitationType: this.tenderBase.invitationType, // 邀请函类型 01:普通邀请函 02:资审后邀请函(数据源不同)
        invitationStageType: this.tenderBase.stageType,
        requestSource: '' // 来源 00:资审公告 01:招标公告 02:资格预审通知书 03:资审邀请函 04:后审邀请函
      }
      // 通过资审和后审判断来源
      if (this.tenderBase.stageType === '00') {
        data.requestSource = '03'// 资审邀请函
      } else if (this.tenderBase.stageType === '01') {
        data.requestSource = '04'// invitationStageType
      }
      data.packIds = [...this.getPackIds()] // 要存储的标段id集合
      // 指定媒体 将数组转成字符串
      data.mediaPartners = data.mediaPartners.join(',')
      // 支付方式 Code码
      data.payModeCode = this.formData.payModeCode.join(',')
      /* 处理保存供应商信息参数（分包）isPack 01分包*/
      if (this.tenderBase.isPack === '01') {
        const len = this.invitationSupplierInfoDtos.length
        const invitedTableData = [] // 已选供应商列表
        for (let i = 0; i < len; i++) {
          invitedTableData.push(...this.invitationSupplierInfoDtos[i].suppliersList)
        }
        data.invitationSupplierInfoDtos = invitedTableData
      } else {
        this.invitationSupplierInfoDtos.map((item) => {
          item.packId = this.packId
          item.stageId = this.stageId
          item.tenderId = this.tenderId
        })
        data.invitationSupplierInfoDtos = this.invitationSupplierInfoDtos
      }

      // 删除不需要的参数
      delete data.listMarkedBulletinPackage// 标段（包）信息
      delete data.bulletinPublishMethodChange // 本次招标标段是否可以修改
      delete data.tenderDocumentPriceInfoVo// 公告已制作标段包
      delete data.tenderBailPriceInfoVo
      delete data.listMarkedInvitationPackage // 已制作邀请函
      delete data.invitationPublishMethodChange // 本次招标标段是否可以修改
      return data
    },
    // 保存数据接口
    saveData(type) {
      clearInterval(this.invitationInterval)// 清除定时器
      const isVali = this.documentReceiveTimeChange()// 标书获取时间规则校验
      if (!isVali) return
      // 按标段发布时
      if (this.formData.invitationPublishMethod === '01' &&
        !this.$refs.packComp.isCheck()) {
        return // 校验是否选择标段（包）
      }
      this.confirmLoading = true// btnLoding
      const data = this.assemblyData()// 保存组装数据
      saveBaseTenderInvitationSimpleInfo(data).then(response => {
        this.invitationId = response.data.invitationId
        this.confirmLoading = false// btnLoding
        // type 00保存 01使用工具制作公告
        if (type === '00') {
          this.initData()// 获取邀请函信息
          this.$message.success(response.header.msg)
        } else {
          getOpenToolsUrl(this.invitationId).then(res => {
            window.open(`${res.data}`, '_self') // 调用工具使用
            this.previewInterval()// 定时器-公告预览
          })
        }
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 邀请函-使用工具端制作公告
    openToolsUrl() {
      // 校验个人信息是否已完善
      this.$store.dispatch('findUserRule').then(() => {
        // 校验输入内容
        this.$refs.form.validate((valid, field) => {
          if (valid) { // 校验通过
            this.saveData('01')
          }
        })
      })
    },
    // 定时器-公告预览
    previewInterval() {
      this.queryInvitationStatus()
      this.invitationInterval = setInterval(() => {
        this.queryInvitationStatus()
      }, 2000)
    },
    // 查询招标公告是否提交
    queryInvitationStatus() {
      const data = {
        tenderId: this.tenderId, // 项目Id
        invitationId: this.invitationId// 邀请函Id
      }
      queryBaseTenderInvitationInfo(data).then(res => {
        const { auditStatus } = res.data
        // 审核状态
        if (auditStatus === '00' || auditStatus === '01') { // 00审核中,01通过
          clearInterval(this.invitationInterval)// 清除定时器
          // 携带参数
          const query = {
            ...this.$route.query,
            invitationId: this.invitationId// 邀请函Id
          }
          this.$router.push({ path: '/bidding/projectDrive/invitation/newTenderInvitation-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/.from_table{
  .form_item_table td{
    border-right: none;
    border-top: none;
    // background-clor: #fff !important;
  }
  .form_item_table tr td:nth-child(odd) {
    background: none;
  }
  .table_method{
    .el-table--border{
      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;
  }
}
</style>

