YY 2 gadi atpakaļ
vecāks
revīzija
d57172acbe
1 mainītis faili ar 43 papildinājumiem un 41 dzēšanām
  1. 43 41
      pages/market/index.vue

+ 43 - 41
pages/market/index.vue

@@ -8,21 +8,21 @@
 				<view class="text_2" v-if="num==0" @click="edit(1)">编辑</view>
 				<view class="text_2" v-if="num==1" @click="edit(0)">完成</view>
 			</view>
-			<view class="one" v-if="!user._id">
+			<view class="one" v-if="!user.id">
 				<view class="logo"><text class="iconfont icon-gouwuche"></text></view>
 				<view class="one_1">您还没有登录</view>
 				<view class="btn">
 					<button type="primary" size="mini" @click="toCommon('/pages/login/index')">去登录</button>
 				</view>
 			</view>
-			<view class="one" v-if="list.length==0">
+			<view class="one" v-if="list.length==0&&user.id">
 				<view class="logo"><text class="iconfont icon-gouwuche"></text></view>
 				<view class="one_1">购物车空空如也~</view>
 				<view class="btn">
 					<button type="primary" size="mini" @click="toCommon('/pages/home/index')">去逛逛</button>
 				</view>
 			</view>
-			<view class="two">
+			<view class="two" v-if="list.length !=0">
 				<scroll-view scroll-y="true" class="scroll-view">
 					<view class="list-scroll-view">
 						<checkbox-group name="checkbox" @change="marketChange">
@@ -31,7 +31,7 @@
 									<view class="title">
 										<checkbox :value="item.id" :checked="item.check">
 											<text class="iconfont icon-shangdian"></text>
-											{{item.title}}
+											{{item.shop}}
 										</checkbox>
 									</view>
 									<checkbox-group name="checkbox" @change="goodsChange">
@@ -88,49 +88,23 @@
 				frameStyle: {
 					useBar: true
 				},
-				user: {
-					_id: '001'
-				},
-				list: [{
-					id: '001',
-					title: '商品1店铺',
-					goods: [{
-						id: '00001',
-						name: '商品商品商品商品商品1',
-						money: 50.00,
-						num: 2,
-						kg: '1.5L',
-					}, {
-						id: '00002',
-						name: '商品商品商品商品商品2',
-						money: 150.00,
-						num: 2,
-						kg: '13.5L',
-					}, ]
-				}, {
-					id: '002',
-					title: '商品1店铺',
-					goods: [{
-						id: '00003',
-						name: '商品商品商品商品商品1',
-						money: 50.00,
-						num: 2,
-						kg: '1.5L',
-					}, {
-						id: '00004',
-						name: '商品商品商品商品商品2',
-						money: 150.00,
-						num: 2,
-						kg: '13.5L',
-					}, ]
-				}, ],
+				// 用户
+				user: {},
+				// 购物车列表
+				list: [],
+				// 全选
 				isAll: false,
 				// 编辑/完成按钮传的数字
 				num: 0,
+				// 总额
 				totalMoney: 0,
 			};
 		},
-		onShow: function() {},
+		onShow: function() {
+			const that = this;
+			// 监听登录
+			that.watchLogin();
+		},
 		methods: {
 			toPath(e) {
 				if (e && e.route) uni.redirectTo({
@@ -143,6 +117,34 @@
 					url: `${route}?id=${e && e._id ? e._id : ''}`
 				})
 			},
+			// 监听登录
+			watchLogin() {
+				const that = this;
+				uni.getStorage({
+					key: 'token',
+					success: (res) => {
+						let user = that.$jwt(res.data);
+						if (user) {
+							that.$set(that, `user`, {
+								id: user.id,
+							})
+							that.searchMarket();
+						}
+					},
+					fail: (err) => {}
+				})
+			},
+			// 查询购物车信息
+			async searchMarket() {
+				const that = this;
+				const res = await that.$api(`/cart/selfCart`, 'GET', {
+					customer: that.user.id
+				});
+				if (res.errcode == '0') {
+					console.log(res.data);
+					that.$set(that, `list`, res.data)
+				}
+			},
 			// 转换金额
 			showMoney(money) {
 				const that = this;