# Conflicts:
#	pages/mine/coupon/my-coupon.vue
This commit is contained in:
PQZ 2025-04-24 18:51:54 +08:00
commit 88a583f2a8
4 changed files with 241 additions and 110 deletions

View File

@ -1,9 +1,9 @@
import request from '@/utils/request'
// 微信登录授权获取code
export function getCodeUrl(userType) {
export function getCodeUrl(userType, url) {
return request({
'url': '/wxApi/getCodeUrl?userType=' + userType,
'url': '/wxApi/getCodeUrl?userType=' + userType + '&url=' + url,
'method': 'get'
})
}

View File

@ -24,7 +24,16 @@
<text>¥</text>{{item.price}}
</view>
</view>
<!-- 购买 -->
<!-- #ifdef H5 -->
<view class="button-dom" @click="toOrder()">购买</view>
<!-- #endif -->
<!-- 调整h5 -->
<!-- #ifdef MP-WEIXIN -->
<view class="button-dom" @click="openVip()">购买</view>
<!-- #endif -->
</view>
<view class="item-field" style="align-items: center;">
<view class="my-suggest-dom" @click="viewRichText()">
@ -39,7 +48,8 @@
<view class="item-box" v-for="(item,index) in byList">
<view class="top-title-box">
<view class="order-no">订单编号{{item.orderNo}}</view>
<view :class="['order-status',item.isPay==1?'payed':'no-pay']">{{item.isPay==1?'已支付':'未支付'}}
<view :class="['order-status',item.isPay==1?'payed':'no-pay']">
{{item.isPay==1?'已支付':'未支付'}}
</view>
</view>
<view class="detail-item">
@ -66,11 +76,29 @@
<script>
import navigationBarVue from '@/components/navigation/navigationBar.vue';
import {initCouponList} from '@/api/business/base.js'
import {saveOrder,getOrderList,getMemberCoupon} from '@/api/business/member.js'
import {toast} from '@/utils/common.js'
import constant from '@/utils/constant';
import {getJSONData} from '@/utils/auth.js'
import {
initCouponList
} from '@/api/business/base.js'
import {
saveOrder,
getOrderList,
prepayment
} from '@/api/business/member.js'
import {
toast
} from '@/utils/common.js'
import constant from '@/utils/constant';
import {
getJSONData
} from '@/utils/auth.js'
import {
getCodeUrl,
getWebAccessTokenAndOpenid,
gzhLogin
} from '@/api/wxApi'
import {
getToken
} from '@/utils/auth'
export default {
components: {
navigationBarVue
@ -80,14 +108,14 @@
globalConfig: getApp().globalData.config,
menus: ['通告券', '购买记录'],
menuIndex: 0,
coupon:0,
coupon: 0,
//
couponIndex: 0,
queryParams: {
pageNum: 1,
pageSize: 10,
orderType:'02',
userId:null,
orderType: '02',
userId: null,
},
total: 0,
//
@ -98,21 +126,76 @@
}
},
onLoad(option) {
this.menuIndex = option.index
this.initCoupon();
this.initOrder()
this.menuIndex = option.index || 0
this.coupon = option.coupon || 0
this.initCoupon();
this.initOrder()
//urlsearch
if (location.search) {
let search = location.search.slice(1);
let arr = search.split("&");
let result = {};
arr.forEach(function(item) {
let itemArr = item.split('=');
result[itemArr[0]] = itemArr[1];
})
if (result.code) {
let that = this
getWebAccessTokenAndOpenid(result.code).then(res => {
that.$store.dispatch('GzhLogin', res).then(() => {
this.initCoupon();
this.initOrder()
that.loginSuccess()
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
})
} else {
this.toLogin()
}
}
},
onShow(){
this.initMyCoupon()
},
methods: {
openVip() {
//
wx.openOfficialAccountProfile({
username: 'tonggaokuaijie', //
success: res => {},
fail: res => {}
})
initMyCoupon(){
getMemberCoupon().then(res=>{
this.coupon = res.data
})
},
},
//
loginSuccess(result) {
//
this.$store.dispatch('GetInfo').then(res => {
})
},
toLogin() {
/*#ifdef APP-PLUS*/
// App
console.log('Running on App-Plus');
/*#endif*/
/*#ifdef H5*/
// H5
if (!getToken()) {
//
getCodeUrl("01", "pages/mine/coupon/my-coupon").then(res => {
window.location.href = res.codeUrl;
})
}
/*#endif*/
/*#ifdef MP-WEIXIN*/
//
console.log('Running on WeChat Mini Program');
/*#endif*/
},
/**
* 菜单点击
* @param {Object} index
@ -123,57 +206,64 @@
},
/**查询卡券*/
initCoupon(){
this.dataList = []
initCouponList().then(res=>{
this.dataList = res.data
})
},
/**查询卡券*/
initCoupon() {
if (getToken()) {
this.dataList = []
initCouponList().then(res => {
this.dataList = res.data
})
}
/**初始化订单数据*/
initOrder(){
this.queryParams.userId = getJSONData(constant.userInfo).userId
getOrderList(this.queryParams).then(res=>{
this.isTriggered = false
if (res.code == 200) {
if (this.queryParams.pageNum == 1) {
this.byList = res.data.records
} else {
this.byList = this.byList.concat(res.data.records)
}
this.total = res.data.total
}
})
},
},
/**生成订单*/
toOrder(){
let data = {
userType:'01',
orderType:'02',
goodsId:this.dataList[this.couponIndex].id,
goodsNum:this.dataList[this.couponIndex].couponNum,
goodsPrice:this.dataList[this.couponIndex].price,
goodsCycle:'04'
}
saveOrder(data).then(res => {
if (res.code == 200) {
uni.showToast({
icon: 'success',
duration: 2000,
title: '保存成功'
});
uni.navigateBack()
}
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
},
/**初始化订单数据*/
initOrder() {
if (getToken()) {
this.queryParams.userId = getJSONData(constant.userInfo).userId
getOrderList(this.queryParams).then(res => {
this.isTriggered = false
if (res.code == 200) {
if (this.queryParams.pageNum == 1) {
this.byList = res.data.records
} else {
this.byList = this.byList.concat(res.data.records)
}
this.total = res.data.total
}
})
}
},
/**生成订单*/
async toOrder() {
let data = {
userType: '01',
orderType: '02',
goodsId: this.dataList[this.couponIndex].id,
goodsNum: this.dataList[this.couponIndex].couponNum,
goodsPrice: this.dataList[this.couponIndex].price,
goodsCycle: '04'
}
let that = this
saveOrder(data).then(res => {
if (res.code == 200) {
//
let payData = {
orderNo: res.data.orderNo
}
prepayment(payData).then(paymentData => {
that.wxpay(paymentData)
})
}
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
},
/**
* 选中的优惠券
@ -202,7 +292,7 @@
}
//+1,
this.queryParams.pageNum++
this.initOrder()
this.initOrder()
},
/**
* 下拉刷新数据
@ -211,8 +301,58 @@
this.isTriggered = true
this.queryParams.pageNum = 1
this.total = 0
this.initOrder()
this.initOrder()
},
// WeixinJSBridge
wxpay(data) {
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
}
} else {
this.onBridgeReady(data);
}
},
onBridgeReady(data) {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
//
"appId": data.appId, //
"timeStamp": data.timeStamp, //
"nonceStr": data.nonceStr, //
"package": data.packageVal, //prepay_id
"signType": data.signType, //RSA
"paySign": data.paySign //
},
function(res) {
//
if (res.err_msg == "get_brand_wcpay_request:ok") {
// 使,
//res.err_msgok
}
//
if (res.err_msg == "get_brand_wcpay_request:cancel") {
}
//
if (res.err_msg == "get_brand_wcpay_request:fail") {
}
/**
* 其它
* 1请检查预支付会话标识prepay_id是否已失效
* 2请求的appid与下单接口的appid是否一致
* */
if (res.err_msg == "调用支付JSAPI缺少参数total_fee") {
}
});
}
}
}
</script>

View File

@ -182,37 +182,37 @@
},
onLoad(options) {
//urlsearch
let search = location.search.slice(1);
let arr = search.split("&");
let result = {};
arr.forEach(function(item) {
let itemArr = item.split('=');
result[itemArr[0]] = itemArr[1];
})
let userTypeTemp = options.userType
this.initData(userTypeTemp);
if (result.code) {
userTypeTemp = result.state
let that = this
getWebAccessTokenAndOpenid(result.code).then(res => {
that.$store.dispatch('GzhLogin', res).then(() => {
that.initData(userTypeTemp);
that.loginSuccess()
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
//urlsearch
if (location.search) {
let search = location.search.slice(1);
let arr = search.split("&");
let result = {};
arr.forEach(function(item) {
let itemArr = item.split('=');
result[itemArr[0]] = itemArr[1];
})
} else {
this.toLogin(userTypeTemp)
if (result.code) {
userTypeTemp = result.state
let that = this
getWebAccessTokenAndOpenid(result.code).then(res => {
that.$store.dispatch('GzhLogin', res).then(() => {
that.initData(userTypeTemp);
that.loginSuccess()
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
})
} else {
this.toLogin(userTypeTemp)
}
}
},
methods: {
openVip() {
@ -223,13 +223,6 @@
fail: res => {}
})
},
binderror() {
},
bindload() {
},
//
loginSuccess(result) {
@ -243,17 +236,15 @@
// App
console.log('Running on App-Plus');
/*#endif*/
/*#ifdef H5*/
// H5
if (!getToken()) {
//
getCodeUrl(userType).then(res => {
getCodeUrl(userType, "pages/mine/member/member-card").then(res => {
window.location.href = res.codeUrl;
})
}
/*#endif*/
/*#ifdef MP-WEIXIN*/
//
console.log('Running on WeChat Mini Program');

View File

@ -76,7 +76,7 @@
<!-- 发布通告 -->
<view class="public-notice-box" v-if="'01'==localUserType">
<view class="left-box">
<view style="margin-bottom: 20rpx;">发布通告额度剩余{{userInfo.coupon}}</view>
<view style="margin-bottom: 20rpx;">发布通告额度剩余{{userInfo.coupon||0}}</view>
<!-- <progress style="width: 90%;" border-radius="5" percent="40" activeColor="#FC1F3E"-->
<!-- backgroundColor="#DEDEDE" stroke-width="8" />-->
</view>