Bladeren bron

Merge branch 'develop' of http://git.chelingzhu.com/chelingzhu-web/zxyj-mini-html into develop

chenrui 4 jaren geleden
bovenliggende
commit
c9b7564e02

+ 22 - 3
components/uni-coods/uni-coods.vue

@@ -54,11 +54,30 @@
 			}
 		},
 		methods: {
+			// 判断当前商品库存是否够
+			hasZgKucun(data){
+				let list = this.$store.state.vuex_cartList
+				let row = list.find(item=> item.goodsTypeNo == data.goodsTypeNo)
+				if(row){
+					let good = row.shoppingCartGoodsList.find(item => item.goodsNo == data.goodsNo)
+					return !good ? true : good.buyQty < data.inventoryQty
+				}else{
+					return true
+				}
+			},
 			// 加入购物车
 			addCart(item) {
-				this.$bindClick(function(){
-					uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
-				})
+				console.log(item)
+				if(this.hasZgKucun(item)){
+					this.$bindClick(function(){
+						uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:1})
+					})
+				}else{
+					uni.showToast({
+						icon: 'none',
+						title: '此商品库存不足'
+					})
+				}
 			},
 			// 商品详情
 			toDetail(item){

+ 3 - 2
components/uni-numbers-box/uni-numbers-box.vue

@@ -50,7 +50,7 @@
 			},
 			inputValue(newVal, oldVal) {
 				console.log(newVal,oldVal,this.index,'111')
-				if (+newVal !== +oldVal) {
+				if (+newVal !== +oldVal && this.max >= +newVal && this.min <= +newVal) {
 					this.$emit("change", newVal, this.index);
 				}
 			}
@@ -126,7 +126,7 @@
 		display: flex;
 		/* #endif */
 		flex-direction: row;
-		width: 100px;
+		width: 120px;
 	}
 
 	.uni-numbox__value {
@@ -136,6 +136,7 @@
 		line-height: $box-height;
 		text-align: center;
 		font-size: $uni-font-size-lg;
+		margin: 0 10px;
 	}
 
 	.uni-numbox__minus {

+ 51 - 19
pages/cart/cart.vue

@@ -56,12 +56,14 @@
 										<image mode="scaleToFill" style="width: 30rpx;height: 30rpx;"src="/static/ledou.png"></image>
 									</view>
 									<view v-if="good.goods.inventoryQty>0&&good.goods.state==1">
-										<uni-numbers-box @change="goodsNumsChange()" :index="cindex+'-'+index" :value="good.buyQty" :min="1"></uni-numbers-box>
+										<uni-numbers-box @change="goodsNumsChange()" :index="cindex+'-'+index" :value="good.buyQty" :max="good.goods.inventoryQty" :min="1"></uni-numbers-box>
 									</view>
 									<view v-else>
 										<view style="width: 100rpx;text-align: center;">×{{good.buyQty}}</view>
 									</view>
 								</view>
+								<view class="goods-kucun" v-if="good.goods.state == 1&&good.goods.inventoryQty==0">库存不足</view>
+								<view class="goods-kucun" v-else>库存:<text>{{good.goods.inventoryQty}}</text></view>
 							</view>
 						</view>
 					</view>
@@ -102,6 +104,13 @@
 				<u-button size="mini" :custom-style="toOrderButton" type="error" @click="delGoods">删除</u-button>
 			</view>
 		</view>
+		<!-- 弹框提示 -->
+		<u-popup v-model="showMsg" border-radius="15" closeable mode="center" width="500rpx">
+			<view style="padding: 40rpx;line-height: 40rpx;font-size: 28rpx;">
+				<view style="text-align: center;font-size: 32rpx;margin-bottom: 20rpx;">提示</view>
+				<view v-for="item in msgContent" :key="item.id">{{item.message}}</view>
+			</view>
+		</u-popup>
 	</view>
 </template>
 <script>
@@ -117,7 +126,9 @@
 				checkAll: false,// 全选
 				isEdit: false, // 是否编辑模式
 				cartList: [], // 商品列表
-				loading: false
+				loading: false,
+				showMsg: false,
+				msgContent: []
 			};
 		},
 		computed: {
@@ -193,22 +204,11 @@
 				})
 				return goods
 			},
-			// 判断当前分类下的商品总和是否满足规则
-			hasZgjindu(item){
-				let ret = 0
-				let goldLimit = item.goldLimit
-				item.shoppingCartGoodsList.map(good=>{
-					ret = ret + good.goods.sellGold * good.buyQty
-				})
-				console.log(ret , goldLimit)
-				return !this.isEdit ? ret >= goldLimit : true
-			},
 			// 设置每个分类下的商品选中状态
 			setClsGoodStatus(item,checked){
-				console.log(checked)
 				item.shoppingCartGoodsList.map(good=>{
 					// 已下架,已删除,已销完的不选
-					if((good.goods.inventoryQty==0||good.goods.state == 0||good.goods.delFlage == 0) && !this.isEdit){
+					if((good.goods.inventoryQty==0||good.goods.state == 0) && !this.isEdit){
 						good.checked = false
 					}else{
 						good.checked = checked
@@ -287,15 +287,40 @@
 				this.checkAll = true
 				this.checkAllChange()
 			},
+			// 判断当前分类下的商品总和是否满足规则
+			hasZgjindu(){
+				let result = []
+				let list = this.cartList.filter(item=>item.total>0)
+				for(let i=0;i<list.length;i++){
+					let item = list[i]
+					let ret = 0
+					item.shoppingCartGoodsList.map(good=>{
+						if(good.checked){
+							ret = ret + good.goods.sellGold * good.buyQty
+						}
+					})
+					result.push({id:item.goodsTypeNo,val:ret >= item.goldLimit,message:`[${item.name}]的商品合计满${item.goldLimit}乐豆才可购买`})
+				}
+				
+				console.log(result.filter(item=>!item.val))
+				return result.filter(item=>!item.val)
+			},
 			// 立即下单
 			toOrder(){
 				let goods = this.getCheckGoods(1)
 				if(this.userData.currentGold >= this.totalPrice){
 					if(goods.length){
-						this.$u.vuex("vuex_toOrderList",goods)
-						uni.redirectTo({
-							url:"/pages/toOrder/index"
-						})
+						// 判断是否满足规则
+						let a = this.hasZgjindu()
+						if(a.length==0){
+							this.$u.vuex("vuex_toOrderList",goods)
+							uni.redirectTo({
+								url:"/pages/toOrder/index"
+							})
+						}else{
+							this.showMsg = true
+							this.msgContent = a
+						}
 					}else{
 						uni.showToast({
 							title:"请选择商品",
@@ -460,11 +485,18 @@ page{
 					}
 				}
 			}
+			.goods-kucun{
+				padding-top: 10rpx;
+				font-size: 22rpx;
+				text{
+					color: #999;
+				}
+			}
 			.goods-price{
 				display: flex;
 				align-items: center;
 				justify-content: space-between;
-				padding-top: 20upx;
+				padding-top: 10upx;
 				>view{
 					&:first-child{
 						font-size: 22upx;

+ 4 - 2
pages/index/index.vue

@@ -214,8 +214,9 @@
 						})
 						// 刷新购物车
 						this.getCartList()
+					}else{
+						uni.hideLoading()
 					}
-					uni.hideLoading()
 				})
 			},
 			// 删除购物车
@@ -232,8 +233,9 @@
 						})
 						// 刷新购物车
 						this.getCartList()
+					}else{
+						uni.hideLoading()
 					}
-					uni.hideLoading()
 				})
 			},
 			// 更新商品数量

+ 14 - 3
pages/order/order.vue

@@ -98,7 +98,7 @@
 		@cancel="payAgain"
 		></u-modal>
 		<!-- 确认支付弹窗 -->
-		 <u-popup mode="center" closeable @close="showLeavePsw=true" v-model="showInputPsw" width="500rpx" >
+		 <u-popup mode="center" closeable @close="closePayModal" v-model="showInputPsw" width="500rpx" >
 			<view class="slot-content">
 				<view>确认支付</view>
 				<view class="text-cont">
@@ -181,6 +181,7 @@
 				showSetPswModal: false,  // 设置支付密码弹窗
 				showInputPsw: false, // 打开输入密码弹窗
 				showLeavePsw: false, // 打开确定放弃弹窗
+				payFinish: false  // 是否支付成功
 			}
 		},
 		onLoad() {
@@ -312,6 +313,12 @@
 					this.showInputPsw = true
 				}
 			},
+			// 关闭输入密码弹窗
+			closePayModal(){
+				if(!this.payFinish) {
+					this.showLeavePsw = true
+				} 
+			},
 			//确认放弃
 			canclePay() {
 				this.password = ''
@@ -327,6 +334,7 @@
 			toPay(item) {
 				this.orderId = item.id
 				this.totalPrice = item.originalGold
+				this.payFinish = false
 				// 判断用户是否设置过支付密码
 				existPayPwd().then(res=>{
 					console.log(res,'rrrrrr')
@@ -362,13 +370,16 @@
 				signPay(params).then(res=>{
 					this.btnLoading = false
 					if(res.status == 200) {
-						this.showLeavePsw = false
+						// 关闭弹窗 刷新列表
+						this.payFinish = true
+						this.showInputPsw = false
+						this.getRow()
 						setTimeout(()=>{
 							// 跳转到支付完成界面
 							uni.navigateTo({
 								url:"/pages/toOrder/payFinish?id=" + this.orderId
 							})
-						},300)
+						},500)
 						
 					} else{
 						this.password = ''

+ 15 - 2
pages/order/orderDetail.vue

@@ -93,7 +93,7 @@
 		@cancel="payAgain"
 		></u-modal>
 		<!-- 确认支付弹窗 -->
-		 <u-popup mode="center" closeable @close="showLeavePsw=true" v-model="showInputPsw" width="500rpx" >
+		 <u-popup mode="center" closeable @close="closePayModal" v-model="showInputPsw" width="500rpx" >
 			<view class="slot-content">
 				<view>确认支付</view>
 				<view class="text-cont">
@@ -134,7 +134,8 @@
 				showInputPsw: false, // 打开输入密码弹窗
 				showLeavePsw: false, // 打开确定放弃弹窗
 				orderId: '', // 订单id
-				leftTime: null
+				leftTime: null,
+				payFinish: false  // 是否支付成功
 			}
 		},
 		onLoad(options) {
@@ -194,6 +195,12 @@
 					this.showInputPsw = true
 				}
 			},
+			// 关闭输入密码弹窗
+			closePayModal(){
+				if(!this.payFinish) {
+					this.showLeavePsw = true
+				} 
+			},
 			//确认放弃
 			canclePay() {
 				this.password = ''
@@ -208,6 +215,7 @@
 			// 支付 判断用户是否设置过支付密码
 			toPay() {
 				this.totalPrice = this.orderInfo.originalGold
+				this.payFinish = false
 				// 判断用户是否设置过支付密码
 				existPayPwd().then(res=>{
 					console.log(res,'rrrrrr')
@@ -244,6 +252,11 @@
 				signPay(params).then(res=>{
 					this.btnLoading = false
 					if(res.status == 200) {
+						// 关闭弹窗 刷新页面
+						this.payFinish = true
+						this.showInputPsw = false
+						this.getOrderDetail()
+						// 刷新订单列表
 						uni.$emit('refresh')
 						// 跳转到支付完成界面
 						uni.navigateTo({