orderDetail.js 24.4 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
// 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 {
  buildOrderDisplayInfo,
  resolveOrderGoodsUnitPrice,
  resolveOrderPackageFinalPrice,
  resolveConstructionButton,
  sumOrderMoney
} from '../../utils/orderDisplay.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,
    customerService: '',
    defaultCustomerService:
      'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/kf.png',
    failCustomerService:
      'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/kf.png',
    warrantyCardVisible: true,
    selectFilmNumberIndex: 0,
    filmRollNoList: [],
    isUseFilmRoll: false,
    filmRollNoPopup: false,
    filmSelectedItem: '',
    tipsProps: {
      tipsText: '技师施工完毕后,点击完成施工按钮结束工单。',
      showTips: true,
      type: 1
    },
    baseConfigData: {},
    isMake: true,
    packageGoodsList: [],
    showModal: false,
    sublistVisible: false,
    constructionVisible: false
  },
    // 监听弹窗关闭事件
	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.$util.showToast('客户画像暂不支持在区域助手中查看')
  },
  showModal(e) {
    let { btnname } = e.currentTarget.dataset
    console.log(e, btnname)
    this.setData(
      {
        [btnname]: true
      },
      () => {
        wx.setPageStyle({
          style: {
            overflow: 'hidden'
          }
        })
      }
    )
  },
  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()
          _this.getOrderDetail(orderCode)
        } 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.setData({
      isYqdSuper: app.globalData.isYqdSuper,
      isStaff: app.globalData.isStaff,
      userInfo: o,
      isMake: !(
        wx.$hasPermission?.canSelectMultiStoreWithTechnician?.(userInfo)
      )
    })
    this.getStaffPermissions()
  },
  showFlag(orderCode) {
    api
      .showFlag({
        orderCode
      })
      .then(res => {
        console.log(res)
        let { code, message, data } = res
        console.log('showFlag', res)
        if (code == 0) {
          this.setData({
            confirmFlagObj: resolveConstructionButton(data.confirmFlag),
            updateFlag: data.updateFlag
          })
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  async getOrderDetail(orderCode) {
    let _this = this

    let { 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)
          // 服务商是否使用膜卷号配置
          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')
            }
            total_price = sumOrderMoney([total_price, e.finalPrice])
            e.originalPrice = e.price
            if (e.totalPrice) {
              e.price = e.totalPrice
              e.sellPrice = e.totalPrice
            } else {
              e.price = resolveOrderGoodsUnitPrice(e).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
              })
            }
            // 膜类商品并且服务商开通了膜卷号配置
            if (
              baseConfigData?.membraneTypeList?.includes(e?.upgradeGoodsType) &&
              isUseFilmRoll
            ) {
              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
                if (g.totalPrice) {
                  g.price = g.totalPrice
                  g.sellPrice = g.totalPrice
                } else {
                  g.price = resolveOrderGoodsUnitPrice(g)
                }
                // 判断是否全为无需施工
                if (g.constructionStatus != 3) {
                  allNoConstruction = false
                }
              })
              item.goodsList = item.packageGoodsOrderList
              item.originalPrice = item.price
              item.price = sumOrderMoney(
                item.goodsList.map(resolveOrderGoodsUnitPrice)
              )
              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 = {
            ...buildOrderDisplayInfo(data),
            packageGoodsList: data.packageGoodsList,
            couponName,
            originalTotalPrice: data.totalPrice || data.total_price,
            total_price:
              data.selectPayType == 0
                ? 0
                : Number(wx.$util.decimal(total_price, 2)).toFixed(2)
          }
          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 || ''}`
          }
          // 处理订单是否显示 操作按钮 支付方式为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,
            flag: true,
            warrantyCardList
          })
          // 去掉车主评价功能
          // 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
        })
      })
  },
  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)
  },

  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) {
  },

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

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

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

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