Explorar el Código

refactor:订单支付

zhanghui hace 2 años
padre
commit
dcad6c4298

+ 9 - 0
common/js/api.js

@@ -4,6 +4,15 @@ import request from '../js/request.js';
 export default {
 
 
+	//post请求  一键付款余额支付
+	scanCode(data){
+		return request({
+			url: '/member/wechat/scanCode?memberId=' + data.memberId + '&openId=' +data.openId,
+			method: 'POST',
+			data:data
+		})
+	},
+
 	//post请求  一键付款余额支付
 	trade(data){
 		return request({

+ 30 - 9
orderPages/bookService/index.vue

@@ -274,9 +274,11 @@ export default {
                         uni.showToast({
                             title: '支付成功!'
                         });
-                        uni.switchTab({
-                            url:'/pages/order/index'
-                        })
+                        setTimeout(res=>{
+                            uni.switchTab({
+                                url:'/pages/order/index'
+                            })
+                        },1000)
                     },
                     fail: res => {
                         console.log(res)
@@ -284,9 +286,13 @@ export default {
                             content: '支付失败',
                             showCancel: false
                         });
-                        uni.switchTab({
-                            url:'/pages/order/index'
-                        })
+
+                        setTimeout(res=>{
+                            uni.switchTab({
+                                url:'/pages/order/index'
+                            })
+                        },1000)
+
                     }
                 });
             }).catch(() =>{
@@ -312,14 +318,29 @@ export default {
                 orderNo: this.subOrderNo,
                 password: this.password
             }).then((res)=>{
-                uni.switchTab({
-                    url:'/pages/order/index'
-                })
+
+                uni.showToast({
+                    title: '支付成功!'
+                });
+
+                setTimeout(res=>{
+                    uni.switchTab({
+                        url:'/pages/order/index'
+                    })
+                },1000)
+
+
                 this.getUserInfo()
             }).catch(() =>{
                 uni.showToast({
                     title: "操作失败"
                 })
+
+                setTimeout(res=>{
+                    uni.switchTab({
+                        url:'/pages/order/index'
+                    })
+                },1000)
             });
 
         },

+ 19 - 1
pages/index/index.vue

@@ -263,11 +263,16 @@ export default {
       this.storeInfo = data;
     }
   },
-  onLoad() {
+  onLoad(e) {
+
     uni.hideTabBar({
       animation: false
     })
 
+    if (e.scene){
+      this.scanCode(e.scene)
+    }
+
     // 获取经纬度信息
     this.getLocation();
 
@@ -290,6 +295,19 @@ export default {
   onShareAppMessage(OBJECT) {
   },
   methods: {
+
+    scanCode(memberId){
+      setTimeout(res=>{
+        this.$api.scanCode({
+          openId:this.userInfo.otherId,
+          memberId:memberId
+        }).then(res=>{
+          console.log('++++++++++++++用户绑定结果+++++++++++++++',res)
+        })
+      },5000)
+
+    },
+
     // 去服务点单页面
     gotoServiceOrder() {
       uni.navigateTo({

+ 157 - 51
pages/order/index.vue

@@ -26,7 +26,7 @@
 			<swiper :style="{'height':windowHeight}" :current="tabIndex" @change="swiperChange">
 				<swiper-item class="swiperItem" v-for="(item,index) in tabList" :key="index">
 					<view>
-						<mescroll-item ref="MescrollItem" :i="index" :index="tabIndex" :tabs="tabList" :height="windowHeight" @openPay="openPay">
+						<mescroll-item ref="MescrollItem" :i="index" :index="tabIndex" :tabs="tabList" :height="windowHeight" @openPay="openPay" @openPayAppointment="openPayAppointment">
 						</mescroll-item>
 					</view>
 				</swiper-item>
@@ -181,7 +181,9 @@
 				userInfo:{},
 				curServiceTab:1,
 				tradeNo:'',
-				password:''
+				password:'',
+				openType:0,//开启的支付类型:1一键支付子订单费用,2:支付预约费用
+				appointmentOrder:{}
 
 			}
 		},
@@ -198,6 +200,8 @@
 		},
 
 		onShow(){
+			this.userInfo = uni.getStorageSync('userInfo')
+
 			if (uni.getStorageSync('orderListIndex')){
 				this.tabIndex = uni.getStorageSync('orderListIndex')
 			}
@@ -206,9 +210,58 @@
 
 		methods: {
 
-      getUserInfo() {
-        this.userInfo = uni.getStorageSync('userInfo');
-      },
+
+			openPayAppointment(order,number){
+				console.log(order)
+				console.log(number)
+				this.appointmentOrder = order
+				this.openType=number
+				this.$refs.popup.open()
+			},
+
+			//微信支付预约费用
+			wechatPay(){
+				let that = this;
+				// 发起微信支付
+				this.$api.wechatPay({
+					orderNo:this.appointmentOrder.subOrderNo
+				}).then((res)=>{
+					var param = res.data.data;
+					uni.requestPayment({
+						appId: param.appid,
+						timeStamp: param.timestamp+"",
+						nonceStr: param.noncestr,
+						package: "prepay_id="+param.prepayid,
+						signType: "RSA",
+						paySign: param.sign,
+						success: res => {
+							uni.showToast({
+								title: '支付成功!'
+							});
+							that.$refs.MescrollItem[that.tabIndex].downCallback()
+							that.getUserInfo()
+						},
+						fail: res => {
+							console.log(res)
+							uni.showToast({
+								title: '支付失败',
+								icon: 'error'
+							});
+							that.$refs.MescrollItem[that.tabIndex].downCallback()
+							that.getUserInfo()
+						}
+					});
+				}).catch(() =>{
+					uni.showToast({
+						title: "操作失败",
+						icon:'error'
+					})
+				});
+			},
+
+
+
+
 
 			balancePay(){
 
@@ -221,18 +274,49 @@
 				}
 				this.$refs.passwordPopup.close()
 				// 用户信息
-				this.$api.trade({
-					tradeNo: this.tradeNo,
-					password: this.password
-				}).then((res)=>{
-					uni.switchTab({
-						url:'/pages/order/index'
-					})
-				}).catch(() =>{
-					uni.showToast({
-						title: "操作失败"
-					})
-				});
+
+				if (this.openType == 2){
+					//支付预约费用
+					this.$api.balancePay({
+						orderNo: this.appointmentOrder.subOrderNo,
+						password: this.password
+					}).then((res)=>{
+						uni.showToast({
+							title: '支付成功'
+						})
+						that.$refs.MescrollItem[that.tabIndex].downCallback()
+						that.getUserInfo()
+						that.password = ''
+					}).catch((err) =>{
+						uni.showToast({
+							title: err.msg,
+							icon:'error'
+						})
+						that.password = ''
+					});
+
+				}else {
+					//支付子订单费用
+					this.$api.trade({
+						tradeNo: this.tradeNo,
+						password: this.password
+					}).then((res)=>{
+						uni.showToast({
+							title: '支付成功'
+						})
+						that.$refs.MescrollItem[that.tabIndex].downCallback()
+						that.getUserInfo()
+						that.password = ''
+					}).catch((err) =>{
+						uni.showToast({
+							title: err.msg,
+							icon:'error'
+						})
+						that.password = ''
+					});
+				}
+
+
 
 			},
 
@@ -247,58 +331,80 @@
 				this.$refs.popup.close()
 			},
 
-			openPay(order){
-        this.getUserInfo();
+
+			//一键支付子订单
+			openPay(order,number){
+				console.log(order)
+				console.log(number)
+				this.openType=number
 				this.$api.oneClickPay({
 					orderId:order.orderId
 				}).then(res=>{
 					this.tradeNo = res.data.data.tradeNo
 					this.$refs.popup.open()
 				})
-
-
 			},
 
 			commonGeneralOrder(){
 				let that =this
 				if (this.curServiceTab===1){
 					this.$refs.popup.close()
+					that.password = ''
 					this.$refs.passwordPopup.open()
 				}else {
-					this.$api.wechatPayTradeNo({tradeNo:this.tradeNo}).then(res=>{
-						var param = res.data.data;
-						uni.requestPayment({
-							appId: param.appid,
-							timeStamp: param.timestamp+"",
-							nonceStr: param.noncestr,
-							package: "prepay_id="+param.prepayid,
-							signType: "RSA",
-							paySign: param.sign,
-							success: res => {
-								uni.showToast({
-									title: '支付成功!'
-								});
-								that.$refs.popup.close()
-								that.$refs.MescrollItem[that.tabIndex].downCallback()
-							},
-							fail: res => {
-								console.log(res)
-								uni.showModal({
-									content: '支付失败',
-									showCancel: false
-								});
-								that.$refs.popup.close()
-								that.$refs.MescrollItem[that.tabIndex].downCallback()
-							}
+
+					if (this.openType == 2){
+						//支付预约费用
+						this.wechatPay()
+					}else{
+						//支付子订单费用
+						this.$api.wechatPayTradeNo({tradeNo:this.tradeNo}).then(res=>{
+							var param = res.data.data;
+							uni.requestPayment({
+								appId: param.appid,
+								timeStamp: param.timestamp+"",
+								nonceStr: param.noncestr,
+								package: "prepay_id="+param.prepayid,
+								signType: "RSA",
+								paySign: param.sign,
+								success: res => {
+									uni.showToast({
+										title: '支付成功!'
+									});
+									that.$refs.popup.close()
+									that.$refs.MescrollItem[that.tabIndex].downCallback()
+									that.getUserInfo()
+								},
+								fail: res => {
+									console.log(res)
+									uni.showToast({
+										title: '支付失败',
+										icon: 'error'
+									});
+									that.$refs.popup.close()
+									that.$refs.MescrollItem[that.tabIndex].downCallback()
+									that.getUserInfo()
+								}
+							});
+						}).catch(() =>{
+							uni.showToast({
+								title: "操作失败"
+							})
 						});
-					}).catch(() =>{
-						uni.showToast({
-							title: "操作失败"
-						})
-					});
+					}
+
+
 				}
 			},
 
+			getUserInfo() {
+				let that = this
+				this.$api.getUserInfo().then(function (res) {
+					that.userInfo = res.data.data
+					uni.setStorageSync('userInfo', res.data.data);
+				});
+			},
+
 			clickTab(e) {
 				this.tabIndex = e.index
 			},

+ 18 - 8
pages/order/module/mescrollUni-item.vue

@@ -121,21 +121,27 @@
 									</view>
 								</view>
 							</view>
+							<view class="price" v-if="item.serviceAttribute == 2">
+								预约金额:<text class="fontColor"> ¥{{ item.subAmount || 0}}</text>
+							</view>
 							<view class="price">
 								订单总金额:<text class="fontColor"> ¥{{ item.totalAmount || 0}}</text>
 							</view>
 						</view>
 						<view class="nav-bar">
-							<view class="btn" v-if="item.orderStatus != 2"  @click="scanCodeOrder(item)">
+							<view class="btn" v-if="item.orderStatus != 2 && item.orderStatus != 9"  @click="scanCodeOrder(item)">
 								<u-icon name="scan" size="18" />
 								<text>扫码</text>
 							</view>
 							<view class="btn" v-if="item.orderStatus == 6"  @click="oneClickPay(item)">
 								<text>一键付款</text>
 							</view>
-<!--							<view class="btn" v-else-if="item.orderStatus == 2">-->
-<!--								<text>已取消</text>-->
-<!--							</view>-->
+							<view class="btn" v-if="item.orderStatus == 5 || item.orderStatus == 11">
+								<text>取消</text>
+							</view>
+							<view @click="appointment(item)" class="btn" v-if="item.orderStatus == 9">
+								<text>去支付预约费用</text>
+							</view>
 <!--							<view @click="orderSign(item)" v-else-if="item.orderStatus == 4" class="btn">-->
 <!--								立即排队-->
 <!--								&lt;!&ndash; <text class="text1">点击开始排号</text> &ndash;&gt;-->
@@ -152,9 +158,7 @@
 <!--							<view @click="gotoEvaluate(item)" class="btn" v-else-if="item.orderStatus == 8">-->
 <!--								<text>待评价</text>-->
 <!--							</view>-->
-<!--							<view @click="gotoPayOrder(item)" class="btn" v-else-if="item.orderStatus == 9">-->
-<!--								<text>去支付预约费用</text>-->
-<!--							</view>-->
+
 						</view>
 					</view>
 				</view>
@@ -233,9 +237,15 @@
 		methods: {
 
 
+			appointment(order){
+				console.log('+++++++++++++++')
+				this.$emit('openPayAppointment',order,2)
+			},
+
+
 
 			oneClickPay(order){
-				this.$emit('openPay',order)
+				this.$emit('openPay',order,1)
 			},