|
|
@@ -71,6 +71,7 @@
|
|
|
import { fastPay } from '@/api/pay'
|
|
|
import { recharge } from '@/api/member'
|
|
|
import { getOrderShop } from '@/utils/config'
|
|
|
+ import { clearStaleHdIdForScanPay, isScanPayLaunchQuery } from '@/utils/launchScene'
|
|
|
export default {
|
|
|
name: 'pay',
|
|
|
components: {
|
|
|
@@ -152,29 +153,61 @@
|
|
|
init(){
|
|
|
this.specialInit();
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 扫码付款请求上下文:强制 account + hdId=0,避免首页异步把旧店 hdId 写回后串到 fast-pay
|
|
|
+ */
|
|
|
+ buildScanSafeRequestContext() {
|
|
|
+ const opt = this.option || {}
|
|
|
+ const account = opt.account || uni.getStorageSync('account') || ''
|
|
|
+ const ctx = {}
|
|
|
+ if (account) {
|
|
|
+ ctx.account = account
|
|
|
+ }
|
|
|
+ // 仅扫码入口强制 hdId=0;店内「向商家付款」继续走本地 hdId 做会员优惠
|
|
|
+ if (isScanPayLaunchQuery(opt)) {
|
|
|
+ clearStaleHdIdForScanPay(opt)
|
|
|
+ ctx.hdId = 0
|
|
|
+ } else if (opt.hdId) {
|
|
|
+ ctx.hdId = opt.hdId
|
|
|
+ }
|
|
|
+ return ctx
|
|
|
+ },
|
|
|
specialInit() {
|
|
|
- if (this.option.pageType) {
|
|
|
+ if (this.option && this.option.pageType) {
|
|
|
this.tabIndex = parseInt(this.option.pageType)
|
|
|
}
|
|
|
- getOrderShop(true).then(res => {
|
|
|
+ // 扫码进店先清旧 hdId,再拉门店;否则 order-relate 会被 BaseController 清空 shop
|
|
|
+ clearStaleHdIdForScanPay(this.option)
|
|
|
+ const relateParams = this.buildScanSafeRequestContext()
|
|
|
+ getOrderShop(true, relateParams).then(res => {
|
|
|
+ // 跨店扫码若仍带旧 hdId,后端会清空 shop;需判空避免 showName/分享拼出 account=undefined
|
|
|
+ const shop = res && res.shop ? res.shop : null
|
|
|
+ if (!shop || this.$util.isEmpty(shop)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
this.inpFocus = true
|
|
|
-
|
|
|
- this.showName = res.shop.showName
|
|
|
- this.smallAvatar = res.shop.smallAvatar
|
|
|
- this.$refs.couponSel._getUserDiscount().then(status => {
|
|
|
- this.discountArr = status
|
|
|
- })
|
|
|
- // 设置分享
|
|
|
+ this.showName = shop.showName || ''
|
|
|
+ this.smallAvatar = shop.smallAvatar || ''
|
|
|
+ if (this.$refs.couponSel && typeof this.$refs.couponSel._getUserDiscount === 'function') {
|
|
|
+ this.$refs.couponSel._getUserDiscount().then(status => {
|
|
|
+ this.discountArr = status
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 分享 account 优先用店铺 id,兜底当前页/本地 account,避免 undefined
|
|
|
+ const account =
|
|
|
+ shop.id ||
|
|
|
+ (this.option && this.option.account) ||
|
|
|
+ uni.getStorageSync('account') ||
|
|
|
+ ''
|
|
|
let shareParams = {
|
|
|
title: `点我付款`,
|
|
|
desc: '支持微信和支付宝',
|
|
|
imgUrl: '',
|
|
|
- pagePath: `/pages/pay/index?account=${res.shop.id}&store=0&fromType=3`
|
|
|
+ pagePath: `/pages/pay/index?account=${account}&store=0&fromType=3`
|
|
|
}
|
|
|
// #ifdef MP-WEIXIN
|
|
|
this.jweixinFn(shareParams)
|
|
|
// #endif
|
|
|
- console.log(`/pages/pay/index?account=${res.shop.id}&store=0&fromType=3`)
|
|
|
})
|
|
|
},
|
|
|
_pay() {
|
|
|
@@ -188,7 +221,8 @@
|
|
|
needSend: this.tabIndex == 0 ? '0' : '1',
|
|
|
prePrice: this.amount,
|
|
|
payWay: this.form.payWay,
|
|
|
- payPassword:this.modalForm.payPassword
|
|
|
+ payPassword:this.modalForm.payPassword,
|
|
|
+ ...this.buildScanSafeRequestContext()
|
|
|
}
|
|
|
if (this.tabIndex == 1) {
|
|
|
let deliveryForm = this.$refs.appDelivery.form ? this.$refs.appDelivery.form : {}
|