<template>
	<view class="app-container">
		<view class="goods-container card">
			<view class="title">商品信息</view>
			<block v-for="(item, index) in detail.orderDetails" :key='index'>
				<view class="item" @tap="toGoodsDetail(item.goodsId)">
					<image :src="item.imgUrl" mode="aspectFill"></image>
					<view class="right">
						<view class="top">
							<view class="name ellipsis-2">{{item.goodsName}}</view>
							<view class="des">{{item.goodsSpecValue}}</view>
						</view>
						<view class="bottom">
							<view class="price">￥{{item.price | numToFixed}}</view>
							<view class="num">x{{item.num}}</view>
						</view>
					</view>
				</view>
			</block>
			<view class="total">合计：<text>¥{{detail.totalAmount | numToFixed}}</text></view>
		</view>
		
		<view class="order-container card">
			<view class="title">订单信息</view>
			<view class="item1">
				<view class="left">
					<view class="label">订单编号</view>
					<view class="value">{{detail.orderId}}</view>
				</view>
				<view class="copy" @tap="copy(detail.orderId)">复制</view>
			</view>
			<view class="item2">
				<view class="label">订单状态</view>
				<view class="value">{{detail.orderStatus | statusFilter}}</view>
			</view>
			<view class="item2">
				<view class="label">创建时间</view>
				<view class="value">{{detail.createTime}}</view>
			</view>
			<view class="item2">
				<view class="label">支付方式</view>
				<view class="value">{{detail.payType}}</view>
			</view>
			<view class="item2">
				<view class="label">支付时间</view>
				<view class="value">{{detail.payTime}}</view>
			</view>
			<view class="item2" v-if="detail.orderShareStatus !== 'CANCEL'">
				<view class="label">分享收益</view>
				<view class="value red">¥{{detail.totalShareAmount | numToFixed}}</view>
			</view>
			<view class="item2">
				<view class="label">收货人</view>
				<view class="value">{{detail.receUserName}}</view>
			</view>
			<view class="item2">
				<view class="label">收货电话</view>
				<view class="value">{{detail.recePhone}}</view>
			</view>
			<view class="item3">
				<view class="label">收货地址</view>
				<view class="value">{{detail.province}}{{detail.city}}{{detail.area}}{{detail.street}}{{detail.receAddress}}{{detail.houseNo || ''}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		filters: {
			statusFilter(val) {
				if(!val) { return '' }
				const statusMap = {
					NOPAY: '待付款',
					DFH: '待发货',
					YFH: '已发货',
					OVER: '已完成',
					CLOSE: '已关闭',
					REFUND: '售后中',
				}
				return statusMap[val];
			}
		},
		
		data() {
			return {
				orderId: null, // 订单id
				orderRefundId: null, // 售后订单id
				isReturnOrder: false, // 是否售后订单
				detail: {}, // 详情数据
			}
		},
		
		onLoad({orderId, orderRefundId}) {
			this.orderId = orderId;
			if(orderRefundId != 'undefined') {
				this.isReturnOrder = true;
				this.orderRefundId = orderRefundId;
			}
			this.getOrderDetail();
		},
		
		methods: {
			getOrderDetail() {
				let url = '', params = {};
				if(this.isReturnOrder) {
					url = '/order/refund/detail';
					params = {
						orderRefundId: this.orderRefundId
					}
				}else {
					url = '/order/detail';
					params = {
						orderId: this.orderId
					}
				}
				this.$axios({
					url,
					method: 'get',
					params
				}).then(res => {
					this.detail = res.data;
				})
			},
			
			// 去商品详情
			toGoodsDetail(id) {
				uni.navigateTo({
					url: '/packageGoods/pages/detail?id=' + id
				})
			},
			
			// 复制
			copy(val) {
				let that = this;
				uni.setClipboardData({
				    data: val,
				    success: function () {
				        that.$successToast('复制成功');
				    }
				});
			},
		}
	}
</script>

<style lang="scss">
	.app-container {
		background: #F4F2F2;
		box-sizing: border-box;
		padding: 20rpx 20rpx 120rpx;
	}
	.card {
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
	}
	.goods-container {
		padding: 0 20rpx;
		.title {
			font-size: 32rpx;
			color: #333333;
			line-height: 32rpx;
			padding-top: 20rpx;
		}
		.total {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			height: 78rpx;
			color: #666666;
			text {
				color: #FF3F42;
			}
		}
		.item {
			padding: 20rpx 0;
			border-bottom: 1px solid #eaeaea;
			display: flex;
			justify-content: space-between;
			align-items: center;
			image {
				width: 180rpx;
				height: 180rpx;
				flex-shrink: 0;
				margin-right: 20rpx;
			}
			.right {
				width: 470rpx;
				height: 180rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.top {
					.name {
						font-size: 28rpx;
						color: #333333;
						line-height: 36rpx;
					}
					.des {
						font-size: 28rpx;
						color: #999999;
						margin-top: 10rpx;
					}
				}
				.bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;
					.price {
						font-size: 28rpx;
						color: #FF3F42;
						line-height: 28rpx;
					}
					.num {
						font-size: 28rpx;
						color: #333333;
						line-height: 28rpx;
					}
				}
			}
		}
	}
	.order-container {
		padding: 20rpx;
		.title {
			font-size: 32rpx;
			color: #333333;
			line-height: 32rpx;
			padding-bottom: 20rpx;
		}
		.item1 {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 60rpx;
			.left {
				display: flex;
				.label {
					flex-shrink: 0;
					width: 140rpx;
				}
			}
			.copy {
				color: #FE781F;
			}
		}
		.item2 {
			display: flex;
			align-items: center;
			height: 60rpx;
			.label {
				flex-shrink: 0;
				width: 140rpx;
			}
			.red {
				color: #FE781F;
			}
		}
		.item3 {
			display: flex;
			min-height: 60rpx;
			margin-top: 10rpx;
			.label {
				flex-shrink: 0;
				width: 140rpx;
			}
		}
	}
</style>
