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-pay">
            <cl-row :margin="[16, 0, 32, 32]">
                <cl-text :size="22" color="info">合计费用</cl-text>
                <cl-text :size="46" bold :margin="[0, 6, 0, 6]">{{ paidAmount }}</cl-text>
                <cl-text :size="22" color="info">元</cl-text>
            </cl-row>
 
            <view class="list">
                <cl-radio-group fill v-model="type">
                    <cl-radio
                        v-for="item in order.payTypes"
                        :key="item.value"
                        :label="String(item.value)"
                        :height="80"
                    >
                        {{ item.label }}
                        <image class="icon" mode="aspectFill" :src="item.icon" />
                    </cl-radio>
                </cl-radio-group>
            </view>
 
            <cl-footer :fixed="false" :vt="[visible]">
                <cl-button custom type="primary" @tap="toPay">
                    确认支付{{ paidAmount }}元
                </cl-button>
            </cl-footer>
        </view>
    </cl-popup>
</template>
 
<script lang="ts" setup>
import { computed, ref } from "vue";
import { useOrder } from "/@/hooks";
import { useUi } from "/$/cool-ui";
 
const emit = defineEmits(["success"]);
 
const ui = useUi();
const order = useOrder();
 
// 是否可见
const visible = ref(false);
 
// 支付方式
const type = ref();
 
// 订单详情
const info = ref<OrderInfo>();
 
// 支付金额
const paidAmount = computed(() => {
    return (Number(info.value?.price) - Number(info.value?.discountPrice)).toFixed(2);
});
 
// 打开弹窗
function open(data: OrderInfo) {
    visible.value = true;
    info.value = data;
    type.value = String(
        order.payTypes.find((e) => e.value == data.payType)?.value ||
            order.payTypes[0].value
    );
}
 
// 关闭弹窗
function close() {
    visible.value = false;
}
 
// 提交支付
function toPay() {
    close();
 
    order
        .toPay(info.value?.id!, type.value)
        .then(() => {
            emit("success");
        })
        .catch((err) => {
            ui.showToast(err.message);
        });
}
 
defineExpose({
    open,
    close,
});
</script>
 
<style lang="scss" scoped>
.order-pay {
    .list {
        padding: 0 32rpx 32rpx 32rpx;
    }
 
    .icon {
        height: 56rpx;
        width: 56rpx;
        position: absolute;
        right: 0;
        top: calc(50% - 28rpx);
    }
}
</style>