11
This commit is contained in:
parent
d64f67140c
commit
7483acfc1f
|
|
@ -75,8 +75,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
if (e.type) {
|
if (e.tyep) {
|
||||||
this.type = e.type
|
this.type = e.tyep
|
||||||
}
|
}
|
||||||
if (e.redirectUrl) {
|
if (e.redirectUrl) {
|
||||||
this.redirectUrl = decodeURIComponent(e.redirectUrl)
|
this.redirectUrl = decodeURIComponent(e.redirectUrl)
|
||||||
|
|
@ -92,7 +92,7 @@ export default {
|
||||||
btnfh(){
|
btnfh(){
|
||||||
if(this.type == 99){
|
if(this.type == 99){
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url:'/pages/my'
|
url:'/pages/nearbystores/index'
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
</view>
|
</view>
|
||||||
<view class="" style="display: flex;padding:0 42rpx;margin-top: 40rpx;gap: 56rpx;">
|
<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="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>
|
</view>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,20 +62,69 @@ export default {
|
||||||
this.useGiftCode(code)
|
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) {
|
useGiftCode(code) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.$u
|
this.$u.post(`/app/vipUser/useGiftCode?code=${encodeURIComponent(code)}`).then(res => {
|
||||||
.post(`/app/vipUser/useGiftCode?code=${encodeURIComponent(code)}`)
|
|
||||||
.then(res => {
|
|
||||||
this.loading = false
|
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
|
this.loading = false
|
||||||
this.success = true
|
this.success = true
|
||||||
this.message = res.msg || '领取成功,已发放至您的会员账户'
|
this.message = res.msg || '领取成功,已发放至您的会员账户'
|
||||||
} else {
|
return
|
||||||
this.success = false
|
|
||||||
this.message = res.msg || '领取失败,请稍后再试'
|
|
||||||
}
|
}
|
||||||
|
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(() => {
|
.catch(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,8 @@
|
||||||
isindex:false,
|
isindex:false,
|
||||||
areaId:'16',
|
areaId:'16',
|
||||||
appid:'',
|
appid:'',
|
||||||
appimg:{}
|
appimg:{},
|
||||||
|
redirectUrl: '' // 登录成功后要跳回的目标页(如礼品码领取页)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(e) {
|
onLoad(e) {
|
||||||
|
|
@ -234,6 +235,9 @@
|
||||||
if(e.isindex=='true'){
|
if(e.isindex=='true'){
|
||||||
this.isindex=true
|
this.isindex=true
|
||||||
}
|
}
|
||||||
|
if (e.redirect) {
|
||||||
|
this.redirectUrl = decodeURIComponent(e.redirect)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
codeButtonStyle() {
|
codeButtonStyle() {
|
||||||
|
|
@ -625,7 +629,10 @@
|
||||||
this.$u.get("/getInfo").then((res) => {
|
this.$u.get("/getInfo").then((res) => {
|
||||||
console.log('进入跳转');
|
console.log('进入跳转');
|
||||||
uni.setStorageSync('user',res.user)
|
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({
|
uni.navigateBack({
|
||||||
delta: 1 // delta值为1时表示返回的页面层数
|
delta: 1 // delta值为1时表示返回的页面层数
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,8 @@ export default {
|
||||||
channelId: '',
|
channelId: '',
|
||||||
showBuy: false,
|
showBuy: false,
|
||||||
selectedVip: {},
|
selectedVip: {},
|
||||||
paying: false
|
paying: false,
|
||||||
|
redirectVipId: '' // 从登录页带回的 vipId,用于自动重新发起购买
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
|
|
@ -138,6 +139,7 @@ export default {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.promotionId = String(id)
|
this.promotionId = String(id)
|
||||||
|
if (option && option.vipId) this.redirectVipId = String(option.vipId)
|
||||||
uni.setStorageSync('areaPromotionId', this.promotionId)
|
uni.setStorageSync('areaPromotionId', this.promotionId)
|
||||||
this.getDetail()
|
this.getDetail()
|
||||||
},
|
},
|
||||||
|
|
@ -237,6 +239,17 @@ export default {
|
||||||
''
|
''
|
||||||
|
|
||||||
if (this.areaId) this.getChannelId()
|
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(() => {
|
}).catch(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||||
|
|
@ -285,6 +298,43 @@ export default {
|
||||||
this.showBuy = false
|
this.showBuy = false
|
||||||
this.selectedVip = {}
|
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() {
|
payNow() {
|
||||||
if (this.paying) return
|
if (this.paying) return
|
||||||
if (!this.selectedVip || !this.selectedVip.id) {
|
if (!this.selectedVip || !this.selectedVip.id) {
|
||||||
|
|
@ -314,14 +364,7 @@ export default {
|
||||||
vip
|
vip
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$u.post(`/app/vipOrder`, data).then(res => {
|
const doPayResult = (res) => {
|
||||||
if (res.code !== 200) {
|
|
||||||
this.paying = false
|
|
||||||
uni.hideLoading()
|
|
||||||
uni.showToast({ title: res.msg || '下单失败', icon: 'none' ,duration:5000})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 需要拉起微信支付
|
|
||||||
if (res.data && res.data.needPay) {
|
if (res.data && res.data.needPay) {
|
||||||
uni.requestPayment({
|
uni.requestPayment({
|
||||||
provider: 'wxpay',
|
provider: 'wxpay',
|
||||||
|
|
@ -349,12 +392,46 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// 无需支付(0元等场景)
|
|
||||||
this.paying = false
|
this.paying = false
|
||||||
this.showBuy = false
|
this.showBuy = false
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
uni.showToast({ title: '购买成功', icon: 'success', duration: 2000 })
|
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(() => {
|
}).catch(() => {
|
||||||
this.paying = false
|
this.paying = false
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user