Просмотр исходного кода

对接投票现金支付(未完成)

lyb 4 лет назад
Родитель
Сommit
9d944da251
4 измененных файлов с 99 добавлено и 28 удалено
  1. 5 0
      assets/http/api.js
  2. 20 10
      components/alert/votePopup.vue
  3. 39 17
      pages/activity/activityDetail.vue
  4. 35 1
      utils/jweixin.js

+ 5 - 0
assets/http/api.js

@@ -227,6 +227,11 @@ const order = {
 			'Content-Type': 'application/x-www-form-urlencoded'
 		}
 	}),
+	cashExchange: p => http.post('/app/help/goods/createCashPropsOrder', p, {
+		header: {
+			'Content-Type': 'application/x-www-form-urlencoded'
+		}
+	}),
 }
 
 /**

+ 20 - 10
components/alert/votePopup.vue

@@ -21,17 +21,19 @@
 				</scroll-view>
 
 				<view class="handle-bar">
-					<view v-if="pointNum>=0" class="text-center padding-bottom-20" style="color: #0A9FEF;">您目前的移动积分:
-						{{pointNum}}
-					</view>
-					<view v-else class="text-center padding-bottom-20" style="color: #0A9FEF;">您目前的移动积分 <u-loading
-							style="margin: 10rpx;" mode="circle"></u-loading>
-					</view>
+					<block v-if="voteText === '移动积分'">
+						<view v-if="pointNum>=0" class="text-center padding-bottom-20" style="color: #0A9FEF;">您目前的移动积分:
+							{{pointNum}}
+						</view>
+						<view v-else class="text-center padding-bottom-20" style="color: #0A9FEF;">您目前的移动积分 <u-loading
+								style="margin: 10rpx;" mode="circle"></u-loading>
+						</view>
+					</block>
 					<view class="button-bar">
 						<view class="button-r">
-							<u-count-to v-if="show" color="#E72226" start-val="0" :end-val="gitfs[selected].point"
-								:duration="500"></u-count-to>
-							<span class="info">移动积分</span>
+							<u-count-to v-if="show" :color="vuex_theme.bgColor" start-val="0" :end-val="voteText === '元' ? gitfs[selected].amount : gitfs[selected].point"
+								:duration="500" :decimals="voteText === '元' ? 2 : 0"></u-count-to>
+							<span class="info">{{voteText}}</span>
 						</view>
 						<view class="button-f" @click="toVote">点击投票</view>
 					</view>
@@ -71,6 +73,14 @@
 					}
 					return ''
 				}
+			},
+			voteText: {
+				get() {
+					if(this.gitfs[this.selected] && this.gitfs[this.selected].payType === 'CASH_EXCHANGE_GOODS'){
+						return "元"
+					}
+					return "移动积分"
+				}
 			}
 		},
 		methods: {
@@ -153,7 +163,7 @@
 			toVote() {
 				let item = this.gitfs[this.selected]
 
-				if (this.pointNum == 0 && item.point != 0) {
+				if (this.pointNum == 0 && item.point != 0 && this.gitfs[this.selected].payType == 'POINT_EXCHANGE_GOODS') {
 					this.$u.toast('您无可用移动积分')
 					return
 				}

+ 39 - 17
pages/activity/activityDetail.vue

@@ -336,24 +336,29 @@
 					this.$cache.put('orderResult', this.orderResult, 1 * 60 * 60)
 				}
 				this.selectGoods = item
-				if (item.point == 0) {
-					//免费投票
-					this.freeVote()
-					return
-				}
-				this.$refs.votePopup.hideVote()
-				//移动积分投票,创建订单
-				if (this.$cache.get('orderResult')) {
-					this.createOrder()
-					return
-				}
-				// #ifdef MP-WEIXIN
-				let params = {
-					url: 'https://vote.guosen-fumao.cn/order.html',
-					goodsId: this.selectGoods.id
+				//移动积分礼物
+				if(item.payType === 'POINT_EXCHANGE_GOODS'){
+					if (item.point == 0 ) {
+						//免费投票
+						this.freeVote()
+						return
+					}
+					this.$refs.votePopup.hideVote()
+					//移动积分投票,创建订单
+					if (this.$cache.get('orderResult')) {
+						this.createOrder()
+						return
+					}
+					// #ifdef MP-WEIXIN
+					let params = {
+						url: 'https://vote.guosen-fumao.cn/order.html',
+						goodsId: this.selectGoods.id
+					}
+					this.$jump('/pages/webview/createOrder' + this.$u.queryParams(params))
+					// #endif
+				}else{
+					this.cashCreateOrder();
 				}
-				this.$jump('/pages/webview/createOrder' + this.$u.queryParams(params))
-				// #endif
 			},
 			//移动积分创建订单
 			async createOrder() {
@@ -381,6 +386,23 @@
 					this.$refs.toast.error(res.data.msg)
 				}
 			},
+			//现金投票创建订单
+			async cashCreateOrder() {
+				let params = {
+					helpGoodsId: this.orderResult.goodsId,
+					num: 1,
+					phone: this.vuex_phone,
+					productId: this.id,
+					userId: this.vuex_userId
+				}
+				let res = await this.$api.order.cashExchange(params)
+				if (res.data.success) {
+					console.log("res", res);
+				} else {
+					this.$refs.toast.error(res.data.msg)
+				}
+				this.$refs.votePopup.hideVote();
+			},
 			async cmccVote(item) {
 				this.$refs.smsAlert.hideSms()
 				let params = {

+ 35 - 1
utils/jweixin.js

@@ -3,7 +3,7 @@ import {api} from "../assets/http/api.js"
 let jweixin = require('jweixin-module');
 let url = encodeURIComponent(window.location.href.split('#')[0])
 /**
- * JS-SDK
+ * JS-SDK 卡片分享
  */
 wx.H5Share = async (shareParam) => {
 	let shareData=(await api.wxApp.getWxShareData({url})).data.data
@@ -49,4 +49,38 @@ wx.H5Share = async (shareParam) => {
 	})		
 }
 
+/**
+ * JS-SDK 支付
+ */
+wx.H5Pay = async (payParam) => {
+	let configData = (await api.wxApp.getWxShareData({url})).data.data;
+	//通过微信config接口注入配置
+	jweixin.config({
+		debug: false, //调试模式
+		appId: configData.appId, //必填,公众号的唯一标识
+		timestamp: configData.timestamp, //必填,生成签名的时间戳
+		nonceStr: configData.nonceStr, //必填,生成签名的随机串
+		signature: configData.signature, //必填,签名
+		jsApiList: ['chooseWXPay'] //必填,需要使用的JS接口列表
+	})
+	jweixin.ready(function() {
+		return new Promise((resolve, reject) => {
+			jweixin.chooseWXPay({
+				timestamp: 0, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
+				nonceStr: '', // 支付签名随机串,不长于 32 位
+				package: '', // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
+				signType: '', // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
+				paySign: '', // 支付签名
+			    success: function (res) {
+				  // 支付成功后的回调函数
+				  resolve(res)
+			    },
+				fail: function(err) {
+					reject(err)
+				}
+			});
+		})
+	})	
+}
+
 export default wx