<template>
	<view class="order_info">
		<view class="order_con">
			<view class="log_info flexS" v-if="orderList[0]">
				<image class="avatar" :src="orderList[0].user.avatar" v-if="orderList[0].user"></image>
				<text class="iconfont icongeren2" v-else></text>
				<view class="user" v-if="orderList[0].user">
					<text>客户：</text>
					<text>{{ orderList[0].user.nickname | getName(orderList[0].user.phone ? 10 : 16) }}</text>
					<text style="margin-left: 10rpx;">{{ orderList[0].user.phone }}</text>
				</view>
			</view>
			<view class="order_box" v-for="(item,idx) in orderList" :key="idx">
				<view class="shop_name">
					<text>订单号：{{item.order_no}}</text>
				</view>
				<view class="goods_box">
					<view class="goods_con" v-for="temp in item.goods" :key="temp.id">
						<view class="goods_info flexS">
							<image :src="temp.img" class="goods_img"></image>
							<view class="goods_intr">
								<text class="goods_name">{{ temp.name }}</text>
								<view class="one_year" style="width: 120rpx;">3条装</view>
								<view class="price_box" style="margin-top:20rpx;">
									<view class="goods_price flexS" v-if="temp.sku[0].price == temp.vip_price">
										<view class="flexS">
											<view class="vip_ident">VIP</view>
											<text class="big_price">
												<text>¥</text>
												<text>{{ temp.vip_price }}</text>
											</text>
										</view>
										<view class="draw_off">
											<text>（</text>
											<text class="old_price">
												<text class="symbol">¥</text>
												<text>{{ temp.price }}</text>
											</text>
											<text>）</text>
										</view>
									</view>
									<view class="goods_price flexS" v-else>
										<text class="big_price">
											<text class="symbol">¥</text>
											<text>{{ temp.price }}</text>
										</text>
										<view class="save_box">
											VIP可省{{ Number(temp.price) - Number(temp.vip_price) || 0 }}</view>
									</view>
								</view>
							</view>
						</view>
						<view class="goods_size" v-for="sku in item.sku" :key="sku.id">
							<view class="flexB">
								<view>
									<text class="gray">款式：</text>
									<text>{{ sku.type }}</text>
								</view>
								<text>{{ sku.price * sku.num }}元</text>
							</view>
							<view class="flexB">
								<view>
									<text class="gray">尺码：</text>
								</view>
								<text>X {{ sku.num }}套</text>
							</view>
						</view>
						<view class="goods_total flexE">
							<text style="color:#999;">共{{ subNum(temp) }}套，</text>
							<text style="color:#999;">小计：</text>
							<view class="price_box">
								<view class="goods_price flexS">
									<text class="big_price">
										<text class="symbol">¥</text>
										<text>{{ subtotal(temp) }}</text>
									</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="flexT" style="margin-top:15rpx;">
					<view style="flex-shrink: 0;">订单备注：</view>
					<text class="gray" @click="copy(item.remark)"
						selectable="true">{{ item.remark ? item.remark : '无' }}
					</text>
				</view>
			</view>

		</view>
		<view class="send_box flexCC">
			<view class="flexC" @click="sendGoods">立即发货</view>
		</view>
	</view>
</template>

<script>
	import {
		getNoSendOrder
	} from '../../../apis/shop.js';
	export default {
		data() {
			return {
				order_no: '',
				orderList: [] //订单列表
			};
		},

		onLoad(options) {
			if (options.order_no) {
				this.order_no = options.order_no;
				this.getOrder(this.order_no);
			}
		},
		methods: {
			/*复制订单号*/
			copy(data) {
				uni.setClipboardData({
					data,
					success: res => {
						uni.showToast({
							title: '复制成功'
						});
					},
					fail() {
						uni.showToast({
							title: '复制失败',
							icon: 'none',
						});
					}
				})
			},
			//立即发货
			sendGoods() {
				let list = this.orderList;
				let arr = [];
				list.map(i => {
					arr.push(i.order_no)
				})
				let order_no = arr.join(',')
				let user_id = this.orderList[0].user_id
				uni.navigateTo({
					url: '../delivery-method/delivery-method?order_no=' +
						order_no + '&user_id=' + user_id
				});
			},
			//小计数量
			subNum(data) {
				let subNum = 0;
				data.sku.map(i => {
					subNum += i.num;
				});
				return subNum;
			},
			//小计金额
			subtotal(data) {
				let subtotal = 0;
				data.sku.map(j => {
					subtotal += j.num * j.price;
				});
				return subtotal;
			},
			/*获取订单详情*/
			getOrder(order_no) {
				uni.showLoading({
					title: '加载中...'
				});
				getNoSendOrder({
						order_no
					})
					.then(res => {
						if (res.code == 200) {
							this.orderList = res.data;
						} else {
							uni.showModal({
								content: res.data || '获取订单详情失败',
								showCancel: false
							});
						}
						uni.hideLoading();
					})
					.catch(err => {
						uni.hideLoading();
					});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.order_info {
		position: relative;
		width: 100%;
		min-height: 100%;
		background: #f9f8f9;

		.order_con {
			width: 100%;
			position: relative;
			padding-top: 30rpx;
			padding-bottom: 140rpx;

			>view {
				width: 690rpx;
				margin: 0 auto;
				background: #fff;
				border-radius: 24rpx;
				padding: 20rpx 30rpx;
			}

			.log_info {
				box-shadow: 0px 4rpx 8rpx #eeeeee;
				border-radius: 24rpx;
				width: 692rpx;
				height: 112rpx;
				background: #fff;
				box-sizing: border-box;

				.log_box {
					border-top: 1rpx solid #eee;
					padding-top: 20rpx;
				}

				.avatar {
					width: 50rpx;
					height: 50rpx;
					border-radius: 50rpx;
					margin-right: 15rpx;
					flex-shrink: 0;
				}

				.iconfont {
					margin-right: 20rpx;
					color: $base-color;
					font-size: 45rpx;
					font-weight: bold;
				}

				.badge {
					width: 36rpx;
					height: 40rpx;
					margin-right: 15rpx;
				}

				.user {
					text {
						font-size: 32rpx;
						font-weight: bold;
					}

				}
			}

			.order_box {
				width: 690rpx;
				margin: 30rpx auto;
				padding: 30rpx;
				box-sizing: border-box;

				.shop_name {
					padding: 0 30rpx 20rpx 0;
					border-bottom: 2rpx solid #eeeeee;

					text {
						font-size: 28rpx;
					}

					.iconfont {
						font-size: 35rpx;
						color: #999;
						margin-right: 10rpx;
						vertical-align: -2rpx;
					}
				}

				.goods_box {
					.goods_con {
						padding-top: 20rpx;

						.goods_info {
							.goods_img {
								width: 200rpx;
								height: 160rpx;
								margin-right: 26rpx;
								border-radius: 8rpx;
								flex-shrink: 0;
							}

							.goods_intr {
								.goods_name {
									font-size: 30rpx;
									font-weight: bold;
								}
							}
						}
					}

					.goods_size {
						margin-top: 30rpx;

						>view {
							margin-top: 15rpx;
						}
					}

					.goods_total {
						margin-top: 15rpx;
					}
				}

				.order_remark {
					.remark_title {
						font-size: 32rpx;
						font-weight: bold;
						padding: 15rpx 0;
					}

					.remark_box {
						width: 100%;
						background: #f8f8f8;
						min-height: 88rpx;
						padding: 20rpx 30rpx;
						border-radius: 16rpx;

						.edit_remark {
							width: 108rpx;
							height: 48rpx;
							background: #ffffff;
							border: 2rpx solid #fb231f;
							border-radius: 26rpx;
							background: #fff;
							margin-top: 15rpx;
							color: $base-color;
						}

						.finish {
							color: #fff;
							background: $base-line-bg;
							margin-left: 15rpx;
						}

						textarea {
							width: 100%;
						}
					}
				}
			}


		}

		.send_box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 100rpx;
			background: #fff;

			view {
				width: 690rpx;
				height: 88rpx;
				background: $base-color;
				border-radius: 44rpx;
				font-size: 32rpx;
				color: #fff;
			}
		}
	}

	.price_box {
		.goods_price {
			.vip_ident {
				width: 56rpx;
				height: 40rpx;
				background: linear-gradient(226deg, #66647a 0%, #404146 100%);
				border-radius: 4rpx;
				font-size: 28rpx;
				color: #fcf7c0;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-right: 10rpx;
			}

			.old_price {
				text-decoration: line-through;
				font-size: 28rpx;
				font-weight: 500;
			}

			.draw_off {
				text {
					color: #999;
				}
			}

			.symbol {
				font-size: 28rpx;
			}

			.price {
				font-weight: 600;
				font-size: 36rpx;

				text {
					color: $base-color;
				}
			}

			.vip {
				font-size: 28rpx;
				font-weight: bold;
				color: #333;
			}

			.vip_active {
				font-size: 36rpx;
				font-weight: bold;

				text {
					color: $base-color;
				}
			}

			.vip_img {
				width: 88rpx;
				height: 36rpx;
				vertical-align: -6rpx;
				margin-right: 10rpx;
			}
		}
	}

	.share_show {
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background-color: rgba(0, 0, 0, 0.7);
		z-index: 9999;

		.share_con {
			width: 80%;
			margin: 0 auto;
			height: 100%;
			z-index: 999999;

			.canvas {
				width: 540rpx;
				height: 960rpx;
				position: relative;

				#canvas {
					width: 540rpx;
					height: 960rpx;
					position: absolute;
					top: 0;
					left: 0;
				}

				.poster_img {
					-webkit-touch-callout: default;
					width: 100%;
					height: 100%;
					display: block;
				}

				img[src=''],
				img:not([src]) {
					opacity: 0;
				}

				// image {
				// 	width: 100%;
				// 	height: 100%;
				// 	border-radius: 24rpx;
				// }
			}

			.save_img {
				color: #fff;
				width: 100%;
				text-align: center;
				font-size: 40rpx;
				margin: 20rpx 0;
			}

			.iconfont {
				position: absolute;
				top: 4vh;
				right: 25rpx;
				color: #dedede;
				font-size: 60rpx;
				z-index: 999;
			}
		}

		.sub_btn {
			margin-top: 76rpx;
		}
	}

	.qrimg {
		opacity: 0;
	}
</style>
