order.vue 9.57 KB
Newer Older
zhangpeng committed
1
<template>
张成 committed
2
	<view class="pages">
weijiguang committed
3 4
		<view v-show="false">{{userms}}</view>
		<view class="empty" v-show="userms && empty == true">
1  
宋冰琦 committed
5 6 7 8 9
			<view :style="{'text-align':'center'}">
				<image class="empty_icon" src="/static/imgs/none_content.png"></image>
			</view>
			<view  class="empty_text">——您还未下单,下单品尝一下吧——</view>
			<button class="empty_button" @click="goHome"></button>
weijiguang committed
10 11
		</view>
		<view class="empty" v-show="!userms">
1  
宋冰琦 committed
12 13 14 15 16
			<view :style="{'text-align':'center'}">
				<image class="empty_icon" src="/static/imgs/none_content.png"></image>
			</view>
			<view  class="empty_text">——您还未登录,请先登录——</view>
			<button class="empty_button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"></button>
weijiguang committed
17
		</view>
张成 committed
18 19 20 21 22
		<view class="orders">
			<view class="order_item" v-for="item in list" :key="item.id" @click="openInfo(item)">
				<view class="order_header">
					<view>
						<h3 class="order_adrass">{{ item.shop.name }}</h3>
张成 committed
23
						<text class="order_time">{{ item.createdAt }}</text>
张成 committed
24
					</view>
25 26 27 28
					<view class="order_status">
						<text>{{ getStateText(item.state) }}</text>
						<image class="xiaojiantou" src="@/static/imgs/xiaojiantou.png"/>
					</view>
张成 committed
29
				</view>
张成 committed
30
				<div class="order_content">
31
					<view class="order_content_box1">
张成 committed
32 33 34 35 36 37
						<view class="goods_item" v-for="good in item.orderDetails" :key="good.id">
							<image class="goods_img" v-if="jsonParse(good.goods.pics).thumbnailApplet"
								:src="jsonParse(good.goods.pics).thumbnailApplet"></image>
							<image v-else class="goods_img" :src="jsonParse(good.goods.pics).thumbnail"></image>

							<view class="goods_text">
38
								<view class="goods_title">{{ good.goodsName }}</view>
张成 committed
39
								<view class="goods_spce">
40 41 42 43 44 45 46 47 48
									<view>
										<span v-for="(rule, index) in jsonParse(good.specRuleDetail)" :key="rule.specId">
											{{ rule.ruleName }}
											<span v-if="index!=jsonParse(good.specRuleDetail).length-1">/</span>
										</span>
									</view>
									<view>
										×{{ good.num }}
									</view>
张成 committed
49
								</view>
张成 committed
50 51 52
							</view>
						</view>
					</view>
1  
weijiguang committed
53
					<view v-if="item.state == 2 || item.state == 3 || item.state == 4 || item.state == 5" class="qr_code">
张成 committed
54 55 56 57
						<image class="qr_code_img" src="/static/imgs/icon-barcode.png"></image>
						<view class="qr_text">点击二维码取单</view>
					</view>
				</div>
张成 committed
58 59
				<view class="order_footer">
					<view class="total">
songbingqi committed
60
{{ orderDetailsSize(item.orderDetails) }}件商品 合计<text class="price">{{ Utils.isInteger(item.amount) }}</text>
张成 committed
61
					</view>
张成 committed
62 63
					<a class="btn" @click.stop="PayNow(item)" v-if="item.state == 1" type="primary">立刻支付</a>
					<a class="btn" v-else @click.stop="oneMoreOrder(item)" type="primary">再来一单</a>
张成 committed
64 65 66
				</view>
			</view>
		</view>
67
		<show-toast ref="toast"/>
zhangpeng committed
68 69 70 71
	</view>
</template>

<script>
张成 committed
72
import order from '@/request/order'
张成 committed
73 74
import Menu from '@/request/menu';
import Utils from '@/utils/utils'
weijiguang committed
75
import User from '@/request/user'
张成 committed
76 77
import { $EventBus } from "@/utils/EventBus";

张成 committed
78
export default {
79 80 81 82 83 84 85
	onLoad() {
		if(!this.userms){
			User.wxLoginAndGetOpenid(true).then(loginInfo=>{
				this.loginInfo = loginInfo
			})
		}
	},
张成 committed
86 87 88
	name: 'order',
	data() {
		return {
weijiguang committed
89
			empty: false,
90
			list: [],
songbingqi committed
91 92
			loginInfo:"",
			Utils
张成 committed
93 94
		}
	},
张成 committed
95 96
	onShow() {
		this.getList()
张成 committed
97
	},
张成 committed
98 99 100
	computed: {
		userms() {
			return this.$store.getters.Authorization;
weijiguang committed
101
		}
张成 committed
102 103
	},
	methods: {
weijiguang committed
104 105 106 107
		getStateText(state) {
			state = '' + state;
			switch (state) {
				case '1':
weijiguang committed
108
					return '待付款'
weijiguang committed
109 110 111 112 113 114 115 116 117
				case '2':
					return '待制作'
				case '3':
					return '制作中'
				case '4':
					return '待取餐'
				case '5':
					return '取餐中'
				case '6':
1  
weijiguang committed
118
				case '7':
weijiguang committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
					return '已完成'
				case '8':
				case '9':
				case '10':
				case '11':
					return '已取消'
				case '12':
					return '退款中'
				case '13':
					return '退款失败'
				case '14':
					return '部分退款'
				case '15':
					return '已退款'
				default:
					return '未知状态'
			}
		},
张成 committed
137
		async oneMoreOrder(item) {
138
			// 清空购物车
张成 committed
139 140
			uni.removeStorageSync('shopCarInfo');
			$EventBus.$emit('updateCar');
141
			//
张成 committed
142 143 144 145 146 147
			const numObj = {}
			const { id, shopId, orderDetails } = item;
			orderDetails.forEach(item => {
				orderDetails[item.skuId] = item.num
			})
			const { data } = await order.moreOrder({ orderId: id, shopId });
148
			if(!data || !data.data){
149
				this.showToast({ title: "该订单中的商品已经售罄了" });
150 151 152 153
				return;
			}
			
			let list = new Array();
张成 committed
154 155 156 157
			data.data.forEach(item => {
				const skuId = item.skus[0].skuId
				const nextData = { ...item, skuId, num: orderDetails[skuId], flag: true, sku: item.skus[0] }
				if (nextData.sku.state == 1) {
158
					list.push(nextData);
张成 committed
159 160
				}
			});
161
			if(!list || list.length<=0) {
162
				this.showToast({ title: "该订单中的商品已经售罄了", icon: 'error' });
163 164 165 166 167 168
				return;
			}
			list.forEach(nextData => {
				Utils.getallNum(nextData);
			})
			uni.switchTab({ url: '/pages/menu/menu' });
张成 committed
169 170 171 172 173
		},
		async getList() {
			if (!this.userms) return
			const { data } = await order.getMyOrder();
			if (data) {
weijiguang committed
174 175 176 177 178 179
				this.list = data.rows;
				if(this.list && this.list.length>0) {
					this.empty = false;
				} else {
					this.empty = true;
				}
张成 committed
180
			} else {
181
				this.showToast({ title: '请登录!', icon: 'error' })
张成 committed
182 183 184 185 186 187 188 189 190 191 192
			}
		},
		async PayNow({ id }) {
			const orderInfo = await order.payOrder({ orderId: id })
			if (orderInfo) {
				if (orderInfo && orderInfo.data.code == 200) {
					await Menu.requestPayment(orderInfo.data.data);
					this.getList()
				}
			}
		},
weijiguang committed
193 194 195 196 197 198
		goHome() {
			uni.switchTab({ url: '/pages/menu/menu' });
		},
		// 手机号授权登录
		getPhoneNumber(e) {
			if (e.detail.errMsg == 'getPhoneNumber:ok') {
199
				e.loginInfo = this.loginInfo
weijiguang committed
200 201
				User.getPhoneNumber(e, this.getList);
			} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
202
				this.showToast({ title: '已拒绝手机号授权', icon: 'error' })
weijiguang committed
203 204
			}
		},
张成 committed
205 206 207 208
		openInfo(data) {
			uni.setStorageSync('orderInfo', data);
			let url = '/orderSubPackage/pages/orderInfo/index'
			uni.navigateTo({ url })
zhangpeng committed
209
		},
张成 committed
210
		jsonParse(json) {
张成 committed
211 212 213 214 215 216 217 218 219 220
			const data = json || {}
			return JSON.parse(data)
		},
		orderDetailsSize(orderDetails) {
			let size = 0;
			orderDetails.forEach(item => {
				const { num } = item;
				size += Number(num)
			});
			return size
zhangpeng committed
221
		}
张成 committed
222 223


zhangpeng committed
224
	}
张成 committed
225
}
zhangpeng committed
226 227
</script>

张成 committed
228
<style lang="scss" scoped>
weijiguang committed
229 230 231 232 233 234
.empty {
	 position: fixed;
	 /* 居中对齐begin */
	 left: 50%;
	 /* 兼容老版本的方法 */
	 -webkit-transform: translateX(-50%);
1  
宋冰琦 committed
235 236
	 transform: translate(-50%);
	 margin-top: 311rpx;
weijiguang committed
237 238
	
	.empty_icon {
1  
宋冰琦 committed
239 240
		 width: 280rpx;
		 height: 266rpx;
weijiguang committed
241 242 243
		 
	}
	.empty_text {
1  
宋冰琦 committed
244
		margin-top: 35rpx;
weijiguang committed
245
		text-align: center;
1  
宋冰琦 committed
246 247 248 249 250

		font-size: 24rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
weijiguang committed
251 252
	}
	.empty_button {
1  
宋冰琦 committed
253 254 255 256 257 258 259 260
		margin-top: 35rpx;
		width: 167rpx;
		height: 64rpx;
		background: url('@/static/imgs/qupinchang.png') center center no-repeat;
		border-radius: 0rpx;
	}
	.empty_button::after{
		border-radius: 0rpx;
songbingqi committed
261
		border: 0rpx;
weijiguang committed
262 263 264
	}
}

张成 committed
265 266 267 268 269 270
.orders {
	padding: 1rpx;

	.order_item {
		width: 686rpx;
		background: #FFFFFF;
271
		margin: 30rpx auto 0;
张成 committed
272
		box-sizing: border-box;
273
		padding: 25rpx 32rpx;
张成 committed
274 275 276 277 278 279 280 281 282

		.order_header {
			display: flex;
			justify-content: space-between;

			.order_adrass {
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
283
				color: #333333;
张成 committed
284 285 286
			}

			.order_time {
287
				font-size: 24rpx;
张成 committed
288
				font-family: ArialMT;
289
				color: #999999;
张成 committed
290 291 292 293 294
			}

			.order_status {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
295 296 297 298 299 300 301 302 303 304
				font-weight: 400;
				color: #999999;
				display: flex;
				align-items: baseline;
				justify-content: flex-start;
				.xiaojiantou {
					width: 12rpx;
					height: 16rpx;
					margin-left: 5rpx;
				}
张成 committed
305 306 307 308 309
			}

		}

		.order_content {
310
			margin-top: 42rpx;
张成 committed
311 312 313 314
			display: flex;
			justify-content: space-between;
			align-items: center;

315 316 317
			.order_content_box1{
				flex: 1;
			}
张成 committed
318 319 320 321 322 323 324 325

			.qr_code {
				font-size: 16rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #666666;
				line-height: 22rpx;
				text-align: center;
326 327
				margin-right: 10rpx;
				margin-left: 39rpx;
张成 committed
328 329 330 331 332

				.qr_code_img {
					width: 76rpx;
					height: 76rpx;
				}
333 334 335 336 337 338 339 340

				.qr_text {
					margin-top:10rpx;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
张成 committed
341
			}
张成 committed
342 343 344 345 346 347 348

			.goods_item {
				display: flex;
				align-items: center;


				.goods_img {
349 350
					height: 96rpx;
					width: 96rpx;
张成 committed
351 352 353 354
					background-color: #eee;
				}

				.goods_text {
355 356
					margin-left: 22rpx;
					flex: 1;
张成 committed
357 358 359

					.goods_title {
						font-size: 28rpx;
360 361 362
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
张成 committed
363 364 365
					}

					.goods_spce {
366
						margin-top: 2rpx;
张成 committed
367 368 369
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
370 371 372 373
						color: #999999;
						display: flex;
						justify-content: space-between;
						align-items: center;
张成 committed
374 375 376 377 378 379 380 381 382 383 384
					}

				}

			}
		}

		.order_footer {
			display: flex;
			align-items: center;
			justify-content: space-between;
385
			margin-top: 28rpx;
张成 committed
386 387

			.total {
388
				font-size: 28rpx;
张成 committed
389 390 391 392 393
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;

				.price {
394 395 396 397 398
					font-size: 28rpx;
					font-family: Futura-Medium, Futura;
					font-weight: 500;
					color: #666666;
					letter-spacing: 1rpx;
张成 committed
399 400 401 402
				}
			}

			.btn {
403 404 405 406 407
				width: 167rpx;
				height: 64rpx;
				line-height: 64rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				background: #003AE9;
张成 committed
408 409 410
				font-size: 24rpx;
				margin: 0;
				color: #fff;
411
				font-weight: 400;
张成 committed
412 413 414 415
				text-align: center;
			}
		}
	}
zhangpeng committed
416

张成 committed
417 418
}
</style>