SecondStep.js 25.1 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
// packageEquity/pages/carEquity/components/SecondStep/SecondStep.js
import data from '../constant/stepData'
// import fn from '../constant/ruleFn'
import { priceCounter } from '~/packageEquity/api'
import {
  getProductStrategy,
  DISCOUNT_TYPE,
  ORDER_TYPE
} from '../../createOrderCarQuotationSimple/productStrategy'
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
    }
  },
  observers: {
    '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
      }
    ],
    orderTypeName: '正常订单',
    orderTypeBox: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tipsEvent() {
      this.triggerEvent('showTips')
    },
    // 打开订单类型选择
    openOrderType() {
      this.setData({
        orderTypeBox: true
      })
    },
    onCloseOrderType() {
      this.setData({
        orderTypeBox: false
      })
    },
    onConfirmOrderType(e) {
      const { value } = e.detail
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let { vdQuotationGoodsList } = orderInfo

      // 如果订单类型改变,重置所有商品的折扣信息
      if (orderInfo.orderType !== value.value) {
        vdQuotationGoodsList.forEach(item => {
          const strategy = getProductStrategy(item)
          if (strategy) {
            // 重置为无折扣
            strategy.resetDiscount()
          }
        })
        thisPage.setData({
          ['orderInfo.vdQuotationGoodsList']: vdQuotationGoodsList
        })
        this.setGoodsListTotal()
      }

      thisPage.setData({
        'orderInfo.orderType': value.value
      })
      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
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let { vdQuotationGoodsList } = orderInfo
      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
        }
        thisPage.setData({
          ['orderInfo.vdQuotationGoodsList']: vdQuotationGoodsList
        })
        this.setGoodsListTotal()
      }
    },
    toggleGift(e) {
      const { index, gindex } = e.currentTarget.dataset
      const value = e.detail.value // "1" or "0"
      const discountType = value === '1' ? 4 : 3 // 4 is Gift, 3 is No Discount

      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let { vdQuotationGoodsList } = orderInfo

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

      if (strategy) {
        if (gindex !== undefined && strategy.updateSubItemDiscount) {
          strategy.updateSubItemDiscount(gindex, discountType, '')
        } else {
          strategy.setDiscount(discountType, '')
        }
        thisPage.setData({
          ['orderInfo.vdQuotationGoodsList']: vdQuotationGoodsList
        })
        this.setGoodsListTotal()
      }
    },
    inputDiscountValue(e) {
      const { index, gindex } = e.currentTarget.dataset
      let { value } = e.detail
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let { vdQuotationGoodsList } = orderInfo

      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, '')

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

          if (currentType == 1) {
            // 折扣比例
            // 2:是折扣比例的话,最多只能输入1位整数和两个小数
            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 > 2) {
                decimalPart = decimalPart.slice(0, 2)
              }
              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
            }

            if (parseFloat(value) > parseFloat(basePrice)) {
              value = basePrice.toString()
            }
          }
        }

        if (gindex !== undefined && strategy.updateSubItemDiscount) {
          strategy.updateSubItemDiscount(gindex, currentType, value)
        } else {
          strategy.setDiscount(currentType, value)
        }
        thisPage.setData({
          ['orderInfo.vdQuotationGoodsList']: vdQuotationGoodsList
        })
        this.setGoodsListTotal()
      }
    },
    changePrice(e) {
      let { value } = e.detail
      let { index, item: datasetItem } = e.currentTarget.dataset
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let item = orderInfo.vdQuotationGoodsList[index]

      let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)

      const strategy = getProductStrategy(item)
      if (strategy) {
        strategy.setBasePrice(number)
        // Sync price for display
        item.goods.price = number

        thisPage.setData({
          [`orderInfo.vdQuotationGoodsList[${index}]`]: item
        })
      }
      this.setGoodsListTotal()
    },
    //多规格单价修改
    changeSpecific(e) {
      let { value } = e.detail
      let { index, item: datasetItem } = e.currentTarget.dataset
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let item = orderInfo.vdQuotationGoodsList[index]

      let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)

      const strategy = getProductStrategy(item)
      if (strategy) {
        strategy.setBasePrice(number)
        // Sync price for display
        item.multipleSpecificationsGoods.goods.price = strategy.getPrice()

        thisPage.setData({
          [`orderInfo.vdQuotationGoodsList[${index}]`]: item
        })
      }
      this.setGoodsListTotal()
    },
    changePricePackage(e) {
      let { value } = e.detail
      let { index, childind } = e.currentTarget.dataset
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let item = orderInfo.vdQuotationGoodsList[index]

      let number = wx.$util.removeLeadingZerosAndEnsureNonNegative(value)

      const strategy = getProductStrategy(item)
      if (strategy) {
        strategy.updateSubItemPrice(childind, number)

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

        thisPage.setData({
          [`orderInfo.vdQuotationGoodsList[${index}]`]: item
        })
      }
      this.setGoodsListTotal()
    },
    delGoodsList(e) {
      let { index } = e.currentTarget.dataset
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      // console.log(orderInfo,'orderInfo');
      orderInfo.vdQuotationGoodsList.splice(index, 1)
      thisPage.setData({
        ['orderInfo.vdQuotationGoodsList']: orderInfo.vdQuotationGoodsList
        // ['orderInfo.total']:wx.$util.decimal(total, 2)
      })
      this.setGoodsListTotal()
    },
    setGoodsListTotal() {
      let thisPage = wx.$router.getPageInstance()
      let { orderInfo } = thisPage.data
      let total = 0
      orderInfo.vdQuotationGoodsList.forEach(item => {
        const strategy = getProductStrategy(item)
        if (strategy) {
          strategy.performValidation()
          total = NP.plus(total, strategy.calculateSubtotal())

          // Sync package price if it's a package
          if (item.packageGoods) {
            item.price = item.packageGoods.price
          }
        }
      })
      thisPage.setData({
        ['orderInfo.total']: wx.$util.decimal(total, 2),
        ['orderInfo.vdQuotationGoodsList']: orderInfo.vdQuotationGoodsList
      })
    },
    chooseGoods(e) {
      console.log(e)
      // let {}
      this.setData({
        chooseGoods: e.detail
      })
      // chooseGoods
    },
    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) {
      console.log(e)
      let { detail } = e
      let { id } = e.currentTarget.dataset
      if (!detail) return false
      let thisPage = wx.$router.getPageInstance()
      // console.log(detail, 'detail')
      let { quotationGoodsList } = this.data
      let goodsItem = quotationGoodsList.find(item => item.id == id)

      let params = thisPage.getInsurance()
      let owner = thisPage.getOwnerInfo()

      //  const owner = wx.$util.deepClone(thisPage.data.owner)
      owner.salesType = owner.salesType == '售后' ? 1 : 0
      params.owner = owner
      params.goodsId = goodsItem.id
      params.goodsName = goodsItem.goodsName
      //  params.owner = owner
      //  params.owner.price = this.multipliedByHundred(orderInfo.owner?.price) || ''
      // console.log(thisPage)
      if (params.owner?.buyCarTime) {
        delete params.owner.buyCarTime
      }
      // quotedPriceUpdate
      delete params?.quotedPriceUpdate
      // if (params?.quotedPriceUpdate) {

      // }
      wx.$util.showLoading()
      // console.log(params, 'params')
      priceCounter(params)
        .then(result => {
          wx.hideLoading()
          console.log('result', result)
          let { data, code, message } = result

          if (code) {
            let thisPage = wx.$router.getPageInstance()
            // thisPage.setData({
            //   // ['orderInfo.quotedPriceUpdate']: data.quotedPriceUpdate

            // })
            // 如果是补录订单,还要做一个订单最低价格对比
            let { orderInfo, totalFee } = thisPage.data
            let minEquityPrice = wx.$util.divideByHundred(data.minEquityPrice)
            // debugger
            if (orderInfo.outTradeNo && data.minEquityPrice > totalFee) {
              wx.$util.showToast('选择商品的最低价格不能大于补录价格')
              return
            }
            thisPage.setData({
              ['orderInfo.quotedPriceUpdate']: wx.$util.divideByHundred(
                orderInfo?.outTradeNo ? totalFee : data.quotedPriceUpdate
              ),
              ['orderInfo.minEquityPrice']: minEquityPrice,
              ['orderInfo.goodsId']: goodsItem.id,
              ['orderInfo.goodsName']: goodsItem.goodsName
            })
            // return
            this.setData({
              // insuranceCheck: true,
              showError: false,
              testQuotedPriceUpdate: wx.$util.divideByHundred(
                data.quotedPriceUpdate
              )
            })
          } else {
            wx.$util.showToast({
              title: message || '获取报价失败',
              icon: 'error'
            })
          }
        })
        .catch(err => {})
    },
    //--------自定义方法----------
    // 选择年份的区域,弹出弹窗框
    chooseYear() {
      console.log('选择年份')
      this.setData({
        showYear: true
      })
    },

    // 弹出框确认事件
    onConfirm(e) {
      // console.log(e, 1111)
      let { value } = e.detail
      let thisPage = wx.$router.getPageInstance()
      console.log(value, 'value')
      thisPage.setData({
        // ['orderInfo' + '.' + attrtype + '.' + attrname]: value
        ['orderInfo.vehiclesAndVessels.compensation']: value + '年'
      })
      this.setData({
        showYear: false
      })
      this.cancelInsuranceCheck()
    },
    cancelInsuranceCheck() {
      let thisPage = wx.$router.getPageInstance()

      thisPage.setData({
        ['orderInfo.quotedPriceUpdate']: '',
        ['orderInfo.goodsId']: '',
        ['orderInfo.goodsName']: '',
        ['orderInfo.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 thisPage = wx.$router.getPageInstance()
      let popValue = thisPage.data.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 thisPage = wx.$router.getPageInstance()
      let popValue = ''
      if (handletype == 'edit') {
        popValue =
          thisPage.data.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, orderInfo, successDateTime } = this.data
      if (successDateTime && !orderInfo.resetOrder) {
        let thisPage = wx.$router.getPageInstance()
        const _temp = new Date(successDateTime).format('yyyy-MM-dd hh:mm:ss')
        thisPage.setData({
          ['orderInfo.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.setData({
        orderInfo
      })
      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
      let { orderInfo } = this.data
      if (orderInfo.resetOrder || orderInfo.outTradeArr) return
      let thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        ['orderInfo.payee']: payee
      })
      if (payee == 1) {
        this.setData({
          payTypeList: merchantPayTypeList
        })
        thisPage.setData({
          ['orderInfo.payType']: 2
        })
      } else {
        this.setData({
          payTypeList: djPayTypeList
        })
        thisPage.setData({
          ['orderInfo.payType']: 1
        })
      }
    },
    // 切换支付方式
    changePayType(e) {
      console.log(e)
      let { paytype } = e.currentTarget.dataset
      let thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        // ['orderInfo.quotedPriceUpdate']: '',
        ['orderInfo.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') {
        value = parseFloat(value) > 2000000 ? 2000000 : value
      }
      let thisPage = wx.$router.getPageInstance()
      console.log(attrtype)
      // onChangeInsurance
      // onChangeInsurance
      if (attrname == 'quotedPriceUpdate') {
        let { orderInfo } = this.data
        let showError = orderInfo.minEquityPrice <= value ? false : true
        this.setData({
          showError
        })
        if (showError) return false
      }
      // ['orderInfo' + '.' + attrType]
      // console.log(['orderInfo' + '.' + attrType], '2')
      thisPage.setData({
        ['orderInfo' + '.' + attrtype + '.' + attrname]: value
      })
      attrname != 'quotedPriceUpdate' && this.cancelInsuranceCheck()
      // console.log(thisPage.data)
    },
    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
    //   })
    // },
  }
})