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
<template>
    <cl-popup
        v-model="visible"
        direction="bottom"
        :border-radius="[32, 32, 0, 0]"
        :padding="0"
        title="请选择取消订单原因(必选)"
        show-close-btn
    >
        <view class="order-cancel">
            <scroll-view class="scroller" scroll-y>
                <view class="list">
                    <cl-radio-group v-model="remark" fill>
                        <cl-radio
                            v-for="(item, index) in dict.get('orderCancelReason')"
                            :key="index"
                            :label="item.label"
                            :height="80"
                        >
                            {{ item.label }}
                        </cl-radio>
                    </cl-radio-group>
                </view>
            </scroll-view>
 
            <cl-footer :fixed="false" :vt="[visible]">
                <cl-button
                    custom
                    type="primary"
                    :loading="loading"
                    :disabled="!remark"
                    @tap="submit"
                >
                    提交
                </cl-button>
            </cl-footer>
        </view>
    </cl-popup>
</template>
 
<script lang="ts" setup>
import { ref } from "vue";
import { useCool, useStore } from "/@/cool";
import { useUi } from "/$/cool-ui";
 
const emit = defineEmits(["success"]);
 
const { service } = useCool();
const { dict } = useStore();
const ui = useUi();
 
// 是否可见
const visible = ref(false);
 
// 取消中
const loading = ref(false);
 
// 备注
const remark = ref();
 
// 订单id
const orderId = ref();
 
// 打开弹窗
function open(data: OrderInfo) {
    visible.value = true;
    remark.value = "";
    orderId.value = data.id;
}
 
// 关闭弹窗
function close() {
    visible.value = false;
}
 
// 提交表单
async function submit() {
    loading.value = true;
 
    await service.order.info
        .cancel({
            orderId: orderId.value,
            remark: remark.value,
        })
        .then(() => {
            ui.showToast("订单取消成功");
            emit("success");
            close();
        })
        .catch((err) => {
            ui.showToast(err.message);
        });
 
    loading.value = false;
}
 
defineExpose({
    open,
    close,
});
</script>
 
<style lang="scss" scoped>
.order-cancel {
    .scroller {
        max-height: 60vh;
 
        .list {
            padding: 0 32rpx;
        }
    }
}
</style>