Jelajahi Sumber

【Add】优惠券去使用功能

liuxiangxin 6 bulan lalu
induk
melakukan
e7a70898be
3 mengubah file dengan 274 tambahan dan 22 penghapusan
  1. 7 0
      pages.json
  2. 71 22
      pages/coupon/index.vue
  3. 196 0
      pages/coupon/product.vue

+ 7 - 0
pages.json

@@ -139,6 +139,13 @@
 			{
 				"navigationBarTitleText" : "添加客服"
 			}
+		},
+		{
+			"path" : "pages/coupon/product",
+			"style" : 
+			{
+				"navigationBarTitleText" : "可用商品"
+			}
 		}
 	],
 	"globalStyle": {

+ 71 - 22
pages/coupon/index.vue

@@ -7,7 +7,7 @@
 		</view> -->
 		<view class="to_bottom" v-if="!couponList.length"> -----还没有优惠券啦-----</view>
 		<view class="coupon_list">
-			<view class="coupon_item" v-for="(item,index) in couponList" :key="index">
+			<view class="coupon_item" v-for="(item,index) in couponList" :key="index" @click="toUse(item)">
 				<view class="box_left">
 					<view class="rebate" v-if="item.rebate_type == 1" > ¥{{item.rebate}}</view>
 					<view class="rebate" v-if="item.rebate_type == 2" > 打 {{item.rebate}} 折</view>
@@ -28,12 +28,17 @@
 						<view class="coupon_status" v-if="item.status == 3">已过期</view>
 						<view class="coupon_status" v-if="item.status == 4">已作废</view>
 					</view>
-					<view class="product_scope">
-						<text class="" v-if="item.type_id == 1">限定商品可用</text>
-						<text class="" v-if="item.type_id == 2">全场可用</text>
+					<view class="coupon_box">
+						<view class="product_scope">
+							<text class="" v-if="item.type_id == 1">限定商品可用</text>
+							<text class="" v-if="item.type_id == 2">全场可用</text>
+						</view>
+						<view class="coupon_info">
+							<view class="coupon_exp">{{item.exp_time}} 到期</view>
+						</view>
 					</view>
-					<view class="coupon_info">
-						<view class="coupon_exp">{{item.exp_time}} 到期</view>
+					<view class="to_use" v-if="item.status == 0">
+						<view class="use_btn" >去使用</view>
 					</view>
 				</view>
 			</view>
@@ -144,6 +149,27 @@
 			});
 		},
 		methods:{
+			toUse(item){
+				// 没有范围
+				if( item.type_id == 2 ){
+					uni.switchTab({url:"/pages/index/index"});
+					return;
+				}
+				// 只有一个商品,直接跳转到对应商品
+				if( item.product_scope.length == 1 ){
+					uni.navigateTo({
+						url:"/pages/product/index?product_id="+item.product_scope[0]
+					})
+					return;
+				}
+				// 没有范围
+				if( item.product_scope.length > 1 ){
+					uni.navigateTo({
+						url:"/pages/coupon/product?coupon_id="+item.coupon_id
+					});
+					return;
+				}
+			}
 		}
 	}
 </script>
@@ -201,6 +227,7 @@
 				width: 485rpx;
 				margin-left: 35rpx;
 				padding-top: 20rpx;
+				overflow: hidden;
 				.coupon_title{
 					width: 485rpx;
 					max-height: 80rpx;
@@ -214,30 +241,52 @@
 						width: 380rpx;
 					}
 					.coupon_status{
-						width: 85rpx;
+						width: 100rpx;
 						float: right;
 						color: #999999;
 						font-size: 24rpx;
+						text-align: center;
 					}
 				}
-				.product_scope{
-					width: 485rpx;
-					height: 80rpx;
-					color: #999999;
-					font-size: 24rpx;
+				.coupon_box{
+					float: left;
+					width: 365rpx;
 					overflow: hidden;
-					line-height: 80rpx;
+					.product_scope{
+						width: 365rpx;
+						height: 80rpx;
+						color: #999999;
+						font-size: 24rpx;
+						overflow: hidden;
+						line-height: 80rpx;
+					}
+					.coupon_info{
+						width: 365rpx;
+						max-height: 80rpx;
+						font-size: 30rpx;
+						overflow: hidden;
+						line-height: 40rpx;
+						padding: 0rpx 0rpx;
+						.coupon_exp{
+							float: left;
+							font-size: 20rpx;
+						}
+					}
 				}
-				.coupon_info{
-					width: 485rpx;
-					max-height: 80rpx;
-					font-size: 30rpx;
+				.to_use{
+					float: right;
+					width: 100rpx;
+					margin-top: 75rpx;
 					overflow: hidden;
-					line-height: 40rpx;
-					padding: 0rpx 0rpx;
-					.coupon_exp{
-						float: left;
-						font-size: 20rpx;
+					.use_btn{
+						color: #FFFFFF;
+						width: 100rpx;
+						height: 40rpx;
+						font-size: 24rpx;
+						line-height: 40rpx;
+						text-align: center;
+						border-radius: 20rpx;
+						background-color: #F59A23;
 					}
 				}
 			}

+ 196 - 0
pages/coupon/product.vue

@@ -0,0 +1,196 @@
+<template>
+	<view>
+		<view class="product_box">
+			<view class="to_bottom" v-if="!productList.length"> -----还没有产品啦-----</view>
+			<!-- 产品列表 -->
+			<view class="product_list" >
+				<!-- Vue3 项目部分小程序端事件延迟或调用失败 在执行事件的元素上添加 data-eventsync="true" 属性以解决此问题 -->
+				<view @click="toDetail(item)" data-eventsync="true" class="product_item" v-for="(item,index) in productList" :key="index" >
+					<image class="product_image" :src="item.thumb" mode=""></image>
+					<view class="product_name"><text>{{item.name}}</text></view>
+					<view class="product_spec"><text>{{item.spec}}</text></view>
+					<view class="stock_price">
+						<view class="product_price" >
+							<text >¥{{item.price}} </text>
+						</view>
+						<view class="product_stock">剩{{item.stock}}个</view>
+					</view>
+				</view>
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				// 产品列表
+				productList:[],
+				// 请求参数
+				requestParam:{
+					coupon_id:0,
+					name:"",
+					page:1,
+				},
+				// 是否最后一页
+				isLast:false,
+				// 是否请求中
+				isReqing:false,
+			}
+		},
+		onLoad(param) {
+			this.requestParam.coupon_id = param.coupon_id;
+		},
+		onShow() {
+			// 没有数据的话,或者请求中,不允许刷新
+			if( this.isReqing )		return ;
+			// 请求参数
+			this.requestParam.name	= "";
+			// 请求参数
+			this.requestParam.page	= 1;
+			// 是否是最后一页
+			this.isLast			 	= false;
+			// 设置请求中
+			this.isReqing			= true;
+			// 请求
+			this.$http.request('api/coupon/get_product',this.requestParam).then((re)=>{
+				// 设置非请求中
+				this.isReqing		= false;
+				// 成功结果
+				if( re.code == 'success' ){
+					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
+					this.productList = re.data.data;
+				}
+			});
+		},
+		onPullDownRefresh() {
+			// 如果请求中,不允许请求,
+			if( this.isReqing )		return false;
+			// 初始化页码为1
+			this.requestParam.page	= 1;
+			// 是否是最后一页
+			this.isLast			 	= false;
+			// 设置请求中
+			this.isReqing			= true;
+			// 请求列表
+			this.$http.request('/api/coupon/get_product',this.requestParam).then((re)=>{
+				// 设置非请求中
+				this.isReqing		= false;
+				// 成功结果
+				if( re.code == 'success' ){
+					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
+					this.productList = re.data.data;
+				}
+			});
+			uni.stopPullDownRefresh();
+		},
+		onReachBottom() {
+			// 如果页码是0,避免第一页重复
+			if( this.requestParam.page < 1 ) return;
+			// 最后一页不再请求
+			if( this.isLast ) 	return;
+			// 请求中,不再请求
+			if( this.isReqing ) return;
+			// 增加一页
+			this.requestParam.page = this.requestParam.page+1;
+			// 设置请求中
+			this.isReqing			= true;
+			// 请求列表
+			this.$http.request('api/product/get_list',this.requestParam).then((re)=>{
+				// 设置非请求中
+				this.isReqing		= false;
+				// 成功结果
+				if( re.code == 'success' ){
+					// 最后一页
+					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
+					// 追加数据
+					this.productList.push(...re.data.data);
+				}
+			});
+		},
+		methods: {
+			toDetail(item){
+				uni.navigateTo({
+					url:"/pages/product/index?product_id="+item.id,
+				})
+			}
+		}
+	}
+</script>
+
+<style lang="less">
+	.product_box{
+		display: block;
+		overflow: hidden;
+		margin: 20rpx auto;
+		padding: 0rpx 35rpx;
+		.product_list{
+			display: block;
+			overflow: hidden;
+			margin: 0rpx auto;
+			.product_item{
+				float: left;
+				width: 320rpx;
+				height: 520rpx;
+				display: block;
+				overflow: hidden;
+				margin: 20rpx 0rpx;
+				margin-right: 40rpx;
+				background-color: #FFFFFF;
+				border-radius: 20rpx;
+				.product_image{
+					width: 320rpx;
+					height: 320rpx;
+				}
+				.product_name{
+					height: 80rpx;
+					font-size: 30rpx;
+					line-height: 40rpx;
+					overflow: hidden;
+					margin: 10rpx 0rpx;
+					padding: 0rpx 10rpx;
+					text-overflow: ellipsis;
+				}
+				.product_spec{
+					height: 30rpx;
+					color: #999999;
+					font-size: 24rpx;
+					line-height: 30rpx;
+					padding: 0rpx 10rpx;
+					overflow: hidden;
+					white-space: nowrap;
+					text-overflow: ellipsis;
+				}
+				.stock_price{
+					color: #dddddd;
+					font-size: 20rpx;
+					overflow: hidden;
+					line-height: 30rpx;
+					padding: 0rpx 10rpx;
+					.product_price{
+						float: left;
+						color: red;
+						font-size: 30rpx;
+						line-height: 60rpx;
+						.product_market{
+							font-size: 24rpx;
+							color: #999999;
+							line-height: 30rpx;
+							vertical-align: top;
+							text-decoration: line-through;
+						}
+					}
+					.product_stock{
+						float: right;
+						font-size: 20rpx;
+						line-height: 60rpx;
+					}
+				}
+			}
+			.product_item:nth-child(even){
+				margin-right: 0rpx;
+			}
+		}
+	}
+</style>