feat:退款完成

This commit is contained in:
dzc committed 2025-08-28 12:41:55 +08:00
1 parent af8e6df1c0
commit 105679446a
4 files changed
+100 -53

No files matched your search

+6
View File
@@ -9,6 +9,12 @@ export function displayPrice(price: any, suffix: string = "元", fixed = 2) {
return (parsedNumber / 100.0).toFixed(fixed) + suffix
}
export function displayWeight(price: any, fixed = 2) {
if (typeof price === "undefined") return "0"
const parsedNumber = typeof price === "string" ? parseFloat(price) : price
return parsedNumber.toFixed(fixed)
}
/**
* 把显示价格改为分
* @param price
+17 -23
View File
@@ -10,23 +10,19 @@
<dict-select v-model="state.queryForm.status" dict-code="hard_sale_status" />
</el-form-item>
<el-form-item style="width: 300px" label="申请时间" prop="createTimeList">
<el-date-picker v-model="state.queryForm.createTimeList" value-format="YYYY-MM-DD" type="daterange" />
<el-date-picker v-model="state.queryForm.createTimeList" value-format="YYYY-MM-DD"
type="daterange" />
</el-form-item>
<el-form-item>
<el-button icon="Search" type="primary" @click="getDataList">{{ $t("common.queryBtn") }}</el-button>
<el-button icon="Search" type="primary" @click="getDataList">{{ $t("common.queryBtn")
}}</el-button>
<el-button icon="Refresh" @click="resetQuery">{{ $t("common.resetBtn") }}</el-button>
</el-form-item>
</el-row>
</el-form>
<el-table
:data="state.dataList"
v-loading="state.loading"
border
:cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle"
@selection-change="selectionChangHandle"
@sort-change="sortChangeHandle"
>
<el-table :data="state.dataList" v-loading="state.loading" border :cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle" @selection-change="selectionChangHandle"
@sort-change="sortChangeHandle">
<el-table-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="40" />
<el-table-column prop="username" label="用户" />
@@ -58,27 +54,25 @@
<el-table-column label="申请时间" align="center" width="180px" prop="createTime" />
<el-table-column label="操作" width="200">
<template #default="{ row }">
<el-button icon="ShoppingCartFull" text type="primary" @click="shopCarDialogRef.openDialog(row.orderId)">购物车</el-button>
<el-button icon="WalletFilled" v-auth="'hard_hardAfterSale_detail_view'" link type="primary" @click="doRefund(row)">
<el-button icon="ShoppingCartFull" text type="primary"
@click="shopCarDialogRef.openDialog(row.orderId)">购物车</el-button>
<el-button icon="WalletFilled" v-auth="'hard_hardAfterSale_detail_view'" link type="primary"
@click="doRefund(row)">
退款
</el-button>
<el-button
v-if="false"
icon="edit-pen"
text
type="primary"
v-auth="'hard_hardAfterSale_edit'"
@click="formDialogRef.openDialog(row.id)"
>
<el-button v-if="false" icon="edit-pen" text type="primary" v-auth="'hard_hardAfterSale_edit'"
@click="formDialogRef.openDialog(row.id)">
编辑
</el-button>
<el-button v-if="false" icon="delete" text type="primary" v-auth="'hard_hardAfterSale_del'" @click="handleDelete([row.id])">
<el-button v-if="false" icon="delete" text type="primary" v-auth="'hard_hardAfterSale_del'"
@click="handleDelete([row.id])">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
v-bind="state.pagination" />
</div>
<!-- 编辑、新增 -->
@@ -57,9 +57,13 @@ const openDialog = (id: string) => {
visible.value = true
state.orderId = id
nextTick(() => {
nextTick(async () => {
loading.value = true
await new Promise((resolve) => setTimeout(() => resolve(true), 500))
state.currentTab = data.tabs[0].name
refundTableRef.value?.getCarList(state.orderId)
refundFormRef.value?.resetFields()
loading.value = false
})
}
@@ -68,11 +72,11 @@ function tabClick(e: any) {
loading.value = true
try {
await new Promise((resolve) => setTimeout(() => resolve(true), 250))
switch (e.paneName) {
case "CAR":
refundTableRef.value?.getCarList(state.orderId)
break
}
// switch (e.paneName) {
// case "CAR":
// refundTableRef.value?.getCarList(state.orderId)
// break
// }
await new Promise((resolve) => setTimeout(() => resolve(true), 250))
} catch (error: any) {
console.log(error);
@@ -5,19 +5,29 @@
<el-table :data="state.dataList" border :cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle" @sort-change="sortChangeHandle" show-summary
:summary-method="getSummaries">
<el-table-column label="商品名" align="center" prop="productName" />
<el-table-column label="商品图片" align="center" prop="code">
<el-table-column label="商品名" width="120" align="center" prop="productName" />
<el-table-column label="商品图片" width="120" align="center" prop="code">
<template #default="{ row }">
<preview-image v-if="row.productPic" :src="row.productPic" />
<div v-else class="w-[60px] h-[60px]" />
</template>
</el-table-column>
<el-table-column width="120" label="商品类型" align="center" prop="productName">
<template #default="{ row }">
<dict-tag :options="supermarket_nature" :value="row.productNature" />
</template>
</el-table-column>
<el-table-column label="商品价格" align="center" prop="productPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.productPrice) }}</span>
</template>
</el-table-column>
<el-table-column label="商品数量" align="center" prop="productCount" />
<el-table-column label="商品数量" align="center" prop="productCount">
<template #default="{ row }">
<span v-if="row.productNature == 1">{{ row.productCount }}</span>
<span v-if="row.productNature == 2">{{ displayWeight(row.productWeight) }}kg</span>
</template>
</el-table-column>
<el-table-column label="商品总额" align="center" prop="totalPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.totalPrice) }}</span>
@@ -32,19 +42,29 @@
<el-table :data="refundSuccessList" border :cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle" @sort-change="sortChangeHandle" show-summary
:summary-method="getSummaries">
<el-table-column label="商品名" align="center" prop="productName" />
<el-table-column label="商品图片" align="center" prop="code">
<el-table-column label="商品名" width="120" align="center" prop="productName" />
<el-table-column label="商品图片" width="120" align="center" prop="code">
<template #default="{ row }">
<preview-image v-if="row.productPic" :src="row.productPic" />
<div v-else class="w-[60px] h-[60px]" />
</template>
</el-table-column>
<el-table-column label="商品类型" width="120" align="center" prop="productName">
<template #default="{ row }">
<dict-tag :options="supermarket_nature" :value="row.productNature" />
</template>
</el-table-column>
<el-table-column label="商品价格" align="center" prop="productPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.productPrice) }}</span>
</template>
</el-table-column>
<el-table-column label="已退款商品数量" align="center" prop="productCount" />
<el-table-column label="已退款商品数量" align="center" prop="productCount">
<template #default="{ row }">
<span v-if="row.productNature == 1">{{ row.productCount }}</span>
<span v-if="row.productNature == 2">{{ displayWeight(row.productWeight) }}kg</span>
</template>
</el-table-column>
<el-table-column label="已退款商品总额" align="center" prop="totalPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.totalPrice) }}</span>
@@ -62,13 +82,18 @@
<el-table :data="disposeDataList" border :cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle" @sort-change="sortChangeHandle" show-summary
:summary-method="getSummaries">
<el-table-column label="商品名" align="center" prop="productName" />
<el-table-column label="商品图片" align="center" prop="code">
<el-table-column label="商品名" width="120" align="center" prop="productName" />
<el-table-column label="商品图片" width="120" align="center" prop="code">
<template #default="{ row }">
<preview-image v-if="row.productPic" :src="row.productPic" />
<div v-else class="w-[60px] h-[60px]" />
</template>
</el-table-column>
<el-table-column label="商品类型" width="120" align="center" prop="productName">
<template #default="{ row }">
<dict-tag :options="supermarket_nature" :value="row.productNature" />
</template>
</el-table-column>
<el-table-column label="商品价格" align="center" prop="productPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.productPrice) }}</span>
@@ -77,13 +102,23 @@
<el-table-column label="退款商品数量" align="center" prop="refundProductCount">
<template #default="{ row }">
<div class="w-full h-full">
<!-- start 重量商品 start -->
<el-input-number size="small" v-if="row.productNature == 2"
v-model="row.refundProductCount" :min="0" :max="row.productCount" :step="0.1"
@change="handleRefundProductCount($event, row)" />
v-model="row.refundProductWeight" :min="0" :max="row.maxRefundProductWeight"
:step="0.01" @change="handleRefundProductCount($event, row)" />
<!-- end 重量商品 end -->
<!-- start 数量商品 start -->
<el-input-number size="small" v-else v-model="row.refundProductCount" :min="0"
:max="row.productCount" @change="handleRefundProductCount($event, row)" />
:max="row.maxRefundProductCount" @change="handleRefundProductCount($event, row)" />
<!-- end 数量商品 end -->
<div class="h-4">
<div v-if="row.productCount <= row.refundProductCount" class="color-danger text-xs">
<div v-if="row.productNature == 1 && row.refundProductCount >= row.maxRefundProductCount"
class="color-danger text-xs">
该商品已全部退款
</div>
<div v-if="row.productNature == 2 && row.refundProductWeight >= row.maxRefundProductWeight"
class="color-danger text-xs">
该商品已全部退款
</div>
</div>
@@ -104,8 +139,9 @@
<script setup lang="ts" name="RefundTable">
import { useMessage } from "/@/hooks/message"
import { BasicTableProps, useTable } from "/@/hooks/table"
import { useDict } from "/@/hooks/dict"
import { displayPrice } from "/@/utils/formatMoney"
import { displayPrice, displayWeight } from "/@/utils/formatMoney"
import * as hardCar from "/@/api/hard/hard-car"
@@ -118,6 +154,7 @@ const state: BasicTableProps = reactive<BasicTableProps>({
const refundSuccessList = ref<any>([])
const disposeDataList = ref<any>([])
const { supermarket_nature } = useDict("supermarket_nature")
// table hook
const { getDataList, sortChangeHandle, tableStyle } = useTable(state)
@@ -137,6 +174,9 @@ const getCarList = async (orderId: string) => {
return {
...item,
refundProductCount: 0,
maxRefundProductCount: item.productCount,
refundProductWeight: 0,
maxRefundProductWeight: displayWeight(item.productWeight),
refundTotalPrice: 0,
}
}).filter(Boolean)
@@ -145,21 +185,20 @@ const getCarList = async (orderId: string) => {
refundSuccessList.value = data
// 计算出需要退款的商品
const refundViewList = [...state.dataList]
for (const item of refundViewList) {
const target = data.find((v: any) => v.productId == item.productId)
if (!target) continue
// 购物车商品 - 已退款商品
item.productCount = item.productCount - target.productCount
item.totalPrice = item.totalPrice - target.totalPrice
}
disposeDataList.value = refundViewList.map((item) => {
if (!item) return null
const target = data.find((v: any) => v.productId == item.productId)
return {
...item,
refundProductCount: 0,
maxRefundProductCount: item.productCount - (target?.productCount ?? 0),
refundProductWeight: 0,
maxRefundProductWeight: displayWeight(item.productWeight - (target?.productWeight ?? 0)),
refundTotalPrice: 0,
}
}).filter(Boolean)
console.log("disposeDataList:", disposeDataList.value);
}
const handleRefundProductCount = (value: any, row: any) => {
@@ -177,15 +216,18 @@ const handleAllRefund = () => {
const target = state.dataList.find((item: any) => item.id == v.id)
if (!target) continue
v.refundProductCount = target.productCount
v.refundProductWeight = displayWeight(target.productWeight)
v.refundTotalPrice = target.totalPrice
}
console.log("全部:", _list);
disposeDataList.value = _list
}
const getSummaries = (param: any) => {
const { columns, data } = param
const totalColumns = ["productCount", "totalPrice", "totalPrice", "refundProductCount", "refundTotalPrice"]
const totalColumns = ["totalPrice", "totalPrice", "refundTotalPrice"]
const totalRow = Array.from({ length: columns.length }, () => "")
totalRow[0] = "合计"
columns.forEach((i: any, index: number) => {
@@ -206,10 +248,10 @@ const getSummaries = (param: any) => {
// 提交
const validate = async () => {
let valid = true
let valid = false
for (const v of disposeDataList.value) {
if (v.refundProductCount <= 0) {
valid = false
if (v.refundProductCount > 0 || v.refundProductWeight > 0) {
valid = true
break
}
}
@@ -222,6 +264,7 @@ const validate = async () => {
return {
...item,
productCount: item.refundProductCount,
productWeight: displayWeight(item.refundProductWeight),
totalPrice: item.refundTotalPrice,
}
})