<template>
    <view class="afterSales">
        <view class="service-content">
            <view class="service"> 本次售后服务将由<span>DT生态平台</span>为您提供服务 </view>
        </view>

        <view class="plane">
            <view class="plane-state">
                <uni-steps class="steps" active-color='#fff' :active="process.index" deactive-color='#fff'
                    :options="process.data" />
                <view class="title" v-if="refundInfo.state"> {{refundInfo.state.remark}}</view>
            </view>
        </view>

        <view class="goods-item">
            <image :src="goodsInfo.cover" mode="aspectFill" class="good-img" />
            <view class="item--content">
                <view class="title">{{goodsInfo.goods_name}}</view>
                <view class="sub_title" v-if="goodsInfo.shop">{{goodsInfo.shop.name}}</view>
                <view class="unit">
                    {{goodsInfo.unit}}
                </view>
                <view class=" number">
                    共 {{goodsInfo.qty}} 件
                </view>
            </view>
        </view>


        <view class="total">
            <view class="total-item grey">
                申请金额<text>{{refundInfo.refund_total || '0.00'}} DT</text>
            </view>
            <view class="total-item">
                合计退款<text>{{refundInfo.refund_total|| '0.00'}} DT</text>
            </view>
        </view>
        <view class="block info-box" v-if="type == 1">
            <view class="info-item">
                <view class="label">售后类型</view>
                <view class="content">{{refundInfo.type.text}}</view>
            </view>
            <view class="info-item">
                <view class="label">退款原因</view>
                <view class="content">{{refundInfo.log.title}}</view>
            </view>
        </view>
        <view class="block info-box" v-if="type == 2">
            <view class="info-item">
                <view class="label">售后类型</view>
                 <view class="content">{{refundInfo.type.text}}</view>
            </view>
            <view class="info-item">
                <view class="label">退货原因</view>
                <view class="content">{{refundInfo.log.title}}</view>
            </view>
            <view class="info-item">
                <view class="label">退货方式</view>
                <view class="content">自行寄回</view>
            </view>
        </view>
        <view class="total" v-if="refundInfo.shopAddress">
            <view class="total-item grey" @longtap='copy(refundInfo.shopAddress.shopUser+ "  "+refundInfo.shopAddress.shopMobile+"  "+refundInfo.shopAddress.shopAddress)'>
                <view class="title">寄件地址</view>
                <view class='address'>
                    {{refundInfo.shopAddress.shopUser}} {{refundInfo.shopAddress.shopMobile}} {{refundInfo.shopAddress.shopAddress}}
                    <text>（长按文字复制）</text>
                </view>
            </view>
        </view>
        <view class="block info-box" v-if="refundInfo.can  && refundInfo.can.user_deliver"
            @click="$Router.push({name:'DeliverForm',params:{id:refundInfo.refund_no}})">
            <view class="info-item">
                <view class="label">完善物流</view>
                <uni-icons type="right" color="#333" />
            </view>
        </view>
        <view class="block info-box" @click="$Router.push({'name':'RefundHistory',params:{id:refundInfo.refund_no}})">
            <view class="info-item">
                <view class="label">售后历史</view>
                <uni-icons type="right" color="#333" />
            </view>
        </view>
        <view class="block info-box">
            <view class="info-item">
                <view class="label">售后单号</view>
                <view class="content">{{refundInfo.refund_no}}</view>
            </view>
            <view class="info-item">
                <view class="label">申请时间</view>
                <view class="content">{{refundInfo.created_at}}</view>
            </view>
        </view>

    </view>
</template>

<script>
    import {
        refundsInfo
    } from '@/apis/interfaces/order.js'
    import eventBus from '../../utils/eventBus.js';
    export default {
        data() {
            return {
                id: '',
                remark: '',
                money: '',
                title: [],
                ttext: '请选择申请原因',
                tel: '',
                goodsInfo: {},
                type: '', // 1退款，2退货，3换货
                process: {},
                refundInfo: {}
            }
        },
        onShow(e) {
            this.id = this.$Route.query.id;
            this.refund();
        },

        methods: {
            refund() {
                refundsInfo(this.$Route.query.id).then(res => {
                    this.goodsInfo = res.items[0];
                    this.refundInfo = res;
                    this.type = res.type.state;
                    this.process = res.process
                    let title = ''
                    switch (res.type.state) {
                        case 1:
                            title = '退款详情'
                            break;
                        case 2:
                            title = '退货详情'
                            break;
                        case 3:
                            title = '换货详情'
                            break;
                    }
                    uni.setNavigationBarTitle({
                        title: title
                    })
                }).catch(err => {
                    uni.showToast({
                        title: err.message,
                        icon: 'none',
                        mask: true,
                    })
                })
            },
            
            copy(info){
                uni.setClipboardData({
                    data:info,
                    showToast:false,
                    success:()=>{
                        uni.showToast({
                            title:'复制成功',
                            icon:'none',
                            mask:true,
                        })
                    }
                })
            }
        }
    }
</script>

<style lang="scss">
    .history {}

    .applyBtn {
        width: 70%;
        background-color: $main-color;
        border-radius: 50rpx;
        text-align: center;
        padding: 20rpx $padding;
        color: #fff;
        position: relative;
        left: 10%;
        font-size: 32rpx;
        margin-top: $margin * 2;
        font-weight: bold;
    }

    .afterSales {
        background-color: #f9f9f9;
        min-height: 100vh;

        .plane {
            width: 100%;

            .plane-state {
                background: linear-gradient(to top right, #34ce98, #22aa98);
                display: flex;
                flex-direction: column;
                align-items: flex-start;
                justify-content: flex-start;
                box-sizing: border-box;
                padding: 60rpx $padding 40rpx $padding;

                .title {
                    font-size: 40rpx;
                    color: #FFFFFF;
                    font-weight: bold;
                    margin-top: 20rpx;
                }
            }

            .plane-history {
                height: 400rpx;
                padding: 40rpx $padding;
                background-color: #fff;
            }
        }

        .service-content {
            background-color: #Fff;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;

            .service {
                font-size: 24rpx;
                margin: $margin;
                padding: 4rpx 20rpx;
                border-radius: 30rpx;
                background-color: #f9f9f9;
                display: inline-;
                text-align: center;
                color: #666;

                span {
                    color: $text-price;
                }
            }
        }

        .total {
            background-color: #fff;
            padding: 0 $padding $padding $padding;
            border-top: solid 2rpx #f9f9f9;
            font-size: 28rpx;
            color: #333;


            .total-item {
                width: 100%;
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: space-between;
                box-sizing: border-box;
                padding-top: $padding;
                font-size: 30rpx;

                .title {
                    width: 170rpx;
                }

                .address {
                    flex: 1;
                    text{
                       color: #84d4d6;
                       padding-left: 10rpx;
                       font-size: 26rpx;
                    }
                }
            }

            .grey {
                color: #666;
            }
        }

        .goods-item {
            background-color: #Fff;
            width: 100%;
            display: inline-block;
            // border-bottom: solid 1rpx #eee;

            // padding: $padding;
            padding-left: $padding;
            padding-top: $padding;
            padding-bottom: $padding - 15;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: flex-start;
            box-sizing: border-box;

            .good-img {
                width: 160rpx;
                height: 160rpx;
                border-radius: 10rpx;
            }

            .item--content {
                flex: 1;
                padding: $padding - 10;

                .number {
                    font-size: 28rpx;
                    color: #666;
                    padding-top: 20rpx;
                }

                &>.title {
                    font-size: 30rpx;
                    color: #333;
                    font-weight: bold;
                    // @extend .ellipsis-1;
                }

                &>.sub_title {
                    color: #a05f0c;
                    font-size: 26rpx;
                    padding-top: 6rpx;
                    // @extend .ellipsis-1;
                }
                .unit{
                    color:#999;
                    font-size: 26rpx;
                    padding-top: 10rpx;
                }

                &>.price {
                    padding-top: 10rpx;
                    display: flex;
                    flex-direction: row;
                    align-items: flex-end;
                    justify-content: flex-end;
                    box-sizing: border-box;
                    font-weight: bold;
                    font-size: 36rpx;
                    color: $text-price;

                    // @extend .ellipsis-1;
                    .price-type {
                        display: flex;
                        flex-direction: row;
                        align-items: center;
                        justify-content: space-between;
                        box-sizing: border-box;
                        flex: 1;

                        text {
                            margin-right: $margin/2;
                            padding-left: 10rpx;
                            font-size: 60%;
                            padding-bottom: 4rpx;
                        }

                        .kucun {
                            color: $text-gray;
                            font-weight: normal;
                        }
                    }

                }
            }

        }
    }

    .apply-number {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        box-sizing: border-box;
        background-color: #fff;
        padding: $padding;
        border-radius: 0 0 30rpx 30rpx;

        .apply-number-title {
            font-size: 30rpx;
            font-weight: bold;

            text {
                font-size: 26rpx;
                color: grey;
                font-weight: normal;
            }
        }
    }

    .block {
        background: white;
        margin-top: 20rpx;
    }

    // 订单信息
    .info-box {
        .info-item {
            position: relative;
            padding: 40rpx $padding 40rpx 200rpx;
            font-size: $title-size-m;
            min-height: 40rpx;
            text-align: right;

            .radio {
                font-size: 28rpx;
                font-weight: bold;
            }

            .label {
                position: absolute;
                left: 40rpx;
                top: 40rpx;
                color: $text-gray;
            }

            .content {
                float: left;
                color: $text-gray;
            }

            .contentHeight {
                height: 120rpx;
            }

            .info-textarea {
                height: 120rpx;
                width: 100%;
                text-align: left;
                font-size: $title-size-m;
            }

            .info-textarea-m {
                height: 120rpx;
                width: 100%;
                text-align: left;
                font-size: 60rpx;
                font-weight: bold;
            }

            &::after {
                position: absolute;
                left: $margin;
                right: $margin;
                content: " ";
                height: 1rpx;
                bottom: 0;
                background: $border-color;
            }

            &:last-child::after {
                display: none;
            }

            .info-item-title {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: flex-end;
                box-sizing: border-box;
                font-size: 28rpx;
                font-weight: bold;

                .icons {
                    padding-top: 2rpx;
                    font-weight: normal;
                    margin-left: 10rpx;
                }
            }
        }
    }
</style>
