multipleSpecificationForm.vue 33.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
<template>
  <div class="multipleSpecification-form">
    <div class="content_box">
      <div class="sepce-box" v-for="(subItem, subIndex) in goodsInfoData.specificationDetailList" :key="subIndex">
        <div>
          <span class="specs-item">
            产品规格{{ subIndex + 1 }}:
            <span style="color: #333333">{{ subItem.specificationName }}</span>
          </span>
          <span class="specs-item" v-for="(n, idx) in subItem.specificationValueList" :key="idx">
            值:
            <span style="color: #333333">{{ n.specificationValue }}</span>
          </span>
        </div>
        <div>
          <el-button type="text" @click="handleSpecsEdit(2, subItem, subIndex)"
            v-if="routeInfo.type != 2">编辑</el-button>
          <el-button type="text" @click="handleSpecsDelete(subIndex)" v-if="routeInfo.type != 2">删除</el-button>
        </div>
      </div>
      <div v-if="goodsInfoData.specificationDetailList && goodsInfoData.specificationDetailList.length">
        <div class="table-wrapper">
          <table class="table-spesc" cellspacing="0" cellpadding="0" :style="{ width: `${tableWidth}px` }">
            <tbody>
              <tr
                style="background: #f2f4f7; height: 42px; display: flex; align-items: center; justify-content: center">
                <td style="width: 75px" v-if="routeInfo.type != 2"><el-checkbox v-model="checked"
                    @change="handleCheckAllChange" :indeterminate="isIndeterminate"></el-checkbox></td>
                <td style="width: 75px">序号</td>
                <td style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden"
                  v-for="(subItem, subIndex) in goodsInfoData.specificationDetailList"
                  :title="subItem.specificationName" :key="subIndex">{{ subItem.specificationName }}</td>
                <td>
                  <span class="color-red">*</span>
                  <span>投保成本/元</span>
                </td>
                <td>
                  <span class="color-red">*</span>
                  <span>上架成本/元</span>
                </td>
                <td>
                  <span class="color-red">*</span>
                  <span>嘀加成本/元</span>
                </td>
                <td>
                  <span>适用车型</span>
                  <img src="@/assets/icon-edit.png"
                    style="cursor: pointer; margin-left: 5px; width: 16px; height: 16px; vertical-align: middle"
                    @click="carTypeSelect(true)" />
                </td>
                <td style="width: 60px" v-if="routeInfo.type != 2"><span>操作</span></td>
              </tr>
            </tbody>
          </table>
          <table class="table-spesc content-table" cellspacing="0" cellpadding="0"
            :style="{ width: `${tableWidth}px` }">
            <tbody>
              <tr
                style="border-bottom: 1px solid #e5e5e5; height: 40px; line-height: 40px; display: flex; align-items: center; justify-content: center"
                v-for="(subItem, subIndex) in filterStatus" :key="subIndex">
                <td style="width: 75px" v-if="routeInfo.type != 2"><el-checkbox v-model="subItem.checked"
                    @change="changeTableCheck"></el-checkbox></td>
                <td style="width: 75px">{{ subIndex + 1 }}</td>
                <td style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden"
                  v-for="(n, idx) in subItem.specsValueList" :key="idx" :title="n">{{ n }}</td>
                <td>
                  <!-- 使用 subItem.originalIndex 传递原始数组索引,避免索引错位 -->
                  <el-input placeholder="请输入" maxlength="20" :disabled="routeInfo.type == 2" size="small"
                    :class="{ 'w-150-per': true, 'border-red': filterEmpty(subItem.insuranceCost) && subItem.insuranceCostEmpty }"
                    v-model.trim="subItem.insuranceCost" @input="handleKilometersInput($event, subItem.originalIndex)"
                    @blur="handleKilometersBlur($event, subItem.originalIndex)">
                    <el-popover v-if="filterEmpty(subItem.insuranceCost) && subItem.insuranceCostEmpty" slot="suffix"
                      placement="top" title width="90" trigger="hover" content="投保成本是必填项">
                      <i class="el-icon-warning color-red" slot="reference" />
                    </el-popover>
                  </el-input>
                </td>
                <td>
                  <el-input placeholder="请输入" maxlength="20" :disabled="routeInfo.type == 2" size="small"
                    v-model.trim="subItem.shelfCost"
                    :class="{ 'w-150-per': true, 'border-red': filterEmpty(subItem.shelfCost) && subItem.shelfCostEmpty }"
                    @input="handleWarrantyPeriodInput($event, subItem.originalIndex)"
                    @blur="handleWarrantyPeriodBlur($event, subItem.originalIndex)">
                    <el-popover v-if="filterEmpty(subItem.shelfCost) && subItem.salesCostEmpty" slot="suffix"
                      placement="top" title width="90" trigger="hover" content="上架成本是必填项">
                      <i class="el-icon-warning color-red" slot="reference" />
                    </el-popover>
                  </el-input>
                </td>
                <td>
                  <el-input placeholder="请输入" maxlength="20" :disabled="routeInfo.type == 2" size="small"
                    v-model.trim="subItem.salesCost"
                    :class="{ 'w-150-per': true, 'border-red': filterEmpty(subItem.salesCost) && subItem.salesCostEmpty }"
                    @input="handlePurchasePrice($event, subItem.originalIndex)" @blur="handlePurchasePriceBlur($event, subItem.originalIndex)">
                    <el-popover v-if="filterEmpty(subItem.salesCost) && subItem.salesCostEmpty" slot="suffix"
                      placement="top" title width="90" trigger="hover" content="嘀加成本是必填项">
                      <i class="el-icon-warning color-red" slot="reference" />
                    </el-popover>
                  </el-input>
                </td>
                <td class="select">
                  <el-select ref="chooseProjectName" placeholder="车型" :disabled="routeInfo.type == 2" size="small"
                    multiple collapse-tags :class="{ 'w-200-per': false }" v-model="subItem.seriesConfigList"
                    @focus="carTypeSelect(false, subItem, subIndex)" value-key="seriesId">
                    <el-option v-for="item in subItem.seriesConfigList" :key="item.vehicleSeriesId"
                      :label="item.vehicleSeriesName" :value="item"></el-option>
                  </el-select>
                </td>
                <td style="width: 60px" v-if="routeInfo.type != 2">
                  <el-button type="text" :disabled="subItem.merchantGoodsInfos && subItem.merchantGoodsInfos.length > 0"
                    @click="delspecificationValueList(subItem)">删除</el-button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>

        <div style="margin-top: 10px">
          共
          <span class="tip-text">{{ filterStatus.length }}</span>
          件规格商品。
        </div>
      </div>
    </div>
    <D2Dialog title="规格" :is-visible.sync="specificationVisible" width="550px"
      :specificationDetailList="goodsInfoData.specificationDetailList" @confirmDialog="handleSpescConfirm"
      @closeDialog="handleSpescClose">
      <el-form label-width="120px" :model="spescEditForm" :rules="spescRules" ref="spescRef">
        <el-form-item label="规格名称:" prop="specificationName">
          <el-input class="w-320" size="small" maxlength="20" v-model="spescEditForm.specificationName"
            placeholder="请输入规格名" :disabled="disabledSpecificationName"></el-input>
        </el-form-item>
        <div class="selectOpt">
          <span class="label">预设规格:</span>
          <el-button type="text" class="selectItem" v-for="(item, index) in disabledSkuSelect"
            @click="handleSelect(item)" :key="index"
            :class="{ active: item.specificationName == spescEditForm.specificationName || item.disabled }">{{
              item.specificationName }}</el-button>
        </div>
        <el-form-item label="规格值:" prop="specificationValueList">
          <el-tag style="margin-right: 10px" v-for="(tag, i) in spescEditForm.specificationValueList" :key="i"
            @click="changeValue(tag, i)" closable @close="handleSpescDelete(tag)">{{ tag.specificationValue }}</el-tag>
          <!-- <el-input min="0" max="100" clearable type="number" step="0.0001" class="!w-[120px]" placeholder="输入检测值" v-model="value" @input="value = value.replace(/^(100|[1-9]?\d)(\.\d{0,4})?.*$/, '$1$2')"></el-input> -->
          <el-input class="input-new-tag" v-if="specsInputVisible && spescEditForm.type == 0" v-model="spescInputVal"
            maxlength="20" ref="saveSpescInput" size="small" @keyup.enter.native="handleInputConfirm"
            @blur="handleInputConfirm"></el-input>
          <el-input min="0" max="100" type="number" class="input-new-tag"
            v-else-if="specsInputVisible && spescEditForm.type != 3" v-model="spescInputVal" ref="saveSpescInput"
            @input="spescInputVal = spescInputVal.replace(/^(100|[1-9]?\d).*$/, '$1')" size="small"
            @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm"></el-input>
          <input-number-range v-else-if="specsInputVisible && spescEditForm.type == 3" :disabled="false"
            :precision="num" :spescInputVal="spescInputVal" @confirm="handleInputConfirmMue"
            @input="spescInputVal = spescInputVal.replace(/^(199|1\d{2}|[1-9]?\d)(\.\d{0,2})?.*$/, '$1$2')"></input-number-range>
          <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 规格值</el-button>
        </el-form-item>
      </el-form>
    </D2Dialog>
    <brandDialog v-if="brandVisible" ref="brandRef" :relate-store-visible="brandVisible" :store-selected="storeSelected"
      @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose">
    </brandDialog>
    <skuDialog v-if="skuVisible" ref="brandRef" :relate-store-visible="skuVisible"
      :goodsSpecificationList="goodsInfoData.goodsSpecificationList"
      :specificationDetailList="goodsInfoData.specificationDetailList" @handleRelateSkuConfirm="handleRelateSkuConfirm"
      @handleSkuClose="handleSkuClose"></skuDialog>
  </div>
</template>
<script>
import D2Dialog from '@/components/d2-dialog'
import InputNumberRange from './inputNumberRange.vue'
// import relateCarDialog from './relateCarDialog.vue'
import brandDialog from './brandDialog'
import skuDialog from './skuDialog'
import { limitPrice, deepClone } from '@/common/constant'
import { mapGetters, mapMutations, mapActions } from 'vuex'
export default {
  name: 'MultipleSpecificationForm',
  components: {
    D2Dialog,
    InputNumberRange,
    brandDialog,
    skuDialog
  },
  props: {
    routeInfo: {
      type: Object,
      default: () => ({})
    },
    productServiceItemList: {
      type: Array,
      default: () => []
    },
    extendServicePartList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      value: '',
      skuVisible: false,
      carSelectName: '',
      isAllow: false,
      storeSelected: [],
      brandVisible: false,
      isIndeterminate: false,
      checked: false,
      carDialogVisibleBoolean: false,
      numberRange: [],
      normalSelectList: [
        {
          specificationName: '服务年限/年',
          type: 1,
          specificationValueList: []
          // specificationValueList: [{ specificationValue: 1 }, { specificationValue: 3 }, { specificationValue: 5 }]
        },
        {
          specificationName: '公里数/km/万',
          type: 2,
          specificationValueList: []
          // specificationValueList: [{ specificationValue: 3 }, { specificationValue: 5 }, { specificationValue: 10 }]
        },
        {
          specificationName: '适用车价/万',
          type: 3,
          // specificationValueList: [{ specificationValue: '0-15' }, { specificationValue: '15-30' }, { specificationValue: '30-50' }]
          specificationValueList: []
        }
      ],
      batchSubmitted: {
        upgradePriceEmpty: false,
        purchasePriceEmpty: false,
        warrantyPeriodEmpty: false
      },
      minPrice: 0,
      maxPrice: 0,
      specificationVisible: false,
      spescEditForm: { type: 0, specificationName: '', specificationValueList: [] },
      specsInputVisible: false,
      spescRules: {
        specificationName: [
          { required: true, message: '请输入规格名', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              return this.spescData.curSpeceNameList.some(item => item == value) ? callback(new Error('规格名重复')) : callback()
            },
            trigger: 'blur'
          }
        ],
        specificationValueList: [{ required: true, message: '请输入规格值', trigger: 'change' }]
      },
      spescInputVal: '',
      reg: {
        priceReg: /^\d[\d.]*$/, // 匹配数字和小数点
        typeReg: /^[A-Za-z0-9]+$/ // 匹配字母和数字
      },
      productPositionTypeList: [],
      // membraneTypeList: baseConfig.membraneTypeList,
      membraneTypeList: [],
      tableWidth: 0,
      tableColNum: 0,
      serviceItemsVisible: false,
      serviceItemsSearchForm: {
        serviceName: '',
        serviceGrade: ''
      },
      serviceSelected: [],
      serviceSelectIndex: null,
      extendServiceSelected: [],
      extendServiceSelectIndex: null,
      extendServiceItemsVisible: false,
      extendServiceItemsSearchForm: {
        serviceName: '',
        supportPosition: 0
      },
      supportPositionList: [] // 部件筛选项数据
    }
  },
  mounted() {
    this.computedTableWidth(this.goodsInfoData?.goodsType)
  },
  watch: {
    specificationVisible: {
      handler() {
        this.isChange = false
        this.spescInputVal = ''
      },
      deep: true
    }
  },
  computed: {
    ...mapGetters('goodsInfoData', { goodsInfoData: 'getGoodsInfoData' }),
    filterStatus() {
      console.log(this.goodsInfoData?.goodsSpecificationList, 'this.goodsInfoData?.goodsSpecificationList')
      // 过滤禁用状态,并为每一行添加原始索引(参照 dj-car-life-system 的实现)
      if (!this.goodsInfoData?.goodsSpecificationList) return []

      return this.goodsInfoData.goodsSpecificationList
        .map((item, originalIndex) => {
          // 为每一行添加原始索引,方便模板中使用
          if (item.useStatus != 1) {
            return {
              ...item,
              originalIndex  // 添加原始数组索引
            }
          }
          return null
        })
        .filter(item => item !== null)
    },
    disabledSpecificationName() {
      return (
        this.normalSelectList.findIndex(item => {
          if (item.specificationName == this.spescEditForm.specificationName) {
            return true
          }
        }) !== -1
      )
    },
    disabledSkuSelect() {
      return this.normalSelectList.map(item => {
        item.disabled = this.goodsInfoData?.specificationDetailList.some(ele => {
          return ele.specificationName == item.specificationName
        })
        return item
      })
    }
  },
  methods: {
    ...mapMutations('goodsInfoData', ['setUpdateGoodsInfo']),
    // 打开门店弹窗或者品牌弹窗
    carTypeSelect(type = false, item, rowindex) {
      console.log('type', item)

      // 阻止下拉框弹出

      let _this = this
      console.log(_this.$refs.chooseProjectName[rowindex])
      item && _this.$refs.chooseProjectName[rowindex].blur()

      if (!type) {
        this.carSelectName = item.specsValueList
        this.storeSelected = deepClone(item.seriesConfigList || [])
      } else {
        this.storeSelected = []
      }
      this.isAllow = type
      this.brandVisible = true
    },
    // 确认门店弹窗或者品牌弹窗
    handleRelateStoreConfirm(selectedData) {
      // 如果是批量
      if (this.isAllow) {
        this.goodsInfoData?.goodsSpecificationList.forEach(item => {
          if (item.checked) {
            item.seriesConfigList = selectedData
          }
        })
      } else {
        this.goodsInfoData?.goodsSpecificationList.forEach(item => {
          if (JSON.stringify(item.specsValueList) == JSON.stringify(this.carSelectName)) {
            item.seriesConfigList = selectedData
          }
        })
      }
      console.log(selectedData, 'selectedData')
      this.handleRelateStoreClose()
    },
    // 关闭门店弹窗或者品牌弹窗
    handleRelateStoreClose() {
      this.brandVisible = false
    },
    handleRelateSkuConfirm(tableData) {
      console.log(tableData, 'tableData')
      tableData.forEach(item => {
        this.goodsInfoData?.goodsSpecificationList.forEach(item2 => {
          if (JSON.stringify(item2.specsValueList) == JSON.stringify(item.specsValueList)) {
            item2.useStatus = item.useStatus
          }
        })
      })
      this.handleSkuClose()
    },
    handleSkuClose() {
      this.skuVisible = !this.skuVisible
    },
    // 门店弹窗按回车查询
    handleStoreInput(e) {
      e.keyCode === 13 && this.handleSearchStore()
    },
    // 门店弹窗点击查询
    handleSearchStore() {
      this.$refs.formRelateStore.handleCurrentChange(1)
    },
    handleCheckAllChange() {
      this.goodsInfoData?.goodsSpecificationList.forEach(item => {
        item.checked = this.checked
      })
      this.isIndeterminate = false
      // this.changeTableCheck()
    },
    changeTableCheck() {
      this.checked = this.goodsInfoData?.goodsSpecificationList.every(item => {
        return item.checked
      })
      this.isIndeterminate =
        !this.checked &&
        this.goodsInfoData?.goodsSpecificationList.some(item => {
          return item.checked
        })
      console.log(this.checked, this.isIndeterminate)
    },
    // carDialogVisible() {},
    handleSelect(item) {
      // 已经是一样的就跳过
      if (item.specificationName == this.spescEditForm.specificationName || item.disabled) return false
      this.spescEditForm = deepClone(item)
    },
    computedTableWidth(newVal, num) {
      const shoppingMallFlag = this.filterEmpty(num) ? num : this.goodsInfoData.shoppingMallFlag
      let tableColNum = this.tableColNum

      // 135 序号和操作栏宽度
      this.tableWidth = tableColNum * 220 + 135
    },
    // 添加规格status(1 - 新增;2 - 编辑)
    handleSpecsEdit(status, targetItem, targetIdx) {
      console.log('handleSpecsEdit')
      console.log(this.goodsInfoData, 'goodsInfoData')
      // debugger
      if (status == 1 && this.goodsInfoData.specificationDetailList?.length >= 5) {
        return this.$message({
          message: '只能新增5个规格值',
          type: 'error'
        })
      }
      var curSpeceNameList = []
      this.goodsInfoData.specificationDetailList?.forEach((item, index) => {
        if (status == 1 || (status == 2 && index != targetIdx)) {
          curSpeceNameList.push(item.specificationName)
        }
      })
      this.spescData = {
        // 1 - 新增;2 - 编辑
        status: status,
        targetIdx: targetIdx,
        curSpeceNameList: curSpeceNameList
      }
      this.spescEditForm = status == 2 ? deepClone(targetItem) : { type: 0, specificationName: '', specificationValueList: [] }
      this.copyGoodsSpecificationNameData = status == 2 ? this.goodsInfoData.goodsSpecificationNameList && this.goodsInfoData.goodsSpecificationNameList[targetIdx] : undefined
      this.handleSpescClose()
    },
    // 二次确认
    secondSimpleConfirm(title, txt, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            fn && fn()
          }
        }
      })
    },
    // 删除规格值
    handleSpecsDelete(index) {
      this.secondSimpleConfirm('删除', '是否删除该规格?', () => {
        this.goodsInfoData.specificationDetailList.splice(index, 1)
        this.changeSpecs()
      })
    },
    filterEmpty(data) {
      return data instanceof Array ? data.length <= 0 : (data ?? '') === ''
    },
    handleSpescClose() {
      this.$nextTick(() => {
        this.$refs['spescRef'].clearValidate()
      })

      this.specificationVisible = !this.specificationVisible
    },
    showInput() {
      this.specsInputVisible = true
      this.spescInputVal = ''
      this.$nextTick(_ => {
        this.$refs.saveSpescInput && this.$refs.saveSpescInput.$refs.input.focus()
      })
    },
    // 修改规格值tag
    changeValue(tag, i) {
      this.specsInputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveSpescInput.$refs.input.focus()
      })
      this.spescInputVal = tag.specificationValue
      this.tempTag = tag.specificationValue
      this.isChange = true
    },
    handleSpescDelete(tag) {
      this.isChange = false
      this.spescEditForm.specificationValueList.splice(this.spescEditForm.specificationValueList.indexOf(tag), 1)
    },
    handleInputConfirmMue(e) {
      this.spescInputVal = e.value
      this.handleInputConfirm(e)
    },
    handleInputConfirm(e) {
      const spescInputVal = this.spescInputVal
      if (spescInputVal.indexOf(';~;') > -1) {
        this.$message({
          message: '规格值不可包含;~;特殊字符',
          type: 'error',
          customClass: 'message-Z-zinde'
        })
        return true
      }
      if (this.spescEditForm.specificationValueList.length == 99) {
        this.$message({
          message: '规格值最多不能超过99个',
          type: 'error',
          customClass: 'message-Z-zinde'
        })
        return true
      }
      if (this.spescEditForm.specificationValueList.findIndex(i => i.specificationValue == spescInputVal) != -1) {
        this.$message({
          message: spescInputVal + '规格值已经存在',
          type: 'error',
          customClass: 'message-Z-zinde'
        })
        return true
      }
      if (this.isChange && spescInputVal) {
        this.spescEditForm.specificationValueList[this.spescEditForm.specificationValueList.findIndex(i => i.specificationValue == this.tempTag)].specificationValue = spescInputVal
        this.specsInputVisible = false
        this.isChange = false
        return
      }
      if (spescInputVal) {
        this.spescEditForm.specificationValueList.push({ specificationValue: spescInputVal })
      }
      this.$refs.spescRef.validateField('specificationValueList')
      this.specsInputVisible = false
      this.spescInputVal = ''
    },
    handleSpescConfirm() {
      const _this = this
      _this.$refs.spescRef.validate(valid => {
        if (valid) {
          if (this.spescData.status == 1) {
            _this.goodsInfoData.specificationDetailList.push(_this.spescEditForm)
          } else {
            _this.goodsInfoData.specificationDetailList[_this.spescData.targetIdx] = _this.spescEditForm
          }
          _this.changeSpecs()
          _this.spescEditForm = {}
          _this.handleSpescClose()
        }
      })
    },
    // 删除某一项
    delspecificationValueList(i) {
      // this.goodsInfoData.goodsSpecificationList.splice(i, 1)
      this.goodsInfoData?.goodsSpecificationList.forEach(item => {
        if (JSON.stringify(item.specsValueList) == JSON.stringify(i.specsValueList)) {
          console.log(item)
          item.useStatus = 1
        }
      })
    },
    // 规格值解构
    changeSpecs(restData) {
      // debugger
      // console.log('changeSpecs')
      this.computedTableWidth(this.goodsInfoData.goodsType)
      console.log(this.goodsInfoData, 'goodsInfoData')
      const copySpecificationValueList = deepClone(this.goodsInfoData.goodsSpecificationList)
      const copyDetailLength = this.goodsInfoData.goodsSpecificationNameList?.length
      const copyDetailData = this.goodsInfoData.goodsSpecificationNameList
      this.goodsInfoData.goodsSpecificationList = []
      console.log(copySpecificationValueList, 'copySpecificationValueList')
      let flag = true
      for (var i = 0; i < this.goodsInfoData.specificationDetailList?.length; i++) {
        // 规格名有变化 需清空id
        if (copyDetailLength && this.goodsInfoData.specificationDetailList[i]?.specificationName !== copyDetailData[i]?.specificationName) {
          console.log(this.goodsInfoData.specificationDetailList[i]?.specificationName, copyDetailData[i]?.specificationName)
          flag = false
          delete this.goodsInfoData.specificationDetailList[i]?.id
        }

        for (var j = 0; j < this.goodsInfoData.specificationDetailList[i]?.specificationValueList?.length; j++) {
          if (i == 0) {
            // 第一层规格:直接创建新行
            this.goodsInfoData.goodsSpecificationList.push({
              id: '',
              position: [],
              purchasePrice: '',
              specificationData: '',
              specsValueList: [this.goodsInfoData.specificationDetailList[i]?.specificationValueList[j]?.specificationValue],
              type: '',
              thirdPartyCode: '',
              warningValue: '',
              warningValueMax: '',
              warrantyPeriod: '5',
              editGoodNameInput: false,
              insuranceCost: '', // 投保成本,单位元
              shelfCost: '', // 上架成本,单位元
              salesCost: '', // salesCost
              seriesConfigList: [],
              useStatus: 0,
              checked: false,
              insuranceCostEmpty: false,
              shelfCostEmpty: false,
              salesCostEmpty: false
            })
          } else {
            // 非第一层规格:需要复制现有行并与新规格值组合
            const targetValLen = this.goodsInfoData.specificationDetailList[i]?.specificationValueList?.length

            if (j == 0) {
              // 第一次进入:复制现有行,为后续规格值做准备
              const currentLength = this.goodsInfoData.goodsSpecificationList.length
              const newRows = []

              // 复制现有行 targetValLen 次
              for (let k = 0; k < targetValLen; k++) {
                this.goodsInfoData.goodsSpecificationList.forEach(item => {
                  newRows.push(deepClone({
                    ...item,
                    specsValueList: [...item.specsValueList]
                  }))
                })
              }

              // 清空并重新赋值
              this.goodsInfoData.goodsSpecificationList = newRows
            }

            // 为当前规格值位置的所有行添加规格值
            const currentLen = this.goodsInfoData.goodsSpecificationList.length
            const step = Math.floor(currentLen / targetValLen)
            const startIdx = j * step

            for (let k = startIdx; k < startIdx + step; k++) {
              if (this.goodsInfoData.goodsSpecificationList[k]) {
                this.goodsInfoData.goodsSpecificationList[k].specsValueList.push(
                  this.goodsInfoData.specificationDetailList[i]?.specificationValueList[j]?.specificationValue
                )
              }
            }
          }
        }
      }
      this.goodsInfoData.goodsSpecificationList.forEach(item => {
        for (var i = 0; i < copySpecificationValueList.length; i++) {
          var temp = copySpecificationValueList[i]
          console.log(temp.specificationData)
          console.log(item.specsValueList.join(';~;'))
          if (temp.specificationData == item.specsValueList.join(';~;') && flag && !restData) {
            console.log(temp, item, flag, !restData, temp.specificationData, item.specsValueList.join(';~;'), '!restData')
            item.id = temp.id ? temp.id : ''
            item.warningValue = temp.warningValue
            item.warningValueMax = temp.warningValueMax
            item.position = temp.position
            item.type = temp.type
            item.thirdPartyCode = temp.thirdPartyCode
            item.purchasePrice = temp.purchasePrice
            item.warrantyPeriod = temp.warrantyPeriod || '5'
            item.insuranceCost = temp.insuranceCost
            item.shelfCost = temp.shelfCost
            item.salesCost = temp.salesCost
            item.useStatus = temp.useStatus
            item.seriesConfigList = temp.seriesConfigList
            item.specificationData = temp.specificationData
            item.checked = temp.checked || false
            item.insuranceCostEmpty = temp.insuranceCostEmpty || false
            item.shelfCostEmpty = temp.shelfCostEmpty || false
            item.salesCostEmpty = temp.salesCostEmpty || false
            break
          }
        }
      })
      console.log(this.goodsInfoData.goodsSpecificationList, 'this.goodsInfoData.goodsSpecificationList')
    },
    // 校验型号
    handleTypeInput(newValue, index) {
      if (!this.reg.typeReg.test(newValue)) {
        newValue = ''
      }
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'type', newValue)
    },
    // 校验采购价
    handlePurchasePrice(newValue, index) {
      newValue = newValue.replace(/[^\d.]/g, '')
      let oldValue = `${this.goodsInfoData.goodsSpecificationList[index]['oldsalesCost']}`
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'salesCost', limitPrice(newValue, oldValue, 20, 2, 0))
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'oldsalesCost', this.goodsInfoData.goodsSpecificationList[index]['salesCost'])
    },
    handlePurchasePriceBlur(e, index) {
      const newValue = e.target.value
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'salesCostEmpty', newValue ? false : true)
    },
    // 质保
    handleWarrantyPeriodInput(newValue, index) {
      newValue = newValue.replace(/[^\d.]/g, '')
      let oldValue = `${this.goodsInfoData.goodsSpecificationList[index]['oldshelfCost']}`
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'shelfCost', limitPrice(newValue, oldValue, 20, 2, 0))
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'oldshelfCost', this.goodsInfoData.goodsSpecificationList[index]['shelfCost'])
    },
    handleWarrantyPeriodBlur(e, index) {
      const newValue = e.target.value
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'shelfCostEmpty', newValue ? false : true)
    },
    // 公里数
    handleKilometersInput(newValue, index) {
      newValue = newValue.replace(/[^\d.]/g, '')
      let oldValue = this.goodsInfoData.goodsSpecificationList[index]['oldInsuranceCost'] ? `${this.goodsInfoData.goodsSpecificationList[index]['oldInsuranceCost']}` : ''
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'insuranceCost', limitPrice(newValue, oldValue, 20, 2, 0))
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'oldInsuranceCost', this.goodsInfoData.goodsSpecificationList[index]['insuranceCost'])
    },
    handleKilometersBlur(e, index) {
      const newValue = e.target.value
      this.$set(this.goodsInfoData.goodsSpecificationList[index], 'insuranceCostEmpty', newValue ? false : true)
    }
  }
}
</script>
<style lang="scss" scoped>
.multipleSpecification-form {
  .content_box {
    font-size: 14px;
    margin-top: 10px;

    .sepce-box {
      margin: 10px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .specs-item {
        color: #666666;
        margin-right: 20px;
      }
    }

    .tip-text {
      color: #2a58ad;
    }

    .table-wrapper {
      max-height: 450px;
      overflow: auto;

      .table-spesc {
        width: 100%;
        text-align: center;
        border: 1px solid #e8e8ea;
        position: relative;

        .table_content {
          table-layout: fixed;
          border-collapse: separate;
        }

        tr {
          display: flex;
          flex-wrap: nowrap;
          border-bottom: 1px solid #e8e8ea;

          td {
            display: inline-block;
            text-align: center;
            vertical-align: middle;
            width: 220px;
            height: 100%;
            line-height: 40px;
            border-right: 1px solid #e8e8ea;

            span {
              display: inline-block;
              vertical-align: middle;
            }
          }

          td:last-child {
            border-right: none;
          }
        }

        .w-150-per {
          width: 150px;

          .el-input__inner {
            padding: 0 10px;
          }
        }

        .w-90-per {
          width: 90px;
        }

        .w-200-per {
          width: 200px;
        }

        .color-red {
          color: #eb4e4e;
          font-size: 14px;
          margin-right: 4px;
          cursor: pointer;
        }
      }
    }

    .content-table {
      color: #666666;
      max-height: 400px;
      overflow-y: overlay;
    }
  }
}

.input-new-tag {
  width: 90px !important;
  vertical-align: bottom;
}

.selectOpt {
  margin-top: 10px;

  .label {
    margin-left: 120px;
  }

  .selectItem {
    padding: 8px 4px;
  }

  .selectItem+.selectItem {
    margin-left: 0px;
  }

  .active {
    color: #999999;
  }
}

.select {
  ::v-deep .el-select .el-tag {
    max-width: 75%;
  }
}

.w-320 {
  width: 320px !important;
}

::v-deep .border-red {
  .el-input__inner {
    border: 1px solid #eb4e4e;
  }
}

::v-deep .service_select_class {
  display: none;
}
</style>