<template>
	<view>
		<!-- 商品信息 -->
		<self-line/>
		<view class="bg-white padding-tb-sm">
			<skeleton :loading="skeletonLoading" :row="2" :showAvatar="false" :showTitle="true">

				<view class="flex justify-between align-start padding-top-sm padding-lr">
					<image v-if="orderDetails.goods.cover" :src="orderDetails.goods.cover" mode="aspectFill" style="width: 150rpx; height: 150rpx;"></image>
					<view class="flex-sub padding-left-sm">
						<view class="bref-box margin-top-xs" v-if="orderDetails.goods.name">
							{{orderDetails.goods.name}} 
						</view>
						<text class="block margin-top-sm text-gray text-sm">数量 <text class="margin-left margin-right-xs text-gray">x</text>{{orderDetails.number}}</text>
						
						<view class="flex justify-between margin-top-sm">
							<view class="text-red text-price text-lg">
								<amount :value="Number(orderDetails.selling_price || 0)" :is-round-up="false" :precision="2" :duration="800" transition></amount>
							</view>
							<view>
								<button v-if="orderDetails.state == 2" class="cu-btn line-orange round margin-left-sm text-sm" @tap="$routerGo('/pages/order/apply-refund')">申请退款</button>
								<button v-if="orderDetails.state == 5" class="cu-btn line-gray bg-white border round margin-left-sm text-sm">退款中</button>
							</view>
						</view>
					</view>
				</view>

			</skeleton>
		</view>
		
		<self-line/>
		<!-- 表单 -->
		<skeleton :loading="skeletonLoading" :row="10" :showAvatar="false" :showTitle="true">
			<view class="bg-white">
				<view class="cu-bar padding-lr solid-bottom flex justify-between align-center text-center">
					<text class="text-gray">订单编号</text>
					<view>
						<text class="margin-right">{{orderDetails.order_sn}}</text>
						<text class="text-orange text-sm" @click="copy(orderDetails.order_sn)">复制</text>
					</view>
				</view>
				<view class="cu-bar padding-lr solid-bottom">
					<text class="text-gray">下单时间</text>
					<text>{{orderDetails.created_at_text}}</text>
				</view>
				<view class="cu-bar padding-lr solid-bottom" v-if="orderDetails.payment_at_text != ''">
					<text class="text-gray">付款时间</text>
					<text>{{orderDetails.payment_at_text}}</text>
				</view>
				<view class="cu-bar padding-lr solid-bottom" v-if="orderDetails.payment_type != ''">
					<text class="text-gray">支付方式</text>
					<text>{{orderDetails.payment_type}}</text>
				</view>
			</view>
			
			<self-line/>
			<view class="bg-white">
				<view class="cu-bar padding-lr solid-bottom">
					<text class="text-gray">优惠</text>
					<text v-if="orderDetails.coupons == null">暂无优惠</text>
				</view>
			</view>
		</skeleton>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				base64Img: '',	//
				skeletonLoading: true,
				loading: false,
				orderId:1,
				orderDetails: {},
			}
		},
		computed: {
			total(){
				return this.num * this.price
			}
		},
		onLoad(e) {
			this.orderId = e.orderid
			if(this.orderId) {
				this.getOrderDetails()
			}
		},
		methods: {
			getOrderDetails() {
				this.$http(this.API.API_ORDER_DETAILS, {order_id: this.orderId}).then(res => {
					if(res.code == 0) {
						this.orderDetails = res.data
						this.skeletonLoading = false
					}
					
				}).catch(err => {
					
				});
			},
			// 点击复制
			copy(text) {
				uni.setClipboardData({
					data: text
				});
			},
			submit(){
				this.$routerGo('/pages/order/order?type=all')
			},
		},
		created() {
			
		}
	}
</script>

<style lang="scss" scoped>
	.bref-box {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
</style>
