constructionOrderDetail.js 31.3 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 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
// tabWorkOrder/pages/orderDetail/orderDetail.js
import api from '../../api.js'
import order_mixins, { data } from '../order_mixins.js'
import { getPositionList } from '~/store/index'
import {
  checkDailyReport,
  checkStudyTask,
  checkOrderLockGate
} from '~/store/ModalToQueueControl'
import { openOrderPromptWithRestrictState } from '~/tabIndex/services/newOrderAbnormalFlowRestrict.service.js'
import { confirmOrderPrompt } from '~/tabIndex/services/orderPromptConfirm.service.js'
import commonApi from '~/api/api'
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: {
    IMG_URL,
    ...order_mixins.data,
    selectType: 1,
    selectTypeOrder: 1,
    qrFlag: true,
    qrHeight: 107,
    isYqdSuper: app.globalData.isYqdSuper,
    isStaff: app.globalData.isStaff,
    customerService: '',
    defaultCustomerService:
      'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/kf.png',
    // defaultCustomerService: 'https://img01.glsx.com.cn/group1/M00/21/01/wKgFHWKEkeSAZRltAAED5CfS91o118.png',
    failCustomerService: `${IMG_URL}components/images/kfrefresh.png`,
    showTip: false,
    warrantyCardVisible: true,
    showRatingPopup: false,
    showRatingCard: true, // 显示评价卡片
    isMake: true,
    warrantyEditObj: {},
    // 发票按钮
    invoiceName: '申请开票',
    invoiveVisible: false,
    showMoreBtn: false,
    constructionVisible: false
  },
  constructionCancel() {
    this.setData(
      {
        constructionVisible: false
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'unset'
          }
        })
      }
    )
  },
  RatingPopupSetting() {
    this.setData({
      showRatingPopup: !this.data.showRatingPopup
    })
    // 更新数据
    this.getOrderDetail(this.data.orderInfo.orderCode)
  },
  jumpUserPortrait() {
    wx.$router.go('tabDate.userPortrait', this.data.orderInfo)
  },
  selectTypeOrder(e) {
    let { type } = e.currentTarget.dataset
    console.log(e, e.currentTarget.dataset, type)
    this.setData({
      selectTypeOrder: type
    })
  },
  blur(e) {
    console.log(e)
    let { value } = e.detail
    // let { shortcutList } = this.data
    value = value.substring(0, 50)
    // if (!value) {
    //   shortcutList.map(i => (i.active = false))
    // }
    this.setData({
      ['warrantyEditObj.warrantyPrice']: value,
      // shortcutList,
      focus: false
    })
  },
  // 确定是否要显示
  showWarranty(e) {
    let { item } = e.currentTarget.dataset
    this.setData({
      warrantyEditObj: item,
      focus: true
    })
    wx.$modal(
      this,
      {
        show: true,
        title: '',
        tabTitleShow: false,
        success: res => {
          let { orderCode } = this.data
          api
            .modifyWarrantyPrice({ ...this.data.warrantyEditObj })
            .then(result => {
              wx.$util.showToast('更新成功')
              this.getOrderDetail(orderCode)
            })
            .catch(err => {})
          // 跳转新增订单页面 并带特定参数
          // let { selectType } = this.data;
          // if (selectType == 1) {
          //   wx.$router.go("tabWorkOrder.createOrder", {
          //     scene,
          //     ...item,
          //   });
          // } else {
          //   wx.$router.go("tabWorkOrder.defeatOrder", {
          //     scene,
          //     ...item,
          //   });
          // }
        },
        error: () => {}
      },
      '#modal4'
    )
  },
  // 确定是否要显示
  showSelectTypeOrder({ scene = '', item = {} }) {
    wx.$modal(
      this,
      {
        show: true,
        title: '请选择录单入口',
        tabTitleShow: false,
        success: async res => {
          // 跳转新增订单页面 并带特定参数
          let { selectTypeOrder } = this.data
          console.log(item, 'showSelectType')
          // if (orderInfo?.selectPayType == 0) { // 解决战败进新建工单导致查询战败商品的问题
          //   orderInfo.selectPayType = 2
          // }
          if (selectTypeOrder == 1) {
            await openOrderPromptWithRestrictState(this)
          } else {
            let orderInfo = this.deleteOrderInfo()
            wx.$router.go('tabWorkOrder.defeatOrder', {
              scene,
              ...orderInfo
            })
          }
        },
        error: () => {}
      },
      '#modal3'
    )
  },
  deleteOrderInfo() {
    let { orderInfo } = this.data
    let copyOrderInfo = wx.$util.deepClone(orderInfo)
    copyOrderInfo.orderSource = 4
    let deleteList = [
      'orderCode',
      'associateOrderCode',
      'packageGoodsList',
      'merchantDistributionList',
      'expenseCategoryList',
      'profitAllocatinList',
      'clientSignatureDTOList',
      'customerPhotos',
      'rating',
      'sellerName',
      'sellerUserId',
      'sellerMerchantName',
      'sellerMerchantId',
      'subOrderList',
      'technicianList',
      'merchantExpenseDistributionList'
    ]
    for (var i = 0; i < deleteList.length; i++) {
      copyOrderInfo[deleteList[i]] && delete copyOrderInfo[deleteList[i]]
    }
    copyOrderInfo.againOrder = true
    return copyOrderInfo
  },
  async promptHandleConfirm(e) {
    const orderInfo = this.deleteOrderInfo()
    const { orderPromptDjQrOnlyMode } = this.data
    await confirmOrderPrompt(
      e.detail,
      {
        onNavigateCreate: paymentMethod => {
          wx.$router.go('tabWorkOrder.createOrder', {
            paymentMethod,
            ...orderInfo
          })
        },
        onOpenRecordingPopup: () => {
          this.tipsEvent()
        }
      },
      orderPromptDjQrOnlyMode
    )
    const paymentMethod = e.detail.payFlag != 2 ? 1 : e.detail.payType
    this.setData({ paymentMethod })
  },
  promptCancel() {
    this.setData({
      showPromptDialog: false
    })
  },
  // 跳转正确订单
  redirectOrder() {
    let { orderInfo } = this.data
    let _this = this
    wx.$util.showLoading('加载中...')
    api
      .getOrderDetail({
        orderCode: orderInfo.associatedOrderCode
      })
      .then(result => {
        // 根据不同状态和施工标志做对应跳转
        let { code, data: item } = result
        if (code == 0) {
          item.oldOrderCode = orderInfo.associatedOrderCode
          let name =
            item.status == 3
              ? 'confirmOrder'
              : item.status == 1
                ? 'createOrder'
                : 'orderDetail'
          if (item.constructionFlag == 'Y' && item.status != 10) {
            wx.$router.go('constructionOrderDetail', item)
          } else {
            // console.log(item)
            // 解决错单能切换支付方式的问题
            // wx.$router.go(name, { ...item, associateOrderType: true })
            wx.$router.go(name, { ...item })
          }
        }
      })
      .catch(err => {
        console.log(err)
      })
    // wx.$router.redirectTo('constructionOrderDetail', { orderCode: orderInfo.associatedOrderCode })
  },
  targetOperate() {
    let { showTip } = this.data
    this.setData({
      showTip: !showTip
    })
  },
  selectType(e) {
    let { type } = e.currentTarget.dataset
    console.log(e, e.currentTarget.dataset, type)
    this.setData({
      selectType: type
    })
  },
  // 确定是否要显示
  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
    })
    if (refundStep?.data == 'Y') return this.showRefundAlert()
    wx.$modal(this, {
      show: true,
      title: '工单标记',
      tabTitleShow: false,
      success: res => {
        this.showErrorType()
      },
      error: () => {}
    })
  },
  showRefundAlert() {
    wx.showModal({
      title: '提示',
      content:
        '订单已发起退款,禁止标记为错误工单!如需标记错误请联系总部运营。',
      showCancel: false,
      confirmText: '好的'
    })
  },
  // 确定是否要显示
  showErrorType() {
    wx.$modal(
      this,
      {
        show: true,
        title: '请选择录单入口',
        tabTitleShow: false,
        success: async res => {
          // 再次校验 防止二次确认弹窗弹起后长时间未操作,导致订单状态变更异常
          let { orderInfo, selectType } = this.data
          let canRefundStep = await commonApi.getOrderRefundStep({
            orderCode: orderInfo.orderCode
          })
          if (canRefundStep?.data == 'Y') return this.showRefundAlert()
          // 跳转新增订单页面 并带特定参数
          console.log(orderInfo)
          if (selectType == 1) {
            orderInfo.associateOrderCode = orderInfo.orderCode
            delete orderInfo.orderCode
            if (orderInfo.technicianList) {
              delete orderInfo.technicianList
            }
            orderInfo.selectPayType = 2
            let urlName = 'createOrder'
            wx.$router.redirectTo(urlName, orderInfo)
          } else {
            // 无需补录
            api
              .noNeedSupplementOrder({ oldOrderCode: orderInfo.orderCode })
              .then(res => {
                console.log(res)
                if (res.code == 0) {
                  wx.$util.refreshPageData()

                  wx.$router.go('pages.index')
                  this.setData({
                    modalShow: false
                  })
                  wx.$modal(this, { show: false }, '#modal2')
                } else {
                  wx.$util.showToast(res.message)
                }
              })
              .catch(err => {
                console.log(err)
              })
          }
        },
        error: () => {}
      },
      '#modal2'
    )
  },

  // 选择技师确认
  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
      }
    })
    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)
      }
    })
  },

  // 选择技师
  selectArtificer(e) {
    // 已施工完成不可操作
    return
    let { item } = e.currentTarget.dataset
    this.setData({
      artificerSelectPopup: true,
      artificerSelectObj: item
    })
  },

  /**
   * 从施工详情进入客户信息修改页;低价单只允许查看。
   *
   * @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)
  },

  async againOrder() {
    // 校验是否填写昨日日报
    let staffCheck = await checkDailyReport()
    if (staffCheck) return false
    // 校验学习中心开单限制
    let staffStudyTask = await checkStudyTask()
    if (staffStudyTask) return false
    let lockCheck = await checkOrderLockGate()
    if (lockCheck) return false
    if (await wx.$globalDataFunction.inspectionOfProhibitionBill()) return
    // 新增订单
    this.showSelectTypeOrder(4)
  },
  showAgain() {
    this.setData({
      showPopup: true
    })
  },
  showModal(e) {
    let { btnname } = e.currentTarget.dataset
    console.log(e, btnname)
    this.setData(
      {
        [btnname]: true
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'hidden'
          }
        })
      }
    )
  },
  setCopyData(e) {
    let { content } = e.currentTarget.dataset
    console.log(e, 'e')
    wx.$util.setCopyData(`${content}`)
  },
  makePhoneCall(e) {
    let { data } = e.currentTarget.dataset
    wx.makePhoneCall({
      phoneNumber: data
    })
  },
  sublistCancel() {
    this.setData(
      {
        sublistVisible: false
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'unset'
          }
        })
      }
    )
  },
  // 获取人员权限
  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)
      }
    })
  },
  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)
      })
  },
  onRoute(options) {
    // wx.$router.go("pages.index");
    console.log(options, 'onRoute')
    let { orderCode } = this.data
    options.orderCode = options.orderCode || orderCode
    // options.orderCode = '250908213534979'
    if (options.orderCode) {
      this.setData({
        orderCode: options.orderCode
      })
      this.getOrderDetail(options.orderCode)
      this.showFlag(options.orderCode)
      // this.getGrass(options.orderCode)
    }
    wx.setPageStyle({
      style: {
        overflow: 'unset'
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options, 'onLoad')
    // debugger
    // options.orderCode = '250908213534979'
    if (options.orderCode) {
      this.getOrderDetail(options.orderCode)
      this.showFlag(options.orderCode)
    }
    let userInfo = wx.$util.getUserInfo()
    let o = wx.$util.getStorageSync('dj_boutique_user_info')
    this.checkPhoneShow(app.globalData.YQorderSetting?.yqPhoneConfig)
    this.getStaffPermissions()
    this.setData({
      userInfo: o,
      isYqdSuper: app.globalData.isYqdSuper,
      isStaff: app.globalData.isStaff,
      isMake: !wx.$hasPermission?.canSelectMultiStoreWithTechnician?.(userInfo)
    })
  },

  checkPhoneShow(config) {
    console.log('config', config)
    // 有就屏蔽手机号的显示
    if (config) {
      let { customerObj } = this.data
      delete customerObj[2]
      this.setData({
        customerObj
      })
    }
  },
  async getOrderDetail(orderCode) {
    let _this = this
    const positionTypeList = (await getPositionList()) || []
    wx.$util.showLoading('加载中...')
    api
      .getPackageGoodsDetail({
        orderCode
      })
      .then(res => {
        let { code, message, data } = res
        if (code == 0) {
          wx.$util.hideLoading()
          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'
                })
              }
            })
          }
          let couponName = data.customerCoupon
            ? data.customerCoupon.couponName
            : ''
          let total_price = 0
          let warrantyCardList = []
          data.subOrderList = data.subOrderList.filter(
            item => item.merchantGoodsId
          )
          for (var i = 0; i < data?.subOrderList?.length; i++) {
            let e = data?.subOrderList[i]
            // 赠品价格为0
            if (e.discountType == 4) {
              e.price = '0'
            } else {
              total_price += e.finalPrice
              e.price = Number(
                wx.$util.decimal(Number(e.finalPrice / e.number), 2)
              ).toFixed(2)
            }
            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,
                warrantyPrice: e.warrantyPrice
              })
            }
          }
          data?.packageGoodsList &&
            data.packageGoodsList.forEach(item => {
              item.packageGoodsOrderList.forEach(g => {
                if (g.discountType == 4) {
                  g.price = '0'
                } else {
                  g.price = g.finalPrice
                    ? Number(g.finalPrice) / Number(g.number)
                    : g.upgradePrice
                }
              })
              item.goodsList = item.packageGoodsOrderList
              item.count = item.goodsList.length ? item.goodsList[0].number : 1
              // 套餐总价直接累加所有商品的总价
              let total = item.goodsList.reduce((prev, cur) => {
                // 赠品价格为0
                if (cur.discountType == 4) return prev
                return prev + Number(cur.finalPrice)
              }, 0)
              item.finalPrice = wx.$util.decimal(total, 2)
              item.packageGoodsOrderList.forEach(g => {
                g.positionStr =
                  positionTypeList.filter(
                    v => v.positionValue == g.upgradeGoodsPosition
                  )[0]?.positionName || ''
              })
              total_price += item.finalPrice
            })
          data = {
            ...data.customer,
            ...data.payOrder,
            ...data,
            packageGoodsList: data.packageGoodsList,
            couponName,
            total_price:
              data.selectPayType == 0
                ? 0
                : Number(wx.$util.decimal(total_price, 2)).toFixed(2)
          }
          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)
          const orderInfo = data
          console.log(orderInfo)
          const clientSignatureDTOList =
            orderInfo.clientSignatureDTOList?.[0] || []
          console.log(clientSignatureDTOList)
          const showRatingCard =
            [6, 4, 2].includes(orderInfo.status) &&
            orderInfo.selectPayType != 0 &&
            !clientSignatureDTOList.electronicSignature
          this.setData({
            orderInfo: { ...clientSignatureDTOList, ...data },
            customerTagLabels: data.customerTagLabels,
            flag: true,
            warrantyCardList,
            showRatingCard,
            invoiceName: data.invoiceStatus == 2 ? '查看发票' : '申请开票'
          })
          this.setQrBoxHeight()
          // 超时关闭的不显示客服码和
          data.status != 10 && this.getWorkWechatLiveQRCode()
          //  已评价的就不再显示评价码 战败也不显示
          data.status != 6 && data.selectPayType != 0 && this.getQrCode(data)
          // 条形码
          warrantyCardList.length && this.getBarCode()
          this.getServiceBaseInfo(data.merchantId)
          // if (data.status == 6) return
          // 校验是否显示二级流量方
          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)
              }
            }
          })
        }
      })
  },
  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({
      artificerList: data,
      customerObj,
      orderInfo
    })
  },

  getBarCode() {
    // warrantyCardList
    let that = this
    let { warrantyCardList } = this.data
    warrantyCardList.forEach((element, index) => {
      setTimeout(() => {
        // console.log(data.now())
        api
          .createBarCode({ content: element.cardCode })
          .then(result => {
            // console.log(index)
            // console.log(element.cardCode)
            // console.log(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 => {})
      }, 500 * index)
    })
  },
  getServiceBaseInfo(merchantId) {
    api.getServiceBaseInfo({ merchantId }).then(result => {
      console.log(result, 'result')
      let { data, code } = result
      console.log(data)
      if (data.cardCodeFlag && data.cardCodeFlag == 1) {
        this.setData({
          warrantyCardVisible: false
        })
      }
    })
  },
  setQrBoxHeight() {
    const { orderInfo } = this.data
    let statusList = [2, 4, 6]
    if (statusList.includes(orderInfo.status) && orderInfo.selectPayType != 0) {
      wx.$util.getViewInfo('#qr-view', () => {
        this.setData({
          // qrHeight: height,
          qrFlag: true
        })
      })
    }
  },
  showQrBox() {
    this.setData({
      qrFlag: !this.data.qrFlag
    })
  },
  getQrCode() {
    // console.log('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
    // 去除掉错误订单对应的关联码
    // delete orderInfo.associateOrderCode
    // 1031车膜下单版本 再次下单去掉商品信息 需重新选择
    let deleteList = [
      'orderCode',
      'associateOrderCode',
      'packageGoodsList',
      'merchantDistributionList',
      'expenseCategoryList',
      'profitAllocatinList',
      'clientSignatureDTOList',
      'customerPhotos',
      'rating',
      'sellerName',
      'sellerUserId',
      'sellerMerchantName',
      'sellerMerchantId',
      'subOrderList',
      'technicianList',
      'merchantExpenseDistributionList'
    ]
    for (var i = 0; i < deleteList.length; i++) {
      // console.log(arr[i])
      orderInfo[deleteList[i]] && delete orderInfo[deleteList[i]]
    }
    orderInfo.againOrder = true
    // console.log(orderInfo);
    // return
    wx.$router.redirectTo('createOrder', orderInfo)
    // merchantDistributionList,expenseCategoryList,profitAllocatinList
  },
  // previewImage(e) {
  //   let { url } = e.currentTarget.dataset
  //   console.log(url)
  //   if (url.includes('http')) {
  //     wx.previewImage({
  //       urls: [url],
  //       current: url
  //     })
  //   } else {
  //     this.getWorkWechatLiveQRCode()
  //   }
  // },
  // imageLoad(params) {
  //   console.log('load', this.data.imgSrc)
  //   // this.setdata({})
  // },
  // imageError(params) {
  //   console.log('error', this.data.imgSrc)
  // },
  getWorkWechatLiveQRCode() {
    this.setData({
      customerService: ''
    })
    // setTimeout(() => {
    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 && url) {
          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
    let urlList = url.map(v => {
      return v.payVoucher
    })
    wx.previewImage({
      urls: urlList,
      current: urlList[index]
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    console.log(this.data)
    let code = this.data.orderCode || ''
    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 () {}
})