This commit is contained in:
吴鹏 2026-03-16 10:03:51 +08:00
parent d64f67140c
commit 7483acfc1f
5 changed files with 156 additions and 23 deletions

View File

@ -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()

View File

@ -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>

View File

@ -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

View File

@ -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 // delta1
});

View File

@ -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()