feat: 订单详情交互对接

This commit is contained in:
duanshuwen
2025-08-02 13:59:29 +08:00
parent 7ff542e57a
commit 9d6abe3e2a
11 changed files with 2145 additions and 61 deletions

View File

@@ -23,8 +23,13 @@
<text class="value">{{ formattedAmount }}</text>
</view>
<!-- 根据订单状态动态显示按钮 -->
<button v-if="shouldShowButton" :class="buttonClass">
{{ buttonText }}
<button
v-if="shouldShowButton"
:class="['reserve-button', { loading: isLoading }]"
:disabled="isLoading"
@click="handleButtonClick"
>
{{ isLoading ? "处理中..." : buttonText }}
</button>
<view class="feedback">
<text @click="openFeedback">投诉反馈</text>
@@ -33,7 +38,13 @@
</template>
<script setup>
import { defineProps, computed } from "vue";
import { defineProps, computed, ref } from "vue";
import {
preOrder,
orderPayNow,
orderCancel,
orderRefund,
} from "@/request/api/OrderApi";
// 支付方式映射常量
const PAY_WAY_MAP = {
@@ -42,6 +53,9 @@ const PAY_WAY_MAP = {
2: "云闪付",
};
// 加载状态
const isLoading = ref(false);
const props = defineProps({
orderData: {
type: Object,
@@ -86,18 +100,60 @@ const shouldShowButton = computed(() => {
return props.orderData.orderStatus !== "4"; // 4-退款中
});
// 按钮样式类逻辑
const buttonClass = computed(() => {
const status = props.orderData.orderStatus;
const baseClass = "reserve-button";
// 处理按钮点击事件
const handleButtonClick = async () => {
if (isLoading.value) return; // 防止重复点击
// 申请退款状态待使用状态保持原样式其他状态添加pre-btn类
if (status === "2") {
return baseClass; // 申请退款状态,背景色不变
} else {
return `${baseClass} pre-btn`; // 其他状态添加pre-btn样式
const status = props.orderData.orderStatus;
const orderId = props.orderData.orderId;
// 支付方式
const payWay = props.orderData.payWay;
// 支付渠道
const paySource = "1";
try {
isLoading.value = true;
if (status === "2") {
// 情况2待使用状态直接申请退款
await orderRefund({ orderId });
uni.showToast({
title: "退款申请已提交",
icon: "success",
});
} else {
// 情况1待支付状态或其他状态先预下单再支付
// 第一步:预下单
const res = await orderPayNow({ orderId, payWay, paySource });
console.log(res);
// 仅作为示例,非真实参数信息。
uni.requestPayment({
provider: "wxpay",
timeStamp: String(Date.now()),
nonceStr: "A1B2C3D4E5",
package: "prepay_id=wx20180101abcdefg",
signType: "MD5",
paySign: "",
success: (res) => {
console.log("success:" + JSON.stringify(res));
},
fail: (err) => {
console.log("fail:" + JSON.stringify(err));
},
});
}
} catch (error) {
console.error("操作失败:", error);
uni.showToast({
title: error.message || "操作失败,请重试",
icon: "none",
});
} finally {
isLoading.value = false;
}
});
};
// 投诉电话
const openFeedback = () => {