<template>
    <app-layout :title="pageTitle">
        <view class="order-id">
            <text class="title">订单编号：</text>
            <text class="value">{{ orderId }}</text>
        </view>
        <view class="price">
            <view class="title-box">申请退款</view>
            <view class="price-box">
                <text class="number">¥{{ utils.formatNumber(price, 2) }}</text>
                <view v-if="type == 'apply'" class="modify-icon" @click="postPriceModal = true">
                    <text class="iconfont icon-bianji"></text>
                    <text class="text">修改金额</text>
                </view>
            </view>
        </view>
        <view class="common-form-container explain">
            <block v-if="type == 'apply'">
                <view class="textarea-item">
                    <view class="title-box">
                        <text>需求说明</text>
                        <text class="desc">您还可输入{{ maxlength - content.length }}个字</text>
                    </view>
                    <view class="textarea-box">
                        <textarea
                            v-model="content"
                            :maxlength="maxlength"
                            class="textarea"
                            placeholder="请您详细填写需求说明"
                            placeholder-class="placeholder-style-3"
                        />
                    </view>
                </view>
            </block>
            <block v-else>
                <view class="textarea-item">
                    <view class="title-box">
                        <text>驳回原因</text>
                    </view>
                    <view class="textarea-box">
                        <text class="textarea">{{ content }}</text>
                    </view>
                </view>
            </block>
            <view class="upload-item">
                <block v-for="(item, index) in images" :key="index">
                    <view class="image-box">
                        <image class="image" :src="item.src" mode="aspectFill" />
                    </view>
                </block>
                <view v-if="type == 'apply'" class="image-box upload" @click="chooseImage">
                    <text class="iconfont icon-shangchuantupian"></text>
                    <text class="text">上传图片</text>
                </view>
            </view>
        </view>
        <view v-if="type == 'apply'" class="common-save-form-btn">
            <view class="btn" @click="save">提交</view>
        </view>
        <widget-modal v-show="postPriceModal" title="修改退款金额" @close="postPriceModal = false">
            <view class="price-box">
                <view class="price-input">
                    <view class="input-box">
                        <input
                            class="input"
                            type="number"
                            v-model="price"
                            placeholder="请输入退款金额"
                            placeholder-class="placeholder-style-3"
                        />
                        <text class="iconfont icon-qingchu" @click="price = 0"></text>
                    </view>
                    <text class="util">元</text>
                </view>
                <view class="submit-price">
                    <text>确认</text>
                </view>
            </view>
        </widget-modal>
    </app-layout>
</template>

<script>
import AppLayout from "@/components/layout/layout";
import WidgetModal from "@/components/widgets/modal";
export default {
    name: "order-refund",
    data() {
        return {
            utils: this.$utils,
            type: "apply",
            pageTitle: "申请退款",
            postPriceModal: false,
            maxlength: 200,
            id: 1,
            orderId: "xxgfdkgn1223",
            price: 306,
            content: "这个是申请内容",
            images: [],
        };
    },
    components: {
        AppLayout,
        WidgetModal,
    },
    onLoad(e) {
        if (e.type && e.type == "reason") {
            this.type = "reason";
            this.pageTitle = "未通过原因";
            uni.setNavigationBarTitle({
                title: this.pageTitle,
            });
        }
    },
    onShow() {},
    onReady() {},
    onReachBottom() {},
    onPullDownRefresh() {},
    methods: {
        chooseImage() {
            uni.chooseImage({
                sizeType: ["compressed"],
                sourceType: ["album"],
                success(res) {
                    console.log(JSON.stringify(res.tempFilePaths));
                },
            });
        },
    },
};
</script>

<style lang="less" scoped>
.order-id {
    width: 100%;
    box-sizing: border-box;
    background-color: #ffffff;
    .title {
        font-size: 28rpx;
        color: #999999;
    }
}
.order-id {
    padding: 22rpx 40rpx;
    margin-bottom: 18rpx;
    .value {
        font-size: 28rpx;
        color: #000000;
    }
}
.price {
    width: 100%;
    box-sizing: border-box;
    padding: 40rpx;
    margin-bottom: 18rpx;
    background-color: #ffffff;
    .title-box {
        font-size: 28rpx;
        color: #000000;
    }
    .price-box {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 20rpx;
        .number {
            font-size: 48rpx;
            font-weight: bold;
            color: #000000;
        }
    }
    .modify-icon {
        display: flex;
        align-items: center;
        flex-direction: column;
        .iconfont {
            font-size: 46rpx;
            color: #999999;
        }
        .text {
            display: inline-block;
            font-size: 24rpx;
            color: #999999;
            margin-top: 6rpx;
        }
    }
}
.common-form-container.explain {
    width: 100%;
    margin-top: 0;
    .textarea-item {
        padding: 30rpx 40rpx;
        .title-box {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .desc {
            font-size: 24rpx;
            color: #999999;
        }
        .textarea-box {
            border: 0;
        }
        .textarea {
            padding: 0;
        }
    }
    .upload-item {
        padding: 0 40rpx 30rpx 40rpx;
    }
}
.price-box {
    .submit-price {
        width: 100%;
        height: 68rpx;
        background: #7286f1;
        text-align: center;
        line-height: 68rpx;
        font-size: 32rpx;
        color: #ffffff;
    }
    .price-input {
        display: flex;
        justify-content: space-between;
        margin: 35rpx 0 50rpx 0;
        line-height: 72rpx;
        .input-box {
            display: flex;
        }
        .input {
            width: 450rpx;
            height: 72rpx;
            border: 2rpx solid #d8d8d8;
            box-sizing: border-box;
            padding: 4rpx;
            font-size: 30rpx;
            font-weight: bold;
            color: #000000;
            text-align: center;
        }
        .iconfont {
            margin-left: 18rpx;
        }
    }
}
</style>