Răsfoiți Sursa

fix(退款): 修复退款弹窗数据绑定和接口调用问题

- 将商品列表数据源从 `order.products` 改为 `order.detailList`
- 更新商品信息显示字段(cover、bookName、isbn)
- 修正数量绑定字段从 `qty` 改为 `num`
- 添加退款提交的加载状态和实际接口调用
- 修复运费退款初始值和最大值的设置
- 在退款成功后触发父组件的 `fetchData` 刷新订单列表
- 防止订单日志组件初始自动加载
ylong 1 lună în urmă
părinte
comite
e9f0d7976c

+ 1 - 0
src/views/mallOrder/all/components/order-log.vue

@@ -6,6 +6,7 @@
             :pageConfig="pageConfig"
             :columns="columns"
             :tools="false"
+            :initLoad="false"
             height="400px"
             :body-style="{padding:0}"
         >

+ 41 - 12
src/views/mallOrder/all/components/refund-dialog.vue

@@ -3,21 +3,21 @@
         <div class="refund-container">
             <div class="section-title">选择要退款的商品及数量</div>
 
-            <el-table ref="tableRef" :data="order?.products || []"
+            <el-table ref="tableRef" :data="order?.detailList || []"
                 style="width: 100%; border: 1px solid #ebeef5; border-bottom: none;"
                 @selection-change="handleSelectionChange" header-row-class-name="custom-header">
                 <el-table-column type="selection" width="55" />
                 <el-table-column label="商品信息">
                     <template #default="{ row }">
                         <div class="product-info">
-                            <el-image :src="row.image" class="product-img" fit="cover" />
-                            <span class="product-title">{{ row.title }}</span>
+                            <el-image :src="row.cover" class="product-img" fit="cover" />
+                            <span class="product-title">{{ row.bookName }} {{ row.isbn }}</span>
                         </div>
                     </template>
                 </el-table-column>
                 <el-table-column label="数量" width="150">
                     <template #default="{ row }">
-                        <el-input-number v-model="row.refundQty" :min="1" :max="row.qty" size="small"
+                        <el-input-number v-model="row.refundQty" :min="1" :max="row.num" size="small"
                             controls-position="right" style="width: 100px;" />
                     </template>
                 </el-table-column>
@@ -55,7 +55,7 @@
 
         <template #footer>
             <el-button @click="visible = false">取消</el-button>
-            <el-button type="primary" @click="handleSubmit">确定并退款</el-button>
+            <el-button type="primary" @click="handleSubmit" :loading="loading">确定并退款</el-button>
         </template>
     </ele-modal>
 </template>
@@ -63,6 +63,7 @@
 <script setup>
     import { ref, reactive, computed, watch } from 'vue';
     import { EleMessage } from 'ele-admin-plus/es';
+    import request from '@/utils/request';
 
     const visible = defineModel({ type: Boolean });
     const order = ref(null);
@@ -70,18 +71,22 @@
     const shippingRefund = ref(0);
     const sendCoupon = ref(true);
     const maxShippingFee = ref(5);
+    const loading = ref(false);
+    
+    const emit = defineEmits(['success']);
 
     const handleOpen = (row) => {
         // Deep copy to avoid mutating original list directly until save
         if (row) {
             order.value = JSON.parse(JSON.stringify(row));
             // Initialize refundQty for each product
-            if (order.value.products) {
-                order.value.products.forEach(p => {
-                    p.refundQty = p.qty; // Default to max qty
+            if (order.value.detailList) {
+                order.value.detailList.forEach(p => {
+                    p.refundQty = p.num; // Default to max qty
                 });
             }
-            shippingRefund.value = 0;
+            shippingRefund.value = order.value.expressMoney || 0;
+            maxShippingFee.value = order.value.expressMoney || 0;
             sendCoupon.value = true;
             selectedRows.value = [];
         }
@@ -111,7 +116,7 @@
     });
 
     const originalTotal = computed(() => {
-        return order.value?.payment?.total || 0;
+        return parseFloat(order.value?.payMoney) || 0;
     });
 
     const newTotal = computed(() => {
@@ -131,8 +136,32 @@
             return;
         }
 
-        EleMessage.success('退款申请已提交');
-        visible.value = false;
+        loading.value = true;
+        const detailList = selectedRows.value.map(item => ({
+            isbn: item.isbn,
+            conditionType: item.conditionType,
+            num: item.refundQty
+        }));
+
+        request.post('/shop/shopOrder/refundOutOfStock', {
+            orderId: order.value.orderId,
+            refundExpressMoney: shipping,
+            sendCoupon: sendCoupon.value ? 1 : 0,
+            detailList: detailList
+        }).then(res => {
+            if (res.data.code === 200) {
+                EleMessage.success('退款申请已提交');
+                visible.value = false;
+                emit('success');
+            } else {
+                EleMessage.error(res.data.msg || '提交失败');
+            }
+        }).catch(e => {
+            console.error(e);
+            EleMessage.error('网络错误');
+        }).finally(() => {
+            loading.value = false;
+        });
     };
 
     defineExpose({

+ 1 - 1
src/views/mallOrder/all/index.vue

@@ -30,7 +30,7 @@
         <!-- Dialogs -->
         <order-detail ref="detailRef" />
         <push-sms-dialog ref="smsRef" />
-        <refund-dialog ref="refundRef" />
+        <refund-dialog ref="refundRef" @success="fetchData" />
         <add-package-dialog ref="packageRef" />
         <order-log ref="logRef" />
         <order-remarks ref="remarkRef" @refresh="fetchData" />