2 Commits 30077f9f73 ... 4ef7e4522a

Author SHA1 Message Date
  xuhaolan 4ef7e4522a Merge branch 'master' of http://git.liuniu946.com/xuhaolan/shuzi 2 years ago
  xuhaolan 7c628b16d8 静态页 2 years ago
2 changed files with 149 additions and 16 deletions
  1. 3 2
      pages/index/index.vue
  2. 146 14
      pages/product/product.vue

+ 3 - 2
pages/index/index.vue

@@ -60,7 +60,7 @@
 		
 		
 		<!-- 客服 -->
-		<uni-popup ref="popupkf" type="center">
+		<!-- <uni-popup ref="popupkf" type="center">
 			<view class="popup-box">
 				<view class="img"><image src="../../static/img/img009.png" mode=""></image></view>
 				<view class="mian">
@@ -75,7 +75,7 @@
 					</view>
 				</view>
 			</view>
-		</uni-popup>
+		</uni-popup> -->
 		
 	</view>
 </template>
@@ -132,6 +132,7 @@ export default {
 		loadIndex(){
 			let obj = this
 			loadIndexs().then(res=>{
+				console.log(res,'res');
 				obj.carouselList = res.data.banner
 				// console.log(res,'res');
 				// obj.list = res.data.info.fastList

+ 146 - 14
pages/product/product.vue

@@ -132,7 +132,7 @@
 								¥<span>{{shopDetail.price}}</span>
 							</view>
 						</view>
-						<view class="buy">
+						<view class="buy" @click="!payLoding ? pay() : ''" :class="{ clickbg: payLoding }">
 							立即支付
 						</view>
 					</view>
@@ -147,6 +147,9 @@
 
 <script>
 	// import uniPopup from '@/components/uni-popup/uni-popup.vue'
+	import {
+		balance
+	} from '@/api/wallet.js';
 	import {
 		mapState
 	} from 'vuex';
@@ -155,15 +158,18 @@
 		cartAdd
 	} from '@/api/product.js';
 	import {
-		confirm
+		confirm,
+		orderPay,
+		createOrderkey
 	} from '@/api/order.js'
 
 	export default {
 		data() {
 			return {
-				moneyAll: { //购物车金额详情
-					totalPrice: 0 //总金额	
-				},
+				orderId: '', //订单编号
+				moneyAll: '', //购物车订单
+				now_money: '', //余额
+				payLoding: false, //判断是否支付中
 				orderKey: '', //订单的key值
 				addressData: {}, //地址信息
 				shopList: [], //商品列表
@@ -178,12 +184,21 @@
 					// 'https://img.php.cn/upload/article/202104/15/2021041518005466284.jpg',
 					// 'https://img.php.cn/upload/article/202104/15/2021041518005466284.jpg',
 					// 'https://img.php.cn/upload/article/202104/15/2021041518005466284.jpg'
-				]
+				],
+				froms: '', //保存h5中数据来源对象
 			};
 		},
 		async onLoad(options) {
 			this.shopId = options.id
 			this.goodsDetail()
+			// 载入余额
+			balance({}).then(({
+				data
+			}) => {
+				// 获取余额
+				this.now_money = data.now_money;
+			});
+
 		},
 		computed: {
 			...mapState(['weichatObj', 'baseURL', 'urlFile'])
@@ -212,6 +227,8 @@
 				//点击购买之后自动生成订单
 				//如果订单生成没有付款,提示尚未付款,是否离开,确认离开,在我的订单里可看到尚未支付订单,点击付款,付款成功订单待发货,失败,尚未支付
 			},
+
+
 			getKeys() {
 				let obj = this
 				confirm({
@@ -220,22 +237,125 @@
 					console.log(data, '生平具体信息');
 					obj.addressData = data.data.addressInfo || {};
 					obj.shopList = data.data.cartInfo; //商品列表
-					obj.moneyAll = data.data.priceGroup; //金额数据
+					// obj.moneyAll = data.data.cartInfo.truePrice; //金额数据
 					obj.orderKey = data.data.orderKey; //订单key
-					let url = `/pages/money/pay?key=${obj.orderKey}`
-					console.log(url);
+					// let url = `/pages/money/pay?key=${obj.orderKey}`
+					// console.log(url);
 				})
 			},
 			//支付
-			pay() {
+			async pay() {
 				let obj = this
-				if (obj.type == 'weixin') {
-
+				// console.log('eeeeeeeeeeeeeee');
+				console.log(obj.type == 'yue', obj.now_money, obj.shopDetail.price);
+				if (obj.type == 'yue' && obj.now_money < obj.shopDetail.price) {
+
+					uni.showModal({
+						title: '提示',
+						content: '账户余额不足!',
+						showCancel: false,
+					});
+					return;
+				}
+				// uni.hideLoading()
+				uni.showLoading({
+					title: "支付中",
+					mask: true
+				})
+				obj.payLoding = true
+				if (obj.type != 1) {
+					// 初次生成订单
+					obj.firstCreateOrder();
+				} else {
+					// 已经生成订单未支付
+					obj.orderMoneyPay();
 				}
-				if (obj.type == 'yue') {
+			},
+			//非第一次支付订单
+			orderMoneyPay() {
+				let obj = this;
+				orderPay({
+					uni: obj.orderKey,
+					from: 'app', //来源
+					paytype: obj.type //支付类型  weixin-微信 yue-余额
+
+				}).then(res => {
+					console.log(res, '订单支付信息')
+					if (res.data.status == 'SUCCESS' && obj.type == 'yue') {
+						if (res.status == 200) {
+							obj.paySuccessTo()
+						} else {
+							obj.$api.msg(msg)
+							console.log('失败');
+						}
+					}
+					console.log('失败2');
+					uni.hideLoading();
+					obj.payLoding = false;
+
+				})
+			},
+			//首次创建订单
+			firstCreateOrder() {
+				let obj = this;
+				// 获取下单页面数据
+				// let prepage = obj.$api.prePage();
+				// console.log(prepage,'prepage');
+				let pages = getCurrentPages(); // 获取页面栈
+				let current = pages[pages.length - 1]; // 当前页面
+				console.log(current, 'current');
 
+				let data = {
+					real_name: '', //联系人名称
+					phone: '', //联系人号码
+					couponId: '', //优惠券编号
+					addressId: '', //支付地址id
+					useIntegral: 0, //是否积分抵扣1为是0为否
+					payType: obj.type, //支付类型  weixin-微信 yue-余额
+					mark: '', //备注
+					from: 'app', //来源
+					shipping_type: 1 //提货方式 1 快递 2自提
 				}
+				// 生成订单
+				createOrderkey(data, obj.orderKey)
+					.then(({
+						data,
+						status,
+						msg
+					}) => {
+						console.log(status);
+						// 判断是否支付失败
+						if (data.status == 'ORDER_EXIST') {
+							uni.showModal({
+								title: '提示',
+								content: msg,
+								showCancel: false
+							});
+							uni.hideLoading();
+							obj.payLoding = false;
+							return;
+						}
+						// 保存订单号
+						obj.orderId = data.result.orderId;
+						// 判断是否为余额支付
+						if (obj.type == 'yue') {
+							if (status == 200) {
+								obj.paySuccessTo();
+							} else {
+								obj.$api.msg(msg);
+							}
+						} else {
+							// 立即支付
+							obj.orderMoneyPay();
+						}
+					})
+					.catch(e => {
+						uni.hideLoading();
+						obj.payLoding = false;
+						console.log(e, '123456789');
+					});
 			},
+
 			goodsDetail() {
 				let obj = this
 				goodsDetail({}, obj.shopId).then(res => {
@@ -244,7 +364,14 @@
 					console.log(obj.shopDetail, obj.uniqueId, 'res1111');
 
 				})
-			}
+			},
+			// 支付成功跳转
+			paySuccessTo() {
+				uni.hideLoading();
+				uni.redirectTo({
+					url: '/pages/money/paySuccess?orderKey=' + this.orderKey
+				});
+			},
 		}
 	};
 </script>
@@ -532,7 +659,12 @@
 					text-align: center;
 					color: #FFFFFF;
 				}
+
 			}
 		}
 	}
+
+	.clickbg {
+		background-color: $color-gray !important;
+	}
 </style>