wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
    <cl-page>
        <view class="page">
            <view class="card">
                <cl-list-item label="申请原因" :arrow-icon="false" :margin="[0, -20, 0, 0]">
                    <cl-select-popup
                        v-model="form.reason"
                        :border="false"
                        :options="list"
                        title="选择申请原因"
                    />
                </cl-list-item>
 
                <cl-list-item label="退款金额" :arrow-icon="false">
                    <cl-text type="price" :size="40" color="error" :value="refundAmount || 0" />
                </cl-list-item>
            </view>
 
            <goods-group :data="info?.goodsList" readonly />
        </view>
 
        <cl-footer>
            <cl-button custom type="primary" :loading="loading" @tap="submit">提交</cl-button>
        </cl-footer>
    </cl-page>
</template>
 
<script lang="ts" setup>
import { computed, reactive, ref } from "vue";
import { useCool, useStore } from "/@/cool";
import { onReady } from "@dcloudio/uni-app";
import { useUi } from "/$/cool-ui";
import GoodsGroup from "/@/components/goods/group.vue";
 
const { service, router } = useCool();
const ui = useUi();
const { dict } = useStore();
 
// 表单
const form = reactive({
    reason: "",
});
 
// 提交中
const loading = ref(false);
 
// 订单信息
const info = ref<OrderInfo>();
 
// 退款金额
const refundAmount = computed(() => {
    return info.value?.goodsList?.reduce((a, b) => {
        return a + b.price * b.count;
    }, 0);
});
 
// 原因列表
const list = computed(() => {
    return dict.get("orderRefundReason").map((e) => {
        return {
            label: e.label,
            value: e.label,
        };
    });
});
 
// 获取订单信息
async function refresh() {
    ui.showLoading();
 
    await service.order.info
        .info({
            id: router.query.orderId,
        })
        .then((res) => {
            info.value = res;
        })
        .catch((err) => {
            ui.showTips(err.message, () => {
                router.back();
            });
        });
 
    ui.hideLoading();
}
 
// 提交
async function submit() {
    if (!form.reason) {
        return ui.showToast("请选择申请原因");
    }
 
    loading.value = true;
 
    await service.order.info
        .refund({
            orderId: router.query.orderId,
            reason: form.reason,
        })
        .then(() => {
            ui.showTips("退款申请提交成功,等待商家处理", () => {
                router.back();
            });
        })
        .catch((err) => {
            ui.showToast(err.message);
        });
 
    loading.value = false;
}
 
onReady(() => {
    refresh();
});
</script>
 
<style lang="scss" scoped>
.page {
    padding: 24rpx;
 
    .goods {
        display: flex;
        padding: 24rpx;
    }
}
</style>