feat:【ele】【crm】初始化界面

This commit is contained in:
YunaiV
2025-11-17 09:28:32 +08:00
parent a273ab2882
commit 32ffc2e556
26 changed files with 2705 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmProductCategoryApi } from '#/api/crm/product/category';
import { handleTree } from '@vben/utils';
import { getProductCategoryList } from '#/api/crm/product/category';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'parentId',
label: '上级分类',
component: 'ApiTreeSelect',
componentProps: {
clearable: true,
api: async () => {
const data = await getProductCategoryList();
data.unshift({
id: 0,
name: '顶级分类',
} as CrmProductCategoryApi.ProductCategory);
return handleTree(data);
},
fieldNames: { label: 'name', value: 'id', children: 'children' },
placeholder: '请选择上级分类',
showSearch: true,
treeDefaultExpandAll: true,
},
rules: 'selectRequired',
},
{
fieldName: 'name',
label: '分类名称',
component: 'Input',
componentProps: {
placeholder: '请输入分类名称',
},
rules: 'required',
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '分类名称',
component: 'Input',
componentProps: {
clearable: true,
placeholder: '请输入分类名称',
},
},
];
}
/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions<CrmProductCategoryApi.ProductCategory>['columns'] {
return [
{
field: 'name',
title: '分类名称',
treeNode: true,
},
{
field: 'id',
title: '分类编号',
},
{
field: 'createTime',
title: '创建时间',
formatter: 'formatDateTime',
},
{
field: 'actions',
title: '操作',
width: 200,
fixed: 'right',
slots: {
default: 'actions',
},
},
];
}

View File

@@ -0,0 +1,168 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmProductCategoryApi } from '#/api/crm/product/category';
import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteProductCategory,
getProductCategoryList,
} from '#/api/crm/product/category';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 切换树形展开/收缩状态 */
const isExpanded = ref(false);
function handleExpand() {
isExpanded.value = !isExpanded.value;
gridApi.grid.setAllTreeExpand(isExpanded.value);
}
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建分类 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 添加下级分类 */
function handleAppend(row: CrmProductCategoryApi.ProductCategory) {
formModalApi.setData({ parentId: row.id }).open();
}
/** 编辑分类 */
function handleEdit(row: CrmProductCategoryApi.ProductCategory) {
formModalApi.setData(row).open();
}
/** 删除分类 */
async function handleDelete(row: CrmProductCategoryApi.ProductCategory) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteProductCategory(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,
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_, formValues) => {
return await getProductCategoryList(formValues);
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
treeConfig: {
parentField: 'parentId',
rowField: 'id',
transform: true,
expandAll: true,
reserve: true,
},
} as VxeTableGridOptions<CrmProductCategoryApi.ProductCategory>,
});
</script>
<template>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【产品】产品管理、产品分类"
url="https://doc.iocoder.cn/crm/product/"
/>
</template>
<FormModal @success="handleRefresh" />
<Grid>
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['分类']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['crm:product-category:create'],
onClick: handleCreate,
},
{
label: isExpanded ? '收缩' : '展开',
type: 'primary',
onClick: handleExpand,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: '新增下级',
type: 'primary',
link: true,
icon: ACTION_ICON.ADD,
auth: ['crm:product-category:create'],
onClick: handleAppend.bind(null, row),
},
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['crm:product-category:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['crm:product-category:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,92 @@
<script lang="ts" setup>
import type { CrmProductCategoryApi } from '#/api/crm/product/category';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { ElMessage } from 'element-plus';
import { useVbenForm } from '#/adapter/form';
import {
createProductCategory,
getProductCategory,
updateProductCategory,
} from '#/api/crm/product/category';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<CrmProductCategoryApi.ProductCategory>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['产品分类'])
: $t('ui.actionTitle.create', ['产品分类']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
formItemClass: 'col-span-2',
labelWidth: 80,
},
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data =
(await formApi.getValues()) as CrmProductCategoryApi.ProductCategory;
try {
await (formData.value?.id
? updateProductCategory(data)
: createProductCategory(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;
}
// 加载数据
let data = modalApi.getData<CrmProductCategoryApi.ProductCategory>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
if (data.id) {
data = await getProductCategory(data.id);
}
// 设置到 values
formData.value = data;
await formApi.setValues(data);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal class="w-2/5" :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>

View File

@@ -0,0 +1,111 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { DICT_TYPE } from '@vben/constants';
/** 产品详情列表的列定义 */
export function useDetailListColumns(
showBusinessPrice: boolean,
): VxeTableGridOptions['columns'] {
return [
{
field: 'productName',
title: '产品名称',
},
{
field: 'productNo',
title: '产品条码',
},
{
field: 'productUnit',
title: '产品单位',
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_PRODUCT_UNIT },
},
},
{
field: 'productPrice',
title: '产品价格(元)',
formatter: 'formatAmount2',
},
{
field: 'businessPrice',
title: '商机价格(元)',
formatter: 'formatAmount2',
visible: showBusinessPrice,
},
{
field: 'contractPrice',
title: '合同价格(元)',
formatter: 'formatAmount2',
visible: !showBusinessPrice,
},
{
field: 'count',
title: '数量',
formatter: 'formatAmount3',
},
{
field: 'totalPrice',
title: '合计金额(元)',
formatter: 'formatAmount2',
},
];
}
/** 产品编辑表格的列定义 */
export function useProductEditTableColumns(): VxeTableGridOptions['columns'] {
return [
{ type: 'seq', title: '序号', minWidth: 50 },
{
field: 'productId',
title: '产品名称',
minWidth: 100,
slots: { default: 'productId' },
},
{
field: 'productNo',
title: '条码',
minWidth: 150,
},
{
field: 'productUnit',
title: '单位',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_PRODUCT_UNIT },
},
},
{
field: 'productPrice',
title: '价格(元)',
minWidth: 100,
formatter: 'formatAmount2',
},
{
field: 'sellingPrice',
title: '售价(元)',
minWidth: 100,
slots: { default: 'sellingPrice' },
},
{
field: 'count',
title: '数量',
minWidth: 100,
slots: { default: 'count' },
},
{
field: 'totalPrice',
title: '合计',
minWidth: 100,
formatter: 'formatAmount2',
},
{
title: '操作',
width: 80,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@@ -0,0 +1,79 @@
<!-- 产品列表用于商机合同详情中展示它们关联的产品列表 -->
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmProductApi } from '#/api/crm/product';
import { ref } from 'vue';
import { erpPriceInputFormatter } from '@vben/utils';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getBusiness } from '#/api/crm/business';
import { getContract } from '#/api/crm/contract';
import { BizTypeEnum } from '#/api/crm/permission';
import { useDetailListColumns } from './data';
/** 组件入参 */
const props = defineProps<{
bizId: number;
bizType: BizTypeEnum;
}>();
/** 整单折扣 */
const discountPercent = ref(0);
/** 产品总金额 */
const totalProductPrice = ref(0);
/** 构建产品列表表格 */
const [Grid] = useVbenVxeGrid({
gridOptions: {
columns: useDetailListColumns(props.bizType === BizTypeEnum.CRM_BUSINESS),
height: 600,
pagerConfig: {
enabled: false,
},
proxyConfig: {
ajax: {
query: async (_params) => {
const data =
props.bizType === BizTypeEnum.CRM_BUSINESS
? await getBusiness(props.bizId)
: await getContract(props.bizId);
discountPercent.value = data.discountPercent;
totalProductPrice.value = data.totalProductPrice;
return data.products;
},
},
},
toolbarConfig: {
refresh: true,
search: true,
},
keepSource: true,
rowConfig: {
keyField: 'id',
isHover: true,
},
} as VxeTableGridOptions<CrmProductApi.Product>,
});
</script>
<template>
<div>
<Grid />
<div class="flex flex-col items-end justify-end">
<span class="ml-4 font-bold text-red-500">
{{ `产品总金额:${erpPriceInputFormatter(totalProductPrice)}` }}
</span>
<span class="font-bold text-red-500">
{{ `整单折扣:${erpPriceInputFormatter(discountPercent)}%` }}
</span>
<span class="font-bold text-red-500">
{{
`实际金额:${erpPriceInputFormatter(totalProductPrice * (1 - discountPercent / 100))}`
}}
</span>
</div>
</div>
</template>

View File

@@ -0,0 +1,203 @@
<script lang="ts" setup>
import type { CrmBusinessApi } from '#/api/crm/business';
import type { CrmContractApi } from '#/api/crm/contract';
import type { CrmProductApi } from '#/api/crm/product';
import { nextTick, onMounted, ref, watch } from 'vue';
import { erpPriceMultiply } from '@vben/utils';
import { ElInputNumber, ElOption, ElSelect } from 'element-plus';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { BizTypeEnum } from '#/api/crm/permission';
import { getProductSimpleList } from '#/api/crm/product';
import { $t } from '#/locales';
import { useProductEditTableColumns } from './data';
const props = defineProps<{
bizType: BizTypeEnum;
products?:
| CrmBusinessApi.BusinessProduct[]
| CrmContractApi.ContractProduct[];
}>();
const emit = defineEmits(['update:products']);
/** 表格内部数据 */
const tableData = ref<any[]>([]);
/** 添加产品行 */
function handleAdd() {
gridApi.grid.insertAt(null, -1);
}
/** 删除产品行 */
function handleDelete(row: CrmProductApi.Product) {
gridApi.grid.remove(row);
}
/** 切换产品时同步基础信息 */
function handleProductChange(productId: any, row: any) {
const product = productOptions.value.find((p) => p.id === productId);
if (!product) {
return;
}
row.productUnit = product.unit;
row.productNo = product.no;
row.productPrice = product.price;
row.sellingPrice = product.price;
row.count = 0;
row.totalPrice = 0;
handleUpdateValue(row);
}
/** 金额变动时重新计算合计 */
function handlePriceChange(row: any) {
row.totalPrice = erpPriceMultiply(row.sellingPrice, row.count) ?? 0;
handleUpdateValue(row);
}
/** 将最新数据写回并通知父组件 */
function handleUpdateValue(row: any) {
const index = tableData.value.findIndex((item) => item.id === row.id);
if (props.bizType === BizTypeEnum.CRM_BUSINESS) {
row.businessPrice = row.sellingPrice;
} else if (props.bizType === BizTypeEnum.CRM_CONTRACT) {
row.contractPrice = row.sellingPrice;
}
if (index === -1) {
row.id = tableData.value.length + 1;
tableData.value.push(row);
} else {
tableData.value[index] = row;
}
emit('update:products', [...tableData.value]);
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
editConfig: {
trigger: 'click',
mode: 'cell',
},
columns: useProductEditTableColumns(),
data: tableData.value,
border: true,
showOverflow: true,
autoResize: true,
keepSource: true,
rowConfig: {
keyField: 'id',
isHover: true,
},
pagerConfig: {
enabled: false,
},
toolbarConfig: {
enabled: false,
},
},
});
/** 监听外部传入的列数据 */
watch(
() => props.products,
async (products) => {
if (!products) {
return;
}
await nextTick();
tableData.value = products;
if (props.bizType === BizTypeEnum.CRM_BUSINESS) {
tableData.value.forEach((item) => {
item.sellingPrice = item.businessPrice;
});
} else if (props.bizType === BizTypeEnum.CRM_CONTRACT) {
tableData.value.forEach((item) => {
item.sellingPrice = item.contractPrice;
});
}
await gridApi.grid.reloadData(tableData.value);
},
{
immediate: true,
},
);
/** 产品下拉选项 */
const productOptions = ref<CrmProductApi.Product[]>([]);
/** 初始化 */
onMounted(async () => {
productOptions.value = await getProductSimpleList();
});
</script>
<template>
<Grid class="w-full">
<template #productId="{ row }">
<ElSelect
v-model="row.productId"
:field-names="{ label: 'name', value: 'id' }"
class="w-full"
@change="handleProductChange($event, row)"
>
<ElOption
v-for="option in productOptions"
:key="option.id"
:label="option.name"
:value="option.id"
/>
</ElSelect>
</template>
<template #sellingPrice="{ row }">
<ElInputNumber
v-model="row.sellingPrice"
:min="0.001"
:precision="2"
controls-position="right"
class="!w-full"
@change="handlePriceChange(row)"
/>
</template>
<template #count="{ row }">
<ElInputNumber
v-model="row.count"
:min="0.001"
:precision="3"
controls-position="right"
class="!w-full"
@change="handlePriceChange(row)"
/>
</template>
<template #bottom>
<TableAction
class="mt-4 flex justify-center"
:actions="[
{
label: '添加产品',
type: 'default',
onClick: handleAdd,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.delete'),
type: 'danger',
link: true,
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</template>

View File

@@ -0,0 +1,2 @@
export { default as ProductDetailsList } from './detail-list.vue';
export { default as ProductEditTable } from './edit-table.vue';

View File

@@ -0,0 +1,231 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { useUserStore } from '@vben/stores';
import { handleTree } from '@vben/utils';
import { z } from '#/adapter/form';
import { getProductCategoryList } from '#/api/crm/product/category';
import { getSimpleUserList } from '#/api/system/user';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
const userStore = useUserStore();
return [
{
component: 'Input',
fieldName: 'id',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
component: 'Input',
fieldName: 'name',
label: '产品名称',
rules: 'required',
componentProps: {
placeholder: '请输入产品名称',
clearable: true,
},
},
{
component: 'ApiSelect',
fieldName: 'ownerUserId',
label: '负责人',
rules: 'required',
dependencies: {
triggerFields: ['id'],
disabled: (values) => values.id,
},
componentProps: {
api: getSimpleUserList,
labelField: 'nickname',
valueField: 'id',
placeholder: '请选择负责人',
clearable: true,
},
defaultValue: userStore.userInfo?.id,
},
{
component: 'Input',
fieldName: 'no',
label: '产品编码',
rules: 'required',
componentProps: {
placeholder: '请输入产品编码',
clearable: true,
},
},
{
component: 'ApiTreeSelect',
fieldName: 'categoryId',
label: '产品类型',
rules: 'required',
componentProps: {
api: async () => {
const data = await getProductCategoryList();
return handleTree(data);
},
fieldNames: { label: 'name', value: 'id', children: 'children' },
placeholder: '请选择产品类型',
clearable: true,
},
},
{
fieldName: 'unit',
label: '产品单位',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.CRM_PRODUCT_UNIT, 'number'),
placeholder: '请选择产品单位',
clearable: true,
},
rules: 'required',
},
{
component: 'InputNumber',
fieldName: 'price',
label: '价格(元)',
rules: 'required',
componentProps: {
min: 0,
precision: 2,
step: 0.1,
placeholder: '请输入产品价格',
controlsPosition: 'right',
class: '!w-full',
},
},
{
component: 'Textarea',
fieldName: 'description',
label: '产品描述',
componentProps: {
placeholder: '请输入产品描述',
clearable: true,
},
},
{
fieldName: 'status',
label: '上架状态',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS, 'number'),
},
rules: z.number().default(CommonStatusEnum.ENABLE),
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '产品名称',
component: 'Input',
componentProps: {
placeholder: '请输入产品名称',
clearable: true,
},
},
{
fieldName: 'status',
label: '上架状态',
component: 'Select',
componentProps: {
clearable: true,
placeholder: '请选择上架状态',
options: getDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS, 'number'),
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '产品编号',
visible: false,
},
{
field: 'name',
title: '产品名称',
minWidth: 240,
slots: { default: 'name' },
},
{
field: 'categoryName',
title: '产品类型',
minWidth: 120,
},
{
field: 'unit',
title: '产品单位',
minWidth: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_PRODUCT_UNIT },
},
},
{
field: 'no',
title: '产品编码',
minWidth: 120,
},
{
field: 'price',
title: '价格(元)',
formatter: 'formatAmount2',
minWidth: 120,
},
{
field: 'description',
title: '产品描述',
minWidth: 200,
},
{
field: 'status',
title: '上架状态',
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.CRM_PRODUCT_STATUS },
},
minWidth: 120,
},
{
field: 'ownerUserName',
title: '负责人',
minWidth: 120,
},
{
field: 'updateTime',
title: '更新时间',
formatter: 'formatDateTime',
minWidth: 180,
},
{
field: 'creatorName',
title: '创建人',
minWidth: 120,
},
{
field: 'createTime',
title: '创建时间',
formatter: 'formatDateTime',
minWidth: 180,
},
{
title: '操作',
width: 160,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@@ -0,0 +1,72 @@
import type { DescriptionItemSchema } from '#/components/description';
import { h } from 'vue';
import { DICT_TYPE } from '@vben/constants';
import { erpPriceInputFormatter } from '@vben/utils';
import { DictTag } from '#/components/dict-tag';
/** 详情页的字段 */
export function useDetailSchema(): DescriptionItemSchema[] {
return [
{
field: 'categoryName',
label: '产品类别',
},
{
field: 'unit',
label: '产品单位',
render: (val) =>
h(DictTag, { type: DICT_TYPE.CRM_PRODUCT_UNIT, value: val }),
},
{
field: 'price',
label: '产品价格(元)',
render: (val) => erpPriceInputFormatter(val),
},
{
field: 'no',
label: '产品编码',
},
];
}
/** 详情页的基础字段 */
export function useDetailBaseSchema(): DescriptionItemSchema[] {
return [
{
field: 'name',
label: '产品名称',
},
{
field: 'no',
label: '产品编码',
},
{
field: 'price',
label: '价格(元)',
render: (val) => erpPriceInputFormatter(val),
},
{
field: 'description',
label: '产品描述',
},
{
field: 'categoryName',
label: '产品类型',
},
{
field: 'status',
label: '是否上下架',
render: (val) =>
h(DictTag, { type: DICT_TYPE.CRM_PRODUCT_STATUS, value: val }),
},
{
field: 'unit',
label: '产品单位',
render: (val) =>
h(DictTag, { type: DICT_TYPE.CRM_PRODUCT_UNIT, value: val }),
},
];
}

View File

@@ -0,0 +1,89 @@
<script setup lang="ts">
import type { CrmProductApi } from '#/api/crm/product';
import type { SystemOperateLogApi } from '#/api/system/operate-log';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { ElButton, ElCard, ElTabPane, ElTabs } from 'element-plus';
import { getOperateLogPage } from '#/api/crm/operateLog';
import { BizTypeEnum } from '#/api/crm/permission';
import { getProduct } from '#/api/crm/product';
import { useDescription } from '#/components/description';
import { OperateLog } from '#/components/operate-log';
import { useDetailSchema } from './data';
import Info from './modules/info.vue';
const route = useRoute();
const router = useRouter();
const tabs = useTabs();
const loading = ref(false); // 加载中
const productId = ref(0); // 产品编号
const product = ref<CrmProductApi.Product>({} as CrmProductApi.Product); // 产品详情
const logList = ref<SystemOperateLogApi.OperateLog[]>([]); // 操作日志
const [Descriptions] = useDescription({
bordered: false,
column: 4,
class: 'mx-4',
schema: useDetailSchema(),
});
/** 加载详情 */
async function getProductDetail() {
loading.value = true;
try {
product.value = await getProduct(productId.value);
// 操作日志
const res = await getOperateLogPage({
bizType: BizTypeEnum.CRM_PRODUCT,
bizId: productId.value,
});
logList.value = res.list;
} finally {
loading.value = false;
}
loading.value = false;
}
/** 返回列表页 */
function handleBack() {
tabs.closeCurrentTab();
router.push({ name: 'CrmProduct' });
}
/** 加载数据 */
onMounted(() => {
productId.value = Number(route.params.id);
getProductDetail();
});
</script>
<template>
<Page auto-content-height :title="product?.name" :loading="loading">
<template #extra>
<div class="flex items-center gap-2">
<ElButton @click="handleBack"> 返回 </ElButton>
</div>
</template>
<ElCard class="min-h-[10%]">
<Descriptions :data="product" />
</ElCard>
<ElCard class="mt-4 min-h-[60%]">
<ElTabs>
<ElTabPane label="详细资料" name="1">
<Info :product="product" />
</ElTabPane>
<ElTabPane label="操作日志" name="2">
<OperateLog :log-list="logList" />
</ElTabPane>
</ElTabs>
</ElCard>
</Page>
</template>

View File

@@ -0,0 +1,25 @@
<script lang="ts" setup>
import type { CrmProductApi } from '#/api/crm/product';
import { useDescription } from '#/components/description';
import { useDetailBaseSchema } from '../data';
defineProps<{
product: CrmProductApi.Product; // 产品信息
}>();
const [ProductDescriptions] = useDescription({
title: '基本信息',
bordered: false,
column: 4,
class: 'mx-4',
schema: useDetailBaseSchema(),
});
</script>
<template>
<div class="p-4">
<ProductDescriptions :data="product" />
</div>
</template>

View File

@@ -0,0 +1,157 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CrmProductApi } from '#/api/crm/product';
import { useRouter } from 'vue-router';
import { 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 {
deleteProduct,
exportProduct,
getProductPage,
} from '#/api/crm/product';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
const { push } = useRouter();
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportProduct(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '产品.xls', source: data });
}
/** 打开详情 */
function handleDetail(row: CrmProductApi.Product) {
push({ name: 'CrmProductDetail', params: { id: row.id } });
}
/** 创建产品 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑产品 */
function handleEdit(row: CrmProductApi.Product) {
formModalApi.setData(row).open();
}
/** 删除产品 */
async function handleDelete(row: CrmProductApi.Product) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteProduct(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 getProductPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<CrmProductApi.Product>,
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="handleRefresh" />
<Grid table-title="产品列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['产品']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['crm:product:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['crm:product:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #name="{ row }">
<ElButton type="primary" link @click="handleDetail(row)">
{{ row.name }}
</ElButton>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['crm:product:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['crm:product:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,82 @@
<script lang="ts" setup>
import type { CrmProductApi } from '#/api/crm/product';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { ElMessage } from 'element-plus';
import { useVbenForm } from '#/adapter/form';
import { createProduct, getProduct, updateProduct } from '#/api/crm/product';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<CrmProductApi.Product>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['产品'])
: $t('ui.actionTitle.create', ['产品']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
formItemClass: 'col-span-2',
labelWidth: 80,
},
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
// 提交表单
const data = (await formApi.getValues()) as CrmProductApi.Product;
try {
await (formData.value?.id ? updateProduct(data) : createProduct(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;
}
// 加载数据
const data = modalApi.getData<CrmProductApi.Product>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getProduct(data.id);
// 设置到 values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-2/5">
<Form class="mx-4" />
</Modal>
</template>