order.vue 8.91 KB
Newer Older
zhangpeng committed
1
<template>
张成 committed
2
	<view class="pages">
weijiguang committed
3 4 5 6 7 8 9 10 11 12 13
		<view v-show="false">{{userms}}</view>
		<view class="empty" v-show="userms && empty == true">
			<image class="empty_icon" src="/static/imgs/none_content.png"></image>
			<view  class="empty_text">---您还未下单,下单品尝一下吧---</view>
			<button class="empty_button" @click="goHome">去品尝</button>
		</view>
		<view class="empty" v-show="!userms">
			<image class="empty_icon" src="/static/imgs/none_content.png"></image>
			<view  class="empty_text">---您还未登录,请先登录---</view>
			<button class="empty_button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">去登录</button>
		</view>
张成 committed
14 15 16 17 18
		<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
19
						<text class="order_time">{{ item.createdAt }}</text>
张成 committed
20 21
					</view>
					<view class="order_status" v-if="item.state == 0">创建未校验</view>
张成 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
					<view class=" order_status" v-if="item.state == 1">未支付</view>
					<view class=" order_status" v-if="item.state == 2">已支付</view>
					<view class=" order_status" v-if="item.state == 3">支付制作中</view>
					<view class=" order_status" v-if="item.state == 4">制作完成未取</view>
					<view class=" order_status" v-if="item.state == 5">取餐中</view>
					<view class=" order_status" v-if="item.state == 6">正常完成</view>
					<view class=" order_status" v-if="item.state == 7">待取超时</view>
					<view class=" order_status" v-if="item.state == 8">未支付取消</view>
					<view class=" order_status" v-if="item.state == 9">支付后制作前取消</view>
					<view class=" order_status" v-if="item.state == 10">制作中取消</view>
					<view class=" order_status" v-if="item.state == 11">制作完成取消</view>
					<view class=" order_status" v-if="item.state == 12">退款中</view>
					<view class=" order_status" v-if="item.state == 13">退款失败</view>
					<view class=" order_status" v-if="item.state == 14">部分退款</view>
					<view class=" order_status" v-if="item.state == 15">已退款</view>
					<view class=" order_status" v-if="item.state == 50">其他人工干预状态</view>
张成 committed
38
				</view>
张成 committed
39 40 41 42 43 44 45 46 47 48
				<div class="order_content">
					<view>
						<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">
								<view class="goods_title">{{ good.goodsName }}×{{ good.num }}</view>
								<view class="goods_spce">
weijiguang committed
49 50 51
									<span v-for="(rule, index) in jsonParse(good.specRuleDetail)" :key="rule.specId">
										{{ rule.ruleName }}
										<span v-if="index!=jsonParse(good.specRuleDetail).length-1">/</span>
张成 committed
52 53
									</span>
								</view>
张成 committed
54 55 56
							</view>
						</view>
					</view>
张成 committed
57 58 59 60 61 62
					<view v-if="item.state == 4 || item.state == 5 || item.state == 6 || item.state == 7"
						class="qr_code">
						<image class="qr_code_img" src="/static/imgs/icon-barcode.png"></image>
						<view class="qr_text">点击二维码取单</view>
					</view>
				</div>
张成 committed
63 64
				<view class="order_footer">
					<view class="total">
张成 committed
65
{{ orderDetailsSize(item.orderDetails) }}件商品 合计: <text class="price">{{ item.amount }}</text>
张成 committed
66
					</view>
张成 committed
67 68
					<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
69 70 71
				</view>
			</view>
		</view>
张成 committed
72

zhangpeng committed
73 74 75 76
	</view>
</template>

<script>
张成 committed
77
import order from '@/request/order'
张成 committed
78 79
import Menu from '@/request/menu';
import Utils from '@/utils/utils'
weijiguang committed
80
import User from '@/request/user'
张成 committed
81 82
import { $EventBus } from "@/utils/EventBus";

张成 committed
83
export default {
84 85 86 87 88 89 90
	onLoad() {
		if(!this.userms){
			User.wxLoginAndGetOpenid(true).then(loginInfo=>{
				this.loginInfo = loginInfo
			})
		}
	},
张成 committed
91 92 93
	name: 'order',
	data() {
		return {
weijiguang committed
94
			empty: false,
95 96
			list: [],
			loginInfo:""
张成 committed
97 98
		}
	},
张成 committed
99 100
	onShow() {
		this.getList()
张成 committed
101
	},
张成 committed
102 103 104 105
	computed: {
		userms() {
			return this.$store.getters.Authorization;
		},
张成 committed
106 107
	},
	methods: {
张成 committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
		async oneMoreOrder(item) {
			uni.removeStorageSync('shopCarInfo');
			$EventBus.$emit('updateCar');
			const numObj = {}
			const { id, shopId, orderDetails } = item;
			orderDetails.forEach(item => {
				orderDetails[item.skuId] = item.num
			})
			const { data } = await order.moreOrder({ orderId: id, shopId });
			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) {
					Utils.getallNum(nextData)
				}
			});
			uni.switchTab({ url: '/pages/menu/menu' })
		},
		async getList() {
			if (!this.userms) return
			const { data } = await order.getMyOrder();
			if (data) {
weijiguang committed
130 131 132 133 134 135
				this.list = data.rows;
				if(this.list && this.list.length>0) {
					this.empty = false;
				} else {
					this.empty = true;
				}
张成 committed
136 137 138 139 140 141 142 143 144 145 146 147 148
			} else {
				uni.showToast({ title: '请登录!', icon: 'error' })
			}
		},
		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
149 150 151 152 153 154
		goHome() {
			uni.switchTab({ url: '/pages/menu/menu' });
		},
		// 手机号授权登录
		getPhoneNumber(e) {
			if (e.detail.errMsg == 'getPhoneNumber:ok') {
155
				e.loginInfo = this.loginInfo
weijiguang committed
156 157 158 159 160
				User.getPhoneNumber(e, this.getList);
			} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
				uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
			}
		},
张成 committed
161 162 163 164
		openInfo(data) {
			uni.setStorageSync('orderInfo', data);
			let url = '/orderSubPackage/pages/orderInfo/index'
			uni.navigateTo({ url })
zhangpeng committed
165
		},
张成 committed
166
		jsonParse(json) {
张成 committed
167 168 169 170 171 172 173 174 175 176
			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
177
		}
张成 committed
178 179


zhangpeng committed
180
	}
张成 committed
181
}
zhangpeng committed
182 183
</script>

张成 committed
184
<style lang="scss" scoped>
weijiguang committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
.empty {
	 position: fixed;
	 /* 居中对齐begin */
	 left: 50%;
	 /* 兼容老版本的方法 */
	 -webkit-transform: translateX(-50%);
	 transform: translateX(-50%);
	 margin-top: 200rpx;
	
	.empty_icon {
		 width: 325rpx;
		 height: 296rpx;
		 
	}
	.empty_text {
		font-size: 20rpx;
		margin-top: 10rpx;
		font-family: ArialMT;
		color: #666666;
		text-align: center;
	}
	.empty_button {
		width: 128rpx;
		height: 46rpx;
		margin-top: 10rpx;
		background: #006ECF;
		border-radius: 10rpx;
		text-align: center;
weijiguang committed
213
		line-height: 46rpx;
weijiguang committed
214 215 216 217 218
		font-size: 20rpx;
		color: #fff;
	}
}

张成 committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
.orders {
	padding: 1rpx;

	.order_item {
		width: 686rpx;
		min-height: 370rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 15rpx auto 0;
		box-sizing: border-box;
		padding: 28rpx 32rpx;

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

			.order_adrass {
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
			}

			.order_time {
				font-size: 20rpx;
				font-family: ArialMT;
				color: #666666;
			}

			.order_status {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 500;
				color: #000000;
				margin-top: 10rpx;
			}

		}

		.order_content {
			margin-top: 38rpx;
张成 committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
			display: flex;
			justify-content: space-between;
			align-items: center;


			.qr_code {
				font-size: 16rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #666666;
				line-height: 22rpx;
				text-align: center;
				margin-right: 15rpx;
				margin-top: 30rpx;

				.qr_code_img {
					width: 76rpx;
					height: 76rpx;
				}
			}
张成 committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

			.goods_item {
				display: flex;
				align-items: center;
				margin-top: 10rpx;


				.goods_img {
					height: 80rpx;
					width: 80rpx;
					background-color: #eee;
				}

				.goods_text {
					margin-left: 38rpx;

					.goods_title {
						font-size: 28rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 600;
						color: #000000;
					}

					.goods_spce {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						margin-top: 6rpx;
					}

				}

			}
		}

		.order_footer {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 50rpx;

			.total {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;

				.price {
					color: #FF5200;
					font-weight: 700
				}
			}

			.btn {
				width: 144rpx;
				height: 48rpx;
				line-height: 48rpx;
				background: #006ECF;
				border-radius: 6rpx;
				font-size: 24rpx;
				margin: 0;
				color: #fff;
				text-align: center;
			}
		}
	}
zhangpeng committed
347

张成 committed
348 349
}
</style>