李红攀:V2.6.969,销售退货管理管理
This commit is contained in:
@@ -22,6 +22,7 @@ export interface SaleOrderItem {
|
||||
taxAmount?: number
|
||||
remark?: string
|
||||
outCount?: number
|
||||
returnCount?: number
|
||||
stockCount?: number
|
||||
}
|
||||
|
||||
|
||||
92
src/api/erp/sale-return/index.ts
Normal file
92
src/api/erp/sale-return/index.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import type { PageParam, PageResult } from '@/http/types'
|
||||
import { http } from '@/http/http'
|
||||
|
||||
/** 销售退货明细 */
|
||||
export interface SaleReturnItem {
|
||||
id?: number
|
||||
orderItemId?: number
|
||||
warehouseId?: number
|
||||
warehouseName?: string
|
||||
productId?: number
|
||||
productName?: string
|
||||
productBarCode?: string
|
||||
productUnitId?: number
|
||||
productUnitName?: string
|
||||
productPrice?: number
|
||||
count?: number
|
||||
totalCount?: number
|
||||
totalPrice?: number
|
||||
taxPercent?: number
|
||||
taxPrice?: number
|
||||
remark?: string
|
||||
stockCount?: number
|
||||
totalProductPrice?: number
|
||||
outCount?: number
|
||||
returnCount?: number
|
||||
productSpec?: string
|
||||
}
|
||||
|
||||
/** 销售退货 */
|
||||
export interface SaleReturn {
|
||||
id?: number
|
||||
no?: string
|
||||
customerId?: number
|
||||
customerName?: string
|
||||
accountId?: number
|
||||
accountName?: string
|
||||
saleUserId?: number
|
||||
saleUserName?: string
|
||||
returnTime?: string | number
|
||||
orderId?: number
|
||||
orderNo?: string
|
||||
totalCount?: number
|
||||
totalPrice?: number
|
||||
refundPrice?: number
|
||||
totalProductPrice?: number
|
||||
totalTaxPrice?: number
|
||||
discountPercent?: number
|
||||
discountPrice?: number
|
||||
otherPrice?: number
|
||||
fileUrl?: string
|
||||
status?: number
|
||||
remark?: string
|
||||
creator?: string
|
||||
creatorName?: string
|
||||
createTime?: string | number
|
||||
productNames?: string
|
||||
items?: SaleReturnItem[]
|
||||
}
|
||||
|
||||
/** 获取销售退货分页列表 */
|
||||
export function getSaleReturnPage(params: PageParam & {
|
||||
no?: string
|
||||
customerId?: number
|
||||
status?: number
|
||||
}) {
|
||||
return http.get<PageResult<SaleReturn>>('/erp/sale-return/page', params)
|
||||
}
|
||||
|
||||
/** 获取销售退货详情 */
|
||||
export function getSaleReturn(id: number) {
|
||||
return http.get<SaleReturn>(`/erp/sale-return/get?id=${id}`)
|
||||
}
|
||||
|
||||
/** 创建销售退货 */
|
||||
export function createSaleReturn(data: SaleReturn) {
|
||||
return http.post<number>('/erp/sale-return/create', data)
|
||||
}
|
||||
|
||||
/** 更新销售退货 */
|
||||
export function updateSaleReturn(data: SaleReturn) {
|
||||
return http.put<boolean>('/erp/sale-return/update', data)
|
||||
}
|
||||
|
||||
/** 更新销售退货状态 */
|
||||
export function updateSaleReturnStatus(id: number, status: number) {
|
||||
return http.put<boolean>('/erp/sale-return/update-status', undefined, { id, status })
|
||||
}
|
||||
|
||||
/** 删除销售退货 */
|
||||
export function deleteSaleReturn(ids: number[]) {
|
||||
return http.delete<boolean>('/erp/sale-return/delete', undefined, { ids: ids.join(',') })
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
/>
|
||||
|
||||
<!-- 详情内容 -->
|
||||
<view v-if="formData">
|
||||
<view v-if="formData" class="pb-180rpx">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="退货单编号" :value="formData.no" />
|
||||
|
||||
@@ -325,7 +325,7 @@ const formData = ref<PurchaseReturn>({
|
||||
no: undefined,
|
||||
supplierId: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
returnTime: Date.now(),
|
||||
orderId: undefined,
|
||||
orderNo: undefined,
|
||||
discountPercent: 0,
|
||||
@@ -358,14 +358,20 @@ const orderTotal = ref(0)
|
||||
const selectedOrderId = ref<number>()
|
||||
|
||||
/** 账户下拉列 */
|
||||
const accountColumns = computed(() => [
|
||||
accountList.value.map(a => ({ value: a.id, label: a.name })),
|
||||
])
|
||||
const accountColumns = computed(() => {
|
||||
if (!accountList.value.length) {
|
||||
return []
|
||||
}
|
||||
return [accountList.value.map(a => ({ value: a.id, label: a.name }))]
|
||||
})
|
||||
|
||||
/** 仓库下拉列 */
|
||||
const warehouseColumns = computed(() => [
|
||||
warehouseList.value.map(w => ({ value: w.id, label: w.name })),
|
||||
])
|
||||
const warehouseColumns = computed(() => {
|
||||
if (!warehouseList.value.length) {
|
||||
return []
|
||||
}
|
||||
return [warehouseList.value.map(w => ({ value: w.id, label: w.name }))]
|
||||
})
|
||||
|
||||
/** 获取供应商名称 */
|
||||
function getSupplierName() {
|
||||
@@ -375,15 +381,29 @@ function getSupplierName() {
|
||||
}
|
||||
|
||||
/** 账户选择回调 */
|
||||
function onAccountConfirm({ value }: any) {
|
||||
formData.value.accountId = value?.[0]
|
||||
function getPickerSingleValue(payload: any) {
|
||||
if (Array.isArray(payload?.value)) {
|
||||
return payload.value[0]
|
||||
}
|
||||
if (payload?.value !== undefined) {
|
||||
return payload.value
|
||||
}
|
||||
if (Array.isArray(payload?.selectedItems) && payload.selectedItems.length > 0) {
|
||||
return payload.selectedItems[0]?.value
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function onAccountConfirm(payload: any) {
|
||||
formData.value.accountId = getPickerSingleValue(payload)
|
||||
}
|
||||
|
||||
/** 仓库选择回调 */
|
||||
function onWarehouseConfirm({ value }: any, index: number) {
|
||||
function onWarehouseConfirm(payload: any, index: number) {
|
||||
if (formData.value.items && formData.value.items[index]) {
|
||||
formData.value.items[index].warehouseId = value?.[0]
|
||||
const warehouse = warehouseList.value.find(w => w.id === value?.[0])
|
||||
const warehouseId = getPickerSingleValue(payload)
|
||||
formData.value.items[index].warehouseId = warehouseId
|
||||
const warehouse = warehouseList.value.find(w => w.id === warehouseId)
|
||||
if (warehouse) {
|
||||
formData.value.items[index].warehouseName = warehouse.name
|
||||
}
|
||||
|
||||
95
src/pages-erp/sale-return/components/search-form.vue
Normal file
95
src/pages-erp/sale-return/components/search-form.vue
Normal file
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<view @click="visible = true">
|
||||
<wd-search :placeholder="placeholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<wd-popup v-model="visible" position="top" @close="visible = false">
|
||||
<view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
退货单编号
|
||||
</view>
|
||||
<wd-input
|
||||
v-model="formData.no"
|
||||
placeholder="请输入退货单编号"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
审核状态
|
||||
</view>
|
||||
<wd-radio-group v-model="formData.status" shape="button">
|
||||
<wd-radio :value="-1">
|
||||
全部
|
||||
</wd-radio>
|
||||
<wd-radio :value="10">
|
||||
待审核
|
||||
</wd-radio>
|
||||
<wd-radio :value="20">
|
||||
已审核
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
<view class="yd-search-form-actions">
|
||||
<wd-button class="flex-1" plain @click="handleReset">
|
||||
重置
|
||||
</wd-button>
|
||||
<wd-button class="flex-1" type="primary" @click="handleSearch">
|
||||
搜索
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { getNavbarHeight } from '@/utils'
|
||||
|
||||
const emit = defineEmits<{
|
||||
search: [data: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const formData = reactive({
|
||||
no: undefined as string | undefined,
|
||||
status: -1,
|
||||
})
|
||||
|
||||
const statusMap: Record<number, string> = {
|
||||
10: '待审核',
|
||||
20: '已审核',
|
||||
}
|
||||
|
||||
const placeholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (formData.no) {
|
||||
conditions.push(`编号:${formData.no}`)
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
conditions.push(`状态:${statusMap[formData.status] || formData.status}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索销售退货单'
|
||||
})
|
||||
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
const params: Record<string, any> = {}
|
||||
if (formData.no) {
|
||||
params.no = formData.no
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
params.status = formData.status
|
||||
}
|
||||
emit('search', params)
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
formData.no = undefined
|
||||
formData.status = -1
|
||||
visible.value = false
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
319
src/pages-erp/sale-return/detail/index.vue
Normal file
319
src/pages-erp/sale-return/detail/index.vue
Normal file
@@ -0,0 +1,319 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="销售退货详情"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<view v-if="formData" class="pb-180rpx">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="退货单编号" :value="formData.no" />
|
||||
<wd-cell title="审核状态">
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(formData.status)"
|
||||
>
|
||||
{{ getStatusText(formData.status) }}
|
||||
</view>
|
||||
</wd-cell>
|
||||
<wd-cell title="客户" :value="formData.customerName || '-'" />
|
||||
<wd-cell title="退货时间" :value="formatDateTime(formData.returnTime)" />
|
||||
<wd-cell title="关联订单" :value="formData.orderNo || '-'" />
|
||||
<wd-cell title="销售人员" :value="formData.saleUserName || '-'" />
|
||||
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
|
||||
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="金额信息" border>
|
||||
<wd-cell title="合计数量" :value="String(formData.totalCount || 0)" />
|
||||
<wd-cell title="合计产品价格" :value="`¥${formatPrice(formData.totalProductPrice)}`" />
|
||||
<wd-cell title="合计税额" :value="`¥${formatPrice(formData.totalTaxPrice)}`" />
|
||||
<wd-cell title="优惠率" :value="`${formData.discountPercent || 0}%`" />
|
||||
<wd-cell title="优惠金额" :value="`¥${formatPrice(formData.discountPrice)}`" />
|
||||
<wd-cell title="其他费用" :value="`¥${formatPrice(formData.otherPrice)}`" />
|
||||
<wd-cell title="应退金额">
|
||||
<text class="text-[#e6a23c] font-semibold">¥{{ formatPrice(formData.totalPrice) }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="已退金额">
|
||||
<text class="text-[#52c41a] font-semibold">¥{{ formatPrice(formData.refundPrice) }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="未退金额">
|
||||
<text
|
||||
class="font-semibold"
|
||||
:class="getUnrefundPrice() > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
|
||||
>
|
||||
¥{{ formatPrice(getUnrefundPrice()) }}
|
||||
</text>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<view class="mx-24rpx mt-24rpx">
|
||||
<view class="mb-16rpx text-32rpx text-[#333] font-semibold">
|
||||
退货明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
<view v-if="formData.items && formData.items.length > 0">
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="item.id || index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-16rpx">
|
||||
<view class="flex items-center">
|
||||
<text class="text-28rpx text-[#333] font-semibold">{{ item.productName || '-' }}</text>
|
||||
<text v-if="item.productBarCode" class="ml-12rpx text-22rpx text-[#999]">{{ item.productBarCode }}</text>
|
||||
</view>
|
||||
<text v-if="item.warehouseName" class="text-24rpx text-[#1890ff]">{{ item.warehouseName }}</text>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<view v-if="item.productSpec" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<text class="mr-8rpx text-[#999]">规格:</text>
|
||||
<text>{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单价:</text>
|
||||
<text class="text-[#f5222d]">¥{{ formatPrice(item.productPrice) }}</text>
|
||||
</view>
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">数量:</text>
|
||||
<text class="font-semibold">{{ item.count || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单位:</text>
|
||||
<text>{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="item.taxPercent" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税率:</text>
|
||||
<text>{{ item.taxPercent }}%</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税额:</text>
|
||||
<text>¥{{ formatPrice(item.taxPrice) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">金额:</text>
|
||||
<text class="text-[#e6a23c]">¥{{ formatPrice(item.totalPrice) }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">库存:</text>
|
||||
<text>{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="item.outCount != null || item.returnCount != null" class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<view v-if="item.outCount != null" class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">已出库:</text>
|
||||
<text>{{ item.outCount }}</text>
|
||||
</view>
|
||||
<view v-if="item.returnCount != null" class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">已退货:</text>
|
||||
<text>{{ item.returnCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="item.remark" class="text-24rpx text-[#999]">
|
||||
备注:{{ item.remark }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无退货明细
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<wd-cell-group v-if="formData.remark" title="备注" border>
|
||||
<wd-cell :value="formData.remark" />
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
<view class="yd-detail-footer">
|
||||
<view class="yd-detail-footer-actions">
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:update']) && formData?.status === 10"
|
||||
class="flex-1"
|
||||
type="warning"
|
||||
@click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && formData?.status === 10"
|
||||
class="flex-1"
|
||||
type="success"
|
||||
@click="handleAudit"
|
||||
>
|
||||
审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && formData?.status === 20"
|
||||
class="flex-1"
|
||||
type="warning"
|
||||
@click="handleReverseAudit"
|
||||
>
|
||||
反审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:delete'])"
|
||||
class="flex-1"
|
||||
type="error"
|
||||
:loading="deleting"
|
||||
@click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { SaleReturn } from '@/api/erp/sale-return'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deleteSaleReturn, getSaleReturn, updateSaleReturnStatus } from '@/api/erp/sale-return'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import { formatDateTime } from '@/utils/date'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const formData = ref<SaleReturn>()
|
||||
const deleting = ref(false)
|
||||
|
||||
function formatPrice(value?: number) {
|
||||
if (value === undefined || value === null) return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function getUnrefundPrice() {
|
||||
return Math.max(Number(formData.value?.totalPrice || 0) - Number(formData.value?.refundPrice || 0), 0)
|
||||
}
|
||||
|
||||
function getStatusText(status?: number) {
|
||||
if (status === 10) return '待审核'
|
||||
if (status === 20) return '已审核'
|
||||
return '未知'
|
||||
}
|
||||
|
||||
function getStatusClass(status?: number) {
|
||||
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/sale-return/index')
|
||||
}
|
||||
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getSaleReturn(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
function handleEdit() {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/sale-return/form/index?id=${props.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
function handleAudit() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要审批该销售退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updateSaleReturnStatus(props.id, 20)
|
||||
toast.success('审批成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleReverseAudit() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要反审批该销售退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updateSaleReturnStatus(props.id, 10)
|
||||
toast.success('反审批成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleDelete() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该销售退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
deleting.value = true
|
||||
try {
|
||||
await deleteSaleReturn([props.id])
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
633
src/pages-erp/sale-return/form/index.vue
Normal file
633
src/pages-erp/sale-return/form/index.vue
Normal file
@@ -0,0 +1,633 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="退货单号" title-width="180rpx" center>
|
||||
<wd-input
|
||||
v-model="formData.no"
|
||||
placeholder="保存时自动生成"
|
||||
disabled
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="退货时间" title-width="180rpx" prop="returnTime" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.returnTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择退货时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="关联订单" title-width="180rpx" center is-link @click="openOrderSelect">
|
||||
<text v-if="formData.orderNo" class="text-[#1890ff]">{{ formData.orderNo }}</text>
|
||||
<text v-else class="text-[#999]">点击选择销售订单</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="客户" title-width="180rpx" center>
|
||||
<text>{{ getCustomerName() || '-' }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="销售人员" title-width="180rpx" center>
|
||||
<text>{{ getSaleUserName() || '-' }}</text>
|
||||
</wd-cell>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="费用信息" border>
|
||||
<wd-input
|
||||
v-model="formData.discountPercent"
|
||||
label="优惠率(%)"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入优惠率"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="退款优惠" title-width="180rpx" center>
|
||||
<text>¥{{ formatPrice(formData.discountPrice) }}</text>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.otherPrice"
|
||||
label="其他费用"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入其他费用"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="优惠后金额" title-width="180rpx" center>
|
||||
<text>¥{{ formatPrice(formData.totalPrice) }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="结算账户" title-width="180rpx" prop="accountId" center>
|
||||
<wd-picker
|
||||
v-model="formData.accountId"
|
||||
:columns="accountColumns"
|
||||
label=""
|
||||
placeholder="请选择结算账户"
|
||||
@confirm="onAccountConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<view class="mx-24rpx mt-24rpx pb-180rpx">
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-32rpx text-[#333] font-semibold">
|
||||
退货明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-12rpx">
|
||||
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
|
||||
<wd-button
|
||||
v-if="formData.items && formData.items.length > 1"
|
||||
size="small"
|
||||
type="error"
|
||||
plain
|
||||
@click="handleRemoveItem(index)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<view class="mb-16rpx">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">仓库</text>
|
||||
<wd-picker
|
||||
v-model="item.warehouseId"
|
||||
:columns="warehouseColumns"
|
||||
placeholder="请选择仓库"
|
||||
@confirm="(e: any) => onWarehouseConfirm(e, index)"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view v-if="item.productId" class="mb-16rpx rounded-8rpx bg-[#f9f9f9] p-16rpx">
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">产品名称</text>
|
||||
<text class="text-[#333]">{{ item.productName || '-' }}</text>
|
||||
</view>
|
||||
<view v-if="item.productSpec" class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">规格</text>
|
||||
<text class="text-[#333]">{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">单位</text>
|
||||
<text class="text-[#333]">{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">条码</text>
|
||||
<text class="text-[#333]">{{ item.productBarCode || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">库存</text>
|
||||
<text class="text-[#333]">{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
<view v-if="item.outCount != null" class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">已出库</text>
|
||||
<text class="text-[#333]">{{ item.outCount }}</text>
|
||||
</view>
|
||||
<view v-if="item.returnCount != null" class="flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">已退货</text>
|
||||
<text class="text-[#333]">{{ item.returnCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mb-16rpx flex gap-16rpx">
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">数量</text>
|
||||
<wd-input
|
||||
v-model="item.count"
|
||||
type="number"
|
||||
placeholder="数量"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">单价(元)</text>
|
||||
<wd-input
|
||||
v-model="item.productPrice"
|
||||
type="number"
|
||||
placeholder="单价"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mb-16rpx flex gap-16rpx">
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">税率(%)</text>
|
||||
<wd-input
|
||||
v-model="item.taxPercent"
|
||||
type="number"
|
||||
placeholder="税率"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">金额</text>
|
||||
<text class="block pt-16rpx text-28rpx text-[#333]">{{ calcTotalPrice(item) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">备注</text>
|
||||
<wd-input
|
||||
v-model="item.remark"
|
||||
placeholder="请输入备注"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!formData.items?.length" class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无产品,请先选择关联订单
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<wd-popup v-model="orderSelectVisible" position="right" custom-style="width: 100%; height: 100%;">
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="选择销售订单"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="orderSelectVisible = false"
|
||||
/>
|
||||
<wd-search
|
||||
v-model="orderQueryParams.no"
|
||||
placeholder="搜索订单单号"
|
||||
@search="getOrderList"
|
||||
@clear="getOrderList"
|
||||
/>
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in orderList"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
|
||||
@click="handleSelectOrder(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<view class="mb-12rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.no }}</view>
|
||||
<wd-icon v-if="selectedOrderId === item.id" name="check" color="#1890ff" size="40rpx" />
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">客户</text>
|
||||
<text>{{ item.customerName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<view class="flex items-center justify-around mt-12rpx pt-12rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#52c41a] font-semibold">{{ item.outCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">已出库</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#f5222d] font-semibold">{{ item.returnCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">已退货</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="orderList.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无可退货订单" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="orderList.length > 0"
|
||||
:state="orderLoadMoreState"
|
||||
@reload="loadMoreOrders"
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button type="primary" block :disabled="!selectedOrderId" @click="confirmSelectOrder">
|
||||
确认选择
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { Account } from '@/api/erp/account'
|
||||
import type { CustomerSimple } from '@/api/erp/customer'
|
||||
import type { SaleOrder, SaleOrderItem } from '@/api/erp/sale-order'
|
||||
import type { SaleReturn, SaleReturnItem } from '@/api/erp/sale-return'
|
||||
import type { Warehouse } from '@/api/erp/warehouse'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import type { User } from '@/api/system/user'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { getAccountSimpleList } from '@/api/erp/account'
|
||||
import { getCustomerSimpleList } from '@/api/erp/customer'
|
||||
import { getSaleOrder, getSaleOrderPage } from '@/api/erp/sale-order'
|
||||
import { createSaleReturn, getSaleReturn, updateSaleReturn } from '@/api/erp/sale-return'
|
||||
import { getWarehouseSimpleList } from '@/api/erp/warehouse'
|
||||
import { getSimpleUserList } from '@/api/system/user'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const getTitle = computed(() => props.id ? '编辑销售退货' : '新增销售退货')
|
||||
const formLoading = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const customerList = ref<CustomerSimple[]>([])
|
||||
const accountList = ref<Account[]>([])
|
||||
const warehouseList = ref<Warehouse[]>([])
|
||||
const userList = ref<User[]>([])
|
||||
const defaultWarehouse = ref<Warehouse>()
|
||||
|
||||
const formData = ref<SaleReturn>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
customerId: undefined,
|
||||
accountId: undefined,
|
||||
saleUserId: undefined,
|
||||
returnTime: Date.now(),
|
||||
orderId: undefined,
|
||||
orderNo: undefined,
|
||||
discountPercent: 0,
|
||||
discountPrice: 0,
|
||||
otherPrice: 0,
|
||||
totalPrice: 0,
|
||||
remark: '',
|
||||
items: [],
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
returnTime: [{ required: true, message: '退货时间不能为空' }],
|
||||
}
|
||||
|
||||
const orderSelectVisible = ref(false)
|
||||
const orderList = ref<SaleOrder[]>([])
|
||||
const orderLoadMoreState = ref<LoadMoreState>('loading')
|
||||
const orderQueryParams = ref<{
|
||||
pageNo: number
|
||||
pageSize: number
|
||||
no?: string
|
||||
returnEnable: boolean
|
||||
}>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
no: undefined as string | undefined,
|
||||
returnEnable: true,
|
||||
})
|
||||
const orderTotal = ref(0)
|
||||
const selectedOrderId = ref<number>()
|
||||
|
||||
const accountColumns = computed(() => {
|
||||
if (!accountList.value.length) {
|
||||
return []
|
||||
}
|
||||
return [accountList.value.map(a => ({ value: a.id, label: a.name }))]
|
||||
})
|
||||
|
||||
const warehouseColumns = computed(() => {
|
||||
if (!warehouseList.value.length) {
|
||||
return []
|
||||
}
|
||||
return [warehouseList.value.map(w => ({ value: w.id, label: w.name }))]
|
||||
})
|
||||
|
||||
function formatPrice(value?: number) {
|
||||
if (value === undefined || value === null) return '0.00'
|
||||
return Number(value).toFixed(2)
|
||||
}
|
||||
|
||||
function getCustomerName() {
|
||||
if (!formData.value.customerId) return ''
|
||||
const customer = customerList.value.find(s => s.id === formData.value.customerId)
|
||||
return customer?.name || formData.value.customerName || ''
|
||||
}
|
||||
|
||||
function getSaleUserName() {
|
||||
if (!formData.value.saleUserId) return ''
|
||||
const user = userList.value.find(s => s.id === formData.value.saleUserId)
|
||||
return user?.nickname || formData.value.saleUserName || ''
|
||||
}
|
||||
|
||||
function getPickerSingleValue(payload: any) {
|
||||
if (Array.isArray(payload?.value)) {
|
||||
return payload.value[0]
|
||||
}
|
||||
if (payload?.value !== undefined) {
|
||||
return payload.value
|
||||
}
|
||||
if (Array.isArray(payload?.selectedItems) && payload.selectedItems.length > 0) {
|
||||
return payload.selectedItems[0]?.value
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function onAccountConfirm(payload: any) {
|
||||
formData.value.accountId = getPickerSingleValue(payload)
|
||||
}
|
||||
|
||||
function onWarehouseConfirm(payload: any, index: number) {
|
||||
if (formData.value.items && formData.value.items[index]) {
|
||||
const warehouseId = getPickerSingleValue(payload)
|
||||
formData.value.items[index].warehouseId = warehouseId
|
||||
const warehouse = warehouseList.value.find(w => w.id === warehouseId)
|
||||
if (warehouse) {
|
||||
formData.value.items[index].warehouseName = warehouse.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calcTotalPrice(item: SaleReturnItem) {
|
||||
if (item.productPrice && item.count) {
|
||||
const productTotal = Number(item.productPrice) * Number(item.count)
|
||||
const taxPrice = item.taxPercent ? productTotal * Number(item.taxPercent) / 100 : 0
|
||||
return `¥${(productTotal + taxPrice).toFixed(2)}`
|
||||
}
|
||||
return '-'
|
||||
}
|
||||
|
||||
watch(
|
||||
() => formData.value,
|
||||
(val) => {
|
||||
if (!val || !val.items) return
|
||||
val.items.forEach((item) => {
|
||||
if (item.productPrice && item.count) {
|
||||
item.totalProductPrice = Number(item.productPrice) * Number(item.count)
|
||||
item.taxPrice = item.taxPercent ? item.totalProductPrice * Number(item.taxPercent) / 100 : 0
|
||||
item.totalPrice = item.totalProductPrice + (item.taxPrice || 0)
|
||||
} else {
|
||||
item.totalProductPrice = 0
|
||||
item.taxPrice = 0
|
||||
item.totalPrice = 0
|
||||
}
|
||||
})
|
||||
const totalPrice = val.items.reduce((prev, curr) => prev + Number(curr.totalPrice || 0), 0)
|
||||
const discountPrice = val.discountPercent ? totalPrice * Number(val.discountPercent) / 100 : 0
|
||||
formData.value.discountPrice = Math.round(discountPrice * 100) / 100
|
||||
formData.value.totalPrice = Math.round((totalPrice - discountPrice + Number(val.otherPrice || 0)) * 100) / 100
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
async function loadDropdownData() {
|
||||
const [customers, accounts, warehouses, users] = await Promise.allSettled([
|
||||
getCustomerSimpleList(),
|
||||
getAccountSimpleList(),
|
||||
getWarehouseSimpleList(),
|
||||
getSimpleUserList(),
|
||||
])
|
||||
|
||||
customerList.value = customers.status === 'fulfilled' ? (customers.value || []) : []
|
||||
accountList.value = accounts.status === 'fulfilled' ? (accounts.value || []) : []
|
||||
warehouseList.value = warehouses.status === 'fulfilled' ? (warehouses.value || []) : []
|
||||
userList.value = users.status === 'fulfilled' ? (users.value || []) : []
|
||||
|
||||
const defaultAccount = accountList.value.find(a => (a as any).defaultStatus)
|
||||
if (defaultAccount && !formData.value.accountId) {
|
||||
formData.value.accountId = defaultAccount.id
|
||||
}
|
||||
defaultWarehouse.value = warehouseList.value.find(w => w.defaultStatus)
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/sale-return/index')
|
||||
}
|
||||
|
||||
function handleRemoveItem(index: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定要删除第 ${index + 1} 项产品吗?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
formData.value.items?.splice(index, 1)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function openOrderSelect() {
|
||||
orderSelectVisible.value = true
|
||||
orderQueryParams.value.pageNo = 1
|
||||
orderList.value = []
|
||||
selectedOrderId.value = formData.value.orderId
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
async function getOrderList() {
|
||||
orderLoadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getSaleOrderPage(orderQueryParams.value)
|
||||
if (orderQueryParams.value.pageNo === 1) {
|
||||
orderList.value = data.list
|
||||
} else {
|
||||
orderList.value = [...orderList.value, ...data.list]
|
||||
}
|
||||
orderTotal.value = data.total
|
||||
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
orderLoadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
function loadMoreOrders() {
|
||||
if (orderLoadMoreState.value === 'finished') return
|
||||
orderQueryParams.value.pageNo++
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
function handleSelectOrder(item: SaleOrder) {
|
||||
selectedOrderId.value = item.id
|
||||
}
|
||||
|
||||
function mapSaleOrderItem(item: SaleOrderItem) {
|
||||
const availableCount = Math.max(Number(item.outCount || 0) - Number(item.returnCount || 0), 0)
|
||||
return {
|
||||
productId: item.productId,
|
||||
productName: item.productName,
|
||||
productUnitId: item.productUnitId,
|
||||
productUnitName: item.productUnitName,
|
||||
productPrice: item.productPrice ?? item.unitPrice,
|
||||
productSpec: item.productSpec,
|
||||
productBarCode: item.productBarCode,
|
||||
count: availableCount,
|
||||
outCount: item.outCount,
|
||||
returnCount: item.returnCount,
|
||||
taxPercent: item.taxPercent,
|
||||
warehouseId: defaultWarehouse.value?.id,
|
||||
warehouseName: defaultWarehouse.value?.name,
|
||||
stockCount: item.stockCount,
|
||||
orderItemId: item.id,
|
||||
remark: item.remark,
|
||||
} as SaleReturnItem
|
||||
}
|
||||
|
||||
async function confirmSelectOrder() {
|
||||
if (!selectedOrderId.value) return
|
||||
try {
|
||||
toast.loading('加载订单详情...')
|
||||
const orderDetail = await getSaleOrder(selectedOrderId.value)
|
||||
formData.value.orderId = orderDetail.id
|
||||
formData.value.orderNo = orderDetail.no
|
||||
formData.value.customerId = orderDetail.customerId
|
||||
formData.value.customerName = orderDetail.customerName
|
||||
formData.value.accountId = orderDetail.accountId
|
||||
formData.value.saleUserId = orderDetail.saleUserId
|
||||
formData.value.saleUserName = orderDetail.saleUserName
|
||||
formData.value.discountPercent = orderDetail.discountPercent
|
||||
formData.value.remark = orderDetail.remark
|
||||
if (orderDetail.items) {
|
||||
formData.value.items = orderDetail.items
|
||||
.filter(item => (Number(item.outCount || 0) - Number(item.returnCount || 0)) > 0)
|
||||
.map(mapSaleOrderItem)
|
||||
}
|
||||
orderSelectVisible.value = false
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getSaleReturn(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
if (!formData.value.items || formData.value.items.length === 0) {
|
||||
toast.warning('请至少添加一项退货产品')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < formData.value.items.length; i++) {
|
||||
const item = formData.value.items[i]
|
||||
if (!item.warehouseId) {
|
||||
toast.warning(`第${i + 1}项产品请选择仓库`)
|
||||
return
|
||||
}
|
||||
if (!item.count || Number(item.count) <= 0) {
|
||||
toast.warning(`第${i + 1}项产品数量不能为空`)
|
||||
return
|
||||
}
|
||||
if (Number(item.count) > Math.max(Number(item.outCount || 0) - Number(item.returnCount || 0), 0)) {
|
||||
toast.warning(`第${i + 1}项产品数量不能超过可退数量`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updateSaleReturn(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createSaleReturn(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadDropdownData()
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
371
src/pages-erp/sale-return/index.vue
Normal file
371
src/pages-erp/sale-return/index.vue
Normal file
@@ -0,0 +1,371 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="销售退货"
|
||||
left-arrow
|
||||
placeholder
|
||||
safe-area-inset-top
|
||||
fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<SearchForm @search="handleQuery" @reset="handleReset" />
|
||||
|
||||
<view class="flex items-center overflow-hidden rounded-12rpx bg-white mx-24rpx mb-16rpx shadow-sm">
|
||||
<view
|
||||
v-for="tab in statusTabs"
|
||||
:key="String(tab.value)"
|
||||
class="flex-1 py-20rpx text-center text-26rpx relative"
|
||||
:class="activeStatus === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
|
||||
@click="handleQuickFilter(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<view
|
||||
v-if="activeStatus === tab.value"
|
||||
class="absolute bottom-0 left-1/4 w-1/2 h-4rpx rounded-2rpx bg-[#1890ff]"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleCardClick(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.no }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(item.status)"
|
||||
>
|
||||
{{ getStatusText(item.status) }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">客户</text>
|
||||
<text>{{ item.customerName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">退货时间</text>
|
||||
<text>{{ formatDate(item.returnTime) }}</text>
|
||||
</view>
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">创建人</text>
|
||||
<text>{{ item.creatorName || '-' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#e6a23c] font-semibold">¥{{ formatPrice(item.totalPrice) }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">应退</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ formatPrice(item.refundPrice) }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">已退</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view
|
||||
class="text-30rpx font-semibold"
|
||||
:class="getUnrefundPrice(item) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
|
||||
>
|
||||
¥{{ formatPrice(getUnrefundPrice(item)) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">未退</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:query'])"
|
||||
size="small"
|
||||
plain
|
||||
@click="handleDetail(item)"
|
||||
>
|
||||
详情
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:update']) && item.status === 10"
|
||||
size="small"
|
||||
type="primary"
|
||||
plain
|
||||
@click="handleEdit(item)"
|
||||
>
|
||||
修改
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && item.status === 10"
|
||||
size="small"
|
||||
type="success"
|
||||
plain
|
||||
@click="handleAudit(item.id!)"
|
||||
>
|
||||
审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:update-status']) && item.status === 20"
|
||||
size="small"
|
||||
type="warning"
|
||||
plain
|
||||
@click="handleReverseAudit(item.id!)"
|
||||
>
|
||||
反审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:sale-return:delete'])"
|
||||
size="small"
|
||||
type="error"
|
||||
plain
|
||||
@click="handleDelete(item.id!)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无销售退货数据" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="list.length > 0"
|
||||
:state="loadMoreState"
|
||||
@reload="loadMore"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<wd-fab
|
||||
v-if="hasAccessByCodes(['erp:sale-return:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { SaleReturn } from '@/api/erp/sale-return'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deleteSaleReturn, getSaleReturnPage, updateSaleReturnStatus } from '@/api/erp/sale-return'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<SaleReturn[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const activeStatus = ref<number | undefined>(undefined)
|
||||
const queryParams = ref<{
|
||||
pageNo: number
|
||||
pageSize: number
|
||||
no?: string
|
||||
customerId?: number
|
||||
status?: number
|
||||
}>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
const statusTabs = [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '待审核', value: 10 },
|
||||
{ label: '已审核', value: 20 },
|
||||
]
|
||||
|
||||
function formatDate(date?: string | number) {
|
||||
if (!date) return '-'
|
||||
const value = new Date(date)
|
||||
if (Number.isNaN(value.getTime())) return String(date).slice(0, 10)
|
||||
return `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function formatPrice(price?: number) {
|
||||
if (price === undefined || price === null) return '0.00'
|
||||
return Number(price).toFixed(2)
|
||||
}
|
||||
|
||||
function getUnrefundPrice(item: SaleReturn) {
|
||||
return Math.max(Number(item.totalPrice || 0) - Number(item.refundPrice || 0), 0)
|
||||
}
|
||||
|
||||
function getStatusText(status?: number) {
|
||||
if (status === 10) return '待审核'
|
||||
if (status === 20) return '已审核'
|
||||
return '未知'
|
||||
}
|
||||
|
||||
function getStatusClass(status?: number) {
|
||||
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getSaleReturnPage({ ...queryParams.value })
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
function handleQuickFilter(status?: number) {
|
||||
activeStatus.value = status
|
||||
queryParams.value.status = status
|
||||
queryParams.value.pageNo = 1
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
function handleQuery(data?: Record<string, any>) {
|
||||
queryParams.value = {
|
||||
...data,
|
||||
status: activeStatus.value,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
activeStatus.value = undefined
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') {
|
||||
return
|
||||
}
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
function handleCardClick(item: SaleReturn) {
|
||||
if (item.status === 20) {
|
||||
handleDetail(item)
|
||||
} else if (item.status === 10) {
|
||||
handleEdit(item)
|
||||
}
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
uni.navigateTo({
|
||||
url: '/pages-erp/sale-return/form/index',
|
||||
})
|
||||
}
|
||||
|
||||
function handleDetail(item: SaleReturn) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/sale-return/detail/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
function handleEdit(item: SaleReturn) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/sale-return/form/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
function handleAudit(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定审批该销售退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updateSaleReturnStatus(id, 20)
|
||||
toast.success('审批成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleReverseAudit(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定反审批该销售退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updateSaleReturnStatus(id, 10)
|
||||
toast.success('反审批成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该销售退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deleteSaleReturn([id])
|
||||
toast.success('删除成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
@@ -115,6 +115,14 @@ const menuGroupsData: MenuGroup[] = [
|
||||
url: '/pages-erp/sale-out/index',
|
||||
iconColor: '#52c41a',
|
||||
permission: 'erp:sale-out:query',
|
||||
},
|
||||
{
|
||||
key: 'saleReturn',
|
||||
name: '销售退货',
|
||||
icon: 'refund',
|
||||
url: '/pages-erp/sale-return/index',
|
||||
iconColor: '#fa8c16',
|
||||
permission: 'erp:sale-return:query',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user