1、新增礼品卡模块

2、完善优惠券
This commit is contained in:
2025-08-11 19:20:16 +08:00
parent 32fe74c71f
commit 25c7c3e984
12 changed files with 1347 additions and 395 deletions

View File

@@ -1,4 +1,6 @@
import type { PageParam } from '@/api/index';
import {ShopCouponApplyCate} from "@/api/shop/shopCouponApplyCate/model";
import {ShopCouponApplyItem} from "@/api/shop/shopCouponApplyItem/model";
/**
* 优惠券
@@ -54,6 +56,8 @@ export interface ShopCoupon {
limitPerUser?: number;
// 是否启用(0禁用 1启用)
enabled?: string;
couponApplyCateList?: ShopCouponApplyCate[];
couponApplyItemList?: ShopCouponApplyItem[];
}
/**

View File

@@ -0,0 +1,11 @@
/**
* 优惠券
*/
export interface ShopCouponApplyCate {
id?: number;
couponId?: number;
cateId?: number;
cateLevel?: number;
}

View File

@@ -0,0 +1,11 @@
/**
* 优惠券
*/
export interface ShopCouponApplyItem {
id?: number;
couponId?: number;
type?: number;
pk?: number;
}

View File

@@ -0,0 +1,130 @@
import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { ShopGift, ShopGiftParam } from './model';
import { MODULES_API_URL } from '@/config/setting';
/**
* 分页查询礼品卡
*/
export async function pageShopGift(params: ShopGiftParam) {
const res = await request.get<ApiResult<PageResult<ShopGift>>>(
MODULES_API_URL + '/shop/shop-gift/page',
{
params
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询礼品卡列表
*/
export async function listShopGift(params?: ShopGiftParam) {
const res = await request.get<ApiResult<ShopGift[]>>(
MODULES_API_URL + '/shop/shop-gift',
{
params
}
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 添加礼品卡
*/
export async function addShopGift(data: ShopGift) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-gift',
data
);
if (res.data.code === 0) {
return res.data.message;
}
}
/**
* 生成礼品卡
*/
export async function makeShopGift(data: ShopGift) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-gift/make',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 修改礼品卡
*/
export async function updateShopGift(data: ShopGift) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-gift',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 删除礼品卡
*/
export async function removeShopGift(id?: number) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-gift/' + id
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 批量删除礼品卡
*/
export async function removeBatchShopGift(data: (number | undefined)[]) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-gift/batch',
{
data
}
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 根据id查询礼品卡
*/
export async function getShopGift(id: number) {
const res = await request.get<ApiResult<ShopGift>>(
MODULES_API_URL + '/shop/shop-gift/' + id
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
export async function exportShopGift(ids?: number[]) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-gift/export',
ids
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}

View File

@@ -0,0 +1,46 @@
import type { PageParam } from '@/api/index';
/**
* 礼品卡
*/
export interface ShopGift {
//
id?: number;
//
name?: string;
// 秘钥
code?: string;
// 商品ID
goodsId?: number;
// 领取时间
takeTime?: string;
// 操作人
operatorUserId?: number;
// 是否展示
isShow?: string;
// 状态, 0上架 1待上架 2待审核 3审核不通过
status?: number;
// 备注
comments?: string;
// 排序号
sortNumber?: number;
// 用户ID
userId?: number;
// 是否删除, 0否, 1是
deleted?: number;
// 租户id
tenantId?: number;
// 创建时间
createTime?: string;
// 修改时间
updateTime?: string;
num?: number;
}
/**
* 礼品卡搜索条件
*/
export interface ShopGiftParam extends PageParam {
id?: number;
keywords?: string;
}

View File

@@ -14,11 +14,7 @@
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
>
<a-form-item label="优惠券名称" name="name">
<a-input
allow-clear
@@ -33,22 +29,32 @@
v-model:value="form.description"
/>
</a-form-item>
<a-form-item label="优惠券类型(10满减券 20折扣券 30免费劵)" name="type">
<a-input
allow-clear
placeholder="请输入优惠券类型(10满减券 20折扣券 30免费劵)"
v-model:value="form.type"
/>
<a-form-item label="优惠券类型" name="type">
<a-select v-model:value="form.type">
<a-select-option :value="10">满减券</a-select-option>
<a-select-option :value="20">折扣券</a-select-option>
<a-select-option :value="30">免费劵</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="满减券-减免金额" name="reducePrice">
<a-form-item
v-if="form.type === 10"
label="减免金额"
name="reducePrice"
>
<a-input
allow-clear
placeholder="请输入满减券-减免金额"
v-model:value="form.reducePrice"
/>
</a-form-item>
<a-form-item label="折扣券-折扣率(0-100)" name="discount">
<a-input
<a-form-item
v-if="form.type === 20"
label="折扣券-折扣率(0-100)"
name="discount"
>
<a-input-number
min="0"
max="100"
allow-clear
placeholder="请输入折扣券-折扣率(0-100)"
v-model:value="form.discount"
@@ -61,90 +67,73 @@
v-model:value="form.minPrice"
/>
</a-form-item>
<a-form-item label="到期类型(10领取后生效 20固定时间)" name="expireType">
<a-input
allow-clear
placeholder="请输入到期类型(10领取后生效 20固定时间)"
v-model:value="form.expireType"
/>
<a-form-item label="到期类型" name="expireType">
<a-select v-model:value="form.expireType">
<a-select-option :value="10">领取后生效</a-select-option>
<a-select-option :value="20">固定时间</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="领取后生效-有效天数" name="expireDay">
<a-form-item
v-if="form.expireType === 10"
label="有效天数"
name="expireDay"
>
<a-input
allow-clear
placeholder="请输入领取后生效-有效天数"
v-model:value="form.expireDay"
/>
</a-form-item>
<a-form-item label="有效期开始时间" name="startTime">
<a-input
allow-clear
placeholder="请输入有效期开始时间"
v-model:value="form.startTime"
/>
<template v-if="form.expireType === 20">
<a-form-item label="有效期开始时间" name="startTime">
<a-input
allow-clear
placeholder="请输入有效期开始时间"
v-model:value="form.startTime"
/>
</a-form-item>
<a-form-item label="有效期结束时间" name="endTime">
<a-input
allow-clear
placeholder="请输入有效期结束时间"
v-model:value="form.endTime"
/>
</a-form-item>
</template>
<a-form-item
label="适用范围"
name="applyRange"
>
<a-select v-model:value="form.applyRange" placeholder="请选择适用范围">
<a-select-option :value="10">全部商品</a-select-option>
<a-select-option :value="20">指定商品</a-select-option>
<a-select-option :value="30">指定分类</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="有效期结束时间" name="endTime">
<a-input
allow-clear
placeholder="请输入有效期结束时间"
v-model:value="form.endTime"
/>
<a-form-item label="限制分类" v-if="form.applyRange === 30">
<a-cascader v-model:value="applyCateListValue" :options="goodsCateList" multiple
:fieldNames="{label: 'title', value: 'categoryId'}"/>
</a-form-item>
<a-form-item label="适用范围(10全部商品 20指定商品 30指定分类)" name="applyRange">
<a-input
allow-clear
placeholder="请输入适用范围(10全部商品 20指定商品 30指定分类)"
v-model:value="form.applyRange"
/>
<a-form-item label="限制单品" v-if="form.applyRange === 20">
<a-select mode="multiple"
v-model:value="applyItemListValue">
<a-select-option v-for="(item, index) in goodsList" :key="index" :value="item.goodsId">{{
item.name
}}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="适用范围配置(json格式)" name="applyRangeConfig">
<a-input
allow-clear
placeholder="请输入适用范围配置(json格式)"
v-model:value="form.applyRangeConfig"
/>
</a-form-item>
<a-form-item label="是否过期(0未过期 1已过期)" name="isExpire">
<a-input
allow-clear
placeholder="请输入是否过期(0未过期 1已过期)"
v-model:value="form.isExpire"
/>
</a-form-item>
<a-form-item label="排序(数字越小越靠前)" name="sortNumber">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
<a-form-item label="状态, 0正常, 1禁用" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="0">显示</a-radio>
<a-radio :value="1">隐藏</a-radio>
<a-form-item label="是否过期" name="isExpire">
<a-radio-group v-model:value="form.isExpire">
<a-radio :value="0">未过期</a-radio>
<a-radio :value="1">已过期</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
<a-form-item label="创建用户ID" name="userId">
<a-input
allow-clear
placeholder="请输入创建用户ID"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="修改时间" name="updateTime">
<a-input
allow-clear
placeholder="请输入修改时间"
v-model:value="form.updateTime"
/>
<a-form-item label="状态" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="0">正常</a-radio>
<a-radio :value="1">禁用</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="发放总数量(-1表示无限制)" name="totalCount">
<a-input
@@ -153,13 +142,6 @@
v-model:value="form.totalCount"
/>
</a-form-item>
<a-form-item label="已发放数量" name="issuedCount">
<a-input
allow-clear
placeholder="请输入已发放数量"
v-model:value="form.issuedCount"
/>
</a-form-item>
<a-form-item label="每人限领数量(-1表示无限制)" name="limitPerUser">
<a-input
allow-clear
@@ -167,11 +149,19 @@
v-model:value="form.limitPerUser"
/>
</a-form-item>
<a-form-item label="是否启用(0禁用 1启用)" name="enabled">
<a-input
allow-clear
placeholder="请输入是否启用(0禁用 1启用)"
v-model:value="form.enabled"
<a-form-item label="是否启用" name="enabled">
<a-radio-group v-model:value="form.enabled">
<a-radio :value="0">禁用</a-radio>
<a-radio :value="1">启用</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="排序(数字越小越靠前)" name="sortNumber">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
</a-form>
@@ -189,6 +179,10 @@
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
import {ShopGoods} from "@/api/shop/shopGoods/model";
import {listShopGoods} from "@/api/shop/shopGoods";
import {ShopGoodsCategory} from "@/api/shop/shopGoodsCategory/model";
import {listShopGoodsCategory} from "@/api/shop/shopGoodsCategory";
// 是否是修改
const isUpdate = ref(false);
@@ -222,31 +216,29 @@
id: undefined,
name: undefined,
description: undefined,
type: undefined,
type: 10,
reducePrice: undefined,
discount: undefined,
minPrice: undefined,
expireType: undefined,
expireType: 10,
expireDay: undefined,
startTime: undefined,
endTime: undefined,
applyRange: undefined,
applyRange: 10,
applyRangeConfig: undefined,
isExpire: undefined,
sortNumber: undefined,
status: undefined,
isExpire: 0,
sortNumber: 100,
status: 0,
deleted: undefined,
userId: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
totalCount: undefined,
totalCount: -1,
issuedCount: undefined,
limitPerUser: undefined,
enabled: undefined,
shopCouponId: undefined,
limitPerUser: 1,
enabled: 1,
shopCouponName: '',
status: 0,
comments: '',
sortNumber: 100
});
@@ -296,6 +288,22 @@
const formData = {
...form
};
if (applyItemListValue.value.length) {
formData.couponApplyItemList = applyItemListValue.value.map(pk => {
return {
pk,
type: 0
}
});
}else formData.couponApplyItemList = []
if (applyCateListValue.value.length) {
formData.couponApplyCateList = applyCateListValue.value.map(cateId => {
return {
cateId,
cateLevel: 0
}
});
}else formData.couponApplyCateList = []
const saveOrUpdate = isUpdate.value ? updateShopCoupon : addShopCoupon;
saveOrUpdate(formData)
.then((msg) => {
@@ -312,25 +320,51 @@
.catch(() => {});
};
const applyItemListValue = ref<any[]>([])
const goodsList = ref<ShopGoods[]>([]);
const getGoodsList = async() => {
goodsList.value = await listShopGoods()
};
const applyCateListValue = ref<any[]>([])
const goodsCateList = ref<ShopGoodsCategory[]>([]);
const getGoodsCateList = async() => {
goodsCateList.value = await listShopGoodsCategory()
};
watch(
() => props.visible,
(visible) => {
async(visible) => {
if (visible) {
images.value = [];
await getGoodsList()
await getGoodsCateList()
if (props.data) {
assignObject(form, props.data);
if(props.data.image){
if (props.data.image) {
images.value.push({
uid: uuid(),
url: props.data.image,
status: 'done'
})
});
}
isUpdate.value = true;
if (props.data.couponApplyCateList && props.data.couponApplyCateList.length > 0) {
props.data.couponApplyCateList.forEach(item => {
applyCateListValue.value.push(item.cateId)
})
}
if (props.data.couponApplyItemList && props.data.couponApplyItemList.length > 0) {
props.data.couponApplyItemList.forEach(item => {
applyItemListValue.value.push(item.pk)
})
}
} else {
isUpdate.value = false;
}
} else {
applyCateListValue.value = []
applyItemListValue.value = []
resetFields();
}
},

View File

@@ -119,19 +119,30 @@
align: 'center',
},
{
title: '优惠券类型(10满减券 20折扣券 30免费劵)',
title: '优惠券类型',
dataIndex: 'type',
key: 'type',
align: 'center',
customRender: ({ text }) => {
switch (text) {
case 10:
return '满减券';
case 20:
return '折扣券';
case 30:
return '免费劵';
}
}
},
{
title: '满减券-减免金额',
title: '满减券',
dataIndex: 'reducePrice',
key: 'reducePrice',
align: 'center',
customRender: ({ text }) => text.toFixed(2)
},
{
title: '折扣券-折扣率(0-100)',
title: '折扣券',
dataIndex: 'discount',
key: 'discount',
align: 'center',
@@ -143,13 +154,21 @@
align: 'center',
},
{
title: '到期类型(10领取后生效 20固定时间)',
title: '到期类型',
dataIndex: 'expireType',
key: 'expireType',
align: 'center',
customRender: ({ text }) => {
switch (text) {
case 10:
return '领取后生效';
case 20:
return '固定时间';
}
}
},
{
title: '领取后生效-有效天数',
title: '有效天数',
dataIndex: 'expireDay',
key: 'expireDay',
align: 'center',
@@ -167,46 +186,34 @@
align: 'center',
},
{
title: '适用范围(10全部商品 20指定商品 30指定分类)',
title: '适用范围',
dataIndex: 'applyRange',
key: 'applyRange',
align: 'center',
customRender: ({ text }) => {
switch (text) {
case 10:
return '全部商品';
case 20:
return '指定商品';
case 30:
return '指定分类';
}
}
},
{
title: '适用范围配置(json格式)',
dataIndex: 'applyRangeConfig',
key: 'applyRangeConfig',
align: 'center',
},
{
title: '是否过期(0未过期 1已过期)',
title: '是否过期',
dataIndex: 'isExpire',
key: 'isExpire',
align: 'center',
},
{
title: '排序(数字越小越靠前)',
dataIndex: 'sortNumber',
key: 'sortNumber',
align: 'center',
},
{
title: '状态, 0正常, 1禁用',
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
},
{
title: '创建用户ID',
dataIndex: 'userId',
key: 'userId',
align: 'center',
customRender: ({ text }) => {
switch (text) {
case 0:
return '未过期';
case 1:
return '已过期';
}
}
},
{
title: '创建时间',
@@ -241,12 +248,6 @@
key: 'limitPerUser',
align: 'center',
},
{
title: '是否启用(0禁用 1启用)',
dataIndex: 'enabled',
key: 'enabled',
align: 'center',
},
{
title: '操作',
key: 'action',

View File

@@ -0,0 +1,140 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
title="生成礼品卡"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="名称" name="name">
<a-input allow-clear placeholder="请输入" v-model:value="form.name" />
</a-form-item>
<a-form-item label="商品" name="goodsId">
<a-select v-model:value="form.goodsId">
<a-select-option
v-for="item in goodsList"
:key="item.goodsId"
:value="item.goodsId"
>
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="数量" name="num">
<a-input-number v-model:value="form.num" :min="0" />
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { makeShopGift } from '@/api/shop/shopGift';
import { ShopGift } from '@/api/shop/shopGift/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance } from 'ant-design-vue/es/form';
import { listShopGoods } from '@/api/shop/shopGoods';
import { ShopGoods } from '@/api/shop/shopGoods/model';
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const rules = reactive({
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
goodsId: [{ required: true, message: '请选择商品', trigger: 'change' }],
num: [{ required: true, message: '请输入数量', trigger: 'blur' }]
});
// 用户信息
const form = reactive<ShopGift>({
id: undefined,
name: undefined,
code: undefined,
goodsId: undefined,
takeTime: undefined,
operatorUserId: undefined,
isShow: undefined,
status: undefined,
comments: undefined,
sortNumber: undefined,
userId: undefined,
deleted: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
num: undefined
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
const goodsList = ref<ShopGoods[]>([]);
const getGoodsList = async () => {
goodsList.value = await listShopGoods();
};
getGoodsList();
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
makeShopGift(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(() => props.visible, { immediate: true });
</script>

View File

@@ -0,0 +1,75 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
<a-button class="ele-btn-icon" @click="openMultiAdd">
<span>批量生成</span>
</a-button>
<a-button class="ele-btn-icon" @click="exportData">
<span>导出</span>
</a-button>
<MakeCard v-model:visible="showMultiAdd" @done="done"></MakeCard>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import { watch, ref } from 'vue';
import {ShopGift, ShopGiftParam} from "@/api/shop/shopGift/model";
import MakeCard from "@/views/shop/shopGift/components/makeCard.vue";
import {exportShopGift} from "@/api/shop/shopGift";
import {message} from "ant-design-vue";
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: ShopGift[];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: ShopGiftParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
(e: 'done'): void;
}>();
// 新增
const add = () => {
emit('add');
};
const done = () => {
emit('done');
};
const showMultiAdd = ref(false)
const openMultiAdd = () => {
showMultiAdd.value = true
};
const exportData = async () => {
const hide = message.loading('请求中..', 0);
const ids = []
if (props.selection && props.selection.length) {
props.selection.forEach(d => {
ids.push(d.id)
})
}
const res = await exportShopGift(ids);
window.open(res.url);
hide();
}
watch(
() => props.selection,
() => {}
);
</script>

View File

@@ -0,0 +1,260 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑礼品卡' : '添加礼品卡'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="" name="name">
<a-input
allow-clear
placeholder="请输入"
v-model:value="form.name"
/>
</a-form-item>
<a-form-item label="秘钥" name="code">
<a-input
allow-clear
placeholder="请输入秘钥"
v-model:value="form.code"
/>
</a-form-item>
<a-form-item label="商品ID" name="goodsId">
<a-input
allow-clear
placeholder="请输入商品ID"
v-model:value="form.goodsId"
/>
</a-form-item>
<a-form-item label="领取时间" name="takeTime">
<a-input
allow-clear
placeholder="请输入领取时间"
v-model:value="form.takeTime"
/>
</a-form-item>
<a-form-item label="操作人" name="operatorUserId">
<a-input
allow-clear
placeholder="请输入操作人"
v-model:value="form.operatorUserId"
/>
</a-form-item>
<a-form-item label="是否展示" name="isShow">
<a-input
allow-clear
placeholder="请输入是否展示"
v-model:value="form.isShow"
/>
</a-form-item>
<a-form-item label="状态, 0上架 1待上架 2待审核 3审核不通过" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="0">显示</a-radio>
<a-radio :value="1">隐藏</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="备注" name="comments">
<a-textarea
:rows="4"
:maxlength="200"
placeholder="请输入描述"
v-model:value="form.comments"
/>
</a-form-item>
<a-form-item label="排序号" name="sortNumber">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
<a-form-item label="用户ID" name="userId">
<a-input
allow-clear
placeholder="请输入用户ID"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
<a-form-item label="修改时间" name="updateTime">
<a-input
allow-clear
placeholder="请输入修改时间"
v-model:value="form.updateTime"
/>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject, uuid } from 'ele-admin-pro';
import { addShopGift, updateShopGift } from '@/api/shop/shopGift';
import { ShopGift } from '@/api/shop/shopGift/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: ShopGift | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
const images = ref<ItemType[]>([]);
// 用户信息
const form = reactive<ShopGift>({
id: undefined,
name: undefined,
code: undefined,
goodsId: undefined,
takeTime: undefined,
operatorUserId: undefined,
isShow: undefined,
status: undefined,
comments: undefined,
sortNumber: undefined,
userId: undefined,
deleted: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
shopGiftId: undefined,
shopGiftName: '',
status: 0,
comments: '',
sortNumber: 100
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
shopGiftName: [
{
required: true,
type: 'string',
message: '请填写礼品卡名称',
trigger: 'blur'
}
]
});
const chooseImage = (data: FileRecord) => {
images.value.push({
uid: data.id,
url: data.path,
status: 'done'
});
form.image = data.path;
};
const onDeleteItem = (index: number) => {
images.value.splice(index, 1);
form.image = '';
};
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateShopGift : addShopGift;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
images.value = [];
if (props.data) {
assignObject(form, props.data);
if(props.data.image){
images.value.push({
uid: uuid(),
url: props.data.image,
status: 'done'
})
}
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>

View File

@@ -0,0 +1,240 @@
<template>
<a-page-header :title="getPageTitle()" @back="() => $router.go(-1)">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="id"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
v-model:selection="selection"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
@done="reload"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<ShopGiftEdit v-model:visible="showEdit" :data="current" @done="reload" />
</a-page-header>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import {getPageTitle} from '@/utils/common';
import ShopGiftEdit from './components/shopGiftEdit.vue';
import { pageShopGift, removeShopGift, removeBatchShopGift } from '@/api/shop/shopGift';
import type { ShopGift, ShopGiftParam } from '@/api/shop/shopGift/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<ShopGift[]>([]);
// 当前编辑数据
const current = ref<ShopGift | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageShopGift({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'ID',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 90,
},
{
title: '名称',
dataIndex: 'name',
key: 'name',
align: 'center',
},
{
title: '秘钥',
dataIndex: 'code',
key: 'code',
align: 'center',
},
{
title: '商品',
dataIndex: ['goods', 'name'],
key: 'goodsId',
align: 'center',
},
{
title: '领取时间',
dataIndex: 'takeTime',
key: 'takeTime',
align: 'center',
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ShopGiftParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: ShopGift) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ShopGift) => {
const hide = message.loading('请求中..', 0);
removeShopGift(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchShopGift(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ShopGift) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'ShopGift'
};
</script>
<style lang="less" scoped></style>