11
This commit is contained in:
parent
d64f67140c
commit
7483acfc1f
|
|
@ -75,8 +75,8 @@ export default {
|
|||
}
|
||||
},
|
||||
onLoad(e) {
|
||||
if (e.type) {
|
||||
this.type = e.type
|
||||
if (e.tyep) {
|
||||
this.type = e.tyep
|
||||
}
|
||||
if (e.redirectUrl) {
|
||||
this.redirectUrl = decodeURIComponent(e.redirectUrl)
|
||||
|
|
@ -92,7 +92,7 @@ export default {
|
|||
btnfh(){
|
||||
if(this.type == 99){
|
||||
uni.reLaunch({
|
||||
url:'/pages/my'
|
||||
url:'/pages/nearbystores/index'
|
||||
})
|
||||
}else{
|
||||
uni.navigateBack()
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@
|
|||
</view>
|
||||
<view class="" style="display: flex;padding:0 42rpx;margin-top: 40rpx;gap: 56rpx;">
|
||||
<image @click="btnkjpw" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/ukU5dVsJRl0LjuGvV0m8" mode=""></image> <!-- 卡劵配额 -->
|
||||
<image @click="btnyy" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/ukU5dVsJRl0LjuGvV0m8" mode=""></image> <!-- 语音同步 -->
|
||||
<image @click="btnyy" style="width: 112rpx;height: 122rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uJ7TUS8111sj8b2M6jcv" mode=""></image> <!-- 语音同步 -->
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
|
|
|||
|
|
@ -62,20 +62,69 @@ export default {
|
|||
this.useGiftCode(code)
|
||||
},
|
||||
|
||||
// 静默登录(仅用 wx.login 的 code 换 token,不弹授权)
|
||||
silentLogin() {
|
||||
return new Promise((resolve) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
if (!res.code) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
const data = { loginCode: res.code, appId: this.$store.state.appid }
|
||||
this.$u.post('/wxLogin', data).then((loginRes) => {
|
||||
if (loginRes.code === 200) {
|
||||
uni.setStorageSync('token', loginRes.token)
|
||||
resolve(true)
|
||||
} else {
|
||||
resolve(false)
|
||||
}
|
||||
}).catch(() => resolve(false))
|
||||
},
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
resolve(false)
|
||||
// #endif
|
||||
})
|
||||
},
|
||||
|
||||
// 跳转到登录页,登录成功后带参数回到本页重新领取
|
||||
goLoginWithRedirect(code) {
|
||||
const backUrl = '/page_user/yonghuewmlq?code=' + encodeURIComponent(code)
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login?redirect=' + encodeURIComponent(backUrl)
|
||||
})
|
||||
},
|
||||
|
||||
// 调用领取接口
|
||||
useGiftCode(code) {
|
||||
this.loading = true
|
||||
this.$u
|
||||
.post(`/app/vipUser/useGiftCode?code=${encodeURIComponent(code)}`)
|
||||
.then(res => {
|
||||
this.loading = false
|
||||
this.$u.post(`/app/vipUser/useGiftCode?code=${encodeURIComponent(code)}`).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.loading = false
|
||||
this.success = true
|
||||
this.message = res.msg || '领取成功,已发放至您的会员账户'
|
||||
} else {
|
||||
this.success = false
|
||||
this.message = res.msg || '领取失败,请稍后再试'
|
||||
return
|
||||
}
|
||||
if (res.code === 401) {
|
||||
// 先尝试静默登录,再决定是否跳登录页
|
||||
this.silentLogin().then((silentOk) => {
|
||||
if (silentOk) {
|
||||
// 静默登录成功,用新 token 再领一次
|
||||
this.useGiftCode(code)
|
||||
} else {
|
||||
this.loading = false
|
||||
this.goLoginWithRedirect(code)
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
this.loading = false
|
||||
this.success = false
|
||||
this.message = res.msg || '领取失败,请稍后再试'
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false
|
||||
|
|
|
|||
|
|
@ -219,7 +219,8 @@
|
|||
isindex:false,
|
||||
areaId:'16',
|
||||
appid:'',
|
||||
appimg:{}
|
||||
appimg:{},
|
||||
redirectUrl: '' // 登录成功后要跳回的目标页(如礼品码领取页)
|
||||
}
|
||||
},
|
||||
onLoad(e) {
|
||||
|
|
@ -234,6 +235,9 @@
|
|||
if(e.isindex=='true'){
|
||||
this.isindex=true
|
||||
}
|
||||
if (e.redirect) {
|
||||
this.redirectUrl = decodeURIComponent(e.redirect)
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
codeButtonStyle() {
|
||||
|
|
@ -625,7 +629,10 @@
|
|||
this.$u.get("/getInfo").then((res) => {
|
||||
console.log('进入跳转');
|
||||
uni.setStorageSync('user',res.user)
|
||||
if(this.isindex==true){
|
||||
if (this.redirectUrl) {
|
||||
const url = this.redirectUrl.startsWith('/') ? this.redirectUrl : '/' + this.redirectUrl
|
||||
uni.reLaunch({ url })
|
||||
} else if(this.isindex==true){
|
||||
uni.navigateBack({
|
||||
delta: 1 // delta值为1时表示返回的页面层数
|
||||
});
|
||||
|
|
|
|||
|
|
@ -128,7 +128,8 @@ export default {
|
|||
channelId: '',
|
||||
showBuy: false,
|
||||
selectedVip: {},
|
||||
paying: false
|
||||
paying: false,
|
||||
redirectVipId: '' // 从登录页带回的 vipId,用于自动重新发起购买
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
|
|
@ -138,6 +139,7 @@ export default {
|
|||
return
|
||||
}
|
||||
this.promotionId = String(id)
|
||||
if (option && option.vipId) this.redirectVipId = String(option.vipId)
|
||||
uni.setStorageSync('areaPromotionId', this.promotionId)
|
||||
this.getDetail()
|
||||
},
|
||||
|
|
@ -237,6 +239,17 @@ export default {
|
|||
''
|
||||
|
||||
if (this.areaId) this.getChannelId()
|
||||
|
||||
// 从登录页带回:自动打开该会员卡并重新发起购买
|
||||
if (this.redirectVipId) {
|
||||
const vip = this.vipList.find(v => String(v.id) === String(this.redirectVipId))
|
||||
const vid = this.redirectVipId
|
||||
this.redirectVipId = ''
|
||||
if (vip) {
|
||||
this.openBuy(vip)
|
||||
setTimeout(() => this.payNow(), 800)
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
this.loading = false
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
|
|
@ -285,6 +298,43 @@ export default {
|
|||
this.showBuy = false
|
||||
this.selectedVip = {}
|
||||
},
|
||||
// 静默登录(仅用 wx.login 的 code 换 token)
|
||||
silentLogin() {
|
||||
return new Promise((resolve) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
if (!res.code) {
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
const data = { loginCode: res.code, appId: this.$store.state.appid }
|
||||
this.$u.post('/wxLogin', data).then((loginRes) => {
|
||||
if (loginRes.code === 200) {
|
||||
uni.setStorageSync('token', loginRes.token)
|
||||
resolve(true)
|
||||
}else if(res.code == 401){
|
||||
resolve(false)
|
||||
} else {
|
||||
resolve(false)
|
||||
}
|
||||
}).catch(() => resolve(false))
|
||||
},
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
resolve(false)
|
||||
// #endif
|
||||
})
|
||||
},
|
||||
// 跳转登录页,登录成功后带参数回到本页重新购买
|
||||
goLoginWithRedirect() {
|
||||
const backUrl = '/pages/tuihuang?i=' + encodeURIComponent(this.promotionId) + '&vipId=' + encodeURIComponent(this.selectedVip.id)
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login?redirect=' + encodeURIComponent(backUrl)
|
||||
})
|
||||
},
|
||||
payNow() {
|
||||
if (this.paying) return
|
||||
if (!this.selectedVip || !this.selectedVip.id) {
|
||||
|
|
@ -314,14 +364,7 @@ export default {
|
|||
vip
|
||||
}
|
||||
|
||||
this.$u.post(`/app/vipOrder`, data).then(res => {
|
||||
if (res.code !== 200) {
|
||||
this.paying = false
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: res.msg || '下单失败', icon: 'none' ,duration:5000})
|
||||
return
|
||||
}
|
||||
// 需要拉起微信支付
|
||||
const doPayResult = (res) => {
|
||||
if (res.data && res.data.needPay) {
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
|
|
@ -349,12 +392,46 @@ export default {
|
|||
}
|
||||
})
|
||||
} else {
|
||||
// 无需支付(0元等场景)
|
||||
this.paying = false
|
||||
this.showBuy = false
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '购买成功', icon: 'success', duration: 2000 })
|
||||
}
|
||||
}
|
||||
|
||||
this.$u.post(`/app/vipOrder`, data).then(res => {
|
||||
if (res.code === 401) {
|
||||
this.silentLogin().then((silentOk) => {
|
||||
if (silentOk) {
|
||||
// 静默登录成功,用新 token 再请求一次并直接调起支付
|
||||
this.$u.post(`/app/vipOrder`, data).then(res2 => {
|
||||
if (res2.code !== 200) {
|
||||
this.paying = false
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: res2.msg || '下单失败', icon: 'none', duration: 5000 })
|
||||
return
|
||||
}
|
||||
doPayResult(res2)
|
||||
}).catch(() => {
|
||||
this.paying = false
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '网络错误', icon: 'none', duration: 5000 })
|
||||
})
|
||||
} else {
|
||||
this.paying = false
|
||||
uni.hideLoading()
|
||||
this.goLoginWithRedirect()
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
if (res.code !== 200) {
|
||||
this.paying = false
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: res.msg || '下单失败', icon: 'none' ,duration:5000})
|
||||
return
|
||||
}
|
||||
doPayResult(res)
|
||||
}).catch(() => {
|
||||
this.paying = false
|
||||
uni.hideLoading()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user