SecondStep.js 31 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 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
// packageEquity/pages/carEquity/components/SecondStep/SecondStep.js
import data from '../constant/stepData'
// import fn from '../constant/ruleFn'
import {
  getProductStrategy,
  DISCOUNT_TYPE,
  ORDER_TYPE
} from '../../services/simpleQuotationProduct.strategy.js'
import { buildOrderTypeSelectionState } from '../../services/orderStrategyUi.js'
import {
  centToYuanText,
  compareCentAmounts,
  yuanToCentInteger
} from '../../services/quotationMoney.helpers.js'
import NP from 'number-precision'
const defaultLabelWidth = 'var(--fontSize140)'
const djPayTypeList = [
  {
    value: 1,
    name: '线上支付'
  },
  {
    value: 6,
    name: '对公转账'
  },
  {
    value: 7,
    name: '其它收款'
  }
]
const merchantPayTypeList = [
  {
    value: 2,
    name: '门店收款'
  }
]
Component({
  options: {
    // styleIsolation: 'apply-shared'
    styleIsolation: 'shared'
  },
  // behaviors: ['wx://component-export'],
  attached() {
    console.log('component attached')
    this.makeYear()
  },

  /**
   * 组件的属性列表
   */
  pageLifetimes: {
    show: function () {},
    attached: function () {
      // 在组件实例进入页面节点树时执行
    },
    hide: function () {}
  },
  properties: {
    serviceInfo: {
      type: Object,
      value: () => {}
    },
    orderInfo: {
      type: Object,
      observer: function (n) {
        // if (n?.modifyEquityQuotation) {
        //   this.setData({
        //     activeNames: ['3'],
        //     disable: true
        //   })
        // } else {
        //   this.setData({
        //     activeNames: ['1', '2', '3', '4'],
        //     disable: false
        //   })
        // }
      }
    },
    quotationGoodsList: {
      type: Array,
      value: () => {}
    },
    paymentMethod: Number,
    totalFee: {
      type: Number,
      value: 0
    },
    createAllGoodsFlag: {
      type: Number,
      value: 1
    }
  },
  observers: {
    'orderInfo.orderType': function (newVal) {
      if (newVal) {
        const matched = this.data.orderTypeList.find(
          item => item.value == newVal
        )
        if (matched) {
          this.setData({
            orderTypeName: matched.text
          })
        }
      }
    },
    'orderInfo.outTradeNo': function (value) {
      // console.log(value, 'outTradeNo')
      // if (value) {
      value &&
        this.setData({
          textNameObj: {
            confirmName: '确认',
            cancelName: '放弃'
          }
        })
      // }
    },
    'orderInfo.payType': function (paytype) {
      // if (value) {
      if (paytype) {
        let { orderInfo } = this.data
        let updateData = {
          payTypeList: paytype == 2 ? merchantPayTypeList : djPayTypeList
        }
        if (!orderInfo?.resetOrder && !orderInfo?.outTradeNo) {
          updateData['textNameObj.confirmName'] =
            paytype == 1 ? '下一步·去支付(1/2)' : '下一步·上传凭证'
        }
        this.setData(updateData)
      }
      // }
    },
    'orderInfo.resetOrder': function (value) {
      // console.log(value, 'outTradeNo')
      // if (value) {
      value &&
        this.setData({
          textNameObj: {
            confirmName: '确认',
            cancelName: '放弃'
          }
        })
      // }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    defaultLabelWidth,
    showYear: false,
    // 选择时间的年份
    columns: [],
    disable: false,
    currentDate: new Date().getTime(),

    // 默认当前年份
    currentIndex: new Date().getFullYear() - (new Date().getFullYear() - 25),

    currentName: new Date().getFullYear() + '年',
    popupShow: false,
    popupInputShow: false,
    // customInput: true,
    // secondObj: data.secondObj,
    formRule: data.formRule,
    textNameObj: {
      confirmName: '下一步·去支付(1/2)',
      // editName: '修改',
      cancelName: '存草稿'
    },
    // '1', '2', '3',
    activeNames: ['1', '2', '3', '4'],
    goodsBox: false,
    skuGoodsBox: false,
    showPicker: false,
    // optionsSelect: Object.freeze(optionsSelect),
    popObj: {
      popValue: ''
    },
    popInputObj: {
      type: 'add'
    },
    showError: false,
    insuranceCheck: false,
    testQuotedPriceUpdate: 0,
    payeeList: [
      {
        name: '嘀加收款',
        value: 0
      },
      {
        name: '4S店收款',
        value: 1
      }
    ],
    payTypeList: djPayTypeList,
    successDateTime: '',
    skuGoodsData: {}, //多规格商品数据
    payTypeObj: {
      1: '线上支付',
      2: '门店收款',
      5: '嘀加收款',
      6: '对公转账',
      7: '其它收款'
    },
    orderTypeList: [
      {
        text: '正常订单',
        value: 1
      },
      {
        text: '打折策略',
        value: 2
      },
      {
        text: '买赠策略',
        value: 3
      },
      {
        text: '冲量活动',
        value: 4
      },
      {
        text: '组合付款',
        value: 5
      },
	  {
        text: '内部结算',
        value: 6
      }
    ],
    orderTypeName: '正常订单',
    orderTypeBox: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getEditableOrderInfo() {
      return wx.$util.deepClone(
        this.properties.orderInfo || this.data.orderInfo || {}
      )
    },
    emitOrderPatch(patch) {
      this.triggerEvent('orderChange', { patch: patch })
    },
    tipsEvent() {
      this.triggerEvent('showTips')
    },
    // 打开订单类型选择
    openOrderType() {
      if (this.data.createAllGoodsFlag == 0) return
      this.setData({
        orderTypeBox: true
      })
    },
    onCloseOrderType() {
      this.setData({
        orderTypeBox: false
      })
    },
    onConfirmOrderType(e) {
      const { value } = e.detail
      const selection = buildOrderTypeSelectionState(
        this.getEditableOrderInfo(),
        value.value
      )
      const { orderInfo, orderPatch } = selection
      const vdQuotationGoodsList = orderInfo.vdQuotationGoodsList || []

      // 如果订单类型改变,重置所有商品的折扣信息
      if (selection.changed) {
        vdQuotationGoodsList.forEach(item => {
          const strategy = getProductStrategy(item)
          if (strategy) {
            // 重置为无折扣
            strategy.resetDiscount()
          }
        })
      }
      this.setGoodsListTotal(orderInfo, orderPatch)
      this.setData({
        orderTypeName: value.text,
        orderTypeBox: false
      })
    },
    changeProductDiscountType(e) {
      console.log(e, 'e')
      // Use currentTarget.dataset for bindtap
      const { index, gindex, type } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      const vdQuotationGoodsList = orderInfo.vdQuotationGoodsList || []
      const discountType = parseInt(type)

      const item = vdQuotationGoodsList[index]
      const strategy = getProductStrategy(item)

      if (strategy) {
        // 如果是套餐子商品
        if (gindex !== undefined && strategy.updateSubItemDiscount) {
          strategy.updateSubItemDiscount(gindex, discountType, '') // Reset to empty string
        } else {
          strategy.setDiscount(discountType, '') // Reset value when type changes
        }
        this.setGoodsListTotal(orderInfo)
      }
    },
    toggleGift(e) {
      const { index, gindex } = e.currentTarget.dataset
      const { value } = e.detail
      const newDiscountType = parseInt(value)

      const orderInfo = this.getEditableOrderInfo()
      const vdQuotationGoodsList = orderInfo.vdQuotationGoodsList || []

      const item = vdQuotationGoodsList[index]
      const strategy = getProductStrategy(item)

      if (strategy) {
        if (gindex !== undefined && strategy.updateSubItemDiscount) {
          strategy.updateSubItemDiscount(gindex, newDiscountType, '')
        } else {
          strategy.setDiscount(newDiscountType, '')
        }
        this.setGoodsListTotal(orderInfo)
      }
    },
    inputDiscountValue(e) {
      const { index, gindex } = e.currentTarget.dataset
      let { value } = e.detail
      const orderInfo = this.getEditableOrderInfo()
      const vdQuotationGoodsList = orderInfo.vdQuotationGoodsList || []

      const item = vdQuotationGoodsList[index]
      const strategy = getProductStrategy(item)

      if (strategy) {
        // 获取当前的 discountType
        let currentType
        let basePrice
        if (gindex !== undefined && strategy.getSubItemData) {
          currentType = strategy.getSubItemData(gindex).discountType
          basePrice = strategy.getSubItemBasePrice(gindex)
        } else {
          currentType = strategy.getData().discountType
          basePrice = strategy.getBasePrice()
        }

        // 1:默认值为空不是为0
        if (value === '') {
          // Allow empty value
        } else {
          // Remove non-digit and non-dot characters
          value = value.replace(/[^\d.]/g, '')

          if (value.length > 1 && value.startsWith('0') && value[1] !== '.') {
            value = value.replace(/^0+/, '')
            if (value === '') {
              value = '0'
            } else if (value.startsWith('.')) {
              value = '0' + value
            }
          }

          // Ensure only one dot
          const parts = value.split('.')
          if (parts.length > 2) {
            value = parts[0] + '.' + parts.slice(1).join('')
          }

          if (currentType == 1) {
            // 折扣比例
            // 2:是折扣比例的话,最多只能输入1位整数和1个小数
            // 允许输入 10 (无折扣)
            if (value === '10') {
              // Allow '10'
            } else if (value.startsWith('10') && value !== '10') {
              // If starts with 10 but has more chars (e.g. 10.1), restrict to 10
              value = '10'
            } else {
              const dotIndex = value.indexOf('.')
              if (dotIndex !== -1) {
                let integerPart = value.substring(0, dotIndex)
                let decimalPart = value.substring(dotIndex + 1)
                if (integerPart.length > 1) {
                  integerPart = integerPart.slice(0, 1)
                }
                if (decimalPart.length > 1) {
                  decimalPart = decimalPart.slice(0, 1)
                }
                value = integerPart + '.' + decimalPart
              } else {
                if (value.length > 1) {
                  value = value.slice(0, 1)
                }
              }
            }
          } else if (currentType == 2) {
            // 折扣金额
            // 3:是折扣金额的话,最大值不能超过 item.goods.sellPrice 的值,超过取 item.goods.sellPrice,输入最多不超过两个小数
            const dotIndex = value.indexOf('.')
            if (dotIndex !== -1) {
              let integerPart = value.substring(0, dotIndex)
              let decimalPart = value.substring(dotIndex + 1)
              if (decimalPart.length > 2) {
                decimalPart = decimalPart.slice(0, 2)
              }
              value = integerPart + '.' + decimalPart
            }

            const discountAmount = yuanToCentInteger(value)
            const compared = discountAmount.ok
              ? compareCentAmounts(discountAmount.value, basePrice)
              : { ok: false }
            if (compared.ok && compared.value > 0) {
              const formatted = centToYuanText(basePrice)
              value = formatted.ok
                ? formatted.value
                    .replace(/\.00$/, '')
                    .replace(/(\.\d)0$/, '$1')
                : '0'
            }
          }
        }

        if (gindex !== undefined && strategy.updateSubItemDiscount) {
          strategy.updateSubItemDiscount(gindex, currentType, value)
        } else {
          strategy.setDiscount(currentType, value)
        }
        this.setGoodsListTotal(orderInfo)
      }
    },
    changePrice(e) {
      let { value } = e.detail
      if (value.length > 1 && value.startsWith('0') && value[1] !== '.') {
        value = value.replace(/^0+/, '')
        if (value === '') {
          value = '0'
        } else if (value.startsWith('.')) {
          value = '0' + value
        }
      }
      // 限制最多小数点后2位
      if (value.includes('.')) {
        const parts = value.split('.')
        if (parts[1] && parts[1].length > 2) {
          value = parts[0] + '.' + parts[1].substring(0, 2)
        }
      }
      let { index, item: datasetItem } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      let item = orderInfo.vdQuotationGoodsList[index]

      item.goods.priceInput = value
      item.goods.checkError = false

      let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
      number = NP.times(number, 100)

      const strategy = getProductStrategy(item)
      if (strategy) {
        if (orderInfo.orderType == 2 || orderInfo.orderType == 5) {
          const currentBasePrice = strategy.getBasePrice()
          if (Number(currentBasePrice) !== Number(number)) {
            const data = strategy.getData()
            if (data.discountType == 1 || data.discountType == 2) {
              strategy.setDiscount(data.discountType, '')
            }
          }
        }
        strategy.setBasePrice(number)
        // Sync price for display
        item.goods.price = number

      }
      this.setGoodsListTotal(orderInfo)
    },
    priceBlur(e) {
      let { index, childind } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      let item = orderInfo.vdQuotationGoodsList[index]
	  console.log( index, childind,item,getProductStrategy(item))
      if (childind !== undefined) {
        const subItem = item.packageGoods.goodsList[childind]
        subItem.priceInput = null
      } else if (item.multipleSpecificationsGoods) {
        item.multipleSpecificationsGoods.goods.priceInput = null
      } else if (item.goods) {
        item.goods.priceInput = null
      }

      const strategy = getProductStrategy(item)
      if (strategy) {
        if (childind !== undefined && strategy.getSubItemData) {
          const subItem = strategy.getSubItemData(childind)
          const currentPrice =
            subItem.basePrice !== undefined
              ? subItem.basePrice
              : subItem.sellPrice !== undefined
                ? subItem.sellPrice
                : subItem.price
          if (!currentPrice && currentPrice !== 0 && subItem.validMinSellPrice === 'Y') {
            strategy.updateSubItemPrice(childind, subItem.minSellPrice)
          }
        } else {
          const currentPrice = strategy.getPrice()
          const data = strategy.getData()
          if (!currentPrice && currentPrice !== 0 && data.validMinSellPrice === 'Y') {
            const minPrice = strategy.getMinPrice()
            strategy.setPrice(minPrice)
          }
        }
        const validation = strategy.performValidation()
		console.log(validation,'performValidation')
        if (!validation.valid) {
          wx.$util.showToast(validation.message)
        }
      }

      this.setGoodsListTotal(orderInfo)
    },
    //多规格单价修改
    changeSpecific(e) {
      let { value } = e.detail
      if (value.length > 1 && value.startsWith('0') && value[1] !== '.') {
        value = value.replace(/^0+/, '')
        if (value === '') {
          value = '0'
        } else if (value.startsWith('.')) {
          value = '0' + value
        }
      }
      // 限制最多小数点后2位
      if (value.includes('.')) {
        const parts = value.split('.')
        if (parts[1] && parts[1].length > 2) {
          value = parts[0] + '.' + parts[1].substring(0, 2)
        }
      }
      let { index, item: datasetItem } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      let item = orderInfo.vdQuotationGoodsList[index]

      item.multipleSpecificationsGoods.goods.priceInput = value
      item.multipleSpecificationsGoods.goods.checkError = false

      let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
      number = NP.times(number, 100)

      const strategy = getProductStrategy(item)
      if (strategy) {
        if (orderInfo.orderType == 2 || orderInfo.orderType == 5) {
          const currentBasePrice = strategy.getBasePrice()
          if (Number(currentBasePrice) !== Number(number)) {
            const data = strategy.getData()
            if (data.discountType == 1 || data.discountType == 2) {
              strategy.setDiscount(data.discountType, '')
            }
          }
        }
        strategy.setBasePrice(number)
        // Sync price for display
        item.multipleSpecificationsGoods.goods.price = strategy.getPrice()

      }
      this.setGoodsListTotal(orderInfo)
    },
    changePricePackage(e) {
      let { value } = e.detail
      if (value.length > 1 && value.startsWith('0') && value[1] !== '.') {
        value = value.replace(/^0+/, '')
        if (value === '') {
          value = '0'
        } else if (value.startsWith('.')) {
          value = '0' + value
        }
      }
      // 限制最多小数点后2位
      if (value.includes('.')) {
        const parts = value.split('.')
        if (parts[1] && parts[1].length > 2) {
          value = parts[0] + '.' + parts[1].substring(0, 2)
        }
      }
      let { index, childind } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      let item = orderInfo.vdQuotationGoodsList[index]

      const subItem = item.packageGoods.goodsList[childind]
      subItem.priceInput = value
      subItem.checkError = false

      let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)
      number = NP.times(number, 100)

      const strategy = getProductStrategy(item)
      if (strategy) {
        if (orderInfo.orderType == 2 || orderInfo.orderType == 5) {
          const currentBasePrice = strategy.getSubItemBasePrice(childind)
          if (Number(currentBasePrice) !== Number(number)) {
            const subData = strategy.getSubItemData(childind)
            if (subData.discountType == 1 || subData.discountType == 2) {
              strategy.updateSubItemDiscount(childind, subData.discountType, '')
            }
          }
        }
        strategy.updateSubItemPrice(childind, number)

        // Sync price for display
        // const subItem = item.packageGoods.goodsList[childind]
        subItem.price = subItem.basePrice

      }
      this.setGoodsListTotal(orderInfo)
      return value
    },
    delGoodsList(e) {
      let { index } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      // console.log(orderInfo,'orderInfo');
      orderInfo.vdQuotationGoodsList.splice(index, 1)
      this.setGoodsListTotal(orderInfo)
    },
    /**
     * 重算商品合计并将同一交互产生的订单字段一次性上报父页面。
     * @param {object} sourceOrderInfo 待计算的订单快照
     * @param {object} [extraPatch] 与商品合计原子提交的订单字段
     * @returns {void}
     */
    setGoodsListTotal(sourceOrderInfo, extraPatch = {}) {
      const orderInfo =
        sourceOrderInfo && typeof sourceOrderInfo === 'object'
          ? sourceOrderInfo
          : this.getEditableOrderInfo()
      let total = 0
      orderInfo.vdQuotationGoodsList.forEach(item => {
        const strategy = getProductStrategy(item)
        if (strategy) {
          strategy.recalculatePrices()
          total = NP.plus(total, strategy.calculateSubtotal())

          // Sync package price if it's a package
          if (item.packageGoods) {
            item.price = item.packageGoods.price
          }
        }
      })
      this.emitOrderPatch({
        ...extraPatch,
        total: wx.$util.decimal(NP.divide(total, 100), 2),
        vdQuotationGoodsList: orderInfo.vdQuotationGoodsList
      })
    },
    /**
     * 应用商品弹层确认结果并关闭商品弹层。
     * @param {{detail:Array<object>}} e 商品组件确认事件
     * @returns {void}
     */
    chooseGoods(e) {
      const orderInfo = this.getEditableOrderInfo()
      orderInfo.vdQuotationGoodsList = Array.isArray(e.detail) ? e.detail : []
      this.setGoodsListTotal(orderInfo)
      this.setData({ goodsBox: false })
    },
    /**
     * 关闭商品弹层;取消选择不改变父页面商品状态。
     * @returns {void}
     */
    onGoodsCancel() {
      this.setData({ goodsBox: false })
    },
    /**
     * 把商品组件的目录刷新请求继续交给页面处理。
     * @param {{detail?:{force?:boolean}}} e 商品组件事件
     * @returns {void}
     */
    onGoodsRefreshRequested(e) {
      this.triggerEvent('catalogRefreshRequested', {
        force: e.detail?.force !== false
      })
    },
    /**
     * 保存进入多规格弹层前的已选商品,并由本组件打开多规格选择。
     * @param {{detail?:{goodsList?:Array<object>,goodsData?:object}}} e 商品组件事件
     * @returns {void}
     */
    onGoodsSkuRequested(e) {
      const detail = e.detail || {}
      const orderInfo = this.getEditableOrderInfo()
      orderInfo.vdQuotationGoodsList = Array.isArray(detail.goodsList)
        ? detail.goodsList
        : []
      this.setGoodsListTotal(orderInfo)
      this.setData({
        goodsBox: false,
        skuGoodsData: detail.goodsData || {},
        skuGoodsBox: true
      })
    },
    /**
     * 应用多规格商品确认结果并关闭弹层。
     * @param {{detail:Array<object>}} e 多规格商品确认事件
     * @returns {void}
     */
    onSkuGoodsConfirm(e) {
      const orderInfo = this.getEditableOrderInfo()
      orderInfo.vdQuotationGoodsList = Array.isArray(e.detail) ? e.detail : []
      this.setGoodsListTotal(orderInfo)
      this.setData({ skuGoodsBox: false })
    },
    /**
     * 关闭多规格商品弹层。
     * @returns {void}
     */
    onSkuGoodsCancel() {
      this.setData({ skuGoodsBox: false })
    },
    /**
     * 将共享多规格弹层的显示状态上报页面,用于锁定底层滚动。
     * @param {{detail?:{show?:boolean}}} e 弹层显示事件
     * @returns {void}
     */
    onSkuVisibilityChange(e) {
      this.triggerEvent('popupVisibilityChange', {
        show: !!e.detail?.show
      })
    },
    showPopup(e) {
      let { quotationGoodsList } = this.data
      let { showName } = e.currentTarget.dataset
      if (showName == 'goodsBox' && quotationGoodsList.length < 1) {
        // if (!data.length)
        return wx.showModal({
          title: '温馨提示',
          content: '商品已下架或计算规则未配置,请联系客服处理。',
          showCancel: false,
          confirmText: '确定',
          confirmColor: '#347BFF'
        })
        // return wx.$util.showToast( '门店无配置商品')
      }
      console.log(showName, 'showName')
      if (showName == 'goodsBox') {
        this.setData({
          [showName]: false
        })
      }
      this.setData({
        [showName]: true
      })
    },
    onChangeInsurance(e) {
      const { detail } = e
      const { id: goodsId } = e.currentTarget.dataset
      if (!detail) return false
      return this.triggerEvent('quoteRequested', { goodsId: goodsId })
    },
    //--------自定义方法----------
    // 选择年份的区域,弹出弹窗框
    chooseYear() {
      console.log('选择年份')
      this.setData({
        showYear: true
      })
    },

    // 弹出框确认事件
    onConfirm(e) {
      const { value } = e.detail
      this.emitOrderPatch({
        vehiclesAndVessels: {
          ...(this.properties.orderInfo?.vehiclesAndVessels || {}),
          compensation: value + '年'
        }
      })
      this.setData({
        showYear: false
      })
      this.cancelInsuranceCheck()
    },
    cancelInsuranceCheck() {
      this.emitOrderPatch({
        quotedPriceUpdate: '',
        goodsId: '',
        goodsName: '',
        valueAddedVehicleLoss: {
          appreciation: '',
          goodsName: '',
          type: 3
        }
      })
      this.setData({
        insuranceCheck: false
      })
    },
    // 取消选择年份的弹框
    onCancel() {
      let that = this
      that.setData({
        showYear: false
      })
    },
    // 对选择时间进行单独的处理
    makeYear() {
      // console.log('makeYear')
      let year = []
      let currentDate = new Date()
      console.log(currentDate.getFullYear())
      for (
        let j = currentDate.getFullYear() - 25;
        j < currentDate.getFullYear();
        j++
      ) {
        year.push(j)
      }
      for (
        let i = currentDate.getFullYear();
        i <= currentDate.getFullYear() + 25;
        i++
      ) {
        year.push(i)
      }
      // console.log(year, 'year')
      this.setData({
        columns: year
      })
    },
    handlePopupShow(e) {
      // console.log(e)
      let { disable } = this.data
      if (disable) return false //修改权益价时,不可修改
      // let { attrtype, attrname, typename } = e.target.dataset
      let { attrtype, attrname, typename } = e.currentTarget.dataset
      console.log(attrtype, attrname, typename, 'attrType, attrName')
      let popValue = this.properties.orderInfo?.[attrtype]?.[attrname] || ''
      this.setData({
        popupShow: true,
        // popValue
        popObj: {
          attrtype,
          attrname,
          popValue,
          typename
        }
      })
    },
    handlePopInputShow(e) {
      // console.log(e)
      let { disable } = this.data
      if (disable) return false //修改权益价时,不可修改

      let { handletype, index } = e.target.dataset
      console.log(handletype, index, 'type, index')
      let popValue = ''
      if (handletype == 'edit') {
        popValue =
          this.properties.orderInfo?.otherInsuranceList?.[index] || ''
      }
      console.log(popValue, 'popValue')
      this.setData({
        popupInputShow: true,
        popInputObj: {
          handletype,
          index,
          ...popValue
        }
      })
    },
    btnTap(e) {
      // console.log(e)
      let { name } = e.detail
      // debugger
      // let { attrtype, attrname, typename } = this.data.tableObj
      let { showError, insuranceCheck, successDateTime } = this.data
      const orderInfo = this.getEditableOrderInfo()
      const orderPatch = {
        vdQuotationGoodsList: orderInfo.vdQuotationGoodsList
      }
      if (successDateTime && !orderInfo.resetOrder) {
        const _temp = new Date(successDateTime).format('yyyy-MM-dd hh:mm:ss')
        orderInfo.pay2Time = _temp
        orderPatch.pay2Time = _temp
      }
      if (showError) return wx.$util.showToast('权益价不能小于最低权益价')
      // 校验商品最低价
      let goodsError = []
      orderInfo?.vdQuotationGoodsList?.forEach(val => {
        if (val.goods) {
          val.goods.checkError = false
          if (
            val.goods?.price < val.goods.minSellPrice &&
            val.goods?.validMinSellPrice == 'Y'
          ) {
            val.goods.checkError = true
            goodsError.push(val.goods)
          }
        }
        if (val.packageGoods) {
          val.packageGoods?.goodsList.forEach(subV => {
            subV.checkError = false
            if (
              subV?.price < subV?.minSellPrice &&
              subV?.validMinSellPrice == 'Y'
            ) {
              subV.checkError = true
              goodsError.push(val.goods)
            }
          })
        }
        if (val.multipleSpecificationsGoods) {
          val.multipleSpecificationsGoods.goods.checkError = false
          if (
            val.multipleSpecificationsGoods.goods?.price <
              val.multipleSpecificationsGoods.goods.minSellPrice &&
            val.multipleSpecificationsGoods.goods?.validMinSellPrice == 'Y'
          ) {
            val.multipleSpecificationsGoods.goods.checkError = true
            goodsError.push(val.multipleSpecificationsGoods.goods)
          }
        }
      })
      this.emitOrderPatch(orderPatch)
      if (goodsError?.length)
        return wx.$util.showToast('价格不可低于商品最低价')
      if (name == 'confirm') {
        // 不是修改报价时,需要勾选保险
        // if (!insuranceCheck && !orderInfo.modifyEquityQuotation) return wx.$util.showToast('请先勾选保险')
        this.triggerEvent('confirm')
      } else {
        this.triggerEvent('editSave')
      }
    },
    // 切换收款方式
    changePayee(e) {
      let { payee } = e.currentTarget.dataset
      const orderInfo = this.getEditableOrderInfo()
      if (orderInfo.resetOrder || orderInfo.outTradeArr) return
      if (payee == 1) {
        this.setData({
          payTypeList: merchantPayTypeList
        })
      } else {
        this.setData({
          payTypeList: djPayTypeList
        })
      }
      this.emitOrderPatch({
        payee: payee,
        payType: payee == 1 ? 2 : 1
      })
    },
    // 切换支付方式
    changePayType(e) {
      console.log(e)
      let { paytype } = e.currentTarget.dataset
      this.emitOrderPatch({
        payType: paytype
      })
      // this.setData({
      //   ['textNameObj.confirmName']: paytype == 1?'下一步·去支付(1/2)':'下一步·上传凭证'
      // })
    },
    handleInput(e) {
      let value = e.detail
      console.log(e)
      let { attrname, attrtype, type } = e.currentTarget.dataset

      value = type == 'number' ? wx.$util.numberFixedDigit(value) : value
      if (type == 'number') {
        const inputAmount = yuanToCentInteger(value)
        const compared = inputAmount.ok
          ? compareCentAmounts(inputAmount.value, 200000000)
          : { ok: false }
        value = compared.ok && compared.value > 0 ? 2000000 : value
      }
      console.log(attrtype)
      // onChangeInsurance
      // onChangeInsurance
      if (attrname == 'quotedPriceUpdate') {
        const orderInfo = this.properties.orderInfo || {}
        let showError = orderInfo.minEquityPrice <= value ? false : true
        this.setData({
          showError
        })
        if (showError) return false
      }
      // ['orderInfo' + '.' + attrType]
      // console.log(['orderInfo' + '.' + attrType], '2')
      const patch = attrtype
        ? {
            [attrtype]: {
              ...(this.properties.orderInfo?.[attrtype] || {}),
              [attrname]: value
            }
          }
        : { [attrname]: value }
      if (attrname != 'quotedPriceUpdate') {
        Object.assign(patch, {
          quotedPriceUpdate: '',
          goodsId: '',
          goodsName: '',
          valueAddedVehicleLoss: {
            appreciation: '',
            goodsName: '',
            type: 3
          }
        })
        this.setData({
          insuranceCheck: false
        })
      }
      this.emitOrderPatch(patch)
    },
    onChanteSuccessDate(e) {
      this.setData({
        successDateTime: e.detail,
        showDateSelect: false
      })
    },
    toSelectDate() {
      this.setData({
        showDateSelect: true
      })
    },
    closeDateModal() {
      this.setData({
        showDateSelect: false
      })
    }
    // onChange (e){
    //   console.log(e);

    //   let value = e.detail

    // }
    // numberFixedDigit (e) { // 固定两位小数
    //   e.target.value = (e.target.value.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
    //   this.$nextTick(() => {
    //     this.number= e.target.value
    //   })
    // },
  }
})