feat:共富商城退款

This commit is contained in:
dzc committed 2025-10-31 17:55:05 +08:00
1 parent d1a4e1373e
commit f6b2a86ff9
1 file changed
+296 -263
@@ -1,139 +1,167 @@
<template>
<div class="refund-table">
<el-descriptions :column="1" title="购物车商品">
<el-descriptions-item labelClassName="no-colon">
<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="商品名" 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">
<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>
</template>
</el-table-column>
</el-table>
</el-descriptions-item>
</el-descriptions>
<div class="refund-table">
<el-descriptions :column="1" title="购物车商品">
<el-descriptions-item labelClassName="no-colon">
<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="商品名" 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">
<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>
</template>
</el-table-column>
</el-table>
</el-descriptions-item>
</el-descriptions>
<el-descriptions :column="1" title="已退款商品">
<el-descriptions-item labelClassName="no-colon">
<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="商品名" 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">
<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>
</template>
</el-table-column>
</el-table>
</el-descriptions-item>
</el-descriptions>
<el-descriptions :column="1" title="已退款商品">
<el-descriptions-item labelClassName="no-colon">
<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="商品名" 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">
<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>
</template>
</el-table-column>
</el-table>
</el-descriptions-item>
</el-descriptions>
<el-descriptions :column="1" title="退款商品">
<template #extra>
<el-button type="primary" text @click="handleAllRefund">全部退款</el-button>
</template>
<el-descriptions-item labelClassName="no-colon">
<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="商品名" 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="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.refundProductWeight" :min="0" :max="row.maxRefundProductWeight"
:step="0.01" @change="handleRefundProductCount($event, row)" />
<!-- end 重量商品 end -->
<el-descriptions :column="1" title="退款商品">
<template #extra>
<el-button type="primary" text @click="handleAllRefund">全部退款</el-button>
</template>
<el-descriptions-item labelClassName="no-colon">
<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="商品名" 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="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.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.maxRefundProductCount" @change="handleRefundProductCount($event, row)" />
<!-- end 数量商品 end -->
<div class="h-4">
<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>
</div>
</template>
</el-table-column>
<el-table-column label="退款商品总额" align="center" prop="refundTotalPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.refundTotalPrice) }}</span>
</template>
</el-table-column>
</el-table>
</el-descriptions-item>
</el-descriptions>
</div>
<!-- start 数量商品 start -->
<el-input-number
size="small"
v-else
v-model="row.refundProductCount"
:min="0"
:max="row.maxRefundProductCount"
@change="handleRefundProductCount($event, row)"
/>
<!-- end 数量商品 end -->
<div class="h-4">
<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>
</div>
</template>
</el-table-column>
<el-table-column label="退款商品总额" align="center" prop="refundTotalPrice">
<template #default="{ row }">
<span>{{ displayPrice(row.refundTotalPrice) }}</span>
</template>
</el-table-column>
</el-table>
</el-descriptions-item>
</el-descriptions>
</div>
</template>
<script setup lang="ts" name="RefundTable">
@@ -146,9 +174,9 @@ import { displayPrice, displayWeight } from "/@/utils/formatMoney"
import * as hardCar from "/@/api/hard/hard-car"
const state: BasicTableProps = reactive<BasicTableProps>({
createdIsNeed: false,
queryForm: {},
pageList: hardCar.getCarByOrderId,
createdIsNeed: false,
queryForm: {},
pageList: hardCar.getCarByOrderId,
})
const refundSuccessList = ref<any>([])
@@ -160,165 +188,170 @@ const { supermarket_nature } = useDict("supermarket_nature")
const { getDataList, sortChangeHandle, tableStyle } = useTable(state)
const getCarList = async (orderId: string) => {
state.queryForm.orderId = orderId
try {
// 获取订单商品列表
await getDataList()
if (!state.dataList || !state.dataList.length) {
return
}
// 获取已退款的商品
const { data } = await hardCar.refundCar({ orderId })
if (!data || !data.length) {
disposeDataList.value = state.dataList.map((item) => {
if (!item) return null
return {
...item,
refundProductCount: 0,
maxRefundProductCount: item.productCount,
refundProductWeight: 0,
maxRefundProductWeight: displayWeight(item.productWeight),
refundTotalPrice: 0,
}
}).filter(Boolean)
return
}
refundSuccessList.value = data
// 计算出需要退款的商品
const refundViewList = [...state.dataList]
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)
} catch (error: any) {
state.dataList = []
disposeDataList.value = []
refundSuccessList.value = []
}
state.queryForm.orderId = orderId
try {
// 获取订单商品列表
await getDataList()
console.log(state.dataList?.length, "state.dataList")
if (!state.dataList || !state.dataList.length) {
return
}
// 获取已退款的商品
const { data } = await hardCar.refundCar({ orderId })
if (!data || !data.length) {
disposeDataList.value = state.dataList
.map((item) => {
if (!item) return null
return {
...item,
refundProductCount: 0,
maxRefundProductCount: item.productCount,
refundProductWeight: 0,
maxRefundProductWeight: displayWeight(item.productWeight ?? 0),
refundTotalPrice: 0,
}
})
.filter(Boolean)
return
}
refundSuccessList.value = data
// 计算出需要退款的商品
const refundViewList = [...state.dataList]
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)
} catch (error: any) {
console.log(error)
state.dataList = []
disposeDataList.value = []
refundSuccessList.value = []
}
}
const handleRefundProductCount = (value: any, row: any) => {
const target = disposeDataList.value.find((item: any) => item.id == row.id)
if (!target) return
const { productPrice } = target
target.refundTotalPrice = productPrice * value
const target = disposeDataList.value.find((item: any) => item.id == row.id)
if (!target) return
const { productPrice } = target
target.refundTotalPrice = productPrice * value
}
// 全部退款
const handleAllRefund = () => {
if (!state.dataList || !state.dataList.length) return
const _list = [...disposeDataList.value]
for (const v of _list) {
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
}
disposeDataList.value = _list
if (!state.dataList || !state.dataList.length) return
const _list = [...disposeDataList.value]
for (const v of _list) {
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
}
disposeDataList.value = _list
}
const getSummaries = (param: any) => {
const { columns, data } = param
const totalColumns = ["totalPrice", "totalPrice", "refundTotalPrice"]
const totalRow = Array.from({ length: columns.length }, () => "")
totalRow[0] = "合计"
columns.forEach((i: any, index: number) => {
if (totalColumns.includes(i.property)) {
const total = data
.filter((v: any) => v[i.property] != null)
.map((v: any) => Number(v[i.property]))
.reduce((pren: number, next: number) => pren + next, 0)
if (i.property.includes("Price")) {
totalRow[index] = displayPrice(total)
} else {
totalRow[index] = total
}
}
})
return totalRow
const { columns, data } = param
const totalColumns = ["totalPrice", "totalPrice", "refundTotalPrice"]
const totalRow = Array.from({ length: columns.length }, () => "")
totalRow[0] = "合计"
columns.forEach((i: any, index: number) => {
if (totalColumns.includes(i.property)) {
const total = data
.filter((v: any) => v[i.property] != null)
.map((v: any) => Number(v[i.property]))
.reduce((pren: number, next: number) => pren + next, 0)
if (i.property.includes("Price")) {
totalRow[index] = displayPrice(total)
} else {
totalRow[index] = total
}
}
})
return totalRow
}
// 提交
const validate = async () => {
// 如果购物车为空直接返回true
if (!state.dataList || !state.dataList.length) {
return []
}
// 如果购物车为空直接返回true
if (!state.dataList || !state.dataList.length) {
return []
}
let valid = false
for (const v of disposeDataList.value) {
if (v.refundProductCount > 0 || v.refundProductWeight > 0) {
valid = true
break
}
}
if (!valid) {
useMessage().error("退款商品列表不能为空")
return false
}
// 处理一下
return disposeDataList.value.map((item: any) => {
return {
...item,
productCount: item.refundProductCount,
productWeight: displayWeight(item.refundProductWeight),
totalPrice: item.refundTotalPrice,
}
})
let valid = false
for (const v of disposeDataList.value) {
if (v.refundProductCount > 0 || v.refundProductWeight > 0) {
valid = true
break
}
}
if (!valid) {
useMessage().error("退款商品列表不能为空")
return false
}
// 处理一下
return disposeDataList.value.map((item: any) => {
return {
...item,
productCount: item.refundProductCount,
productWeight: displayWeight(item.refundProductWeight),
totalPrice: item.refundTotalPrice,
}
})
}
// 暴露变量
defineExpose({
getCarList,
validate,
getCarList,
validate,
})
</script>
<style lang="scss" scoped>
.refund-table {
padding: 0 10px;
padding: 0 10px;
}
:deep(.el-descriptions) {
&:not(:nth-child(1)) {
margin-top: 20px;
}
&:not(:nth-child(1)) {
margin-top: 20px;
}
.el-descriptions__title {
display: flex;
align-items: center;
.el-descriptions__title {
display: flex;
align-items: center;
&::before {
display: inline-block;
width: 3px;
height: 20px;
margin-right: 10px;
background-color: #409eff;
content: "";
}
}
&::before {
display: inline-block;
width: 3px;
height: 20px;
margin-right: 10px;
background-color: #409eff;
content: "";
}
}
.el-descriptions-item__container {
margin: 0 10px;
.el-descriptions-item__container {
margin: 0 10px;
.no-colon {
margin: 0;
.no-colon {
margin: 0;
&::after {
content: "";
}
}
}
&::after {
content: "";
}
}
}
}
</style>
</style>