!205 feat(@vben/web-antd): erp 模块除去收款单和付款单功能基本完成
* fix(@vben/web-antd): erp 解决冲突 * fix(@vben/web-antd): erp 更新采购和销售退货表单,修复关联订单选择功能不统一详细可编辑的问题,统一文件名称格式 * feat(@vben/web-antd): erp-finance-account 新增结算账户管理功能,包括表单、列表及相关操作 * feat(@vben/web-antd): erp-sale-return 新增销售退货管理功能,包括退货列表、表单及相关操作 * feat(@vben/web-antd): erp-sale-out 新增销售出库管理功能,包括出库列表、表单及相关操作 * feat(@vben/web-antd): erp-sale-order 新增销售订单管理功能,包括订单列表、表单及相关操作 * feat(@vben/web-antd): erp-sale-customer 新增客户管理功能,包括客户表单、列表及相关操作 * feat(@vben/web-antd): erp-purchase-return 新增采购退货管理功能,包括表单、列表及相关操作 * feat(@vben/web-antd): erp-purchase-in 新增采购入库管理功能,包括表单、列表及相关操作 * feat(@vben/web-antd): erp-stock-check 新增库存盘点单管理功能,包括表单、列表及相关操作 * feat(@vben/web-antd): erp-stock-move 新增库存调拨单管理功能,包括表单、列表及相关操作 * feat(@vben/web-antd): erp-stock-out 新增其它出库单管理功能,包括表单、列表及相关操作 * fix(@vben/web-antd): erp-stock-in 修复提交表单时清空产品项 ID,确保请求成功不报row_xxx报错pull/207/MERGE
parent
4af5931e92
commit
bc2b71baa3
|
|
@ -2,19 +2,45 @@ import type { PageParam, PageResult } from '@vben/request';
|
|||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
namespace ErpPurchaseInApi {
|
||||
export namespace ErpPurchaseInApi {
|
||||
/** 采购入库信息 */
|
||||
export interface PurchaseIn {
|
||||
id?: number; // 入库工单编号
|
||||
no: string; // 采购入库号
|
||||
supplierId: number; // 供应商编号
|
||||
inTime: Date; // 入库时间
|
||||
totalCount: number; // 合计数量
|
||||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
outCount: number; // 采购出库数量
|
||||
returnCount: number; // 采购退货数量
|
||||
no?: string; // 采购入库号
|
||||
supplierId?: number; // 供应商编号
|
||||
inTime?: Date; // 入库时间
|
||||
totalCount?: number; // 合计数量
|
||||
totalPrice?: number; // 合计金额,单位:元
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
outCount?: number; // 采购出库数量
|
||||
returnCount?: number; // 采购退货数量
|
||||
discountPercent?: number; // 折扣百分比
|
||||
discountPrice?: number; // 折扣金额
|
||||
paymentPrice?: number; // 实际支付金额
|
||||
otherPrice?: number; // 其他费用
|
||||
totalProductPrice?: number; // 合计商品金额
|
||||
taxPrice?: number; // 合计税额
|
||||
items?: PurchaseInItem[]; // 采购入库明细
|
||||
}
|
||||
export interface PurchaseInItem {
|
||||
count?: number;
|
||||
id?: number;
|
||||
orderItemId?: number;
|
||||
productBarCode?: string;
|
||||
productId?: number;
|
||||
productName: string;
|
||||
productPrice: number;
|
||||
productUnitId?: number;
|
||||
productUnitName?: string;
|
||||
totalProductPrice?: number;
|
||||
remark: string;
|
||||
stockCount?: number;
|
||||
taxPercent?: number;
|
||||
taxPrice?: number;
|
||||
totalPrice?: number;
|
||||
warehouseId?: number;
|
||||
inCount?: number;
|
||||
}
|
||||
|
||||
/** 采购入库分页查询参数 */
|
||||
|
|
@ -71,11 +97,12 @@ export function updatePurchaseIn(data: ErpPurchaseInApi.PurchaseIn) {
|
|||
/**
|
||||
* 更新采购入库的状态
|
||||
*/
|
||||
export function updatePurchaseInStatus(
|
||||
params: ErpPurchaseInApi.PurchaseInStatusParams,
|
||||
) {
|
||||
export function updatePurchaseInStatus(id: number, status: number) {
|
||||
return requestClient.put('/erp/purchase-in/update-status', null, {
|
||||
params,
|
||||
params: {
|
||||
id,
|
||||
status,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ export namespace ErpPurchaseOrderApi {
|
|||
remark?: string; // 备注
|
||||
fileUrl?: string; // 附件地址
|
||||
inCount?: number; // 采购入库数量
|
||||
count?: number; // 数量
|
||||
returnCount?: number; // 采购退货数量
|
||||
inStatus?: number; // 入库状态
|
||||
returnStatus?: number; // 退货状态
|
||||
|
|
|
|||
|
|
@ -2,17 +2,40 @@ import type { PageParam, PageResult } from '@vben/request';
|
|||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
namespace ErpPurchaseReturnApi {
|
||||
export namespace ErpPurchaseReturnApi {
|
||||
/** 采购退货信息 */
|
||||
export interface PurchaseReturn {
|
||||
id?: number; // 采购退货编号
|
||||
no: string; // 采购退货号
|
||||
supplierId: number; // 供应商编号
|
||||
returnTime: Date; // 退货时间
|
||||
totalCount: number; // 合计数量
|
||||
no?: string; // 采购退货号
|
||||
supplierId?: number; // 供应商编号
|
||||
returnTime?: Date; // 退货时间
|
||||
totalCount?: number; // 合计数量
|
||||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
discountPercent?: number; // 折扣百分比
|
||||
discountPrice?: number; // 折扣金额
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
totalTaxPrice?: number; // 合计税额
|
||||
otherPrice?: number; // 其他费用
|
||||
items?: PurchaseReturnItem[];
|
||||
}
|
||||
export interface PurchaseReturnItem {
|
||||
count?: number;
|
||||
id?: number;
|
||||
orderItemId?: number;
|
||||
productBarCode?: string;
|
||||
productId?: number;
|
||||
productName: string;
|
||||
productPrice: number;
|
||||
productUnitId?: number;
|
||||
productUnitName?: string;
|
||||
totalProductPrice?: number;
|
||||
remark: string;
|
||||
stockCount?: number;
|
||||
taxPercent?: number;
|
||||
taxPrice?: number;
|
||||
totalPrice?: number;
|
||||
warehouseId?: number;
|
||||
}
|
||||
|
||||
/** 采购退货分页查询参数 */
|
||||
|
|
|
|||
|
|
@ -8,13 +8,40 @@ export namespace ErpSaleOrderApi {
|
|||
id?: number; // 订单工单编号
|
||||
no: string; // 销售订单号
|
||||
customerId: number; // 客户编号
|
||||
accountId?: number; // 收款账户编号
|
||||
orderTime: Date; // 订单时间
|
||||
totalCount: number; // 合计数量
|
||||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
outCount: number; // 销售出库数量
|
||||
fileUrl?: string; // 附件地址
|
||||
inCount?: number; // 采购入库数量
|
||||
returnCount: number; // 销售退货数量
|
||||
totalProductPrice?: number; // 产品金额,单位:元
|
||||
discountPercent?: number; // 优惠率,百分比
|
||||
discountPrice?: number; // 优惠金额,单位:元
|
||||
depositPrice?: number; // 定金金额,单位:元
|
||||
items?: SaleOrderItem[]; // 销售订单产品明细列表
|
||||
}
|
||||
/** ERP 销售订单产品明细 */
|
||||
export interface SaleOrderItem {
|
||||
id?: number; // 订单项编号
|
||||
orderId?: number; // 采购订单编号
|
||||
productId?: number; // 产品编号
|
||||
productName?: string; // 产品名称
|
||||
productBarCode?: string; // 产品条码
|
||||
productUnitId?: number; // 产品单位编号
|
||||
productUnitName?: string; // 产品单位名称
|
||||
productPrice?: number; // 产品单价,单位:元
|
||||
totalProductPrice?: number; // 产品总价,单位:元
|
||||
count?: number; // 数量
|
||||
totalPrice?: number; // 总价,单位:元
|
||||
taxPercent?: number; // 税率,百分比
|
||||
taxPrice?: number; // 税额,单位:元
|
||||
totalTaxPrice?: number; // 含税总价,单位:元
|
||||
remark?: string; // 备注
|
||||
stockCount?: number; // 库存数量(显示字段)
|
||||
}
|
||||
|
||||
/** 销售订单分页查询参数 */
|
||||
|
|
|
|||
|
|
@ -2,17 +2,45 @@ import type { PageParam, PageResult } from '@vben/request';
|
|||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
namespace ErpSaleOutApi {
|
||||
export namespace ErpSaleOutApi {
|
||||
/** 销售出库信息 */
|
||||
export interface SaleOut {
|
||||
id?: number; // 销售出库编号
|
||||
no: string; // 销售出库号
|
||||
customerId: number; // 客户编号
|
||||
outTime: Date; // 出库时间
|
||||
totalCount: number; // 合计数量
|
||||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
no?: string; // 销售出库号
|
||||
customerId?: number; // 客户编号
|
||||
saleUserId?: number; // 客户编号
|
||||
outTime?: Date; // 出库时间
|
||||
totalCount?: number; // 合计数量
|
||||
totalPrice?: number; // 合计金额,单位:元
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
discountPercent?: number; // 折扣百分比
|
||||
discountPrice?: number; // 折扣金额
|
||||
otherPrice?: number; // 其他费用
|
||||
totalProductPrice?: number; // 合计商品金额
|
||||
taxPrice?: number; // 合计税额
|
||||
totalTaxPrice?: number; // 合计税额
|
||||
fileUrl?: string; // 附件地址
|
||||
items?: SaleOutItem[];
|
||||
}
|
||||
export interface SaleOutItem {
|
||||
count?: number;
|
||||
id?: number;
|
||||
orderItemId?: number;
|
||||
productBarCode?: string;
|
||||
productId?: number;
|
||||
productName: string;
|
||||
productPrice: number;
|
||||
productUnitId?: number;
|
||||
productUnitName?: string;
|
||||
totalProductPrice?: number;
|
||||
remark: string;
|
||||
stockCount?: number;
|
||||
taxPercent?: number;
|
||||
taxPrice?: number;
|
||||
totalPrice?: number;
|
||||
warehouseId?: number;
|
||||
outCount?: number;
|
||||
}
|
||||
|
||||
/** 销售出库分页查询参数 */
|
||||
|
|
|
|||
|
|
@ -2,17 +2,44 @@ import type { PageParam, PageResult } from '@vben/request';
|
|||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
namespace ErpSaleReturnApi {
|
||||
export namespace ErpSaleReturnApi {
|
||||
/** 销售退货信息 */
|
||||
export interface SaleReturn {
|
||||
id?: number; // 销售退货编号
|
||||
no: string; // 销售退货号
|
||||
customerId: number; // 客户编号
|
||||
returnTime: Date; // 退货时间
|
||||
totalCount: number; // 合计数量
|
||||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
no?: string; // 销售退货号
|
||||
customerId?: number; // 客户编号
|
||||
returnTime?: Date; // 退货时间
|
||||
totalCount?: number; // 合计数量
|
||||
totalPrice?: number; // 合计金额,单位:元
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
discountPercent?: number; // 折扣百分比
|
||||
discountPrice?: number; // 折扣金额
|
||||
otherPrice?: number; // 其他费用
|
||||
totalProductPrice?: number; // 合计商品金额
|
||||
taxPrice?: number; // 合计税额
|
||||
totalTaxPrice?: number; // 合计税额
|
||||
fileUrl?: string; // 附件地址
|
||||
items?: SaleReturnItem[];
|
||||
}
|
||||
export interface SaleReturnItem {
|
||||
count?: number;
|
||||
id?: number;
|
||||
orderItemId?: number;
|
||||
productBarCode?: string;
|
||||
productId?: number;
|
||||
productName: string;
|
||||
productPrice: number;
|
||||
productUnitId?: number;
|
||||
productUnitName?: string;
|
||||
totalProductPrice?: number;
|
||||
remark: string;
|
||||
stockCount?: number;
|
||||
taxPercent?: number;
|
||||
taxPrice?: number;
|
||||
totalPrice?: number;
|
||||
warehouseId?: number;
|
||||
returnCount?: number;
|
||||
}
|
||||
|
||||
/** 销售退货分页查询参数 */
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import type { PageParam, PageResult } from '@vben/request';
|
|||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
namespace ErpStockCheckApi {
|
||||
export namespace ErpStockCheckApi {
|
||||
/** 库存盘点单信息 */
|
||||
export interface StockCheck {
|
||||
id?: number; // 盘点编号
|
||||
|
|
@ -12,8 +12,27 @@ namespace ErpStockCheckApi {
|
|||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
fileUrl?: string; // 附件
|
||||
productNames?: string; // 产品信息
|
||||
creatorName?: string; // 创建人
|
||||
items?: StockCheckItem[]; // 盘点产品清单
|
||||
}
|
||||
// 库存盘点单产品信息
|
||||
export interface StockCheckItem {
|
||||
id?: number; // 编号
|
||||
warehouseId?: number; // 仓库编号
|
||||
productId?: number; // 产品编号
|
||||
productName?: string; // 产品名称
|
||||
productUnitId?: number; // 产品单位编号
|
||||
productUnitName?: string; // 产品单位名称
|
||||
productBarCode?: string; // 产品条码
|
||||
count?: number; // 盈亏数量
|
||||
actualCount?: number; // 实际库存
|
||||
productPrice?: number; // 产品单价
|
||||
totalPrice?: number; // 总价
|
||||
stockCount?: number; // 账面库存
|
||||
remark?: string; // 备注
|
||||
}
|
||||
|
||||
/** 库存盘点单分页查询参数 */
|
||||
export interface StockCheckPageParams extends PageParam {
|
||||
no?: string;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import type { PageParam, PageResult } from '@vben/request';
|
|||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
namespace ErpStockMoveApi {
|
||||
export namespace ErpStockMoveApi {
|
||||
/** 库存调拨单信息 */
|
||||
export interface StockMove {
|
||||
id?: number; // 调拨编号
|
||||
|
|
@ -12,6 +12,29 @@ namespace ErpStockMoveApi {
|
|||
totalPrice: number; // 合计金额,单位:元
|
||||
status: number; // 状态
|
||||
remark: string; // 备注
|
||||
fileUrl?: string; // 附件
|
||||
fromWarehouseId?: number; // 来源仓库编号
|
||||
createTime: Date; // 创建时间
|
||||
creator: string; // 创建人
|
||||
creatorName: string; // 创建人名称
|
||||
productNames: string; // 产品名称
|
||||
items?: StockMoveItem[]; // 子表信息
|
||||
}
|
||||
|
||||
/** 库存调拨单子表信息 */
|
||||
export interface StockMoveItem {
|
||||
count: number; // 数量
|
||||
fromWarehouseId?: number; // 来源仓库ID
|
||||
id?: number; // ID
|
||||
productBarCode: string; // 产品条形码
|
||||
productId?: number; // 产品ID
|
||||
productName?: string; // 产品名称
|
||||
productPrice: number; // 产品单价
|
||||
productUnitName?: string; // 产品单位
|
||||
remark?: string; // 备注
|
||||
stockCount: number; // 库存数量
|
||||
toWarehouseId?: number; // 目标仓库ID
|
||||
totalPrice?: number; // 总价
|
||||
}
|
||||
|
||||
/** 库存调拨单分页查询参数 */
|
||||
|
|
|
|||
|
|
@ -72,3 +72,12 @@ export function exportStock(params: ErpStockApi.StockPageParams) {
|
|||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取库存数量
|
||||
*/
|
||||
export function getWarehouseStockCount(params: ErpStockApi.StockQueryParams) {
|
||||
return requestClient.get<number>('/erp/stock/get-count', {
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,167 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { Tag } from 'ant-design-vue';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '名称',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
placeholder: '请输入名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入排序',
|
||||
precision: 0,
|
||||
class: 'w-full',
|
||||
},
|
||||
rules: 'required',
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
fieldName: 'defaultStatus',
|
||||
label: '是否默认',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{
|
||||
label: '是',
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
label: '否',
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.boolean().default(false).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '名称',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '编码',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '名称',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '编码',
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '排序',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'defaultStatus',
|
||||
title: '是否默认',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
return h(
|
||||
Tag,
|
||||
{
|
||||
class: 'mr-1',
|
||||
color: row.defaultStatus ? 'blue' : 'red',
|
||||
},
|
||||
() => (row.defaultStatus ? '是' : '否'),
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,152 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpAccountApi } from '#/api/erp/finance/account';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteAccount,
|
||||
exportAccount,
|
||||
getAccountPage,
|
||||
} from '#/api/erp/finance/account';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportAccount(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '结算账户信息.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建结算账户 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑结算账户 */
|
||||
function handleEdit(row: ErpAccountApi.Account) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除结算账户 */
|
||||
async function handleDelete(row: ErpAccountApi.Account) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
await deleteAccount(row.id as number);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getAccountPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpAccountApi.Account>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【财务】采购付款、销售收款"
|
||||
url="https://doc.iocoder.cn/sale/finance-payment-receipt/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/finance/account/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/finance/account/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
<Grid table-title="结算账户列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['结算账户']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:account:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:account:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:account:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:account:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpAccountApi } from '#/api/erp/finance/account';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createAccount,
|
||||
getAccount,
|
||||
updateAccount,
|
||||
} from '#/api/erp/finance/account';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<ErpAccountApi.Account>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['结算产品'])
|
||||
: $t('ui.actionTitle.create', ['结算产品']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
// 一共2列
|
||||
wrapperClass: 'grid-cols-1',
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpAccountApi.Account;
|
||||
try {
|
||||
await (formData.value?.id ? updateAccount(data) : createAccount(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<ErpAccountApi.Account>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getAccount(data.id as number);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-2/5" :title="getTitle">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,586 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { erpPriceInputFormatter } from '@vben/utils';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getAccountSimpleList } from '#/api/erp/finance/account';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getSupplierSimpleList } from '#/api/erp/purchase/supplier';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(formType: string): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '入库单号',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: '请选择供应商',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSupplierSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'supplierId',
|
||||
label: '供应商',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-1',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '请选择关联订单',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '选择订单时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'inTime',
|
||||
label: '入库时间',
|
||||
rules: 'required',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
disabled: formType === 'detail',
|
||||
autoSize: { minRows: 1, maxRows: 1 },
|
||||
class: 'w-full',
|
||||
},
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
formItemClass: 'col-span-2',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'FileUpload',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'discountPercent',
|
||||
componentProps: {
|
||||
placeholder: '优惠率',
|
||||
min: 0,
|
||||
max: 100,
|
||||
disabled: true,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
|
||||
label: '优惠率(%)',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '付款优惠',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountPrice',
|
||||
label: '付款优惠',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '优惠后金额',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountedPrice',
|
||||
label: '优惠后金额',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '请输入其他费用',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'otherPrice',
|
||||
label: '其他费用',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择结算账户',
|
||||
disabled: true,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getAccountSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'accountId',
|
||||
label: '结算账户',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
disabled: true,
|
||||
min: 0,
|
||||
},
|
||||
fieldName: 'totalPrice',
|
||||
label: '应付金额',
|
||||
rules: z.number().min(0).optional(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购订单项表格列定义 */
|
||||
export function usePurchaseOrderItemTableColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'warehouseId',
|
||||
title: '仓库名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'warehouseId' },
|
||||
},
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '仓库库存',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '原数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'inCount',
|
||||
title: '已入库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '数量',
|
||||
minWidth: 120,
|
||||
fixed: 'right',
|
||||
slots: { default: 'count' },
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
fixed: 'right',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
fixed: 'right',
|
||||
title: '产品金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPercent',
|
||||
title: '税率(%)',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPrice',
|
||||
title: '税额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
fixed: 'right',
|
||||
title: '合计金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '入库单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入入库单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'inTime',
|
||||
label: '入库时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'supplierId',
|
||||
label: '供应商',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择供应商',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSupplierSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'warehouseId',
|
||||
label: '仓库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择仓库',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getWarehouseSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
fieldNames: {
|
||||
label: 'nickname',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入关联订单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'paymentStatus',
|
||||
label: '付款状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '未付款', value: 0 },
|
||||
{ label: '部分付款', value: 1 },
|
||||
{ label: '全部付款', value: 2 },
|
||||
],
|
||||
placeholder: '请选择退货状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '入库单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'supplierName',
|
||||
title: '供应商',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'inTime',
|
||||
title: '入库时间',
|
||||
width: 160,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '应付金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'paymentPrice',
|
||||
title: '已付金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 250,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
/** 列表的搜索表单 */
|
||||
export function useOrderGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '订单单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入订单单号',
|
||||
allowClear: true,
|
||||
disabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderTime',
|
||||
label: '订单时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useOrderGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'radio',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '订单单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'supplierName',
|
||||
title: '供应商',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'orderTime',
|
||||
title: '订单时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'inCount',
|
||||
title: '入库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
title: '金额合计',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '含税金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,232 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePurchaseIn,
|
||||
exportPurchaseIn,
|
||||
getPurchaseInPage,
|
||||
updatePurchaseInStatus,
|
||||
} from '#/api/erp/purchase/in';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import PurchaseInForm from './modules/purchase-in-form.vue';
|
||||
|
||||
/** ERP 采购入库列表 */
|
||||
defineOptions({ name: 'ErpPurchaseIn' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: PurchaseInForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
|
||||
/** 详情 */
|
||||
function handleDetail(row: ErpPurchaseInApi.PurchaseIn) {
|
||||
formModalApi.setData({ type: 'detail', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(row: ErpPurchaseInApi.PurchaseIn) {
|
||||
formModalApi.setData({ type: 'edit', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: number[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deletePurchaseIn(ids);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess'),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 处理错误
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审批/反审批操作 */
|
||||
function handleUpdateStatus(row: ErpPurchaseInApi.PurchaseIn, status: number) {
|
||||
const hideLoading = message.loading({
|
||||
content: `确定${status === 20 ? '审批' : '反审批'}该订单吗?`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
updatePurchaseInStatus(row.id!, status)
|
||||
.then(() => {
|
||||
message.success({
|
||||
content: `${status === 20 ? '审批' : '反审批'}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
})
|
||||
.catch(() => {
|
||||
// 处理错误
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoading();
|
||||
});
|
||||
}
|
||||
|
||||
/** 导出 */
|
||||
async function handleExport() {
|
||||
const data = await exportPurchaseIn(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '采购入库.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getPurchaseInPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpPurchaseInApi.PurchaseIn>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【采购】采购订单、入库、退货"
|
||||
url="https://doc.iocoder.cn/erp/purchase/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/purchase/in/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/purchase/in/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
|
||||
<Grid table-title="采购入库列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['采购入库']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:purchase-in:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:purchase-in:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
disabled: isEmpty(checkedIds),
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:purchase-in:delete'],
|
||||
popConfirm: {
|
||||
title: `是否删除所选中数据?`,
|
||||
confirm: () => {
|
||||
const checkboxRecords = gridApi.grid.getCheckboxRecords();
|
||||
if (checkboxRecords.length === 0) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
handleDelete(checkboxRecords.map((item) => item.id!));
|
||||
},
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:purchase-in:query'],
|
||||
onClick: handleDetail.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:purchase-in:update'],
|
||||
ifShow: () => row.status !== 20,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: row.status === 10 ? '审批' : '反审批',
|
||||
type: 'link',
|
||||
auth: ['erp:purchase-in:update-status'],
|
||||
popConfirm: {
|
||||
title: `确认${row.status === 10 ? '审批' : '反审批'}${row.no}吗?`,
|
||||
confirm: handleUpdateStatus.bind(
|
||||
null,
|
||||
row,
|
||||
row.status === 10 ? 20 : 10,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
color: 'error',
|
||||
auth: ['erp:purchase-in:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
||||
confirm: () => handleDelete([row.id!]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,313 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
|
||||
import type { ErpPurchaseOrderApi } from '#/api/erp/purchase/order';
|
||||
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createPurchaseIn,
|
||||
getPurchaseIn,
|
||||
updatePurchaseIn,
|
||||
} from '#/api/erp/purchase/in';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import PurchaseInItemForm from './purchase-in-item-form.vue';
|
||||
import SelectPurchaseOrderForm from './select-purchase-order-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<
|
||||
ErpPurchaseInApi.PurchaseIn & {
|
||||
accountId?: number;
|
||||
discountedPrice?: number;
|
||||
discountPercent?: number;
|
||||
fileUrl?: string;
|
||||
order?: ErpPurchaseOrderApi.PurchaseOrder;
|
||||
orderId?: number;
|
||||
orderNo?: string;
|
||||
supplierId?: number;
|
||||
}
|
||||
>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
inTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
supplierId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
discountedPrice: 0,
|
||||
items: [],
|
||||
});
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加采购入库';
|
||||
if (formType.value === 'update') return '编辑采购入库';
|
||||
return '采购入库详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(formType.value),
|
||||
showDefaultActions: false,
|
||||
handleValuesChange: (values, changedFields) => {
|
||||
if (formData.value && changedFields.includes('otherPrice')) {
|
||||
formData.value.otherPrice = values.otherPrice;
|
||||
formData.value.totalPrice =
|
||||
(formData.value.discountedPrice || 0) +
|
||||
(formData.value.otherPrice || 0);
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 更新采购入库项
|
||||
const handleUpdateItems = async (items: ErpPurchaseInApi.PurchaseInItem[]) => {
|
||||
if (formData.value) {
|
||||
const data = await formApi.getValues();
|
||||
formData.value = { ...data, items };
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
};
|
||||
|
||||
// 选择采购订单
|
||||
const handleUpdateOrder = (order: ErpPurchaseOrderApi.PurchaseOrder) => {
|
||||
formData.value = {
|
||||
...formData.value,
|
||||
orderId: order.id,
|
||||
orderNo: order.no!,
|
||||
supplierId: order.supplierId!,
|
||||
accountId: order.accountId!,
|
||||
remark: order.remark!,
|
||||
discountPercent: order.discountPercent!,
|
||||
fileUrl: order.fileUrl!,
|
||||
};
|
||||
// 将订单项设置到入库单项
|
||||
order.items!.forEach((item: any) => {
|
||||
item.totalCount = item.count;
|
||||
item.count = item.totalCount - item.inCount;
|
||||
item.orderItemId = item.id;
|
||||
item.id = undefined;
|
||||
});
|
||||
formData.value.items = order.items!.filter(
|
||||
(item) => item.count && item.count > 0,
|
||||
) as ErpPurchaseInApi.PurchaseInItem[];
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
};
|
||||
|
||||
watch(
|
||||
() => formData.value.items!,
|
||||
(newItems: ErpPurchaseInApi.PurchaseInItem[]) => {
|
||||
if (newItems && newItems.length > 0) {
|
||||
// 计算每个产品的总价、税额和总价
|
||||
newItems.forEach((item) => {
|
||||
item.totalProductPrice = (item.productPrice || 0) * (item.count || 0);
|
||||
item.taxPrice =
|
||||
(item.totalProductPrice || 0) * ((item.taxPercent || 0) / 100);
|
||||
item.totalPrice = (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
});
|
||||
// 计算总价
|
||||
const totalPrice = newItems.reduce((sum, item) => {
|
||||
return sum + (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
}, 0);
|
||||
formData.value.totalPrice = totalPrice;
|
||||
} else {
|
||||
formData.value.totalPrice = 0;
|
||||
}
|
||||
// 优惠金额
|
||||
formData.value.discountPrice =
|
||||
((formData.value.totalPrice || 0) *
|
||||
(formData.value.discountPercent || 0)) /
|
||||
100;
|
||||
// 优惠后价格
|
||||
formData.value.discountedPrice =
|
||||
formData.value.totalPrice - formData.value.discountPrice;
|
||||
|
||||
// 计算最终价格(包含其他费用)
|
||||
formData.value.totalPrice =
|
||||
formData.value.discountedPrice + (formData.value.otherPrice || 0);
|
||||
formApi.setValues(formData.value, false);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* 创建或更新采购入库
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('子表单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpPurchaseInApi.PurchaseIn;
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
// 解决新增采购入库报错
|
||||
id: undefined,
|
||||
}));
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createPurchaseIn(data)
|
||||
: updatePurchaseIn(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
inTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
supplierId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
};
|
||||
formApi.setValues(formData.value, false);
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
formApi.updateSchema(useFormSchema(formType.value));
|
||||
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
inTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
supplierId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
} as unknown as ErpPurchaseInApi.PurchaseIn;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getPurchaseIn(data.id);
|
||||
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value, false);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose({ modalApi });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-2/3"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<PurchaseInItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
@update:items="handleUpdateItems"
|
||||
/>
|
||||
</template>
|
||||
<template #orderNo="slotProps">
|
||||
<SelectPurchaseOrderForm
|
||||
v-bind="slotProps"
|
||||
:order-no="formData?.orderNo"
|
||||
@update:order="handleUpdateOrder"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getWarehouseStockCount } from '#/api/erp/stock/stock';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
|
||||
import { usePurchaseOrderItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:items', 'update:totalPrice']);
|
||||
|
||||
interface Props {
|
||||
items?: ErpPurchaseInApi.PurchaseInItem[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpPurchaseInApi.PurchaseInItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
const warehouseOptions = ref<any[]>([]);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: usePurchaseOrderItemTableColumns(),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 250,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
warehouseOptions.value = await getWarehouseSimpleList();
|
||||
});
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.count) {
|
||||
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
row.taxPrice =
|
||||
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
||||
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
const handleWarehouseChange = async (row: ErpPurchaseInApi.PurchaseInItem) => {
|
||||
const warehouseId = row.warehouseId;
|
||||
const stockCount = await getWarehouseStockCount({
|
||||
productId: row.productId!,
|
||||
warehouseId: warehouseId!,
|
||||
});
|
||||
row.stockCount = stockCount || 0;
|
||||
handleUpdateValue(row);
|
||||
};
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
productName: string;
|
||||
taxPrice: number;
|
||||
totalPrice: number;
|
||||
totalProductPrice: number;
|
||||
} => {
|
||||
const count = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.count || 0),
|
||||
0,
|
||||
);
|
||||
const totalProductPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalProductPrice || 0),
|
||||
0,
|
||||
);
|
||||
const taxPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.taxPrice || 0),
|
||||
0,
|
||||
);
|
||||
const totalPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
);
|
||||
return {
|
||||
productName: '合计',
|
||||
count,
|
||||
totalProductPrice,
|
||||
taxPrice,
|
||||
totalPrice,
|
||||
};
|
||||
};
|
||||
|
||||
const validate = async (): Promise<boolean> => {
|
||||
try {
|
||||
for (let i = 0; i < tableData.value.length; i++) {
|
||||
const item = tableData.value[i];
|
||||
if (item) {
|
||||
if (!item.warehouseId) {
|
||||
throw new Error(`第 ${i + 1} 行:仓库不能为空`);
|
||||
}
|
||||
if (!item.count || item.count <= 0) {
|
||||
throw new Error(`第 ${i + 1} 行:产品数量不能为空`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('验证失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getData = (): ErpPurchaseInApi.PurchaseInItem[] => tableData.value;
|
||||
const init = (items: ErpPurchaseInApi.PurchaseInItem[] | undefined): void => {
|
||||
tableData.value =
|
||||
items && items.length > 0
|
||||
? items.map((item) => {
|
||||
const newItem = { ...item };
|
||||
if (newItem.productPrice && newItem.count) {
|
||||
newItem.totalProductPrice =
|
||||
erpPriceMultiply(newItem.productPrice, newItem.count) ?? 0;
|
||||
newItem.taxPrice =
|
||||
erpPriceMultiply(
|
||||
newItem.totalProductPrice,
|
||||
(newItem.taxPercent || 0) / 100,
|
||||
) ?? 0;
|
||||
newItem.totalPrice = newItem.totalProductPrice + newItem.taxPrice;
|
||||
}
|
||||
return newItem;
|
||||
})
|
||||
: [];
|
||||
nextTick(() => {
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
getData,
|
||||
init,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="w-full">
|
||||
<template #warehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.warehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
class="w-full"
|
||||
@change="handleWarehouseChange(row)"
|
||||
/>
|
||||
</template>
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
disabled
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
style="width: 100%"
|
||||
placeholder="请选择产品"
|
||||
show-search
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.count"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.count || '-' }}</span>
|
||||
</template>
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
disabled
|
||||
v-model:value="row.productPrice"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<div class="border-border bg-muted mt-2 rounded border p-2">
|
||||
<div class="text-muted-foreground flex justify-between text-sm">
|
||||
<span class="text-foreground font-medium">合计:</span>
|
||||
<div class="flex space-x-4">
|
||||
<span>数量:{{ getSummaries().count }}</span>
|
||||
<span>金额:{{ getSummaries().totalProductPrice }}</span>
|
||||
<span>税额:{{ getSummaries().taxPrice }}</span>
|
||||
<span>税额合计:{{ getSummaries().totalPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpPurchaseOrderApi } from '#/api/erp/purchase/order';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Input, message, Modal } from 'ant-design-vue';
|
||||
|
||||
import SelectPurchaseOrderGrid from './select-purchase-order-grid.vue';
|
||||
|
||||
const props = defineProps({
|
||||
orderNo: {
|
||||
type: String,
|
||||
default: () => undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
'update:order': [order: ErpPurchaseOrderApi.PurchaseOrder];
|
||||
}>();
|
||||
const order = ref<ErpPurchaseOrderApi.PurchaseOrder>();
|
||||
const open = ref<boolean>(false);
|
||||
const handleSelectOrder = (selectorder: ErpPurchaseOrderApi.PurchaseOrder) => {
|
||||
order.value = selectorder;
|
||||
};
|
||||
|
||||
const handleOk = () => {
|
||||
if (!order.value) {
|
||||
message.warning('请选择一个采购订单');
|
||||
return;
|
||||
}
|
||||
emit('update:order', order.value);
|
||||
open.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Input
|
||||
v-bind="$attrs"
|
||||
readonly
|
||||
:value="orderNo"
|
||||
:disabled="disabled"
|
||||
@click="() => !disabled && (open = true)"
|
||||
>
|
||||
<template #addonAfter>
|
||||
<div>
|
||||
<IconifyIcon
|
||||
class="h-full w-6 cursor-pointer"
|
||||
icon="ant-design:setting-outlined"
|
||||
:style="{ cursor: props.disabled ? 'not-allowed' : 'pointer' }"
|
||||
@click="() => !props.disabled && (open = true)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Input>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="选择关联订单"
|
||||
class="!w-[50vw]"
|
||||
:show-confirm-button="true"
|
||||
@ok="handleOk"
|
||||
>
|
||||
<SelectPurchaseOrderGrid @select-row="handleSelectOrder" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpPurchaseOrderApi } from '#/api/erp/purchase/order';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getPurchaseOrderPage } from '#/api/erp/purchase/order';
|
||||
|
||||
import { useOrderGridColumns, useOrderGridFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['selectRow']);
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useOrderGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useOrderGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getPurchaseOrderPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
inEnable: true,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
radioConfig: {
|
||||
trigger: 'row',
|
||||
highlight: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpPurchaseOrderApi.PurchaseOrder>,
|
||||
gridEvents: {
|
||||
radioChange: ({ row }: { row: ErpPurchaseOrderApi.PurchaseOrder }) => {
|
||||
emit('selectRow', row);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="max-h-[600px]" table-title="采购订单列表(仅展示可入库)" />
|
||||
</template>
|
||||
|
|
@ -15,7 +15,7 @@ import {
|
|||
} from '#/api/erp/purchase/order';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import PurchaseOrderItemForm from './PurchaseOrderItemForm.vue';
|
||||
import PurchaseOrderItemForm from './purchase-order-item-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<ErpPurchaseOrderApi.PurchaseOrder>();
|
||||
|
|
@ -94,8 +94,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
message.error('子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
// TODO @nehc:这里的红色告警,看看怎么处理掉
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '子表单验证失败');
|
||||
return;
|
||||
}
|
||||
|
|
@ -164,17 +163,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getPurchaseOrder(data.id);
|
||||
// 将字符串形式的文件 URL 转换为数组形式以适配 FileUpload 组件
|
||||
// TODO @nehc:这里的 idea 会有黄色告警,看看是不是简化下?
|
||||
// TODO @nehc:记忆中,好像不用数组的转换,可以在看看?
|
||||
if (
|
||||
formData.value.fileUrl &&
|
||||
typeof formData.value.fileUrl === 'string'
|
||||
) {
|
||||
formData.value.fileUrl = formData.value.fileUrl
|
||||
? [formData.value.fileUrl]
|
||||
: [];
|
||||
}
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
// 初始化子表单
|
||||
|
|
|
|||
|
|
@ -95,8 +95,7 @@ watch(
|
|||
props.discountPercent === null
|
||||
? 0
|
||||
: erpPriceMultiply(totalPrice, props.discountPercent / 100);
|
||||
// TODO @nehc:这里的 idea 红色告警?
|
||||
const finalTotalPrice = totalPrice - discountPrice;
|
||||
const finalTotalPrice = totalPrice - discountPrice!;
|
||||
|
||||
// 发送计算结果给父组件
|
||||
emit('update:discount-price', discountPrice);
|
||||
|
|
@ -112,9 +111,9 @@ onMounted(async () => {
|
|||
|
||||
function handleAdd() {
|
||||
const newRow = {
|
||||
productId: null,
|
||||
productId: undefined,
|
||||
productName: '',
|
||||
productUnitId: null,
|
||||
productUnitId: undefined,
|
||||
productUnitName: '',
|
||||
productBarCode: '',
|
||||
count: 1,
|
||||
|
|
@ -0,0 +1,599 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { erpNumberFormatter, erpPriceInputFormatter } from '@vben/utils';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getAccountSimpleList } from '#/api/erp/finance/account';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getSupplierSimpleList } from '#/api/erp/purchase/supplier';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(formType: string): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '退货单号',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: '请选择供应商',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSupplierSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'supplierId',
|
||||
label: '供应商',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-1',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '请选择关联订单',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '选择退货时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'returnTime',
|
||||
label: '退货时间',
|
||||
rules: 'required',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
disabled: formType === 'detail',
|
||||
autoSize: { minRows: 1, maxRows: 1 },
|
||||
class: 'w-full',
|
||||
},
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
formItemClass: 'col-span-2',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'FileUpload',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'discountPercent',
|
||||
componentProps: {
|
||||
placeholder: '优惠率',
|
||||
min: 0,
|
||||
max: 100,
|
||||
disabled: true,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
|
||||
label: '优惠率(%)',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '付款优惠',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountPrice',
|
||||
label: '付款优惠',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '优惠后金额',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountedPrice',
|
||||
label: '优惠后金额',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '请输入其他费用',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'otherPrice',
|
||||
label: '其他费用',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择结算账户',
|
||||
disabled: true,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getAccountSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'accountId',
|
||||
label: '结算账户',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
disabled: true,
|
||||
min: 0,
|
||||
},
|
||||
fieldName: 'totalPrice',
|
||||
label: '应退金额',
|
||||
rules: z.number().min(0).optional(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购订单项表格列定义 */
|
||||
export function usePurchaseOrderItemTableColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'warehouseId',
|
||||
title: '仓库名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'warehouseId' },
|
||||
},
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '仓库库存',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'inCount',
|
||||
title: '已入库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnCount',
|
||||
title: '已退货',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '数量',
|
||||
minWidth: 120,
|
||||
fixed: 'right',
|
||||
slots: { default: 'count' },
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
fixed: 'right',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
fixed: 'right',
|
||||
title: '产品金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPercent',
|
||||
title: '税率(%)',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPrice',
|
||||
title: '税额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
fixed: 'right',
|
||||
title: '合计金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购退货列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '退货单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入入库单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'returnTime',
|
||||
label: '退货时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'supplierId',
|
||||
label: '供应商',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择供应商',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSupplierSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'warehouseId',
|
||||
label: '仓库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择仓库',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getWarehouseSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
fieldNames: {
|
||||
label: 'nickname',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入关联订单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'refundStatus',
|
||||
label: '退款状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '未退款', value: 0 },
|
||||
{ label: '部分退款', value: 1 },
|
||||
{ label: '全部退款', value: 2 },
|
||||
],
|
||||
placeholder: '请选择退货状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购退货列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '退货单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'supplierName',
|
||||
title: '供应商',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnTime',
|
||||
title: '退货时间',
|
||||
width: 160,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '应退金额',
|
||||
formatter: 'formatAmount2',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'refundPrice',
|
||||
title: '已退金额',
|
||||
formatter: 'formatAmount2',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'noRefundPrice',
|
||||
title: '未退金额',
|
||||
minWidth: 120,
|
||||
formatter: ({ row }) => {
|
||||
return `${erpNumberFormatter(row.totalPrice - row.refundPrice, 2)}元`;
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 250,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
/** 采购订单列表的搜索表单 */
|
||||
export function useOrderGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '订单单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入订单单号',
|
||||
allowClear: true,
|
||||
disabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderTime',
|
||||
label: '订单时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购订单列表的字段 */
|
||||
export function useOrderGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'radio',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '订单单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'supplierName',
|
||||
title: '供应商',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'orderTime',
|
||||
title: '订单时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'inCount',
|
||||
title: '入库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnCount',
|
||||
title: '退货数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
title: '金额合计',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '含税金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,233 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpPurchaseReturnApi } from '#/api/erp/purchase/return';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePurchaseReturn,
|
||||
exportPurchaseReturn,
|
||||
getPurchaseReturnPage,
|
||||
updatePurchaseReturnStatus,
|
||||
} from '#/api/erp/purchase/return';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import PurchaseInForm from './modules/purchase-return-form.vue';
|
||||
|
||||
/** ERP 采购入库列表 */
|
||||
defineOptions({ name: 'ErpPurchaseIn' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: PurchaseInForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
|
||||
/** 详情 */
|
||||
function handleDetail(row: ErpPurchaseReturnApi.PurchaseReturn) {
|
||||
formModalApi.setData({ type: 'detail', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(row: ErpPurchaseReturnApi.PurchaseReturn) {
|
||||
formModalApi.setData({ type: 'edit', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: number[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deletePurchaseReturn(ids);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess'),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 处理错误
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审批/反审批操作 */
|
||||
async function handleUpdateStatus(
|
||||
row: ErpPurchaseReturnApi.PurchaseReturn,
|
||||
status: number,
|
||||
) {
|
||||
const hideLoading = message.loading({
|
||||
content: `确定${status === 20 ? '审批' : '反审批'}该订单吗?`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await updatePurchaseReturnStatus({ id: row.id!, status });
|
||||
message.success({
|
||||
content: `${status === 20 ? '审批' : '反审批'}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 处理错误
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出 */
|
||||
async function handleExport() {
|
||||
const data = await exportPurchaseReturn(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '采购退货.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getPurchaseReturnPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpPurchaseReturnApi.PurchaseReturn>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【采购】采购订单、入库、退货"
|
||||
url="https://doc.iocoder.cn/erp/purchase/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/purchase/return/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/purchase/return/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
|
||||
<Grid table-title="采购退货列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['采购退货']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:purchase-return:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:purchase-return:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
disabled: isEmpty(checkedIds),
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:purchase-return:delete'],
|
||||
popConfirm: {
|
||||
title: `是否删除所选中数据?`,
|
||||
confirm: () => {
|
||||
const checkboxRecords = gridApi.grid.getCheckboxRecords();
|
||||
if (checkboxRecords.length === 0) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
handleDelete(checkboxRecords.map((item) => item.id!));
|
||||
},
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:purchase-return:query'],
|
||||
onClick: handleDetail.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:purchase-return:update'],
|
||||
ifShow: () => row.status !== 20,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: row.status === 10 ? '审批' : '反审批',
|
||||
type: 'link',
|
||||
auth: ['erp:purchase-return:update-status'],
|
||||
popConfirm: {
|
||||
title: `确认${row.status === 10 ? '审批' : '反审批'}${row.no}吗?`,
|
||||
confirm: handleUpdateStatus.bind(
|
||||
null,
|
||||
row,
|
||||
row.status === 10 ? 20 : 10,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
color: 'error',
|
||||
auth: ['erp:purchase-return:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
||||
confirm: () => handleDelete([row.id!]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,315 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpPurchaseOrderApi } from '#/api/erp/purchase/order';
|
||||
import type { ErpPurchaseReturnApi } from '#/api/erp/purchase/return';
|
||||
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createPurchaseReturn,
|
||||
getPurchaseReturn,
|
||||
updatePurchaseReturn,
|
||||
} from '#/api/erp/purchase/return';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import PurchaseReturnItemForm from './purchase-return-item-form.vue';
|
||||
import SelectPurchaseOrderForm from './select-purchase-order-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<
|
||||
ErpPurchaseReturnApi.PurchaseReturn & {
|
||||
accountId?: number;
|
||||
discountedPrice?: number;
|
||||
discountPercent?: number;
|
||||
fileUrl?: string;
|
||||
orderId?: number;
|
||||
orderNo?: string;
|
||||
supplierId?: number;
|
||||
}
|
||||
>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
supplierId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
discountedPrice: 0,
|
||||
items: [],
|
||||
});
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加采购退货';
|
||||
if (formType.value === 'update') return '编辑采购退货';
|
||||
return '采购退货详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(formType.value),
|
||||
showDefaultActions: false,
|
||||
handleValuesChange: (values, changedFields) => {
|
||||
if (formData.value && changedFields.includes('otherPrice')) {
|
||||
formData.value.otherPrice = values.otherPrice;
|
||||
formData.value.totalPrice =
|
||||
(formData.value.discountedPrice || 0) +
|
||||
(formData.value.otherPrice || 0);
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 更新采购退货项
|
||||
const handleUpdateItems = async (
|
||||
items: ErpPurchaseReturnApi.PurchaseReturnItem[],
|
||||
) => {
|
||||
if (formData.value) {
|
||||
const data =
|
||||
(await formApi.getValues()) as ErpPurchaseReturnApi.PurchaseReturn;
|
||||
formData.value = { ...data, items };
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
};
|
||||
|
||||
// 选择采购订单
|
||||
const handleUpdateOrder = (order: ErpPurchaseOrderApi.PurchaseOrder) => {
|
||||
formData.value = {
|
||||
...formData.value,
|
||||
orderId: order.id,
|
||||
orderNo: order.no!,
|
||||
supplierId: order.supplierId!,
|
||||
accountId: order.accountId!,
|
||||
remark: order.remark!,
|
||||
discountPercent: order.discountPercent!,
|
||||
fileUrl: order.fileUrl!,
|
||||
};
|
||||
// 将订单项设置到入库单项
|
||||
order.items!.forEach((item: any) => {
|
||||
item.totalCount = item.count;
|
||||
item.count = item.inCount - item.returnCount;
|
||||
item.orderItemId = item.id;
|
||||
item.id = undefined;
|
||||
});
|
||||
formData.value.items = order.items!.filter(
|
||||
(item) => item.count && item.count > 0,
|
||||
) as ErpPurchaseReturnApi.PurchaseReturnItem[];
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
};
|
||||
|
||||
watch(
|
||||
() => formData.value.items!,
|
||||
(newItems: ErpPurchaseReturnApi.PurchaseReturnItem[]) => {
|
||||
if (newItems && newItems.length > 0) {
|
||||
// 计算每个产品的总价、税额和总价
|
||||
newItems.forEach((item) => {
|
||||
item.totalProductPrice = (item.productPrice || 0) * (item.count || 0);
|
||||
item.taxPrice =
|
||||
(item.totalProductPrice || 0) * ((item.taxPercent || 0) / 100);
|
||||
item.totalPrice = (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
});
|
||||
// 计算总价
|
||||
const totalPrice = newItems.reduce((sum, item) => {
|
||||
return sum + (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
}, 0);
|
||||
formData.value.totalPrice = totalPrice;
|
||||
} else {
|
||||
formData.value.totalPrice = 0;
|
||||
}
|
||||
// 优惠金额
|
||||
formData.value.discountPrice =
|
||||
((formData.value.totalPrice || 0) *
|
||||
(formData.value.discountPercent || 0)) /
|
||||
100;
|
||||
// 优惠后价格
|
||||
formData.value.discountedPrice =
|
||||
formData.value.totalPrice - formData.value.discountPrice;
|
||||
|
||||
// 计算最终价格(包含其他费用)
|
||||
formData.value.totalPrice =
|
||||
formData.value.discountedPrice + (formData.value.otherPrice || 0);
|
||||
formApi.setValues(formData.value, false);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* 创建或更新采购退货
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('子表单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data: ErpPurchaseReturnApi.PurchaseReturn = await formApi.getValues();
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
// 解决新增采购退货报错
|
||||
id: undefined,
|
||||
}));
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createPurchaseReturn(data)
|
||||
: updatePurchaseReturn(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
supplierId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
};
|
||||
formApi.setValues(formData.value, false);
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
formApi.updateSchema(useFormSchema(formType.value));
|
||||
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
supplierId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
} as unknown as ErpPurchaseReturnApi.PurchaseReturn;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getPurchaseReturn(data.id);
|
||||
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value, false);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose({ modalApi });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-2/3"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<PurchaseReturnItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
@update:items="handleUpdateItems"
|
||||
/>
|
||||
</template>
|
||||
<template #orderNo="slotProps">
|
||||
<SelectPurchaseOrderForm
|
||||
v-bind="slotProps"
|
||||
:order-no="formData?.orderNo"
|
||||
@update:order="handleUpdateOrder"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpPurchaseReturnApi } from '#/api/erp/purchase/return';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getWarehouseStockCount } from '#/api/erp/stock/stock';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
|
||||
import { usePurchaseOrderItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:items', 'update:totalPrice']);
|
||||
|
||||
interface Props {
|
||||
items?: ErpPurchaseReturnApi.PurchaseReturnItem[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpPurchaseReturnApi.PurchaseReturnItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
const warehouseOptions = ref<any[]>([]);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: usePurchaseOrderItemTableColumns(),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 150,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
warehouseOptions.value = await getWarehouseSimpleList();
|
||||
});
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.count) {
|
||||
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
row.taxPrice =
|
||||
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
||||
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
const handleWarehouseChange = async (
|
||||
row: ErpPurchaseReturnApi.PurchaseReturnItem,
|
||||
) => {
|
||||
const warehouseId = row.warehouseId;
|
||||
const stockCount = await getWarehouseStockCount({
|
||||
productId: row.productId!,
|
||||
warehouseId: warehouseId!,
|
||||
});
|
||||
row.stockCount = stockCount || 0;
|
||||
handleUpdateValue(row);
|
||||
};
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
productName: string;
|
||||
taxPrice: number;
|
||||
totalPrice: number;
|
||||
totalProductPrice: number;
|
||||
} => {
|
||||
const count = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.count || 0),
|
||||
0,
|
||||
);
|
||||
const totalProductPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalProductPrice || 0),
|
||||
0,
|
||||
);
|
||||
const taxPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.taxPrice || 0),
|
||||
0,
|
||||
);
|
||||
const totalPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
);
|
||||
return {
|
||||
productName: '合计',
|
||||
count,
|
||||
totalProductPrice,
|
||||
taxPrice,
|
||||
totalPrice,
|
||||
};
|
||||
};
|
||||
|
||||
const validate = async (): Promise<boolean> => {
|
||||
try {
|
||||
for (let i = 0; i < tableData.value.length; i++) {
|
||||
const item = tableData.value[i];
|
||||
if (item) {
|
||||
if (!item.warehouseId) {
|
||||
throw new Error(`第 ${i + 1} 行:仓库不能为空`);
|
||||
}
|
||||
if (!item.count || item.count <= 0) {
|
||||
throw new Error(`第 ${i + 1} 行:产品数量不能为空`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('验证失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getData = (): ErpPurchaseReturnApi.PurchaseReturnItem[] =>
|
||||
tableData.value;
|
||||
const init = (
|
||||
items: ErpPurchaseReturnApi.PurchaseReturnItem[] | undefined,
|
||||
): void => {
|
||||
tableData.value =
|
||||
items && items.length > 0
|
||||
? items.map((item) => {
|
||||
const newItem = { ...item };
|
||||
if (newItem.productPrice && newItem.count) {
|
||||
newItem.totalProductPrice =
|
||||
erpPriceMultiply(newItem.productPrice, newItem.count) ?? 0;
|
||||
newItem.taxPrice =
|
||||
erpPriceMultiply(
|
||||
newItem.totalProductPrice,
|
||||
(newItem.taxPercent || 0) / 100,
|
||||
) ?? 0;
|
||||
newItem.totalPrice = newItem.totalProductPrice + newItem.taxPrice;
|
||||
}
|
||||
return newItem;
|
||||
})
|
||||
: [];
|
||||
nextTick(() => {
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
getData,
|
||||
init,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="w-full">
|
||||
<template #warehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.warehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
class="w-full"
|
||||
@change="handleWarehouseChange(row)"
|
||||
/>
|
||||
</template>
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
disabled
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
style="width: 100%"
|
||||
placeholder="请选择产品"
|
||||
show-search
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.count"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.count || '-' }}</span>
|
||||
</template>
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
disabled
|
||||
v-model:value="row.productPrice"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<div class="border-border bg-muted mt-2 rounded border p-2">
|
||||
<div class="text-muted-foreground flex justify-between text-sm">
|
||||
<span class="text-foreground font-medium">合计:</span>
|
||||
<div class="flex space-x-4">
|
||||
<span>数量:{{ getSummaries().count }}</span>
|
||||
<span>金额:{{ getSummaries().totalProductPrice }}</span>
|
||||
<span>税额:{{ getSummaries().taxPrice }}</span>
|
||||
<span>税额合计:{{ getSummaries().totalPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpPurchaseOrderApi } from '#/api/erp/purchase/order';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Input, message, Modal } from 'ant-design-vue';
|
||||
|
||||
import SelectPurchaseOrderGrid from './select-purchase-order-grid.vue';
|
||||
|
||||
const props = defineProps({
|
||||
orderNo: {
|
||||
type: String,
|
||||
default: () => undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
'update:order': [order: ErpPurchaseOrderApi.PurchaseOrder];
|
||||
}>();
|
||||
const order = ref<ErpPurchaseOrderApi.PurchaseOrder>();
|
||||
const open = ref<boolean>(false);
|
||||
const handleSelectOrder = (selectorder: ErpPurchaseOrderApi.PurchaseOrder) => {
|
||||
order.value = selectorder;
|
||||
};
|
||||
|
||||
const handleOk = () => {
|
||||
if (!order.value) {
|
||||
message.warning('请选择一个采购订单');
|
||||
return;
|
||||
}
|
||||
emit('update:order', order.value);
|
||||
open.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Input
|
||||
v-bind="$attrs"
|
||||
readonly
|
||||
:value="orderNo"
|
||||
:disabled="disabled"
|
||||
@click="() => !disabled && (open = true)"
|
||||
>
|
||||
<template #addonAfter>
|
||||
<div>
|
||||
<IconifyIcon
|
||||
class="h-full w-6 cursor-pointer"
|
||||
icon="ant-design:setting-outlined"
|
||||
:style="{ cursor: props.disabled ? 'not-allowed' : 'pointer' }"
|
||||
@click="() => !props.disabled && (open = true)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Input>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="选择关联订单"
|
||||
class="!w-[50vw]"
|
||||
:show-confirm-button="true"
|
||||
@ok="handleOk"
|
||||
>
|
||||
<SelectPurchaseOrderGrid @select-row="handleSelectOrder" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpPurchaseOrderApi } from '#/api/erp/purchase/order';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getPurchaseOrderPage } from '#/api/erp/purchase/order';
|
||||
|
||||
import { useOrderGridColumns, useOrderGridFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['selectRow']);
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useOrderGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useOrderGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getPurchaseOrderPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
returnEnable: true,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
radioConfig: {
|
||||
trigger: 'row',
|
||||
highlight: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpPurchaseOrderApi.PurchaseOrder>,
|
||||
gridEvents: {
|
||||
radioChange: ({ row }: { row: ErpPurchaseOrderApi.PurchaseOrder }) => {
|
||||
emit('selectRow', row);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="max-h-[600px]" table-title="采购订单列表(仅展示可退货)" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '名称',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
placeholder: '请输入名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact',
|
||||
label: '联系人',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'mobile',
|
||||
label: '手机号码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入手机号码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'telephone',
|
||||
label: '联系电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'email',
|
||||
label: '电子邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入电子邮箱',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'fax',
|
||||
label: '传真',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入传真',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入排序',
|
||||
precision: 0,
|
||||
class: 'w-full',
|
||||
},
|
||||
rules: 'required',
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
fieldName: 'taxNo',
|
||||
label: '纳税人识别号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入纳税人识别号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'taxPercent',
|
||||
label: '税率(%)',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入税率',
|
||||
precision: 0,
|
||||
class: 'w-full',
|
||||
},
|
||||
rules: z.number().min(0).max(100).default(0).optional(),
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
fieldName: 'bankName',
|
||||
label: '开户行名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入开户行名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'bankAccount',
|
||||
label: '开户行账号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入开户行账号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'bankAddress',
|
||||
label: '开户行地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入开户行地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '名称',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'mobile',
|
||||
label: '手机号码',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'email',
|
||||
label: '邮箱',
|
||||
component: 'Input',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '名称',
|
||||
},
|
||||
{
|
||||
field: 'contact',
|
||||
title: '联系人',
|
||||
},
|
||||
{
|
||||
field: 'mobile',
|
||||
title: '手机号码',
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '联系电话',
|
||||
},
|
||||
{
|
||||
field: 'email',
|
||||
title: '邮箱',
|
||||
},
|
||||
{
|
||||
field: 'taxNo',
|
||||
title: '纳税人识别号',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,152 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpCustomerApi } from '#/api/erp/sale/customer';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteCustomer,
|
||||
exportCustomer,
|
||||
getCustomerPage,
|
||||
} from '#/api/erp/sale/customer';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportCustomer(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '客户信息.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建客户 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑客户 */
|
||||
function handleEdit(row: ErpCustomerApi.Customer) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除客户 */
|
||||
async function handleDelete(row: ErpCustomerApi.Customer) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
await deleteCustomer(row.id as number);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getCustomerPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpCustomerApi.Customer>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【销售】销售订单、出库、退货"
|
||||
url="https://doc.iocoder.cn/erp/sale/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/customer/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/customer/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
<Grid table-title="客户列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['客户']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:customer:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:customer:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:customer:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:customer:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpCustomerApi } from '#/api/erp/sale/customer';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createCustomer,
|
||||
getCustomer,
|
||||
updateCustomer,
|
||||
} from '#/api/erp/sale/customer';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<ErpCustomerApi.Customer>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['客户'])
|
||||
: $t('ui.actionTitle.create', ['客户']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
// 一共2列
|
||||
wrapperClass: 'grid-cols-2',
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpCustomerApi.Customer;
|
||||
try {
|
||||
await (formData.value?.id ? updateCustomer(data) : createCustomer(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<ErpCustomerApi.Customer>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getCustomer(data.id as number);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-2/5" :title="getTitle">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,454 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { erpPriceInputFormatter } from '@vben/utils';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getAccountSimpleList } from '#/api/erp/finance/account';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getCustomerSimpleList } from '#/api/erp/sale/customer';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '订单单号',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '选择订单时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'orderTime',
|
||||
label: '订单时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择客户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getCustomerSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'customerId',
|
||||
label: '客户',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'saleUserId',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
fieldNames: {
|
||||
label: 'nickname',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
autoSize: { minRows: 1, maxRows: 1 },
|
||||
},
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
},
|
||||
{
|
||||
component: 'FileUpload',
|
||||
componentProps: {
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入优惠率',
|
||||
min: 0,
|
||||
max: 100,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountPercent',
|
||||
label: '优惠率(%)',
|
||||
rules: z.number().min(0).optional(),
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '收款优惠',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountPrice',
|
||||
label: '付款优惠',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '优惠后金额',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'totalPrice',
|
||||
label: '优惠后金额',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择结算账户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getAccountSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'accountId',
|
||||
label: '结算账户',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入收取订金',
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
min: 0,
|
||||
},
|
||||
fieldName: 'depositPrice',
|
||||
label: '收取订金',
|
||||
rules: z.number().min(0).optional(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购订单项表格列定义 */
|
||||
export function useSaleOrderItemTableColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '库存',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '数量',
|
||||
minWidth: 120,
|
||||
slots: { default: 'count' },
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
title: '金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'taxPercent',
|
||||
title: '税率(%)',
|
||||
minWidth: 100,
|
||||
slots: { default: 'taxPercent' },
|
||||
},
|
||||
{
|
||||
field: 'taxPrice',
|
||||
title: '税额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '税额合计',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 150,
|
||||
slots: { default: 'remark' },
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 50,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '订单单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入订单单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderTime',
|
||||
label: '订单时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'supplierId',
|
||||
label: '客户',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择客户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getCustomerSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
fieldNames: {
|
||||
label: 'nickname',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'outStatus',
|
||||
label: '出库状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '未出库', value: 0 },
|
||||
{ label: '部分出库', value: 1 },
|
||||
{ label: '全部出库', value: 2 },
|
||||
],
|
||||
placeholder: '请选择出库状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'returnStatus',
|
||||
label: '退货状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '未退货', value: 0 },
|
||||
{ label: '部分退货', value: 1 },
|
||||
{ label: '全部退货', value: 2 },
|
||||
],
|
||||
placeholder: '请选择退货状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '订单单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'customerName',
|
||||
title: '客户',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'orderTime',
|
||||
title: '订单时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'outCount',
|
||||
title: '出库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnCount',
|
||||
title: '退货数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
title: '金额合计',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '含税金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'depositPrice',
|
||||
title: '收取订金',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 220,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,236 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteSaleOrder,
|
||||
exportSaleOrder,
|
||||
getSaleOrderPage,
|
||||
updateSaleOrderStatus,
|
||||
} from '#/api/erp/sale/order';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import SaleOrderForm from './modules/form.vue';
|
||||
|
||||
/** ERP 销售订单列表 */
|
||||
defineOptions({ name: 'ErpSaleOrder' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: SaleOrderForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function handleRowCheckboxChange({
|
||||
records,
|
||||
}: {
|
||||
records: ErpSaleOrderApi.SaleOrder[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 详情 */
|
||||
function handleDetail(row: ErpSaleOrderApi.SaleOrder) {
|
||||
formModalApi.setData({ type: 'detail', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(row: ErpSaleOrderApi.SaleOrder) {
|
||||
formModalApi.setData({ type: 'edit', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: number[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deleteSaleOrder(ids);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess'),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 处理错误
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审批/反审批操作 */
|
||||
function handleUpdateStatus(row: ErpSaleOrderApi.SaleOrder, status: number) {
|
||||
const hideLoading = message.loading({
|
||||
content: `确定${status === 20 ? '审批' : '反审批'}该订单吗?`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
updateSaleOrderStatus(row.id!, status)
|
||||
.then(() => {
|
||||
message.success({
|
||||
content: `${status === 20 ? '审批' : '反审批'}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
})
|
||||
.catch(() => {
|
||||
// 处理错误
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoading();
|
||||
});
|
||||
}
|
||||
|
||||
/** 导出 */
|
||||
async function handleExport() {
|
||||
const data = await exportSaleOrder(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '销售订单.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getSaleOrderPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpSaleOrderApi.SaleOrder>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleRowCheckboxChange,
|
||||
checkboxChange: handleRowCheckboxChange,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【销售】销售订单、出库、退货"
|
||||
url="https://doc.iocoder.cn/erp/sale/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/order/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/order/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
|
||||
<Grid table-title="销售订单列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['销售订单']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:sale-order:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:sale-order:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
disabled: isEmpty(checkedIds),
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:sale-order:delete'],
|
||||
popConfirm: {
|
||||
title: `是否删除所选中数据?`,
|
||||
confirm: handleDelete.bind(null, checkedIds),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:sale-order:query'],
|
||||
onClick: handleDetail.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:sale-order:update'],
|
||||
ifShow: () => row.status !== 20,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: row.status === 10 ? '审批' : '反审批',
|
||||
type: 'link',
|
||||
auth: ['erp:sale-order:update-status'],
|
||||
popConfirm: {
|
||||
title: `确认${row.status === 10 ? '审批' : '反审批'}${row.no}吗?`,
|
||||
confirm: handleUpdateStatus.bind(
|
||||
null,
|
||||
row,
|
||||
row.status === 10 ? 20 : 10,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
color: 'error',
|
||||
auth: ['erp:sale-order:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
||||
confirm: handleDelete.bind(null, [row.id!]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,206 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createSaleOrder,
|
||||
getSaleOrder,
|
||||
updateSaleOrder,
|
||||
} from '#/api/erp/sale/order';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import SaleOrderItemForm from './sale-order-item-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<ErpSaleOrderApi.SaleOrder>();
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加销售订单';
|
||||
if (formType.value === 'update') return '编辑销售订单';
|
||||
return '销售订单详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
handleValuesChange: (values, changedFields) => {
|
||||
if (formData.value && changedFields.includes('discountPercent')) {
|
||||
formData.value.discountPercent = values.discountPercent;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const handleUpdateItems = (items: ErpSaleOrderApi.SaleOrderItem[]) => {
|
||||
formData.value = modalApi.getData<ErpSaleOrderApi.SaleOrder>();
|
||||
if (formData.value) {
|
||||
formData.value.items = items;
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdateDiscountPrice = (discountPrice: number) => {
|
||||
if (formData.value) {
|
||||
formData.value.discountPrice = discountPrice;
|
||||
formApi.setValues({
|
||||
discountPrice: formData.value.discountPrice,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdateTotalPrice = (totalPrice: number) => {
|
||||
if (formData.value) {
|
||||
formData.value.totalPrice = totalPrice;
|
||||
formApi.setValues({
|
||||
totalPrice: formData.value.totalPrice,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建或更新销售订单
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('子表单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpSaleOrderApi.SaleOrder;
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
// 解决新增销售订单报错
|
||||
id: undefined,
|
||||
}));
|
||||
// 将文件数组转换为字符串
|
||||
if (data.fileUrl && Array.isArray(data.fileUrl)) {
|
||||
data.fileUrl = data.fileUrl.length > 0 ? data.fileUrl[0] : '';
|
||||
}
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createSaleOrder(data)
|
||||
: updateSaleOrder(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = { items: [] } as unknown as ErpSaleOrderApi.SaleOrder;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getSaleOrder(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose({ modalApi });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-1/2"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<SaleOrderItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
:discount-percent="formData?.discountPercent ?? 0"
|
||||
@update:items="handleUpdateItems"
|
||||
@update:discount-price="handleUpdateDiscountPrice"
|
||||
@update:total-price="handleUpdateTotalPrice"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,356 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { Input, InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getStockCount } from '#/api/erp/stock/stock';
|
||||
|
||||
import { useSaleOrderItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
discountPercent: 0,
|
||||
});
|
||||
|
||||
const emit = defineEmits([
|
||||
'update:items',
|
||||
'update:discount-price',
|
||||
'update:total-price',
|
||||
]);
|
||||
|
||||
interface Props {
|
||||
items?: ErpSaleOrderApi.SaleOrderItem[];
|
||||
disabled?: boolean;
|
||||
discountPercent?: number;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpSaleOrderApi.SaleOrderItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: useSaleOrderItemTableColumns(),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 250,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 计算 discountPrice、totalPrice 价格 */
|
||||
watch(
|
||||
() => [tableData.value, props.discountPercent],
|
||||
() => {
|
||||
if (!tableData.value || tableData.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
const totalPrice = tableData.value.reduce(
|
||||
(prev, curr) => prev + (curr.totalPrice || 0),
|
||||
0,
|
||||
);
|
||||
const discountPrice =
|
||||
props.discountPercent === null
|
||||
? 0
|
||||
: erpPriceMultiply(totalPrice, props.discountPercent / 100);
|
||||
const finalTotalPrice = totalPrice - discountPrice!;
|
||||
|
||||
// 发送计算结果给父组件
|
||||
emit('update:discount-price', discountPrice);
|
||||
emit('update:total-price', finalTotalPrice);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
const newRow = {
|
||||
productId: undefined,
|
||||
productName: '',
|
||||
productUnitId: undefined,
|
||||
productUnitName: '',
|
||||
productBarCode: '',
|
||||
count: 1,
|
||||
productPrice: 0,
|
||||
totalProductPrice: 0,
|
||||
taxPercent: 0,
|
||||
taxPrice: 0,
|
||||
totalPrice: 0,
|
||||
stockCount: 0,
|
||||
remark: '',
|
||||
};
|
||||
tableData.value.push(newRow);
|
||||
gridApi.grid.insertAt(newRow, -1);
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
function handleDelete(row: ErpSaleOrderApi.SaleOrderItem) {
|
||||
gridApi.grid.remove(row);
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index !== -1) {
|
||||
tableData.value.splice(index, 1);
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
async function handleProductChange(productId: any, row: any) {
|
||||
const product = productOptions.value.find((p) => p.id === productId);
|
||||
if (!product) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stockCount = await getStockCount(productId);
|
||||
|
||||
row.productId = productId;
|
||||
row.productUnitId = product.unitId;
|
||||
row.productBarCode = product.barCode;
|
||||
row.productUnitName = product.unitName;
|
||||
row.productName = product.name;
|
||||
row.stockCount = stockCount || 0;
|
||||
row.productPrice = product.salePrice || 0;
|
||||
row.count = row.count || 1;
|
||||
|
||||
handlePriceChange(row);
|
||||
}
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.count) {
|
||||
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
row.taxPrice =
|
||||
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
||||
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
productName: string;
|
||||
taxPrice: number;
|
||||
totalPrice: number;
|
||||
totalProductPrice: number;
|
||||
} => {
|
||||
return {
|
||||
productName: '合计',
|
||||
count: tableData.value.reduce((sum, item) => sum + (item.count || 0), 0),
|
||||
totalProductPrice: tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalProductPrice || 0),
|
||||
0,
|
||||
),
|
||||
taxPrice: tableData.value.reduce(
|
||||
(sum, item) => sum + (item.taxPrice || 0),
|
||||
0,
|
||||
),
|
||||
totalPrice: tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
const validate = async (): Promise<boolean> => {
|
||||
try {
|
||||
for (let i = 0; i < tableData.value.length; i++) {
|
||||
const item = tableData.value[i];
|
||||
if (item) {
|
||||
if (!item.productId) {
|
||||
throw new Error(`第 ${i + 1} 行:产品不能为空`);
|
||||
}
|
||||
if (!item.count || item.count <= 0) {
|
||||
throw new Error(`第 ${i + 1} 行:产品数量不能为空`);
|
||||
}
|
||||
if (!item.productPrice || item.productPrice <= 0) {
|
||||
throw new Error(`第 ${i + 1} 行:产品单价不能为空`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('验证失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getData = (): ErpSaleOrderApi.SaleOrderItem[] => tableData.value;
|
||||
const init = (items: ErpSaleOrderApi.SaleOrderItem[] | undefined): void => {
|
||||
tableData.value =
|
||||
items && items.length > 0
|
||||
? items.map((item) => {
|
||||
const newItem = { ...item };
|
||||
if (newItem.productPrice && newItem.count) {
|
||||
newItem.totalProductPrice =
|
||||
erpPriceMultiply(newItem.productPrice, newItem.count) ?? 0;
|
||||
newItem.taxPrice =
|
||||
erpPriceMultiply(
|
||||
newItem.totalProductPrice,
|
||||
(newItem.taxPercent || 0) / 100,
|
||||
) ?? 0;
|
||||
newItem.totalPrice = newItem.totalProductPrice + newItem.taxPrice;
|
||||
}
|
||||
return newItem;
|
||||
})
|
||||
: [];
|
||||
nextTick(() => {
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
getData,
|
||||
init,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="w-full">
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
v-if="!disabled"
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
style="width: 100%"
|
||||
placeholder="请选择产品"
|
||||
show-search
|
||||
@change="handleProductChange($event, row)"
|
||||
/>
|
||||
<span v-else>{{ row.productName || '-' }}</span>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.count"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.count || '-' }}</span>
|
||||
</template>
|
||||
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.productPrice"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.productPrice || '-' }}</span>
|
||||
</template>
|
||||
|
||||
<template #taxPercent="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.taxPercent"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.taxPercent || '-' }}</span>
|
||||
</template>
|
||||
|
||||
<template #remark="{ row }">
|
||||
<Input v-if="!disabled" v-model:value="row.remark" class="w-full" />
|
||||
<span v-else>{{ row.remark || '-' }}</span>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<div class="border-border bg-muted mt-2 rounded border p-2">
|
||||
<div class="text-muted-foreground flex justify-between text-sm">
|
||||
<span class="text-foreground font-medium">合计:</span>
|
||||
<div class="flex space-x-4">
|
||||
<span>数量:{{ getSummaries().count }}</span>
|
||||
<span>金额:{{ getSummaries().totalProductPrice }}</span>
|
||||
<span>税额:{{ getSummaries().taxPrice }}</span>
|
||||
<span>税额合计:{{ getSummaries().totalPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TableAction
|
||||
v-if="!disabled"
|
||||
class="mt-4 flex justify-center"
|
||||
:actions="[
|
||||
{
|
||||
label: '添加产品',
|
||||
type: 'default',
|
||||
onClick: handleAdd,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
v-if="!disabled"
|
||||
:actions="[
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
danger: true,
|
||||
popConfirm: {
|
||||
title: '确认删除该产品吗?',
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,591 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { erpNumberFormatter, erpPriceInputFormatter } from '@vben/utils';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getAccountSimpleList } from '#/api/erp/finance/account';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getCustomerSimpleList } from '#/api/erp/sale/customer';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(formType: string): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '出库单号',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: '请选择客户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getCustomerSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'customerId',
|
||||
label: '客户',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-1',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
placeholder: '请选择关联订单',
|
||||
disabled: formType === 'detail',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '选择出库时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'outTime',
|
||||
label: '出库时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
disabled: formType === 'detail',
|
||||
autoSize: { minRows: 1, maxRows: 1 },
|
||||
class: 'w-full',
|
||||
},
|
||||
fieldName: 'remark',
|
||||
formItemClass: 'col-span-2',
|
||||
label: '备注',
|
||||
},
|
||||
{
|
||||
component: 'FileUpload',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'discountPercent',
|
||||
componentProps: {
|
||||
placeholder: '优惠率',
|
||||
min: 0,
|
||||
max: 100,
|
||||
disabled: true,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
|
||||
label: '优惠率(%)',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '付款优惠',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountPrice',
|
||||
label: '付款优惠',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '优惠后金额',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountedPrice',
|
||||
label: '优惠后金额',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '请输入其他费用',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'otherPrice',
|
||||
label: '其他费用',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择结算账户',
|
||||
disabled: true,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getAccountSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'accountId',
|
||||
label: '结算账户',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
disabled: true,
|
||||
min: 0,
|
||||
},
|
||||
fieldName: 'totalPrice',
|
||||
label: '应收金额',
|
||||
rules: z.number().min(0).optional(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购订单项表格列定义 */
|
||||
export function useSaleOutItemTableColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'warehouseId',
|
||||
title: '仓库名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'warehouseId' },
|
||||
},
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '仓库库存',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '原数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'outCount',
|
||||
title: '已出库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '数量',
|
||||
minWidth: 120,
|
||||
fixed: 'right',
|
||||
slots: { default: 'count' },
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
fixed: 'right',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
fixed: 'right',
|
||||
title: '产品金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPercent',
|
||||
title: '税率(%)',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPrice',
|
||||
title: '税额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
fixed: 'right',
|
||||
title: '合计金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '出库单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入出库单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'outTime',
|
||||
label: '出库时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'customerId',
|
||||
label: '客户',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择客户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getCustomerSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'warehouseId',
|
||||
label: '仓库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择仓库',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getWarehouseSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
fieldNames: {
|
||||
label: 'nickname',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入关联订单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'receiptStatus',
|
||||
label: '收款状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '未收款', value: 0 },
|
||||
{ label: '部分收款', value: 1 },
|
||||
{ label: '全部收款', value: 2 },
|
||||
],
|
||||
placeholder: '请选择收款状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '出库单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'customerName',
|
||||
title: '客户',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'outTime',
|
||||
title: '出库时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '应收金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'receiptPrice',
|
||||
title: '已收金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'unReceiptPrice',
|
||||
title: '未收金额',
|
||||
formatter: ({ row }) => {
|
||||
return `${erpNumberFormatter(row.totalPrice - row.receiptPrice, 2)}元`;
|
||||
},
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 250,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
/** 列表的搜索表单 */
|
||||
export function useOrderGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '订单单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入订单单号',
|
||||
allowClear: true,
|
||||
disabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderTime',
|
||||
label: '订单时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useOrderGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'radio',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '订单单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'customerName',
|
||||
title: '客户',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'orderTime',
|
||||
title: '订单时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'outCount',
|
||||
title: '出库数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
title: '金额合计',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '含税金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,239 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpSaleOutApi } from '#/api/erp/sale/out';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteSaleOut,
|
||||
exportSaleOut,
|
||||
getSaleOutPage,
|
||||
updateSaleOutStatus,
|
||||
} from '#/api/erp/sale/out';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import SaleOutForm from './modules/sale-out-form.vue';
|
||||
|
||||
/** ERP 销售出库列表 */
|
||||
defineOptions({ name: 'ErpSaleOut' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: SaleOutForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function handleRowCheckboxChange({
|
||||
records,
|
||||
}: {
|
||||
records: ErpSaleOutApi.SaleOut[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 详情 */
|
||||
function handleDetail(row: ErpSaleOutApi.SaleOut) {
|
||||
formModalApi.setData({ type: 'detail', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(row: ErpSaleOutApi.SaleOut) {
|
||||
formModalApi.setData({ type: 'update', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: number[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deleteSaleOut(ids);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess'),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 处理错误
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审批/反审批操作 */
|
||||
function handleUpdateStatus(row: ErpSaleOutApi.SaleOut, status: number) {
|
||||
const hideLoading = message.loading({
|
||||
content: `确定${status === 20 ? '审批' : '反审批'}该订单吗?`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
updateSaleOutStatus({ id: row.id!, status })
|
||||
.then(() => {
|
||||
message.success({
|
||||
content: `${status === 20 ? '审批' : '反审批'}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
})
|
||||
.catch(() => {
|
||||
// 处理错误
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoading();
|
||||
});
|
||||
}
|
||||
|
||||
/** 导出 */
|
||||
async function handleExport() {
|
||||
const data = await exportSaleOut(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '销售出库.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getSaleOutPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpSaleOutApi.SaleOut>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleRowCheckboxChange,
|
||||
checkboxChange: handleRowCheckboxChange,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【销售】销售订单、出库、退货"
|
||||
url="https://doc.iocoder.cn/erp/sale/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/out/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/out/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
|
||||
<Grid table-title="销售出库列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['销售出库']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:sale-out:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:sale-out:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
disabled: isEmpty(checkedIds),
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:sale-out:delete'],
|
||||
popConfirm: {
|
||||
disabled: isEmpty(checkedIds),
|
||||
title: `是否删除所选中数据?`,
|
||||
confirm: () => {
|
||||
handleDelete(checkedIds);
|
||||
},
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:sale-out:query'],
|
||||
onClick: handleDetail.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:sale-out:update'],
|
||||
ifShow: () => row.status !== 20,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: row.status === 10 ? '审批' : '反审批',
|
||||
type: 'link',
|
||||
auth: ['erp:sale-out:update-status'],
|
||||
popConfirm: {
|
||||
title: `确认${row.status === 10 ? '审批' : '反审批'}${row.no}吗?`,
|
||||
confirm: handleUpdateStatus.bind(
|
||||
null,
|
||||
row,
|
||||
row.status === 10 ? 20 : 10,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
color: 'error',
|
||||
auth: ['erp:sale-out:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
||||
confirm: () => handleDelete([row.id!]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,309 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
import type { ErpSaleOutApi } from '#/api/erp/sale/out';
|
||||
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createSaleOut, getSaleOut, updateSaleOut } from '#/api/erp/sale/out';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import SaleOutItemForm from './sale-out-item-form.vue';
|
||||
import SelectSaleOrderForm from './select-sale-order-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<
|
||||
ErpSaleOutApi.SaleOut & {
|
||||
accountId?: number;
|
||||
customerId?: number;
|
||||
discountedPrice?: number;
|
||||
discountPercent?: number;
|
||||
fileUrl?: string;
|
||||
order?: ErpSaleOrderApi.SaleOrder;
|
||||
orderId?: number;
|
||||
orderNo?: string;
|
||||
}
|
||||
>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
outTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
customerId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
discountedPrice: 0,
|
||||
items: [],
|
||||
});
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加销售出库';
|
||||
if (formType.value === 'update') return '编辑销售出库';
|
||||
return '销售出库详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(formType.value),
|
||||
showDefaultActions: false,
|
||||
handleValuesChange: (values, changedFields) => {
|
||||
if (formData.value && changedFields.includes('otherPrice')) {
|
||||
formData.value.otherPrice = values.otherPrice;
|
||||
formData.value.totalPrice =
|
||||
(formData.value.discountedPrice || 0) +
|
||||
(formData.value.otherPrice || 0);
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 更新销售出库项
|
||||
const handleUpdateItems = async (items: ErpSaleOutApi.SaleOutItem[]) => {
|
||||
if (formData.value) {
|
||||
const data = await formApi.getValues();
|
||||
formData.value = { ...data, items };
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
};
|
||||
|
||||
// 选择采购订单
|
||||
const handleUpdateOrder = (order: ErpSaleOrderApi.SaleOrder) => {
|
||||
formData.value = {
|
||||
...formData.value,
|
||||
orderId: order.id,
|
||||
orderNo: order.no!,
|
||||
customerId: order.customerId!,
|
||||
accountId: order.accountId!,
|
||||
remark: order.remark!,
|
||||
discountPercent: order.discountPercent!,
|
||||
fileUrl: order.fileUrl!,
|
||||
};
|
||||
// 将订单项设置到入库单项
|
||||
order.items!.forEach((item: any) => {
|
||||
item.totalCount = item.count;
|
||||
item.count = item.totalCount - item.outCount;
|
||||
item.orderItemId = item.id;
|
||||
item.id = undefined;
|
||||
});
|
||||
formData.value.items = order.items!.filter(
|
||||
(item) => item.count && item.count > 0,
|
||||
) as ErpSaleOutApi.SaleOutItem[];
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
};
|
||||
|
||||
watch(
|
||||
() => formData.value.items!,
|
||||
(newItems: ErpSaleOutApi.SaleOutItem[]) => {
|
||||
if (newItems && newItems.length > 0) {
|
||||
// 计算每个产品的总价、税额和总价
|
||||
newItems.forEach((item) => {
|
||||
item.totalProductPrice = (item.productPrice || 0) * (item.count || 0);
|
||||
item.taxPrice =
|
||||
(item.totalProductPrice || 0) * ((item.taxPercent || 0) / 100);
|
||||
item.totalPrice = (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
});
|
||||
// 计算总价
|
||||
const totalPrice = newItems.reduce((sum, item) => {
|
||||
return sum + (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
}, 0);
|
||||
formData.value.totalPrice = totalPrice;
|
||||
} else {
|
||||
formData.value.totalPrice = 0;
|
||||
}
|
||||
// 优惠金额
|
||||
formData.value.discountPrice =
|
||||
((formData.value.totalPrice || 0) *
|
||||
(formData.value.discountPercent || 0)) /
|
||||
100;
|
||||
// 优惠后价格
|
||||
formData.value.discountedPrice =
|
||||
formData.value.totalPrice - formData.value.discountPrice;
|
||||
|
||||
// 计算最终价格(包含其他费用)
|
||||
formData.value.totalPrice =
|
||||
formData.value.discountedPrice + (formData.value.otherPrice || 0);
|
||||
formApi.setValues(formData.value, false);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* 创建或更新销售出库
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('子表单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpSaleOutApi.SaleOut;
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
// 解决新增销售出库报错
|
||||
id: undefined,
|
||||
}));
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createSaleOut(data)
|
||||
: updateSaleOut(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
outTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
customerId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
};
|
||||
formApi.setValues(formData.value, false);
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
formApi.updateSchema(useFormSchema(formType.value));
|
||||
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
outTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
customerId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
} as unknown as ErpSaleOutApi.SaleOut;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getSaleOut(data.id);
|
||||
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value, false);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose({ modalApi });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-2/3"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<SaleOutItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
@update:items="handleUpdateItems"
|
||||
/>
|
||||
</template>
|
||||
<template #orderNo="slotProps">
|
||||
<SelectSaleOrderForm
|
||||
v-bind="slotProps"
|
||||
:order-no="formData?.orderNo"
|
||||
@update:order="handleUpdateOrder"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOutApi } from '#/api/erp/sale/out';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getWarehouseStockCount } from '#/api/erp/stock/stock';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
|
||||
import { useSaleOutItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:items', 'update:totalPrice']);
|
||||
|
||||
interface Props {
|
||||
items?: ErpSaleOutApi.SaleOutItem[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpSaleOutApi.SaleOutItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
const warehouseOptions = ref<any[]>([]);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: useSaleOutItemTableColumns(),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 250,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
warehouseOptions.value = await getWarehouseSimpleList();
|
||||
});
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.count) {
|
||||
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
row.taxPrice =
|
||||
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
||||
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
const handleWarehouseChange = async (row: ErpSaleOutApi.SaleOutItem) => {
|
||||
const warehouseId = row.warehouseId;
|
||||
const stockCount = await getWarehouseStockCount({
|
||||
productId: row.productId!,
|
||||
warehouseId: warehouseId!,
|
||||
});
|
||||
row.stockCount = stockCount || 0;
|
||||
handleUpdateValue(row);
|
||||
};
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
productName: string;
|
||||
taxPrice: number;
|
||||
totalPrice: number;
|
||||
totalProductPrice: number;
|
||||
} => {
|
||||
const count = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.count || 0),
|
||||
0,
|
||||
);
|
||||
const totalProductPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalProductPrice || 0),
|
||||
0,
|
||||
);
|
||||
const taxPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.taxPrice || 0),
|
||||
0,
|
||||
);
|
||||
const totalPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
);
|
||||
return {
|
||||
productName: '合计',
|
||||
count,
|
||||
totalProductPrice,
|
||||
taxPrice,
|
||||
totalPrice,
|
||||
};
|
||||
};
|
||||
|
||||
const validate = async (): Promise<boolean> => {
|
||||
try {
|
||||
for (let i = 0; i < tableData.value.length; i++) {
|
||||
const item = tableData.value[i];
|
||||
if (item) {
|
||||
if (!item.warehouseId) {
|
||||
throw new Error(`第 ${i + 1} 行:仓库不能为空`);
|
||||
}
|
||||
if (!item.count || item.count <= 0) {
|
||||
throw new Error(`第 ${i + 1} 行:产品数量不能为空`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('验证失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getData = (): ErpSaleOutApi.SaleOutItem[] => tableData.value;
|
||||
const init = (items: ErpSaleOutApi.SaleOutItem[] | undefined): void => {
|
||||
tableData.value =
|
||||
items && items.length > 0
|
||||
? items.map((item) => {
|
||||
const newItem = { ...item };
|
||||
if (newItem.productPrice && newItem.count) {
|
||||
newItem.totalProductPrice =
|
||||
erpPriceMultiply(newItem.productPrice, newItem.count) ?? 0;
|
||||
newItem.taxPrice =
|
||||
erpPriceMultiply(
|
||||
newItem.totalProductPrice,
|
||||
(newItem.taxPercent || 0) / 100,
|
||||
) ?? 0;
|
||||
newItem.totalPrice = newItem.totalProductPrice + newItem.taxPrice;
|
||||
}
|
||||
return newItem;
|
||||
})
|
||||
: [];
|
||||
nextTick(() => {
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
getData,
|
||||
init,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="w-full">
|
||||
<template #warehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.warehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
class="w-full"
|
||||
@change="handleWarehouseChange(row)"
|
||||
/>
|
||||
</template>
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
disabled
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
style="width: 100%"
|
||||
placeholder="请选择产品"
|
||||
show-search
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.count"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.count || '-' }}</span>
|
||||
</template>
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
disabled
|
||||
v-model:value="row.productPrice"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<div class="border-border bg-muted mt-2 rounded border p-2">
|
||||
<div class="text-muted-foreground flex justify-between text-sm">
|
||||
<span class="text-foreground font-medium">合计:</span>
|
||||
<div class="flex space-x-4">
|
||||
<span>数量:{{ getSummaries().count }}</span>
|
||||
<span>金额:{{ getSummaries().totalProductPrice }}</span>
|
||||
<span>税额:{{ getSummaries().taxPrice }}</span>
|
||||
<span>税额合计:{{ getSummaries().totalPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Input, message, Modal } from 'ant-design-vue';
|
||||
|
||||
import SelectSaleOrderGrid from './select-sale-order-grid.vue';
|
||||
|
||||
defineProps({
|
||||
orderNo: {
|
||||
type: String,
|
||||
default: () => undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
'update:order': [order: ErpSaleOrderApi.SaleOrder];
|
||||
}>();
|
||||
const order = ref<ErpSaleOrderApi.SaleOrder>();
|
||||
const open = ref<boolean>(false);
|
||||
const handleSelectOrder = (selectorder: ErpSaleOrderApi.SaleOrder) => {
|
||||
order.value = selectorder;
|
||||
};
|
||||
|
||||
const handleOk = () => {
|
||||
if (!order.value) {
|
||||
message.warning('请选择一个采购订单');
|
||||
return;
|
||||
}
|
||||
emit('update:order', order.value);
|
||||
open.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Input
|
||||
v-bind="$attrs"
|
||||
readonly
|
||||
:value="orderNo"
|
||||
:disabled="disabled"
|
||||
@click="() => !disabled && (open = true)"
|
||||
>
|
||||
<template #addonAfter>
|
||||
<div>
|
||||
<IconifyIcon
|
||||
class="h-full w-6 cursor-pointer"
|
||||
icon="ant-design:setting-outlined"
|
||||
:style="{ cursor: disabled ? 'not-allowed' : 'pointer' }"
|
||||
@click="() => !disabled && (open = true)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Input>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="选择关联订单"
|
||||
class="!w-[50vw]"
|
||||
:show-confirm-button="true"
|
||||
@ok="handleOk"
|
||||
>
|
||||
<SelectSaleOrderGrid @select-row="handleSelectOrder" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getSaleOrderPage } from '#/api/erp/sale/order';
|
||||
|
||||
import { useOrderGridColumns, useOrderGridFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['selectRow']);
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useOrderGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useOrderGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getSaleOrderPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
outEnable: true,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
radioConfig: {
|
||||
trigger: 'row',
|
||||
highlight: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpSaleOrderApi.SaleOrder>,
|
||||
gridEvents: {
|
||||
radioChange: ({ row }: { row: ErpSaleOrderApi.SaleOrder }) => {
|
||||
emit('selectRow', row);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="max-h-[600px]" table-title="销售订单列表(仅展示可出库)" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,591 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { erpNumberFormatter, erpPriceInputFormatter } from '@vben/utils';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getAccountSimpleList } from '#/api/erp/finance/account';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getCustomerSimpleList } from '#/api/erp/sale/customer';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(formType: string): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '退货单号',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: '请选择客户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getCustomerSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'customerId',
|
||||
label: '客户',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-1',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
placeholder: '请选择关联订单',
|
||||
disabled: formType === 'detail',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '选择退货时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'returnTime',
|
||||
label: '退货时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
disabled: formType === 'detail',
|
||||
autoSize: { minRows: 1, maxRows: 1 },
|
||||
class: 'w-full',
|
||||
},
|
||||
fieldName: 'remark',
|
||||
formItemClass: 'col-span-2',
|
||||
label: '备注',
|
||||
},
|
||||
{
|
||||
component: 'FileUpload',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'discountPercent',
|
||||
componentProps: {
|
||||
placeholder: '优惠率',
|
||||
min: 0,
|
||||
max: 100,
|
||||
disabled: true,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
|
||||
label: '优惠率(%)',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '付款优惠',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountPrice',
|
||||
label: '付款优惠',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '优惠后金额',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
disabled: true,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'discountedPrice',
|
||||
label: '优惠后金额',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
disabled: formType === 'detail',
|
||||
placeholder: '请输入其他费用',
|
||||
precision: 2,
|
||||
formatter: erpPriceInputFormatter,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'otherPrice',
|
||||
label: '其他费用',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择结算账户',
|
||||
disabled: true,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getAccountSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
fieldName: 'accountId',
|
||||
label: '结算账户',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
disabled: true,
|
||||
min: 0,
|
||||
},
|
||||
fieldName: 'totalPrice',
|
||||
label: '应退金额',
|
||||
rules: z.number().min(0).optional(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 采购订单项表格列定义 */
|
||||
export function useSaleReturnItemTableColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'warehouseId',
|
||||
title: '仓库名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'warehouseId' },
|
||||
},
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '仓库库存',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '原数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnCount',
|
||||
title: '已退货数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '数量',
|
||||
minWidth: 120,
|
||||
fixed: 'right',
|
||||
slots: { default: 'count' },
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
fixed: 'right',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
fixed: 'right',
|
||||
title: '产品金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPercent',
|
||||
title: '税率(%)',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
fixed: 'right',
|
||||
field: 'taxPrice',
|
||||
title: '税额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
fixed: 'right',
|
||||
title: '合计金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '退货单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入退货单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'returnTime',
|
||||
label: '退货时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'customerId',
|
||||
label: '客户',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择客户',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getCustomerSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'warehouseId',
|
||||
label: '仓库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择仓库',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getWarehouseSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
fieldNames: {
|
||||
label: 'nickname',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderNo',
|
||||
label: '关联订单',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入关联订单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'refundStatus',
|
||||
label: '退货状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '未退货', value: 0 },
|
||||
{ label: '部分退货', value: 1 },
|
||||
{ label: '全部退货', value: 2 },
|
||||
],
|
||||
placeholder: '请选择退货状态',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '退货单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'customerName',
|
||||
title: '客户',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnTime',
|
||||
title: '退货时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '应退金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'refundPrice',
|
||||
title: '已退金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'unRefundPrice',
|
||||
title: '未退金额',
|
||||
formatter: ({ row }) => {
|
||||
return `${erpNumberFormatter(row.totalPrice - row.refundPrice, 2)}元`;
|
||||
},
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 250,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
/** 列表的搜索表单 */
|
||||
export function useOrderGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '订单单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入订单单号',
|
||||
allowClear: true,
|
||||
disabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
fieldNames: {
|
||||
label: 'name',
|
||||
value: 'id',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'orderTime',
|
||||
label: '订单时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始时间', '结束时间'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useOrderGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'radio',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '订单单号',
|
||||
width: 200,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
showOverflow: 'tooltip',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'customerName',
|
||||
title: '客户',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'orderTime',
|
||||
title: '订单时间',
|
||||
width: 160,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '总数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'returnCount',
|
||||
title: '已退货数量',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalProductPrice',
|
||||
title: '金额合计',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '含税金额',
|
||||
formatter: 'formatNumber',
|
||||
minWidth: 120,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,239 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpSaleReturnApi } from '#/api/erp/sale/return';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteSaleReturn,
|
||||
exportSaleReturn,
|
||||
getSaleReturnPage,
|
||||
updateSaleReturnStatus,
|
||||
} from '#/api/erp/sale/return';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import SaleReturnForm from './modules/sale-return-form.vue';
|
||||
|
||||
/** ERP 销售退货列表 */
|
||||
defineOptions({ name: 'ErpSaleReturn' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: SaleReturnForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function handleRowCheckboxChange({
|
||||
records,
|
||||
}: {
|
||||
records: ErpSaleReturnApi.SaleReturn[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 详情 */
|
||||
function handleDetail(row: ErpSaleReturnApi.SaleReturn) {
|
||||
formModalApi.setData({ type: 'detail', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(row: ErpSaleReturnApi.SaleReturn) {
|
||||
formModalApi.setData({ type: 'update', id: row.id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: number[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting'),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deleteSaleReturn(ids);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess'),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 处理错误
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审批/反审批操作 */
|
||||
function handleUpdateStatus(row: ErpSaleReturnApi.SaleReturn, status: number) {
|
||||
const hideLoading = message.loading({
|
||||
content: `确定${status === 20 ? '审批' : '反审批'}该订单吗?`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
updateSaleReturnStatus({ id: row.id!, status })
|
||||
.then(() => {
|
||||
message.success({
|
||||
content: `${status === 20 ? '审批' : '反审批'}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
})
|
||||
.catch(() => {
|
||||
// 处理错误
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoading();
|
||||
});
|
||||
}
|
||||
|
||||
/** 导出 */
|
||||
async function handleExport() {
|
||||
const data = await exportSaleReturn(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '销售退货.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getSaleReturnPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpSaleReturnApi.SaleReturn>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleRowCheckboxChange,
|
||||
checkboxChange: handleRowCheckboxChange,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【销售】销售订单、出库、退货"
|
||||
url="https://doc.iocoder.cn/erp/sale/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/return/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/sale/return/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<FormModal @success="onRefresh" />
|
||||
|
||||
<Grid table-title="销售退货列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['销售退货']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:sale-return:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:sale-return:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'primary',
|
||||
danger: true,
|
||||
disabled: isEmpty(checkedIds),
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:sale-return:delete'],
|
||||
popConfirm: {
|
||||
disabled: isEmpty(checkedIds),
|
||||
title: `是否删除所选中数据?`,
|
||||
confirm: () => {
|
||||
handleDelete(checkedIds);
|
||||
},
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.detail'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:sale-return:query'],
|
||||
onClick: handleDetail.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['erp:sale-return:update'],
|
||||
ifShow: () => row.status !== 20,
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: row.status === 10 ? '审批' : '反审批',
|
||||
type: 'link',
|
||||
auth: ['erp:sale-return:update-status'],
|
||||
popConfirm: {
|
||||
title: `确认${row.status === 10 ? '审批' : '反审批'}${row.no}吗?`,
|
||||
confirm: handleUpdateStatus.bind(
|
||||
null,
|
||||
row,
|
||||
row.status === 10 ? 20 : 10,
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
color: 'error',
|
||||
auth: ['erp:sale-return:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
||||
confirm: () => handleDelete([row.id!]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,313 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
import type { ErpSaleReturnApi } from '#/api/erp/sale/return';
|
||||
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createSaleReturn,
|
||||
getSaleReturn,
|
||||
updateSaleReturn,
|
||||
} from '#/api/erp/sale/return';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import SaleReturnItemForm from './sale-return-item-form.vue';
|
||||
import SelectSaleOrderForm from './select-sale-order-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<
|
||||
ErpSaleReturnApi.SaleReturn & {
|
||||
accountId?: number;
|
||||
customerId?: number;
|
||||
discountedPrice?: number;
|
||||
discountPercent?: number;
|
||||
fileUrl?: string;
|
||||
order?: ErpSaleOrderApi.SaleOrder;
|
||||
orderId?: number;
|
||||
orderNo?: string;
|
||||
}
|
||||
>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
customerId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
discountedPrice: 0,
|
||||
items: [],
|
||||
});
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加销售退货';
|
||||
if (formType.value === 'update') return '编辑销售退货';
|
||||
return '销售退货详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(formType.value),
|
||||
showDefaultActions: false,
|
||||
handleValuesChange: (values, changedFields) => {
|
||||
if (formData.value && changedFields.includes('otherPrice')) {
|
||||
formData.value.otherPrice = values.otherPrice;
|
||||
formData.value.totalPrice =
|
||||
(formData.value.discountedPrice || 0) +
|
||||
(formData.value.otherPrice || 0);
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 更新销售退货项
|
||||
const handleUpdateItems = async (items: ErpSaleReturnApi.SaleReturnItem[]) => {
|
||||
if (formData.value) {
|
||||
const data = await formApi.getValues();
|
||||
formData.value = { ...data, items };
|
||||
formApi.setValues(formData.value, false);
|
||||
}
|
||||
};
|
||||
|
||||
// 选择采购订单
|
||||
const handleUpdateOrder = (order: ErpSaleOrderApi.SaleOrder) => {
|
||||
formData.value = {
|
||||
...formData.value,
|
||||
orderId: order.id,
|
||||
orderNo: order.no!,
|
||||
customerId: order.customerId!,
|
||||
accountId: order.accountId!,
|
||||
remark: order.remark!,
|
||||
discountPercent: order.discountPercent!,
|
||||
fileUrl: order.fileUrl!,
|
||||
};
|
||||
// 将订单项设置到入库单项
|
||||
order.items!.forEach((item: any) => {
|
||||
item.totalCount = item.count;
|
||||
item.count = item.totalCount - item.returnCount;
|
||||
item.orderItemId = item.id;
|
||||
item.id = undefined;
|
||||
});
|
||||
formData.value.items = order.items!.filter(
|
||||
(item) => item.count && item.count > 0,
|
||||
) as ErpSaleReturnApi.SaleReturnItem[];
|
||||
|
||||
formApi.setValues(formData.value, false);
|
||||
};
|
||||
|
||||
watch(
|
||||
() => formData.value.items!,
|
||||
(newItems: ErpSaleReturnApi.SaleReturnItem[]) => {
|
||||
if (newItems && newItems.length > 0) {
|
||||
// 计算每个产品的总价、税额和总价
|
||||
newItems.forEach((item) => {
|
||||
item.totalProductPrice = (item.productPrice || 0) * (item.count || 0);
|
||||
item.taxPrice =
|
||||
(item.totalProductPrice || 0) * ((item.taxPercent || 0) / 100);
|
||||
item.totalPrice = (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
});
|
||||
// 计算总价
|
||||
const totalPrice = newItems.reduce((sum, item) => {
|
||||
return sum + (item.totalProductPrice || 0) + (item.taxPrice || 0);
|
||||
}, 0);
|
||||
formData.value.totalPrice = totalPrice;
|
||||
} else {
|
||||
formData.value.totalPrice = 0;
|
||||
}
|
||||
// 优惠金额
|
||||
formData.value.discountPrice =
|
||||
((formData.value.totalPrice || 0) *
|
||||
(formData.value.discountPercent || 0)) /
|
||||
100;
|
||||
// 优惠后价格
|
||||
formData.value.discountedPrice =
|
||||
formData.value.totalPrice - formData.value.discountPrice;
|
||||
|
||||
// 计算最终价格(包含其他费用)
|
||||
formData.value.totalPrice =
|
||||
formData.value.discountedPrice + (formData.value.otherPrice || 0);
|
||||
formApi.setValues(formData.value, false);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* 创建或更新销售退货
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '子表单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('子表单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpSaleReturnApi.SaleReturn;
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
// 解决新增销售退货报错
|
||||
id: undefined,
|
||||
}));
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createSaleReturn(data)
|
||||
: updateSaleReturn(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
customerId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
};
|
||||
formApi.setValues(formData.value, false);
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
formApi.updateSchema(useFormSchema(formType.value));
|
||||
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
remark: undefined,
|
||||
fileUrl: undefined,
|
||||
discountPercent: 0,
|
||||
customerId: undefined,
|
||||
discountPrice: 0,
|
||||
totalPrice: 0,
|
||||
otherPrice: 0,
|
||||
items: [],
|
||||
} as unknown as ErpSaleReturnApi.SaleReturn;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getSaleReturn(data.id);
|
||||
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value, false);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
defineExpose({ modalApi });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-2/3"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<SaleReturnItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
@update:items="handleUpdateItems"
|
||||
/>
|
||||
</template>
|
||||
<template #orderNo="slotProps">
|
||||
<SelectSaleOrderForm
|
||||
v-bind="slotProps"
|
||||
:order-no="formData?.orderNo"
|
||||
@update:order="handleUpdateOrder"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOutApi } from '#/api/erp/sale/out';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getWarehouseStockCount } from '#/api/erp/stock/stock';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
|
||||
import { useSaleReturnItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:items', 'update:totalPrice']);
|
||||
|
||||
interface Props {
|
||||
items?: ErpSaleOutApi.SaleOutItem[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpSaleOutApi.SaleOutItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
const warehouseOptions = ref<any[]>([]);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: useSaleReturnItemTableColumns(),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 250,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
warehouseOptions.value = await getWarehouseSimpleList();
|
||||
});
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.count) {
|
||||
row.totalProductPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
row.taxPrice =
|
||||
erpPriceMultiply(row.totalProductPrice, (row.taxPercent || 0) / 100) ?? 0;
|
||||
row.totalPrice = row.totalProductPrice + row.taxPrice;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
const handleWarehouseChange = async (row: ErpSaleOutApi.SaleOutItem) => {
|
||||
const warehouseId = row.warehouseId;
|
||||
const stockCount = await getWarehouseStockCount({
|
||||
productId: row.productId!,
|
||||
warehouseId: warehouseId!,
|
||||
});
|
||||
row.stockCount = stockCount || 0;
|
||||
handleUpdateValue(row);
|
||||
};
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
productName: string;
|
||||
taxPrice: number;
|
||||
totalPrice: number;
|
||||
totalProductPrice: number;
|
||||
} => {
|
||||
const count = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.count || 0),
|
||||
0,
|
||||
);
|
||||
const totalProductPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalProductPrice || 0),
|
||||
0,
|
||||
);
|
||||
const taxPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.taxPrice || 0),
|
||||
0,
|
||||
);
|
||||
const totalPrice = tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
);
|
||||
return {
|
||||
productName: '合计',
|
||||
count,
|
||||
totalProductPrice,
|
||||
taxPrice,
|
||||
totalPrice,
|
||||
};
|
||||
};
|
||||
|
||||
const validate = async (): Promise<boolean> => {
|
||||
try {
|
||||
for (let i = 0; i < tableData.value.length; i++) {
|
||||
const item = tableData.value[i];
|
||||
if (item) {
|
||||
if (!item.warehouseId) {
|
||||
throw new Error(`第 ${i + 1} 行:仓库不能为空`);
|
||||
}
|
||||
if (!item.count || item.count <= 0) {
|
||||
throw new Error(`第 ${i + 1} 行:产品数量不能为空`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('验证失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getData = (): ErpSaleOutApi.SaleOutItem[] => tableData.value;
|
||||
const init = (items: ErpSaleOutApi.SaleOutItem[] | undefined): void => {
|
||||
tableData.value =
|
||||
items && items.length > 0
|
||||
? items.map((item) => {
|
||||
const newItem = { ...item };
|
||||
if (newItem.productPrice && newItem.count) {
|
||||
newItem.totalProductPrice =
|
||||
erpPriceMultiply(newItem.productPrice, newItem.count) ?? 0;
|
||||
newItem.taxPrice =
|
||||
erpPriceMultiply(
|
||||
newItem.totalProductPrice,
|
||||
(newItem.taxPercent || 0) / 100,
|
||||
) ?? 0;
|
||||
newItem.totalPrice = newItem.totalProductPrice + newItem.taxPrice;
|
||||
}
|
||||
return newItem;
|
||||
})
|
||||
: [];
|
||||
nextTick(() => {
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
getData,
|
||||
init,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="w-full">
|
||||
<template #warehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.warehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
class="w-full"
|
||||
@change="handleWarehouseChange(row)"
|
||||
/>
|
||||
</template>
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
disabled
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
style="width: 100%"
|
||||
placeholder="请选择产品"
|
||||
show-search
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-if="!disabled"
|
||||
v-model:value="row.count"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
<span v-else>{{ row.count || '-' }}</span>
|
||||
</template>
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
disabled
|
||||
v-model:value="row.productPrice"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
@change="handlePriceChange(row)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<div class="border-border bg-muted mt-2 rounded border p-2">
|
||||
<div class="text-muted-foreground flex justify-between text-sm">
|
||||
<span class="text-foreground font-medium">合计:</span>
|
||||
<div class="flex space-x-4">
|
||||
<span>数量:{{ getSummaries().count }}</span>
|
||||
<span>金额:{{ getSummaries().totalProductPrice }}</span>
|
||||
<span>税额:{{ getSummaries().taxPrice }}</span>
|
||||
<span>税额合计:{{ getSummaries().totalPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Input, message, Modal } from 'ant-design-vue';
|
||||
|
||||
import SelectSaleOrderGrid from './select-sale-order-grid.vue';
|
||||
|
||||
defineProps({
|
||||
orderNo: {
|
||||
type: String,
|
||||
default: () => undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
'update:order': [order: ErpSaleOrderApi.SaleOrder];
|
||||
}>();
|
||||
const order = ref<ErpSaleOrderApi.SaleOrder>();
|
||||
const open = ref<boolean>(false);
|
||||
const handleSelectOrder = (selectorder: ErpSaleOrderApi.SaleOrder) => {
|
||||
order.value = selectorder;
|
||||
};
|
||||
|
||||
const handleOk = () => {
|
||||
if (!order.value) {
|
||||
message.warning('请选择一个采购订单');
|
||||
return;
|
||||
}
|
||||
emit('update:order', order.value);
|
||||
open.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Input
|
||||
v-bind="$attrs"
|
||||
readonly
|
||||
:value="orderNo"
|
||||
:disabled="disabled"
|
||||
@click="() => !disabled && (open = true)"
|
||||
>
|
||||
<template #addonAfter>
|
||||
<div>
|
||||
<IconifyIcon
|
||||
class="h-full w-6 cursor-pointer"
|
||||
icon="ant-design:setting-outlined"
|
||||
:style="{ cursor: disabled ? 'not-allowed' : 'pointer' }"
|
||||
@click="() => !disabled && (open = true)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Input>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="选择关联订单"
|
||||
class="!w-[50vw]"
|
||||
:show-confirm-button="true"
|
||||
@ok="handleOk"
|
||||
>
|
||||
<SelectSaleOrderGrid @select-row="handleSelectOrder" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getSaleOrderPage } from '#/api/erp/sale/order';
|
||||
|
||||
import { useOrderGridColumns, useOrderGridFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['selectRow']);
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useOrderGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useOrderGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getSaleOrderPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
returnEnable: true,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
radioConfig: {
|
||||
trigger: 'row',
|
||||
highlight: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpSaleOrderApi.SaleOrder>,
|
||||
gridEvents: {
|
||||
radioChange: ({ row }: { row: ErpSaleOrderApi.SaleOrder }) => {
|
||||
emit('selectRow', row);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid class="max-h-[600px]" table-title="销售订单列表(仅展示可退货)" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,313 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { createRequiredValidation } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(formType: string): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '盘点单号',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '选择盘点时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
disabled: formType === 'detail',
|
||||
fieldName: 'checkTime',
|
||||
label: '盘点时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
autoSize: { minRows: 2, maxRows: 4 },
|
||||
class: 'w-full',
|
||||
},
|
||||
disabled: formType === 'detail',
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'FileUpload',
|
||||
disabled: formType === 'detail',
|
||||
componentProps: {
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
disabled: formType === 'detail',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 库存盘点清单表格列定义 */
|
||||
export function useStockCheckItemTableColumns(
|
||||
isValidating?: any,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'warehouseId',
|
||||
title: '仓库名称',
|
||||
minWidth: 150,
|
||||
slots: { default: 'warehouseId' },
|
||||
className: createRequiredValidation(isValidating, 'warehouseId'),
|
||||
},
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
className: createRequiredValidation(isValidating, 'productId'),
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '账面库存',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'actualCount',
|
||||
title: '实际库存',
|
||||
minWidth: 120,
|
||||
slots: { default: 'actualCount' },
|
||||
className: createRequiredValidation(isValidating, 'actualCount'),
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '盈亏数量',
|
||||
minWidth: 120,
|
||||
slots: { default: 'count' },
|
||||
className: createRequiredValidation(isValidating, 'count'),
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '合计金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 150,
|
||||
slots: { default: 'remark' },
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 50,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '盘点单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入盘点单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'checkTime',
|
||||
label: '盘点时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始日期', '结束日期'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'warehouseId',
|
||||
label: '仓库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择仓库',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getWarehouseSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
labelField: 'nickname',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '盘点单号',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip',
|
||||
},
|
||||
{
|
||||
field: 'checkTime',
|
||||
title: '出库时间',
|
||||
minWidth: 180,
|
||||
cellRender: {
|
||||
name: 'CellDateTime',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '数量',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '金额',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 90,
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 300,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,219 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpStockCheckApi } from '#/api/erp/stock/check';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteStockCheck,
|
||||
exportStockCheck,
|
||||
getStockCheckPage,
|
||||
updateStockCheckStatus,
|
||||
} from '#/api/erp/stock/check';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import StockInForm from './modules/form.vue';
|
||||
|
||||
/** 库存盘点管理 */
|
||||
defineOptions({ name: 'ErpStockCheck' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: StockInForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出库存盘点单 */
|
||||
async function handleExport() {
|
||||
const data = await exportStockCheck(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '库存盘点单.xls', source: data });
|
||||
}
|
||||
|
||||
/** 新增/编辑/详情 */
|
||||
function openForm(type: string, id?: number) {
|
||||
formModalApi.setData({ type, id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: any[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: '删除中...',
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deleteStockCheck(ids);
|
||||
message.success({
|
||||
content: '删除成功',
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审核/反审核 */
|
||||
async function handleUpdateStatus(id: any, status: number) {
|
||||
const statusText = status === 20 ? '审核' : '反审核';
|
||||
const hideLoading = message.loading({
|
||||
content: `${statusText}中...`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await updateStockCheckStatus({ id, status });
|
||||
message.success({
|
||||
content: `${statusText}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getStockCheckPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
checkboxConfig: {
|
||||
reserve: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpStockCheckApi.StockCheck>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【库存】库存调拨、库存盘点"
|
||||
url="https://doc.iocoder.cn/erp/stock-move-check/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/stock/check/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/stock/check/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<Grid table-title="库存盘点单列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['库存盘点']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:stock-check:create'],
|
||||
onClick: () => openForm('create'),
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'default',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:stock-check:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'default',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:stock-check:delete'],
|
||||
popConfirm: {
|
||||
title: '是否删除所选中数据?',
|
||||
confirm: () => {
|
||||
const checkboxRecords = gridApi.grid.getCheckboxRecords();
|
||||
if (checkboxRecords.length === 0) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
handleDelete(checkboxRecords.map((item) => item.id));
|
||||
},
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '详情',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:stock-check:query'],
|
||||
onClick: () => openForm('detail', row.id),
|
||||
},
|
||||
{
|
||||
label: '编辑',
|
||||
auth: ['erp:stock-check:update'],
|
||||
icon: ACTION_ICON.EDIT,
|
||||
disabled: row.status !== 10,
|
||||
onClick: () => openForm('update', row.id),
|
||||
},
|
||||
{
|
||||
label: '审核',
|
||||
auth: ['erp:stock-check:update'],
|
||||
ifShow: row.status === 10,
|
||||
popConfirm: {
|
||||
title: '确认要审核该盘点单吗?',
|
||||
confirm: () => handleUpdateStatus(row.id, 20),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '反审核',
|
||||
danger: true,
|
||||
auth: ['erp:stock-check:update'],
|
||||
ifShow: row.status === 20,
|
||||
popConfirm: {
|
||||
title: '确认要反审核该盘点单吗?',
|
||||
confirm: () => handleUpdateStatus(row.id, 10),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
danger: true,
|
||||
auth: ['erp:stock-check:delete'],
|
||||
disabled: row.status !== 10,
|
||||
popConfirm: {
|
||||
title: '确认要删除该盘点单吗?',
|
||||
confirm: () => handleDelete([row.id]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<FormModal @success="onRefresh" />
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,196 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpStockCheckApi } from '#/api/erp/stock/check';
|
||||
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createStockCheck,
|
||||
getStockCheck,
|
||||
updateStockCheck,
|
||||
updateStockCheckStatus,
|
||||
} from '#/api/erp/stock/check';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import StockInItemForm from './stock-check-item-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<ErpStockCheckApi.StockCheck>();
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加库存盘点单';
|
||||
if (formType.value === 'update') return '编辑库存盘点单';
|
||||
return '库存盘点单详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(formType.value),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const handleUpdateItems = (items: ErpStockCheckApi.StockCheckItem[]) => {
|
||||
formData.value = modalApi.getData<ErpStockCheckApi.StockCheck>();
|
||||
if (formData.value) {
|
||||
formData.value.items = items;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建或更新库存盘点单
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('产品清单验证失败,请检查必填项');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '产品清单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('产品清单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpStockCheckApi.StockCheck;
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
id: undefined,
|
||||
}));
|
||||
// 将文件数组转换为字符串
|
||||
if (data.fileUrl && Array.isArray(data.fileUrl)) {
|
||||
data.fileUrl = data.fileUrl.length > 0 ? data.fileUrl[0] : '';
|
||||
}
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createStockCheck(data)
|
||||
: updateStockCheck(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
formApi.updateSchema(useFormSchema(formType.value));
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = { items: [] } as unknown as ErpStockCheckApi.StockCheck;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
// 如果是新增,自动添加一行
|
||||
if (formType.value === 'create' && itemFormInstance) {
|
||||
itemFormInstance.handleAdd();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getStockCheck(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 审核/反审核 */
|
||||
async function handleUpdateStatus(id: number, status: number) {
|
||||
try {
|
||||
await updateStockCheckStatus({ id, status });
|
||||
message.success(status === 20 ? '审核成功' : '反审核成功');
|
||||
emit('success');
|
||||
await modalApi.close();
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ modalApi, handleUpdateStatus });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-4/5"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<StockInItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
@update:items="handleUpdateItems"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,373 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpStockCheckApi } from '#/api/erp/stock/check';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { Input, InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getStockCount } from '#/api/erp/stock/stock';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
|
||||
import { useStockCheckItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:items']);
|
||||
|
||||
interface Props {
|
||||
items?: ErpStockCheckApi.StockCheckItem[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpStockCheckApi.StockCheckItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
const warehouseOptions = ref<any[]>([]);
|
||||
const isValidating = ref(false);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: useStockCheckItemTableColumns(isValidating),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 250,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
showFooter: true,
|
||||
footerCellClassName: 'stock-in-footer-cell',
|
||||
footerMethod: ({
|
||||
columns,
|
||||
}: {
|
||||
columns: VxeTableGridOptions['columns'];
|
||||
}) => {
|
||||
const footers: any[][] = [];
|
||||
const sums = getSummaries();
|
||||
const footerData: any[] = [];
|
||||
columns!.forEach((column, columnIndex: number) => {
|
||||
if (columnIndex === 0) {
|
||||
footerData.push('合计');
|
||||
} else if (column.field === 'count') {
|
||||
footerData.push(sums.count);
|
||||
} else if (column.field === 'totalPrice') {
|
||||
footerData.push(sums.totalPrice);
|
||||
} else {
|
||||
footerData.push('');
|
||||
}
|
||||
});
|
||||
footers.push(footerData);
|
||||
return footers;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
warehouseOptions.value = await getWarehouseSimpleList();
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
const newRow = {
|
||||
warehouseId: undefined,
|
||||
productId: undefined,
|
||||
productName: '',
|
||||
productUnitId: undefined,
|
||||
productUnitName: '',
|
||||
productBarCode: '',
|
||||
count: 1,
|
||||
productPrice: 0,
|
||||
totalPrice: 0,
|
||||
stockCount: 0,
|
||||
remark: '',
|
||||
};
|
||||
tableData.value.push(newRow);
|
||||
gridApi.grid.insertAt(newRow, -1);
|
||||
emit('update:items', [...tableData.value]);
|
||||
// 触发表格重新渲染以更新cellClassName
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete(row: ErpStockCheckApi.StockCheckItem) {
|
||||
gridApi.grid.remove(row);
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index !== -1) {
|
||||
tableData.value.splice(index, 1);
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
async function handleWarehouseChange(warehouseId: any, row: any) {
|
||||
const warehouse = warehouseOptions.value.find((w) => w.id === warehouseId);
|
||||
if (!warehouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
row.warehouseId = warehouseId;
|
||||
|
||||
// 如果已选择产品,重新获取库存
|
||||
if (row.productId) {
|
||||
const stockCount = await getStockCount(row.productId, warehouseId);
|
||||
row.stockCount = stockCount || 0;
|
||||
}
|
||||
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
async function handleProductChange(productId: any, row: any) {
|
||||
const product = productOptions.value.find((p) => p.id === productId);
|
||||
if (!product) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取库存数量
|
||||
const stockCount = row.warehouseId
|
||||
? await getStockCount(productId, row.warehouseId)
|
||||
: await getStockCount(productId);
|
||||
|
||||
row.productId = productId;
|
||||
row.productUnitId = product.unitId;
|
||||
row.productBarCode = product.barCode;
|
||||
row.productUnitName = product.unitName;
|
||||
row.productName = product.name;
|
||||
row.stockCount = stockCount || 0;
|
||||
row.actualCount = stockCount || 0;
|
||||
row.productPrice = product.purchasePrice || 0;
|
||||
row.count = 0;
|
||||
|
||||
handlePriceChange(row);
|
||||
}
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.actualCount) {
|
||||
row.count = row.actualCount - row.stockCount;
|
||||
row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
// 触发表格重新渲染以更新cellClassName
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
totalPrice: number;
|
||||
} => {
|
||||
return {
|
||||
count: tableData.value.reduce((sum, item) => sum + (item.count || 0), 0),
|
||||
totalPrice: tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
/** 验证表单 */
|
||||
function validate(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
isValidating.value = true;
|
||||
|
||||
// 触发表格重新渲染以显示验证错误
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
|
||||
// 验证是否有产品清单
|
||||
if (!tableData.value || tableData.value.length === 0) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证每一行的必填字段
|
||||
for (const item of tableData.value) {
|
||||
if (!item.warehouseId || !item.productId || !item.actualCount) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证通过,清除验证状态
|
||||
isValidating.value = false;
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
/** 初始化表格数据 */
|
||||
function init(items: ErpStockCheckApi.StockCheckItem[]) {
|
||||
tableData.value = items || [];
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
init,
|
||||
handleAdd,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full">
|
||||
<div class="mb-4 flex justify-between">
|
||||
<span class="text-lg font-medium"></span>
|
||||
</div>
|
||||
|
||||
<Grid>
|
||||
<template #warehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.warehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
@change="(value) => handleWarehouseChange(value, row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择产品"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
@change="(value) => handleProductChange(value, row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
<template #actualCount="{ row }">
|
||||
<InputNumber
|
||||
v-model:value="row.actualCount"
|
||||
:disabled="disabled"
|
||||
:min="0.001"
|
||||
:precision="2"
|
||||
@change="() => handlePriceChange(row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-model:value="row.count"
|
||||
:disabled="true"
|
||||
:min="0.001"
|
||||
:precision="2"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
v-model:value="row.productPrice"
|
||||
:disabled="disabled"
|
||||
:min="0.01"
|
||||
:precision="2"
|
||||
@change="() => handlePriceChange(row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #remark="{ row }">
|
||||
<Input
|
||||
v-model:value="row.remark"
|
||||
:disabled="disabled"
|
||||
placeholder="请输入备注"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
v-if="!disabled"
|
||||
:actions="[
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
danger: true,
|
||||
popConfirm: {
|
||||
title: '确认删除该产品吗?',
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<TableAction
|
||||
v-if="!disabled"
|
||||
class="mt-4 flex justify-center"
|
||||
:actions="[
|
||||
{
|
||||
label: '添加产品',
|
||||
type: 'default',
|
||||
onClick: handleAdd,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.vxe-table .vxe-footer--column.stock-in-footer-cell .vxe-cell) {
|
||||
background-color: #f5f5f5 !important;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,312 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { createRequiredValidation } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||
|
||||
/** 表单的配置项 */
|
||||
export function useFormSchema(formType: string): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
style: { display: 'none' },
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
hideLabel: true,
|
||||
formItemClass: 'hidden',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '系统自动生成',
|
||||
disabled: true,
|
||||
},
|
||||
fieldName: 'no',
|
||||
label: '调度单号',
|
||||
disabled: formType === 'detail',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '选择调度时间',
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'x',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
disabled: formType === 'detail',
|
||||
fieldName: 'moveTime',
|
||||
label: '调度时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
autoSize: { minRows: 2, maxRows: 4 },
|
||||
class: 'w-full',
|
||||
},
|
||||
disabled: formType === 'detail',
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
component: 'FileUpload',
|
||||
disabled: formType === 'detail',
|
||||
componentProps: {
|
||||
maxNumber: 1,
|
||||
maxSize: 10,
|
||||
accept: [
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'txt',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
],
|
||||
showDescription: true,
|
||||
},
|
||||
fieldName: 'fileUrl',
|
||||
label: '附件',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
{
|
||||
fieldName: 'product',
|
||||
disabled: formType === 'detail',
|
||||
label: '产品清单',
|
||||
component: 'Input',
|
||||
formItemClass: 'col-span-3',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 调度产品清单表格列定义 */
|
||||
export function useStockMoveItemTableColumns(
|
||||
isValidating?: any,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
|
||||
{
|
||||
field: 'fromWarehouseId',
|
||||
title: '调出仓库',
|
||||
minWidth: 150,
|
||||
slots: { default: 'fromWarehouseId' },
|
||||
className: createRequiredValidation(isValidating, 'fromWarehouseId'),
|
||||
},
|
||||
{
|
||||
field: 'toWarehouseId',
|
||||
title: '调入仓库',
|
||||
minWidth: 150,
|
||||
slots: { default: 'toWarehouseId' },
|
||||
className: createRequiredValidation(isValidating, 'toWarehouseId'),
|
||||
},
|
||||
{
|
||||
field: 'productId',
|
||||
title: '产品名称',
|
||||
minWidth: 200,
|
||||
slots: { default: 'productId' },
|
||||
className: createRequiredValidation(isValidating, 'productId'),
|
||||
},
|
||||
{
|
||||
field: 'stockCount',
|
||||
title: '库存',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'productBarCode',
|
||||
title: '条码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'productUnitName',
|
||||
title: '单位',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'count',
|
||||
title: '数量',
|
||||
minWidth: 120,
|
||||
slots: { default: 'count' },
|
||||
className: createRequiredValidation(isValidating, 'count'),
|
||||
},
|
||||
{
|
||||
field: 'productPrice',
|
||||
title: '产品单价',
|
||||
minWidth: 120,
|
||||
slots: { default: 'productPrice' },
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '金额',
|
||||
minWidth: 120,
|
||||
formatter: 'formatAmount2',
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 150,
|
||||
slots: { default: 'remark' },
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 50,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'no',
|
||||
label: '调度单号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入调度单号',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'productId',
|
||||
label: '产品',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择产品',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getProductSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'moveTime',
|
||||
label: '调度时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
placeholder: ['开始日期', '结束日期'],
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'fromWarehouseId',
|
||||
label: '调出仓库',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择调出仓库',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getWarehouseSimpleList,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.ERP_AUDIT_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'creator',
|
||||
label: '创建人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
placeholder: '请选择创建人',
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
api: getSimpleUserList,
|
||||
labelField: 'nickname',
|
||||
valueField: 'id',
|
||||
filterOption: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'no',
|
||||
title: '调度单号',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'productNames',
|
||||
title: '产品信息',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip',
|
||||
},
|
||||
{
|
||||
field: 'moveTime',
|
||||
title: '调度时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDate',
|
||||
},
|
||||
{
|
||||
field: 'creatorName',
|
||||
title: '创建人',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'totalCount',
|
||||
title: '数量',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'totalPrice',
|
||||
title: '金额',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 90,
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.ERP_AUDIT_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 300,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +1,219 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpStockMoveApi } from '#/api/erp/stock/move';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteStockMove,
|
||||
exportStockMove,
|
||||
getStockMovePage,
|
||||
updateStockMoveStatus,
|
||||
} from '#/api/erp/stock/move';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import StockInForm from './modules/form.vue';
|
||||
|
||||
/** 库存调拨单管理 */
|
||||
defineOptions({ name: 'ErpStockMove' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: StockInForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出库存调拨单 */
|
||||
async function handleExport() {
|
||||
const data = await exportStockMove(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '库存调拨单.xls', source: data });
|
||||
}
|
||||
|
||||
/** 新增/编辑/详情 */
|
||||
function openForm(type: string, id?: number) {
|
||||
formModalApi.setData({ type, id }).open();
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
async function handleDelete(ids: any[]) {
|
||||
const hideLoading = message.loading({
|
||||
content: '删除中...',
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deleteStockMove(ids);
|
||||
message.success({
|
||||
content: '删除成功',
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 审核/反审核 */
|
||||
async function handleUpdateStatus(id: any, status: number) {
|
||||
const statusText = status === 20 ? '审核' : '反审核';
|
||||
const hideLoading = message.loading({
|
||||
content: `${statusText}中...`,
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await updateStockMoveStatus({ id, status });
|
||||
message.success({
|
||||
content: `${statusText}成功`,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getStockMovePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
checkboxConfig: {
|
||||
reserve: true,
|
||||
},
|
||||
} as VxeTableGridOptions<ErpStockMoveApi.StockMove>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【库存】库存调拨、库存盘点"
|
||||
url="https://doc.iocoder.cn/erp/stock-move-check/"
|
||||
/>
|
||||
</template>
|
||||
<Button
|
||||
danger
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
||||
>
|
||||
该功能支持 Vue3 + element-plus 版本!
|
||||
</Button>
|
||||
<br />
|
||||
<Button
|
||||
type="link"
|
||||
target="_blank"
|
||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/stock/move/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/erp/stock/move/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<Grid table-title="库存调拨单列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['库存调拨']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['erp:stock-move:create'],
|
||||
onClick: () => openForm('create'),
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'default',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['erp:stock-move:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: '批量删除',
|
||||
type: 'default',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['erp:stock-move:delete'],
|
||||
popConfirm: {
|
||||
title: '是否删除所选中数据?',
|
||||
confirm: () => {
|
||||
const checkboxRecords = gridApi.grid.getCheckboxRecords();
|
||||
if (checkboxRecords.length === 0) {
|
||||
message.warning('请选择要删除的数据');
|
||||
return;
|
||||
}
|
||||
handleDelete(checkboxRecords.map((item) => item.id));
|
||||
},
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '详情',
|
||||
icon: ACTION_ICON.VIEW,
|
||||
auth: ['erp:stock-move:query'],
|
||||
onClick: () => openForm('detail', row.id),
|
||||
},
|
||||
{
|
||||
label: '编辑',
|
||||
auth: ['erp:stock-move:update'],
|
||||
icon: ACTION_ICON.EDIT,
|
||||
disabled: row.status !== 10,
|
||||
onClick: () => openForm('update', row.id),
|
||||
},
|
||||
{
|
||||
label: '审核',
|
||||
auth: ['erp:stock-move:update'],
|
||||
ifShow: row.status === 10,
|
||||
popConfirm: {
|
||||
title: '确认要审核该调度单吗?',
|
||||
confirm: () => handleUpdateStatus(row.id, 20),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '反审核',
|
||||
danger: true,
|
||||
auth: ['erp:stock-move:update'],
|
||||
ifShow: row.status === 20,
|
||||
popConfirm: {
|
||||
title: '确认要反审核该调度单吗?',
|
||||
confirm: () => handleUpdateStatus(row.id, 10),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
danger: true,
|
||||
auth: ['erp:stock-move:delete'],
|
||||
disabled: row.status !== 10,
|
||||
popConfirm: {
|
||||
title: '确认要删除该调度单吗?',
|
||||
confirm: () => handleDelete([row.id]),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<FormModal @success="onRefresh" />
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,196 @@
|
|||
<script lang="ts" setup>
|
||||
import type { ErpStockMoveApi } from '#/api/erp/stock/move';
|
||||
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createStockMove,
|
||||
getStockMove,
|
||||
updateStockMove,
|
||||
updateStockMoveStatus,
|
||||
} from '#/api/erp/stock/move';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import StockMoveItemForm from './stock-move-item-form.vue';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<ErpStockMoveApi.StockMove>();
|
||||
const formType = ref('');
|
||||
const itemFormRef = ref();
|
||||
|
||||
const getTitle = computed(() => {
|
||||
if (formType.value === 'create') return '添加库存调拨单';
|
||||
if (formType.value === 'update') return '编辑库存调拨单';
|
||||
return '库存调拨单详情';
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'vertical',
|
||||
schema: useFormSchema(formType.value),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const handleUpdateItems = (items: ErpStockMoveApi.StockMoveItem[]) => {
|
||||
formData.value = modalApi.getData<ErpStockMoveApi.StockMove>();
|
||||
if (formData.value) {
|
||||
formData.value.items = items;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建或更新其它出库单
|
||||
*/
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.validate === 'function') {
|
||||
try {
|
||||
const isValid = await itemFormInstance.validate();
|
||||
if (!isValid) {
|
||||
message.error('产品清单验证失败,请检查必填项');
|
||||
return;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '产品清单验证失败');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
message.error('产品清单验证方法不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证产品清单不能为空
|
||||
if (!formData.value?.items || formData.value.items.length === 0) {
|
||||
message.error('产品清单不能为空,请至少添加一个产品');
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as ErpStockMoveApi.StockMove;
|
||||
data.items = formData.value?.items?.map((item) => ({
|
||||
...item,
|
||||
id: undefined,
|
||||
}));
|
||||
// 将文件数组转换为字符串
|
||||
if (data.fileUrl && Array.isArray(data.fileUrl)) {
|
||||
data.fileUrl = data.fileUrl.length > 0 ? data.fileUrl[0] : '';
|
||||
}
|
||||
try {
|
||||
await (formType.value === 'create'
|
||||
? createStockMove(data)
|
||||
: updateStockMove(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success(formType.value === 'create' ? '新增成功' : '更新成功');
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type: string }>();
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
formType.value = data.type;
|
||||
formApi.updateSchema(useFormSchema(formType.value));
|
||||
if (!data.id) {
|
||||
// 初始化空的表单数据
|
||||
formData.value = { items: [] } as unknown as ErpStockMoveApi.StockMove;
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init([]);
|
||||
}
|
||||
// 如果是新增,自动添加一行
|
||||
if (formType.value === 'create' && itemFormInstance) {
|
||||
itemFormInstance.handleAdd();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getStockMove(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
// 初始化子表单
|
||||
await nextTick();
|
||||
const itemFormInstance = Array.isArray(itemFormRef.value)
|
||||
? itemFormRef.value[0]
|
||||
: itemFormRef.value;
|
||||
if (itemFormInstance && typeof itemFormInstance.init === 'function') {
|
||||
itemFormInstance.init(formData.value.items || []);
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 审核/反审核 */
|
||||
async function handleUpdateStatus(id: number, status: number) {
|
||||
try {
|
||||
await updateStockMoveStatus({ id, status });
|
||||
message.success(status === 20 ? '审核成功' : '反审核成功');
|
||||
emit('success');
|
||||
await modalApi.close();
|
||||
} catch (error: any) {
|
||||
message.error(error.message || '操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ modalApi, handleUpdateStatus });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
:title="getTitle"
|
||||
class="w-4/5"
|
||||
:closable="true"
|
||||
:mask-closable="true"
|
||||
:show-confirm-button="formType !== 'detail'"
|
||||
>
|
||||
<Form class="mx-3">
|
||||
<template #product="slotProps">
|
||||
<StockMoveItemForm
|
||||
v-bind="slotProps"
|
||||
ref="itemFormRef"
|
||||
class="w-full"
|
||||
:items="formData?.items ?? []"
|
||||
:disabled="formType === 'detail'"
|
||||
@update:items="handleUpdateItems"
|
||||
/>
|
||||
</template>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,382 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { ErpStockMoveApi } from '#/api/erp/stock/move';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { erpPriceMultiply } from '@vben/utils';
|
||||
|
||||
import { Input, InputNumber, Select } from 'ant-design-vue';
|
||||
|
||||
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSimpleList } from '#/api/erp/product/product';
|
||||
import { getStockCount } from '#/api/erp/stock/stock';
|
||||
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
|
||||
|
||||
import { useStockMoveItemTableColumns } from '../data';
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
items: () => [],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:items']);
|
||||
|
||||
interface Props {
|
||||
items?: ErpStockMoveApi.StockMoveItem[];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const tableData = ref<ErpStockMoveApi.StockMoveItem[]>([]);
|
||||
const productOptions = ref<any[]>([]);
|
||||
const warehouseOptions = ref<any[]>([]);
|
||||
const isValidating = ref(false);
|
||||
|
||||
/** 表格配置 */
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
editConfig: {
|
||||
trigger: 'click',
|
||||
mode: 'cell',
|
||||
},
|
||||
columns: useStockMoveItemTableColumns(isValidating),
|
||||
data: tableData.value,
|
||||
border: true,
|
||||
showOverflow: true,
|
||||
autoResize: true,
|
||||
minHeight: 250,
|
||||
keepSource: true,
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbarConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
showFooter: true,
|
||||
footerCellClassName: 'stock-in-footer-cell',
|
||||
footerMethod: ({
|
||||
columns,
|
||||
}: {
|
||||
columns: VxeTableGridOptions['columns'];
|
||||
}) => {
|
||||
const footers: any[][] = [];
|
||||
const sums = getSummaries();
|
||||
const footerData: any[] = [];
|
||||
columns!.forEach((column, columnIndex: number) => {
|
||||
if (columnIndex === 0) {
|
||||
footerData.push('合计');
|
||||
} else if (column.field === 'count') {
|
||||
footerData.push(sums.count);
|
||||
} else if (column.field === 'totalPrice') {
|
||||
footerData.push(sums.totalPrice);
|
||||
} else {
|
||||
footerData.push('');
|
||||
}
|
||||
});
|
||||
footers.push(footerData);
|
||||
return footers;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/** 监听外部传入的列数据 */
|
||||
watch(
|
||||
() => props.items,
|
||||
async (items) => {
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
await nextTick();
|
||||
tableData.value = [...items];
|
||||
await nextTick();
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
);
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
productOptions.value = await getProductSimpleList();
|
||||
warehouseOptions.value = await getWarehouseSimpleList();
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
const newRow = {
|
||||
fromWarehouseId: undefined,
|
||||
toWarehouseId: undefined,
|
||||
productId: undefined,
|
||||
productName: '',
|
||||
productUnitId: undefined,
|
||||
productUnitName: '',
|
||||
productBarCode: '',
|
||||
count: 1,
|
||||
productPrice: 0,
|
||||
totalPrice: 0,
|
||||
stockCount: 0,
|
||||
remark: '',
|
||||
};
|
||||
tableData.value.push(newRow);
|
||||
gridApi.grid.insertAt(newRow, -1);
|
||||
emit('update:items', [...tableData.value]);
|
||||
// 触发表格重新渲染以更新cellClassName
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
}
|
||||
|
||||
function handleDelete(row: ErpStockMoveApi.StockMoveItem) {
|
||||
gridApi.grid.remove(row);
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index !== -1) {
|
||||
tableData.value.splice(index, 1);
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
}
|
||||
|
||||
async function handleWarehouseChange(warehouseId: any, row: any) {
|
||||
const warehouse = warehouseOptions.value.find((w) => w.id === warehouseId);
|
||||
if (!warehouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
row.warehouseId = warehouseId;
|
||||
|
||||
// 如果已选择产品,重新获取库存
|
||||
if (row.productId) {
|
||||
const stockCount = await getStockCount(row.productId, warehouseId);
|
||||
row.stockCount = stockCount || 0;
|
||||
}
|
||||
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
async function handleProductChange(productId: any, row: any) {
|
||||
const product = productOptions.value.find((p) => p.id === productId);
|
||||
if (!product) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取库存数量
|
||||
const stockCount = row.warehouseId
|
||||
? await getStockCount(productId, row.warehouseId)
|
||||
: await getStockCount(productId);
|
||||
|
||||
row.productId = productId;
|
||||
row.productUnitId = product.unitId;
|
||||
row.productBarCode = product.barCode;
|
||||
row.productUnitName = product.unitName;
|
||||
row.productName = product.name;
|
||||
row.stockCount = stockCount || 0;
|
||||
row.productPrice = product.purchasePrice || 0;
|
||||
row.count = row.count || 1;
|
||||
|
||||
handlePriceChange(row);
|
||||
}
|
||||
|
||||
function handlePriceChange(row: any) {
|
||||
if (row.productPrice && row.count) {
|
||||
row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
|
||||
}
|
||||
handleUpdateValue(row);
|
||||
}
|
||||
|
||||
function handleUpdateValue(row: any) {
|
||||
const index = tableData.value.findIndex((item) => item.id === row.id);
|
||||
if (index === -1) {
|
||||
tableData.value.push(row);
|
||||
} else {
|
||||
tableData.value[index] = row;
|
||||
}
|
||||
emit('update:items', [...tableData.value]);
|
||||
// 触发表格重新渲染以更新cellClassName
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
}
|
||||
|
||||
const getSummaries = (): {
|
||||
count: number;
|
||||
totalPrice: number;
|
||||
} => {
|
||||
return {
|
||||
count: tableData.value.reduce((sum, item) => sum + (item.count || 0), 0),
|
||||
totalPrice: tableData.value.reduce(
|
||||
(sum, item) => sum + (item.totalPrice || 0),
|
||||
0,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
/** 验证表单 */
|
||||
function validate(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
isValidating.value = true;
|
||||
|
||||
// 触发表格重新渲染以显示验证错误
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
|
||||
// 验证是否有产品清单
|
||||
if (!tableData.value || tableData.value.length === 0) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证每一行的必填字段
|
||||
for (const item of tableData.value) {
|
||||
if (
|
||||
!item.fromWarehouseId ||
|
||||
!item.toWarehouseId ||
|
||||
!item.productId ||
|
||||
!item.count ||
|
||||
item.count <= 0
|
||||
) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证通过,清除验证状态
|
||||
isValidating.value = false;
|
||||
nextTick(() => {
|
||||
gridApi.grid.refreshColumn();
|
||||
});
|
||||
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
/** 初始化表格数据 */
|
||||
function init(items: ErpStockMoveApi.StockMoveItem[]) {
|
||||
tableData.value = items || [];
|
||||
gridApi.grid.reloadData(tableData.value);
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
init,
|
||||
handleAdd,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full">
|
||||
<div class="mb-4 flex justify-between">
|
||||
<span class="text-lg font-medium"></span>
|
||||
</div>
|
||||
|
||||
<Grid>
|
||||
<template #fromWarehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.fromWarehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择调出仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
@change="(value) => handleWarehouseChange(value, row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #toWarehouseId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.toWarehouseId"
|
||||
:options="warehouseOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择调入仓库"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
@change="(value) => handleWarehouseChange(value, row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #productId="{ row }">
|
||||
<Select
|
||||
v-model:value="row.productId"
|
||||
:options="productOptions"
|
||||
:field-names="{ label: 'name', value: 'id' }"
|
||||
placeholder="请选择产品"
|
||||
:disabled="disabled"
|
||||
show-search
|
||||
@change="(value) => handleProductChange(value, row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #count="{ row }">
|
||||
<InputNumber
|
||||
v-model:value="row.count"
|
||||
:disabled="disabled"
|
||||
:min="0.001"
|
||||
:precision="3"
|
||||
@change="() => handlePriceChange(row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #productPrice="{ row }">
|
||||
<InputNumber
|
||||
v-model:value="row.productPrice"
|
||||
:disabled="disabled"
|
||||
:min="0.01"
|
||||
:precision="2"
|
||||
@change="() => handlePriceChange(row)"
|
||||
class="w-full"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #remark="{ row }">
|
||||
<Input
|
||||
v-model:value="row.remark"
|
||||
:disabled="disabled"
|
||||
placeholder="请输入备注"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
v-if="!disabled"
|
||||
:actions="[
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
danger: true,
|
||||
popConfirm: {
|
||||
title: '确认删除该产品吗?',
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #bottom>
|
||||
<TableAction
|
||||
v-if="!disabled"
|
||||
class="mt-4 flex justify-center"
|
||||
:actions="[
|
||||
{
|
||||
label: '添加产品',
|
||||
type: 'default',
|
||||
onClick: handleAdd,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.vxe-table .vxe-footer--column.stock-in-footer-cell .vxe-cell) {
|
||||
background-color: #f5f5f5 !important;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue