This commit is contained in:
ctw committed 2025-11-03 15:41:17 +08:00
commit 0a57151809
5 files changed
+505 -352

No files matched your search

+101
View File
@@ -0,0 +1,101 @@
<template>
<el-select
style="width: 100%"
v-model="selectId"
:placeholder="props.placeholder"
clearable
remote-show-suffix
filterable
remote
:disabled="props.disabled"
:remote-method="remoteSearch"
:loading="state.loading"
@visible-change="(e: boolean) => e && getOptions()"
:multiple="props.multiple"
>
<el-option v-for="v in state.options" :key="v.id" :label="`${v.actTitle}`" :value="v.id">
<div class="flex items-center">
<div class="color-primary">{{ v.actTitle }}</div>
</div>
</el-option>
</el-select>
</template>
<script setup lang="ts" name="select-merchant">
import { reactive } from "vue"
import * as actCancelApi from "/@/api/act/actCancel"
const selectId = defineModel()
const props = withDefaults(
defineProps<{
placeholder?: string
apiParams?: any
autoFirst?: boolean
disabled?: boolean
multiple?: boolean
}>(),
{
placeholder: "请选择",
apiParams: {},
autoFirst: false,
disabled: false,
multiple: false,
},
)
const queryForm = reactive<any>({
name: null,
current: 1,
size: 9999,
})
const state = reactive<any>({
loading: true,
selectId: selectId.value,
options: [],
})
watch(
selectId,
(newVal, oldValue) => {
if (newVal == oldValue) return
state.selectId = newVal
getOptions()
},
{ immediate: true },
)
async function getOptions() {
try {
state.loading = true
const _pa = {
...queryForm,
...props.apiParams,
}
const { data } = await actCancelApi.fetchList(_pa)
state.options = data.records ?? []
if (props.autoFirst && state.options.length != 0) {
state.selectId = state.options[0].id
}
} finally {
setTimeout(() => (state.loading = false), 500)
}
}
function remoteSearch(params: string) {
if (params != queryForm.name) {
queryForm.name = params
getOptions()
}
}
function clear() {
state.selectId = null
getOptions()
}
onMounted(() => {
props.autoFirst && getOptions()
})
</script>
+2
View File
@@ -39,6 +39,7 @@ import SelectMchCatory from "/@/components/Select/SelectMchCatory.vue"
import SelectCanteenSupplier from "/@/components/Select/SelectCanteenSupplier.vue"
import SelectWalletInvoice from "/@/components/Select/SelectWalletInvoice.vue"
import SelectNotice from "/@/components/Select/SelectNotice.vue"
import SelectAct from "/@/components/Select/SelectAct.vue"
// 地图组件
import MapSelect from "/@/components/map/map-select.vue"
@@ -100,6 +101,7 @@ export default {
app.component("SelectCanteenSupplier", SelectCanteenSupplier)
app.component("SelectWalletInvoice", SelectWalletInvoice)
app.component("SelectNotice", SelectNotice)
app.component("SelectAct", SelectAct)
app.component("MapSelect", MapSelect)
+9 -1
View File
@@ -26,7 +26,13 @@
</el-form-item>
</el-col>
<el-col :span="24" class="mb20">
<el-col :span="12" class="mb20">
<el-form-item label="开始时间" prop="startTime">
<el-date-picker value-format="YYYY-MM-DD HH:mm:ss" type="datetime" placeholder="请选择开始时间" v-model="form.startTime" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="到期时间" prop="expireTime">
<el-date-picker value-format="YYYY-MM-DD HH:mm:ss" type="datetime" placeholder="请选择到期时间" v-model="form.expireTime" />
</el-form-item>
@@ -82,6 +88,7 @@ const form = reactive({
noticeId: "",
activeOrgPrice: "",
activeCancelPrice: "",
startTime: "",
expireTime: "",
actStatus: "",
actTitle: "",
@@ -93,6 +100,7 @@ const dataRules = ref({
mchId: [{ required: true, message: "活动商户不能为空", trigger: "change" }],
noticeId: [{ required: true, message: "活动公告不能为空", trigger: "change" }],
activeCancelPrice: [{ required: true, message: "活动价不能为空", trigger: "blur" }],
startTime: [{ required: true, message: "到期时间不能为空", trigger: "change" }],
expireTime: [{ required: true, message: "到期时间不能为空", trigger: "change" }],
actTitle: [{ required: true, message: "活动标题不能为空", trigger: "blur" }],
})
+97 -88
View File
@@ -1,66 +1,82 @@
<template>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList">
<el-row>
<el-form-item style="width: 300px" label="领取人用户" prop="receiverUserId">
<select-user v-model="state.queryForm.receiverUserId" />
</el-form-item>
<el-form-item style="width: 300px" label="核销状态" prop="actStatus">
<dict-select v-model="state.queryForm.actStatus" dict-code="act_cancel_status" />
</el-form-item>
<el-form-item>
<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-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="40" />
<el-table-column prop="mchName" label="活动商户" />
<el-table-column prop="receiverUsername" label="领取人" />
<el-table-column prop="receiverTime" label="领取时间" />
<el-table-column prop="actStatus" label="活动状态">
<template #default="{ row }">
<dict-tag :options="act_cancel_status" :value="row.actStatus" />
</template>
</el-table-column>
<el-table-column prop="cancelUsername" label="核销人" />
<el-table-column prop="cancelTime" label="核销时间" />
<el-table-column prop="expireTime" label="过期时间" />
<el-table-column label="操作" v-if="false" width="150">
<template #default="scope">
<el-button icon="edit-pen" text type="primary" v-auth="'wallet_actCancelItem_edit'"
@click="formDialogRef.openDialog(scope.row.id)">编辑</el-button>
<el-button icon="delete" text type="primary" v-auth="'wallet_actCancelItem_del'"
@click="handleDelete([scope.row.id])">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
</div>
<div class="layout-padding">
<div class="layout-padding-auto layout-padding-view">
<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList">
<el-row>
<el-form-item style="width: 300px" label="活动" prop="actId">
<select-act v-model="state.queryForm.actId" />
</el-form-item>
<el-form-item style="width: 300px" label="领取人用户" prop="receiverUserId">
<select-user v-model="state.queryForm.receiverUserId" />
</el-form-item>
<el-form-item style="width: 300px" label="核销状态" prop="actStatus">
<dict-select v-model="state.queryForm.actStatus" dict-code="act_cancel_status" />
</el-form-item>
<el-form-item>
<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-column type="selection" width="40" align="center" />
<el-table-column type="index" label="#" width="40" />
<el-table-column prop="mchName" label="活动商户" />
<el-table-column prop="actTitlel" label="活动标题" show-overflow-tooltip />
<el-table-column prop="receiverUsername" label="领取人" />
<el-table-column prop="receiverTime" label="领取时间" />
<el-table-column prop="actStatus" label="活动状态">
<template #default="{ row }">
<dict-tag :options="act_cancel_status" :value="row.actStatus" />
</template>
</el-table-column>
<el-table-column prop="cancelUsername" label="核销人" />
<el-table-column prop="cancelTime" label="核销时间" />
<el-table-column prop="expireTime" label="过期时间" />
<el-table-column label="操作" v-if="false" width="150">
<template #default="scope">
<el-button
icon="edit-pen"
text
type="primary"
v-auth="'wallet_actCancelItem_edit'"
@click="formDialogRef.openDialog(scope.row.id)"
>编辑</el-button
>
<el-button icon="delete" text type="primary" v-auth="'wallet_actCancelItem_del'" @click="handleDelete([scope.row.id])"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
</div>
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
</div>
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
</div>
</template>
<script setup lang="ts" name="systemActCancelItem">
import { BasicTableProps, useTable } from "/@/hooks/table";
import { fetchList, delObjs } from "/@/api/act/act-cancel-item";
import { useMessage, useMessageBox } from "/@/hooks/message";
import { useDict } from '/@/hooks/dict';
import { BasicTableProps, useTable } from "/@/hooks/table"
import { fetchList, delObjs } from "/@/api/act/act-cancel-item"
import { useMessage, useMessageBox } from "/@/hooks/message"
import { useDict } from "/@/hooks/dict"
// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
const FormDialog = defineAsyncComponent(() => import("./form.vue"))
// 定义查询字典
const { act_cancel_status } = useDict("act_cancel_status")
// 定义变量内容
@@ -73,49 +89,42 @@ const selectObjs = ref([]) as any
const multiple = ref(true)
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: fetchList
queryForm: {},
pageList: fetchList,
})
// table hook
const {
getDataList,
currentChangeHandle,
sizeChangeHandle,
sortChangeHandle,
downBlobFile,
tableStyle
} = useTable(state)
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state)
// 清空搜索条件
const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
// 清空搜索条件
queryRef.value?.resetFields()
// 清空多选
selectObjs.value = []
getDataList()
}
// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
selectObjs.value = objs.map(({ id }) => id);
multiple.value = !objs.length;
};
selectObjs.value = objs.map(({ id }) => id)
multiple.value = !objs.length
}
// 删除操作
const handleDelete = async (ids: string[]) => {
try {
await useMessageBox().confirm('此操作将永久删除');
} catch {
return;
}
try {
await useMessageBox().confirm("此操作将永久删除")
} catch {
return
}
try {
await delObjs(ids);
getDataList();
useMessage().success('删除成功');
} catch (err: any) {
useMessage().error(err.msg);
}
};
</script>
try {
await delObjs(ids)
getDataList()
useMessage().success("删除成功")
} catch (err: any) {
useMessage().error(err.msg)
}
}
</script>
@@ -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>