zs 2 years ago
parent
commit
83f895a335
3 changed files with 136 additions and 10 deletions
  1. 22 5
      components/discount/index.vue
  2. 111 5
      pagesHome/exchange/index.vue
  3. 3 0
      pagesMy/discount/index.vue

+ 22 - 5
components/discount/index.vue

@@ -8,13 +8,19 @@
 			</view>
 			<view class="right">
 				<view class="other">
-					<view class="type"><text>{{item.type||'暂无'}}</text> {{item.coupon.name||'暂无'}}</view>
-					<view class="date">有效期{{item.start_time||'暂无'}}-{{item.end_time||'暂无'}}</view>
+					<view class="type"><text>{{item.discount_type_label||'暂无'}}</text>
+						{{item.name||'暂无'}}
+					</view>
+					<view class="date">有效期{{item.expire_time||'暂无'}}</view>
+					<view class="date">{{item.use_limit_label||'暂无'}}-{{item.get_limit_label||'暂无'}}</view>
 				</view>
 				<view class="btn">
 					<button v-if="Style&&Style.btn||false" type="default" size="mini"
 						@click="toDiscount(item)">确认</button>
-					<button v-else type="default" size="mini">{{item.status=='0'?'未使用':item.status=='1'?'已使用':'已过期'}}</button>
+					<button v-if="Style&&Style.status||false" type="default"
+						size="mini">{{item.status=='0'?'未使用':item.status=='1'?'已使用':'已过期'}}</button>
+					<button v-if="Style&&Style.receive||false" type="default" size="mini"
+						@click="toReceive(item)">领取</button>
 				</view>
 			</view>
 		</view>
@@ -42,6 +48,11 @@
 				const that = this;
 				that.$emit('toDiscount', e)
 			},
+			// 领取优惠劵
+			toReceive(e) {
+				const that = this;
+				that.$emit('toReceive', e)
+			},
 		}
 	}
 </script>
@@ -64,9 +75,10 @@
 			.left {
 				text-align: center;
 				border-radius: 3vw;
-				padding: 5vw 3vw;
+				padding: 6vw 3vw;
 				background-color: #FFFACD;
 				color: #8B4513;
+				border-right: 0.5vw dashed var(--fcColor);
 
 				.money {
 					font-size: var(--font18Szie);
@@ -84,7 +96,7 @@
 				align-items: center;
 				flex-grow: 1;
 				border-radius: 3vw;
-				padding: 5vw 3vw;
+				padding: 4vw 3vw;
 				background-color: var(--mainColor);
 
 				.other {
@@ -113,6 +125,11 @@
 					}
 
 					.date {
+						overflow: hidden;
+						text-overflow: ellipsis;
+						display: -webkit-box;
+						-webkit-line-clamp: 1;
+						-webkit-box-orient: vertical;
 						font-size: var(--font12Size);
 						color: var(--f99Color);
 					}

+ 111 - 5
pagesHome/exchange/index.vue

@@ -1,23 +1,129 @@
 <template>
 	<mobile-frame>
-		兑换中心
+		<view class="main">
+			<view class="one">
+				<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
+					<view class="list-scroll-view">
+						<discount :Style="Style" :couponList="list" @toReceive="toReceive"></discount>
+					</view>
+				</scroll-view>
+			</view>
+		</view>
 	</mobile-frame>
 </template>
 
 <script>
+	import discount from '@/components/discount/index.vue';
 	export default {
+		components: {
+			discount
+		},
 		data() {
 			return {
-
+				Style: {
+					receive: true
+				},
+				user: {},
+				list: [],
+				total: 0,
+				skip: 0,
+				limit: 5,
+				page: 0
 			};
 		},
-		onShow: function() {},
+		onLoad: function(e) {
+			const that = this;
+			// 监听用户是否登录
+			that.watchLogin();
+		},
 		methods: {
-
+			// 领取优惠劵
+			async toReceive(e) {
+				const that = this;
+				const arr = await that.$api(`/userCoupon/getCoupon/${e._id}`, 'POST');
+				if (arr.errcode == '0') {
+					uni.showToast({
+						title: `领取成功`,
+						icon: 'none',
+						duration: 3000
+					})
+					uni.navigateBack({
+						detail: 1
+					})
+				} else {
+					uni.showToast({
+						title: arr.errmsg,
+						icon: 'error',
+						duration: 2000
+					});
+				}
+			},
+			// 监听用户是否登录
+			watchLogin() {
+				const that = this;
+				uni.getStorage({
+					key: 'token',
+					success: function(res) {
+						let user = that.$jwt(res.data);
+						if (user) that.$set(that, `user`, user);
+						that.search();
+					},
+					fail: function(err) {
+						uni.navigateTo({
+							url: `/pages/login/index`
+						})
+					}
+				});
+			},
+			// 查询列表
+			async search() {
+				const that = this;
+				let user = that.user;
+				const res = await that.$api(`/coupon`, 'GET');
+				if (res.errcode == '0') {
+					let list = [...that.list, ...res.data];
+					that.$set(that, `list`, list)
+					that.$set(that, `total`, res.total)
+				} else {
+					uni.showToast({
+						title: res.errmsg,
+					});
+				}
+			},
+			// 分页
+			toPage(e) {
+				const that = this;
+				let list = that.list;
+				let limit = that.limit;
+				if (that.total > list.length) {
+					uni.showLoading({
+						title: '加载中',
+						mask: true
+					})
+					let page = that.page + 1;
+					that.$set(that, `page`, page)
+					let skip = page * limit;
+					that.$set(that, `skip`, skip)
+					that.search();
+					uni.hideLoading();
+				} else uni.showToast({
+					title: '没有更多数据了'
+				});
+			},
+			// 清空列表
+			clearPage() {
+				const that = this;
+				that.$set(that, `list`, [])
+				that.$set(that, `skip`, 0)
+				that.$set(that, `limit`, 5)
+				that.$set(that, `page`, 0)
+			}
 		}
 	}
 </script>
 
 <style lang="scss">
-
+	.main {
+		background-color: var(--f5Color);
+	}
 </style>

+ 3 - 0
pagesMy/discount/index.vue

@@ -20,6 +20,9 @@
 		},
 		data() {
 			return {
+				Style: {
+					status: true
+				},
 				user: {},
 				list: [],
 				total: 0,