feat:【antd】商品积分活动的 review
This commit is contained in:
@@ -234,7 +234,9 @@ async function handleSubmit() {
|
|||||||
// 校验表单
|
// 校验表单
|
||||||
if (!formRef.value) return;
|
if (!formRef.value) return;
|
||||||
const valid = await formRef.value.validate();
|
const valid = await formRef.value.validate();
|
||||||
if (!valid) return;
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 提交请求
|
// 提交请求
|
||||||
submitLoading.value = true;
|
submitLoading.value = true;
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ export { default as SpuAndSkuList } from './spu-and-sku-list.vue';
|
|||||||
export { default as SpuSkuSelect } from './spu-sku-select.vue';
|
export { default as SpuSkuSelect } from './spu-sku-select.vue';
|
||||||
|
|
||||||
export type * from './types';
|
export type * from './types';
|
||||||
|
// TODO @puhui999:这个要不要也放到 product/spu/components 下?相当于各种商品的 select 能力,统一由 spu 提供组件化能力!
|
||||||
|
|||||||
@@ -15,14 +15,10 @@ import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
|||||||
import { SkuList } from '#/views/mall/product/spu/form';
|
import { SkuList } from '#/views/mall/product/spu/form';
|
||||||
|
|
||||||
interface SpuAndSkuListProps {
|
interface SpuAndSkuListProps {
|
||||||
/** SPU 列表 */
|
spuList: T[]; // SPU 列表
|
||||||
spuList: T[];
|
ruleConfig: RuleConfig[]; // 规则配置
|
||||||
/** 规则配置 */
|
spuPropertyList: SpuProperty<T>[]; // SPU 属性列表
|
||||||
ruleConfig: RuleConfig[];
|
deletable?: boolean; // 是否可删除
|
||||||
/** SPU 属性列表 */
|
|
||||||
spuPropertyList: SpuProperty<T>[];
|
|
||||||
/** 是否可删除 */
|
|
||||||
deletable?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<SpuAndSkuListProps>(), {
|
const props = withDefaults(defineProps<SpuAndSkuListProps>(), {
|
||||||
@@ -33,13 +29,11 @@ const emit = defineEmits<{
|
|||||||
delete: [spuId: number];
|
delete: [spuId: number];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// 内部数据
|
|
||||||
const spuData = ref<MallSpuApi.Spu[]>([]);
|
const spuData = ref<MallSpuApi.Spu[]>([]);
|
||||||
const spuPropertyListData = ref<SpuProperty<T>[]>([]);
|
const spuPropertyListData = ref<SpuProperty<T>[]>([]);
|
||||||
const expandedRowKeys = ref<number[]>([]);
|
const expandedRowKeys = ref<number[]>([]);
|
||||||
const skuListRef = ref<InstanceType<typeof SkuList>>();
|
const skuListRef = ref<InstanceType<typeof SkuList>>();
|
||||||
|
|
||||||
// 列配置(动态计算)
|
|
||||||
const columns = computed<VxeGridProps['columns']>(() => {
|
const columns = computed<VxeGridProps['columns']>(() => {
|
||||||
const cols: VxeGridProps['columns'] = [
|
const cols: VxeGridProps['columns'] = [
|
||||||
{
|
{
|
||||||
@@ -103,7 +97,6 @@ const columns = computed<VxeGridProps['columns']>(() => {
|
|||||||
return cols;
|
return cols;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 初始化表格
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: columns.value,
|
columns: columns.value,
|
||||||
@@ -121,14 +114,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/** 删除 SPU */
|
||||||
* 删除 SPU
|
|
||||||
*/
|
|
||||||
async function handleDelete(row: MallSpuApi.Spu) {
|
async function handleDelete(row: MallSpuApi.Spu) {
|
||||||
|
// TODO @puhui999:可以使用 TableAction 的 popConfirm 哈?
|
||||||
await confirm({
|
await confirm({
|
||||||
content: `是否删除商品编号为 ${row.id} 的数据?`,
|
content: `是否删除商品编号为 ${row.id} 的数据?`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const index = spuData.value.findIndex((item) => item.id === row.id);
|
const index = spuData.value.findIndex((item) => item.id === row.id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
spuData.value.splice(index, 1);
|
spuData.value.splice(index, 1);
|
||||||
@@ -138,6 +129,7 @@ async function handleDelete(row: MallSpuApi.Spu) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有 SKU 活动配置
|
* 获取所有 SKU 活动配置
|
||||||
|
*
|
||||||
* @param extendedAttribute 在 SKU 上扩展的属性名称
|
* @param extendedAttribute 在 SKU 上扩展的属性名称
|
||||||
*/
|
*/
|
||||||
function getSkuConfigs(extendedAttribute: string) {
|
function getSkuConfigs(extendedAttribute: string) {
|
||||||
@@ -157,32 +149,36 @@ function getSkuConfigs(extendedAttribute: string) {
|
|||||||
return configs;
|
return configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暴露方法给父组件
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
getSkuConfigs,
|
getSkuConfigs,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听 spuList 变化
|
/** 监听 spuList 变化 */
|
||||||
watch(
|
watch(
|
||||||
() => props.spuList,
|
() => props.spuList,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (!data) return;
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
spuData.value = data as MallSpuApi.Spu[];
|
spuData.value = data as MallSpuApi.Spu[];
|
||||||
// 更新表格列配置和数据
|
// 更新表格列配置和数据
|
||||||
gridApi.grid.reloadData(spuData.value);
|
gridApi.grid.reloadData(spuData.value);
|
||||||
gridApi.grid.reloadColumn(columns.value);
|
gridApi.grid.reloadColumn(columns.value as any[]);
|
||||||
},
|
},
|
||||||
{ deep: true, immediate: true },
|
{ deep: true, immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
// 监听 spuPropertyList 变化
|
/** 监听 spuPropertyList 变化 */
|
||||||
watch(
|
watch(
|
||||||
() => props.spuPropertyList,
|
() => props.spuPropertyList,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (!data) return;
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
spuPropertyListData.value = data as SpuProperty<T>[];
|
spuPropertyListData.value = data as SpuProperty<T>[];
|
||||||
|
|
||||||
// 延迟展开所有行,确保 SKU 列表正确渲染
|
// 延迟展开所有行,确保 SKU 列表正确渲染
|
||||||
|
// TODO @puhui999:只能 setTimeout 么?await 之类可以么?
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expandedRowKeys.value = data.map((item) => item.spuId);
|
expandedRowKeys.value = data.map((item) => item.spuId);
|
||||||
// 手动展开每一行
|
// 手动展开每一行
|
||||||
@@ -222,7 +218,6 @@ watch(
|
|||||||
</SkuList>
|
</SkuList>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 操作列 -->
|
<!-- 操作列 -->
|
||||||
<template
|
<template
|
||||||
v-if="props.deletable && props.spuList.length > 1"
|
v-if="props.deletable && props.spuList.length > 1"
|
||||||
|
|||||||
@@ -18,10 +18,8 @@ import { getRangePickerDefaultProps } from '#/utils';
|
|||||||
import { getPropertyList, SkuList } from '#/views/mall/product/spu/form';
|
import { getPropertyList, SkuList } from '#/views/mall/product/spu/form';
|
||||||
|
|
||||||
interface SpuSkuSelectProps {
|
interface SpuSkuSelectProps {
|
||||||
/** 是否选择 SKU */
|
isSelectSku?: boolean; // 是否选择 SKU
|
||||||
isSelectSku?: boolean;
|
radio?: boolean; // 是否单选 SKU
|
||||||
/** 是否单选 SKU */
|
|
||||||
radio?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<SpuSkuSelectProps>(), {
|
const props = withDefaults(defineProps<SpuSkuSelectProps>(), {
|
||||||
@@ -33,33 +31,17 @@ const emit = defineEmits<{
|
|||||||
confirm: [spuId: number, skuIds?: number[]];
|
confirm: [spuId: number, skuIds?: number[]];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// 单选:选中的 SPU ID
|
const selectedSpuId = ref<number>(); // 单选:选中的 SPU ID
|
||||||
const selectedSpuId = ref<number>();
|
const selectedSkuIds = ref<number[]>([]); // 选中的 SKU ID 列表
|
||||||
// 选中的 SKU ID 列表
|
|
||||||
const selectedSkuIds = ref<number[]>([]);
|
|
||||||
// SKU 列表数据
|
|
||||||
const spuData = ref<MallSpuApi.Spu>();
|
const spuData = ref<MallSpuApi.Spu>();
|
||||||
const propertyList = ref<any[]>([]);
|
const propertyList = ref<any[]>([]);
|
||||||
const isExpand = ref(false);
|
const isExpand = ref(false);
|
||||||
const expandRowKeys = ref<number[]>([]);
|
const expandRowKeys = ref<number[]>([]);
|
||||||
const skuListRef = ref<InstanceType<typeof SkuList>>();
|
const skuListRef = ref<InstanceType<typeof SkuList>>();
|
||||||
|
|
||||||
// 分类列表(扁平)
|
const categoryList = ref<any[]>([]); // 分类列表(扁平)
|
||||||
const categoryList = ref<any[]>([]);
|
const categoryTreeList = ref<any[]>([]); // 分类树
|
||||||
// 分类树
|
|
||||||
const categoryTreeList = ref<any[]>([]);
|
|
||||||
|
|
||||||
// 初始化分类数据
|
|
||||||
onMounted(async () => {
|
|
||||||
try {
|
|
||||||
categoryList.value = await getCategoryList({});
|
|
||||||
categoryTreeList.value = handleTree(categoryList.value, 'id', 'parentId');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('加载分类数据失败:', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 搜索表单配置
|
|
||||||
const formSchema = computed<VbenFormSchema[]>(() => {
|
const formSchema = computed<VbenFormSchema[]>(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -100,10 +82,8 @@ const formSchema = computed<VbenFormSchema[]>(() => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
// 列配置
|
|
||||||
const gridColumns = computed<VxeGridProps['columns']>(() => {
|
const gridColumns = computed<VxeGridProps['columns']>(() => {
|
||||||
const columns: VxeGridProps['columns'] = [];
|
const columns: VxeGridProps['columns'] = [];
|
||||||
|
|
||||||
// 如果需要选择 SKU,添加展开列
|
// 如果需要选择 SKU,添加展开列
|
||||||
if (props.isSelectSku) {
|
if (props.isSelectSku) {
|
||||||
columns.push({
|
columns.push({
|
||||||
@@ -112,7 +92,6 @@ const gridColumns = computed<VxeGridProps['columns']>(() => {
|
|||||||
slots: { content: 'expand-content' },
|
slots: { content: 'expand-content' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 单选列
|
// 单选列
|
||||||
columns.push(
|
columns.push(
|
||||||
{
|
{
|
||||||
@@ -152,11 +131,9 @@ const gridColumns = computed<VxeGridProps['columns']>(() => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 初始化表格
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: formSchema.value,
|
schema: formSchema.value,
|
||||||
@@ -175,6 +152,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
ajax: {
|
ajax: {
|
||||||
async query({ page }: any, formValues: any) {
|
async query({ page }: any, formValues: any) {
|
||||||
try {
|
try {
|
||||||
|
// TODO @puhui999:1)try catch 可以去掉?;2)params 直接放到 getSpuPage 里哇?
|
||||||
const params = {
|
const params = {
|
||||||
pageNo: page.currentPage,
|
pageNo: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
@@ -200,28 +178,27 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 单选:处理选中 SPU
|
/** 单选:处理选中 SPU */
|
||||||
async function handleSingleSelected(row: MallSpuApi.Spu) {
|
async function handleSingleSelected(row: MallSpuApi.Spu) {
|
||||||
selectedSpuId.value = row.id;
|
selectedSpuId.value = row.id;
|
||||||
|
|
||||||
// 如果需要选择 SKU,展开行
|
// 如果需要选择 SKU,展开行
|
||||||
if (props.isSelectSku) {
|
if (props.isSelectSku) {
|
||||||
await expandChange(row, [row]);
|
await expandChange(row, [row]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选择 SKU
|
/** 选择 SKU */
|
||||||
function selectSku(skus: MallSpuApi.Sku[]) {
|
function selectSku(skus: MallSpuApi.Sku[]) {
|
||||||
if (!selectedSpuId.value) {
|
if (!selectedSpuId.value) {
|
||||||
message.warning('请先选择商品再选择相应的规格!');
|
message.warning('请先选择商品再选择相应的规格!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skus.length === 0) {
|
if (skus.length === 0) {
|
||||||
selectedSkuIds.value = [];
|
selectedSkuIds.value = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @puhui999:有 idea 告警
|
||||||
if (props.radio) {
|
if (props.radio) {
|
||||||
// 单选模式
|
// 单选模式
|
||||||
selectedSkuIds.value = [skus[0]?.id!];
|
selectedSkuIds.value = [skus[0]?.id!];
|
||||||
@@ -231,7 +208,7 @@ function selectSku(skus: MallSpuApi.Sku[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 展开行,加载 SKU 列表
|
/** 展开行,加载 SKU 列表 */
|
||||||
async function expandChange(
|
async function expandChange(
|
||||||
row: MallSpuApi.Spu,
|
row: MallSpuApi.Spu,
|
||||||
expandedRows?: MallSpuApi.Spu[],
|
expandedRows?: MallSpuApi.Spu[],
|
||||||
@@ -242,7 +219,6 @@ async function expandChange(
|
|||||||
expandRowKeys.value = [selectedSpuId.value];
|
expandRowKeys.value = [selectedSpuId.value];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果已经展开且是同一个 SPU,不重复加载
|
// 如果已经展开且是同一个 SPU,不重复加载
|
||||||
if (isExpand.value && spuData.value?.id === row.id) {
|
if (isExpand.value && spuData.value?.id === row.id) {
|
||||||
return;
|
return;
|
||||||
@@ -252,7 +228,6 @@ async function expandChange(
|
|||||||
spuData.value = undefined;
|
spuData.value = undefined;
|
||||||
propertyList.value = [];
|
propertyList.value = [];
|
||||||
isExpand.value = false;
|
isExpand.value = false;
|
||||||
|
|
||||||
if (!expandedRows || expandedRows.length === 0) {
|
if (!expandedRows || expandedRows.length === 0) {
|
||||||
expandRowKeys.value = [];
|
expandRowKeys.value = [];
|
||||||
return;
|
return;
|
||||||
@@ -266,13 +241,12 @@ async function expandChange(
|
|||||||
expandRowKeys.value = [row.id!];
|
expandRowKeys.value = [row.id!];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确认选择
|
/** 确认选择 */
|
||||||
function handleConfirm() {
|
function handleConfirm() {
|
||||||
if (!selectedSpuId.value) {
|
if (!selectedSpuId.value) {
|
||||||
message.warning('没有选择任何商品');
|
message.warning('没有选择任何商品');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.isSelectSku && selectedSkuIds.value.length === 0) {
|
if (props.isSelectSku && selectedSkuIds.value.length === 0) {
|
||||||
message.warning('没有选择任何商品属性');
|
message.warning('没有选择任何商品属性');
|
||||||
return;
|
return;
|
||||||
@@ -284,12 +258,10 @@ function handleConfirm() {
|
|||||||
selectedSpuId.value,
|
selectedSpuId.value,
|
||||||
props.isSelectSku ? selectedSkuIds.value : undefined,
|
props.isSelectSku ? selectedSkuIds.value : undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
// 关闭弹窗
|
// 关闭弹窗
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化弹窗
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
onConfirm: handleConfirm,
|
onConfirm: handleConfirm,
|
||||||
async onOpenChange(isOpen: boolean) {
|
async onOpenChange(isOpen: boolean) {
|
||||||
@@ -308,6 +280,12 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
await gridApi.query();
|
await gridApi.query();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** 初始化分类数据 */
|
||||||
|
onMounted(async () => {
|
||||||
|
categoryList.value = await getCategoryList({});
|
||||||
|
categoryTreeList.value = handleTree(categoryList.value, 'id', 'parentId');
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -5,11 +5,7 @@ import type { PropertyAndValues } from '#/views/mall/product/spu/form';
|
|||||||
* 用于活动商品选择中,关联 SPU 和其属性列表
|
* 用于活动商品选择中,关联 SPU 和其属性列表
|
||||||
*/
|
*/
|
||||||
export interface SpuProperty<T = any> {
|
export interface SpuProperty<T = any> {
|
||||||
/** SPU ID */
|
spuId: number; // SPU ID
|
||||||
spuId: number;
|
spuDetail: T; // SPU 详情
|
||||||
/** SPU 详情 */
|
propertyList: PropertyAndValues[]; // 属性列表
|
||||||
spuDetail: T;
|
|
||||||
/** 属性列表 */
|
|
||||||
propertyList: PropertyAndValues[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
// 1. 导入类型
|
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
// 2. 导入 VBEN 常量和工具
|
|
||||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
import { getDictOptions } from '@vben/hooks';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
// 3. 导入 Zod 用于高级验证
|
|
||||||
import { z } from '#/adapter/form';
|
import { z } from '#/adapter/form';
|
||||||
|
|
||||||
/**
|
// TODO @AI:注释
|
||||||
* @description: 列表的搜索表单
|
|
||||||
*/
|
|
||||||
export function useGridFormSchema(): VbenFormSchema[] {
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -28,12 +23,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// TODO @AI:注释
|
||||||
* @description: 列表的字段
|
|
||||||
*/
|
|
||||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
{ type: 'checkbox', width: 40 },
|
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '活动编号',
|
title: '活动编号',
|
||||||
@@ -78,20 +70,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
field: 'stock',
|
field: 'stock',
|
||||||
title: '库存',
|
title: '库存',
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
align: 'center',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'totalStock',
|
field: 'totalStock',
|
||||||
title: '总库存',
|
title: '总库存',
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
align: 'center',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'redeemedQuantity',
|
field: 'redeemedQuantity',
|
||||||
title: '已兑换数量',
|
title: '已兑换数量',
|
||||||
minWidth: 100,
|
minWidth: 100,
|
||||||
align: 'center',
|
|
||||||
// 使用 formatter 计算已兑换数量
|
|
||||||
formatter: ({ row }) => {
|
formatter: ({ row }) => {
|
||||||
return (row.totalStock || 0) - (row.stock || 0);
|
return (row.totalStock || 0) - (row.stock || 0);
|
||||||
},
|
},
|
||||||
@@ -100,7 +89,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
title: $t('common.createTime'),
|
title: $t('common.createTime'),
|
||||||
minWidth: 180,
|
minWidth: 180,
|
||||||
align: 'center',
|
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -112,12 +101,9 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// TODO @AI:注释下
|
||||||
* @description: 新增/修改的表单
|
|
||||||
*/
|
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
// 隐藏的 ID 字段
|
|
||||||
{
|
{
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
fieldName: 'id',
|
fieldName: 'id',
|
||||||
@@ -132,7 +118,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
component: 'Input',
|
component: 'Input',
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
formItemClass: 'col-span-2',
|
formItemClass: 'col-span-2',
|
||||||
// 通过插槽实现自定义商品选择器
|
|
||||||
renderComponentContent: () => ({
|
renderComponentContent: () => ({
|
||||||
default: () => null,
|
default: () => null,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -20,27 +20,29 @@ import Form from './modules/form.vue';
|
|||||||
|
|
||||||
defineOptions({ name: 'PromotionPointActivity' });
|
defineOptions({ name: 'PromotionPointActivity' });
|
||||||
|
|
||||||
// 1. 使用 useVbenModal 初始化弹窗
|
|
||||||
const [FormModal, formModalApi] = useVbenModal({
|
const [FormModal, formModalApi] = useVbenModal({
|
||||||
connectedComponent: Form,
|
connectedComponent: Form,
|
||||||
destroyOnClose: true,
|
destroyOnClose: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. 定义业务操作函数
|
// TODO @AI:增加注释
|
||||||
function handleCreate() {
|
function handleCreate() {
|
||||||
formModalApi.setData(null).open();
|
formModalApi.setData(null).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @AI:增加注释
|
||||||
function handleEdit(row: any) {
|
function handleEdit(row: any) {
|
||||||
formModalApi.setData(row).open();
|
formModalApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @AI:增加注释
|
||||||
async function handleClose(row: any) {
|
async function handleClose(row: any) {
|
||||||
await confirm({
|
await confirm({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: '确认关闭该积分商城活动吗?',
|
content: '确认关闭该积分商城活动吗?',
|
||||||
});
|
});
|
||||||
await closePointActivity(row.id);
|
await closePointActivity(row.id);
|
||||||
|
// TODO @AI:增加 loading
|
||||||
message.success('关闭成功');
|
message.success('关闭成功');
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
@@ -51,11 +53,13 @@ async function handleDelete(row: any) {
|
|||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @AI:增加注释
|
||||||
function handleRefresh() {
|
function handleRefresh() {
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算操作按钮
|
// 计算操作按钮
|
||||||
|
// TODO @AI:不用方法,直接 vue 标签里,写条件 ifShow !
|
||||||
const getActions = computed(() => (row: any) => {
|
const getActions = computed(() => (row: any) => {
|
||||||
const actions: any[] = [
|
const actions: any[] = [
|
||||||
{
|
{
|
||||||
@@ -64,8 +68,6 @@ const getActions = computed(() => (row: any) => {
|
|||||||
onClick: handleEdit.bind(null, row),
|
onClick: handleEdit.bind(null, row),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
// 如果状态是启用(0),显示关闭按钮
|
|
||||||
if (row.status === 0) {
|
if (row.status === 0) {
|
||||||
actions.push({
|
actions.push({
|
||||||
label: '关闭',
|
label: '关闭',
|
||||||
@@ -77,7 +79,6 @@ const getActions = computed(() => (row: any) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 否则显示删除按钮
|
|
||||||
actions.push({
|
actions.push({
|
||||||
label: $t('common.delete'),
|
label: $t('common.delete'),
|
||||||
icon: ACTION_ICON.DELETE,
|
icon: ACTION_ICON.DELETE,
|
||||||
@@ -88,11 +89,10 @@ const getActions = computed(() => (row: any) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. 使用 useVbenVxeGrid 初始化列表
|
// TODO @AI:参考 system/notice 补全,简化;
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
@@ -117,17 +117,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<!-- TODO @puhui999:不用 description 哈。 -->
|
||||||
<Page
|
<Page
|
||||||
description="积分商城活动,用于管理积分兑换商品的配置"
|
description="积分商城活动,用于管理积分兑换商品的配置"
|
||||||
doc-link="https://doc.iocoder.cn/mall/promotion-point/"
|
doc-link="https://doc.iocoder.cn/mall/promotion-point/"
|
||||||
title="积分商城活动"
|
title="积分商城活动"
|
||||||
>
|
>
|
||||||
<!-- 弹窗组件的注册 -->
|
|
||||||
<FormModal @success="handleRefresh" />
|
<FormModal @success="handleRefresh" />
|
||||||
|
|
||||||
<!-- 列表组件的渲染 -->
|
|
||||||
<Grid table-title="积分商城活动列表">
|
<Grid table-title="积分商城活动列表">
|
||||||
<!-- 工具栏按钮 -->
|
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<TableAction
|
<TableAction
|
||||||
:actions="[
|
:actions="[
|
||||||
@@ -139,7 +137,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<!-- 操作列按钮 -->
|
|
||||||
<template #actions="{ row }">
|
<template #actions="{ row }">
|
||||||
<TableAction :actions="getActions(row)" />
|
<TableAction :actions="getActions(row)" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const getTitle = computed(() =>
|
|||||||
isFormUpdate.value ? '编辑积分活动' : '新增积分活动',
|
isFormUpdate.value ? '编辑积分活动' : '新增积分活动',
|
||||||
);
|
);
|
||||||
|
|
||||||
// 1. 使用 useVbenForm 初始化表单
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
schema: useFormSchema(),
|
schema: useFormSchema(),
|
||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
@@ -69,6 +68,7 @@ const spuPropertyList = ref<SpuProperty<any>[]>([]); // SPU 属性列表
|
|||||||
/**
|
/**
|
||||||
* 打开商品选择器
|
* 打开商品选择器
|
||||||
*/
|
*/
|
||||||
|
// TODO @puhui999:spuSkuSelectRef.value.open is not a function
|
||||||
function openSpuSelect() {
|
function openSpuSelect() {
|
||||||
spuSkuSelectRef.value.open();
|
spuSkuSelectRef.value.open();
|
||||||
}
|
}
|
||||||
@@ -140,9 +140,7 @@ async function getSpuDetails(
|
|||||||
|
|
||||||
// ================= end =================
|
// ================= end =================
|
||||||
|
|
||||||
// 2. 使用 useVbenModal 定义弹窗行为
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
// "确认"按钮的回调
|
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
@@ -176,7 +174,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 弹窗打开时的回调
|
|
||||||
async onOpenChange(isOpen: boolean) {
|
async onOpenChange(isOpen: boolean) {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
// 关闭时清理状态
|
// 关闭时清理状态
|
||||||
@@ -244,7 +241,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</VxeColumn>
|
</VxeColumn>
|
||||||
|
|
||||||
<VxeColumn align="center" min-width="168" title="可兑换次数">
|
<VxeColumn align="center" min-width="168" title="可兑换次数">
|
||||||
<template #default="{ row: sku }">
|
<template #default="{ row: sku }">
|
||||||
<InputNumber
|
<InputNumber
|
||||||
@@ -254,7 +250,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</VxeColumn>
|
</VxeColumn>
|
||||||
|
|
||||||
<VxeColumn align="center" min-width="168" title="所需积分">
|
<VxeColumn align="center" min-width="168" title="所需积分">
|
||||||
<template #default="{ row: sku }">
|
<template #default="{ row: sku }">
|
||||||
<InputNumber
|
<InputNumber
|
||||||
@@ -264,7 +259,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</VxeColumn>
|
</VxeColumn>
|
||||||
|
|
||||||
<VxeColumn align="center" min-width="168" title="所需金额(元)">
|
<VxeColumn align="center" min-width="168" title="所需金额(元)">
|
||||||
<template #default="{ row: sku }">
|
<template #default="{ row: sku }">
|
||||||
<InputNumber
|
<InputNumber
|
||||||
|
|||||||
Reference in New Issue
Block a user