zs 2 سال پیش
والد
کامیت
e1aa871939
3فایلهای تغییر یافته به همراه102 افزوده شده و 8 حذف شده
  1. 7 1
      components/discount/index.vue
  2. 6 2
      pagesHome/order/order.vue
  3. 89 5
      pagesMy/discount/index.vue

+ 7 - 1
components/discount/index.vue

@@ -12,7 +12,9 @@
 					<view class="date">有效期{{item.start_time||'暂无'}}-{{item.end_time||'暂无'}}</view>
 				</view>
 				<view class="btn">
-					<button type="default" size="mini" @click="toDiscount(item)">确认</button>
+					<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>
 				</view>
 			</view>
 		</view>
@@ -25,6 +27,9 @@
 			couponList: {
 				type: Array,
 			},
+			Style: {
+				type: Object,
+			},
 		},
 		data() {
 			return {
@@ -96,6 +101,7 @@
 						-webkit-box-orient: vertical;
 						font-size: var(--font14Size);
 						margin: 0 1vw 1vw 0;
+
 						text {
 							margin: 0 1vw 0 0;
 							border: 0.5vw solid red;

+ 6 - 2
pagesHome/order/order.vue

@@ -62,7 +62,8 @@
 									<view class="other">
 										<view class="other_1">优惠劵</view>
 										<view class="other_2" @click="toCoupon" v-if="couponList.length">
-											{{coupon_name||'请选择优惠劵'}}</view>
+											{{coupon_name||'请选择优惠劵'}}
+										</view>
 										<view class="other_2" v-else>暂无优惠劵使用</view>
 									</view>
 									<view class="other">
@@ -116,7 +117,7 @@
 				</view>
 			</view>
 			<view class="content" v-else>
-				<discount :couponList="couponList" @toDiscount="toDiscount"></discount>
+				<discount :Style="Style" :couponList="couponList" @toDiscount="toDiscount"></discount>
 			</view>
 		</uni-popup>
 	</mobile-frame>
@@ -130,6 +131,9 @@
 		},
 		data() {
 			return {
+				Style: {
+					btn: true
+				},
 				user: {},
 				key: '',
 				address: {},

+ 89 - 5
pagesMy/discount/index.vue

@@ -1,23 +1,107 @@
 <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"></discount>
+					</view>
+				</scroll-view>
+			</view>
+		</view>
 	</mobile-frame>
 </template>
 
 <script>
+	import discount from '@/components/discount/index.vue';
 	export default {
+		components: {
+			discount
+		},
 		data() {
 			return {
-
+				user: {},
+				list: [],
+				total: 0,
+				skip: 0,
+				limit: 5,
+				page: 0
 			};
 		},
-		onShow: function() {},
+		onLoad: function(e) {
+			const that = this;
+			// 监听用户是否登录
+			that.watchLogin();
+		},
 		methods: {
-
+			// 监听用户是否登录
+			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(`/userCoupon`, 'GET', {
+					customer: user._id
+				});
+				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>