Parcourir la source

支付时新增优惠券使用流程

DELL il y a 3 ans
Parent
commit
b894eecf84

+ 3 - 8
components/pay-popup/pay-popup.vue

@@ -17,7 +17,8 @@
 						<view class="txt">优惠券</view>
 					</view>
 					<view class="flex coupon-right">
-						<view class="txt">{{}}</view>
+						<view class="txt" v-if="payInfo.couponTitle">{{ payInfo.couponTitle }}</view>
+						<view class="txt" v-else>暂无可用优惠券</view>
 						<u-icon name="arrow-right" size="16" color="#333"></u-icon>
 					</view>
 				</view>
@@ -61,10 +62,6 @@
 		data() {
 			return {
 				checked: false,
-				couponIds: [],
-				autoCoupon: 1,
-
-				couponTitle: '',
 			};
 		},
 
@@ -74,10 +71,8 @@
 			},
 
 			toCoupon() {
-				// return
-				console.log(this.payInfo+"11111111111111111111")
 				uni.navigateTo({
-					url: '/pages/coupon/index'
+					url: `/pages/coupon/index?couponId=${ this.payInfo.couponId }&boxId=${ this.payInfo.boxId }`
 				})
 			},
 

+ 54 - 19
pages/coupon/index.vue

@@ -1,23 +1,24 @@
 <template>
 	<view>
-		<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择优惠券" ></u-navbar>
+		<u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择优惠券"></u-navbar>
 		<view class="coupon-title">可用优惠券:{{listNum}}</view>
 		<view class="coupon-list">
-			<u-radio-group v-model="radiovalue1" placement="column">
+			<u-radio-group v-model="radiovalue1" placement="column" @change="changeChechk()">
 				<view class="flex coupon-list-item" v-for="(item,index) in list" :key="index">
 					<view class="flex coupon-list-item-info">
 						<view class="money">
-							<view class="">¥<text>{{item.discount}}</text></view>
+							<view class="">¥<text>{{ item.discount / 100 }}</text></view>
 						</view>
 						<view class="flex content">
-							<view class="txt title">{{item.title}}</view>
+							<view class="txt title">{{ item.title }}</view>
 							<view class="txt">
 								使用期限:{{ $parseTime(item.validStart, '{y}.{m}.{d}')}}-{{$parseTime(item.validEnd, '{y}.{m}.{d}')}}
 							</view>
-							<view class="txt">适用范围:{{item.useAreaDesc || '-'}}</view>
+							<view class="txt">适用范围:{{ item.useAreaDesc || '-' }}</view>
 						</view>
 					</view>
-					<u-radio :customStyle="{marginBottom: '8px'}" :name="index"> </u-radio>
+					<u-radio :customStyle="{ marginBottom: '8px' }" :name="item.id" activeColor="#E96737" size="24">
+					</u-radio>
 				</view>
 			</u-radio-group>
 		</view>
@@ -45,15 +46,28 @@
 				pageNum: 1,
 				total: 0,
 				list: [],
-
-				listNum: '',//可用优惠券数量
-				radiovalue1: 0, //被选中的下标
+				listNum: '', //可用优惠券数量
+				radiovalue1: '', //选中项的下标
+				couponId: '', //选中项的id
+				boxId: '',
 			};
 		},
 		onShow() {
-			this.getList()
+			this.pageList()
+		},
+		onLoad(opthios) {
+			this.boxId = opthios.boxId
+			if (opthios.couponId) {
+				this.couponId = opthios.couponId
+				this.radiovalue1 = opthios.couponId
+			}
 		},
 		methods: {
+			pageList() {
+				this.list = []
+				this.getList()
+			},
+
 			getList() {
 				uni.showLoading({
 					title: '加载中'
@@ -61,30 +75,51 @@
 				$http.post('/api/v1/mp/user/ticket/order/coupon/list', {}).then(
 					res => {
 						uni.hideLoading();
-						console.log(res)
 						if (res.code == 0) {
 							this.listNum = res.data.length
 							res.data.forEach(item => {
 								let useAreaDesc = JSON.parse(item.useArea)
 								item.useAreaDesc = useAreaDesc.desc
 							})
-							this.list = this.list.concat(res.data)
-							console.log(this.list)
+							this.list = res.data
 						}
+
 					}).catch(() => {
 					uni.hideLoading();
 				})
 			},
 
+			// 点击切换事件
+			changeChechk(e) {
+				this.couponId = e
+			},
+
 			// 点击确认事件
 			exchange() {
-				for (var i = 0; i < this.list.length; i++) {
-					if(i == this.radiovalue1){
-						console.log(this.list[i])
-						uni.navigateBack({data:this.list[i]})
-					}
+				let data = {
+					userCouponIds: [this.couponId],
+					autoCoupon: 0,
+					boxId: this.boxId,
+					orderNum: 1
 				}
-				
+				$http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
+					if (res.code == 0) {
+						let pages = getCurrentPages()
+						let page = pages[pages.length - 2]
+						let payInfo = {
+							...res.data,
+							picUrl: env.filePublic + res.data.picUrl,
+							couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
+								.data.couponList[0].title,
+							couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
+								.couponList[0].id
+						}
+						page.$vm.payInfo = payInfo
+						uni.navigateBack({
+							delta: 1
+						})
+					}
+				})
 			}
 		}
 	}

+ 7 - 2
pages/index/index.vue

@@ -121,6 +121,7 @@
 		},
 		onShow(opthios) {
 			this.loginState = uni.getStorageSync('token') ? true : false
+			if (this.payShow) return
 			this.getList()
 			this.getPrizeNews()
 		},
@@ -201,7 +202,7 @@
 			payment() {
 				this.payInfo = this.ticketList[this.currentIndex]
 				let data = {
-					couponIds: [],
+					userCouponIds: [],
 					autoCoupon: 1,
 					boxId: this.payInfo.boxId,
 					orderNum: 1
@@ -210,7 +211,11 @@
 					if (res.code == 0) {
 						let info = {
 							...res.data,
-							...this.payInfo
+							...this.payInfo,
+							couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
+								.data.couponList[0].title,
+							couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
+								.couponList[0].id
 						}
 						this.payInfo = info
 						this.payShow = true

+ 12 - 5
pages/lucky/index.vue

@@ -3,7 +3,8 @@
 		<u-navbar leftIconSize="0" title="盲票详情" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
 		<view class="detail">
 			<view class="detail-top">
-				<u-swiper :list="picUrlArr" height="375" imgMode="aspectFit" bgColor="#fff" radius="0" :indicator="true" :circular="true"></u-swiper>
+				<u-swiper :list="picUrlArr" height="375" imgMode="aspectFit" bgColor="#fff" radius="0" :indicator="true"
+					:circular="true"></u-swiper>
 			</view>
 			<view class="flex detail-info">
 				<view class="detail-info__left">
@@ -153,13 +154,13 @@
 						_this.serialNo = url.substring(url.length - 21, url.length)
 						_this.getDetail()
 					},
-					fail(){
+					fail() {
 						uni.$u.toast('请扫二维码');
 					}
 				});
 			},
-			
-			
+
+
 			getDetail() {
 				uni.showLoading({
 					title: '加载中'
@@ -293,7 +294,9 @@
 			pay() {
 				let data = {
 					ticketId: this.info.ticketId,
-					autoCoupon: 1
+					autoCoupon: 1,
+					userCouponIds: [],
+					orderNum: 1
 				}
 				this.payLookFlag = false
 				uni.showLoading({
@@ -306,6 +309,10 @@
 							...res.data,
 							...this.info,
 							picUrl: env.filePublic + res.data.picUrl,
+							couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
+								.data.couponList[0].title,
+							couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
+								.couponList[0].id
 						}
 						this.payInfo = info
 						this.payShow = true

+ 17 - 12
pages/ticketBox/detail.vue

@@ -14,7 +14,8 @@
 
 		<view class="detail">
 			<view class="detail-top">
-				<u-swiper :list="picUrlArr" height="375" imgMode="aspectFit" bgColor="#fff" radius="0" :indicator="true" :circular="true"></u-swiper>
+				<u-swiper :list="picUrlArr" height="375" imgMode="aspectFit" bgColor="#fff" radius="0" :indicator="true"
+					:circular="true"></u-swiper>
 			</view>
 			<view class="flex detail-info">
 				<view class="detail-info__left">
@@ -35,7 +36,8 @@
 				<view class="detail-goods-list">
 					<!-- <navigator :url="`/pages/prizeGoods/detail?id=${ item.prizeId }`" class="detail-goods-list-item"
 						hover-class="navigator-hover" v-for="(item, index) in prizeList" :key="index"> -->
-					<view class="detail-goods-list-item" v-for="(item, index) in prizeList" :key="index" @click="toPrizeGoods(item)">
+					<view class="detail-goods-list-item" v-for="(item, index) in prizeList" :key="index"
+						@click="toPrizeGoods(item)">
 						<view class="detail-goods-list-item__value">
 							<view class="flex image-wrap">
 								<image :src="item.picUrl" mode="scaleToFill"></image>
@@ -102,12 +104,12 @@
 			if (opthios.boxId) {
 				this.boxId = opthios.boxId
 			}
-			
-			if(opthios.userId){
+
+			if (opthios.userId) {
 				uni.setStorageSync('shareUid', opthios.userId)
 			}
-			
-			if(opthios.type){
+
+			if (opthios.type) {
 				uni.setStorageSync('shareType', opthios.type)
 			}
 		},
@@ -164,10 +166,9 @@
 
 			exchange() {
 				let data = {
-					couponIds: [],
+					userCouponIds: [],
 					autoCoupon: 1,
 					boxId: this.info.boxId,
-					ticketId: this.info.ticketId,
 					orderNum: 1
 				}
 				$http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
@@ -176,6 +177,10 @@
 							...res.data,
 							...this.info,
 							picUrl: env.filePublic + res.data.picUrl,
+							couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
+								.data.couponList[0].title,
+							couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
+								.couponList[0].id
 						}
 						this.payInfo = info
 						this.payShow = true
@@ -200,11 +205,11 @@
 					url: '/pages/index/index'
 				})
 			},
-			
-			toPrizeGoods(item){
-				if(item.prizeType == "goods"){
+
+			toPrizeGoods(item) {
+				if (item.prizeType == "goods") {
 					uni.navigateTo({
-						url:`/pages/prizeGoods/detail?id=${ item.refId }`
+						url: `/pages/prizeGoods/detail?id=${ item.refId }`
 					})
 				}
 			}

+ 2 - 2
pages/ticketBox/index.vue

@@ -121,8 +121,8 @@
 				background: none;
 			}
 		}
-		
-		.empty{
+
+		.empty {
 			height: 60vh;
 		}
 	}