销售换货模块

This commit is contained in:
2026-03-14 10:57:04 +08:00
parent 5a1923d9ca
commit 4546481f48
7 changed files with 1700 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
import request from '@/config/axios'
// ERP 销售换货 VO
export interface SaleExchangeVO {
id: number // 换货编号
no: string // 换货单号
exchangeTime: Date // 换货时间
outId: number // 关联出库单编号
outNo: string // 关联出库单号
customerId: number // 客户编号
customerName: string // 客户名称
saleUserId: number // 销售人员编号
saleUserName: string // 销售人员名称
accountId: number // 结算账户编号
totalOutCount: number // 换出商品总数
totalInCount: number // 换入商品总数
totalPrice: number // 差价金额,单位:元
otherPrice: number // 其它费用,单位:元
status: number // 状态
remark: string // 备注
fileUrl: string // 附件地址
outItems: SaleExchangeOutItemVO[] // 换出商品明细
inItems: SaleExchangeInItemVO[] // 换入商品明细
}
// ERP 销售换货换出商品明细 VO
export interface SaleExchangeOutItemVO {
id: number // 明细编号
exchangeId: number // 换货编号
productId: number // 产品编号
productName: string // 产品名称
productBarCode: string // 产品条码
productUnitId: number // 产品单位编号
productUnitName: string // 产品单位名称
warehouseId: number // 仓库编号
warehouseName: string // 仓库名称
count: number // 换出数量
productPrice: number // 产品单价,单位:元
totalPrice: number // 合计金额,单位:元
}
// ERP 销售换货换入商品明细 VO
export interface SaleExchangeInItemVO {
id: number // 明细编号
exchangeId: number // 换货编号
productId: number // 产品编号
productName: string // 产品名称
productBarCode: string // 产品条码
productUnitId: number // 产品单位编号
productUnitName: string // 产品单位名称
warehouseId: number // 仓库编号
warehouseName: string // 仓库名称
count: number // 换入数量
productPrice: number // 产品单价,单位:元
totalPrice: number // 合计金额,单位:元
}
// 查询销售换货分页
export const getSaleExchangePage = async (params: any) => {
return await request.get({ url: `/erp/sale-exchange/page`, params })
}
// 查询销售换货详情
export const getSaleExchange = async (id: number) => {
return await request.get({ url: `/erp/sale-exchange/get?id=` + id })
}
// 新增销售换货
export const createSaleExchange = async (data: SaleExchangeVO) => {
return await request.post({ url: `/erp/sale-exchange/create`, data })
}
// 修改销售换货
export const updateSaleExchange = async (data: SaleExchangeVO) => {
return await request.put({ url: `/erp/sale-exchange/update`, data })
}
// 更新销售换货的状态
export const updateSaleExchangeStatus = async (id: number, status: number) => {
return await request.put({
url: `/erp/sale-exchange/update-status`,
params: {
id,
status
}
})
}
// 删除销售换货
export const deleteSaleExchange = async (ids: number[]) => {
return await request.delete({
url: `/erp/sale-exchange/delete`,
params: {
ids: ids.join(',')
}
})
}
// 导出销售换货 Excel
export const exportSaleExchange = async (params: any) => {
return await request.download({ url: `/erp/sale-exchange/export-excel`, params })
}

View File

@@ -0,0 +1,411 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="1440">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
:disabled="disabled"
>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="换货单号" prop="no">
<el-input disabled v-model="formData.no" placeholder="保存时自动生成" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="换货时间" prop="exchangeTime">
<el-date-picker
v-model="formData.exchangeTime"
type="date"
value-format="x"
placeholder="选择换货时间"
class="!w-1/1"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="关联出库单" prop="outNo">
<el-input readonly>
<template #prefix>
<el-link
v-if="formData.outNo && formData.outId"
type="primary"
:underline="false"
@click.stop="openSaleOutDetail"
class="order-link"
>
{{ formData.outNo }}
</el-link>
</template>
<template #append>
<el-button @click="openSaleOutEnableList">
<Icon icon="ep:search" /> 选择
</el-button>
</template>
</el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="客户" prop="customerId">
<el-select
v-model="formData.customerId"
clearable
filterable
disabled
placeholder="请选择客户"
class="!w-1/1"
>
<el-option
v-for="item in customerList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="销售人员" prop="saleUserId">
<el-select
v-model="formData.saleUserId"
clearable
filterable
placeholder="请选择销售人员"
class="!w-1/1"
>
<el-option
v-for="item in userList"
:key="item.id"
:label="item.nickname"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="16">
<el-form-item label="备注" prop="remark">
<el-input
type="textarea"
v-model="formData.remark"
:rows="1"
placeholder="请输入备注"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="附件" prop="fileUrl">
<UploadFile :is-show-tip="false" v-model="formData.fileUrl" :limit="1" />
</el-form-item>
</el-col>
</el-row>
<!-- 换货商品清单 -->
<ContentWrap>
<el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
<el-tab-pane label="换入商品清单" name="inItems">
<SaleExchangeInItemForm
ref="inItemFormRef"
:items="formData.inItems"
:disabled="disabled"
@change="calculateTotals"
/>
</el-tab-pane>
<el-tab-pane label="换出商品清单" name="outItems">
<SaleExchangeOutItemForm
ref="outItemFormRef"
:items="formData.outItems"
:disabled="disabled"
@change="calculateTotals"
/>
</el-tab-pane>
</el-tabs>
</ContentWrap>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="换出商品总数">
<el-input disabled v-model="formData.totalOutCount" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="换入商品总数">
<el-input disabled v-model="formData.totalInCount" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="差价金额">
<el-input
disabled
v-model="formData.totalPrice"
:formatter="erpPriceInputFormatter"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="其它费用" prop="otherPrice">
<el-input-number
v-model="formData.otherPrice"
controls-position="right"
:min="0"
:precision="4"
placeholder="请输入其它费用"
class="!w-1/1"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="结算账户" prop="accountId">
<el-select
v-model="formData.accountId"
clearable
filterable
placeholder="请选择结算账户"
class="!w-1/1"
>
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="实际结算金额">
<el-input
disabled
:model-value="formData.totalPrice + formData.otherPrice"
:formatter="erpPriceInputFormatter"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading" v-if="!disabled">
</el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
<!-- 可选择的销售出库单列表 -->
<SaleOutEnableList ref="saleOutEnableListRef" @success="handleSaleOutChange" />
<!-- 销售出库单详情弹窗 -->
<SaleOutForm ref="saleOutFormRef" />
</template>
<script setup lang="ts">
import { getSaleExchange, createSaleExchange, updateSaleExchange, SaleExchangeVO } from '@/api/erp/sale/exchange'
import SaleExchangeOutItemForm from './components/SaleExchangeOutItemForm.vue'
import SaleExchangeInItemForm from './components/SaleExchangeInItemForm.vue'
import { CustomerApi, CustomerVO } from '@/api/erp/sale/customer'
import { AccountApi, AccountVO } from '@/api/erp/finance/account'
import { getSimpleUserList, UserVO } from '@/api/system/user'
import { StockApi } from '@/api/erp/stock/stock'
import { erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
import SaleOutEnableList from './components/SaleOutEnableList.vue'
import SaleOutForm from '../out/SaleOutForm.vue'
defineOptions({ name: 'SaleExchangeForm' })
const { t } = useI18n()
const message = useMessage()
const dialogVisible = ref(false)
const dialogTitle = ref('')
const formLoading = ref(false)
const formType = ref('')
const formData = ref({
id: undefined,
no: undefined,
exchangeTime: undefined,
outId: undefined,
outNo: undefined,
customerId: undefined,
customerName: undefined,
saleUserId: undefined,
accountId: undefined,
totalOutCount: 0,
totalInCount: 0,
totalPrice: 0,
otherPrice: 0,
remark: undefined,
fileUrl: undefined,
status: 10,
outItems: [],
inItems: []
})
const formRules = reactive({
exchangeTime: [{ required: true, message: '换货时间不能为空', trigger: 'blur' }],
outId: [{ required: true, message: '关联出库单不能为空', trigger: 'blur' }],
saleUserId: [{ required: true, message: '销售人员不能为空', trigger: 'blur' }]
})
const formRef = ref()
const disabled = computed(() => formType.value === 'detail')
const subTabsName = ref('outItems')
const outItemFormRef = ref()
const inItemFormRef = ref()
const customerList = ref<CustomerVO[]>([])
const userList = ref<UserVO[]>([])
const accountList = ref<AccountVO[]>([])
const saleOutEnableListRef = ref()
const saleOutFormRef = ref()
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
if (id) {
formLoading.value = true
try {
formData.value = await getSaleExchange(id)
// 加载每个明细项的库存数量
await loadItemsStockCount(formData.value.outItems)
await loadItemsStockCount(formData.value.inItems)
} finally {
formLoading.value = false
}
}
}
const loadItemsStockCount = async (items: any[]) => {
if (!items || items.length === 0) return
for (const item of items) {
if (item.productId && item.warehouseId) {
try {
const stock = await StockApi.getStock2(item.productId, item.warehouseId)
item.stockCount = stock?.count || 0
} catch {
item.stockCount = 0
}
}
}
}
const resetForm = () => {
formData.value = {
id: undefined,
no: undefined,
exchangeTime: new Date().getTime(),
outId: undefined,
outNo: undefined,
customerId: undefined,
customerName: undefined,
saleUserId: undefined,
accountId: undefined,
totalOutCount: 0,
totalInCount: 0,
totalPrice: 0,
otherPrice: 0,
remark: undefined,
fileUrl: undefined,
status: 10,
outItems: [],
inItems: []
}
subTabsName.value = 'outItems'
}
const submitForm = async () => {
await formRef.value.validate()
await outItemFormRef.value?.validate()
await inItemFormRef.value?.validate()
formLoading.value = true
try {
const data = formData.value as unknown as SaleExchangeVO
data.outItems = outItemFormRef.value?.getData() || []
data.inItems = inItemFormRef.value?.getData() || []
if (formType.value === 'create') {
await createSaleExchange(data)
message.success(t('common.createSuccess'))
} else {
await updateSaleExchange(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
emit('success')
} finally {
formLoading.value = false
}
}
const openSaleOutEnableList = () => {
saleOutEnableListRef.value.open()
}
const handleSaleOutChange = (out: any) => {
formData.value.outId = out.id
formData.value.outNo = out.no
formData.value.customerId = out.customerId
formData.value.customerName = out.customerName
formData.value.saleUserId = out.saleUserId
// 自动填充换入商品清单(原出库单的商品作为换入商品)
formData.value.inItems = out.items?.map((item: any) => ({
productId: item.productId,
productName: item.productName,
productBarCode: item.productBarCode,
productUnitId: item.productUnitId,
productUnitName: item.productUnitName,
warehouseId: item.warehouseId,
warehouseName: item.warehouseName,
count: item.count,
productPrice: item.productPrice || 0,
totalPrice: item.totalProductPrice || (item.count * (item.productPrice || 0)),
stockCount: item.stockCount || 0
})) || []
// 清空换出商品清单,让用户手动录入
formData.value.outItems = []
calculateTotals()
}
const calculateTotals = () => {
const outItems = outItemFormRef.value?.getData() || formData.value.outItems || []
const inItems = inItemFormRef.value?.getData() || formData.value.inItems || []
formData.value.totalOutCount = outItems.reduce((sum: number, item: any) => sum + (item.count || 0), 0)
formData.value.totalInCount = inItems.reduce((sum: number, item: any) => sum + (item.count || 0), 0)
const outTotalPrice = outItems.reduce((sum: number, item: any) => sum + (item.totalPrice || 0), 0)
const inTotalPrice = inItems.reduce((sum: number, item: any) => sum + (item.totalPrice || 0), 0)
formData.value.totalPrice = inTotalPrice - outTotalPrice
}
const openSaleOutDetail = () => {
saleOutFormRef.value.open('detail', formData.value.outId)
}
const emit = defineEmits(['success'])
if (onMounted) {
onMounted(async () => {
customerList.value = await CustomerApi.getCustomerSimpleList()
userList.value = await getSimpleUserList()
accountList.value = await AccountApi.getAccountSimpleList()
})
}
defineExpose({ open })
</script>
<style scoped>
.order-link {
color: var(--el-color-primary);
cursor: pointer;
}
</style>

View File

@@ -0,0 +1,152 @@
<template>
<Dialog title="选择产品" v-model="dialogVisible" width="1200px">
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="产品名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入产品名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="产品分类" prop="categoryId">
<el-tree-select
v-model="queryParams.categoryId"
:data="productCategoryList"
:props="defaultProps"
check-strictly
placeholder="请选择产品分类"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column label="产品名称" align="center" prop="name" />
<el-table-column label="产品分类" align="center" prop="categoryName" />
<el-table-column label="产品条码" align="center" prop="barCode" />
<el-table-column label="产品单位" align="center" prop="unitName" />
<el-table-column label="销售价格" align="center" prop="salePrice">
<template #default="scope">
<span>{{ erpPriceInputFormatter(scope.row.salePrice) }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="selectionList.length === 0">
</el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { ProductApi,ProductVO }from '@/api/erp/product/product'
import {ProductCategoryApi ,ProductCategoryVO} from '@/api/erp/product/category'
import { erpPriceInputFormatter } from '@/utils'
defineOptions({ name: 'ProductEnableList' })
const dialogVisible = ref(false)
const loading = ref(true)
const total = ref(0)
const list = ref([])
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: undefined,
categoryId: undefined,
status: 0
})
const queryFormRef = ref()
const selectionList = ref<ProductVO[]>([])
const productCategoryList = ref([])
const defaultProps = {
children: 'children',
label: 'name',
value: 'id'
}
const getList = async () => {
loading.value = true
try {
const data = await ProductApi.getProductPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
const handleSelectionChange = (selection: ProductVO[]) => {
selectionList.value = selection
}
const open = async () => {
dialogVisible.value = true
await getList()
}
const submitForm = () => {
emit('success', selectionList.value)
dialogVisible.value = false
}
const emit = defineEmits(['success'])
onMounted(async () => {
productCategoryList.value = await ProductCategoryApi.getProductCategoryList({})
})
defineExpose({ open })
</script>

View File

@@ -0,0 +1,254 @@
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
v-loading="formLoading"
label-width="0px"
:inline-message="true"
:disabled="disabled"
>
<el-table :data="formData" show-summary :summary-method="getSummaries" class="-mt-10px">
<el-table-column label="序号" type="index" align="center" width="60" />
<el-table-column label="仓库名称" min-width="125">
<template #default="{ row, $index }">
<el-form-item
:prop="`${$index}.warehouseId`"
:rules="formRules.warehouseId"
class="mb-0px!"
>
<el-select
v-model="row.warehouseId"
clearable
filterable
placeholder="请选择仓库"
@change="onChangeWarehouse($event, row)"
>
<el-option
v-for="item in warehouseList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="产品名称" min-width="180">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productName" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="库存" min-width="100">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.stockCount" :formatter="erpCountInputFormatter" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="条码" min-width="150">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productBarCode" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="单位" min-width="80">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productUnitName" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="换入数量" prop="count" fixed="right" min-width="140">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.count`" :rules="formRules.count" class="mb-0px!">
<el-input-number
v-model="row.count"
controls-position="right"
:min="0.001"
:precision="3"
class="!w-100%"
@change="calculateRowPrice(row)"
/>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="产品单价" prop="productPrice" fixed="right" min-width="120">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.productPrice`" :rules="formRules.productPrice" class="mb-0px!">
<el-input-number
v-model="row.productPrice"
controls-position="right"
:min="0"
:precision="4"
class="!w-100%"
@change="calculateRowPrice(row)"
/>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="合计金额" prop="totalPrice" fixed="right" min-width="100">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.totalPrice" :formatter="erpPriceInputFormatter" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="60">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link>
<Icon icon="ep:delete" />
</el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3">
<el-button @click="handleAdd" round>+ 添加换入商品</el-button>
</el-row>
<!-- 产品选择弹窗 -->
<ProductEnableList ref="productEnableListRef" @success="handleProductChange" />
</template>
<script setup lang="ts">
import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
import { StockApi } from '@/api/erp/stock/stock'
import { erpCountInputFormatter, erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
import ProductEnableList from './ProductEnableList.vue'
defineOptions({ name: 'SaleExchangeInItemForm' })
interface Props {
items: any[]
disabled: boolean
}
const props = withDefaults(defineProps<Props>(), {
items: () => [],
disabled: false
})
const formLoading = ref(false)
const formData = ref<any[]>([])
const formRules = reactive({
warehouseId: [{ required: true, message: '仓库不能为空', trigger: 'blur' }],
count: [{ required: true, message: '数量不能为空', trigger: 'blur' }],
productPrice: [{ required: true, message: '单价不能为空', trigger: 'blur' }]
})
const formRef = ref()
const warehouseList = ref<WarehouseVO[]>([])
const productEnableListRef = ref()
watch(
() => props.items,
(val) => {
formData.value = val || []
},
{ immediate: true, deep: true }
)
const handleAdd = () => {
productEnableListRef.value.open()
}
const handleDelete = (index: number) => {
formData.value.splice(index, 1)
emit('change')
}
const handleProductChange = async (products: any[]) => {
for (const product of products) {
const exists = formData.value.find(item => item.productId === product.id)
if (!exists) {
formData.value.push({
productId: product.id,
productName: product.name,
productBarCode: product.barCode,
productUnitId: product.unitId,
productUnitName: product.unitName,
warehouseId: undefined,
warehouseName: undefined,
count: 1,
productPrice: product.salePrice || 0,
totalPrice: product.salePrice || 0,
stockCount: 0
})
}
}
emit('change')
}
const onChangeWarehouse = async (warehouseId: number, row: any) => {
if (!warehouseId || !row.productId) return
const warehouse = warehouseList.value.find(item => item.id === warehouseId)
row.warehouseName = warehouse?.name
try {
const stock = await StockApi.getStock2(row.productId, warehouseId)
row.stockCount = stock?.count || 0
} catch {
row.stockCount = 0
}
}
const calculateRowPrice = (row: any) => {
row.totalPrice = erpPriceMultiply(row.count, row.productPrice)
emit('change')
}
const emit = defineEmits(['change'])
const getSummaries = (param: any) => {
const { columns, data } = param
const sums: string[] = []
columns.forEach((column: any, index: number) => {
if (index === 0) {
sums[index] = '合计'
return
}
if (['count', 'totalPrice'].includes(column.property)) {
const values = data.map((item: any) => Number(item[column.property]))
if (!values.every((value: any) => isNaN(value))) {
const sum = values.reduce((prev: any, curr: any) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
if (column.property === 'totalPrice') {
sums[index] = erpPriceInputFormatter(sum)
} else {
sums[index] = erpCountInputFormatter(sum)
}
} else {
sums[index] = ''
}
} else {
sums[index] = ''
}
})
return sums
}
const validate = async () => {
return await formRef.value?.validate()
}
const getData = () => {
return formData.value
}
onMounted(async () => {
warehouseList.value = await WarehouseApi.getWarehouseSimpleList()
})
defineExpose({ validate, getData })
</script>

View File

@@ -0,0 +1,256 @@
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
v-loading="formLoading"
label-width="0px"
:inline-message="true"
:disabled="disabled"
>
<el-table :data="formData" show-summary :summary-method="getSummaries" class="-mt-10px">
<el-table-column label="序号" type="index" align="center" width="60" />
<el-table-column label="仓库名称" min-width="125">
<template #default="{ row, $index }">
<el-form-item
:prop="`${$index}.warehouseId`"
:rules="formRules.warehouseId"
class="mb-0px!"
>
<el-select
v-model="row.warehouseId"
clearable
filterable
placeholder="请选择仓库"
@change="onChangeWarehouse($event, row)"
>
<el-option
v-for="item in warehouseList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="产品名称" min-width="180">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productName" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="库存" min-width="100">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.stockCount" :formatter="erpCountInputFormatter" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="条码" min-width="150">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productBarCode" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="单位" min-width="80">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productUnitName" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="换出数量" prop="count" fixed="right" min-width="140">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.count`" :rules="formRules.count" class="mb-0px!">
<el-input-number
v-model="row.count"
controls-position="right"
:min="0.001"
:precision="3"
class="!w-100%"
@change="calculateRowPrice(row)"
/>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="产品单价" prop="productPrice" fixed="right" min-width="120">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.productPrice`" :rules="formRules.productPrice" class="mb-0px!">
<el-input-number
v-model="row.productPrice"
controls-position="right"
:min="0"
:precision="4"
class="!w-100%"
@change="calculateRowPrice(row)"
/>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="合计金额" prop="totalPrice" fixed="right" min-width="100">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.totalPrice" :formatter="erpPriceInputFormatter" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="60">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link>
<Icon icon="ep:delete" />
</el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3">
<el-button @click="handleAdd" round>+ 添加换出商品</el-button>
</el-row>
<!-- 产品选择弹窗 -->
<ProductEnableList ref="productEnableListRef" @success="handleProductChange" />
</template>
<script setup lang="ts">
import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
import { StockApi } from '@/api/erp/stock/stock'
import { erpCountInputFormatter, erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
import ProductEnableList from './ProductEnableList.vue'
defineOptions({ name: 'SaleExchangeOutItemForm' })
interface Props {
items: any[]
disabled: boolean
}
const props = withDefaults(defineProps<Props>(), {
items: () => [],
disabled: false
})
const formLoading = ref(false)
const formData = ref<any[]>([])
const formRules = reactive({
warehouseId: [{ required: true, message: '仓库不能为空', trigger: 'blur' }],
count: [{ required: true, message: '数量不能为空', trigger: 'blur' }],
productPrice: [{ required: true, message: '单价不能为空', trigger: 'blur' }]
})
const formRef = ref()
const warehouseList = ref<WarehouseVO[]>([])
const productEnableListRef = ref()
watch(
() => props.items,
(val) => {
formData.value = val || []
},
{ immediate: true, deep: true }
)
const handleAdd = () => {
productEnableListRef.value.open()
}
const handleDelete = (index: number) => {
formData.value.splice(index, 1)
emit('change')
}
const handleProductChange = async (products: any[]) => {
for (const product of products) {
const exists = formData.value.find(item => item.productId === product.id)
if (!exists) {
formData.value.push({
productId: product.id,
productName: product.name,
productBarCode: product.barCode,
productUnitId: product.unitId,
productUnitName: product.unitName,
warehouseId: undefined,
warehouseName: undefined,
count: 1,
productPrice: product.salePrice || 0,
totalPrice: product.salePrice || 0,
stockCount: 0
})
}
}
emit('change')
}
const onChangeWarehouse = async (warehouseId: number, row: any) => {
if (!warehouseId || !row.productId) return
const warehouse = warehouseList.value.find(item => item.id === warehouseId)
row.warehouseName = warehouse?.name
try {
const stock = await StockApi.getStock2(row.productId, warehouseId)
row.stockCount = stock?.count || 0
} catch {
row.stockCount = 0
}
}
const calculateRowPrice = (row: any) => {
row.totalPrice = erpPriceMultiply(row.count, row.productPrice)
emit('change')
}
const emit = defineEmits(['change'])
const getSummaries = (param: any) => {
const { columns, data } = param
const sums: string[] = []
columns.forEach((column: any, index: number) => {
if (index === 0) {
sums[index] = '合计'
return
}
if (['count', 'totalPrice'].includes(column.property)) {
const values = data.map((item: any) => Number(item[column.property]))
if (!values.every((value: any) => isNaN(value))) {
const sum = values.reduce((prev: any, curr: any) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
if (column.property === 'totalPrice') {
sums[index] = erpPriceInputFormatter(sum)
} else {
sums[index] = erpCountInputFormatter(sum)
}
} else {
sums[index] = ''
}
} else {
sums[index] = ''
}
})
return sums
}
const validate = async () => {
return await formRef.value?.validate()
}
const getData = () => {
return formData.value
}
if (onMounted) {
onMounted(async () => {
warehouseList.value = await WarehouseApi.getWarehouseSimpleList()
})
}
defineExpose({ validate, getData })
</script>

View File

@@ -0,0 +1,177 @@
<template>
<Dialog title="选择销售出库单" v-model="dialogVisible" width="1200px">
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="出库单号" prop="no">
<el-input
v-model="queryParams.no"
placeholder="请输入出库单号"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="客户" prop="customerId">
<el-select
v-model="queryParams.customerId"
clearable
filterable
placeholder="请选择客户"
class="!w-240px"
>
<el-option
v-for="item in customerList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="出库时间" prop="outTime">
<el-date-picker
v-model="queryParams.outTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column label="出库单号" align="center" prop="no" width="180"/>
<el-table-column label="出库时间" align="center" prop="outTime" :formatter="dateFormatter2" width="180"/>
<el-table-column label="客户" align="center" prop="customerName" />
<!-- <el-table-column label="销售人员" align="center" prop="saleUserName" />-->
<el-table-column label="商品数量" align="center" prop="totalCount" />
<el-table-column label="总金额" align="center" prop="totalPrice">
<template #default="scope">
<span>{{ erpPriceInputFormatter(scope.row.totalPrice) }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.ERP_AUDIT_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="!selectedOut">
</el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter2 } from '@/utils/formatTime'
import { SaleOutApi,SaleOutVO} from '@/api/erp/sale/out'
import {CustomerApi,CustomerVO} from '@/api/erp/sale/customer'
import { erpPriceInputFormatter } from '@/utils'
defineOptions({ name: 'SaleOutEnableList' })
const dialogVisible = ref(false)
const loading = ref(true)
const total = ref(0)
const list = ref([])
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
no: undefined,
customerId: undefined,
outTime: [],
status: 20 // 只显示已审核的出库单
})
const queryFormRef = ref()
const selectedOut = ref<SaleOutVO | null>(null)
const customerList = ref<CustomerVO[]>([])
const getList = async () => {
loading.value = true
try {
const data = await SaleOutApi.getSaleOutPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
const handleSelectionChange = (selection: SaleOutVO[]) => {
selectedOut.value = selection.length > 0 ? selection[0] : null
}
const open = async () => {
dialogVisible.value = true
selectedOut.value = null
await getList()
}
const submitForm = async () => {
if (!selectedOut.value) return
// 获取出库单详情,包含商品明细
const outDetail = await SaleOutApi.getSaleOut(selectedOut.value.id)
emit('success', outDetail)
dialogVisible.value = false
}
const emit = defineEmits(['success'])
if (onMounted) {
onMounted(async () => {
customerList.value = await CustomerApi.getCustomerSimpleList()
})
}
defineExpose({ open })
</script>

View File

@@ -0,0 +1,348 @@
<template>
<doc-alert title="【销售】销售订单、出库、退货" url="https://doc.iocoder.cn/erp/sale/" />
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="换货单号" prop="no">
<el-input
v-model="queryParams.no"
placeholder="请输入换货单号"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="产品" prop="productId">
<el-select
v-model="queryParams.productId"
clearable
filterable
placeholder="请选择产品"
class="!w-240px"
>
<el-option
v-for="item in productList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="换货时间" prop="exchangeTime">
<el-date-picker
v-model="queryParams.exchangeTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="客户" prop="customerId">
<el-select
v-model="queryParams.customerId"
clearable
filterable
placeholder="请选择客户"
class="!w-240px"
>
<el-option
v-for="item in customerList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="请选择状态"
clearable
class="!w-240px"
>
<el-option label="未审核" value="10" />
<el-option label="已审核" value="20" />
</el-select>
</el-form-item>
<el-form-item label="关联出库单" prop="outNo">
<el-input
v-model="queryParams.outNo"
placeholder="请输入关联出库单号"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['erp:sale-exchange:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['erp:sale-exchange:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
<el-button
type="danger"
plain
@click="handleDelete(selectionList.map((item) => item.id))"
v-hasPermi="['erp:sale-exchange:delete']"
:disabled="selectionList.length === 0"
>
<Icon icon="ep:delete" class="mr-5px" /> 删除
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column label="换货单号" align="center" prop="no" width="180"/>
<el-table-column
label="换货时间"
align="center"
prop="exchangeTime"
:formatter="dateFormatter" width="180" />
<el-table-column label="客户" align="center" prop="customerName" />
<el-table-column label="销售人员" align="center" prop="saleUserName" />
<el-table-column label="关联出库单" align="center" prop="outNo" width="180px">
<template #default="scope">
<el-link
v-if="scope.row.outNo"
type="primary"
@click="openSaleOutDetail(scope.row.outId)"
>
{{ scope.row.outNo }}
</el-link>
</template>
</el-table-column>
<el-table-column label="换出商品总数" align="center" prop="totalOutCount" />
<el-table-column label="换入商品总数" align="center" prop="totalInCount" />
<el-table-column label="总金额" align="center" prop="totalPrice">
<template #default="scope">
<span>{{ erpPriceInputFormatter(scope.row.totalPrice) }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.ERP_AUDIT_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column
label="操作"
align="center"
width="220"
class-name="small-padding fixed-width"
>
<template #default="scope">
<el-tooltip content="详情" placement="top">
<el-button
link
type="primary"
@click="openForm('detail', scope.row.id)"
v-hasPermi="['erp:sale-exchange:query']"
>
详情
</el-button>
</el-tooltip>
<el-tooltip content="编辑" placement="top">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['erp:sale-exchange:update']"
:disabled="scope.row.status === 20"
>
编辑
</el-button>
</el-tooltip>
<el-tooltip content="审核" placement="top" v-if="scope.row.status === 10">
<el-button
link
type="success"
@click="handleUpdateStatus(scope.row.id, 20)"
v-hasPermi="['erp:sale-exchange:update-status']"
>
审核
</el-button>
</el-tooltip>
<el-tooltip content="反审核" placement="top" v-else>
<el-button
link
type="warning"
@click="handleUpdateStatus(scope.row.id, 10)"
v-hasPermi="['erp:sale-exchange:update-status']"
>
反审核
</el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button
link
type="danger"
@click="handleDelete([scope.row.id])"
v-hasPermi="['erp:sale-exchange:delete']"
>
删除
</el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改/详情 -->
<SaleExchangeForm ref="formRef" @success="getList" />
<!-- 销售出库单详情弹窗 -->
<SaleOutForm ref="saleOutFormRef" />
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter,dateFormatter2 } from '@/utils/formatTime'
import download from '@/utils/download'
import { getSaleExchangePage, deleteSaleExchange, updateSaleExchangeStatus, exportSaleExchange, SaleExchangeVO } from '@/api/erp/sale/exchange'
import {ProductApi,ProductVO} from '@/api/erp/product/product'
import {CustomerApi,CustomerVO} from '@/api/erp/sale/customer'
import SaleExchangeForm from './SaleExchangeForm.vue'
import { erpPriceInputFormatter } from '@/utils'
import SaleOutForm from '@/views/erp/sale/out/SaleOutForm.vue'
import {ErpBizType} from "@/utils/constants";
defineOptions({ name: 'ErpSaleExchange' })
const message = useMessage()
const { t } = useI18n()
const loading = ref(true)
const total = ref(0)
const list = ref([])
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
no: undefined,
customerId: undefined,
productId: undefined,
exchangeTime: [],
status: undefined,
outNo: undefined,
remark: undefined
})
const queryFormRef = ref()
const exportLoading = ref(false)
const selectionList = ref<SaleExchangeVO[]>([])
const productList = ref<ProductVO[]>([])
const customerList = ref<CustomerVO[]>([])
const getList = async () => {
loading.value = true
try {
const data = await getSaleExchangePage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
const handleSelectionChange = (selection: SaleExchangeVO[]) => {
selectionList.value = selection
}
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
const handleDelete = async (ids: number[]) => {
try {
await message.delConfirm()
await deleteSaleExchange(ids)
message.success(t('common.delSuccess'))
await getList()
} catch {}
}
const handleUpdateStatus = async (id: number, status: number) => {
try {
await updateSaleExchangeStatus(id, status)
message.success('更新状态成功')
await getList()
} catch {}
}
const handleExport = async () => {
try {
await message.exportConfirm()
exportLoading.value = true
const data = await exportSaleExchange(queryParams)
download.excel(data, '销售换货.xls')
} catch {
} finally {
exportLoading.value = false
}
}
const saleOutFormRef = ref()
const openSaleOutDetail = (id: number) => {
console.log('打开销售出库单详情', id)
saleOutFormRef.value.open('detail', id)
}
if (onMounted) {
onMounted(async () => {
await getList()
productList.value = await ProductApi.getProductSimpleList()
customerList.value = await CustomerApi.getCustomerSimpleList()
})
}
</script>