open.js 12.5 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
import {
  equityApi, carlifeApi
} from '../../../api/api'
import { defaultMerchantId } from '../../../api/environment'
let navBarHeight = 38
const navStyle = 'background-color: transparent;'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navStyle,
    isOpen: false,
    openingStatus: false,
    packageList: [],
    packageCurIndex: 0,
    equityList: [],
    to: '',
    servicesList: [],
    showAuthBtn: true,
    showLogin: false,
    showPop: false,
    showType: 1,
    showSingleModel: false
  },
  navbarReady(e) {
    navBarHeight = e.detail.height
  },
  onPageScroll({
    scrollTop
  }) {
    if (scrollTop >= navBarHeight && this.data.navStyle) this.setData({
      navStyle: ''
    })
    if (scrollTop < navBarHeight && !this.data.navStyle) this.setData({
      navStyle
    })
  },
  selectPackage(e) {
    const {
      index,
      item
    } = e.currentTarget.dataset;
    if (index != this.data.packageCurIndex) {
      this.data.control = false
    }
    if (index) {
      this.getServicesData(item.id)
    }
    this.setData({
      packageCurIndex: index,
      packageCurItem: item,
      to: `to-${index}`,
      servicesList: index ? this.data.servicesList : []
    })
  },
  toIntroducePage(e) {
    let {
      servicesList,
      packageCurItem
    } = this.data
    let param = {
      servicesList,
      package: packageCurItem
    }
    let temp = encodeURIComponent(JSON.stringify(param));
    wx.navigateTo({
      url: "/packageEquity/pages/introduce/introduce?element=" + temp,
    });
  },
  toAllEquity() {
    wx.navigateTo({
      url: "/packageEquity/pages/allEquity/allEquity",
    });
  },
  // 获取权益列表
  getEquityData() {
    equityApi.equityFnMenu({}).then(res => {
      this.setData({
        equityList: res || []
      })
    })
  },

  // 获取服务列表
  getServicesData(packageId) {
    if (this.data.control) {
      return
    }
    this.data.control = true
    equityApi.equityServices({
      packageId
    }).then(res => {
      this.setData({
        servicesList: res
      })
    })
  },

  // 获取门店会员卡信息
  getMemberCardData(options) {
    const merchantId = wx.$util.getStorageSync('srcm_shopmall_merchant_id') || defaultMerchantId
    this.dyRefreshVIPcardInfo(options, merchantId)
    const equityInfo = wx.$util.getStorageSync('equity_info')
    let userInfo = wx.$util.getStorageSync('srcm_shopmall_user_info')
    if (!userInfo) {
      wx.$util.setStorageSync('open_page_options', options)
    }
    this.setData({
      equityInfo,
      loginStatus: !userInfo,
      merchantId
    })
  },

  // 获取用户会员信息
  toCheckMember() {
    equityApi.checkOpenMember().then(res => {
      if (res.code == 0 && res.data) {
        wx.$eventbus.emit('EQUITY')
        this.setData({
          openingStatus: false,
        })
        if (this.data.pageForm) {
          if (this.data.pageForm == 'oil') {
            wx.$eventbus.emit('OILPAGE', true)
          }
          this.toBack()
          return
        }
        wx.switchTab({
          url: '/pages/tab/equity/equity'
        })
      } else {
        setTimeout(() => {
          this.setData({
            openingStatus: false,
          })
        }, 1000)
      }
    })
  },
  // 去购买会员
  async openMemberFn(carbind = '') {
    const {
      memberInfo,
      merchantId,
      packageCurItem,
      showLogin,
      staff
    } = this.data
    const userInfo = wx.$util.getStorageSync('srcm_shopmall_user_info')
    // const merchantName = wx.$util.getStorageSync('merchant_info')
    let apiName = 'buyMemberCard'
    if (showLogin) {
      return
    }

    wx.$util.showLoading()
    let para = {
      equityClassId: memberInfo.equityClassId,
      orderSource: 3,
      merchantId: merchantId,
      merchantName: userInfo.merchantName
    };

    if (packageCurItem.id) {
      para.packageId = packageCurItem.id
      para.merchantId = merchantId
      para.merchantName = userInfo.merchantName
      para.paySource = 3
      apiName = 'equityBuy'
      para.bindCarType = carbind.length == 17 ? 2 : 1
      para.bindCarNum = carbind
      if (staff) {
        const { shareStaffUuid, shareStaffName } = staff
        para.shareStaffUuid = shareStaffUuid
        para.shareStaffName = shareStaffName
      }
    } else {
      para.orderCode = memberInfo.orderCode
    }
    wx.$Track.setTrack({
      ...para,
      type: '购买权益卡'
    }, 7)
    equityApi[apiName](para).then(res => {
      wx.hideLoading()
      this.handlePay(res)
    })
  },
  // 处理购买参数拉起支付
  handlePay(payData) {
    const {
      timeStamp,
      nonceStr,
      packages,
      signType,
      paySign
    } = payData;
    let self = this
    wx.requestPayment({
      timeStamp: timeStamp,
      nonceStr: nonceStr,
      package: packages,
      signType: signType,
      paySign: paySign,
      success() {
        setTimeout(() => {
          self.toCheckMember()
          self.buyToTrack()
        }, 1500)
        self.setData({
          openingStatus: true,
        })
      },
      fail() {

      }
    })
  },

  clickWebImage() {
    const vip = wx.$util.isMember()
    if (vip) {
      let bizjiaUrl = wx.getStorageSync("bizjiaUrl");
      wx.$router.jumpH5(bizjiaUrl, false);
      return
    }
    this.setData({
      showPop: true,
      showType: 1
    })
  },
  tocomfirm(e) {
    this.openMemberFn(e.detail)
  },
  // 绑定车架号
  toCheckVin() {
    const SID = wx.$util.getSessionId()
    if (!SID) {
      this.setData({
        canAcceptLoginCallBack: true,
        showLogin: true
      })
      return
    }
    if (this.data.packageCurItem.id) {
      this.setData({
        showBind: true
      })
    } else {
      this.openMemberFn()
    }
  },

  onLoad(options) {
    let tempOptions = wx.$util.getStorageSync('open_page_options')
    if (tempOptions) {
      options = tempOptions
      wx.removeStorageSync('open_page_options')
    }
    // 此处单独走单个套餐+推荐人逻辑
    if (options.packageType && options.packageType == 2) {
      this.handlerShortLink(options)
      return
    }
    this.getMemberCardData(options)
    this.getEquityData()
  },
  toBack() {
    if (this.data.showSingleModel) {
      wx.switchTab({
        url: '/pages/tab/equity/equity'
      })
      return
    }
    wx.navigateBack({
      delta: 1
    })
  },
  toLook() {
    wx.navigateTo({
      url: '/packageEquity/pages/agreement/index'
    })
  },
  toActive() {
    wx.navigateTo({
      url: '/packageEquity/pages/active/active'
    })
  },
  toArticle() {
    const url = 'https://mp.weixin.qq.com/s/kkpZaucCn0QOCqgbf6WvFA'
    const temp = encodeURIComponent(url)
    wx.navigateTo({
      url: '/pages/webView/webView?url=' + temp
    })
  },
  toNewPage(e) {
    const {
      item
    } = e.currentTarget.dataset
    let url = ''
    if (item.supplier == 'GL_OIL') {
      let sid = wx.$util.getSessionId()
      if (!sid) {
        url = '/packageEquity/pages/oil/oil?open=2'
      }
      const vip = wx.$util.isMember()
      url = '/packageEquity/pages/oil/oil?open=' + `${vip ? 1 : 2}`
      // let para = 'https://mp.weixin.qq.com/s/q-01zUdBjlOc4z_5HO-ruA'
      // para = encodeURIComponent(para)
      // url = '/pages/webView/webView?url=' + para
    } else if (item.supplier == 'GL_ROAD_RESCUE') {
      url = 'packageEquity.road.index'
      wx.$router.go(url, {});
      return
    } else if (item.supplier == 'GL_TIRE_PROTECTION') {
      url = '/packageEquity/pages/tire/tire'
    } else if (item.supplier == 'EDJ') {
      let para = wx.getStorageSync('edjurl') || ''
      para = encodeURIComponent(para)
      url = '/pages/webView/webView?url=' + para
    } else if (item.appearance == 1) {
      let para = {
        supplier: item.supplier,
        brandName: item.brandName,
        location: true
      }
      const temp = JSON.stringify(para)
      url = '/packageEquity/pages/commodity/detail/detail?param=' + temp
    } else if (item.appearance == 2) {
      let para = {
        supplier: item.supplier,
        brandName: item.brandName,
        icon: item.equityIcon,
      }
      const temp = JSON.stringify(para)
      url = '/packageEquity/pages/commodity/chargeDetail/chargeDetail?param=' + temp
    }
    wx.navigateTo({
      url,
    })
  },
  init() {

  },
  onShow() {
    let plate = wx.getStorageSync('plate');
    if (plate) {
      this.setData({
        plate
      }, () => {
        wx.removeStorageSync('plate')
      })
    }
  },
  /**v2.7.0版本:权益卡金卡名称动态获取 */
  dyRefreshVIPcardInfo(options, merchantId) {
    let { packageList } = this.data
    const {
      page,
      memberType,
      index,
      item
    } = options
    packageList = wx.$util.getStorageSync('packageList')|| []
    equityApi.memberCard({ merchantId }).then((res) => {
      wx.$util.setStorageSync('vip_card_info', res)
      packageList.unshift({
        packageName: res.equityGoldName || '金卡优享会员',
        payPrice: res.goodPrice,
        packagePrice: res.goodPrice,
      })
      let obj = {
        memberType,
        pageForm: page,
        packageCurItem: packageList[0],
        memberInfo: res,
        packageList
      }
      if (item != 'null') {
        let temp = JSON.parse(item)
        this.getServicesData(temp.id)
        let addobj = {
          to: `to-${Number(index) + 1}`,
          packageCurIndex: Number(index) + 1,
          packageCurItem: temp,
          memberType: memberType,
          pageForm: page,
        }
        Object.assign(obj, addobj)
      }
      this.setData(obj)
      this.toGetPackage(options, merchantId, packageList)
      wx.$Track.setTrack({
        memberInfo: res
      }, 6)
    });
  },
  /****以下内容皆为企微端单独处理--企微端--集团套餐短链分享 */
  async handlerShortLink(options) {
    const { id, merchantId, shareStaffName, shareStaffUuid } = options
    await this.getVIPcard(merchantId, id)
    this.getServicesData(id)
    this.getEquityData()
    this.setData({
      staff: { shareStaffName, shareStaffUuid },
      showSingleModel: true,
      merchantId
    })
    options.item_type = 4
    options.action_type = 1
    options.item_id = id
    wx.$util.reportData(options, false, false, true)
    this.data.trackOptions = options
  },
  buyToTrack() {
    let { trackOptions } = this.data
    if (!trackOptions) return
    let options = trackOptions
    options.item_type = 4
    options.action_type = 3
    options.item_id = options.id
    options.order_id = orderCode
    wx.$util.reportData(options, false, false, true)
  },
  // 获取门店会员卡信息
  getVIPcard(merchantId, id) {
    equityApi.memberCard({ merchantId }).then((res) => {
      wx.$util.setStorageSync('vip_card_info', res)
      this.setData({
        memberInfo: res,
      }, () => {
        this.getJTdetail(id)
      });
    });
  },
  // 获取套餐详情
  getJTdetail(id) {
    let para = {
      packageId: id
    }
    equityApi.equityJTpackageDetail(para).then(res => {
      let { packageList, memberInfo } = this.data
      packageList.unshift({
        packageName: memberInfo.equityGoldName || '金卡优享会员',
        payPrice: memberInfo.goodPrice,
        packagePrice: memberInfo.goodPrice,
      })
      packageList.push(res)
      this.setData({
        packageList,
        packageCurIndex: 1,
        packageCurItem: res
      })
    })
  },
  loginCallBack(data) {
    if (data) {
      wx.$eventbus.emit('PLATEREFRESH', true)
      if (this.data.canAcceptLoginCallBack) {
        this.toCheckVin()
      }
      if (this.data.showSingleModel) {
        this.getVIPinfo()
        this.getBizjiaUrl()
      }
      wx.$eventbus.emit('REFRESHINDEX')
    }
  },
  getBizjiaUrl() {
    carlifeApi.getBizjiaUrl().then((res) => {
      wx.setStorageSync("bizjiaUrl", res);
    });
  },
  getVIPinfo() {
    equityApi.checkOpenMember().then((res) => {
      if (res.data && res.data.cardType) {
        this.data.memberType = 6
      }
    });
  },
  /**v2.8.0首页进入 */
  toGetPackage(options, merchantId, packageList) {
    if (!options.getPackage) return
    let userInfo = wx.$util.getStorageSync("srcm_shopmall_user_info");
    let newMerchantId = merchantId || defaultMerchantId;
    let para = {
      merchantId: newMerchantId,
      pageNum: 1,
      pageSize: 100,
      state: 1
    }
    if (userInfo) {
      para.accountId = userInfo.accountId
    }
    wx.$util.showLoading()
    equityApi.equityPacks(para).then((res) => {
      wx.hideLoading()
      let arr = res.list || []
      if (!arr.length) return
      arr.forEach(el => {
        packageList.push(el)
      })
      this.setData({
        packageList,
      });
    })
    this.getBizjiaUrl()
  },
})