<template>
  <div class="app-container" style="overflow: hidden">
    <el-container>
      <el-header style="padding: 0px;height: 24px">
        <span style="float: right">
        <el-button @click="debug = !debug" v-hasPermi="['bt:business:quotation:showdebug']">DEBUG {{ debug }}</el-button>
        <el-button v-if="this.type === 'add' || this.type === 'edit'" type="primary" @click="submitForm" icon="el-icon-circle-check">{{ $t('common.confirm') }}</el-button>
        <el-button @click="cancel" icon="el-icon-remove-outline">{{ $t('common.cancel') }}</el-button>
        </span>
      </el-header>
      <el-container style="margin-top: 16px">
        <el-aside class="container-aside">
          <el-card class="aside-card">
            <div v-for="(item,index) in asideCardList" :class="asideCardList[index].value === true?'aside-div-checked':'aside-div-unchecked'" @click="clickAside(index)">
              {{ item.label }}
            </div>
          </el-card>
        </el-aside>
        <el-main class="container-main">
          <div ref="scrollContainer" style="overflow: auto;height: calc(100vh - 200px);border-radius: 6px" @scroll="listenScroll">
            <el-form ref="form" :model="form" :rules="rules" label-width="200px" label-position="top" >
              <!--基本信息-->
              <el-card class="main-card">
                <div class="form-div">
                  <!-- 电梯类型-->
                  <el-form-item :label="$t('paraLibrary.elevatorType')" prop="elevatorType">
                    <el-select :disabled="disableFlag" v-model="form.elevatorType" class="w-100" @change="elevatorTypeChange"
                               :placeholder="$t('common.pleaseSelect') + $t('paraLibrary.elevatorType')">
                      <el-option v-for="dict in dict.type.elevator_type" :key="dict.value"
                                 :label="dict.label" :value="dict.value"/>
                    </el-select>
                  </el-form-item>
                </div>
                <div class="form-div">
                  <!-- 电梯型号-->
                  <el-form-item :label="$t('elevatorModel.elevatorModel')" prop="elevatorModelId">
                    <el-select :disabled="disableFlag" v-model="form.elevatorModelId" class="w-100" @change="elevatorModelChange(form.elevatorModelId,true)"
                               :placeholder="$t('common.pleaseSelect') + $t('elevatorModel.elevatorModel')">
                      <el-option v-for="dict in elevatorModelList" :key="Number(dict.value)"
                                 :label="dict.label" :value="Number(dict.value)"/>
                    </el-select>
                  </el-form-item>
                </div>
                <div class="form-div">
                  <!-- 数量-->
                  <el-form-item :label="$t('quotation.count')" prop="count">
                    <el-input-number :disabled="disableFlag" v-model.trim="form.count" :placeholder="$t('common.pleaseInput') + $t('quotation.count')"
                                     :min="1" class="w-100" :step="1" :max="9999" :controls="false"/>
                  </el-form-item>
                </div>
                <div class="form-div">
                  <!-- 电梯组号-->
                  <el-form-item :label="$t('elevator.groupCode')" prop="elevatorGroupCode">
                    <el-input :disabled="disableFlag" v-model.trim="form.elevatorGroupCode" :placeholder="$t('common.pleaseInput') + $t('elevator.groupCode')"
                              @input="e => form.elevatorGroupCode = replaceGroupCode(e)" maxlength="5" class="w-100"/>
                  </el-form-item>
                </div>
              </el-card>

              <!-- 后台获取参数-->
              <el-card class="main-card mt30 ts-form-item" v-for="(card,pIndex) in paramCategoryList" :id="'renderCard' + pIndex" v-if="(card.isShow && card.enabled) || debug">
                <div v-for="(item,index) in card.paramList" :key="'basic'+index" class="form-div" v-if="(item.isShow && item.enabled) || debug">
                  <el-form-item :prop="paramCategoryList[pIndex].paramList[index].paraCode">
                    <template slot="label">
                      <el-tooltip :content="item['label'+localLabelSuffix]" placement="top-start" v-if="item.inputType !== '05'" :tabindex="-1">
                        <span>{{ item['label' + localLabelSuffix] }}</span>
                      </el-tooltip>
                      <span v-if="item.inputType === '04'" style="font-size: 10px;font-weight: normal">({{ $t('quotation.otherOptions') }})</span>
                    </template>
                    <!--                    输入框-->
                    <el-input :disabled="disableFlag||getUnEditable(paramCategoryList[pIndex].paramList[index].paraCode)" v-model="paramCategoryList[pIndex].paramList[index].finalValue"
                              :placeholder="$t('common.pleaseInput') + item['label'+localLabelSuffix]" v-if="item.inputType === '00'" maxlength="60" @change="paramChange(item,true)"/>
                    <!--                    整数输入框-->
                    <el-input-number :disabled="disableFlag||getUnEditable(paramCategoryList[pIndex].paramList[index].paraCode)" :controls="false"
                                     v-model="paramCategoryList[pIndex].paramList[index].finalValue" class="w-100" @change="paramChange(item,true)" :max="999999999999999999" :min="0"
                                     :placeholder="$t('common.pleaseInput') + item['label'+localLabelSuffix]" v-if="item.inputType === '01'"/>
                    <!--                    下拉框-->
                    <el-select :disabled="disableFlag||getUnEditable(paramCategoryList[pIndex].paramList[index].paraCode)" filterable clearable
                               v-model="paramCategoryList[pIndex].paramList[index].finalValue" class="w-100" @change="item.paramType === '01'?parabarChange(item):paramChange(item,true)"
                               :placeholder="$t('common.pleaseSelect') + item['label'+localLabelSuffix]" v-if="item.inputType === '02'">
                      <el-option v-for="(dict,optIndex) in item.paramOptionList" :key="dict.value + optIndex" v-if="dict.isShow"
                                 :value="dict.value" :label="dict['label'+localLabelSuffix]">
                        <span style="float: left">{{ dict['label' + localLabelSuffix] }}</span>
                        <span style="float: right; color: #8492a6; font-size: 13px" v-if="dict.paraSource">
                                                  <el-popover
                                                    placement="top"
                                                    offset="170"
                                                    trigger="hover">
                                                    <span slot="reference">
                                                      <el-image :key="dict.value" :src="baseApi + dict.paraSource" style="width: 30px;height: 30px" fit="contain">
                                                          <div slot="error">
                                                              <div class="err-div" style="width: 30px;height: 30px;font-size: 6px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                          <div slot="placeholder">
                                                             <div class="err-div" style="width: 30px;height: 30px;font-size: 6px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                      </el-image>
                                                    </span>
                                                    <span><el-image :key="dict.value" :src="baseApi + dict.paraSource" style="width: auto;height: 200px" fit="fill">
                                                          <div slot="error">
                                                              <div class="err-div" style="width: 400px;height: 400px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                          <div slot="placeholder">
                                                             <div class="err-div" style="width: 400px;height: 400px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                    </el-image></span>
                                                    </el-popover>
                                                </span>
                      </el-option>
                    </el-select>
                    <!--                    小数输入框-->
                    <el-input-number :disabled="disableFlag||getUnEditable(paramCategoryList[pIndex].paramList[index].paraCode)" :precision="2" :controls="false"
                                     v-model="paramCategoryList[pIndex].paramList[index].finalValue" class="w-100" @change="paramChange(item,true)" :max="999999999999999999.99" :min="0"
                                     :placeholder="$t('common.pleaseInput') + item['label'+localLabelSuffix]" v-if="item.inputType === '03'"/>
                    <!--                    可输入下拉框-->
                    <el-select :disabled="disableFlag||getUnEditable(paramCategoryList[pIndex].paramList[index].paraCode)" filterable allow-create maxlength="60" clearable default-first-option
                               v-model="paramCategoryList[pIndex].paramList[index].finalValue" class="w-100" @change="paramChange(item,true)"
                               :placeholder="$t('common.pleaseSelect') + item['label'+localLabelSuffix]" v-if="item.inputType === '04'">
                      <el-option v-for="(dict,optIndex) in item.paramOptionList" :key="dict.value + optIndex" v-if="dict.isShow"
                                 :value="dict.value" :label="dict['label'+localLabelSuffix]">
                        <span style="float: left">{{ dict['label' + localLabelSuffix] }}</span>
                        <span style="float: right; color: #8492a6; font-size: 13px" v-if="dict.paraSource">
                                                  <el-popover
                                                    placement="top"
                                                    offset="170"
                                                    trigger="hover">
                                                    <span slot="reference">
                                                      <el-image :key="dict.value" :src="baseApi + dict.paraSource" style="width: 34px;height: 34px" fit="contain">
                                                          <div slot="error">
                                                              <div class="err-div" style="width: 34px;height: 34px;font-size: 6px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                          <div slot="placeholder">
                                                             <div class="err-div" style="width: 34px;height: 34px;font-size: 6px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                      </el-image>
                                                    </span>
                                                    <span><el-image :key="dict.value" :src="baseApi + dict.paraSource" style="width: auto;height: auto" fit="fill">
                                                          <div slot="error">
                                                              <div class="err-div" style="width: 400px;height: 400px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                          <div slot="placeholder">
                                                             <div class="err-div" style="width: 400px;height: 400px">{{ $t('quotation.noImg') }}</div>
                                                          </div>
                                                    </el-image></span>
                                                    </el-popover>
                                                </span>

                      </el-option>
                    </el-select>
                    <!--                    复选框-->
                    <el-checkbox :disabled="disableFlag||getUnEditable(paramCategoryList[pIndex].paramList[index].paraCode)"
                                 v-model="paramCategoryList[pIndex].paramList[index].finalValue" v-if="item.inputType === '05'"
                                 :true-label="'Yes'" :false-label="'No'" class="para-checkbox" @change="paramChange(item,true)"
                                  style=" ">
                      <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;max-width: 300px;display: inline-block;margin-bottom: -13px">
                        <span style="font-weight: 700;line-height: 36px;font-size: 14px;color:#606266;
                        ">{{ item['label' + localLabelSuffix] }}</span>
                      </div>
                    </el-checkbox>

                  </el-form-item>
                </div>
              </el-card>
              <!--              装潢包-->
              <el-card class="main-card mt30" id="renderCard1001" style="min-height: 400px;max-height: 800px;" v-if="decoratePicList.length > 0">
                <el-row>
                  <!--                  装潢包选择-->
                  <el-col :span="7" style="overflow: auto;max-height: 780px">
                    <div v-for="(item,index) in decoratePicList" class="out-check-div" @click="decorateSelectionChange(item,true)">
                      <div class="check-div" style="z-index: 2"><img v-if="item.checked" src="@/assets/images/check.png" class="check-img br6"/></div>
                      <div style="z-index: 1" class="br6">
                        <el-image :src="baseApi + item.url" class="br6" fit="fill" style="width: 6.5VW;height: 6.5vW">
                          <div slot="error">
                            <div class="err-div br6" style="width: 6.5vw;height: 6.5vw;font-size: 12px">{{ $t('quotation.noImg') }}</div>
                          </div>
                        </el-image>
                        <div style="color: gray;font-size: 12px;text-align: center;margin: auto;">{{ item.parabarDetailName }}</div>
                      </div>
                    </div>
                  </el-col>
                  <!--                  装潢包大图预览-->
                  <el-col :span="10">
                    <el-image :key="checkPicInfo.url" class="br6" fit="fill" style="width: 30.5vw;height: 770px;" :src="baseApi + checkPicInfo.url" >
                      <div slot="error">
                        <div class="err-div br6" style="width: 30.5vw;">{{ $t('quotation.noImg') }}</div>
                      </div>
                      <div slot="placeholder">
                        <div class="err-div br6" style="width: 30.5vw;">{{ $t('quotation.noImg') }}</div>
                      </div>
                    </el-image>
                  </el-col>
                  <!--                  装潢包选项-->
                  <el-col :span="7" style="overflow: auto;max-height: 780px">
                    <div v-for="(item,index) in decorateSelectionList" :key="'basicDecorate'+index" style="margin-left: 4%">
                      <el-form-item :prop="decorateSelectionList[index].paraCode" v-if="decorateSelectionList[index].finalValue">
                        <template slot="label">
                          <el-tooltip :content="item['label'+localLabelSuffix]" placement="top-start">
                            <span>{{ item['label' + localLabelSuffix] }}</span>
                          </el-tooltip>
                        </template>
                        <el-input v-model="decorateSelectionList[index].finalValue" class="w-100" disabled v-if="item.inputType == '00'"></el-input>
                        <el-input-number v-model="decorateSelectionList[index].finalValue" class="w-100" disabled v-if="item.inputType == '01'"
                                         :max="999999999999999999" :min="0" :controls="false"></el-input-number>
                        <el-select v-model="decorateSelectionList[index].finalValue" class="w-100" disabled v-if="item.inputType == '02' || item.inputType == '04'">
                          <el-option v-for="dict in item.paramOptionList" :key="dict.value"
                                     :label="dict['label'+localLabelSuffix]" :value="dict.value"/>
                        </el-select>
                        <el-input v-model="decorateSelectionList[index].finalValue" class="w-100" disabled v-if="item.inputType == '03'" :precision="2"
                                  :max="999999999999999999.99" :min="0" :controls="false"></el-input>
                      </el-form-item>
                    </div>
                  </el-col>
                </el-row>
              </el-card>
              <!--              非标描述-->
              <el-card class="main-card mt30" id="renderCard1002">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="addLine" v-if="!disableFlag">
                  {{ $t('quotation.addNonStandardDesc') }}
                </el-button>
                <el-button size="mini" plain icon="el-icon-delete" @click="deleteLine" :disabled="deleteDisabled" v-if="!disableFlag">
                  {{ $t('quotation.delNonStandardDesc') }}
                </el-button>
                <el-table :data="nonStandardList" @selection-change="additionalCostSelection" :style="disableFlag ? '':'margin-top: 10px'"
                          :header-cell-style="tableHeaderStyle" :border="true" :class="disableFlag ? 'desc':'desc-table'">
                  <el-table-column prop="selection" type="selection" width="60" align="center" key="selection" v-if="!disableFlag"></el-table-column>
                  <!--                  序号-->
                  <el-table-column label="No." type="index" width="50" align="center" key="no" min-width="200px"></el-table-column>
                  <el-table-column prop="nonStandardDesc" :label="$t('quotation.nonStandardDesc')" min-width="300" key="nonStandardDesc">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.nonStandardDesc" :disabled="disableFlag" maxlength="50"
                                :placeholder="$t('common.pleaseInput') + $t('quotation.nonStandardDesc')"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="fileList" :label="$t('common.annex')" width="250" key="fileList">
                    <template slot-scope="scope">
                      <div v-for="item in scope.row.fileList" style="margin-bottom: 5px" v-if="item.showFlag">
                        <el-alert type="error" @close="fileDelete(scope.row,item)" :closable="!disableFlag">
                          <div slot="title">
                            <a :href="baseApi + item.filePath" :download="item.realFileName">{{ item.realFileName }}</a>
                          </div>
                        </el-alert>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="operate" :label="$t('common.operate')" width="140" v-if="!disableFlag">
                    <template slot-scope="scope">
                      <el-upload
                        :show-file-list="false"
                        :file-list="fileList"
                        :headers="headers"
                        :on-remove="handleRemove"
                        :on-success="handleUploadSuccess"
                        :on-error="handleUploadError"
                        :on-preview="handlePreview"
                        :before-upload="handleBeforeUpload"
                        :action="uploadUrl"
                        multiple>
                        <el-button type="primary" @click="handleUploadFile(scope.row)">{{ $t('common.uploadFile') }}<i class="el-icon-upload el-icon&#45;&#45;right"></i></el-button>
                      </el-upload>
                    </template>
                  </el-table-column>
                </el-table>
              </el-card>

            </el-form>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>


<script>
import {listElevatorParam, listModelNewAll, listNewAllParam} from "@/api/business/crm/elevatorModel";
import {getInfoByTpElevatorModelId} from "@/api/business/crm/paraRelatedCase/relatedCase";
import store from '@/store'
import {checkElevatorParam, computeResult} from "@/api/business/crm/paraValidation/paraValidation";
import {getToken} from "@/utils/auth";
import {listSpecification} from "@/api/business/quotation/specification";
import {getCountry} from "@/api/user/country";
import {checkRole} from "@/utils/permission";

const labelSuffix = {
  chinese: '',
  english: 'US',
  russia: 'RU',
  spanish: 'ES',
}

export default {
  name: "Elevator",
  components: {},
  dicts: ['elevator_type'],
  data() {
    return {
      // 国家
      country: null,
      // 国家Id
      countryId: null,
      // 表头style
      tableHeaderStyle: {'background-color': '#F4F6F8', 'border-right': '1px solid #dfdcdc', 'color': '#92A2B5'},
      // 附件上传所在行
      rowIndex: null,
      // 上传文件文件头
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      // 上传的图片服务器地址
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload",
      // 上传附件列表
      fileList: [],
      // 附件弹窗
      attachmentVisible: false,
      // 非标描述选中行
      multipleSelection: [],
      // 删除非标描述是否可用
      deleteDisabled: true,
      // 非标列表
      nonStandardList: [],
      // 调试标记
      debug: false,
      // 下载文件url前缀
      baseApi: process.env.VUE_APP_BASE_API,
      paramCategoryList: [],
      // 侧面卡片
      asideCardList: [
        {'label': this.$t('lead.baseInfo'), 'value': true},
        {'label': this.$t('quotation.nonStandardDesc'), 'value': false}
      ],
      // 每个模块的滚定条值
      mainScrollList: [0],
      scrollTop: 10,
      form: {
        count: 1,
        elevatorType: null,
        elevatorModelId: null,
        elevatorGroupCode: null,
      },
      type: null,
      quotationType: null,
      disableFlag: false,
      // 电梯型号列表（下拉）
      elevatorModelList: [],
      // 电梯型号列表（全部）
      allElevatorModelList: [],
      rules: {
        elevatorType: [
          {required: true, message: this.$t('common.pleaseSelect') + this.$t('paraLibrary.elevatorType'), trigger: 'change'}
        ],
        elevatorModelId: [
          {required: true, message: this.$t('common.pleaseSelect') + this.$t('elevatorModel.elevatorModel'), trigger: 'change'}
        ],
        count: [
          {required: true, message: this.$t('common.pleaseInput') + this.$t('quotation.count'), trigger: 'blur'}
        ],
        elevatorGroupCode: [
          {required: true, message: this.$t('common.pleaseInput') + this.$t('elevator.groupCode'), trigger: 'blur'}
        ],
      },
      quotationId: null,
      elevatorId: null,
      // 实时参数联动规则
      ruleList: {},
      // 提交时参数联动规则
      onCommitRuleList: [],
      unEditAble: new Set(),
      scrollDisabledFlag: false,
      decoratePicList: [],
      decorateSelectionList: [],
      checkPicInfo: {},
      lastDecorateList: [],
      containerLoading: false,
      // 已存在的梯形，不能重复添加
      elevatorModelIdStr: '',
      areaId: null,
      // 最大文件上传大小
      fileSize: 10 * 1024 * 1024,
      // 参数
      loopTimes: 0,
      // 联动结果是否改变值
      isChangeResult: false,
      // 规格配置参数的特殊符号
      code: '$_$',
      paramCategoryMap: {}
    };
  },
  async created() {
    this.$modal.loading()
    this.quotationId = this.$route.query && this.$route.query.quotationId;
    this.elevatorModelIdStr = this.$route.query && this.$route.query.elevatorModelIdStr;
    this.areaId = this.$route.query && this.$route.query.areaId;
    this.countryId = this.$route.query && this.$route.query.countryId;
    await this.getCountryByCountryId()
    await this.initType();
    await this.initElevatorModel();
    // 页面回填
    await this.fillData();
    this.isChangeResult = true
    // this.renderAsideCard();
    this.$modal.closeLoading();
  },
  async activated() {
    await this.initType();
  },
  computed: {
    localLabelSuffix() {
      return labelSuffix[this.$i18n.locale] || '';
    }
  },
  watch: {
    asideCardList() {
      setTimeout(() => {
        this.initScrollList()
      }, 1000)
    }
  },
  methods: {
    checkRole,
    // 根据  countryId  获取country
    async getCountryByCountryId() {
      if (this.countryId) {
        getCountry(this.countryId).then(response => {
          try {
            this.country = response.data.countryName
          } catch (e) {
          }
          console.log('国家详细信息', this.country, response)
        })
      } else {
        console.log('无法获取国家，countryId 为空')
      }
    },
    // 替换电梯组号内的特殊符号
    replaceGroupCode(value) {
      if (value) {
        return value.replaceAll('-', '').replaceAll(',', '').replaceAll(':', '').replaceAll(' ', '')
      } else {
        return value
      }
    },
    // 上传前校验
    handleBeforeUpload(file) {
      // 校检文件大小
      if (this.fileSize) {
        console.log('文件大小', file.size)
        console.log('限制大小', this.fileSize)
        const sizeFlag = file.size > this.fileSize;
        if (sizeFlag) {
          this.$modal.msgError(`${this.$t('fileupload.sizeError')} 10 MB!`);
          return false;
        }
      }
      this.$modal.loading(this.$t('fileupload.uploading'));
      return true
    },
    // 非标描述附件删除
    fileDelete(row, item) {
      row.fileList.filter(a => {
        if (a.serverFileName === item.serverFileName) {
          a.showFlag = false
        }
      })
    },
    // 文件预览
    handlePreview(file) {
      console.log('文件预览', file)
      window.open(this.baseApi + file.filePath);
    },
    // 删除上传文件
    handleRemove(file, fileList) {
      this.fileList = fileList
    },
    // 上传成功
    handleUploadSuccess(res, file, fileList) {
      this.$modal.closeLoading();
      this.nonStandardList[this.rowIndex].fileList.push({
        name: res.originalFilename,
        realFileName: res.originalFilename,
        serverFileName: res.newFileName,
        filePath: res.fileName,
        showFlag: true
      })
    },
    // 上传失败
    handleUploadError() {
      this.$modal.closeLoading();
    },
    // 附件上传弹窗
    handleUploadFile(row) {
      this.rowIndex = row.index
    },
    // 非标描述增加行
    addLine() {
      this.nonStandardList.push({fileList: []})
      for (let i = 0; i < this.nonStandardList.length; i++) {
        this.nonStandardList[i].index = i;
      }
    },
    // 非标描述删除行
    deleteLine() {
      this.multipleSelection.forEach((account) => {
        this.nonStandardList = this.nonStandardList.filter((item) => {
          return item.index !== account.index;
        });
      });
      for (let i = 0; i < this.nonStandardList.length; i++) {
        this.nonStandardList[i].index = i;
      }
    },
    // 非标描述多选
    additionalCostSelection(selection) {
      this.multipleSelection = selection;
      this.deleteDisabled = this.multipleSelection.length === 0;
    },
    // 装潢参数联动还原
    restoreLastDecorateList() {
      let decorateSet = new Set();
      this.lastDecorateList.forEach(item => {
        decorateSet.add(item.paraCode)
      })
      for (let a = 0; a < this.paramCategoryList.length; a++) {
        let paramCategory = this.paramCategoryList[a]
        for (let b = 0; b < paramCategory.paramList.length; b++) {
          let param = paramCategory.paramList[b];
          // 需要联动还原
          if (decorateSet.has(param.paraCode)) {
            this.paramCategoryList[a].paramList[b].decorateValue = null
            this.paramChange(this.paramCategoryList[a].paramList[b])
          }
        }
      }
    },
    decorateSelectionChange(selection, needCheck) {
      console.log('选中装潢图片', selection)
      if (needCheck === true && (this.type === 'view' || this.type === 'detail')) {
        console.log('选中装潢图片无效', needCheck)
        // 查看/详情时点击图片失效
        return
      }
      // 重置图片点击状态
      this.decoratePicList.forEach(item => {
        item.checked = item.parabarDetailId === selection.parabarDetailId
      })
      // 设置选中大图信息
      this.$set(this.checkPicInfo, 'url', selection.url);
      // 还原上次联动
      this.restoreLastDecorateList()
      // 设置选中配置参数信息
      for (let i = 0; i < this.decoratePicList.length; i++) {
        if (selection.parabarDetailId === this.decoratePicList[i].parabarDetailId) {
          this.decorateSelectionList = this.decoratePicList[i].paramList
          this.lastDecorateList = this.decoratePicList[i].paramList
          break
        }
      }

      // check装潢参数 是否覆盖其他类型参数
      let decorateSet = new Set();
      let decorateMap = new Map();
      this.decorateSelectionList.forEach(item => {
        decorateSet.add(item.paraCode)
        decorateMap.set(item.paraCode, item.finalValue)
      })

      // STEP1 设置参数不可用
      for (let a = 0; a < this.paramCategoryList.length; a++) {
        let paramCategory = this.paramCategoryList[a]
        for (let b = 0; b < paramCategory.paramList.length; b++) {
          let param = paramCategory.paramList[b];
          this.paramCategoryList[a].paramList[b].enabled = !decorateSet.has(param.paraCode)
          let decorateValue = decorateMap.get(this.paramCategoryList[a].paramList[b].paraCode);
          if (decorateValue != null) {
            this.paramCategoryList[a].paramList[b].decorateValue = decorateValue
          }
        }
      }
      // STEP2 设置CARD
      for (let a = 0; a < this.paramCategoryList.length; a++) {
        let paramCategory = this.paramCategoryList[a]
        let cardEnabled = false;
        for (let b = 0; b < paramCategory.paramList.length; b++) {
          let param = paramCategory.paramList[b];
          if (param.enabled) {
            cardEnabled = true
            break
          }
        }
        this.paramCategoryList[a].enabled = cardEnabled;
      }
      //STEP3 装潢选型触发参数联动
      for (let i = 0; i < this.decorateSelectionList.length; i++) {
        // 触发参数联动
        this.paramChange(this.decorateSelectionList[i])
      }

      console.log('装潢选择后的卡片', this.paramCategoryList)
      console.log('装潢选择后的大图', this.checkPicInfo)
      // STEP4 页面重新渲染
      this.renderAsideCard()
    },
    parabarChange: function (item) {
      console.log('参数包变更', item)
      if (item.paramOptionList == null) {
        console.log('参数报配置参数为空')
        return;
      }
      // 获取参数包配置对应的值，转map
      let codeValueMap = new Map();
      // 选中参数包
      if (item.finalValue) {
        for (let i = 0; i < item.paramOptionList.length; i++) {
          let param = item.paramOptionList[i]
          if (param.value == item.finalValue) {
            let detailValueList = param.parabarDetailValueList
            if (detailValueList == null) {
              console.log('参数报配置参数详情为空')
              return;
            }
            for (let j = 0; j < detailValueList.length; j++) {
              let detail = detailValueList[j];
              codeValueMap.set(detail.paraCode, detail.paraValue)
            }
          }
        }
      } else {
        // 清空参数包
        if (item.paramOptionList && item.paramOptionList.length > 0) {
          let detailValueList = item.paramOptionList[0].parabarDetailValueList
          if (detailValueList == null) {
            console.log('参数报配置参数详情为空')
            return;
          }
          for (let j = 0; j < detailValueList.length; j++) {
            let detail = detailValueList[j];
            codeValueMap.set(detail.paraCode, null)
          }
        }
      }

      console.log('参数包配置参数值map', codeValueMap)
      codeValueMap.keys().forEach(key => {
        const param = this.paramCategoryMap[key]
        if (codeValueMap.has(param.paraCode)) {
            let paramValue = codeValueMap.get(param.paraCode);
            param.finalValue = this.getValue(paramValue)
            console.log('参数包配置参数变化联动', param)
            // 触发参数联动
            this.paramChange(param)
          }
      })
    },
    async paramChange(item, isFirst) {
      if (isFirst === true) {
        this.loopTimes = 0
      } else {
        this.loopTimes += 1
      }
      console.log('++++++++++++++++++当前循环次数 [' + this.loopTimes + ']')
      if (this.loopTimes > 10000) {
        console.log('参数联动循环次数大于10000次，循环停止');
        return;
      }
      if (this.type === 'view' || this.type === 'detail') {
        // 查看/详情时参数联动失效
        // return
      }
      console.log('参数变更', item)
      let rules = this.ruleList[item.paraCode];
      console.log('参数联动规则', this.ruleList)
      if (rules && rules.length > 0) {
        if (isFirst === true) {
          this.$modal.loading();
        }
        //判断项目是否存在联动关系中
        for (let i = 0; i < rules.length; i++) {
          let ruleItem = rules[i]
          let ruleItemConditionList = ruleItem.logics
          //判断if条件中 是 and 还是or
          let rule = ruleItem.relationship
          console.log('[ ' + ruleItem.caseName + ' ] 参数联动')
          //判断结果，存多个，后面如果if条件是and,那resultList中，但凡有一个FALSE，就不满足，如果条件是or，但凡有一个True，就满足
          let resultList = []
          for (let j = 0; j < ruleItemConditionList.length; j++) {
            let condition = ruleItemConditionList[j]
            //判断当前修改的控件对应的项目，所选值是否满足联动条件
            if (condition.paramCode == item.paraCode) {
              let formualResult = this.formualCalc(item.finalValue, condition.operation, condition.value)
              resultList.push(formualResult)
            } else {
              //判断联动条件中，非当前修改的控件对应的项目，所选值是否满足联动条件
              const otherItem = this.paramCategoryMap[condition.paraCode]
              if (otherItem) {
                // 优先获取装潢包参数值
                let calcValue = otherItem.decorateValue
                if (otherItem.enabled) {
                  calcValue = otherItem.finalValue
                }
                let conditionValue = condition.value
                // 如果是参数值，则先获取
                if (condition.valueType == '1') {
                  conditionValue = this.getParamValue(condition.value);
                  console.log('参数联动条件 参数值获取: 编码 [' + condition.value + '] 获取值 [' + conditionValue + ']')
                } else {
                  console.log('参数联动条件 普通参数值 [' + condition.value + '] ')
                }
                let otherResult = this.formualCalc(calcValue, condition.operation, conditionValue)
                resultList.push(otherResult)
              }
            }
          }
          console.log('判断结果计算', resultList)
          //只有一个条件的情况
          if (ruleItemConditionList.length === 1) {
            //满足条件
            if (resultList[0]) {
              console.log('开始满足一个条件，执行联动结果')
              //满足条件，执行联动结果
              await this.executeLinkResult(ruleItem.actions, true)
            } else {
            }
          } else {
            //存在多个条件的情况，也要考虑不满足条件，联动结果的选项，退回原来的可选list
            //都要满足 and
            if ('00' == rule) {
              if (resultList.indexOf(false) < 0) {
                //执行联动结果
                console.log('开始满足多个条件 && ，执行联动结果')
                //满足条件，执行联动结果
                await this.executeLinkResult(ruleItem.actions, true)
              } else {
              }
            } else {
              //满足其一 or

              if (resultList.indexOf(true) > -1) {
                //执行联动结果
                console.log('开始满足多个条件 || ，执行联动结果')
                //满足条件，执行联动结果
                await this.executeLinkResult(ruleItem.actions, true)
              } else {
              }
            }
          }
        }
      }

      if (isFirst === true) {
        this.renderAsideCard();
        this.$modal.closeLoading();
      }
    },
    async executeLinkResult(ruleResultList, needNext) {
      for (let i = 0; i < ruleResultList.length; i++) {
        let result = ruleResultList[i]
        const param = this.paramCategoryMap[result.paraCode]
        console.log('联动结果', result)
        if (!param) {
          continue
        }

        // 参数包配置参数不修改
        if (param.paramType === '02') {
          console.log('跳过参数包配置参数', param)
          continue
        }
        let resultValue = result.value;
        if (result.computedFlag === '1') {
          console.log('联动结果是公式', result.valueFormulaTxt)
          let form = {
            formula: result.valueFormulaTxt,
            paramList: this.getParamList(),
          }
          console.log('参数联动计算请求参数', form)
          let response = await computeResult(form)
          if (response.data.result === true) {
            resultValue = response.data.calculateValue
          } else {
            console.log('[' + result.valueFormulaTxt + ']无法计算联动结果')
            continue
          }
          console.log('联动结果是公式', resultValue)
        }
        console.log('联动结果值', resultValue)
        console.log('当前结果值', originalValue)
        let originalValue = param.finalValue
        // 修改值   输入框直接赋值
        if (param.inputType != '02' && param.inputType != '04' && this.isChangeResult) {
          param.finalValue = this.getValue(resultValue)
        }

        // 修改下拉的可选项
        if (result.selectItem !== null && result.selectItem.length > 0) {
          param.paramOptionList.forEach(dpItem => {
            dpItem.isShow = result.selectItem.split(';').includes(dpItem.value)
          })

          // 修改选中值  下拉框 如果目前的选中值，在可选范围则不变，否则清空
          // 当前选中值
          let currentValue = param.finalValue
          console.log('当前值', currentValue)
          console.log('当选下拉可选值', result.selectItem)
          if (result.selectItem.split(';').includes(currentValue)) {
            // 在可选范围，但是设定了默认值
            if (resultValue && this.isChangeResult) {
              param.finalValue = this.getValue(resultValue)
            }
          } else {
            if (this.isChangeResult) {
              // 不在可选范围
              param.finalValue = this.getValue(resultValue)
            }
          }
        } else {
          console.log(result.paraName + '无下拉选项', result)
        }
        console.log('满足一个条件，执行联动结果', param)
        if (this.isChangeResult && result.emptyFlag === '1') {
          if (param.inputType === '05') {
            console.log('复选框强制清除 ', param.label)
            param.finalValue = 'No'
          } else {
            console.log('非复选框强制清除 ', param.label)
            param.finalValue = undefined
          }
        }

        // 非活性时禁止编辑  1：非活性  0：活性
        if ('1' === result.editable) {
          this.unEditAble.add(result.paraCode)
        } else {
          this.unEditAble.delete(result.paraCode)
        }
        // 显示不显示  0：显示  1：隐藏
        if ('0' === result.displayFlag) {
          console.log(param.label + ' 显示')
          param.isShow = true
        } else {
          console.log(param.label + ' 隐藏')
          param.isShow = false
        }
        // 如果参数存在且有变化，继续执行参数联动
        let flag1 = param.finalValue;
        let flag2 = param.finalValue != originalValue
        if (flag1 && flag2 && needNext === true) {
          console.log('继续执行参数联动[' + flag1 + '] [' + flag2 + ']', param)
          await this.paramChange(param)
        } else {
          console.log('不继续执行参数联动[' + flag1 + '] [' + flag2 + ']', param)
        }
      }
    },
    formualCalc(param, formula, value) {
      console.log('[' + param + ']   [' + formula + ']  [' + value + ']')
      if (!param) {
        if (formula == '不包含') {
          console.log('页面填写参数为空，且不包含 true')
          return true
        } else {
          console.log('页面填写参数为空 false')
          return false
        }
      }
      switch (formula) {
        case '<':
          return Number(param) < Number(value)
        case '>':
          return Number(param) > Number(value)
        case '<=':
          return Number(param) <= Number(value)
        case '>=':
          return Number(param) >= Number(value)
        case '=':
          return param == value
        case '包含':
          return value.indexOf(param) > -1
        case '不包含':
          return value.indexOf(param) === -1
      }
    },
    async fillData() {
      console.log('页面数据回填 [' + this.type + ']', this.type === 'view' || this.type === 'edit' || this.type === 'detail')
      if (this.type === 'view' || this.type === 'edit' || this.type === 'detail') {
        this.elevatorId = this.$route.query && this.$route.query.elevatorId;
        let fillData = this.$store.state.elevators[this.elevatorId]
        console.log('页面回填数据', fillData);
        if (!fillData) {
          // 缓存没找到从后端获取
          if (this.elevatorId) {
            let form = {
              id: this.elevatorId
            }
            let data = await listSpecification(form)
            if (data.rows && data.rows.length > 0) {
              fillData = data.rows[0]
            }
            if (!fillData) {
              console.log('页面回填数据获取失败');
              return
            }
          }
        }
        this.form.elevatorType = fillData.elevatorType
        this.elevatorTypeChange(fillData.elevatorType)
        this.form.elevatorModelId = fillData.elevatorModelId
        await this.elevatorModelChange(fillData.elevatorModelId, false)
        this.form.count = fillData.elevatorNumber
        this.form.elevatorGroupCode = fillData.elevatorGroupCode

        // 参数值列表 =》 参数值map   key: category_code  value： value
        let fillParamMap = new Map();
        if (fillData.paramList != null && fillData.paramList.length > 0) {
          fillData.paramList.forEach(item => {
            fillParamMap.set(item.paraCategory + '_' + item.paraCode, item.paraValue)
          })
        }

        console.log('回填数据map', fillParamMap)
        for (let j = 0; j < this.paramCategoryList.length; j++) {
          // 参数类别
          let paramCategory = this.paramCategoryList[j]
          for (let k = 0; k < paramCategory.paramList.length; k++) {
            let fillValue = fillParamMap.get(paramCategory.paraCategory + '_' + paramCategory.paramList[k].paraCode)
            this.paramCategoryList[j].paramList[k].finalValue = this.getValue(fillValue);
          }
        }
        // 参数联动
        console.log('参数联动开始')
        console.log(this.paramCategoryList)
        for (let j = 0; j < this.paramCategoryList.length; j++) {
          // 参数类别
          let paramCategory = this.paramCategoryList[j]
          for (let k = 0; k < paramCategory.paramList.length; k++) {
            if (this.paramCategoryList[j].paramList[k].paramType === '01') {
              this.parabarChange(this.paramCategoryList[j].paramList[k])
            } else {
              await this.paramChange(this.paramCategoryList[j].paramList[k])
            }
          }
        }
        console.log('参数联动结束')
        // 装潢参数回填
        let decorateTempList = fillData.paramList.filter(item => item.paraCategory === '99');
        console.log('装潢参数回填1', decorateTempList)
        console.log('装潢参数回填2', this.decoratePicList)
        if (decorateTempList != null && decorateTempList.length > 0) {
          for (let i = 0; i < this.decoratePicList.length; i++) {
            if (this.decoratePicList[i].parabarDetailId === decorateTempList[0].parabarDetailId) {
              this.decorateSelectionChange(this.decoratePicList[i])
              break;
            }
          }
        }
        // 非标描述回填
        this.nonStandardList = fillData.nonStandardList
        for (let i = 0; i < this.nonStandardList.length; i++) {
          this.nonStandardList[i].index = i;
        }
        // 重新渲染对应高度
        this.initScrollList()
      }
    },
    async getInfoByTpElevatorMode(key, form) {
      const {cases} = this.$store.state.relatedCase
      const realTimeRules = cases.filter(item => item.elevatorIds && item.elevatorIds.split(',').includes(String(key)) && item.runType === '0')
      const onCommitRules = cases.filter(item => item.elevatorIds && item.elevatorIds.split(',').includes(String(key)) && item.runType === '1')


      // let cases = await getInfoByTpElevatorModelId(key, form)
      const ruleList = {}
      realTimeRules.forEach(rule => {
        rule.logics.forEach(logic => {
          const ruleCodeMap = ruleList[logic.paraCode] || []
          ruleCodeMap.push(rule)
          ruleList[logic.paraCode] = ruleCodeMap
        })
      })

      this.ruleList = ruleList
      this.onCommitRuleList = onCommitRules
      console.log('实时规则', this.ruleList)
      console.log('提交规则', this.onCommitRuleList)
    },
    // 电梯型号切换
    async elevatorModelChange(key, needLink) {
      this.$modal.loading();
      if (key) {
        let form = {
          quotationFlag: true
        }
        await this.getInfoByTpElevatorMode(key, form)

        this.decorateSelectionList = []
        this.checkPicInfo = {}
        let response = await listNewAllParam(key, {quotationFlag: true})


        this.$modal.closeLoading();

        let resultList = response.data.categoryList
        const paramCategoryMap = {}
        for (let j = 0; j < resultList.length; j++) {
          // 参数类别
          let paramCategory = resultList[j]
          for (let k = 0; k < paramCategory.paramList.length; k++) {
            // 将finalValue为null 的参数值变更为 undefined ,防止组件显示异常
            if (resultList[j].paramList[k].finalValue === null) {
              resultList[j].paramList[k].finalValue = undefined
            }
            // 赋值 '国家'参数，从项目获取
            if (resultList[j].paramList[k].paraCode == 'COUNTRY') {
              if (this.country) {
                resultList[j].paramList[k].finalValue = this.country
                resultList[j].paramList[k].paramOptionList = []
                resultList[j].paramList[k].paramOptionList.push(
                  {
                    'isShow': true,
                    'label': this.country,
                    'labelES': this.country,
                    'labelRU': this.country,
                    'labelUS': this.country,
                    'paraSource': null,
                    'paraBarDetailValueList': null,
                    'value': this.country,
                  }
                )
              } else {
                console.log('国家 赋值失败')
              }
            }

            paramCategoryMap[resultList[j].paramList[k].paraCode] = resultList[j].paramList[k]
          }
        }
        this.paramCategoryList = resultList
        this.paramCategoryMap = paramCategoryMap


        this.decoratePicList = response.data.eleDecorateConfigList
        if (needLink) {
          console.log('参数联动start')
          console.log(this.paramCategoryList)
          // 参数联动
          for (let j = 0; j < this.paramCategoryList.length; j++) {
            // 参数类别
            let paramCategory = this.paramCategoryList[j]
            for (let k = 0; k < paramCategory.paramList.length; k++) {
              if (this.paramCategoryList[j].paramList[k].paramType === '01') {
                this.parabarChange(this.paramCategoryList[j].paramList[k])
              } else {
                this.paramChange(this.paramCategoryList[j].paramList[k])
              }
            }
          }
          console.log('参数联动end')
          if (this.decoratePicList.length > 0) {
            this.decorateSelectionChange(this.decoratePicList[0])
          }
        } else {
          console.log('选择梯形参数联动不执行')
        }
        // 普通参数联通  装潢包参数联动
        console.log('电梯参数列表', this.paramCategoryList)
        this.renderAsideCard()

      } else {
        this.renderAsideCard()
      }
      // 自动出发时不要关闭loading
      if (needLink) {
        this.$modal.closeLoading();
      }
    },
    // 电梯类型切换
    elevatorTypeChange(key) {
      let elevatorModelIdList = []
      // if (this.elevatorModelIdStr) {
      // elevatorModelIdList = this.elevatorModelIdStr.split(',');
      // }
      let checkElevatorModeList = this.allElevatorModelList.filter(item => item.elevatorType === key && elevatorModelIdList.indexOf(item.id + '') === -1)
      this.elevatorModelList = []
      checkElevatorModeList.forEach(item => {
        this.elevatorModelList.push(
          {
            'label': item.elevatorModel,
            'value': item.id,
          }
        )
      })
      // 清空电梯型号，选配参数，侧边卡片
      this.form.elevatorModelId = null
      this.paramCategoryList = []
      this.decorateSelectionList = []
      this.decoratePicList = []
      this.checkPicInfo = {}
      this.unEditAble = new Set();
      this.renderAsideCard()
    },
    async initElevatorModel() {
      let form = {}
      if (this.type === 'detail'){
        form = {
          needAll: true
        }
      }else {
        form = {
          // areaId: [this.areaId],
          countryId: this.countryId,
        }
      }
      const response = await listModelNewAll(form);
      if (response.rows) {
        this.allElevatorModelList = response.rows
      }
    },
    initScrollList() {
      this.$nextTick(() => {
        this.mainScrollList = [0]
        for (let i = 0; i < this.paramCategoryList.length; i++) {
          if (this.paramCategoryList[i].isShow && this.paramCategoryList[i].enabled) {
            // 计算每个卡片的滚动条位置
            let div = document.getElementById('renderCard' + i);
            // console.log(('renderCard' + i), div)
            this.mainScrollList.push(div.offsetTop - 57)
          }
        }
        // 装潢包
        if (this.decoratePicList != null && this.decoratePicList.length > 0) {
          let div = document.getElementById('renderCard1001');
          this.mainScrollList.push(div.offsetTop - 57)
        }
        // 非标描述
        let div2 = document.getElementById('renderCard1002');
        this.mainScrollList.push(div2.offsetTop - 57)
      })
    },
    // 渲染左侧卡片
    renderAsideCard() {
      let index = 0
      for (let i = 0; i < this.asideCardList.length; i++) {
        if (this.asideCardList[i].value) {
          index = i
        }
      }
      let newAsideCardList = []
      newAsideCardList.push({'label': this.$t('lead.baseInfo'), 'value': false})
      let newList = this.paramCategoryList.filter(item => item.isShow && item.enabled)
      for (let i = 0; i < newList.length; i++) {
        newAsideCardList.push({'label': newList[i]['label' + this.localLabelSuffix], 'value': false})
      }
      // 装潢参数
      if (this.decoratePicList != null && this.decoratePicList.length > 0) {
        newAsideCardList.push({'label': this.$t('validation.decorationParam'), 'value': false})
      }
      // 非标描述
      newAsideCardList.push({'label': this.$t('quotation.nonStandardDesc'), 'value': false})
      if (newAsideCardList.length > index) {
        newAsideCardList[index].value = true
      }
      this.asideCardList = newAsideCardList;
    },
    async initType() {
      this.type = this.$route.query && this.$route.query.type;
      this.quotationType = this.$route.query && this.$route.query.quotationType;
      this.accountTitle = this.$t('elevator.view');
      switch (this.type) {
        case 'add':
          this.accountTitle = this.$t('elevator.add');
          this.disableFlag = false
          break;
        case 'edit':
          this.accountTitle = this.$t('elevator.edit');
          this.disableFlag = false
          break;
        case 'view':
          this.accountTitle = this.$t('elevator.view');
          this.disableFlag = true
          break;
        case 'detail':
          this.accountTitle = this.$t('elevator.view');
          this.disableFlag = true
          break;
      }
      console.log('标题', this.accountTitle)
      const obj = Object.assign({}, this.$route, {title: this.accountTitle})
      this.$tab.updatePage(obj);
    },
    submitForm: async function () {
      this.$modal.loading()
      console.log(this.nonStandardList)
      if (this.nonStandardList && this.nonStandardList.length > 0) {
        for (let i = 0; i < this.nonStandardList.length; i++) {
          if (!this.nonStandardList[i].nonStandardDesc) {
            this.$modal.closeLoading()
            this.$message.error(this.$t('quotation.nonStandardDescEmpty'))
            return
          }
        }
      }
      let config = await this.getSpecification('quoatation.specification:' + this.form.elevatorType)
      let configMap = new Map()

      // this.$refs['form'].validate((valid) => {
      let valid = false
      try {
        valid = await this.$refs['form'].validate()
      } catch (e) {

      }
      console.log('表单验证结果', valid)
      if (!valid) {
        this.$modal.closeLoading()
      } else {
        // 执行提交时参数联动
        if (this.onCommitRuleList && this.onCommitRuleList.length > 0) {
          console.log('执行提交时参数联动++++++++++++++++START++++++++++++++++++++')
          // 提交时参数联动
          for (let i = 0; i < this.onCommitRuleList.length; i++) {
            let ruleItem = this.onCommitRuleList[i]
            // 参数联动逻辑运算符
            let ruleItemConditionList = ruleItem.logics
            let rule = ruleItem.relationship
            // 条件结果
            let resultList = []
            for (let j = 0; j < ruleItemConditionList.length; j++) {
              let condition = ruleItemConditionList[j]
              const otherItem = this.paramCategoryMap.get(condition.paraCode)
              //判断联动条件中，非当前修改的控件对应的项目，所选值是否满足联动条件
              // 优先获取装潢包参数值
              let calcValue = otherItem.decorateValue
              if (otherItem.enabled) {
                calcValue = otherItem.finalValue
              }
              let conditionValue = condition.value
              // 如果是参数值，则先获取
              if (condition.valueType == '1') {
                conditionValue = this.getParamValue(condition.value);
                console.log('参数联动条件 参数值获取: 编码 [' + condition.value + '] 获取值 [' + conditionValue + ']')
              } else {
                console.log('参数联动条件 普通参数值 [' + condition.value + '] ')
              }
              let otherResult = this.formualCalc(calcValue, condition.operation, conditionValue)
              resultList.push(otherResult)
            }
            console.log('判断结果计算', resultList)
            //只有一个条件的情况
            if (ruleItemConditionList.length === 1) {
              //满足条件
              if (resultList[0]) {
                console.log('开始满足一个条件，执行联动结果')
                //满足条件，执行联动结果
                await this.executeLinkResult(ruleItem.actions, false)
              }
            } else {
              //存在多个条件的情况，也要考虑不满足条件，联动结果的选项，退回原来的可选list
              //都要满足 and
              if ('00' == rule) {
                if (resultList.indexOf(false) < 0) {
                  //执行联动结果
                  console.log('开始满足多个条件 && ，执行联动结果')
                  //满足条件，执行联动结果
                  await this.executeLinkResult(ruleItem.actions, false)
                }
              } else {
                //满足其一 or

                if (resultList.indexOf(true) > -1) {
                  //执行联动结果
                  console.log('开始满足多个条件 || ，执行联动结果')
                  //满足条件，执行联动结果
                  await this.executeLinkResult(ruleItem.actions, false)
                }
              }
            }
          }
          console.log('执行提交时参数联动++++++++++++++++ END ++++++++++++++++++++')
        } else {
          console.log('无提交时参数联动')
        }

        // 组装传递数据
        let elevatorModelName = this.elevatorModelList.filter(item => item.value === this.form.elevatorModelId)[0]?.label
        let storage = {...this.form}
        if (this.elevatorId) {
          storage.id = this.elevatorId
        } else {
          storage.id = Date.now()
        }
        // 获取规则的各项参数，拼接展示
        storage.elevatorModel = elevatorModelName
        storage.areaId = this.areaId
        storage.createTime1 = this.formatDate(new Date())
        storage.elevatorNumber = storage.count
        for (let i = 0; i < this.nonStandardList.length; i++) {
          if (this.nonStandardList[i].fileList && this.nonStandardList[i].fileList.length > 0) {
            this.nonStandardList[i].fileList = this.nonStandardList[i].fileList.filter(a => a.showFlag)
          }
        }
        storage.nonStandardList = this.nonStandardList
        // 获取电梯参数
        let paramListForm = []
        for (let j = 0; j < this.paramCategoryList.length; j++) {
          // 参数类别
          let paramCategory = this.paramCategoryList[j]
          for (let k = 0; k < paramCategory.paramList.length; k++) {
            if (paramCategory.paramList[k].enabled) {
              paramListForm.push({
                paramType: paramCategory.paramList[k].paramType,
                parabarId: paramCategory.paramList[k].parabarId,
                parabarDetailId: paramCategory.paramList[k].parabarDetailId,
                paraValue: paramCategory.paramList[k].finalValue,
                paraCode: paramCategory.paramList[k].paraCode,
                paraCategory: paramCategory.paraCategory
              })
            } else {
              console.log('跳过参数', paramCategory.paramList[k])
            }
            if (config.indexOf(this.code + paramCategory.paramList[k].paraCode + this.code) !== -1) {
              configMap.set(this.code + paramCategory.paramList[k].paraCode + this.code, paramCategory.paramList[k].finalValue)
            }
          }
        }
        // 装潢包参数组装
        if (this.decorateSelectionList != null && this.decorateSelectionList.length > 0) {
          for (let i = 0; i < this.decorateSelectionList.length; i++) {
            paramListForm.push({
              paramType: '02',
              parabarId: this.decorateSelectionList[i].parabarId,
              parabarDetailId: this.decorateSelectionList[i].parabarDetailId,
              paraValue: this.decorateSelectionList[i].finalValue,
              paraCode: this.decorateSelectionList[i].paraCode,
              paraCategory: '99'
            })

            if (config.indexOf(this.code + this.decorateSelectionList[i].paraCode + this.code) !== -1) {
              configMap.set(this.code + this.decorateSelectionList[i].paraCode + this.code, this.decorateSelectionList[i].finalValue)
            }
          }
        }
        // 电梯规格
        configMap.forEach((value, key) => {
          let replaceValue = value ? value : ''
          config = config.replaceAll(key, replaceValue)
        });
        // 异常电梯规格格式化
        if (config.indexOf(this.code) !== -1) {
          let configList = config.split(this.code);
          // 2的倍数
          if (Math.log2(configList.length) % 1 === 0) {
            config = config.replaceAll(this.code, '')
          } else {
            for (let i = 0; i < configList.length; i++) {
              if ((i & 1) === 1) {
                configList[i] = ''
              }
            }
            config = configList.join('');
          }
        }

        storage.specification = config
        console.log('电梯规格', config)
        storage.paramList = paramListForm
        let quotationIdFlag = this.quotationId != null
        let checkParamForm = {
          elevatorModelId: this.form.elevatorModelId,
          paramList: paramListForm,
          quotationFlag: true
        }
        console.log('电梯参数校验参数', checkParamForm)
        checkElevatorParam(checkParamForm).then(response => {
          if (response.data != null && response.data.length > 0) {
            let message = ''
            for (let i = 0; i < response.data.length; i++) {
              let item = response.data[i]
              message += item['resultFalse' + this.localLabelSuffix]
              if (i !== response.data.length - 1) {
                message += '<br>'
              }
            }
            let up = '<div style="word-break: break-all;">'
            let down = '</div>'
            this.$notify.error({
              title: this.$t('elevator.rulesResult'),
              message: up + message + down,
              // 毫秒
              duration: 1000 * 30,
              dangerouslyUseHTMLString: true,
            });
          } else {
            store.commit('PUT_ELEVATOR', storage)
            console.log('电梯保存 ' + storage.id + '  ,', storage)
            this.$tab.closeOpenPage({path: "/quotation/editQuotation?type=" + this.quotationType + '&elevatorId=' + storage.id + (quotationIdFlag ? "&quotationId=" + this.quotationId : "")});
            let msg = this.$t('common.addSuccess')
            if (this.type === 'edit') {
              msg = this.$t('common.editSuccess')
            }
            this.$message.success(msg)
          }
        }).finally(() => {
          this.$modal.closeLoading()
        })
      }
      //   }
      // )
    },
    cancel() {
      let quotationIdFlag = this.quotationId != null
      if (this.type === 'detail' || this.type === 'view') {
        this.$tab.closePage();
      } else {
        this.$tab.closeOpenPage({path: "/quotation/editQuotation?type=" + this.quotationType + (quotationIdFlag ? "&quotationId=" + this.quotationId : "")});
      }
    },
    // 获取所有电梯参数
    getParamList() {
      let paramListForm = []
      for (let j = 0; j < this.paramCategoryList.length; j++) {
        // 参数类别
        let paramCategory = this.paramCategoryList[j]
        for (let k = 0; k < paramCategory.paramList.length; k++) {
          if (paramCategory.paramList[k].enabled) {
            paramListForm.push({
              inputType: paramCategory.paramList[k].inputType,
              paramType: paramCategory.paramList[k].paramType,
              parabarId: paramCategory.paramList[k].parabarId,
              parabarDetailId: paramCategory.paramList[k].parabarDetailId,
              paraValue: paramCategory.paramList[k].finalValue,
              paraCode: paramCategory.paramList[k].paraCode,
              paraCategory: paramCategory.paraCategory
            })
          } else {
            console.log('跳过参数', paramCategory.paramList[k])
          }
        }
      }
      // 装潢包参数组装
      if (this.decorateSelectionList != null && this.decorateSelectionList.length > 0) {
        for (let i = 0; i < this.decorateSelectionList.length; i++) {
          paramListForm.push({
            inputType: this.decorateSelectionList[i].inputType,
            paramType: '02',
            parabarId: this.decorateSelectionList[i].parabarId,
            parabarDetailId: this.decorateSelectionList[i].parabarDetailId,
            paraValue: this.decorateSelectionList[i].finalValue,
            paraCode: this.decorateSelectionList[i].paraCode,
            paraCategory: '99'
          })
        }
      }
      return paramListForm;
    },
    // 根据电梯参数CODE  获取参数值
    getParamValue(code) {
      const item = this.paramCategoryMap[code]
      if (item && item.enabled) {
        return item.finalValue
      }

      // 装潢包参数组装
      if (this.decorateSelectionList != null && this.decorateSelectionList.length > 0) {
        for (let i = 0; i < this.decorateSelectionList.length; i++) {
          if (this.decorateSelectionList[i].paraCode == code) {
            return this.decorateSelectionList[i].finalValue
          }
        }
      }
      return paramListForm;
    },
    // 监听滚动条
    listenScroll(event) {
      if (this.scrollDisabledFlag) {
        this.scrollDisabledFlag = false
        return;
      }
      let scrollTop = event.target.scrollTop;
      for (let i = 0; i < this.mainScrollList.length; i++) {
        if (this.mainScrollList[i] <= scrollTop && scrollTop < this.mainScrollList[i + 1]) {
          // console.log("选中", i)
          this.checkAside(i)
          return
        } else if (i === this.mainScrollList.length - 1 && scrollTop > this.mainScrollList[i]) {
          // 选中最后一条
          // console.log("选中", i + 1)
          this.checkAside(i)
          return
        }
      }
    },
    // 左侧导航条点击事件
    clickAside(index) {
      this.checkAside(index)
      this.scrollDisabledFlag = true
      const container = this.$refs.scrollContainer;
      container.scrollTop = this.mainScrollList[index]
    },
    // 高亮左侧导航条
    checkAside(index) {
      this.asideCardList.forEach(item => item.value = false);
      this.asideCardList[index].value = true
    },
    // 从参数联动设定管理获取（活性 false/非活性 true）
    getUnEditable(item) {
      // 国家不允许修改，默认值
      if (item == 'COUNTRY') {
        return true
      }
      return this.unEditAble.has(item)
    },
    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      const seconds = String(date.getSeconds()).padStart(2, '0');
      return `${year}-${month}-${day}`;
      // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    async getSpecification(key) {
      let response = await this.getConfigKey(key)
      if (response.msg) {
        return response.msg;
      }
      return '';
    },
    getValue(value) {
      return value === null ? undefined : value
    }
  }
};
</script>

<!--style-->
<style scoped>
.ts-form-item ::v-deep .el-form-item__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  /*display:inline;*/
}


.err-div {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  text-align: center; /* 文字水平居中 */
  height: 200px; /* 设置容器高度 */
  width: 300px; /* 设置容器宽度 */
  /*border: 1px solid #ccc; !* 边框 *!*/
  user-select: none;
  background-color: rgb(245, 247, 250);
}

.aside-div-unchecked {
  height: 50px;
  font-family: Arial, Arial;
  font-weight: normal;
  font-size: 18px;
  color: #3C485B;
  line-height: 23px;
  text-align: left;
  font-style: normal;
  padding-top: 14px;
  padding-left: 24px;
  cursor: pointer;
}

.aside-div-checked {
  height: 50px;
  background: #D31017;
  border-radius: 6px;
  font-family: Arial, Arial;
  font-weight: normal;
  font-size: 18px;
  color: #FFFFFF;
  line-height: 23px;
  text-align: left;
  font-style: normal;
  padding-top: 14px;
  padding-left: 24px;
  cursor: pointer;
}

.container-aside {
  overflow: hidden;
  width: 20% !important;
  background: #f1f5f9 !important;
}

.container-main {
  padding-top: 8px !important;
  padding-right: 0px !important;
}

.aside-card {
  border-radius: 6px;
}

.w-100 {
  width: 100%;
}

.mt30 {
  margin-top: 30px;
}

.check-div {
  position: absolute;
}

.check-img {
  background-color: white;
  width: 1vw;
  position: relative;
  float: right;
  /*border-radius: 4px !important;*/
  border: #ffffff 2px solid;
  margin-top: -1px;
  margin-left: -1px;
}

.br6 {
  border-radius: 6px;
}

.out-check-div {
  display: inline-block;
  margin-left: 5px;
  width: 31%;
  cursor: pointer;
}

.form-div {
  width: calc(25% - 10px) !important;
  display: inline-block;
  margin-right: 10px
}

.el-input-number ::v-deep .el-input__inner {
  text-align: left;
}

.desc-table ::v-deep .el-table__cell:first-child .cell {
  padding: 0;
}

.para-checkbox ::v-deep .el-checkbox__inner {
  width: 20px;
  height: 20px;
}

.para-checkbox ::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
  background-color: #e0e0e3;
  border-color: #DCDFE6;
}

.para-checkbox ::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner {
  background-color: #e0e0e3;
  border-color: #DCDFE6;
}

.para-checkbox ::v-deep .el-checkbox__inner::after {
  width: 6px;
  height: 14px;
  border: 2px solid #FFF !important;
  border-left: 0 !important;
  border-top: 0 !important;
  top: -1px;
  left: 5px;
}
</style>
