瀏覽代碼

commit -m 优惠券

zhengjinyi 3 年之前
父節點
當前提交
068fed6f5f

+ 56 - 46
components/cm-module/cart-components/index.vue

@@ -700,7 +700,15 @@
 				this.allPrice = totalPrice ;
 				// 计算优惠券
 				if(this.totalCouponList.length>0){
-					this.calculationCoupon()
+					let eligibleCoupons = this.calculationCoupon()
+					console.log('eligibleCoupons',eligibleCoupons)
+					if(eligibleCoupons.length>0){
+						this.eligibleCoupons.splice(0,this.eligibleCoupons.length);
+						this.eligibleCoupons.push(eligibleCoupons[0])
+						this.couponPrice = this.eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount)[0].couponAmount
+					}else{
+						this.couponPrice = 0
+					}
 				}
 				// 最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
 				this.totalDiscountAmount = this.reducedPrice + this.couponPrice;
@@ -728,62 +736,64 @@
 			    })
 			},		 
 			calculationCoupon(){// 优惠券计算
-				const eligibleCoupons = [];
-				this.goodsList.forEach((shop,index)=>{
-					shop.cartList.forEach(pros=>{	
+				let eligibleCoupons = []
+				this.goodsList.forEach(shop=>{ 
+					shop.cartList.forEach(pros=>{
 						if(pros.productsChecked){		
-							this.totalCouponList.map((coupon,index)=>{//循环优惠券
-								const couponType = coupon.couponType;
-								if(couponType == 0){// 活动券
-									if(coupon.productType == 1){// 活动券-全商城商品
-										if(this.allPrice>=coupon.touchPrice){
-											eligibleCoupons.push(coupon)
-											eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
+							this.totalCouponList.forEach(coupon=>{//循环优惠券
+								switch(coupon.couponType){
+									case 0:// 活动券
+										if(coupon.productType == 1){// 活动券-全商城商品
+											if(this.allPrice >= coupon.touchPrice){
+												eligibleCoupons = this.setCouponsArr(coupon)
+											}
+										}else if(coupon.productType == 2){// 活动券-指定商品
+											if(coupon.productIds && coupon.productIds.includes(pros.productId)){
+												if(this.allPrice >= coupon.touchPrice){
+													eligibleCoupons = this.setCouponsArr(coupon)
+												}
+											}
 										}
-									}else if(coupon.productType == 2){// 活动券-指定商品
-										if(coupon.productIds && coupon.productIds.includes(pros.productId)){
-											if(this.allPrice>=coupon.touchPrice){
-												eligibleCoupons.push(coupon)
-												eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
+										break;
+									case 1:// 品类券适用于产品或者仪器 categoryType(commodityType) : 1 产品  2 仪器 
+										if( coupon.categoryType && coupon.categoryType == pros.commodityType){
+											if(this.allPrice >= coupon.touchPrice){
+												eligibleCoupons = this.setCouponsArr(coupon)
 											}
-										}else{
-											return false
 										}
-									}
-								// 品类券适用于产品或者仪器,购买产品类或仪器类的商品,商品金额达到优惠标准即可使用优惠券	
-								}else if(couponType == 1){// 品类券 categoryType(commodityType) : 1 产品  2 仪器 
-									if( coupon.categoryType && coupon.categoryType == pros.commodityType){
-										if(this.allPrice>=coupon.touchPrice){
-											eligibleCoupons.push(coupon)
-											eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
+										break;
+									case 2:// 用户专享券 适用于商城全部商品
+										if(this.allPrice >= coupon.touchPrice){
+											eligibleCoupons = this.setCouponsArr(coupon)
 										}
-									}
-								// 适用于商城全部商品
-								}else if(couponType == 2 || couponType == 4){// 用户专享券和新用户券
-									if(this.allPrice>=coupon.touchPrice){
-										eligibleCoupons.push(coupon)
-										eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
-									}
-								// 店铺券适用于某个供应商的全部商品	
-								}else if(couponType == 3){// 店铺券 supplierId
-									if(coupon.shopId && pros.supplierId == coupon.shopId){
-										if(this.allPrice>=coupon.touchPrice){
-											eligibleCoupons.push(coupon)
-											eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
+										break;
+									case 3:// 店铺券适用于某个供应商的全部商品	
+										if(coupon.shopId && pros.supplierId == coupon.shopId){
+											if(this.allPrice >= coupon.touchPrice){
+												eligibleCoupons = this.setCouponsArr(coupon)
+											}
 										}
-									}
+										break;		
+									case 4://新用户券 适用于商城全部商品
+										if(this.allPrice >= coupon.touchPrice){
+											eligibleCoupons = this.setCouponsArr(coupon)
+										}
+										break;
 								}
-							})
+							})  
+						}else{
+							console.log('没有选择商品')
+							return;
 						}	
 					})
 				})
-				if(eligibleCoupons.length>0){
-					this.eligibleCoupons.push(eligibleCoupons[0])
-					this.couponPrice = this.eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount)[0].couponAmount
-				}
+				return eligibleCoupons;
 			},
-			checkenTotalPrice(){
-				
+			setCouponsArr(coupon){//处理
+				const list = []
+				list.push(coupon)
+				list.sort((a,b)=> b.couponAmount - a.couponAmount )
+				return list
 			},
 			changeCountAdd(item,pros){//商品数量加加
 				if(pros.step === 2){

+ 10 - 6
components/cm-module/homeIndex/pageFloor.vue

@@ -1,6 +1,6 @@
 <template>
 	<view>
-		<view class="page-content clearfix" v-for="(page, index) in pageFloorList" :key="index">
+		<view class="page-content clearfix" v-for="(page, index) in list" :key="index">
 			<view class="tui-group-name" v-if="page.floorContent">
 				<view class="tui-group-title">
 					<view class="tui-group-l">{{ page.title }}</view>
@@ -81,13 +81,17 @@ export default {
 		}
 	},
 	created() {
-		this.initData(this.list)
+		
+	},
+	watch: {
+		list: {
+			handler: function (el) {//监听对象的变换使用 function,箭头函数容易出现this指向不正确
+				this.list = el
+			},
+			deep: true
+		}
 	},
-	computed: {},
 	methods: {
-		initData(data) {
-			this.pageFloorList = data
-		},
 		NavToDetailPage(page) {
 			//跳转
 			this.$api.navigateTo(

+ 1 - 1
pages/seller/order/create-order.vue

@@ -111,7 +111,7 @@
 								<text v-if="ExchangeCouponData.couponType == 3">仅限购买店铺【{{ ExchangeCouponData.shopName }}】的商品</text>
 								<text v-if="ExchangeCouponData.couponType == 4 || ExchangeCouponData.couponType == 2">全商城商品通用</text>
 							</view>
-							<view class="list-cell-time">有效期:{{ ExchangeCouponData.startDate  }} - {{ ExchangeCouponData.endDate }}</view>
+							<view class="list-cell-time">{{ ExchangeCouponData.startDate  }} - {{ ExchangeCouponData.endDate }}</view>
 						</view>
 					</view>
 					<view class="coupon-btn" @click.stop="handleClickCancel">立即收下</view>

+ 4 - 11
pages/tabBar/home/index.vue

@@ -9,7 +9,7 @@
 			<!-- 金刚区菜单 -->
 			<navbars :list="navBarsList" v-if="isNavRequest"></navbars>
 			<!-- 优惠券入口 -->
-			<coupon v-if="isNavRequest"></coupon>
+			<coupon v-if="isNavRequest && couponEntry == 1"></coupon>
 			<!-- 直播 -->
 			<page-special :templateData="templateData" v-if="isLiveRequest"></page-special>
 		</view>	
@@ -85,6 +85,7 @@
 				isActivityBean:false,
 				beansType:1,
 				beanNumber:50,
+				couponEntry:2,
 			}
 		},
 		onLoad() {
@@ -137,6 +138,7 @@
 				this.CommonService.GetHomeInit({source:2}).then(response =>{
 					let data = response.data
 					this.navBarsList = data.topMenuList
+					this.couponEntry = data.couponEntry
 					this.isNavRequest = true
 				}).catch(error =>{
 					this.$util.msg(error.msg,2000)
@@ -207,15 +209,6 @@
 			},
 			handleBeanlClick(){
 				this.isActivityBean = false
-			},
-			InitAuthorize(){ //是否已授权 
-				this.GetWxAuthorize()
-				this.$api.getComStorage('userInfo').then((resolve) =>{
-					this.userID = resolve.userId ? resolve.userId :0;
-					this.getHomeInformation()
-				}).catch(error =>{
-					this.getHomeInformation()
-				})
 			}
 		},
 		onPageScroll(e){//实时获取到滚动的值
@@ -246,7 +239,7 @@
 		},
 		onShow(){
 			this.modallayer = false
-			this.InitAuthorize()
+			this.GetWxAuthorize()
 		}
 	}
 </script>

+ 13 - 13
pages/user/order/create-order.vue

@@ -98,7 +98,7 @@
 								<text v-if="ExchangeCouponData.couponType == 3">仅限购买店铺【{{ ExchangeCouponData.shopName }}】的商品</text>
 								<text v-if="ExchangeCouponData.couponType == 4 || ExchangeCouponData.couponType == 2">全商城商品通用</text>
 							</view>
-							<view class="list-cell-time">有效期:{{ ExchangeCouponData.startDate }} - {{ ExchangeCouponData.endDate }}</view>
+							<view class="list-cell-time">{{ ExchangeCouponData.startDate }} - {{ ExchangeCouponData.endDate }}</view>
 						</view>
 					</view>
 					<view class="coupon-btn" @click.stop="handleClickCancel">立即收下</view>
@@ -363,8 +363,8 @@
 						}
 						this.balanceDeductionFlag = 2
 					}
-					console.log('this.payAllPrice',this.payAllPrice)
-					console.log('this.couponAmount',this.couponAmount)
+					console.log('最终订单支付金额',this.payAllPrice)
+					console.log('优惠券金额',this.couponAmount)
 				}else{
 					return
 				}
@@ -380,7 +380,7 @@
 				if(this.ischecked){
 					if(this.userMoney>=this.payAllPrice){
 						this.payAllPrice = 0.00
-						this.deductMoney = this.allPrice							// 当前使用金额等于订单金额
+						this.deductMoney = this.allPrice - this.couponAmount 		// 当前使用金额等于订单金额
 						this.surplusMoney = this.userMoney - this.deductMoney	    // 剩余金额等于余额-当前使用金额
 					}else{
 						this.payAllPrice = this.allPrice - this.userMoney - this.couponAmount       	// 订单最终支付金额等于订单金额-账户余额
@@ -392,28 +392,28 @@
 					this.deductMoney = 0.00; // 当前使用
 					this.surplusMoney = this.userMoney; // 剩余余额
 				}
-				console.log('this.payAllPrice',this.payAllPrice)
-				console.log('this.couponAmount',this.couponAmount)
+				console.log('最终订单支付金额',this.payAllPrice)
+				console.log('优惠券金额',this.couponAmount)
 			},
 			attributeHashfreight(freight){// 计算需要邮费的支付价格
-				this.payAllPrice = this.allPrice+parseInt(freight)// 计算不包邮的价格 总价等于商品价格+邮费
+				this.payAllPrice = this.allPrice - this.couponAmount + parseInt(freight) // 计算不包邮的价格 总价等于商品价格+邮费
 				if(this.ischecked){
 					if(this.userMoney>=this.payAllPrice){// 全部抵扣
 						this.payAllPrice =0.00
 						if(this.isCheckedBeans){// 抵扣运费了
-							this.deductMoney = this.allPrice								// 当前使用金额等于订单金额
+							this.deductMoney =  this.allPrice - this.couponAmount			// 当前使用金额等于订单金额
 							this.surplusMoney = this.userMoney - this.deductMoney	    	// 剩余金额等于余额减去当前使用金额
 						}else{
-							this.deductMoney = this.allPrice + parseInt(freight)			// 当前使用金额等于订单金额+运费金额
+							this.deductMoney = this.allPrice + parseInt(freight)- this.couponAmount	// 当前使用金额等于订单金额+运费金额
 							this.surplusMoney = this.userMoney - this.deductMoney	    	// 剩余余额等于总余额-当前使用金额
 						}
 					}else{// 部分抵扣
 						if(this.isCheckedBeans){// 抵扣运费了
-							this.payAllPrice = this.allPrice - this.userMoney - this.couponAmount // 订单最终支付金额等于订单金额+运费-账户余额
+							this.payAllPrice = this.allPrice - this.userMoney - this.couponAmount // 订单最终支付金额等于订单金额-账户余额-优惠券金额
 							this.deductMoney = this.userMoney				            		// 当前使用金额等于账户余额
 							this.surplusMoney = this.userMoney - this.deductMoney	    		// 剩余余额等于账户余额-当前使用金额
 						}else{
-							this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney - this.couponAmount // 订单最终支付金额等于订单金额+运费-账户余额
+							this.payAllPrice = this.allPrice + parseInt(freight) - this.userMoney - this.couponAmount//订单支付金额等于订单金额+运费-账户余额-优惠券
 							this.deductMoney = this.userMoney				            		// 当前使用金额等于账户余额
 							this.surplusMoney = this.userMoney - this.deductMoney	    		// 剩余余额等于账户余额-当前使用金额
 						}
@@ -423,8 +423,8 @@
 					this.deductMoney = 0.00 // 当前使用金额
 					this.surplusMoney = this.userMoney // 剩余余额
 				}
-				console.log('this.payAllPrice',this.payAllPrice)
-				console.log('this.couponAmount',this.couponAmount)
+				console.log('最终订单支付金额',this.payAllPrice)
+				console.log('优惠券金额',this.couponAmount)
 			},
 			orderSubmitMit(){// 提交订单
 				if(this.isSubLoading){ return; }