<template>
    <view class="">
        <!-- 订单状态 -->
        <view class="order-statl">
        	{{ order.state_text || order.status_text }}
        	<image v-if="order.state == 'UNPAY'" src="/static/icon/order_icon_00.png" class="order-statl-icon"></image>
        	<image v-else-if="order.state == 'PAID'" src="/static/icon/order_icon_01.png" class="order-statl-icon"></image>
        	<image v-else-if="order.state == 'COMPLETED'" src="/static/icon/order_icon_02.png" class="order-statl-icon"></image>
            <image v-else src="/static/icon/order_icon_02.png" class="order-statl-icon"></image>
        </view>
        
        <!-- 收货人 -->
        <view class="order-address" v-if="order.express != '' && order.express != null">
        	<image class="address-icon" src="https://storage.funnyzhibo.com/images/2020/05/06/address_icon.png" mode="widthFix"></image>
        	<view class="order-address-name nowrap">
        		收货人：{{ order.express.name }}
        		<text>{{ order.express.mobile }}</text>
        	</view>
        	<view class="order-address-text">{{ order.express.address }}</view>
        	<image class="order-address-back" src="/static/img/address_back.png" mode="widthFix"></image>
        </view>
        
        <view class="order-goods">
        	<view class="goods-goods-li">
        		<image v-if="order.items" class="goods-img" :src="order.items.cover" mode="aspectFill"></image>
                <image v-else-if="order.source" class="goods-img" :src="order.source.right.cover" mode="aspectFill"></image>
                
        		<view class="goods-body">
        			<view v-if="order.items" class="goods-name nowrap">{{ order.items.title }}</view>
                    <view v-else-if="order.source" class="goods-name nowrap">{{ order.source.right.title }}</view>
                    
        			<view class="goods-price nowrap">
                        ￥<block v-if="order.items">{{ order.items.price }}</block>
                        <block v-else-if="order.source">{{ order.source.welfare.price }}</block>
        				<text class="goods-qty" v-if="order.items">×{{ order.items.qty }}</text>
                        <text class="goods-qty" v-else>×1</text>
        			</view>
        		</view>
        	</view>
        </view>
        
        <view class="order-total">
        	<view class="order-total-li order-type">
        		权益类型
        		<text>{{ order.type_text || order.type_text }}</text>
        	</view>
        	<view class="order-total-li">
        		订单号
        		<text @tap="copyText(order.orderid)">{{ order.orderid }}</text>
        	</view>
        	<view class="order-total-li">
        		下单时间
        		<text>{{ order.created_at }}</text>
        	</view>
        </view>
        <view class="order-total">
        	<view class="order-total-li">
        		实际支付
        		<text class="redCor" v-if="order.total">￥{{ order.total }}</text>
                <text class="redCor" v-else-if="order.source">￥{{ order.source.welfare.price }}</text>
        	</view>
        </view>
        
        <view class="order-data-footer" :class="{iphoneX : statusHeight > 30}">
        	<view class="order-btn" @tap="orderRun">返回订单</view>
        </view>
    </view>
</template>

<script>
    import clipboard from "@/js_sdk/ican-clipBoard/ican-clipBoard.js"
    import { show, welfaresShow } from '@/apis/interfaces/user'
    export default {
    	data() {
    		return {
                statusHeight : '',
                orderId      : '',  // 订单id
                order        : '',  // 订单详情
                orderType    : ''   // 订单来源
            }
        },
        onLoad(options) {
            // 获取商品活动订单详情
            this.orderType = options.orderType
            this.orderId   = options.id
            this.orderInfo();
        },
        methods:{
            // 商品活动订单详情
            orderInfo() {
                let url = ''
                if(this.orderType == 'welfare' || this.orderType == 'welfareGoods') url = welfaresShow
                if(this.orderType == 'rights' || this.orderType == 'rightsCoupons') url = show
                
                url(this.orderId).then(res=>{
                    this.order = res
                }).catch(err => {});
            },
            
            // 返回上一页
            orderRun() {
                uni.navigateBack({
                    delta: 1
                })
            },
            
            // 复制快递单号
            copyText (id) {
                wx.setClipboardData({
                    data    : id,
                    success : res=> {
                       uni.showToast({
                           title: '复制成功',
                           icon: 'none'
                       })
                    }
                })
            }
        },
    }
</script>

<style lang="scss" scoped>
     .order-statl{
        background-color: #f57e32;
        padding: 0 30rpx 10rpx;
        color: white;
        line-height: 90rpx;
        height: 90rpx;
        position: relative;
    }
    
    .order-statl-icon{
        width: 80rpx;
        height: 80rpx;
        vertical-align: middle;
        position: absolute;
        right: 30rpx;
        top: 5rpx;
    }
    
     /* 收货人信息 */
    .order-address{
        padding: 30rpx 30rpx 40rpx 100rpx;
        position: relative;
        background: white;
    }
    
    .order-address-back{
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        vertical-align:bottom;
    }
    
    .order-address-name{
        padding-right: 300rpx;
        position: relative;
        font-size: 33rpx;
        padding-bottom: 10rpx;
        text{
            position: absolute;
            right: 0;
            top: 0;
            width: 280rpx;
            text-align: right;
        }
    }
    
    .order-address-text{
        color: #464854;
        font-size: 26rpx;
    }
    
    .address-icon,
    .arrows-right{
        position: absolute;
    }
    
    .address-icon{
        height: 42rpx;
        width: 42rpx;
        left: 30rpx;
        top: calc(50% - 26rpx);
        top: -webkit-calc(50% - 26rpx);
    }
    
    .arrows-right{
        height: 28rpx;
        width: 28rpx;
        right: 30rpx;
        top: calc(50% - 19rpx);
        top: -webkit-calc(50% - 19rpx);
    }
    
    .order-add-address{
        text-align: center;
        padding: 30rpx 0;
    }
    
    .order-add-address navigator{
        display: inline-block;
        background: #e92344;
        color: white;
        line-height: 60rpx;
        padding: 0 30rpx;
        margin-right: 20rpx;
    }
    
    /* 订单商品 */
    
    .order-content{
        border-bottom: solid 100rpx transparent;
    }
    
    .order-goods{
        margin-bottom: 20rpx;
    }
    
    .goods-goods-mall{
        padding: 20rpx 30rpx 0 30rpx;
        line-height: 50rpx;
        image{
            width: 48rpx;
            height: 48rpx;
            vertical-align: middle;
            margin-right: 15rpx;
            margin-bottom: 2rpx;
        }
    }
    
    .goods-goods-li{
        padding: 20rpx 30rpx;
        position: relative;
        border-bottom: solid 1rpx #f2f2f2;
        min-height: 130rpx;
        background: white;
    }
    
    .goods-goods-li:last-child{
        border-bottom: none;
    }
    
    .goods-img{
        position: absolute;
        top: 20rpx;
        left: 30rpx;
        height: 130rpx;
        width: 130rpx;
        background: #f5f6fa;
    }
    
    .goods-body{
        padding-left: 150rpx;
    }
    
    .goods-name{
        font-weight: bold;
        padding: 10rpx 0 20rpx;
    }
    
    .goods-price{
        color: #e92344;
    }
    
    .goods-qty{
        color: gray;
        font-weight: normal;
        padding-left: 10rpx;
        font-size: 28rpx;
    }
    
    .goods-params{
        color: gray;
        padding-bottom: 20rpx;
        font-size: 28rpx;
    }
    
    /* 统计信息 */
    
    .order-total{
        background: white;
        margin: 20rpx 0;
    }
    
    .order-total-li{
        padding: 0 30rpx;
        line-height: 90rpx;
        position: relative;
        font-size: 28rpx;
    }
    
    .order-total-li::before{
        position: absolute;
        content: " ";
        left: 30rpx;
        bottom: 0;
        right: 0;
        height: 1rpx;
        background: #f2f2f2;
    }
    
    .order-total-li:last-child::before{
        display: none;
    }
    
    .order-total-li text{
        float: right;
        color: #999;
    }
    
    .order-total-li .redCor {
        color: #e92344;
        font-size: 32rpx;
    }
    
    .order-type text {
        color: #e92344;
    }
    
    /* 底部工具栏 */
    .order-data-footer{
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        border-top: solid 1rpx #f2f2f2;
        padding-top: 17rpx;
        padding-right: 30rpx;
        padding-left: 30rpx;
        height: 83rpx;
        background: white;
        display: flex;
        flex-wrap: wrap;
        flex-direction:row-reverse;
    }
    
    .order-data-footer.iphoneX {
        padding-bottom: 30rpx;
    }
    
    .order-btn{
        margin-left: 20rpx;
        height: 54rpx;
        line-height: 50rpx;
        box-sizing: border-box;
        border:solid 1rpx #747788;
        padding: 0 20rpx;
        font-size: 26rpx;
        border-radius: 40rpx;
        margin-top: 10rpx;
    }
    
    .order-btn-back {
        border-color: #f57e32;
        color: #f57e32;
    }
</style>
