orderDetail.js 30.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 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 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
// tabWorkOrder/pages/orderDetail/orderDetail.js
import api from '../../api.js'
import order_mixins from '../order_mixins.js'
import {
  getPositionList,
  getServiceFilmRollSetting,
  setConfigInfo
} from '~/store/index'
import {
  checkDailyReport,
  checkStudyTask,
  checkOrderLockGate
} from '~/store/ModalToQueueControl'
import commonApi from '~/api/api'
import { normalizeMarketingFlagOnItem } from '~/utils/marketingFlag'
import {
  formatOrderGoodsUnitPrice,
  formatOrderMoney,
  normalizeOrderMoney,
  resolveOrderGoodsUnitPrice,
  resolveOrderPackageFinalPrice,
  sumOrderMoney
} from '../../services/orderPricePresentation.helpers.js'
import {
  buildBoutiqueCustomerDailyDisplay,
  resolveBoutiqueDetailCustomerPhone
} from '../createOrder/services/customerDailyFields.helpers.js'
import {
  LOW_PRICE_ORDER_EDIT_MESSAGE,
  isLowPriceOrder
} from '~/utils/workOrderLowPrice.helpers.js'
const IMG_URL =
  'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
	showInventory:false,
	inventoryData: {
		upgradeGoodsCommodityCode: '',
		upgradeGoodsCustomCode: '',
		specification: '',
		stock: ''
	  },
    IMG_URL,
    ...order_mixins.data,
    selectType: 1,
    selectTypeOrder: 1,
    allNoConstruction: true,
    userPermissions: [], // 权限数组
    showTips: true,
    isYqdSuper: app.globalData.isYqdSuper,
    isStaff: app.globalData.isStaff,
    isShowPhone: app.globalData.YQorderSetting?.yqPhoneConfig,
    customerService: '',
    defaultCustomerService:
      'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/kf.png',
    failCustomerService: `${IMG_URL}components/images/kfrefresh.png`,
    warrantyCardVisible: true,
    signatureSwitch: false, //不需要走签名逻辑 没有开启签名功能或则是战败订单
    selectFilmNumberIndex: 0,
    filmRollNoList: [],
    isUseFilmRoll: false,
    filmRollNoPopup: false,
    filmSelectedItem: '',
    tipsProps: {
      tipsText: '技师施工完毕后,点击完成施工按钮结束工单。',
      showTips: true,
      type: 1
    },
    baseConfigData: {},
    isMake: true,
    packageGoodsList: [],
    // 发票按钮
    invoiceName: '申请开票',
    invoiveVisible: false,
    showModal: false,
    sublistVisible: false,
    constructionVisible: false,
    customerTagLabels: []
  },
    // 监听弹窗关闭事件
	onInventoryClose() {
		this.setData({
			showInventory: false
		  });
	  },
	    // 打开弹窗
  openInventoryPopup(e) {
	console.log(e.target.dataset)
	let {inventory:{
	  upgradeGoodsCommodityCode,
	  upgradeGoodsCustomCode,
	  specification,
	  stock
	}} = e.target.dataset
	const inventoryData ={
	  upgradeGoodsCommodityCode,
	  upgradeGoodsCustomCode,
	  specification,
	  stock
	}
  this.setData({
	showInventory: true,
	inventoryData
  });
},
//   打开物料弹窗
openInventory(e){
	const inventoryData=e.detail
	this.setData({
		showInventory: true,
		inventoryData
	  });
},
  sublistCancel() {
    this.setData(
      {
        sublistVisible: false
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'unset'
          }
        })
      }
    )
  },
  selectType(e) {
    let { type } = e.currentTarget.dataset
    console.log(e, e.currentTarget.dataset, type)
    this.setData({
      selectType: type
    })
  },
  showRefundAlert() {
    wx.showModal({
      title: '提示',
      content:
        '订单已发起退款,禁止标记为错误工单!如需标记错误请联系总部运营。',
      showCancel: false,
      confirmText: '好的'
    })
  },
  constructionCancel() {
    this.setData(
      {
        constructionVisible: false
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'unset'
          }
        })
      }
    )
    // this.setData({
    //   constructionVisible: false
    // })
  },
  // 跳转新增订单页面
  goToCreateOrder() {
    let { orderInfo } = this.data
    // 跳转新增订单页面 并带特定参数
    console.log(orderInfo)
    orderInfo.associateOrderCode = orderInfo.orderCode
    delete orderInfo.orderCode
    if (orderInfo.technicianList) {
      delete orderInfo.technicianList
    }
    orderInfo.selectPayType = 2
    let urlName = 'createOrder'
    wx.$router.redirectTo(urlName, orderInfo)
  },
  // 确定是否要显示
  async targetError() {
    // 校验是否填写昨日日报
    let staffCheck = await checkDailyReport()
    if (staffCheck) return false
    // 校验学习中心开单限制
    let staffStudyTask = await checkStudyTask()
    if (staffStudyTask) return false
    // 校验异常订单
    let lockCheck = await checkOrderLockGate()
    if (lockCheck) return false
    // 校验订单是否可标记错误工单(退款流程中订单状态无法变更)
    let { orderInfo } = this.data
    let refundStep = await commonApi.getOrderRefundStep({
      orderCode: orderInfo.orderCode
    })
    // console.log(refundStep, 'refundStep')
    if (refundStep?.data == 'Y') return this.showRefundAlert()

    // 有进行的施工单做提示
    let res = await api.statByStatus({
      merchantId: orderInfo.merchantId,
      orderCode: orderInfo.orderCode
    })
    console.log(res, 'status')
    let { data } = res
    if (data?.incompleteTotal > 0) {
      wx.$modal(
        this,
        {
          show: true,
          title: '提醒',
          tabTitleShow: false,
          success: res => {
            console.log(res, 'res')
            this.goToCreateOrder()
          },
          error: () => {}
        },
        '#modal5'
      )
    } else {
      this.goToCreateOrder()
    }
  },
  targetOperate() {
    let { showTip } = this.data
    this.setData({
      showTip: !showTip
    })
  },
  jumpUserPortrait() {
    wx.$router.go('tabDate.userPortrait', this.data.orderInfo)
  },
  showModal(e) {
    let { btnname } = e.currentTarget.dataset
    console.log(e, btnname)
    this.setData(
      {
        [btnname]: true
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'hidden'
          }
        })
      }
    )
  },
  navOrderSignature() {
    let { orderInfo } = this.data
    wx.$router.redirectTo('orderSignature', orderInfo)
  },
  /**
   * 进入客户信息修改页;低价单详情仅展示客户信息,不提供修改入口。
   *
   * @returns {void|false} 低价单拦截时返回 false
   */
  jumpUpdate() {
    let { orderInfo } = this.data
    if (isLowPriceOrder(orderInfo)) {
      wx.$util.showToast(LOW_PRICE_ORDER_EDIT_MESSAGE)
      return false
    }
    wx.$router.go('updateOrderInfo', orderInfo)
  },
  confirmConstruction() {
    let { orderCode, orderInfo, isUseFilmRoll } = this.data
    wx.$util.showLoading('加载中...')
    // 使用膜卷号
    if (isUseFilmRoll) {
      let flag = false
      for (var i = 0; i < orderInfo?.subOrderList?.length; i++) {
        let val = orderInfo?.subOrderList[i]
        if (val?.filmNumberData?.length) {
          if (!val.filmRollNo) return wx.$util.showToast(`请配置膜卷号`)
          flag = true
        }
      }
      if (flag) {
        let arr = []
        orderInfo?.subOrderList?.forEach(val => {
          if (val?.filmNumberData?.length && val.filmRollNo)
            arr.push({
              subOrderCode: val.subOrderCode,
              filmRollNo: val.filmRollNo
            })
        })
        api
          .setfilmRollNo({
            subOrderList: arr
          })
          .then(res => {
            let { code, message } = res
            if (code == 0) {
              this.confirmEvent(orderInfo, orderCode)
            } else {
              wx.$util.showToast(message)
            }
          })
          .catch(err => {
            wx.$util.hideLoading()
          })
      } else {
        this.confirmEvent(orderInfo, orderCode)
      }
    } else {
      this.confirmEvent(orderInfo, orderCode)
    }
  },
  confirmEvent(orderInfo, orderCode) {
    let _this = this
    api
      .confirmConstruction({
        orderCode
      })
      .then(result => {
        wx.$util.hideLoading()
        // console.log(result)
        let { code, message, solution } = result
        if (code == 0) {
          wx.$util.refreshPageData()
          wx.$router.redirectTo('constructionOrderDetail', orderInfo)
        } else {
          if (solution) {
            wx.showModal({
              title: '温馨提示',
              content: message,
              showCancel: false,
              confirmText: '刷新',
              confirmColor: '#347BFF',
              success(res) {
                if (res.confirm) {
                  _this.getOrderDetail(orderCode)
                }
              }
            })
          } else {
            wx.$util.showToast(message)
          }
        }
      })
      .catch(err => {
        wx.$util.hideLoading()
        console.log(err)
      })
  },
  closeTips() {
    this.setData({
      showTips: false
    })
  },
  showAgain() {
    this.setData({
      showPopup: true
    })
  },
  setCopyData(e) {
    let { content } = e.currentTarget.dataset
    wx.$util.setCopyData(`${content}`)
  },
  makePhoneCall(e) {
    let { data } = e.currentTarget.dataset
    wx.makePhoneCall({
      phoneNumber: data
    })
  },
  // 获取人员权限
  getStaffPermissions() {
    let { userInfo } = this.data
    commonApi.staffPermissions({ phone: userInfo?.phone }).then(res => {
      console.log(res)
      let { code, data, message } = res
      if (code == 0) {
        this.setData({
          userPermissions: data || []
        })
      } else {
        wx.$util.showToast(message)
      }
    })
  },
  async onRoute(options) {
    let { orderCode } = this.data
    options.orderCode = options.orderCode || orderCode
    if (options.orderCode) {
      // 获取配置服务数据
      let baseConfigData = await setConfigInfo(app.globalData)
      this.setData({
        baseConfigData
      })
      this.getOrderDetail(options.orderCode)
      this.showFlag(options.orderCode)
      this.setData({
        orderCode: options.orderCode
      })
    }
    wx.setPageStyle({
      style: {
        overflow: 'unset'
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    if (options.orderCode) {
      // 获取配置服务数据
      let baseConfigData = await setConfigInfo(app.globalData)
      this.setData({
        baseConfigData
      })
      this.getOrderDetail(options.orderCode)
      this.showFlag(options.orderCode)
      this.setData({
        orderCode: options.orderCode
      })
    }
    let userInfo = wx.$util.getUserInfo()
    let o = wx.$util.getStorageSync('dj_boutique_user_info')

    this.checkPhoneShow(app.globalData.YQorderSetting?.yqPhoneConfig)

    this.setData({
      isYqdSuper: app.globalData.isYqdSuper,
      isStaff: app.globalData.isStaff,
      userInfo: o,
      isMake: !(
        wx.$hasPermission?.canSelectMultiStoreWithTechnician?.(userInfo)
      )
    })
    this.getStaffPermissions()
  },
  showFlag(orderCode) {
    const confirmFlagObj = {
      0: {
        showBtn: false
      },
      1: {
        showBtn: '确认订单是否施工',
        btnName: 'sublistVisible'
      },
      2: {
        showBtn: '查看施工单',
        btnName: 'constructionVisible'
      }
    }
    //confirmFlag 确认施工单按钮:0-隐藏,1-展示确认按钮,2-展示查询按钮
    // 用策略模式处理不同值会有不同展示和操作
    api
      .showFlag({
        orderCode
      })
      .then(res => {
        console.log(res)
        let { code, message, data } = res
        console.log('showFlag', res)
        if (code == 0) {
          this.setData({
            confirmFlagObj: confirmFlagObj[data.confirmFlag],
            updateFlag: data.updateFlag
          })
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  checkPhoneShow(config) {
    // 有就屏蔽手机号的显示
    if (config) {
      let { customerObj } = this.data
      delete customerObj[2]
      this.setData({
        customerObj
      })
    }
  },
  async getOrderDetail(orderCode) {
    let _this = this

    let { signatureSwitch, baseConfigData } = _this.data
    let allNoConstruction = true
    const positionTypeList = (await getPositionList()) || []
    wx.$util.showLoading('加载中...')

    api
      .getPackageGoodsDetail({
        orderCode
      })
      .then(async res => {
        let { code, message, data, isUseFilmRoll } = res
        let userInfo = wx.$util.getUserInfo()
        if (code == 0) {
          wx.$util.hideLoading()
          // 获取对应园区店配置
          await this.getServiceBaseInfo(data.merchantId)
          await this.getSignatureSwitch(data.merchantId)
          if (data.status == 4 || data.status == 6 || data.status == 12) {
            // 查询订单可展示按钮
            commonApi.getMoreBtnAPI({ orderCode: data.orderCode }).then(res => {
              let { code, data } = res
              if (code == 0) {
                this.setData({
                  showMoreBtn:
                    data.refundApplyButton == 'Y' ||
                    data.refundApplyDetailButton == 'Y'
                })
              }
            })
          }
          // 服务商是否使用膜卷号配置
          if (
            !wx.$hasPermission?.isSuper?.(userInfo) &&
            userInfo.userType == 2 &&
            data.status != 10 &&
            data.status != 9
          ) {
            isUseFilmRoll = await getServiceFilmRollSetting(
              data?.sellerMerchantId
            )
            this.setData({
              isUseFilmRoll
            })
          }
          let couponName = data.customerCoupon
            ? data.customerCoupon.couponName
            : ''
          let total_price = 0
          let warrantyCardList = []
          for (var i = 0; i < data?.subOrderList?.length; i++) {
            let e = data?.subOrderList[i]
            // 判断是否全为无需施工
            if (e.constructionStatus != 3) {
              allNoConstruction = false
              console.log(e.constructionStatus, 'e.constructionStatus')
            }
            e.finalPrice = normalizeOrderMoney(e.finalPrice) ?? e.finalPrice
            total_price = sumOrderMoney([total_price, e.finalPrice])
            e.originalPrice = e.price
            const hasTotalPrice =
              e.totalPrice !== null &&
              e.totalPrice !== undefined &&
              e.totalPrice !== ''
            e.price = formatOrderGoodsUnitPrice(e)
            if (hasTotalPrice) e.sellPrice = e.price
            e.displayPrice = e.price
            e.positionStr =
              positionTypeList.filter(
                v => v.positionValue == e.upgradeGoodsPosition
              )[0]?.positionName || ''
            if (
              (e.upgradeWarrantyPeriod || e.upgradeWarrantyPeriod > 0) &&
              data.selectPayType != 0
            ) {
              warrantyCardList.push({
                warrantyPeriod: e.upgradeWarrantyPeriod,
                goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName,
                cardCode: e.cardCode
              })
            }
            // 膜类商品 并且服务商开通了使用膜卷号配置 不走签名流程
            if (
              baseConfigData?.membraneTypeList?.includes(e?.upgradeGoodsType) &&
              isUseFilmRoll &&
              !signatureSwitch
            ) {
              let result = await api.getfilmRollNoByGoods({
                upgradeGoodsId: e.upgradeGoodsId,
                yqMerchantId: data?.sellerMerchantId,
                merchantId: data?.merchantId
              })
              e.filmNumberData = result?.data || []
              // 仅配置一个膜卷号 自动选中
              if (!e.filmRollNo && e.filmNumberData?.length == 1)
                e.filmRollNo = e.filmNumberData[0]
            }
          }
          if (data.packageGoodsList) {
            data.packageGoodsList.forEach(item => {
              item.packageGoodsOrderList.forEach(g => {
                g.originalPrice = g.price
                g.finalPrice = normalizeOrderMoney(g.finalPrice) ?? g.finalPrice
                const hasTotalPrice =
                  g.totalPrice !== null &&
                  g.totalPrice !== undefined &&
                  g.totalPrice !== ''
                g.price = resolveOrderGoodsUnitPrice(g)
                if (hasTotalPrice) g.sellPrice = g.price
                g.displayPrice =
                  g.discountType == 4
                    ? '0.00'
                    : formatOrderMoney(g.price, '0.00')
                // 判断是否全为无需施工
                if (g.constructionStatus != 3) {
                  allNoConstruction = false
                }
              })
              item.goodsList = item.packageGoodsOrderList
              item.originalPrice = item.price
              item.price = item.goodsList.reduce((prev, cur) => {
                if (cur.discountType == 4) return prev
                return sumOrderMoney([prev, cur.price])
              }, 0)
              item.count = item.goodsList.length ? item.goodsList[0].number : 1
              item.finalPrice = resolveOrderPackageFinalPrice(item.goodsList)
              item.packageGoodsOrderList.forEach(g => {
                g.positionStr =
                  positionTypeList.filter(
                    v => v.positionValue == g.upgradeGoodsPosition
                  )[0]?.positionName || ''
              })
              total_price = sumOrderMoney([total_price, item.finalPrice])
              normalizeMarketingFlagOnItem(item)
            })
          }

          data.subOrderList?.forEach((item) => normalizeMarketingFlagOnItem(item))

          data = {
            ...data.customer,
            ...data.payOrder,
            ...data,
            packageGoodsList: data.packageGoodsList,
            couponName,
            originalTotalPrice: data.totalPrice || data.total_price,
            total_price:
              data.selectPayType == 0
                ? 0
                : formatOrderMoney(total_price, '0.00')
          }
          data.customerPhone = resolveBoutiqueDetailCustomerPhone(data)
          if (data.customerCoupon) {
            data.customerCoupon.customerCouponCode =
              data.customerCoupon.customerCouponCode.split('-')[0]
          }
          if (data.orderTime)
            data.time = new Date(data.orderTime).format('yyyy-MM-dd hh:mm:ss')
          if (data.customer && data.customer.carSeriesName) {
            data.carType = `${data.customer.carBrand || ''}-${
              data.customer.carChildsBrandName || ''
            }-${data.customer.carSeriesName || ''}`
          }
          const customerDailyDisplay = buildBoutiqueCustomerDailyDisplay(
            data.customer
          )
          data.customerTagLabels = customerDailyDisplay.customerTagLabels
          data.actualDeliveryDateDisplay = customerDailyDisplay.actualDeliveryDate
          data.showCustomerTags = customerDailyDisplay.showCustomerTags
          data.showActualDeliveryDate = customerDailyDisplay.showActualDeliveryDate
          // 处理订单是否显示 操作按钮 支付方式为pos和微信 并且订单状态是 4和6
          // data.failureFlag != 'Y'
          data.canOperate =
            [1, 3, 4].includes(data.selectPayType) &&
            [4, 6].includes(data.status)
          // data.goodsOrderApplyStatus = 2
          this.setData({
            allNoConstruction,
            orderInfo: data,
            customerTagLabels: data.customerTagLabels,
            flag: true,
            warrantyCardList,
            invoiceName: data.invoiceStatus == 2 ? '查看发票' : '申请开票'
          })
          // 去掉车主评价功能
          // this.setQrBoxHeight()
          // if (data.status == 6) return
          // this.getQrCode(data)

          this.getWorkWechatLiveQRCode()
          // 条形码
          warrantyCardList.length && this.getBarCode()

          // 校验是否显示二级流量方
          if (data.subShopMerchantName) {
            let { customerObj } = this.data
            if (
              customerObj.findIndex(
                val => val?.key && val.key == 'subShopMerchantName'
              ) < 0
            ) {
              customerObj[customerObj.length - 2] = {
                label: '二级流量方',
                key: 'subShopMerchantName'
              }
            }
            this.setData({
              customerObj
            })
          }
          // // 门店是否配置技师
          // if (data?.technicianConfigDTOList?.length > 0) {
          //   this.isArtificer(data)
          // }
          // 获取园区店技师配置数据 wx.$util.getStorageSync('dj_boutique_user_info')?.merchantId
          api
            .getQYTechnicianList({
              yqMerchantId: wx.$util.getStorageSync('dj_boutique_user_info')
                ?.merchantId
            })
            .then(respone => {
              if (respone?.code == 0) {
                if (respone?.data.length > 0) this.isArtificer(respone.data)
              }
            })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: message,
            showCancel: false,
            confirmText: '刷新',
            confirmColor: '#347BFF',
            success(res) {
              if (res.confirm) {
                _this.getOrderDetail(orderCode)
              }
            }
          })
        }
      })
  },

  // 选择技师确认
  changeArtificer(e) {
    let value = e?.detail || {}
    let { orderInfo } = this.data
    orderInfo?.subOrderList?.forEach(val => {
      if (val.subOrderCode == value?.subOrderCode) {
        val.technicianName = value.technicianName
        val.technicianUuid = value.technicianUuid
        val.technicianId = value.technicianId
      }
    })
    orderInfo?.packageGoodsList?.forEach(child => {
      console.log(child, 'child')
      child?.goodsList.forEach(val => {
        if (val.subOrderCode == value?.subOrderCode) {
          val.technicianName = value.technicianName
          val.technicianUuid = value.technicianUuid
          val.technicianId = value.technicianId
        }
      })
    })
    let params = {
      orderCode: orderInfo?.orderCode,
      subOrderCode: value?.subOrderCode,
      technicianName: value?.technicianName,
      technicianUuid: value?.technicianUuid,
      technicianId: value?.technicianId
    }
    api.updateTechnicianInfo(params).then(res => {
      let { code, message } = res
      if (code == 0) {
        this.setData({
          artificerSelectPopup: false,
          artificerSelectObj: value,
          orderInfo
        })
      } else {
        wx.$util.showToast(message)
      }
    })
  },

  // 选择膜卷号
  selectfilmRollNo(e) {
    let { item, index } = e.currentTarget.dataset
    this.setData({
      filmRollNoList: item?.filmNumberData,
      selectFilmNumberIndex: index,
      filmSelectedItem: item.filmRollNo,
      filmRollNoPopup: true
    })
  },

  // 选择膜卷号确认
  changefilmRollNo(e) {
    let { selectFilmNumberIndex } = this.data
    let prop = `orderInfo.subOrderList[${selectFilmNumberIndex}].filmRollNo`
    this.setData({
      [prop]: e?.detail,
      filmRollNoPopup: false
    })
  },

  // 选择技师
  selectArtificer(e) {
    let { item } = e.currentTarget.dataset
    this.setData({
      artificerSelectPopup: true,
      artificerSelectObj: item
    })
  },

  isArtificer(data) {
    let { customerObj, orderInfo } = this.data
    orderInfo.isOpenArtificer = true
    orderInfo.technicianList = data || [] // 技师数据
    // if (customerObj.findIndex(val =>val?.key && val.key == 'technicianName') < 0) {
    //   customerObj[customerObj.length] = {
    //     label: '选择技师:',
    //     key: 'technicianName'
    //   }
    // }
    this.setData({
      customerObj,
      artificerList: data,
      orderInfo
    })
  },

  getBarCode() {
    // warrantyCardList
    let that = this
    let { warrantyCardList } = this.data
    warrantyCardList.forEach((element, index) => {
      setTimeout(() => {
        api
          .createBarCode({
            content: element.cardCode
          })
          .then(result => {
            let { code, data } = result
            // 待优化 应该都有之后再一次性更新
            // warrantyCardList[index].barCodeUrl = 'http://qcimg01.glsx.com.cn:7060/group1/M00/02/96/wKgD3mNXkD-ALMu3AAABmn9Id4c794.png'
            if (code == 0) {
              warrantyCardList[index].barCodeUrl = data
            }
            that.setData({
              warrantyCardList
            })
          })
          .catch(err => {})
      }, 1000 * index)
    })
  },
  getServiceBaseInfo(merchantId) {
    api
      .getServiceBaseInfo({
        merchantId
      })
      .then(result => {
        console.log(result, 'result')
        let { data, code } = result
        const warrantyCardVisible = data.cardCodeFlag && data.cardCodeFlag == 1
        this.setData({
          warrantyCardVisible: !warrantyCardVisible
        })
      })
  },
  getSignatureSwitch(merchantId) {
    api
      .getSignatureSwitch({
        merchantId
      })
      .then(result => {
        console.log(result, 'result')
        let { data, code } = result
        // const warrantyCardVisible = data.cardCodeFlag && data.cardCodeFlag == 1
        const signatureSwitchValue =
          data?.signatureSwitch && data?.signatureSwitch == 1
        this.setData({
          // warrantyCardVisible: !warrantyCardVisible,
          signatureSwitch: signatureSwitchValue
        })
      })
  },
  setQrBoxHeight() {
    wx.$util.getViewInfo('#qr-view', ({ height }) => {
      // console.log(height)
      this.setData({
        qrHeight: height,
        qrFlag: true
      })
    })
  },
  showQrBox() {
    this.setData({
      qrFlag: !this.data.qrFlag
    })
  },
  getQrCode() {
    let data = this.data.orderInfo
    let appId = 'wx06d1198e751435d1'
    let path =
      'packagePersonal/pages/boutiquePages/boutiqueInstall/boutiqueInstall'
    let scene = `orderCode=${data.orderCode}&merchantId=${data.merchantId}`
    // B端小程序调用接口生成领券码时,传参userId用uuid,类型由int变string
    api
      .createWeappQrcode({
        qrcodeType: 'QR_WXA_UNLIMIT',
        appId,
        channelType: 1,
        path,
        scene
      })
      .then(qr => {
        if (qr.data) {
          this.setData({
            qr: qr.data
          })
        }
        this.setData({
          qrFlag: true
        })
      })
  },
  keepGoing(type) {
    let { orderInfo } = this.data
    orderInfo.orderSource = type
    delete orderInfo.orderCode
    wx.$router.redirectTo('createOrder', orderInfo)
  },
  getWorkWechatLiveQRCode() {
    this.setData({
      customerService: ''
    })
    let { failCustomerService, defaultCustomerService } = this.data
    let {
      orderCode,
      customerPhone: phoneNumber,
      selectPayType
    } = this.data.orderInfo
    // console.log(orderCode, phoneNumber, selectPayType)
    // 订单状态 1-升级订单 2-战败订单
    let orderType = selectPayType == 0 ? 2 : 1
    api
      .getWorkWechatLiveQRCode({
        orderCode,
        phoneNumber,
        orderType
      })
      .then(result => {
        let { code, data: url, message } = result
        // console.log(url)
        if (code == 0) {
          this.setData({
            customerService: url
          })
        } else {
          // console.log(defaultCustomerService)
          this.setData({
            customerService: defaultCustomerService
          })
        }
        //  else {
        //   wx.$util.showToast(message)
        // }
      })
      .catch(err => {
        // console.log(err)
        this.setData({
          customerService: failCustomerService
        })
      })
    // }, 3000)
  },

  // 开票
  handleBtnInvoice() {
    this.handleInvoiceDetail()
  },

  handleSelectInvoice() {
    let { invoiveVisible } = this.data
    this.setData({
      invoiveVisible: !invoiveVisible
    })
  },
  handleInvoiceDetail() {
    let { orderInfo } = this.data
    const params = {
      orderCode: orderInfo.orderCode
    }
    wx.$util.showLoading()
    commonApi
      .getOrderCode(params)
      .then(res => {
        let { invoiceInfo, invoiceIssueQrcode } = res.data
        if (invoiceInfo) {
          // 开票成功、开票失败
          wx.$router.go('tabWorkOrder.invoiceResult', {
            obj: {
              // code - 0000:成功;其他:失败
              code: invoiceInfo.code,
              bizOrderCode: invoiceIssueQrcode.bizOrderCode,
              invoiceAmount: invoiceIssueQrcode.invoiceAmount,
              createdDate: invoiceIssueQrcode.createdDate,
              imgUrl: invoiceInfo.imgUrl,
              msg: invoiceInfo.msg
            }
          })
        } else {
          /**
           * 未开发票
           * invoiceIssueQrcode若存在,已开了开票二维码,无需选择发票类型;反之,需选。
           *  */
          !invoiceIssueQrcode
            ? this.handleSelectInvoice()
            : wx.$router.go('tabWorkOrder.invoiceCode', {
                obj: invoiceIssueQrcode
              })
        }
      })
      .finally(() => {
        wx.$util.hideLoading()
      })
  },

  previewImage(e) {
    let { url, index } = e.currentTarget.dataset
    // if (url.includes('http')) {
    let urlList = url.map(v => {
      return v.payVoucher
    })
    wx.previewImage({
      urls: urlList,
      current: urlList[index]
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    const selectInvoiceObj = getApp().globalData.selectInvoiceObj
    if (selectInvoiceObj?.isOpen) {
      this.handleSelectInvoice()
    }
    delete getApp().globalData?.selectInvoiceObj // 使用后清除
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let { orderCode } = this.data
    if (orderCode) {
      this.getOrderDetail(orderCode)
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {}
})