<template>
    <view class="container">
        <view class="aftersales-switch">
            <view :class="'item ' + (showType == 1 ? 'active' : '')" @tap="switchTab" data-index="1">
                <view class="txt">申请中</view>
            </view>
            <view :class="'item ' + (showType == 2 ? 'active' : '')" @tap="switchTab" data-index="2">
                <view class="txt">处理中</view>
            </view>
            <view :class="'item ' + (showType == 3 ? 'active' : '')" @tap="switchTab" data-index="3">
                <view class="txt">已完成</view>
            </view>
            <view :class="'item ' + (showType == 4 ? 'active' : '')" @tap="switchTab" data-index="4">
                <view class="txt">已拒绝</view>
            </view>
        </view>
        <view class="no-aftersale" v-if="aftersaleList.length <= 0">
            <view class="c">
                <text>还没有呢</text>
            </view>
        </view>

        <view class="aftersales">
            <navigator :url="'../aftersaleDetail/aftersaleDetail?id=' + item.aftersale.orderId" class="aftersale" v-for="(item, index) in aftersaleList" :key="index">
                <view class="h">
                    <view class="l">售后编号：{{ item.aftersale.aftersaleSn }}</view>
                </view>

                <view class="goods" v-for="(gitem, index1) in item.goodsList" :key="index1">
                    <view class="img">
                        <image :src="gitem.picUrl"></image>
                    </view>

                    <view class="info">
                        <text class="name">{{ gitem.goodsName }}</text>
                        <text class="number">{{ gitem.number }}件商品</text>
                    </view>

                    <view class="status"></view>
                </view>

                <view class="b">
                    <view class="l">申请退款金额：￥{{ item.aftersale.amount }}元</view>
                </view>
            </navigator>
        </view>
    </view>
</template>

<script>
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
export default {
    data() {
        return {
            aftersaleList: [],
            showType: 1,
            page: 1,
            limit: 10,
            totalPages: 1,

            gitem: {
                picUrl: '',
                goodsName: '',
                number: ''
            }
        };
    },
    onLoad: function (options) {},
    onReachBottom() {
        if (this.totalPages > this.page) {
            this.setData({
                page: this.page + 1
            });
            this.getAftersaleList();
        } else {
            uni.showToast({
                title: '没有更多售后了',
                icon: 'none',
                duration: 2000
            });
            return false;
        }
    },
    onReady: function () {
        // 页面渲染完成
    },
    onShow: function () {
        // 页面显示
        this.getAftersaleList();
    },
    onHide: function () {
        // 页面隐藏
        this.setData({
            aftersaleList: []
        });
    },
    onUnload: function () {
        // 页面关闭
    },
    methods: {
        getAftersaleList() {
            let that = this;
            util.request(api.AftersaleList, {
                status: that.showType,
                page: that.page,
                limit: that.limit
            }).then(function (res) {
                if (res.errno === 0) {
                    console.log(res.data);
                    that.setData({
                        aftersaleList: that.aftersaleList.concat(res.data.list),
                        totalPages: res.data.pages
                    });
                }
            });
        },

        switchTab: function (event) {
            let showType = event.currentTarget.dataset.index;
            this.setData({
                aftersaleList: [],
                showType: showType,
                page: 1,
                limit: 10,
                totalPages: 1
            });
            this.getAftersaleList();
        }
    }
};
</script>
<style>
page {
    height: 100%;
    width: 100%;
    background: #f4f4f4;
}

.aftersales-switch {
    width: 100%;
    background: #fff;
    height: 84rpx;
}

.aftersales-switch .item {
    display: inline-block;
    height: 82rpx;
    width: 25%;
    padding: 0 15rpx;
    text-align: center;
}

.aftersales-switch .item .txt {
    display: inline-block;
    height: 82rpx;
    padding: 0 20rpx;
    line-height: 82rpx;
    color: #999;
    font-size: 28rpx;
    width: 140rpx;
}

.aftersales-switch .item.active .txt {
    color: #d77958;
    border-bottom: 4rpx solid #d77958;
}

.no-aftersale {
    width: 100%;
    height: auto;
    margin: 0 auto;
}

.no-aftersale .c {
    width: 100%;
    height: auto;
    margin-top: 400rpx;
}

.no-aftersale .c text {
    margin: 0 auto;
    display: block;
    width: 258rpx;
    height: 29rpx;
    line-height: 29rpx;
    text-align: center;
    font-size: 29rpx;
    color: #999;
}

.aftersales {
    height: auto;
    width: 100%;
    overflow: hidden;
}

.aftersale {
    margin-top: 20rpx;
    background: #fff;
}

.aftersale .h {
    height: 83.3rpx;
    line-height: 83.3rpx;
    margin-left: 31.25rpx;
    padding-right: 31.25rpx;
    border-bottom: 1px solid #f4f4f4;
    font-size: 30rpx;
    color: #333;
}

.aftersale .h .l {
    float: left;
}

.aftersale .h .r {
    float: right;
    color: #b4282d;
    font-size: 24rpx;
}

.aftersale .goods {
    display: flex;
    align-items: center;
    height: 199rpx;
    margin-left: 31.25rpx;
}

.aftersale .goods .img {
    height: 145.83rpx;
    width: 145.83rpx;
    background: #f4f4f4;
}

.aftersale .goods .img image {
    height: 145.83rpx;
    width: 145.83rpx;
}

.aftersale .goods .info {
    height: 145.83rpx;
    flex: 1;
    padding-left: 20rpx;
}

.aftersale .goods .name {
    margin-top: 30rpx;
    display: block;
    height: 44rpx;
    line-height: 44rpx;
    color: #333;
    font-size: 30rpx;
}

.aftersale .goods .number {
    display: block;
    height: 37rpx;
    line-height: 37rpx;
    color: #666;
    font-size: 25rpx;
}

.aftersale .goods .status {
    width: 105rpx;
    color: #b4282d;
    font-size: 25rpx;
}

.aftersale .b {
    height: 103rpx;
    line-height: 103rpx;
    margin-left: 31.25rpx;
    padding-right: 31.25rpx;
    border-top: 1px solid #f4f4f4;
    font-size: 30rpx;
    color: #333;
}

.aftersale .b .l {
    float: left;
}

.aftersale .b .r {
    float: right;
}

.aftersale .b .btn {
    margin-top: 19rpx;
    height: 64.5rpx;
    line-height: 64.5rpx;
    text-align: center;
    padding: 0 20rpx;
    border-radius: 5rpx;
    font-size: 28rpx;
    color: #fff;
    background: #b4282d;
}
</style>
