<template>
    <view class="content">
        <view class="header">
            <view class="tabs">
            	<view class="item" :class="{'show': listType == 'paid'}" @click="onTabs('paid')">待发货</view>
            	<view class="item" :class="{'show': listType == 'delivered'}" @click="onTabs('delivered')">已发货</view>
            	<view class="item" :class="{'show': listType == 'signed'}" @click="onTabs('signed')">已签收</view>
            </view>
        </view>
        <view class="order" v-if="orderArr.length > 0">
            <view class="While order-list" v-for="(item, index) in orderArr" :key="index">
                <view class="order-top">
                    <view class="order-top-number">{{ item.order_no }}</view>
                    <view class="order-top-tips">{{ item.state }}</view>
                </view>
                <view class="order-name" v-for="(goodItem, index) in item.items" :key="index">
                    <image class="order-img" :src="goodItem.sku.cover" mode="aspectFill"></image>
                    <view class="order-goods">
                        <view class="order-label">
                            <view class="nowrap order-label-name">
                                {{ goodItem.sku.goods_name }}
                            </view>
                            <view class="order-label-price">
                                ￥{{ goodItem.sku.price }}
                            </view>
                        </view>
                        <view class="order-specs">
                          x{{ goodItem.qty }}
                        </view>
                    </view>
                </view>
                <view class="order-text">
                    <view class="order-time">下单时间：{{ item.created_at }}</view>
                    <view class="order-price">合计金额：<text class="red">￥{{ item.amount }}</text></view>
                </view>
                <view class="order-btn">
                    <view class="order-btn-atn active" @click="orderSign(item.order_no)" v-if="item.can.sign == true">立即签收</view>
                    <view class="order-btn-atn" @click="$Router.push({name: 'OrderDetails', params: { orderNo: item.order_no, listType: listType}})">订单详情</view>
                </view>
            </view>
        </view>
        <view class="pack-center pages-hint" v-else>
            <image src="/static/imgs/coupon_null.png"></image>
            <view>暂无数据</view>
        </view>
    </view>
</template>

<script>
    import { orders, goodsSign } from '@/apis/interfaces/user'
	export default {
		data() {
			return {
                listType: 'paid',
				orderArr: [],   //订单列表
			}
		},
        onLoad() {
            this.listType = this.$Route.query.listType
            
            // 获取省市区列表
            this.ordersInfo();
        },
		methods: {
            // 商品详情数据
            ordersInfo() {
            	orders({
                    state: this.listType
                }).then(res => {
                    this.orderArr = res.data
            	}).catch(err => {
            		uni.showToast({
            			title: err.message,
            			icon: "none"
            		})
            	})
            },
            
            // 状态筛选
            onTabs(val){
            	if(this.listType === val) return
            	this.listType = val
                
            	// 商品详情数据
            	this.ordersInfo();
            },
            
            // 立即签收
            orderSign(orderNo) {
                goodsSign(orderNo).then(res => {
                    uni.showToast({
                    	title: '签收成功',
                    	icon: "none"
                    })
                    setTimeout(()=>{
                        // 商品详情数据
                        this.ordersInfo();
                    },2000)
                    
                }).catch(err => {
                	uni.showToast({
                		title: err.message,
                		icon: "none"
                	})
                })
            }
		}
	}
</script>

<style lang="scss" scoped>
    page {
        background-color: #f3f4f6;
    }
    
    .content{
    	overflow: hidden;
    	background: #f3f4f6;
        padding: 30rpx;
        box-sizing: border-box;
    }
    
    .While {
        border-radius: 10rpx;
        margin-bottom: 30rpx;
        background-color: #FFFFFF;
        padding: 0 30rpx;
        box-sizing: border-box;
        box-shadow: 0 0 10rpx rgba($color: #000000, $alpha: .05);
    }
    
    .order {
        margin-top: 90rpx;
    }
    
    .order-top {
        line-height: 90rpx;
        box-sizing: border-box;
        display: flex;
        font-size: 28rpx;
        border-bottom: 2rpx #f2f2f2 solid;
        .order-top-number {
            flex: 1;
        }
        .order-top-tips {
            font-size: 26rpx;
            color: #edb25f;
        }
    }
    
    .order-name {
        padding: 20rpx 0;
        box-sizing: border-box;
        position: relative;
        .order-img {
            width: 90rpx;
            height: 90rpx;
            margin-right: 20rpx;
            border-radius: 10rpx;
        }
        .order-goods {
            position: absolute;
            width: 100%;
            left: 0;
            top: 0;
            padding: 20rpx 20rpx 20rpx 110rpx;
            box-sizing: border-box;
            .order-label {
                display: flex;
                font-size: 30rpx;
                margin-bottom: 15rpx;
                .order-label-name {
                    flex: 1;
                    margin-right: 30rpx;
                }
                .order-label-price {
                    font-weight: 600;
                }
            }
            .order-specs {
                font-size: 24rpx;
                color: #919191;
                display: flex;
                text {
                    display: inline-block;
                    flex: 1;
                }
            }
        }
    }
    
    .order-text {
        font-size: 28rpx;
        line-height: 40rpx;
        display: flex;
        padding-bottom: 20rpx;
        border-top: 2rpx solid #f2f2f2;
        border-bottom: 2rpx solid #f2f2f2;
        padding-top: 20rpx;
        .order-time {
            color: #919191;
            font-size: 26rpx;
            flex: 1;
        }
        .order-price {
            text {
                font-weight: 600;
                color: #6d79ec;
            }
        }
    }
    
    .order-btn {
        text-align: right;
        padding: 30rpx 0;
        box-sizing: border-box;
        position: relative;
        .order-btn-atn {
            border: 2rpx solid #f2f2f2;
            border-radius: 40rpx;
            padding: 0 30rpx;
            height: 52rpx;
            line-height: 52rpx;
            color: #767676;
            display: inline-block;
            margin-left: 15rpx;
            font-size: 24rpx;
            &.active {
                color: #6d79ec;
                border-color: #bfc5ff;
            }
        }
    }
    
    // tabs
    .header{
    	position: fixed;
    	top: 0;
    	left: 0;
    	right: 0;
    	z-index: 99;
    	.tabs{
    		display: flex;
    		justify-content: space-around;
    		background: white;
    		padding: 15rpx 0;
    		font-size: $title-size-lg;
    		color: $text-gray;
    		.item{
    			height: 60rpx;
    			line-height: 60rpx;
    			&.show{
    				color: #6d79ec;
    				border-bottom: solid 4rpx #6d79ec;
    			}
    		}
    	}
    	// 类型
    	.tabs-type{
    		display: flex;
    		padding: 20rpx 30rpx;
    		background: white;
    		.item{
    			font-size: $title-size-sm;
    			height: 46rpx;
    			line-height: 46rpx;
    			border-radius: 23rpx;
    			padding: 0 ($padding - 10);
    			background: white;
    			margin-right: $margin/2;
    			color: $text-gray;
    			&.show{
    				background-color:#6d79ec;
    				color: #6d79ec;
    			}
    		}
    	}
    }
</style>
