<!--
  @description: 立项-标段(包)信息（有标的物）
  @Modifier:haoFx
  @routerPath: /bidding/buildBiddingProject/haveMaterialPack
  @date:2019/10/26-16:49
-->
<template>
  <div>
    <div class="mb16">
      <!--批量创建-->
      <el-button v-if="isPack === '01'" type="primary" @click="createBlock()">
        创建标段（包）
      </el-button>
      <!--删除-->
      <el-button v-if="formData.packageList.length > 0 && isPack === '01'" type="primary" @click="deletePackage">
        删除
      </el-button>
      <!-- 重新选择是否分包     -->
      <el-button v-if="isShowRest" type="primary" @click="$parent.isBtn = true">
        重新选择是否分包
      </el-button>
    </div>
    <el-form ref="forms" :model="formData" :rules="formData.rules" :inline-message="true">
      <div>
        <!--标段列表-->
        <el-table
          ref="package"
          :data="formData.packageList"
        >
          <el-table-column type="selection" align="center" width="50" />
          <el-table-column label="序号" align="center" min-width="50">
            <template slot-scope="scope">
              <span>{{ scope.$index }}</span>
            </template>
          </el-table-column>
          <!-- v-if="isPack === '01'" -->
          <el-table-column
            header-align="center"
            align="center"
            prop="packNo"
            min-width="200"
          >
            <template slot="header">
              <span class="red-star">*</span>
              <span>标段（包）编号</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'packageList.' + scope.$index + '.packNo'" :rules="formData.rules.packNo">
                <gx-input
                  v-model.trim="scope.row.packNo"
                  gx-maxlength="varchar200"
                  size="mini"
                  :show-word-limit="false"
                  @blur="verifyPackage(scope.row, 'packNo')"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="packName"
            align="center"
            min-width="200"
          >
            <template slot="header">
              <span class="red-star">*</span>
              <span>标段（包）名称</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'packageList.' + scope.$index + '.packName'" :rules="formData.rules.packName">
                <gx-input
                  v-model.trim="scope.row.packName"
                  gx-maxlength="varchar500"
                  size="mini"
                  @blur="verifyPackage(scope.row, 'packName')"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="packName"
            align="center"
            min-width="200"
          >
            <template slot="header">
              <span class="red-star">*</span>
              <span>标段（包）分类</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'packageList.' + scope.$index + '.packTypeCode'" :rules="formData.rules.packTypeCode">
                <div style="display: flex;">
                  <gx-input
                    v-model.trim="scope.row.packTypeName"
                    disabled
                    gx-maxlength="varchar500"
                    size="mini"
                  />
                  <el-button size="mini" style="flex: 1;margin-left:6px" type="primary" class="ml10" @click="packTypeSelect(scope.row, scope.$index)">
                    选 择
                  </el-button>
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="packageContent"
            align="center"
            min-width="200"
          >
            <template slot="header">
              <!--              <span class="red-star">*</span>-->
              <span>标段（包）内容</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'packageList.' + scope.$index + '.packageContent'" :rules="formData.rules.packageContent">
                <gx-input
                  v-model.trim="scope.row.packageContent"
                  gx-maxlength="varchar500"
                  size="mini"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="本标段（包）预算（元）"
            prop="contractBudget"
            align="right"
            min-width="170"
          >
            <template slot="header">
              <span class="red-star">*</span>
              <span>本标段（包）预算（元）</span>
            </template>
            <template slot-scope="scope">
              <!--hn && 无物料可填写-->
              <!--              <money-->
              <!--                v-if="bidProjectSystemSourceType && scope.row.isContractBudgetModify==='01'"-->
              <!--                :money-value="scope.row"-->
              <!--                :thousands="true"-->
              <!--                size="mini"-->
              <!--                width="100%"-->
              <!--                name="contractBudget"-->
              <!--              />-->
              <!--              <span v-else>-->
              <!--                {{ scope.row.contractBudget ? moneyFormat(scope.row.contractBudget.toFixed(2)) : scope.row.contractBudget }}-->
              <!--              </span>-->
              <el-form-item :prop="'packageList.' + scope.$index + '.contractBudget'" :rules="formData.rules.contractBudget">
                <money
                  :money-value="scope.row"
                  :thousands="true"
                  size="mini"
                  width="100%"
                  name="contractBudget"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="最高限价（元）"
            width="150"
          >
            <template slot-scope="scope">
              <money
                :money-value="scope.row"
                :thousands="true"
                size="mini"
                width="100%"
                name="maxLimitedPrice"
              />
            </template>
          </el-table-column>
          <template v-if="bidProjectSystemSourceType">
            <!--招标代理服务费收取方式 差额定率累进制00 固定金额01 固定比例02 注：固定金额01服务费金额-->
            <el-table-column
              v-if="projectData.agentServiceFeeMethod === '01'"
              header-align="center"
              min-width="150"
            >
              <template slot="header">
                <span class="red-star">*</span>
                <span>服务费金额（元）</span>
              </template>
              <template slot-scope="scope">
                <money
                  :money-value="scope.row"
                  :thousands="true"
                  size="mini"
                  width="auto"
                  name="servicePrice"
                />
              </template>
            </el-table-column>
            <!--招标代理服务费收取方式 差额定率累进制00 固定金额01 固定比例02 注：固定比例02服务费金额-->
            <el-table-column
              v-if="projectData.agentServiceFeeMethod === '02'"
              header-align="center"
              min-width="100"
            >
              <template slot="header">
                <span class="red-star">*</span>
                <span>服务费比例（%）</span>
              </template>
              <template slot-scope="scope">
                <gx-input
                  v-model.trim="scope.row.serviceRate"
                  type="number"
                  gx-maxlength="varchar50"
                  size="mini"
                />
              </template>
            </el-table-column>
          </template>
          <!--          <el-table-column label="" align="center" width="300">-->
          <!--            <template slot-scope="scope">-->
          <!--              <template v-if="bidProjectSystemSourceType">-->
          <!--                &lt;!&ndash;流程信息&#45;&#45;有招标计划则显示&ndash;&gt;-->
          <!--                <el-link-->
          <!--                  :underline="false"-->
          <!--                  :disabled="scope.row.taskPlanList.length<1"-->
          <!--                  type="primary"-->
          <!--                  @click="processControl(scope.row.taskPlanList[0].schemeId)"-->
          <!--                >-->
          <!--                  [流程信息]-->
          <!--                </el-link>-->
          <!--                <el-link-->
          <!--                  :disabled="scope.row.taskPlanList.length>0"-->
          <!--                  :underline="false"-->
          <!--                  type="primary"-->
          <!--                  @click="relevanceTenderPlanClick(scope.$index)"-->
          <!--                >-->
          <!--                  [挑选计划]-->
          <!--                </el-link>-->
          <!--                <el-link-->
          <!--                  :underline="false"-->
          <!--                  type="primary"-->
          <!--                  @click="relevanceTenderPlanListClick(scope.row, scope.$index)"-->
          <!--                >-->
          <!--                  [已选计划]（{{ scope.row.taskPlanList.length }}）-->
          <!--                </el-link>-->
          <!--              </template>-->
          <!--              <template v-if="!bidProjectSystemSourceType">-->
          <!--                <el-link-->
          <!--                  :underline="false"-->
          <!--                  type="primary"-->
          <!--                  @click="materielSelect(scope.$index)"-->
          <!--                >-->
          <!--                  [挑选物料]-->
          <!--                </el-link>-->
          <!--                <el-link-->
          <!--                  :underline="false"-->
          <!--                  type="primary"-->
          <!--                  @click="materielListClick(scope.row, scope.$index)"-->
          <!--                >-->
          <!--                  [已选物料]（{{ scope.row.material.length }}）-->
          <!--                </el-link>-->
          <!--              </template>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
        </el-table>
      </div>
    </el-form>
    <el-button
      size="mini"
      class="fr"
      style="color: red;margin-top: 16px"
      type="text"
    >
      注：最高限价不填即不设限价
    </el-button>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button @click="prevStep">
            上一步
          </el-button>
          <el-button :loading="confirmLoading" type="primary" @click="saveData()">
            暂存, 进入下一步
          </el-button>
        </div>
      </div>
    </div>
    <!--挑选物料-弹框-->
    <materielSelectDialog
      :project-data="projectData"
      :dialog-data="dialogData"
      @materialSelect="materialSelect"
    />
    <!--查看标段已选物料-弹框-->
    <materielListDialog
      :dialog-data="materielListDialog"
      @materialSelect="materialSelect"
    />
    <!--流程控制-弹框-->
    <processControlInfoDialog v-if="bidProjectSystemSourceType" ref="processControlInfo" />
    <!--关联招标计划选择弹框-弹框-->
    <relevanceTenderPlanSelectDialog
      v-if="bidProjectSystemSourceType"
      :dialog-data="relevanceTenderPlanDialog"
      @relevanceTenderPlanSelect="relevanceTenderPlanSelect"
    />
    <relevanceTenderPlanListDialog
      v-if="bidProjectSystemSourceType"
      :dialog-data="relevanceTenderPlanListDialog"
      @relevanceTenderPlanSelect="relevanceTenderPlanSelect"
    />
    <pack-type-dialog
      ref="expertSelectworkunitDialog"
      :dialog-data="packTypeDialog"
      @change="packTypeChange"
    />
  </div>
</template>
<script>
/* api*/
import {
  getPackNoListByRule,
  listPackage, // 获取包
  listTenderMaterie, // 获取物料
  savePackageInfo, // 保存包
  removePackage, // 删除包
  queryBaseTenderProjectInfo
} from '@/api/bidding/biddingProject'
/* 公用方法*/
import { moneyFormat, cloneObject, formatZero } from '@assets/js/utils' // 常用方法
import { validateRoleCode, validateInput, characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* 组件*/
import money from '@comp/common/money/money' // 金额
import materielSelectDialog from './materielSelect-dialog' // 挑选物料
import materielListDialog from './materielList-dialog' // 已选物料查看
import processControlInfoDialog from '@views/purchasePlan/tenderPlan/tenderPlan-dialog/processControlInfo-dialog' // 流程控制弹框
import relevanceTenderPlanSelectDialog from '@views/purchasePlan/tenderPlan/tenderPlan-dialog/relevanceTenderPlanSelect-dialog' // 关联招标计划选择-弹框
import relevanceTenderPlanListDialog from '@views/purchasePlan/tenderPlan/tenderPlan-dialog/relevanceTenderPlanList-dialog' // 已关联招标计划-弹框
/* 混入*/
import { bidProjectCommon } from '../mixins/bidProjectCommon'
import packTypeDialog from './packType-dialog'
export default {
  name: 'PackageAdd',
  components: {
    money, // 金额
    materielSelectDialog, // 挑选物料
    materielListDialog, // 物料查看
    processControlInfoDialog, // 流程控制弹框
    relevanceTenderPlanSelectDialog, // 关联招标计划选择弹框-弹框
    relevanceTenderPlanListDialog, // 标段已关联计划弹框
    packTypeDialog
  },
  mixins: [bidProjectCommon],
  props: {
    isPack: {
      type: String,
      default: ''
    },
    // 保存分包状态
    savePack: {
      type: Function,
      default: function(isPack) {
        // isPack 00 不分包 01 分包
      }
    },
    // 上一步
    prevStep: {
      type: Function,
      default: function() {}
    },
    // 下一步
    nextStep: {
      type: Function,
      default: function() {}
    }
  },
  data() {
    return {
      /* ========================标段部分========================*/
      confirmLoading: false, // 暂存草稿 进行下一步 Loding
      // 挑选物料弹框
      dialogData: {
        materialId: [], // 物料Id去重列表
        packIndex: '', // 标段索引,
        materielSelectVisible: false // 弹框展示状态
      },
      // 查看标段已选物料
      materielListDialog: {
        dialog: false, // // 弹框展示状态
        isShowRemoveBtn: true, // 是否显示移除按钮,
        packIndex: '', // 标段索引,
        materialList: [] // 物料列表
      },
      packTypeDialog: {
        dialog: false, // // 弹框展示状态
        packIndex: '', // 标段索引
        selectCodes: []
      },
      // 创建标段（包）=>信息
      addPackage: {
        annualPrequalificationScreeningProject: '', // 年度资格预审筛选项目 00:否 01:是
        qualificationCheckWay: '', // 资格审查方式，00单次资格预审，01年度资格预审，02资格后审
        isSetUpMaxLimitedPrice: '', // 标段最高限价-设置 00 否 01 是
        contractBudget: '', // 标段预算
        maxLimitedPrice: '', // 标段最高限价
        orderlevel: '', // 排序
        packId: '', // 标包Id
        packName: '', // 标包名称
        packNo: '', // 标包编号
        material: [], // 物料信息
        taskPlanList: [], // 标段关联计划集合
        schemeName: '', // 关联计划名称 （表格显示用）
        packTypeName: '', // 标段包分类名称
        packTypeCode: '', // 标段包分类Code
        packageContent: '', // 标段包内容
        constructionProjectId: ''// 大项ID
      },
      formData: {
        rules: {
          packNo: [
            { required: true, validator: characters1_auto, trigger: 'blur' },
            { validator: validateInput, trigger: 'blur' },
            { validator: validateRoleCode, trigger: 'blur' }
          ],
          packName: [{ required: true, validator: characters1_auto, trigger: 'blur' }, { validator: validateInput, trigger: 'blur' }],
          packTypeCode: [{ required: true, validator: characters1_auto, trigger: 'blur' }],
          contractBudget: [{ required: true, validator: characters1_auto, trigger: 'blur' }]
        },
        packageList: [] // 回填包组
      },
      /* ========================关联招标计划部分========================*/
      // 关联招标计划选择-弹框
      relevanceTenderPlanDialog: {
        selectedPlanId: [], // 招标计划Id去重列表
        dialog: false, // 弹框展示状态
        packIndex: '' // 标段索引
      },
      // 查看标段已选关联招标计划
      relevanceTenderPlanListDialog: {
        dialog: false, // // 弹框展示状态
        isShowRemoveBtn: true, // 是否显示移除按钮,
        packIndex: '', // 标段索引,
        taskPlanList: [] // 物料列表
      }
    }
  },
  computed: {
    isShowRest() {
      console.log((this.formData.packageList.length === 0 && this.isPack === '01') || ((this.formData.packageList.length === 1 || this.formData.packageList.length === 0) && this.isPack === '00'))
      return (this.formData.packageList.length === 0 && this.isPack === '01') || ((this.formData.packageList.length === 1 || this.formData.packageList.length === 0) && this.isPack === '00')
    }
  },
  watch: {
    isPack(newValue, oldValue) {

    },
    'formData.packageList': {
      handler() {
        if (this.formData.packageList) {
          // 从集合的最多流水给物料编号流水加一
          this.formData.packageList.map((item, i) => {
            item.packNo = this.tenderNo + formatZero(i + 1, 3)
          })
        }
      },
      deep: true // true 深度监听
    }
  },
  created() {
    /* if (sessionStorage.getItem('projectInfo')) {
      this.tenderNo = JSON.parse(sessionStorage.getItem('projectInfo')).tenderNo
    } */

    this.queryBaseTenderProjectInfo().then(res => {
      this.initData() // 获取标包列表
    })
  },
  methods: {
    moneyFormat, // 转千分位

    async queryBaseTenderProjectInfo() {
      // 获取项目信息中的组织形式
      queryBaseTenderProjectInfo(this.projectData.id).then((res) => {
        this.tenderNo = res.data.tenderNo
        this.addPackage.constructionProjectId = res.data.constructionProjectId
      })
    },

    // 生成标段编号（根据配置调用）
    getPackNoRule(packNum, packNoArr) {
      const packNoRuleDtoParasm = {
        packNoList: packNoArr, // 标段编号集合
        packNumber: packNum, // 标段数量
        tenderId: this.projectData.id // 项目id
      }
      // 过滤新增的没有标段编号的数据
      const filterList = this.formData.packageList.filter(i => !i.packNo)
      getPackNoListByRule(packNoRuleDtoParasm).then(res => {
        const { data } = res
        if (data && data.length > 0) {
          filterList.map((item, index) => {
            item.packNo = data[index].packNo
          })
        }
      }).catch(() => {
      })
    },
    /* ========================标段部分========================*/
    // 获取标包列表
    async initData() {
      this.formData.packageList = []
      await listPackage(this.projectData.id).then(response => {
        const { data } = response
        // 组装数组
        data.map((item, index) => {
          // 解决默认会带出0的问题
          if (!item.maxLimitedPrice) {
            item.maxLimitedPrice = null
          }
          item.material = []// 创建物料仓库-存储该标包下的物料
          if (!item.taskPlanList) {
            item.taskPlanList = []
          }
          // 处理默认带出服务费比例和服务费金额
          if (this.projectData.agentServiceFeeMethod === '01') {
            if (!item.servicePrice) item.servicePrice = this.projectData.contractChargeValue
            item.servicePrice = String(item.servicePrice)
          }
          // 处理默认带出服务费金额
          if (this.projectData.agentServiceFeeMethod === '02') {
            if (!item.serviceRate) item.serviceRate = this.projectData.contractChargeValue
            item.serviceRate = String(item.serviceRate)
          }
          this.formData.packageList.push(item) // 包信息
          this.materialClick(item, index)// 获取物料 item 包信息
        })
        if (this.isPack === '00') {
          if (!data || !data.length) {
            const obj = cloneObject(this.addPackage) // 深层拷贝要创建的标包信息
            obj.packNo = this.tenderNo + '001'
            this.formData.packageList.push(obj)
          }
        }
      })
    },
    // 获取物料 item 包信息
    materialClick(item, index) {
      const data = {
        tenderId: this.projectData.id, // 项目Id
        packId: item.packId // 包id
      }
      listTenderMaterie(data).then(res => {
        this.formData.packageList[index].material = res.data // 物料
      })
    },
    // 创建标段（包）
    createBlock() {
      return new Promise((resolve, reject) => {
        this.$prompt('数量', '批量创建', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          inputPattern: /^[1-9]{1}[\d]*$/,
          inputErrorMessage: '请输入创建数量'
        }).then(({ value }) => {
          for (let i = value; i--; i > 0) {
            const data = cloneObject(this.addPackage) // 深层拷贝要创建的标包信息
            this.formData.packageList.push(data)
          }
          // 创建标段根据配置调用生成标段编号 hn执行
          if (this.bidProjectSystemSourceType) {
            const packNoArr = [] // 标段编号集合
            // 招标代理服务费收取方式 差额定率累进制00 固定金额01 固定比例02 注：固定比例02服务费金额
            // servicePrice 服务费金额 serviceRate 服务费比例字段
            this.formData.packageList.map((item) => {
              item.packNo && packNoArr.push(item.packNo)
              if (this.projectData.agentServiceFeeMethod === '01') {
                item.servicePrice = this.projectData.contractChargeValue
              }
              if (this.projectData.agentServiceFeeMethod === '02') {
                item.serviceRate = this.projectData.contractChargeValue
              }
            })
            this.getPackNoRule(Number(value), packNoArr)
          }
          resolve()
        }).catch(() => {
          reject()
        })
      })
    },
    /* ---------------------------删除标段（包） Start------------------------------*/
    // 删除标段（包）
    deletePackage() {
      /*
      当选择要删除的标段和所有标段的数量相等时并且不是华能则删除玩后跳回分包页面 注：华能项目不走分包
      * */
      if (this.$refs.package.selection.length >= this.formData.packageList.length && !this.bidProjectSystemSourceType) {
        // 当选择要删除的标段和所有标段的数量相等时显示弹框
        this.$confirm(
          '所有标段（包）删除后将改成不分标段（包），确定继续吗?',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }
        ).then(() => {
          this.removePackage()
        })
      } else if (this.$refs.package.selection.length > 0) {
        // 已选中
        this.$confirm('确认删除该标段（包），是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.removePackage()
        })
      } else {
        // 未选中
        this.$message({
          type: 'warning',
          message: '请选择标段（包）'
        })
      }
    },
    // 获取已选标段
    getPackageSelet() {
      // 获取已选中标段
      const data = [] // 标段（包）Id
      this.$refs.package.selection.map((item) => {
        // 只筛选有packId的标段
        if (item.packId) {
          data.push({
            packId: item.packId, // 标段Id
            tenderId: this.projectData.id // 项目Id
          })
        }
      })
      return data
    },
    // 删除标段（包）
    removePackage() {
      const data = this.getPackageSelet() // 获取已选标段 只有packId的标段
      const _this = this // this指向
      if (data.length > 0) {
        // 删除标段为大于0时调接口-有packId时
        removePackage(data).then(() => {
          _this.deleteSelection(_this) // 前端-删除已选中的标段
        })
      } else {
        // 当前选中标段的packId都为空时调用
        this.deleteSelection(_this) // 前端-删除已选中的标段
      }
    },
    // 前端-删除已选中的标段
    deleteSelection(_this) {
      _this.$refs.package.selection.map((item) => {
        _this.formData.packageList.splice(this.formData.packageList.lastIndexOf(item), 1)
      })
      _this.$message({
        message: '删除成功',
        type: 'success'
      })
      // 标段为0时候 && 是新产品项目改为不分包 否则不切换页面
      if (_this.formData.packageList.length < 1 && !this.bidProjectSystemSourceType) {
        _this.savePack('00')
      }
    },
    /* ---------------------------删除标段（包） End------------------------------*/
    /* ---------------------------查看已选物料-弹框 Start------------------------------*/
    // 查看标段物料
    materielListClick(row, index) {
      this.materielListDialog.packIndex = index
      this.materielListDialog.dialog = true // 查看状态
      this.materielListDialog.materialList = row.material // 物料列表
    },
    /* ---------------------------查看已选物料-弹框 End------------------------------*/
    /* ---------------------------挑选物料-弹框 Start------------------------------*/
    // 挑选物料 material 所有标包当前已有物料
    materielSelect(packIndex) {
      const materialId = [] // 取物料Id去去重
      this.formData.packageList.map(item => {
        item.material.map(chid => {
          materialId.push(chid.id)
        })
      })
      this.dialogData = {
        materialId: materialId, // 物料Id
        packIndex: packIndex, // 标段索引
        materielSelectVisible: true // 弹框展示状态
      }
    },
    // 带回已选择的物料信息 materielList 选择的物料
    materialSelect(materielList, packIndex, status) {
      let contractBudget = 0.00
      // 01 挑选物料
      if (status === '01') {
        this.formData.packageList[packIndex].material.push(...materielList) // 添加已选择的物料
      } else if (status === '02') {
        // 02 移除物料
        this.formData.packageList[packIndex].material = materielList // 添加已选择的物料
      } else {
        throw console.error('操作无效')
      }
      // 该标包下的物料金额小计
      this.formData.packageList[packIndex].material.forEach(item => {
        // 判断是不是一个数字
        if (typeof Number(item.totalBudget) === 'number') {
          contractBudget += Number(item.totalBudget)
        }
      })
      this.formData.packageList[packIndex].contractBudget = contractBudget
    },
    /* ---------------------------挑选物料-弹框 End------------------------------*/
    /* ---------------------------挑选标段分类-弹框 Start------------------------------*/
    /* ---------------------------挑选标段分类-弹框 End------------------------------*/
    // 校验是否有重复的标题或者标段编号
    verifyPackage() {
      let verify = true // 是否重复 布尔值 true 没有重复
      this.formData.packageList.map((item, index) => {
        this.formData.packageList.map((items, indexs) => {
          // 冒泡循环时 必须循环的和自己的下标不同时&& verify===true
          if (index !== indexs && verify) {
            if (items.packName && items.packName === item.packName) { // 标段名称 重复
              this.$message({
                message: '序号为【' + (index + 1) + '，' + (indexs + 1) + '】标段（包）名称重复，请您重新输入！',
                type: 'warning'
              })
              verify = false // 已重复
              return verify
            } else if (items.packNo && items.packNo === item.packNo) { // 标段编号 重复
              this.$message({
                message: '序号为【' + (index + 1) + '，' + (indexs + 1) + '】标段（包）编号重复，请您重新输入！',
                type: 'warning'
              })
              verify = false // 已重复
            }
          }
        })
      })
      return verify
    },
    // 保存数据组装
    packageData() {
      const packageList = [] // 标包数组
      this.formData.packageList.map((item, index) => {
        /* ========================标段物料数据组装========================*/
        if (item.maxLimitedPrice) {
          // 填写即设限价
          item.isSetUpMaxLimitedPrice = '01'
        } else {
          // 不填即不设限价
          item.isSetUpMaxLimitedPrice = '00'
        }
        // 单个标包数据
        const data = {
          tenderId: this.projectData.id, // 项目Id
          ...item, // 标包信息
          matterIdList: [], // 物料Id
          orderlevel: index + 1 // 排序
        }
        if (item.material) {
          // 取当前标包下的物料Id
          item.material.map(chid => {
            data.matterIdList.push(chid.id)
          })
        }
        packageList.push(data)
        delete item.material // 删除不需要保存的数据
      })
      return packageList
    },
    /*
     * 保存数据 暂存，进行下一步
     * type参数 draft 点击步骤条切换-进行保存草稿
     * */
    saveData(type) {
      // 判断是否-点击步骤条切换&&标包数量小于1 不执行以下代码
      if (type === 'draft' && this.formData.packageList.length < 1) return
      const verify = this.verifyPackage() // 判断标段是否重复 布尔值 true 没有重复
      if (this.isPack === '00') {
        /* this.formData.packageList = this.formData.packageList.map(item => {
          item.packNo = item.packNo + '001'
          return item
        }) */
      }
      if (verify) {
        this.$refs['forms'].validate((valid) => {
          if (valid) {
            this.confirmLoading = true
            const data = this.packageData() // 保存数据组装

            savePackageInfo(data).then(() => {
              if (type === 'draft') return false // 判断是否-点击步骤条切换-如果是则不执行next下一步
              this.nextStep() // 下一步
              this.confirmLoading = false
            }).catch(() => {
              this.confirmLoading = false
            })
          }
        })
      }
    },
    /* ========================关联招标计划部分 Start========================*/
    // 标段添加招标计划信息
    initTaskPlanListData(index, taskPlanData) {
      const taskPlanListData = [{
        annualPrequalificationScreeningProject: taskPlanData.annualPrequalificationScreeningProject, // 年度资格预审筛选项目 00:否 01:是
        qualificationCheckWay: taskPlanData.qualificationCheckWay, // 资格审查方式，00单次资格预审，01年度资格预审，02资格后审
        schemeId: taskPlanData.schemeId, // 采购计划ID
        schemeName: taskPlanData.schemeName, // 计划名称
        schemeNo: taskPlanData.schemeNo, // 计划编号
        schemeBudget: taskPlanData.schemeBudget, // 计划总概算
        biddingPlanType: taskPlanData.biddingPlanType // 招标计划类型 00:带招标方案 01:自建项目
      }]
      this.formData.packageList[index].schemeId = taskPlanData.schemeId// 招标计划id
      this.formData.packageList[index].annualPrequalificationScreeningProject = taskPlanData.annualPrequalificationScreeningProject
      this.formData.packageList[index].qualificationCheckWay = taskPlanData.qualificationCheckWay
      this.formData.packageList[index].taskPlanList.push(...taskPlanListData)
    },
    /*
     * 关联招标计划
     * row 当前点击的标段信息 index 下标
     * */
    relevanceTenderPlanClick(index) {
      const schemeIdList = [] // 计划Id去去重
      this.formData.packageList.map(item => {
        item.taskPlanList.map(chid => {
          schemeIdList.push(chid.schemeId)
        })
      })
      this.relevanceTenderPlanDialog = {
        schemeIdList: schemeIdList, // 计划Id
        packIndex: index, // 标段索引
        dialog: true // 弹框展示状态
      }
    },
    /*
     * 关联招标计划选择-弹框-相应方法
     * data 当前选中的招标计划信息
     * */
    relevanceTenderPlanSelect(currentDataPlanList, packIndex, status) {
      // 01 挑选计划
      if (status === '01') {
        this.initTaskPlanListData(packIndex, currentDataPlanList)
      } else if (status === '02') {
        // 02 移除计划
        // 移除计划需清空 annualPrequalificationScreeningProject、qualificationCheckWay
        this.formData.packageList[packIndex].annualPrequalificationScreeningProject = ''
        this.formData.packageList[packIndex].qualificationCheckWay = ''
        this.formData.packageList[packIndex].schemeId = ''// 招标计划id
        this.formData.packageList[packIndex].taskPlanList = []
      } else {
        throw console.error('操作无效')
      }
      let contractBudget = '' // 标段(包）预算
      // 该标包的概算
      this.formData.packageList[packIndex].taskPlanList.forEach(item => {
        contractBudget = item.schemeBudget // 计划总概算
      })
      this.formData.packageList[packIndex].contractBudget = contractBudget
      if (!this.formData.packageList[packIndex].contractBudget) {
        this.formData.packageList[packIndex].isContractBudgetModify = '01'
      }
    },
    // 查看已选计划
    relevanceTenderPlanListClick(row, index) {
      this.relevanceTenderPlanListDialog.packIndex = index
      this.relevanceTenderPlanListDialog.dialog = true // 查看状态
      this.relevanceTenderPlanListDialog.taskPlanList = row.taskPlanList // 物料列表
    },
    // 流程信息
    processControl(schemeId) {
      this.$refs.processControlInfo.openProcessControlInfoDetail(schemeId)
    },
    /* ========================关联招标计划部分 End========================*/
    // 标段分类选择
    packTypeSelect(row, index) {
      this.packTypeDialog.packIndex = index
      if (row.packTypeCode) {
        this.packTypeDialog.selectCodes = [row.packTypeCode]
      }
      this.packTypeDialog.dialog = true // 查看状态
    },
    // 标段分类选择
    packTypeChange(item) {
      // keys: "A010101"
      // labels: "总体规划"
      this.formData.packageList[this.packTypeDialog.packIndex].packTypeName = item.labels
      this.formData.packageList[this.packTypeDialog.packIndex].packTypeCode = item.keys
    }
  }
}
</script>

<style lang="less" scoped>
  /deep/.el-form-item--small.el-form-item{
    margin: 0;
  }
</style>
