feat(mes): 迁移客户、供应商、车间管理到 vben
parent
0d175cbe9c
commit
e6e15ca4ef
|
|
@ -0,0 +1,86 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdClientApi {
|
||||
/** MES 客户 */
|
||||
export interface Client {
|
||||
id?: number; // 客户编号
|
||||
code?: string; // 客户编码
|
||||
name?: string; // 客户名称
|
||||
nickname?: string; // 客户简称
|
||||
englishName?: string; // 客户英文名称
|
||||
description?: string; // 客户简介
|
||||
logo?: string; // 客户 LOGO 地址
|
||||
type?: number; // 客户类型
|
||||
address?: string; // 客户地址
|
||||
website?: string; // 客户官网地址
|
||||
email?: string; // 客户邮箱地址
|
||||
telephone?: string; // 客户电话
|
||||
contact1Name?: string; // 联系人1
|
||||
contact1Telephone?: string; // 联系人1电话
|
||||
contact1Email?: string; // 联系人1邮箱
|
||||
contact2Name?: string; // 联系人2
|
||||
contact2Telephone?: string; // 联系人2电话
|
||||
contact2Email?: string; // 联系人2邮箱
|
||||
creditCode?: string; // 统一社会信用代码
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
|
||||
/** 客户导入结果 */
|
||||
export interface ClientImportRespVO {
|
||||
createCodes?: string[]; // 新增成功的客户编码
|
||||
updateCodes?: string[]; // 更新成功的客户编码
|
||||
failureCodes?: Record<string, string>; // 导入失败的客户编码及原因
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询客户分页 */
|
||||
export function getClientPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesMdClientApi.Client>>(
|
||||
'/mes/md-client/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询客户详情 */
|
||||
export function getClient(id: number) {
|
||||
return requestClient.get<MesMdClientApi.Client>(
|
||||
`/mes/md-client/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增客户 */
|
||||
export function createClient(data: MesMdClientApi.Client) {
|
||||
return requestClient.post('/mes/md-client/create', data);
|
||||
}
|
||||
|
||||
/** 修改客户 */
|
||||
export function updateClient(data: MesMdClientApi.Client) {
|
||||
return requestClient.put('/mes/md-client/update', data);
|
||||
}
|
||||
|
||||
/** 删除客户 */
|
||||
export function deleteClient(id: number) {
|
||||
return requestClient.delete(`/mes/md-client/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出客户 */
|
||||
export function exportClient(params: any) {
|
||||
return requestClient.download('/mes/md-client/export-excel', { params });
|
||||
}
|
||||
|
||||
/** 下载客户导入模板 */
|
||||
export function importClientTemplate() {
|
||||
return requestClient.download('/mes/md-client/get-import-template');
|
||||
}
|
||||
|
||||
/** 导入客户 */
|
||||
export function importClient(file: File, updateSupport: boolean) {
|
||||
return requestClient.upload<MesMdClientApi.ClientImportRespVO>(
|
||||
`/mes/md-client/import?updateSupport=${updateSupport}`,
|
||||
{ file },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdVendorApi {
|
||||
/** MES 供应商 */
|
||||
export interface Vendor {
|
||||
id?: number; // 供应商编号
|
||||
code?: string; // 供应商编码
|
||||
name?: string; // 供应商名称
|
||||
nickname?: string; // 供应商简称
|
||||
englishName?: string; // 供应商英文名称
|
||||
description?: string; // 供应商简介
|
||||
logo?: string; // 供应商 LOGO 地址
|
||||
level?: string; // 供应商等级
|
||||
score?: number; // 供应商评分
|
||||
address?: string; // 供应商地址
|
||||
website?: string; // 供应商官网地址
|
||||
email?: string; // 供应商邮箱地址
|
||||
telephone?: string; // 供应商电话
|
||||
contact1Name?: string; // 联系人1
|
||||
contact1Telephone?: string; // 联系人1电话
|
||||
contact1Email?: string; // 联系人1邮箱
|
||||
contact2Name?: string; // 联系人2
|
||||
contact2Telephone?: string; // 联系人2电话
|
||||
contact2Email?: string; // 联系人2邮箱
|
||||
creditCode?: string; // 统一社会信用代码
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
|
||||
/** 供应商导入结果 */
|
||||
export interface VendorImportRespVO {
|
||||
createCodes?: string[]; // 新增成功的供应商编码
|
||||
updateCodes?: string[]; // 更新成功的供应商编码
|
||||
failureCodes?: Record<string, string>; // 导入失败的供应商编码及原因
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询供应商分页 */
|
||||
export function getVendorPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesMdVendorApi.Vendor>>(
|
||||
'/mes/md-vendor/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询供应商详情 */
|
||||
export function getVendor(id: number) {
|
||||
return requestClient.get<MesMdVendorApi.Vendor>(
|
||||
`/mes/md-vendor/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增供应商 */
|
||||
export function createVendor(data: MesMdVendorApi.Vendor) {
|
||||
return requestClient.post('/mes/md-vendor/create', data);
|
||||
}
|
||||
|
||||
/** 修改供应商 */
|
||||
export function updateVendor(data: MesMdVendorApi.Vendor) {
|
||||
return requestClient.put('/mes/md-vendor/update', data);
|
||||
}
|
||||
|
||||
/** 删除供应商 */
|
||||
export function deleteVendor(id: number) {
|
||||
return requestClient.delete(`/mes/md-vendor/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出供应商 */
|
||||
export function exportVendor(params: any) {
|
||||
return requestClient.download('/mes/md-vendor/export-excel', { params });
|
||||
}
|
||||
|
||||
/** 下载供应商导入模板 */
|
||||
export function importVendorTemplate() {
|
||||
return requestClient.download('/mes/md-vendor/get-import-template');
|
||||
}
|
||||
|
||||
/** 导入供应商 */
|
||||
export function importVendor(file: File, updateSupport: boolean) {
|
||||
return requestClient.upload<MesMdVendorApi.VendorImportRespVO>(
|
||||
`/mes/md-vendor/import?updateSupport=${updateSupport}`,
|
||||
{ file },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdWorkshopApi {
|
||||
/** MES 车间 */
|
||||
export interface Workshop {
|
||||
id?: number; // 车间编号
|
||||
code?: string; // 车间编码
|
||||
name?: string; // 车间名称
|
||||
area?: number; // 面积
|
||||
chargeUserId?: number; // 负责人用户编号
|
||||
chargeUserName?: string; // 负责人名称
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询车间分页 */
|
||||
export function getWorkshopPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesMdWorkshopApi.Workshop>>(
|
||||
'/mes/md-workshop/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询车间精简列表 */
|
||||
export function getWorkshopSimpleList() {
|
||||
return requestClient.get<MesMdWorkshopApi.Workshop[]>(
|
||||
'/mes/md-workshop/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询车间详情 */
|
||||
export function getWorkshop(id: number) {
|
||||
return requestClient.get<MesMdWorkshopApi.Workshop>(
|
||||
`/mes/md-workshop/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增车间 */
|
||||
export function createWorkshop(data: MesMdWorkshopApi.Workshop) {
|
||||
return requestClient.post('/mes/md-workshop/create', data);
|
||||
}
|
||||
|
||||
/** 修改车间 */
|
||||
export function updateWorkshop(data: MesMdWorkshopApi.Workshop) {
|
||||
return requestClient.put('/mes/md-workshop/update', data);
|
||||
}
|
||||
|
||||
/** 删除车间 */
|
||||
export function deleteWorkshop(id: number) {
|
||||
return requestClient.delete(`/mes/md-workshop/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出车间 */
|
||||
export function exportWorkshop(params: any) {
|
||||
return requestClient.download('/mes/md-workshop/export-excel', { params });
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesWmItemReceiptLineApi {
|
||||
/** MES 物料接收单行 */
|
||||
export interface ItemReceiptLine {
|
||||
id?: number; // 行编号
|
||||
receiptId?: number; // 入库单编号
|
||||
receiptCode?: string; // 入库单编码
|
||||
purchaseOrderCode?: string; // 采购订单号
|
||||
itemId?: number; // 物料编号
|
||||
itemCode?: string; // 物料编码
|
||||
itemName?: string; // 物料名称
|
||||
specification?: string; // 规格型号
|
||||
unitMeasureName?: string; // 单位
|
||||
receivedQuantity?: number; // 入库数量
|
||||
batchCode?: string; // 批次号
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询物料接收单行分页 */
|
||||
export function getItemReceiptLinePage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesWmItemReceiptLineApi.ItemReceiptLine>>(
|
||||
'/mes/wm/item-receipt-line/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesWmProductSalesApi {
|
||||
/** MES 销售出库单 */
|
||||
export interface ProductSales {
|
||||
id?: number; // 销售出库单编号
|
||||
code?: string; // 出库单编号
|
||||
name?: string; // 出库单名称
|
||||
salesOrderCode?: string; // 销售订单编号
|
||||
salesDate?: Date; // 出库日期
|
||||
status?: number; // 单据状态
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询销售出库单分页 */
|
||||
export function getProductSalesPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesWmProductSalesApi.ProductSales>>(
|
||||
'/mes/wm/product-sales/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesWmProductSalesLineApi {
|
||||
/** MES 销售出库单行 */
|
||||
export interface ProductSalesLine {
|
||||
id?: number; // 行编号
|
||||
itemId?: number; // 物料编号
|
||||
itemCode?: string; // 物料编码
|
||||
itemName?: string; // 物料名称
|
||||
specification?: string; // 规格型号
|
||||
unitMeasureName?: string; // 单位
|
||||
quantity?: number; // 出库数量
|
||||
batchCode?: string; // 批次号
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询销售出库单行分页 */
|
||||
export function getProductSalesLinePage(params: PageParam) {
|
||||
return requestClient.get<
|
||||
PageResult<MesWmProductSalesLineApi.ProductSalesLine>
|
||||
>('/mes/wm/product-sales-line/page', { params });
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import { CommonStatusEnum } from '@vben/constants';
|
||||
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getClientPage } from '#/api/mes/md/client';
|
||||
|
||||
import {
|
||||
useClientSelectGridColumns,
|
||||
useClientSelectGridFormSchema,
|
||||
} from '../data';
|
||||
|
||||
const emit = defineEmits<{
|
||||
selected: [rows: MesMdClientApi.Client[]];
|
||||
}>();
|
||||
|
||||
const open = ref(false); // 弹窗是否打开
|
||||
const multiple = ref(true); // 是否多选
|
||||
const syncingSingleSelection = ref(false); // 是否同步单选勾选状态
|
||||
const selectedRows = ref<MesMdClientApi.Client[]>([]); // 已选客户列表
|
||||
const preSelectedIds = ref<number[]>([]); // 预选客户编号列表
|
||||
|
||||
/** 单选模式下同步 VXE 勾选状态,避免跨页残留多选 */
|
||||
async function syncSingleSelection(row?: MesMdClientApi.Client) {
|
||||
syncingSingleSelection.value = true;
|
||||
await nextTick();
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
if (row) {
|
||||
await gridApi.grid.setCheckboxRow(row, true);
|
||||
}
|
||||
await nextTick();
|
||||
syncingSingleSelection.value = false;
|
||||
}
|
||||
|
||||
/** 处理勾选变化,单选模式只保留最后一条 */
|
||||
async function handleCheckboxChange({
|
||||
checked,
|
||||
records,
|
||||
row,
|
||||
}: {
|
||||
checked: boolean;
|
||||
records: MesMdClientApi.Client[];
|
||||
row?: MesMdClientApi.Client;
|
||||
}) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
if (!multiple.value) {
|
||||
const selected = checked && row ? [row] : [];
|
||||
selectedRows.value = selected;
|
||||
await syncSingleSelection(selected[0]);
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 处理全选变化 */
|
||||
function handleCheckboxAll({ records }: { records: MesMdClientApi.Client[] }) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 回显预选客户 */
|
||||
function applyPreSelection() {
|
||||
if (preSelectedIds.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
const rows = gridApi.grid.getData() as MesMdClientApi.Client[];
|
||||
for (const row of rows) {
|
||||
if (row.id && preSelectedIds.value.includes(row.id)) {
|
||||
gridApi.grid.setCheckboxRow(row, true);
|
||||
if (!multiple.value) {
|
||||
selectedRows.value = [row];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useClientSelectGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useClientSelectGridColumns(),
|
||||
height: 520,
|
||||
keepSource: true,
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
range: true,
|
||||
reserve: true,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getClientPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdClientApi.Client>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleCheckboxAll,
|
||||
checkboxChange: handleCheckboxChange,
|
||||
},
|
||||
});
|
||||
|
||||
/** 重置查询和选择状态 */
|
||||
async function resetQueryState() {
|
||||
selectedRows.value = [];
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
await gridApi.formApi.resetForm();
|
||||
}
|
||||
|
||||
/** 打开客户选择弹窗 */
|
||||
async function openModal(selectedIds?: number[], options?: { multiple?: boolean }) {
|
||||
open.value = true;
|
||||
multiple.value = options?.multiple ?? true;
|
||||
preSelectedIds.value = selectedIds || [];
|
||||
await nextTick();
|
||||
await resetQueryState();
|
||||
await gridApi.query();
|
||||
await nextTick();
|
||||
applyPreSelection();
|
||||
}
|
||||
|
||||
/** 关闭客户选择弹窗 */
|
||||
async function closeModal() {
|
||||
open.value = false;
|
||||
await resetQueryState();
|
||||
}
|
||||
|
||||
/** 确认选择客户 */
|
||||
function handleConfirm() {
|
||||
if (selectedRows.value.length === 0) {
|
||||
message.warning(multiple.value ? '请至少选择一条数据' : '请选择一条数据');
|
||||
return;
|
||||
}
|
||||
emit('selected', multiple.value ? selectedRows.value : [selectedRows.value[0]!]);
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
defineExpose({ open: openModal });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="客户选择"
|
||||
width="70%"
|
||||
:destroy-on-close="true"
|
||||
@ok="handleConfirm"
|
||||
@cancel="closeModal"
|
||||
>
|
||||
<Grid table-title="客户列表" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { computed, ref, useAttrs, watch } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Input, Tooltip } from 'ant-design-vue';
|
||||
|
||||
import { getClient } from '#/api/mes/md/client';
|
||||
|
||||
import MdClientSelectDialog from './md-client-select-dialog.vue';
|
||||
|
||||
defineOptions({ name: 'MdClientSelect', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
allowClear?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
allowClear: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择客户',
|
||||
},
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
change: [item: MesMdClientApi.Client | undefined];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
const attrs = useAttrs(); // 透传属性
|
||||
const dialogRef = ref<InstanceType<typeof MdClientSelectDialog>>(); // 客户选择弹窗
|
||||
const hovering = ref(false); // 是否悬停
|
||||
const selectedItem = ref<MesMdClientApi.Client>(); // 当前选中客户
|
||||
|
||||
const displayLabel = computed(() => selectedItem.value?.name ?? ''); // 选择器展示名称
|
||||
const showClear = computed( // 是否显示清空图标
|
||||
() => props.allowClear && !props.disabled && hovering.value && props.modelValue != null,
|
||||
);
|
||||
|
||||
/** 根据客户编号回显选择器 */
|
||||
async function resolveItemById(id: number | undefined) {
|
||||
if (id == null) {
|
||||
selectedItem.value = undefined;
|
||||
return;
|
||||
}
|
||||
if (selectedItem.value?.id === id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
selectedItem.value = await getClient(id);
|
||||
} catch (error) {
|
||||
console.error('[MdClientSelect] resolveItemById failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
resolveItemById(value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** 清空已选客户 */
|
||||
function clearSelected() {
|
||||
selectedItem.value = undefined;
|
||||
emit('update:modelValue', undefined);
|
||||
emit('change', undefined);
|
||||
}
|
||||
|
||||
/** 打开客户选择弹窗 */
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (props.disabled) {
|
||||
return;
|
||||
}
|
||||
const target = event.target as HTMLElement;
|
||||
if (showClear.value && target.closest('.ant-input-suffix')) {
|
||||
event.stopPropagation();
|
||||
clearSelected();
|
||||
return;
|
||||
}
|
||||
const selectedIds = props.modelValue == null ? [] : [props.modelValue];
|
||||
dialogRef.value?.open(selectedIds, { multiple: false });
|
||||
}
|
||||
|
||||
/** 回填选中的客户 */
|
||||
function handleSelected(rows: MesMdClientApi.Client[]) {
|
||||
const item = rows[0];
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
selectedItem.value = item;
|
||||
emit('update:modelValue', item.id);
|
||||
emit('change', item);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
class="w-full"
|
||||
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
||||
@click="handleClick"
|
||||
@mouseenter="hovering = true"
|
||||
@mouseleave="hovering = false"
|
||||
>
|
||||
<Tooltip :mouse-enter-delay="0.5" :open="selectedItem ? undefined : false">
|
||||
<template #title>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>简称:{{ selectedItem.nickname || '-' }}</div>
|
||||
<div>电话:{{ selectedItem.telephone || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<Input
|
||||
:disabled="disabled"
|
||||
:placeholder="placeholder"
|
||||
:value="displayLabel"
|
||||
readonly
|
||||
>
|
||||
<template #suffix>
|
||||
<IconifyIcon
|
||||
class="size-4"
|
||||
:icon="showClear ? 'lucide:circle-x' : 'lucide:search'"
|
||||
/>
|
||||
</template>
|
||||
</Input>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<MdClientSelectDialog ref="dialogRef" @selected="handleSelected" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteClient, exportClient, getClientPage } from '#/api/mes/md/client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
import ImportForm from './modules/import-form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [ImportModal, importModalApi] = useVbenModal({
|
||||
connectedComponent: ImportForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建客户 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看客户 */
|
||||
function handleDetail(row: MesMdClientApi.Client) {
|
||||
formModalApi.setData({ id: row.id, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
/** 编辑客户 */
|
||||
function handleEdit(row: MesMdClientApi.Client) {
|
||||
formModalApi.setData({ id: row.id, type: 'update' }).open();
|
||||
}
|
||||
|
||||
/** 删除客户 */
|
||||
async function handleDelete(row: MesMdClientApi.Client) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteClient(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportClient(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '客户.xls', source: data });
|
||||
}
|
||||
|
||||
/** 导入客户 */
|
||||
function handleImport() {
|
||||
importModalApi.open();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getClientPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdClientApi.Client>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】客户管理、供应商管理"
|
||||
url="https://doc.iocoder.cn/mes/md/client-vendor/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<ImportModal @success="handleRefresh" />
|
||||
|
||||
<Grid table-title="客户列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['客户']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-client:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.import', ['客户']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.UPLOAD,
|
||||
auth: ['mes:md-client:import'],
|
||||
onClick: handleImport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:md-client:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<Button type="link" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</Button>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-client:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-client:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Tabs } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createClient, getClient, updateClient } from '#/api/mes/md/client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import ClientProductSalesLineList from './product-sales-line-list.vue';
|
||||
import ClientProductSalesList from './product-sales-list.vue';
|
||||
|
||||
type FormMode = 'create' | 'detail' | 'update';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formMode = ref<FormMode>('create'); // 表单模式
|
||||
const subTabsName = ref('productSalesLine'); // 当前子表页签
|
||||
const formData = ref<MesMdClientApi.Client>();
|
||||
|
||||
const isDetail = computed(() => formMode.value === 'detail'); // 是否查看模式
|
||||
const getTitle = computed(() => {
|
||||
const titles: Record<FormMode, string> = {
|
||||
create: '新增客户',
|
||||
update: '修改客户',
|
||||
detail: '查看客户',
|
||||
};
|
||||
return titles[formMode.value];
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdClientApi.Client;
|
||||
try {
|
||||
await (formData.value?.id ? updateClient(data) : createClient(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;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
subTabsName.value = 'productSalesLine';
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type?: FormMode }>();
|
||||
formMode.value = data?.type || 'create';
|
||||
formApi.setDisabled(formMode.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formMode.value !== 'detail' });
|
||||
if (!data?.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getClient(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-4/5">
|
||||
<Form class="mx-4" />
|
||||
<Tabs
|
||||
v-if="formMode !== 'create' && formData?.id"
|
||||
v-model:active-key="subTabsName"
|
||||
class="mx-4 mt-4"
|
||||
>
|
||||
<Tabs.TabPane key="productSalesLine" tab="产品清单">
|
||||
<ClientProductSalesLineList :client-id="formData.id" />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="productSales" tab="销售记录">
|
||||
<ClientProductSalesList :client-id="formData.id" />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<script lang="ts" setup>
|
||||
import type { FileType } from 'ant-design-vue/es/upload/interface';
|
||||
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { Button, message, Upload } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { importClient, importClientTemplate } from '#/api/mes/md/client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useImportFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 120,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useImportFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = await formApi.getValues();
|
||||
try {
|
||||
const result = await importClient(data.file, data.updateSupport);
|
||||
const importData = result as MesMdClientApi.ClientImportRespVO;
|
||||
let text = `上传成功数量:${importData.createCodes?.length || 0};`;
|
||||
for (const code of importData.createCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新成功数量:${importData.updateCodes?.length || 0};`;
|
||||
for (const code of importData.updateCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新失败数量:${Object.keys(importData.failureCodes || {}).length};`;
|
||||
for (const code in importData.failureCodes || {}) {
|
||||
text += `< ${code}: ${importData.failureCodes?.[code]} >`;
|
||||
}
|
||||
message.info(text);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 上传前 */
|
||||
function beforeUpload(file: FileType) {
|
||||
formApi.setFieldValue('file', file);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 下载模板 */
|
||||
async function handleDownload() {
|
||||
const data = await importClientTemplate();
|
||||
downloadFileFromBlobPart({ fileName: '客户导入模板.xls', source: data });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="$t('ui.actionTitle.import', ['客户'])" class="w-1/3">
|
||||
<Form class="mx-4">
|
||||
<template #file>
|
||||
<div class="w-full">
|
||||
<Upload
|
||||
:before-upload="beforeUpload"
|
||||
:max-count="1"
|
||||
accept=".xls,.xlsx"
|
||||
>
|
||||
<Button type="primary">选择 Excel 文件</Button>
|
||||
</Upload>
|
||||
</div>
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<Button @click="handleDownload">下载导入模板</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmProductSalesLineApi } from '#/api/mes/wm/productsales/line';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSalesLinePage } from '#/api/mes/wm/productsales/line';
|
||||
import ItemForm from '#/views/mes/md/item/modules/form.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
clientId: number;
|
||||
}>();
|
||||
|
||||
const [ItemFormModal, itemFormModalApi] = useVbenModal({
|
||||
connectedComponent: ItemForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 查看物料详情 */
|
||||
function handleViewItem(row: MesWmProductSalesLineApi.ProductSalesLine) {
|
||||
itemFormModalApi.setData({ id: row.itemId, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{
|
||||
field: 'itemCode',
|
||||
title: '物料编码',
|
||||
width: 140,
|
||||
slots: { default: 'itemCode' },
|
||||
},
|
||||
{ field: 'itemName', title: '物料名称', minWidth: 150 },
|
||||
{ field: 'specification', title: '规格型号', minWidth: 140 },
|
||||
{ field: 'unitMeasureName', title: '单位', width: 100 },
|
||||
{ field: 'quantity', title: '出库数量', width: 120 },
|
||||
{ field: 'batchCode', title: '批次号', minWidth: 140 },
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getProductSalesLinePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
clientId: props.clientId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmProductSalesLineApi.ProductSalesLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ItemFormModal />
|
||||
<Grid table-title="产品清单">
|
||||
<template #itemCode="{ row }">
|
||||
<Button type="link" @click="handleViewItem(row)">
|
||||
{{ row.itemCode }}
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmProductSalesApi } from '#/api/mes/wm/productsales';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSalesPage } from '#/api/mes/wm/productsales';
|
||||
|
||||
const props = defineProps<{
|
||||
clientId: number;
|
||||
}>();
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{ field: 'code', title: '出库单编号', minWidth: 160 },
|
||||
{ field: 'name', title: '出库单名称', minWidth: 150 },
|
||||
{ field: 'salesOrderCode', title: '销售订单编号', minWidth: 140 },
|
||||
{
|
||||
field: 'salesDate',
|
||||
title: '出库日期',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '单据状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_WM_PRODUCT_SALES_STATUS },
|
||||
},
|
||||
},
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getProductSalesPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
clientId: props.clientId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmProductSalesApi.ProductSales>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid table-title="销售记录" />
|
||||
</template>
|
||||
176
apps/web-antd/src/views/mes/md/vendor/components/md-vendor-select-dialog.vue
vendored
Normal file
176
apps/web-antd/src/views/mes/md/vendor/components/md-vendor-select-dialog.vue
vendored
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import { CommonStatusEnum } from '@vben/constants';
|
||||
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getVendorPage } from '#/api/mes/md/vendor';
|
||||
|
||||
import {
|
||||
useVendorSelectGridColumns,
|
||||
useVendorSelectGridFormSchema,
|
||||
} from '../data';
|
||||
|
||||
const emit = defineEmits<{
|
||||
selected: [rows: MesMdVendorApi.Vendor[]];
|
||||
}>();
|
||||
|
||||
const open = ref(false); // 弹窗是否打开
|
||||
const multiple = ref(true); // 是否多选
|
||||
const syncingSingleSelection = ref(false); // 是否同步单选勾选状态
|
||||
const selectedRows = ref<MesMdVendorApi.Vendor[]>([]); // 已选供应商列表
|
||||
const preSelectedIds = ref<number[]>([]); // 预选供应商编号列表
|
||||
|
||||
/** 单选模式下同步 VXE 勾选状态,避免跨页残留多选 */
|
||||
async function syncSingleSelection(row?: MesMdVendorApi.Vendor) {
|
||||
syncingSingleSelection.value = true;
|
||||
await nextTick();
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
if (row) {
|
||||
await gridApi.grid.setCheckboxRow(row, true);
|
||||
}
|
||||
await nextTick();
|
||||
syncingSingleSelection.value = false;
|
||||
}
|
||||
|
||||
/** 处理勾选变化,单选模式只保留最后一条 */
|
||||
async function handleCheckboxChange({
|
||||
checked,
|
||||
records,
|
||||
row,
|
||||
}: {
|
||||
checked: boolean;
|
||||
records: MesMdVendorApi.Vendor[];
|
||||
row?: MesMdVendorApi.Vendor;
|
||||
}) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
if (!multiple.value) {
|
||||
const selected = checked && row ? [row] : [];
|
||||
selectedRows.value = selected;
|
||||
await syncSingleSelection(selected[0]);
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 处理全选变化 */
|
||||
function handleCheckboxAll({ records }: { records: MesMdVendorApi.Vendor[] }) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 回显预选供应商 */
|
||||
function applyPreSelection() {
|
||||
if (preSelectedIds.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
const rows = gridApi.grid.getData() as MesMdVendorApi.Vendor[];
|
||||
for (const row of rows) {
|
||||
if (row.id && preSelectedIds.value.includes(row.id)) {
|
||||
gridApi.grid.setCheckboxRow(row, true);
|
||||
if (!multiple.value) {
|
||||
selectedRows.value = [row];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useVendorSelectGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useVendorSelectGridColumns(),
|
||||
height: 520,
|
||||
keepSource: true,
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
range: true,
|
||||
reserve: true,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getVendorPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdVendorApi.Vendor>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleCheckboxAll,
|
||||
checkboxChange: handleCheckboxChange,
|
||||
},
|
||||
});
|
||||
|
||||
/** 重置查询和选择状态 */
|
||||
async function resetQueryState() {
|
||||
selectedRows.value = [];
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
await gridApi.formApi.resetForm();
|
||||
}
|
||||
|
||||
/** 打开供应商选择弹窗 */
|
||||
async function openModal(selectedIds?: number[], options?: { multiple?: boolean }) {
|
||||
open.value = true;
|
||||
multiple.value = options?.multiple ?? true;
|
||||
preSelectedIds.value = selectedIds || [];
|
||||
await nextTick();
|
||||
await resetQueryState();
|
||||
await gridApi.query();
|
||||
await nextTick();
|
||||
applyPreSelection();
|
||||
}
|
||||
|
||||
/** 关闭供应商选择弹窗 */
|
||||
async function closeModal() {
|
||||
open.value = false;
|
||||
await resetQueryState();
|
||||
}
|
||||
|
||||
/** 确认选择供应商 */
|
||||
function handleConfirm() {
|
||||
if (selectedRows.value.length === 0) {
|
||||
message.warning(multiple.value ? '请至少选择一条数据' : '请选择一条数据');
|
||||
return;
|
||||
}
|
||||
emit('selected', multiple.value ? selectedRows.value : [selectedRows.value[0]!]);
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
defineExpose({ open: openModal });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="open"
|
||||
title="供应商选择"
|
||||
width="70%"
|
||||
:destroy-on-close="true"
|
||||
@ok="handleConfirm"
|
||||
@cancel="closeModal"
|
||||
>
|
||||
<Grid table-title="供应商列表" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { computed, ref, useAttrs, watch } from 'vue';
|
||||
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Input, Tooltip } from 'ant-design-vue';
|
||||
|
||||
import { getVendor } from '#/api/mes/md/vendor';
|
||||
|
||||
import MdVendorSelectDialog from './md-vendor-select-dialog.vue';
|
||||
|
||||
defineOptions({ name: 'MdVendorSelect', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
allowClear?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
allowClear: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择供应商',
|
||||
},
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
change: [item: MesMdVendorApi.Vendor | undefined];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
const attrs = useAttrs(); // 透传属性
|
||||
const dialogRef = ref<InstanceType<typeof MdVendorSelectDialog>>(); // 供应商选择弹窗
|
||||
const hovering = ref(false); // 是否悬停
|
||||
const selectedItem = ref<MesMdVendorApi.Vendor>(); // 当前选中供应商
|
||||
|
||||
const displayLabel = computed(() => selectedItem.value?.name ?? ''); // 选择器展示名称
|
||||
const showClear = computed( // 是否显示清空图标
|
||||
() => props.allowClear && !props.disabled && hovering.value && props.modelValue != null,
|
||||
);
|
||||
|
||||
/** 根据供应商编号回显选择器 */
|
||||
async function resolveItemById(id: number | undefined) {
|
||||
if (id == null) {
|
||||
selectedItem.value = undefined;
|
||||
return;
|
||||
}
|
||||
if (selectedItem.value?.id === id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
selectedItem.value = await getVendor(id);
|
||||
} catch (error) {
|
||||
console.error('[MdVendorSelect] resolveItemById failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
resolveItemById(value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** 清空已选供应商 */
|
||||
function clearSelected() {
|
||||
selectedItem.value = undefined;
|
||||
emit('update:modelValue', undefined);
|
||||
emit('change', undefined);
|
||||
}
|
||||
|
||||
/** 打开供应商选择弹窗 */
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (props.disabled) {
|
||||
return;
|
||||
}
|
||||
const target = event.target as HTMLElement;
|
||||
if (showClear.value && target.closest('.ant-input-suffix')) {
|
||||
event.stopPropagation();
|
||||
clearSelected();
|
||||
return;
|
||||
}
|
||||
const selectedIds = props.modelValue == null ? [] : [props.modelValue];
|
||||
dialogRef.value?.open(selectedIds, { multiple: false });
|
||||
}
|
||||
|
||||
/** 回填选中的供应商 */
|
||||
function handleSelected(rows: MesMdVendorApi.Vendor[]) {
|
||||
const item = rows[0];
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
selectedItem.value = item;
|
||||
emit('update:modelValue', item.id);
|
||||
emit('change', item);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
class="w-full"
|
||||
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
||||
@click="handleClick"
|
||||
@mouseenter="hovering = true"
|
||||
@mouseleave="hovering = false"
|
||||
>
|
||||
<Tooltip :mouse-enter-delay="0.5" :open="selectedItem ? undefined : false">
|
||||
<template #title>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>简称:{{ selectedItem.nickname || '-' }}</div>
|
||||
<div>电话:{{ selectedItem.telephone || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<Input
|
||||
:disabled="disabled"
|
||||
:placeholder="placeholder"
|
||||
:value="displayLabel"
|
||||
readonly
|
||||
>
|
||||
<template #suffix>
|
||||
<IconifyIcon
|
||||
class="size-4"
|
||||
:icon="showClear ? 'lucide:circle-x' : 'lucide:search'"
|
||||
/>
|
||||
</template>
|
||||
</Input>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<MdVendorSelectDialog ref="dialogRef" @selected="handleSelected" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,473 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改供应商的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '供应商编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商编码',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['id'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.id,
|
||||
}),
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
Button,
|
||||
{
|
||||
type: 'default',
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_VENDOR_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '供应商名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商名称',
|
||||
},
|
||||
rules: z.string().min(1, '供应商名称不能为空').max(100),
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '供应商简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商英文名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'level',
|
||||
label: '供应商等级',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_VENDOR_LEVEL),
|
||||
placeholder: '请选择供应商等级',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'description',
|
||||
label: '供应商简介',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商简介',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'address',
|
||||
label: '供应商地址',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商地址',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'website',
|
||||
label: '官网地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商官网地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'email',
|
||||
label: '邮箱地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商邮箱地址',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'telephone',
|
||||
label: '供应商电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'score',
|
||||
label: '供应商评分',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
max: 100,
|
||||
min: 0,
|
||||
precision: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Name',
|
||||
label: '联系人1',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Telephone',
|
||||
label: '联系人1电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Email',
|
||||
label: '联系人1邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1邮箱',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Name',
|
||||
label: '联系人2',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Telephone',
|
||||
label: '联系人2电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Email',
|
||||
label: '联系人2邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2邮箱',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'creditCode',
|
||||
label: '社会信用代码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入统一社会信用代码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'logo',
|
||||
label: '供应商 LOGO',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商 LOGO 地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 导入供应商的表单 */
|
||||
export function useImportFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'file',
|
||||
label: '供应商数据',
|
||||
component: 'Upload',
|
||||
rules: 'required',
|
||||
help: '仅允许导入 xls、xlsx 格式文件',
|
||||
},
|
||||
{
|
||||
fieldName: 'updateSupport',
|
||||
label: '是否覆盖',
|
||||
component: 'Switch',
|
||||
componentProps: {
|
||||
checkedChildren: '是',
|
||||
unCheckedChildren: '否',
|
||||
},
|
||||
rules: z.boolean().default(false),
|
||||
help: '是否更新已经存在的供应商数据',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '供应商编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入供应商编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '供应商名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入供应商名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '供应商简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入供应商简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入英文名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdVendorApi.Vendor>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '供应商编码',
|
||||
minWidth: 150,
|
||||
slots: { default: 'code' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '供应商名称',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '供应商简称',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'level',
|
||||
title: '供应商等级',
|
||||
width: 130,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_VENDOR_LEVEL },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'score',
|
||||
title: '供应商评分',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '供应商电话',
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 供应商选择弹窗的搜索表单 */
|
||||
export function useVendorSelectGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '供应商编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入供应商编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '供应商名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入供应商名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '供应商简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入供应商简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入英文名称',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 供应商选择弹窗的字段 */
|
||||
export function useVendorSelectGridColumns(): VxeTableGridOptions<MesMdVendorApi.Vendor>['columns'] {
|
||||
return [
|
||||
{ type: 'checkbox', width: 50 },
|
||||
{
|
||||
field: 'code',
|
||||
title: '供应商编码',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '供应商名称',
|
||||
minWidth: 170,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '供应商简称',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'level',
|
||||
title: '供应商等级',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_VENDOR_LEVEL },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'score',
|
||||
title: '供应商评分',
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '联系电话',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 140,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteVendor, exportVendor, getVendorPage } from '#/api/mes/md/vendor';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
import ImportForm from './modules/import-form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [ImportModal, importModalApi] = useVbenModal({
|
||||
connectedComponent: ImportForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建供应商 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看供应商 */
|
||||
function handleDetail(row: MesMdVendorApi.Vendor) {
|
||||
formModalApi.setData({ id: row.id, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
/** 编辑供应商 */
|
||||
function handleEdit(row: MesMdVendorApi.Vendor) {
|
||||
formModalApi.setData({ id: row.id, type: 'update' }).open();
|
||||
}
|
||||
|
||||
/** 删除供应商 */
|
||||
async function handleDelete(row: MesMdVendorApi.Vendor) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteVendor(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportVendor(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '供应商.xls', source: data });
|
||||
}
|
||||
|
||||
/** 导入供应商 */
|
||||
function handleImport() {
|
||||
importModalApi.open();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getVendorPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdVendorApi.Vendor>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】客户管理、供应商管理"
|
||||
url="https://doc.iocoder.cn/mes/md/client-vendor/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<ImportModal @success="handleRefresh" />
|
||||
|
||||
<Grid table-title="供应商列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['供应商']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-vendor:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.import', ['供应商']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.UPLOAD,
|
||||
auth: ['mes:md-vendor:import'],
|
||||
onClick: handleImport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:md-vendor:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<Button type="link" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</Button>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-vendor:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-vendor:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Tabs } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createVendor, getVendor, updateVendor } from '#/api/mes/md/vendor';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import VendorItemReceiptLineList from './item-receipt-line-list.vue';
|
||||
import VendorItemReceiptList from './item-receipt-list.vue';
|
||||
|
||||
type FormMode = 'create' | 'detail' | 'update';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formMode = ref<FormMode>('create'); // 表单模式
|
||||
const subTabsName = ref('itemReceiptLine'); // 当前子表页签
|
||||
const formData = ref<MesMdVendorApi.Vendor>();
|
||||
|
||||
const isDetail = computed(() => formMode.value === 'detail'); // 是否查看模式
|
||||
const getTitle = computed(() => {
|
||||
const titles: Record<FormMode, string> = {
|
||||
create: '新增供应商',
|
||||
update: '修改供应商',
|
||||
detail: '查看供应商',
|
||||
};
|
||||
return titles[formMode.value];
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdVendorApi.Vendor;
|
||||
try {
|
||||
await (formData.value?.id ? updateVendor(data) : createVendor(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;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
subTabsName.value = 'itemReceiptLine';
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type?: FormMode }>();
|
||||
formMode.value = data?.type || 'create';
|
||||
formApi.setDisabled(formMode.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formMode.value !== 'detail' });
|
||||
if (!data?.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getVendor(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-4/5">
|
||||
<Form class="mx-4" />
|
||||
<Tabs
|
||||
v-if="formMode !== 'create' && formData?.id"
|
||||
v-model:active-key="subTabsName"
|
||||
class="mx-4 mt-4"
|
||||
>
|
||||
<Tabs.TabPane key="itemReceiptLine" tab="物料清单">
|
||||
<VendorItemReceiptLineList :vendor-id="formData.id" />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="itemReceipt" tab="采购记录">
|
||||
<VendorItemReceiptList :vendor-id="formData.id" />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<script lang="ts" setup>
|
||||
import type { FileType } from 'ant-design-vue/es/upload/interface';
|
||||
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { Button, message, Upload } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { importVendor, importVendorTemplate } from '#/api/mes/md/vendor';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useImportFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 120,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useImportFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = await formApi.getValues();
|
||||
try {
|
||||
const result = await importVendor(data.file, data.updateSupport);
|
||||
const importData = result as MesMdVendorApi.VendorImportRespVO;
|
||||
let text = `上传成功数量:${importData.createCodes?.length || 0};`;
|
||||
for (const code of importData.createCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新成功数量:${importData.updateCodes?.length || 0};`;
|
||||
for (const code of importData.updateCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新失败数量:${Object.keys(importData.failureCodes || {}).length};`;
|
||||
for (const code in importData.failureCodes || {}) {
|
||||
text += `< ${code}: ${importData.failureCodes?.[code]} >`;
|
||||
}
|
||||
message.info(text);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 上传前 */
|
||||
function beforeUpload(file: FileType) {
|
||||
formApi.setFieldValue('file', file);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 下载模板 */
|
||||
async function handleDownload() {
|
||||
const data = await importVendorTemplate();
|
||||
downloadFileFromBlobPart({ fileName: '供应商导入模板.xls', source: data });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="$t('ui.actionTitle.import', ['供应商'])" class="w-1/3">
|
||||
<Form class="mx-4">
|
||||
<template #file>
|
||||
<div class="w-full">
|
||||
<Upload
|
||||
:before-upload="beforeUpload"
|
||||
:max-count="1"
|
||||
accept=".xls,.xlsx"
|
||||
>
|
||||
<Button type="primary">选择 Excel 文件</Button>
|
||||
</Upload>
|
||||
</div>
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<Button @click="handleDownload">下载导入模板</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmItemReceiptLineApi } from '#/api/mes/wm/itemreceipt/line';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getItemReceiptLinePage } from '#/api/mes/wm/itemreceipt/line';
|
||||
import ItemForm from '#/views/mes/md/item/modules/form.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
vendorId: number;
|
||||
}>();
|
||||
|
||||
const [ItemFormModal, itemFormModalApi] = useVbenModal({
|
||||
connectedComponent: ItemForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 查看物料详情 */
|
||||
function handleViewItem(row: MesWmItemReceiptLineApi.ItemReceiptLine) {
|
||||
itemFormModalApi.setData({ id: row.itemId, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{
|
||||
field: 'itemCode',
|
||||
title: '物料编码',
|
||||
width: 140,
|
||||
slots: { default: 'itemCode' },
|
||||
},
|
||||
{ field: 'itemName', title: '物料名称', minWidth: 150 },
|
||||
{ field: 'specification', title: '规格型号', minWidth: 140 },
|
||||
{ field: 'unitMeasureName', title: '单位', width: 100 },
|
||||
{ field: 'receivedQuantity', title: '入库数量', width: 120 },
|
||||
{ field: 'batchCode', title: '批次号', minWidth: 140 },
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getItemReceiptLinePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
vendorId: props.vendorId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmItemReceiptLineApi.ItemReceiptLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ItemFormModal />
|
||||
<Grid table-title="物料清单">
|
||||
<template #itemCode="{ row }">
|
||||
<Button type="link" @click="handleViewItem(row)">
|
||||
{{ row.itemCode }}
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmItemReceiptLineApi } from '#/api/mes/wm/itemreceipt/line';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getItemReceiptLinePage } from '#/api/mes/wm/itemreceipt/line';
|
||||
|
||||
const props = defineProps<{
|
||||
vendorId: number;
|
||||
}>();
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{ field: 'receiptCode', title: '入库单编号', minWidth: 160 },
|
||||
{ field: 'purchaseOrderCode', title: '采购订单号', minWidth: 150 },
|
||||
{ field: 'itemCode', title: '物料编码', width: 140 },
|
||||
{ field: 'itemName', title: '物料名称', minWidth: 150 },
|
||||
{ field: 'specification', title: '规格型号', minWidth: 140 },
|
||||
{ field: 'unitMeasureName', title: '单位', width: 100 },
|
||||
{ field: 'receivedQuantity', title: '入库数量', width: 120 },
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getItemReceiptLinePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
vendorId: props.vendorId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmItemReceiptLineApi.ItemReceiptLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid table-title="采购记录" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdWorkshopApi } from '#/api/mes/md/workstation/workshop';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改车间的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '车间编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入车间编码',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['id'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.id,
|
||||
}),
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
Button,
|
||||
{
|
||||
type: 'default',
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_WORKSHOP_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '车间名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入车间名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'area',
|
||||
label: '面积',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'chargeUserId',
|
||||
label: '负责人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
api: getSimpleUserList,
|
||||
labelField: 'nickname',
|
||||
placeholder: '请选择负责人',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-2',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '车间编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入车间编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '车间名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入车间名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdWorkshopApi.Workshop>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '车间编码',
|
||||
minWidth: 150,
|
||||
slots: { default: 'code' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '车间名称',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'area',
|
||||
title: '面积',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'chargeUserName',
|
||||
title: '负责人',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdWorkshopApi } from '#/api/mes/md/workstation/workshop';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteWorkshop,
|
||||
getWorkshopPage,
|
||||
} from '#/api/mes/md/workstation/workshop';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建车间 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看车间 */
|
||||
function handleDetail(row: MesMdWorkshopApi.Workshop) {
|
||||
formModalApi.setData({ id: row.id, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
/** 编辑车间 */
|
||||
function handleEdit(row: MesMdWorkshopApi.Workshop) {
|
||||
formModalApi.setData({ id: row.id, type: 'update' }).open();
|
||||
}
|
||||
|
||||
/** 删除车间 */
|
||||
async function handleDelete(row: MesMdWorkshopApi.Workshop) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteWorkshop(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getWorkshopPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdWorkshopApi.Workshop>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】车间设置、工作站设置"
|
||||
url="https://doc.iocoder.cn/mes/md/workshop/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="车间列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['车间']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-workshop:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<Button type="link" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</Button>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-workshop:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-workshop:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdWorkshopApi } from '#/api/mes/md/workstation/workshop';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createWorkshop,
|
||||
getWorkshop,
|
||||
updateWorkshop,
|
||||
} from '#/api/mes/md/workstation/workshop';
|
||||
import { $t } from '#/locales';
|
||||
import { BarcodeBizTypeEnum } from '#/views/mes/utils/constants';
|
||||
import { BarcodeDetail } from '#/views/mes/wm/barcode/components';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
type FormMode = 'create' | 'detail' | 'update';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formMode = ref<FormMode>('create'); // 表单模式
|
||||
const formData = ref<MesMdWorkshopApi.Workshop>();
|
||||
const barcodeDetailRef = ref<InstanceType<typeof BarcodeDetail>>(); // 条码详情弹窗
|
||||
|
||||
const isDetail = computed(() => formMode.value === 'detail'); // 是否查看模式
|
||||
const getTitle = computed(() => {
|
||||
const titles: Record<FormMode, string> = {
|
||||
create: '新增车间',
|
||||
update: '修改车间',
|
||||
detail: '查看车间',
|
||||
};
|
||||
return titles[formMode.value];
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 100,
|
||||
},
|
||||
wrapperClass: 'grid-cols-2',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
/** 查看车间条码 */
|
||||
function handleBarcode() {
|
||||
if (!formData.value?.id) {
|
||||
return;
|
||||
}
|
||||
barcodeDetailRef.value?.openByBusiness(
|
||||
formData.value.id,
|
||||
BarcodeBizTypeEnum.WORKSHOP,
|
||||
formData.value.code,
|
||||
formData.value.name,
|
||||
);
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdWorkshopApi.Workshop;
|
||||
try {
|
||||
await (formData.value?.id ? updateWorkshop(data) : createWorkshop(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;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type?: FormMode }>();
|
||||
formMode.value = data?.type || 'create';
|
||||
formApi.setDisabled(formMode.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formMode.value !== 'detail' });
|
||||
if (!data?.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getWorkshop(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/2">
|
||||
<Form class="mx-4" />
|
||||
<template v-if="isDetail && formData?.id" #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<Button @click="handleBarcode">查看条码</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
<BarcodeDetail ref="barcodeDetailRef" />
|
||||
</template>
|
||||
|
|
@ -12,8 +12,11 @@ export const MesItemOrProductEnum = {
|
|||
|
||||
/** MES 自动编码规则 Code 枚举 */
|
||||
export const MesAutoCodeRuleCode = {
|
||||
MD_CLIENT_CODE: 'MD_CLIENT_CODE',
|
||||
MD_ITEM_TYPE_CODE: 'MD_ITEM_TYPE_CODE',
|
||||
MD_ITEM_CODE: 'MD_ITEM_CODE',
|
||||
MD_VENDOR_CODE: 'MD_VENDOR_CODE',
|
||||
MD_WORKSHOP_CODE: 'MD_WORKSHOP_CODE',
|
||||
} as const;
|
||||
|
||||
/** MES 条码格式枚举 */
|
||||
|
|
|
|||
|
|
@ -195,7 +195,9 @@ export const ThingModelFormRules: Record<string, FormItemRule[]> = {
|
|||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
accessMode: [{ required: true, message: '请选择读写类型', trigger: 'change' }],
|
||||
accessMode: [
|
||||
{ required: true, message: '请选择读写类型', trigger: 'change' },
|
||||
],
|
||||
callType: [{ required: true, message: '请选择调用方式', trigger: 'change' }],
|
||||
eventType: [{ required: true, message: '请选择事件类型', trigger: 'change' }],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdClientApi {
|
||||
/** MES 客户 */
|
||||
export interface Client {
|
||||
id?: number; // 客户编号
|
||||
code?: string; // 客户编码
|
||||
name?: string; // 客户名称
|
||||
nickname?: string; // 客户简称
|
||||
englishName?: string; // 客户英文名称
|
||||
description?: string; // 客户简介
|
||||
logo?: string; // 客户 LOGO 地址
|
||||
type?: number; // 客户类型
|
||||
address?: string; // 客户地址
|
||||
website?: string; // 客户官网地址
|
||||
email?: string; // 客户邮箱地址
|
||||
telephone?: string; // 客户电话
|
||||
contact1Name?: string; // 联系人1
|
||||
contact1Telephone?: string; // 联系人1电话
|
||||
contact1Email?: string; // 联系人1邮箱
|
||||
contact2Name?: string; // 联系人2
|
||||
contact2Telephone?: string; // 联系人2电话
|
||||
contact2Email?: string; // 联系人2邮箱
|
||||
creditCode?: string; // 统一社会信用代码
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
|
||||
/** 客户导入结果 */
|
||||
export interface ClientImportRespVO {
|
||||
createCodes?: string[]; // 新增成功的客户编码
|
||||
updateCodes?: string[]; // 更新成功的客户编码
|
||||
failureCodes?: Record<string, string>; // 导入失败的客户编码及原因
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询客户分页 */
|
||||
export function getClientPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesMdClientApi.Client>>(
|
||||
'/mes/md-client/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询客户详情 */
|
||||
export function getClient(id: number) {
|
||||
return requestClient.get<MesMdClientApi.Client>(
|
||||
`/mes/md-client/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增客户 */
|
||||
export function createClient(data: MesMdClientApi.Client) {
|
||||
return requestClient.post('/mes/md-client/create', data);
|
||||
}
|
||||
|
||||
/** 修改客户 */
|
||||
export function updateClient(data: MesMdClientApi.Client) {
|
||||
return requestClient.put('/mes/md-client/update', data);
|
||||
}
|
||||
|
||||
/** 删除客户 */
|
||||
export function deleteClient(id: number) {
|
||||
return requestClient.delete(`/mes/md-client/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出客户 */
|
||||
export function exportClient(params: any) {
|
||||
return requestClient.download('/mes/md-client/export-excel', { params });
|
||||
}
|
||||
|
||||
/** 下载客户导入模板 */
|
||||
export function importClientTemplate() {
|
||||
return requestClient.download('/mes/md-client/get-import-template');
|
||||
}
|
||||
|
||||
/** 导入客户 */
|
||||
export function importClient(file: File, updateSupport: boolean) {
|
||||
return requestClient.upload<MesMdClientApi.ClientImportRespVO>(
|
||||
`/mes/md-client/import?updateSupport=${updateSupport}`,
|
||||
{ file },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdVendorApi {
|
||||
/** MES 供应商 */
|
||||
export interface Vendor {
|
||||
id?: number; // 供应商编号
|
||||
code?: string; // 供应商编码
|
||||
name?: string; // 供应商名称
|
||||
nickname?: string; // 供应商简称
|
||||
englishName?: string; // 供应商英文名称
|
||||
description?: string; // 供应商简介
|
||||
logo?: string; // 供应商 LOGO 地址
|
||||
level?: string; // 供应商等级
|
||||
score?: number; // 供应商评分
|
||||
address?: string; // 供应商地址
|
||||
website?: string; // 供应商官网地址
|
||||
email?: string; // 供应商邮箱地址
|
||||
telephone?: string; // 供应商电话
|
||||
contact1Name?: string; // 联系人1
|
||||
contact1Telephone?: string; // 联系人1电话
|
||||
contact1Email?: string; // 联系人1邮箱
|
||||
contact2Name?: string; // 联系人2
|
||||
contact2Telephone?: string; // 联系人2电话
|
||||
contact2Email?: string; // 联系人2邮箱
|
||||
creditCode?: string; // 统一社会信用代码
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
|
||||
/** 供应商导入结果 */
|
||||
export interface VendorImportRespVO {
|
||||
createCodes?: string[]; // 新增成功的供应商编码
|
||||
updateCodes?: string[]; // 更新成功的供应商编码
|
||||
failureCodes?: Record<string, string>; // 导入失败的供应商编码及原因
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询供应商分页 */
|
||||
export function getVendorPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesMdVendorApi.Vendor>>(
|
||||
'/mes/md-vendor/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询供应商详情 */
|
||||
export function getVendor(id: number) {
|
||||
return requestClient.get<MesMdVendorApi.Vendor>(
|
||||
`/mes/md-vendor/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增供应商 */
|
||||
export function createVendor(data: MesMdVendorApi.Vendor) {
|
||||
return requestClient.post('/mes/md-vendor/create', data);
|
||||
}
|
||||
|
||||
/** 修改供应商 */
|
||||
export function updateVendor(data: MesMdVendorApi.Vendor) {
|
||||
return requestClient.put('/mes/md-vendor/update', data);
|
||||
}
|
||||
|
||||
/** 删除供应商 */
|
||||
export function deleteVendor(id: number) {
|
||||
return requestClient.delete(`/mes/md-vendor/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出供应商 */
|
||||
export function exportVendor(params: any) {
|
||||
return requestClient.download('/mes/md-vendor/export-excel', { params });
|
||||
}
|
||||
|
||||
/** 下载供应商导入模板 */
|
||||
export function importVendorTemplate() {
|
||||
return requestClient.download('/mes/md-vendor/get-import-template');
|
||||
}
|
||||
|
||||
/** 导入供应商 */
|
||||
export function importVendor(file: File, updateSupport: boolean) {
|
||||
return requestClient.upload<MesMdVendorApi.VendorImportRespVO>(
|
||||
`/mes/md-vendor/import?updateSupport=${updateSupport}`,
|
||||
{ file },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesMdWorkshopApi {
|
||||
/** MES 车间 */
|
||||
export interface Workshop {
|
||||
id?: number; // 车间编号
|
||||
code?: string; // 车间编码
|
||||
name?: string; // 车间名称
|
||||
area?: number; // 面积
|
||||
chargeUserId?: number; // 负责人用户编号
|
||||
chargeUserName?: string; // 负责人名称
|
||||
status?: number; // 状态
|
||||
remark?: string; // 备注
|
||||
createTime?: Date; // 创建时间
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询车间分页 */
|
||||
export function getWorkshopPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesMdWorkshopApi.Workshop>>(
|
||||
'/mes/md-workshop/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询车间精简列表 */
|
||||
export function getWorkshopSimpleList() {
|
||||
return requestClient.get<MesMdWorkshopApi.Workshop[]>(
|
||||
'/mes/md-workshop/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询车间详情 */
|
||||
export function getWorkshop(id: number) {
|
||||
return requestClient.get<MesMdWorkshopApi.Workshop>(
|
||||
`/mes/md-workshop/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增车间 */
|
||||
export function createWorkshop(data: MesMdWorkshopApi.Workshop) {
|
||||
return requestClient.post('/mes/md-workshop/create', data);
|
||||
}
|
||||
|
||||
/** 修改车间 */
|
||||
export function updateWorkshop(data: MesMdWorkshopApi.Workshop) {
|
||||
return requestClient.put('/mes/md-workshop/update', data);
|
||||
}
|
||||
|
||||
/** 删除车间 */
|
||||
export function deleteWorkshop(id: number) {
|
||||
return requestClient.delete(`/mes/md-workshop/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出车间 */
|
||||
export function exportWorkshop(params: any) {
|
||||
return requestClient.download('/mes/md-workshop/export-excel', { params });
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesWmItemReceiptLineApi {
|
||||
/** MES 物料接收单行 */
|
||||
export interface ItemReceiptLine {
|
||||
id?: number; // 行编号
|
||||
receiptId?: number; // 入库单编号
|
||||
receiptCode?: string; // 入库单编码
|
||||
purchaseOrderCode?: string; // 采购订单号
|
||||
itemId?: number; // 物料编号
|
||||
itemCode?: string; // 物料编码
|
||||
itemName?: string; // 物料名称
|
||||
specification?: string; // 规格型号
|
||||
unitMeasureName?: string; // 单位
|
||||
receivedQuantity?: number; // 入库数量
|
||||
batchCode?: string; // 批次号
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询物料接收单行分页 */
|
||||
export function getItemReceiptLinePage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesWmItemReceiptLineApi.ItemReceiptLine>>(
|
||||
'/mes/wm/item-receipt-line/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesWmProductSalesApi {
|
||||
/** MES 销售出库单 */
|
||||
export interface ProductSales {
|
||||
id?: number; // 销售出库单编号
|
||||
code?: string; // 出库单编号
|
||||
name?: string; // 出库单名称
|
||||
salesOrderCode?: string; // 销售订单编号
|
||||
salesDate?: Date; // 出库日期
|
||||
status?: number; // 单据状态
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询销售出库单分页 */
|
||||
export function getProductSalesPage(params: PageParam) {
|
||||
return requestClient.get<PageResult<MesWmProductSalesApi.ProductSales>>(
|
||||
'/mes/wm/product-sales/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MesWmProductSalesLineApi {
|
||||
/** MES 销售出库单行 */
|
||||
export interface ProductSalesLine {
|
||||
id?: number; // 行编号
|
||||
itemId?: number; // 物料编号
|
||||
itemCode?: string; // 物料编码
|
||||
itemName?: string; // 物料名称
|
||||
specification?: string; // 规格型号
|
||||
unitMeasureName?: string; // 单位
|
||||
quantity?: number; // 出库数量
|
||||
batchCode?: string; // 批次号
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询销售出库单行分页 */
|
||||
export function getProductSalesLinePage(params: PageParam) {
|
||||
return requestClient.get<
|
||||
PageResult<MesWmProductSalesLineApi.ProductSalesLine>
|
||||
>('/mes/wm/product-sales-line/page', { params });
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import { CommonStatusEnum } from '@vben/constants';
|
||||
|
||||
import { ElButton, ElDialog, ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getClientPage } from '#/api/mes/md/client';
|
||||
|
||||
import {
|
||||
useClientSelectGridColumns,
|
||||
useClientSelectGridFormSchema,
|
||||
} from '../data';
|
||||
|
||||
const emit = defineEmits<{
|
||||
selected: [rows: MesMdClientApi.Client[]];
|
||||
}>();
|
||||
|
||||
const open = ref(false); // 弹窗是否打开
|
||||
const multiple = ref(true); // 是否多选
|
||||
const syncingSingleSelection = ref(false); // 是否同步单选勾选状态
|
||||
const selectedRows = ref<MesMdClientApi.Client[]>([]); // 已选客户列表
|
||||
const preSelectedIds = ref<number[]>([]); // 预选客户编号列表
|
||||
|
||||
/** 单选模式下同步 VXE 勾选状态,避免跨页残留多选 */
|
||||
async function syncSingleSelection(row?: MesMdClientApi.Client) {
|
||||
syncingSingleSelection.value = true;
|
||||
await nextTick();
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
if (row) {
|
||||
await gridApi.grid.setCheckboxRow(row, true);
|
||||
}
|
||||
await nextTick();
|
||||
syncingSingleSelection.value = false;
|
||||
}
|
||||
|
||||
/** 处理勾选变化,单选模式只保留最后一条 */
|
||||
async function handleCheckboxChange({
|
||||
checked,
|
||||
records,
|
||||
row,
|
||||
}: {
|
||||
checked: boolean;
|
||||
records: MesMdClientApi.Client[];
|
||||
row?: MesMdClientApi.Client;
|
||||
}) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
if (!multiple.value) {
|
||||
const selected = checked && row ? [row] : [];
|
||||
selectedRows.value = selected;
|
||||
await syncSingleSelection(selected[0]);
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 处理全选变化 */
|
||||
function handleCheckboxAll({ records }: { records: MesMdClientApi.Client[] }) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 回显预选客户 */
|
||||
function applyPreSelection() {
|
||||
if (preSelectedIds.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
const rows = gridApi.grid.getData() as MesMdClientApi.Client[];
|
||||
for (const row of rows) {
|
||||
if (row.id && preSelectedIds.value.includes(row.id)) {
|
||||
gridApi.grid.setCheckboxRow(row, true);
|
||||
if (!multiple.value) {
|
||||
selectedRows.value = [row];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useClientSelectGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useClientSelectGridColumns(),
|
||||
height: 520,
|
||||
keepSource: true,
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
range: true,
|
||||
reserve: true,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getClientPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdClientApi.Client>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleCheckboxAll,
|
||||
checkboxChange: handleCheckboxChange,
|
||||
},
|
||||
});
|
||||
|
||||
/** 重置查询和选择状态 */
|
||||
async function resetQueryState() {
|
||||
selectedRows.value = [];
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
await gridApi.formApi.resetForm();
|
||||
}
|
||||
|
||||
/** 打开客户选择弹窗 */
|
||||
async function openModal(selectedIds?: number[], options?: { multiple?: boolean }) {
|
||||
open.value = true;
|
||||
multiple.value = options?.multiple ?? true;
|
||||
preSelectedIds.value = selectedIds || [];
|
||||
await nextTick();
|
||||
await resetQueryState();
|
||||
await gridApi.query();
|
||||
await nextTick();
|
||||
applyPreSelection();
|
||||
}
|
||||
|
||||
/** 关闭客户选择弹窗 */
|
||||
async function closeModal() {
|
||||
open.value = false;
|
||||
await resetQueryState();
|
||||
}
|
||||
|
||||
/** 确认选择客户 */
|
||||
function handleConfirm() {
|
||||
if (selectedRows.value.length === 0) {
|
||||
ElMessage.warning(multiple.value ? '请至少选择一条数据' : '请选择一条数据');
|
||||
return;
|
||||
}
|
||||
emit('selected', multiple.value ? selectedRows.value : [selectedRows.value[0]!]);
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
defineExpose({ open: openModal });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ElDialog
|
||||
v-model="open"
|
||||
title="客户选择"
|
||||
width="70%"
|
||||
destroy-on-close
|
||||
@close="closeModal"
|
||||
>
|
||||
<Grid table-title="客户列表" />
|
||||
<template #footer>
|
||||
<ElButton @click="closeModal">取消</ElButton>
|
||||
<ElButton type="primary" @click="handleConfirm">确定</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { computed, ref, useAttrs, watch } from 'vue';
|
||||
|
||||
import { CircleX, Search } from '@vben/icons';
|
||||
|
||||
import { ElInput, ElTooltip } from 'element-plus';
|
||||
|
||||
import { getClient } from '#/api/mes/md/client';
|
||||
|
||||
import MdClientSelectDialog from './md-client-select-dialog.vue';
|
||||
|
||||
defineOptions({ name: 'MdClientSelect', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
clearable?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
clearable: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择客户',
|
||||
},
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
change: [item: MesMdClientApi.Client | undefined];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
const attrs = useAttrs(); // 透传属性
|
||||
const dialogRef = ref<InstanceType<typeof MdClientSelectDialog>>(); // 客户选择弹窗
|
||||
const hovering = ref(false); // 是否悬停
|
||||
const selectedItem = ref<MesMdClientApi.Client>(); // 当前选中客户
|
||||
|
||||
const displayLabel = computed(() => selectedItem.value?.name ?? ''); // 选择器展示名称
|
||||
const showClear = computed( // 是否显示清空图标
|
||||
() => props.clearable && !props.disabled && hovering.value && props.modelValue != null,
|
||||
);
|
||||
|
||||
/** 根据客户编号回显选择器 */
|
||||
async function resolveItemById(id: number | undefined) {
|
||||
if (id == null) {
|
||||
selectedItem.value = undefined;
|
||||
return;
|
||||
}
|
||||
if (selectedItem.value?.id === id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
selectedItem.value = await getClient(id);
|
||||
} catch (error) {
|
||||
console.error('[MdClientSelect] resolveItemById failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
resolveItemById(value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** 清空已选客户 */
|
||||
function clearSelected() {
|
||||
selectedItem.value = undefined;
|
||||
emit('update:modelValue', undefined);
|
||||
emit('change', undefined);
|
||||
}
|
||||
|
||||
/** 打开客户选择弹窗 */
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (props.disabled) {
|
||||
return;
|
||||
}
|
||||
const target = event.target as HTMLElement;
|
||||
if (showClear.value && target.closest('.el-input__suffix')) {
|
||||
event.stopPropagation();
|
||||
clearSelected();
|
||||
return;
|
||||
}
|
||||
const selectedIds = props.modelValue == null ? [] : [props.modelValue];
|
||||
dialogRef.value?.open(selectedIds, { multiple: false });
|
||||
}
|
||||
|
||||
/** 回填选中的客户 */
|
||||
function handleSelected(rows: MesMdClientApi.Client[]) {
|
||||
const item = rows[0];
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
selectedItem.value = item;
|
||||
emit('update:modelValue', item.id);
|
||||
emit('change', item);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
class="w-full"
|
||||
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
||||
@click="handleClick"
|
||||
@mouseenter="hovering = true"
|
||||
@mouseleave="hovering = false"
|
||||
>
|
||||
<ElTooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||
<template #content>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>简称:{{ selectedItem.nickname || '-' }}</div>
|
||||
<div>电话:{{ selectedItem.telephone || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<ElInput
|
||||
:disabled="disabled"
|
||||
:model-value="displayLabel"
|
||||
:placeholder="placeholder"
|
||||
readonly
|
||||
>
|
||||
<template #suffix>
|
||||
<CircleX v-if="showClear" class="size-4" />
|
||||
<Search v-else class="size-4" />
|
||||
</template>
|
||||
</ElInput>
|
||||
</ElTooltip>
|
||||
</div>
|
||||
<MdClientSelectDialog ref="dialogRef" @selected="handleSelected" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,477 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改客户的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '客户编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户编码',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['id'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.id,
|
||||
}),
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_CLIENT_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '客户名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户名称',
|
||||
},
|
||||
rules: z.string().min(1, '客户名称不能为空').max(100),
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '客户简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '客户英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户英文名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '客户类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_CLIENT_TYPE, 'number'),
|
||||
placeholder: '请选择客户类型',
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
fieldName: 'description',
|
||||
label: '客户简介',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户简介',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'address',
|
||||
label: '客户地址',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户地址',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'website',
|
||||
label: '客户官网地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户官网地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'email',
|
||||
label: '客户邮箱地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户邮箱地址',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'telephone',
|
||||
label: '客户电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'logo',
|
||||
label: '客户 LOGO',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入客户 LOGO 地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Name',
|
||||
label: '联系人1',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Telephone',
|
||||
label: '联系人1电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Email',
|
||||
label: '联系人1邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1邮箱',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Name',
|
||||
label: '联系人2',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Telephone',
|
||||
label: '联系人2电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Email',
|
||||
label: '联系人2邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2邮箱',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'creditCode',
|
||||
label: '社会信用代码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入统一社会信用代码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 导入客户的表单 */
|
||||
export function useImportFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'file',
|
||||
label: '客户数据',
|
||||
component: 'Upload',
|
||||
rules: 'required',
|
||||
help: '仅允许导入 xls、xlsx 格式文件',
|
||||
},
|
||||
{
|
||||
fieldName: 'updateSupport',
|
||||
label: '是否覆盖',
|
||||
component: 'Switch',
|
||||
componentProps: {
|
||||
activeText: '是',
|
||||
inactiveText: '否',
|
||||
inlinePrompt: true,
|
||||
},
|
||||
rules: z.boolean().default(false),
|
||||
help: '是否更新已经存在的客户数据',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '客户编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '客户名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '客户简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户英文名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '客户类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_CLIENT_TYPE, 'number'),
|
||||
placeholder: '请选择客户类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdClientApi.Client>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '客户编码',
|
||||
minWidth: 150,
|
||||
slots: { default: 'code' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '客户名称',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '客户简称',
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '客户类型',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_CLIENT_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '客户电话',
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
field: 'contact1Name',
|
||||
title: '联系人1',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'contact1Telephone',
|
||||
title: '联系人1电话',
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 客户选择弹窗的搜索表单 */
|
||||
export function useClientSelectGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '客户编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '客户名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '客户简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入客户英文名称',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 客户选择弹窗的字段 */
|
||||
export function useClientSelectGridColumns(): VxeTableGridOptions<MesMdClientApi.Client>['columns'] {
|
||||
return [
|
||||
{ type: 'checkbox', width: 50 },
|
||||
{
|
||||
field: 'code',
|
||||
title: '客户编码',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '客户名称',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '客户简称',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '客户类型',
|
||||
width: 110,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_CLIENT_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'contact1Name',
|
||||
title: '联系人',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '联系电话',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
field: 'contact1Telephone',
|
||||
title: '联系人电话',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteClient, exportClient, getClientPage } from '#/api/mes/md/client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
import ImportForm from './modules/import-form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [ImportModal, importModalApi] = useVbenModal({
|
||||
connectedComponent: ImportForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建客户 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看客户 */
|
||||
function handleDetail(row: MesMdClientApi.Client) {
|
||||
formModalApi.setData({ id: row.id, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
/** 编辑客户 */
|
||||
function handleEdit(row: MesMdClientApi.Client) {
|
||||
formModalApi.setData({ id: row.id, type: 'update' }).open();
|
||||
}
|
||||
|
||||
/** 删除客户 */
|
||||
async function handleDelete(row: MesMdClientApi.Client) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteClient(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportClient(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '客户.xls', source: data });
|
||||
}
|
||||
|
||||
/** 导入客户 */
|
||||
function handleImport() {
|
||||
importModalApi.open();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getClientPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdClientApi.Client>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】客户管理、供应商管理"
|
||||
url="https://doc.iocoder.cn/mes/md/client-vendor/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<ImportModal @success="handleRefresh" />
|
||||
|
||||
<Grid table-title="客户列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['客户']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-client:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.import', ['客户']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.UPLOAD,
|
||||
auth: ['mes:md-client:import'],
|
||||
onClick: handleImport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:md-client:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<ElButton link type="primary" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</ElButton>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-client:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-client:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createClient, getClient, updateClient } from '#/api/mes/md/client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import ClientProductSalesLineList from './product-sales-line-list.vue';
|
||||
import ClientProductSalesList from './product-sales-list.vue';
|
||||
|
||||
type FormMode = 'create' | 'detail' | 'update';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formMode = ref<FormMode>('create'); // 表单模式
|
||||
const subTabsName = ref('productSalesLine'); // 当前子表页签
|
||||
const formData = ref<MesMdClientApi.Client>();
|
||||
|
||||
const isDetail = computed(() => formMode.value === 'detail'); // 是否查看模式
|
||||
const getTitle = computed(() => {
|
||||
const titles: Record<FormMode, string> = {
|
||||
create: '新增客户',
|
||||
update: '修改客户',
|
||||
detail: '查看客户',
|
||||
};
|
||||
return titles[formMode.value];
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdClientApi.Client;
|
||||
try {
|
||||
await (formData.value?.id ? updateClient(data) : createClient(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
subTabsName.value = 'productSalesLine';
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type?: FormMode }>();
|
||||
formMode.value = data?.type || 'create';
|
||||
formApi.setDisabled(formMode.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formMode.value !== 'detail' });
|
||||
if (!data?.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getClient(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-4/5">
|
||||
<Form class="mx-4" />
|
||||
<ElTabs
|
||||
v-if="formMode !== 'create' && formData?.id"
|
||||
v-model="subTabsName"
|
||||
class="mx-4 mt-4"
|
||||
>
|
||||
<ElTabPane label="产品清单" name="productSalesLine">
|
||||
<ClientProductSalesLineList :client-id="formData.id" />
|
||||
</ElTabPane>
|
||||
<ElTabPane label="销售记录" name="productSales">
|
||||
<ClientProductSalesList :client-id="formData.id" />
|
||||
</ElTabPane>
|
||||
</ElTabs>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdClientApi } from '#/api/mes/md/client';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElButton, ElMessage, ElUpload } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { importClient, importClientTemplate } from '#/api/mes/md/client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useImportFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 120,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useImportFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = await formApi.getValues();
|
||||
try {
|
||||
const result = await importClient(data.file, data.updateSupport);
|
||||
const importData = result as MesMdClientApi.ClientImportRespVO;
|
||||
let text = `上传成功数量:${importData.createCodes?.length || 0};`;
|
||||
for (const code of importData.createCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新成功数量:${importData.updateCodes?.length || 0};`;
|
||||
for (const code of importData.updateCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新失败数量:${Object.keys(importData.failureCodes || {}).length};`;
|
||||
for (const code in importData.failureCodes || {}) {
|
||||
text += `< ${code}: ${importData.failureCodes?.[code]} >`;
|
||||
}
|
||||
ElMessage.info(text);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 文件改变时 */
|
||||
function handleChange(file: any) {
|
||||
if (file.raw) {
|
||||
formApi.setFieldValue('file', file.raw);
|
||||
}
|
||||
}
|
||||
|
||||
/** 下载模板 */
|
||||
async function handleDownload() {
|
||||
const data = await importClientTemplate();
|
||||
downloadFileFromBlobPart({ fileName: '客户导入模板.xls', source: data });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="$t('ui.actionTitle.import', ['客户'])" class="w-1/3">
|
||||
<Form class="mx-4">
|
||||
<template #file>
|
||||
<div class="w-full">
|
||||
<ElUpload
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
:on-change="handleChange"
|
||||
accept=".xls,.xlsx"
|
||||
>
|
||||
<ElButton type="primary">选择 Excel 文件</ElButton>
|
||||
</ElUpload>
|
||||
</div>
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<ElButton @click="handleDownload">下载导入模板</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmProductSalesLineApi } from '#/api/mes/wm/productsales/line';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSalesLinePage } from '#/api/mes/wm/productsales/line';
|
||||
import ItemForm from '#/views/mes/md/item/modules/form.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
clientId: number;
|
||||
}>();
|
||||
|
||||
const [ItemFormModal, itemFormModalApi] = useVbenModal({
|
||||
connectedComponent: ItemForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 查看物料详情 */
|
||||
function handleViewItem(row: MesWmProductSalesLineApi.ProductSalesLine) {
|
||||
itemFormModalApi.setData({ id: row.itemId, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{
|
||||
field: 'itemCode',
|
||||
title: '物料编码',
|
||||
width: 140,
|
||||
slots: { default: 'itemCode' },
|
||||
},
|
||||
{ field: 'itemName', title: '物料名称', minWidth: 150 },
|
||||
{ field: 'specification', title: '规格型号', minWidth: 140 },
|
||||
{ field: 'unitMeasureName', title: '单位', width: 100 },
|
||||
{ field: 'quantity', title: '出库数量', width: 120 },
|
||||
{ field: 'batchCode', title: '批次号', minWidth: 140 },
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getProductSalesLinePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
clientId: props.clientId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmProductSalesLineApi.ProductSalesLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ItemFormModal />
|
||||
<Grid table-title="产品清单">
|
||||
<template #itemCode="{ row }">
|
||||
<ElButton link type="primary" @click="handleViewItem(row)">
|
||||
{{ row.itemCode }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmProductSalesApi } from '#/api/mes/wm/productsales';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductSalesPage } from '#/api/mes/wm/productsales';
|
||||
|
||||
const props = defineProps<{
|
||||
clientId: number;
|
||||
}>();
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{ field: 'code', title: '出库单编号', minWidth: 160 },
|
||||
{ field: 'name', title: '出库单名称', minWidth: 150 },
|
||||
{ field: 'salesOrderCode', title: '销售订单编号', minWidth: 140 },
|
||||
{
|
||||
field: 'salesDate',
|
||||
title: '出库日期',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '单据状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_WM_PRODUCT_SALES_STATUS },
|
||||
},
|
||||
},
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getProductSalesPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
clientId: props.clientId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmProductSalesApi.ProductSales>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid table-title="销售记录" />
|
||||
</template>
|
||||
179
apps/web-ele/src/views/mes/md/vendor/components/md-vendor-select-dialog.vue
vendored
Normal file
179
apps/web-ele/src/views/mes/md/vendor/components/md-vendor-select-dialog.vue
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import { CommonStatusEnum } from '@vben/constants';
|
||||
|
||||
import { ElButton, ElDialog, ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getVendorPage } from '#/api/mes/md/vendor';
|
||||
|
||||
import {
|
||||
useVendorSelectGridColumns,
|
||||
useVendorSelectGridFormSchema,
|
||||
} from '../data';
|
||||
|
||||
const emit = defineEmits<{
|
||||
selected: [rows: MesMdVendorApi.Vendor[]];
|
||||
}>();
|
||||
|
||||
const open = ref(false); // 弹窗是否打开
|
||||
const multiple = ref(true); // 是否多选
|
||||
const syncingSingleSelection = ref(false); // 是否同步单选勾选状态
|
||||
const selectedRows = ref<MesMdVendorApi.Vendor[]>([]); // 已选供应商列表
|
||||
const preSelectedIds = ref<number[]>([]); // 预选供应商编号列表
|
||||
|
||||
/** 单选模式下同步 VXE 勾选状态,避免跨页残留多选 */
|
||||
async function syncSingleSelection(row?: MesMdVendorApi.Vendor) {
|
||||
syncingSingleSelection.value = true;
|
||||
await nextTick();
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
if (row) {
|
||||
await gridApi.grid.setCheckboxRow(row, true);
|
||||
}
|
||||
await nextTick();
|
||||
syncingSingleSelection.value = false;
|
||||
}
|
||||
|
||||
/** 处理勾选变化,单选模式只保留最后一条 */
|
||||
async function handleCheckboxChange({
|
||||
checked,
|
||||
records,
|
||||
row,
|
||||
}: {
|
||||
checked: boolean;
|
||||
records: MesMdVendorApi.Vendor[];
|
||||
row?: MesMdVendorApi.Vendor;
|
||||
}) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
if (!multiple.value) {
|
||||
const selected = checked && row ? [row] : [];
|
||||
selectedRows.value = selected;
|
||||
await syncSingleSelection(selected[0]);
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 处理全选变化 */
|
||||
function handleCheckboxAll({ records }: { records: MesMdVendorApi.Vendor[] }) {
|
||||
if (syncingSingleSelection.value) {
|
||||
return;
|
||||
}
|
||||
selectedRows.value = records;
|
||||
}
|
||||
|
||||
/** 回显预选供应商 */
|
||||
function applyPreSelection() {
|
||||
if (preSelectedIds.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
const rows = gridApi.grid.getData() as MesMdVendorApi.Vendor[];
|
||||
for (const row of rows) {
|
||||
if (row.id && preSelectedIds.value.includes(row.id)) {
|
||||
gridApi.grid.setCheckboxRow(row, true);
|
||||
if (!multiple.value) {
|
||||
selectedRows.value = [row];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useVendorSelectGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useVendorSelectGridColumns(),
|
||||
height: 520,
|
||||
keepSource: true,
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
range: true,
|
||||
reserve: true,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getVendorPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdVendorApi.Vendor>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleCheckboxAll,
|
||||
checkboxChange: handleCheckboxChange,
|
||||
},
|
||||
});
|
||||
|
||||
/** 重置查询和选择状态 */
|
||||
async function resetQueryState() {
|
||||
selectedRows.value = [];
|
||||
await gridApi.grid.clearCheckboxRow();
|
||||
await gridApi.formApi.resetForm();
|
||||
}
|
||||
|
||||
/** 打开供应商选择弹窗 */
|
||||
async function openModal(selectedIds?: number[], options?: { multiple?: boolean }) {
|
||||
open.value = true;
|
||||
multiple.value = options?.multiple ?? true;
|
||||
preSelectedIds.value = selectedIds || [];
|
||||
await nextTick();
|
||||
await resetQueryState();
|
||||
await gridApi.query();
|
||||
await nextTick();
|
||||
applyPreSelection();
|
||||
}
|
||||
|
||||
/** 关闭供应商选择弹窗 */
|
||||
async function closeModal() {
|
||||
open.value = false;
|
||||
await resetQueryState();
|
||||
}
|
||||
|
||||
/** 确认选择供应商 */
|
||||
function handleConfirm() {
|
||||
if (selectedRows.value.length === 0) {
|
||||
ElMessage.warning(multiple.value ? '请至少选择一条数据' : '请选择一条数据');
|
||||
return;
|
||||
}
|
||||
emit('selected', multiple.value ? selectedRows.value : [selectedRows.value[0]!]);
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
defineExpose({ open: openModal });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ElDialog
|
||||
v-model="open"
|
||||
title="供应商选择"
|
||||
width="70%"
|
||||
destroy-on-close
|
||||
@close="closeModal"
|
||||
>
|
||||
<Grid table-title="供应商列表" />
|
||||
<template #footer>
|
||||
<ElButton @click="closeModal">取消</ElButton>
|
||||
<ElButton type="primary" @click="handleConfirm">确定</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { computed, ref, useAttrs, watch } from 'vue';
|
||||
|
||||
import { CircleX, Search } from '@vben/icons';
|
||||
|
||||
import { ElInput, ElTooltip } from 'element-plus';
|
||||
|
||||
import { getVendor } from '#/api/mes/md/vendor';
|
||||
|
||||
import MdVendorSelectDialog from './md-vendor-select-dialog.vue';
|
||||
|
||||
defineOptions({ name: 'MdVendorSelect', inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
clearable?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
clearable: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择供应商',
|
||||
},
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
change: [item: MesMdVendorApi.Vendor | undefined];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
const attrs = useAttrs(); // 透传属性
|
||||
const dialogRef = ref<InstanceType<typeof MdVendorSelectDialog>>(); // 供应商选择弹窗
|
||||
const hovering = ref(false); // 是否悬停
|
||||
const selectedItem = ref<MesMdVendorApi.Vendor>(); // 当前选中供应商
|
||||
|
||||
const displayLabel = computed(() => selectedItem.value?.name ?? ''); // 选择器展示名称
|
||||
const showClear = computed( // 是否显示清空图标
|
||||
() => props.clearable && !props.disabled && hovering.value && props.modelValue != null,
|
||||
);
|
||||
|
||||
/** 根据供应商编号回显选择器 */
|
||||
async function resolveItemById(id: number | undefined) {
|
||||
if (id == null) {
|
||||
selectedItem.value = undefined;
|
||||
return;
|
||||
}
|
||||
if (selectedItem.value?.id === id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
selectedItem.value = await getVendor(id);
|
||||
} catch (error) {
|
||||
console.error('[MdVendorSelect] resolveItemById failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
resolveItemById(value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** 清空已选供应商 */
|
||||
function clearSelected() {
|
||||
selectedItem.value = undefined;
|
||||
emit('update:modelValue', undefined);
|
||||
emit('change', undefined);
|
||||
}
|
||||
|
||||
/** 打开供应商选择弹窗 */
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (props.disabled) {
|
||||
return;
|
||||
}
|
||||
const target = event.target as HTMLElement;
|
||||
if (showClear.value && target.closest('.el-input__suffix')) {
|
||||
event.stopPropagation();
|
||||
clearSelected();
|
||||
return;
|
||||
}
|
||||
const selectedIds = props.modelValue == null ? [] : [props.modelValue];
|
||||
dialogRef.value?.open(selectedIds, { multiple: false });
|
||||
}
|
||||
|
||||
/** 回填选中的供应商 */
|
||||
function handleSelected(rows: MesMdVendorApi.Vendor[]) {
|
||||
const item = rows[0];
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
selectedItem.value = item;
|
||||
emit('update:modelValue', item.id);
|
||||
emit('change', item);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
class="w-full"
|
||||
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
||||
@click="handleClick"
|
||||
@mouseenter="hovering = true"
|
||||
@mouseleave="hovering = false"
|
||||
>
|
||||
<ElTooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||
<template #content>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>简称:{{ selectedItem.nickname || '-' }}</div>
|
||||
<div>电话:{{ selectedItem.telephone || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<ElInput
|
||||
:disabled="disabled"
|
||||
:model-value="displayLabel"
|
||||
:placeholder="placeholder"
|
||||
readonly
|
||||
>
|
||||
<template #suffix>
|
||||
<CircleX v-if="showClear" class="size-4" />
|
||||
<Search v-else class="size-4" />
|
||||
</template>
|
||||
</ElInput>
|
||||
</ElTooltip>
|
||||
</div>
|
||||
<MdVendorSelectDialog ref="dialogRef" @selected="handleSelected" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,472 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改供应商的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '供应商编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商编码',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['id'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.id,
|
||||
}),
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_VENDOR_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '供应商名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商名称',
|
||||
},
|
||||
rules: z.string().min(1, '供应商名称不能为空').max(100),
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '供应商简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商英文名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'level',
|
||||
label: '供应商等级',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.MES_VENDOR_LEVEL),
|
||||
placeholder: '请选择供应商等级',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'description',
|
||||
label: '供应商简介',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商简介',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'address',
|
||||
label: '供应商地址',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商地址',
|
||||
rows: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'website',
|
||||
label: '官网地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商官网地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'email',
|
||||
label: '邮箱地址',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商邮箱地址',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'telephone',
|
||||
label: '供应商电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'score',
|
||||
label: '供应商评分',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
max: 100,
|
||||
min: 0,
|
||||
precision: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Name',
|
||||
label: '联系人1',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Telephone',
|
||||
label: '联系人1电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact1Email',
|
||||
label: '联系人1邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人1邮箱',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Name',
|
||||
label: '联系人2',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Telephone',
|
||||
label: '联系人2电话',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2电话',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'contact2Email',
|
||||
label: '联系人2邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人2邮箱',
|
||||
},
|
||||
rules: z.string().email('邮箱格式不正确').or(z.literal('')).optional(),
|
||||
},
|
||||
{
|
||||
fieldName: 'creditCode',
|
||||
label: '社会信用代码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入统一社会信用代码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'logo',
|
||||
label: '供应商 LOGO',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入供应商 LOGO 地址',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-3',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 导入供应商的表单 */
|
||||
export function useImportFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'file',
|
||||
label: '供应商数据',
|
||||
component: 'Upload',
|
||||
rules: 'required',
|
||||
help: '仅允许导入 xls、xlsx 格式文件',
|
||||
},
|
||||
{
|
||||
fieldName: 'updateSupport',
|
||||
label: '是否覆盖',
|
||||
component: 'Switch',
|
||||
componentProps: {
|
||||
activeText: '是',
|
||||
inactiveText: '否',
|
||||
inlinePrompt: true,
|
||||
},
|
||||
rules: z.boolean().default(false),
|
||||
help: '是否更新已经存在的供应商数据',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '供应商编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '供应商名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '供应商简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入英文名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdVendorApi.Vendor>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '供应商编码',
|
||||
minWidth: 150,
|
||||
slots: { default: 'code' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '供应商名称',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '供应商简称',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'level',
|
||||
title: '供应商等级',
|
||||
width: 130,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_VENDOR_LEVEL },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'score',
|
||||
title: '供应商评分',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '供应商电话',
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 供应商选择弹窗的搜索表单 */
|
||||
export function useVendorSelectGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '供应商编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '供应商名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '供应商简称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入供应商简称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'englishName',
|
||||
label: '英文名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入英文名称',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 供应商选择弹窗的字段 */
|
||||
export function useVendorSelectGridColumns(): VxeTableGridOptions<MesMdVendorApi.Vendor>['columns'] {
|
||||
return [
|
||||
{ type: 'checkbox', width: 50 },
|
||||
{
|
||||
field: 'code',
|
||||
title: '供应商编码',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '供应商名称',
|
||||
minWidth: 170,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '供应商简称',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'level',
|
||||
title: '供应商等级',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MES_VENDOR_LEVEL },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'score',
|
||||
title: '供应商评分',
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
field: 'telephone',
|
||||
title: '联系电话',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 140,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteVendor, exportVendor, getVendorPage } from '#/api/mes/md/vendor';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
import ImportForm from './modules/import-form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [ImportModal, importModalApi] = useVbenModal({
|
||||
connectedComponent: ImportForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建供应商 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看供应商 */
|
||||
function handleDetail(row: MesMdVendorApi.Vendor) {
|
||||
formModalApi.setData({ id: row.id, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
/** 编辑供应商 */
|
||||
function handleEdit(row: MesMdVendorApi.Vendor) {
|
||||
formModalApi.setData({ id: row.id, type: 'update' }).open();
|
||||
}
|
||||
|
||||
/** 删除供应商 */
|
||||
async function handleDelete(row: MesMdVendorApi.Vendor) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteVendor(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportVendor(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '供应商.xls', source: data });
|
||||
}
|
||||
|
||||
/** 导入供应商 */
|
||||
function handleImport() {
|
||||
importModalApi.open();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getVendorPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdVendorApi.Vendor>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】客户管理、供应商管理"
|
||||
url="https://doc.iocoder.cn/mes/md/client-vendor/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<ImportModal @success="handleRefresh" />
|
||||
|
||||
<Grid table-title="供应商列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['供应商']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-vendor:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.import', ['供应商']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.UPLOAD,
|
||||
auth: ['mes:md-vendor:import'],
|
||||
onClick: handleImport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['mes:md-vendor:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<ElButton link type="primary" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</ElButton>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-vendor:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-vendor:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createVendor, getVendor, updateVendor } from '#/api/mes/md/vendor';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import VendorItemReceiptLineList from './item-receipt-line-list.vue';
|
||||
import VendorItemReceiptList from './item-receipt-list.vue';
|
||||
|
||||
type FormMode = 'create' | 'detail' | 'update';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formMode = ref<FormMode>('create'); // 表单模式
|
||||
const subTabsName = ref('itemReceiptLine'); // 当前子表页签
|
||||
const formData = ref<MesMdVendorApi.Vendor>();
|
||||
|
||||
const isDetail = computed(() => formMode.value === 'detail'); // 是否查看模式
|
||||
const getTitle = computed(() => {
|
||||
const titles: Record<FormMode, string> = {
|
||||
create: '新增供应商',
|
||||
update: '修改供应商',
|
||||
detail: '查看供应商',
|
||||
};
|
||||
return titles[formMode.value];
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 120,
|
||||
},
|
||||
wrapperClass: 'grid-cols-3',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdVendorApi.Vendor;
|
||||
try {
|
||||
await (formData.value?.id ? updateVendor(data) : createVendor(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
subTabsName.value = 'itemReceiptLine';
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type?: FormMode }>();
|
||||
formMode.value = data?.type || 'create';
|
||||
formApi.setDisabled(formMode.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formMode.value !== 'detail' });
|
||||
if (!data?.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getVendor(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-4/5">
|
||||
<Form class="mx-4" />
|
||||
<ElTabs
|
||||
v-if="formMode !== 'create' && formData?.id"
|
||||
v-model="subTabsName"
|
||||
class="mx-4 mt-4"
|
||||
>
|
||||
<ElTabPane label="物料清单" name="itemReceiptLine">
|
||||
<VendorItemReceiptLineList :vendor-id="formData.id" />
|
||||
</ElTabPane>
|
||||
<ElTabPane label="采购记录" name="itemReceipt">
|
||||
<VendorItemReceiptList :vendor-id="formData.id" />
|
||||
</ElTabPane>
|
||||
</ElTabs>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdVendorApi } from '#/api/mes/md/vendor';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElButton, ElMessage, ElUpload } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { importVendor, importVendorTemplate } from '#/api/mes/md/vendor';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useImportFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 120,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useImportFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = await formApi.getValues();
|
||||
try {
|
||||
const result = await importVendor(data.file, data.updateSupport);
|
||||
const importData = result as MesMdVendorApi.VendorImportRespVO;
|
||||
let text = `上传成功数量:${importData.createCodes?.length || 0};`;
|
||||
for (const code of importData.createCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新成功数量:${importData.updateCodes?.length || 0};`;
|
||||
for (const code of importData.updateCodes || []) {
|
||||
text += `< ${code} >`;
|
||||
}
|
||||
text += `更新失败数量:${Object.keys(importData.failureCodes || {}).length};`;
|
||||
for (const code in importData.failureCodes || {}) {
|
||||
text += `< ${code}: ${importData.failureCodes?.[code]} >`;
|
||||
}
|
||||
ElMessage.info(text);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 文件改变时 */
|
||||
function handleChange(file: any) {
|
||||
if (file.raw) {
|
||||
formApi.setFieldValue('file', file.raw);
|
||||
}
|
||||
}
|
||||
|
||||
/** 下载模板 */
|
||||
async function handleDownload() {
|
||||
const data = await importVendorTemplate();
|
||||
downloadFileFromBlobPart({ fileName: '供应商导入模板.xls', source: data });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="$t('ui.actionTitle.import', ['供应商'])" class="w-1/3">
|
||||
<Form class="mx-4">
|
||||
<template #file>
|
||||
<div class="w-full">
|
||||
<ElUpload
|
||||
:auto-upload="false"
|
||||
:limit="1"
|
||||
:on-change="handleChange"
|
||||
accept=".xls,.xlsx"
|
||||
>
|
||||
<ElButton type="primary">选择 Excel 文件</ElButton>
|
||||
</ElUpload>
|
||||
</div>
|
||||
</template>
|
||||
</Form>
|
||||
<template #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<ElButton @click="handleDownload">下载导入模板</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmItemReceiptLineApi } from '#/api/mes/wm/itemreceipt/line';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getItemReceiptLinePage } from '#/api/mes/wm/itemreceipt/line';
|
||||
import ItemForm from '#/views/mes/md/item/modules/form.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
vendorId: number;
|
||||
}>();
|
||||
|
||||
const [ItemFormModal, itemFormModalApi] = useVbenModal({
|
||||
connectedComponent: ItemForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 查看物料详情 */
|
||||
function handleViewItem(row: MesWmItemReceiptLineApi.ItemReceiptLine) {
|
||||
itemFormModalApi.setData({ id: row.itemId, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{
|
||||
field: 'itemCode',
|
||||
title: '物料编码',
|
||||
width: 140,
|
||||
slots: { default: 'itemCode' },
|
||||
},
|
||||
{ field: 'itemName', title: '物料名称', minWidth: 150 },
|
||||
{ field: 'specification', title: '规格型号', minWidth: 140 },
|
||||
{ field: 'unitMeasureName', title: '单位', width: 100 },
|
||||
{ field: 'receivedQuantity', title: '入库数量', width: 120 },
|
||||
{ field: 'batchCode', title: '批次号', minWidth: 140 },
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getItemReceiptLinePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
vendorId: props.vendorId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmItemReceiptLineApi.ItemReceiptLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ItemFormModal />
|
||||
<Grid table-title="物料清单">
|
||||
<template #itemCode="{ row }">
|
||||
<ElButton link type="primary" @click="handleViewItem(row)">
|
||||
{{ row.itemCode }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesWmItemReceiptLineApi } from '#/api/mes/wm/itemreceipt/line';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getItemReceiptLinePage } from '#/api/mes/wm/itemreceipt/line';
|
||||
|
||||
const props = defineProps<{
|
||||
vendorId: number;
|
||||
}>();
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{ field: 'receiptCode', title: '入库单编号', minWidth: 160 },
|
||||
{ field: 'purchaseOrderCode', title: '采购订单号', minWidth: 150 },
|
||||
{ field: 'itemCode', title: '物料编码', width: 140 },
|
||||
{ field: 'itemName', title: '物料名称', minWidth: 150 },
|
||||
{ field: 'specification', title: '规格型号', minWidth: 140 },
|
||||
{ field: 'unitMeasureName', title: '单位', width: 100 },
|
||||
{ field: 'receivedQuantity', title: '入库数量', width: 120 },
|
||||
],
|
||||
height: 320,
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
return await getItemReceiptLinePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
vendorId: props.vendorId,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesWmItemReceiptLineApi.ItemReceiptLine>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid table-title="采购记录" />
|
||||
</template>
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdWorkshopApi } from '#/api/mes/md/workstation/workshop';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||||
|
||||
/** 新增/修改车间的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '车间编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入车间编码',
|
||||
},
|
||||
dependencies: {
|
||||
triggerFields: ['id'],
|
||||
componentProps: (values) => ({
|
||||
disabled: !!values.id,
|
||||
}),
|
||||
},
|
||||
rules: 'required',
|
||||
suffix: () =>
|
||||
h(
|
||||
ElButton,
|
||||
{
|
||||
onClick: async () => {
|
||||
try {
|
||||
const code = await generateAutoCode(
|
||||
MesAutoCodeRuleCode.MD_WORKSHOP_CODE,
|
||||
);
|
||||
await formApi?.setFieldValue('code', code);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
{ default: () => '自动生成' },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '车间名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入车间名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'area',
|
||||
label: '面积',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'chargeUserId',
|
||||
label: '负责人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getSimpleUserList,
|
||||
clearable: true,
|
||||
labelField: 'nickname',
|
||||
placeholder: '请选择负责人',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
formItemClass: 'col-span-2',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '车间编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入车间编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '车间名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入车间名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions<MesMdWorkshopApi.Workshop>['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'code',
|
||||
title: '车间编码',
|
||||
minWidth: 150,
|
||||
slots: { default: 'code' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '车间名称',
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
field: 'area',
|
||||
title: '面积',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'chargeUserName',
|
||||
title: '负责人',
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
width: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MesMdWorkshopApi } from '#/api/mes/md/workstation/workshop';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteWorkshop,
|
||||
getWorkshopPage,
|
||||
} from '#/api/mes/md/workstation/workshop';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建车间 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData({ type: 'create' }).open();
|
||||
}
|
||||
|
||||
/** 查看车间 */
|
||||
function handleDetail(row: MesMdWorkshopApi.Workshop) {
|
||||
formModalApi.setData({ id: row.id, type: 'detail' }).open();
|
||||
}
|
||||
|
||||
/** 编辑车间 */
|
||||
function handleEdit(row: MesMdWorkshopApi.Workshop) {
|
||||
formModalApi.setData({ id: row.id, type: 'update' }).open();
|
||||
}
|
||||
|
||||
/** 删除车间 */
|
||||
async function handleDelete(row: MesMdWorkshopApi.Workshop) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteWorkshop(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getWorkshopPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MesMdWorkshopApi.Workshop>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】车间设置、工作站设置"
|
||||
url="https://doc.iocoder.cn/mes/md/workshop/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="车间列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['车间']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['mes:md-workshop:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #code="{ row }">
|
||||
<ElButton link type="primary" @click="handleDetail(row)">
|
||||
{{ row.code }}
|
||||
</ElButton>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['mes:md-workshop:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['mes:md-workshop:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MesMdWorkshopApi } from '#/api/mes/md/workstation/workshop';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElButton, ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createWorkshop,
|
||||
getWorkshop,
|
||||
updateWorkshop,
|
||||
} from '#/api/mes/md/workstation/workshop';
|
||||
import { $t } from '#/locales';
|
||||
import { BarcodeBizTypeEnum } from '#/views/mes/utils/constants';
|
||||
import { BarcodeDetail } from '#/views/mes/wm/barcode/components';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
type FormMode = 'create' | 'detail' | 'update';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formMode = ref<FormMode>('create'); // 表单模式
|
||||
const formData = ref<MesMdWorkshopApi.Workshop>();
|
||||
const barcodeDetailRef = ref<InstanceType<typeof BarcodeDetail>>(); // 条码详情弹窗
|
||||
|
||||
const isDetail = computed(() => formMode.value === 'detail'); // 是否查看模式
|
||||
const getTitle = computed(() => {
|
||||
const titles: Record<FormMode, string> = {
|
||||
create: '新增车间',
|
||||
update: '修改车间',
|
||||
detail: '查看车间',
|
||||
};
|
||||
return titles[formMode.value];
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-1',
|
||||
labelWidth: 100,
|
||||
},
|
||||
wrapperClass: 'grid-cols-2',
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
/** 查看车间条码 */
|
||||
function handleBarcode() {
|
||||
if (!formData.value?.id) {
|
||||
return;
|
||||
}
|
||||
barcodeDetailRef.value?.openByBusiness(
|
||||
formData.value.id,
|
||||
BarcodeBizTypeEnum.WORKSHOP,
|
||||
formData.value.code,
|
||||
formData.value.name,
|
||||
);
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (isDetail.value) {
|
||||
await modalApi.close();
|
||||
return;
|
||||
}
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as MesMdWorkshopApi.Workshop;
|
||||
try {
|
||||
await (formData.value?.id ? updateWorkshop(data) : createWorkshop(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
await formApi.resetForm();
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{ id?: number; type?: FormMode }>();
|
||||
formMode.value = data?.type || 'create';
|
||||
formApi.setDisabled(formMode.value === 'detail');
|
||||
modalApi.setState({ showConfirmButton: formMode.value !== 'detail' });
|
||||
if (!data?.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getWorkshop(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/2">
|
||||
<Form class="mx-4" />
|
||||
<template v-if="isDetail && formData?.id" #prepend-footer>
|
||||
<div class="flex flex-auto items-center">
|
||||
<ElButton @click="handleBarcode">查看条码</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</Modal>
|
||||
<BarcodeDetail ref="barcodeDetailRef" />
|
||||
</template>
|
||||
Loading…
Reference in New Issue