<template>
	<view>
		<!-- 商品信息 -->
		<block v-if="isRight(orderDetails)">
			<view class="bg-white">
				<skeleton :loading="skeletonLoading" :row="2" :showAvatar="false" :showTitle="true">
			
					<view class="flex justify-between align-start" style="padding: 32rpx 32rpx 30rpx 32rpx;">
						<image :src="orderDetails.goods.cover" mode="aspectFill" style="width: 240rpx; height: 240rpx;border-radius: 10rpx;"></image>
						<view class="flex-sub padding-left-sm">
							<view class="bref-box text-black1 lf-font-32 lf-font-bold" style="height: 88rpx;line-height: 44rpx;" v-if="orderDetails.goods.name">
								{{orderDetails.goods.name}} 
							</view>
							<text class="block text-gray lf-font-28" style="margin-top: 20rpx;line-height: 40rpx;">数量 <text class="margin-left margin-right-xs text-gray">x</text>{{orderDetails.number}}</text>
							
							<view class="flex justify-between" style="margin-top: 28rpx;">
								<lf-price :price="orderDetails.selling_price" /> 
								<view>
									<button v-if="orderDetails.state == 1" class="cu-btn line-orange text-orange round margin-left-sm lf-font-28" @tap.stop="$routerGo('/pages/order/confirm-atonce?type=1&goods_id='+orderDetails.goods_id+'&goods_specs_id='+orderDetails.goods_specs_id +'&order_id='+ orderDetails.id+'&order_number='+orderDetails.number)">立即付款</button>
									<button v-if="orderDetails.state == 2" class="cu-btn line-orange text-orange round margin-left-sm lf-font-28" @tap="$routerGo('/pages/order/apply-refund?order_id='+orderDetails.id)">申请退款</button>
									<button v-if="orderDetails.state == 5 ||  orderDetails.state == 7" class="cu-btn line-gray bg-white border round margin-left-sm lf-font-28">{{orderDetails.state_text.text}}</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 lf-font-32">订单编号</text>
						<view>
							<text class="margin-right lf-font-32 text-black1">{{orderDetails.order_sn}}</text>
							<text class="text-orange lf-font-32" @click="copy(orderDetails.order_sn)">复制</text>
						</view>
					</view>
					<view class="cu-bar padding-lr solid-bottom">
						<text class="text-gray lf-font-32">下单时间</text>
						<text class="lf-font-32 text-black1">{{orderDetails.created_at_text}}</text>
					</view>
					<view class="cu-bar padding-lr solid-bottom" v-if="orderDetails.payment_at_text != ''">
						<text class="text-gray lf-font-32">付款时间</text>
						<text class="lf-font-32 text-black1">{{orderDetails.payment_at_text}}</text>
					</view>
					<view class="cu-bar padding-lr" v-if="orderDetails.payment_type != ''">
						<text class="text-gray lf-font-32">支付方式</text>
						<text class="lf-font-32 text-black1">{{orderDetails.payment_type}}</text>
					</view>
				</view>
				
				<self-line/>
				<view class="bg-white">
					<view class="cu-bar padding-lr">
						<text class="text-gray lf-font-32">优惠</text>
						<text class="lf-font-32 text-black1" v-if="orderDetails.coupons == null">暂无优惠</text>
					</view>
				</view>
				<self-line/>
				
				
				<view class="padding-lr padding-tb-sm bg-white flex justify-between align-center solid-top1 btn-bottom">
					<view class="flex align-center">
						<lf-price :price="orderDetails.amount" /> 
					</view>
					<view class="lf-font-32 text-black1">
						{{orderDetails.state_text.text}}
					</view>
				</view>
			</skeleton>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				skeletonLoading: true,
				order_id:1,
				orderDetails: {},
			}
		},
		computed: {
			total(){
				return this.num * this.price
			},
			isRight(){
				return function(val){
					return this.$shared.isRight(val);
				}
			}
		},
		onLoad(e) {
			this.order_id = e.order_id
			if(this.order_id) {
				this.getOrderDetails()
			}
		},
		methods: {
			getOrderDetails() {
				this.$http(this.API.API_ORDER_DETAILS, {order_id: this.order_id}).then(res => {
					if(res.code == 0) {
						this.orderDetails = res.data
						this.skeletonLoading = false
					}	
				}).catch(err => {
					setTimeout(() => {
						this.$toBack()
					},1000)
				});
			},
			// 点击复制
			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>
