Ver Fonte

Signed-off-by: 1004749546@qq.com <1004749546@qq.com>
优惠券修改

1004749546@qq.com há 4 anos atrás
pai
commit
1122a7e850

+ 22 - 19
api/coupon.js

@@ -1,33 +1,36 @@
 import axios from '@/libs/axios.js';
 // 确认领取优惠券
 export const receivesCoupon = (params) => {
-  return axios.request({
-    url: `couponReceives/receivesCoupon/${params.couponCode}`,
-    method: 'get'
-  })
+	return axios.request({
+		url: `couponReceives/receivesCoupon/${params.couponCode}`,
+		method: 'get'
+	})
 }
 
 // 查询要领取的优惠券
 export const couponData = (params) => {
-  return axios.request({
-    url: `couponReceives/receivesCoupon/${params.couponCode}`,
-    method: 'get'
-  })
+	return axios.request({
+		url: `couponReceives/receivesCoupon/${params.couponCode}`,
+		method: 'get'
+	})
 }
 
 // 优惠券领取明细查询
 export const couponListFind = (params) => {
-  return axios.request({
-    url: `couponReceives/findPage`,
-    method: 'post',
-	data: params
-  })
+	let url = `couponReceives/findPage/${params.pageNo}/${params.pageSize}`
+	delete params.pageNo
+	delete params.pageSize
+	return axios.request({
+		url: url,
+		method: 'post',
+		data: params
+	})
 }
 // 订单可用优惠券查询
 export const couponEnable = (params) => {
-  return axios.request({
-    url: `couponReceives/findUsableCoupon`,
-    method: 'post',
-	data: params
-  })
-}
+	return axios.request({
+		url: 'couponReceives/findUsableCoupon',
+		method: 'post',
+		data: params
+	})
+}

+ 16 - 4
pages/coupon/chooseCoupon/chooseCoupon.vue

@@ -3,7 +3,7 @@
 		<couponTpl @checkOk="checkOk" :list="couponList" :showCheck="true"></couponTpl>
 		<view class="fix-button" v-if="curCoupon">
 			<view>
-				<view>优惠:¥9.8</view>
+				<view>优惠:¥{{curCoupon.couponAmount}}</view>
 				<view @click="comfirn">确认</view>
 			</view>
 		</view>
@@ -22,12 +22,24 @@
 				couponList:  []
 			};
 		},
-		onLoad(opt) {
-			this.couponList = JSON.parse(decodeURIComponent(opt.list)) 
+		onLoad(options) {
+			console.log(options,'options')
+			this.couponList = JSON.parse(decodeURIComponent(options.list)) 
+			this.curCoupon = JSON.parse(decodeURIComponent(options.curCoupon)) 
 		},
 		methods:{
 			checkOk(item){
-				this.curCoupon = item
+				this.couponList.map(list=>{
+					list.checked = (list.id === item.id && !list.checked) ? true : false
+				})
+				let has = this.couponList.find(item=> item.checked)
+				if (has) {
+					this.curCoupon = has
+				} else {
+					this.curCoupon = null
+				}
+				// 将用户选择优惠券传给下单页面
+				uni.$emit('couponChoose',{curCoupon:this.curCoupon})
 			},
 			// 确认按钮
 			comfirn(){

+ 2 - 7
pages/coupon/couponTpl.vue

@@ -12,8 +12,8 @@
 				</view>
 			</view>
 			<view class="coupon-desc">
-				<view><u-icon class="icon" size="30" name="clock"></u-icon> 有效期至:{{item.validDateStr}}</view>
-				<view><u-icon class="icon" size="30" name="info-circle"></u-icon>{{item.ruleDesc}}</view>
+				<view><u-icon class="icon" size="30" name="clock"></u-icon> 有效期至:{{item.validEndTime}}</view>
+				<view><u-icon class="icon" size="30" name="info-circle"></u-icon>{{item.couponRuleDesc}}</view>
 			</view>
 		</view>
 	</view>
@@ -38,11 +38,6 @@
 			// 选中优惠卷
 			checked(item) {
 				if(this.showCheck){
-					let has = this.list.find(item=>item.checked)
-					if(has){
-						has.checked = false
-					}
-					item.checked = true
 					this.$emit('checkOk',item)
 				}
 			},

+ 26 - 3
pages/coupon/index/index.vue

@@ -6,7 +6,7 @@
 		</view>
 		<swiper style="height: calc(100% - 40px);" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
 			<swiper-item class="swiper-item" v-for="(item, index) in tabsList" :key="index">
-				<scroll-view scroll-y style="height: 100%;width: 100%;">
+				<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
 					<couponTpl :list="couponList"></couponTpl>
 					<u-empty :text="noDataText" img-width="120" v-if="couponList.length==0 && status!='loading'" mode="list"></u-empty>
 					<view style="padding: 20upx;">
@@ -95,11 +95,15 @@
 			pageInit () {
 				this.current = 0 // tabs组件的current值,表示当前活动的tab选项
 				this.swiperCurrent = 0
+				this.count = 0
+				this.couponList = []
 				this.getList()
 			},
 			// tabs通知swiper切换
 			tabsChange(index) {
 				this.swiperCurrent = index;
+				this.couponList = []
+				this.count = 0
 				this.getList()
 			},
 			// swiper-item左右移动,通知tabs的滑块跟随移动
@@ -114,20 +118,39 @@
 				this.$refs.uTabs.setFinishCurrent(current);
 				this.swiperCurrent = current;
 				this.current = current;
+				this.couponList = []
+				this.count = 0
 				this.getList()
 			},
 			// 获取优惠卷列表
 			getList(){
 				this.status = 'loading'
 				let item = this.tabsList[this.swiperCurrent]
-				couponListFind({status:item.status}).then(res=>{
+				let params = {
+					pageNo: this.pageNo,
+					pageSize: this.pageSize,
+					status: item.status
+				}
+				couponListFind(params).then(res=>{
 					this.status = 'loadmore'
 					if (res.status == 200) {
-						this.couponList = res.data
+						let list = res.data.list
+						this.couponList = this.couponList.concat(list)
+						this.count = res.data.count
 					} else {
 						this.couponList = []
+						this.count = 0
 					}
 				})
+			},
+			// scroll-view到底部加载更多
+			onreachBottom() {
+				if (this.couponList.length<this.count) {
+					this.pageNo++
+					this.getList()
+				} else {
+					this.status = "nomore"
+				}
 			}
 		}
 	};

+ 32 - 43
pages/getOrder/getOrder.vue

@@ -48,9 +48,9 @@
 					<view class="choose-item">
 						<view class="item" @click="intoChooseCoupon">
 							<text>优惠卷</text>
-							<view v-if="checkedCoupon" class="right">
+							<view v-if="couponList.length" class="right">
 								<u-icon name="gift" color="rgb(255,0,0)" size="32"></u-icon>
-								<text class="coopon">9.8元洗车券(¥-9.8)</text>
+								<text class="coopon">{{checkedCoupon?(checkedCoupon.couponTitle+'(¥-'+checkedCoupon.couponAmount+')'):''}}</text>
 								<u-icon name="arrow-right" color="rgb(255,0,0)" size="32"></u-icon>
 							</view>
 							<view v-else class="right">
@@ -200,6 +200,8 @@
 			dataInit(){
 				// 监听点击已阅读事件
 				uni.$once('read', this.read)
+				// 监听用户选择的优惠券
+				uni.$on('couponChoose', this.couponChoose)
 				// 获取用户信息
 				this.getUserPhone()
 				// 获取服务项目
@@ -262,7 +264,8 @@
 					if (res.status == 200) {
 						this.itemList = res.data
 						this.serverIndex = 0
-						this.getFinalAmount()
+						// 获取用户可用优惠券
+						this.getCouponList()
 					} else {
 						this.itemList = []
 					}
@@ -271,7 +274,8 @@
 			// 选择服务项目
 			chooseItem(index) {
 				this.serverIndex = index
-				this.getFinalAmount()
+				// 获取用户可用优惠券
+				this.getCouponList()
 			},
 			// 下一步
 			nextStep() {
@@ -282,66 +286,51 @@
 			read(e) {
 				this.isRead = e.msg
 			},
+			// 获取用户选择的优惠券
+			couponChoose (e) {
+				this.checkedCoupon = e.curCoupon
+				// 计算合计
+				this.getFinalAmount()
+			},
 			// 获取用户可用优惠券
 			getCouponList() {
+				let item = this.itemList[this.serverIndex]
 				let params = {
-					consumAmount: this.amount, //订单金额
-					couponScopeList: [
-						{
-							
-						}
-					],
-					goodsType: 'ORDER'  // 	string消费商品类型 ORDER 工单/ORDER_BUNDLE套餐订单
+					consumAmount: item.currentPrice, //服务金额
+					itemId: item.itemId  // 服务id
 				}
+				uni.showLoading({
+					title: '正在查询可用优惠券...',
+					mask: true
+				})
 				couponEnable(params).then(res=> {
+					uni.hideLoading()
 					if (res.status == 200) {
 						this.couponList = res.data
+						this.checkedCoupon = this.couponList[0]
+						// 计算合计
+						this.getFinalAmount()
 					} else {
 						this.couponList = []
+						this.checkedCoupon = null
 					}
 				})
 			},
-			// 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
-			formatCouponData() {
-				let arr = []
-				let _this = this
-				this.couponList.map(item => {
-					let data = {}
-					data.id = item.couponReceivesId
-					if (item.couponType == 'DISCOUNT') {
-						console.log(_this.amount, '_this.amount')
-						data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
-					} else {
-						data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
-					}
-					arr.push(data)
-				})
-				console.log(arr, 'arr')
-				// 比较数据中优惠金额最大的值 并返回该对象
-				let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
-				console.log(obj)
-				let p = this.couponList.find(item => item.couponReceivesId == obj.id)
-				// 订单金额为0时,默认不使用优惠卷
-				if (this.amount != 0) {
-					this.checkedCoupon = p
-					this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
-				} else {
-					this.checkedCoupon = null
-					this.couponAmount = 0
-				}
-				// 计算合计
-				this.getFinalAmount()
-			},
+			
 			// 计算合计
 			getFinalAmount() {
 				this.amount = this.itemList[this.serverIndex].currentPrice
+				this.couponAmount = (this.checkedCoupon && this.checkedCoupon.couponAmount > this.amount) ? this.amount : (this.checkedCoupon ?this.checkedCoupon.couponAmount : 0)
 				let ret = this.amount - this.couponAmount
 				this.finalAmount = ret.toFixed(2)
 			},
 			// 选择优惠券
 			intoChooseCoupon() {
+				this.couponList.map((item)=> {
+					item.checked = (this.checkedCoupon && item.id == this.checkedCoupon.id) ? true : false
+				})
 				uni.navigateTo({
-					url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
+					url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}&curCoupon=${encodeURIComponent(JSON.stringify(this.checkedCoupon))}`
 				})
 			},
 			// 打开服务协议