后台管理页面商品管理初版
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
<a-image
|
||||
:width="60"
|
||||
:height="60"
|
||||
:src="record.image || DEFAULT_PRODUCT_IMAGE"
|
||||
:src="record.imageFileIds ? record.imageFileIds.split(',')[0] : DEFAULT_PRODUCT_IMAGE"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
/>
|
||||
</template>
|
||||
@@ -42,11 +42,7 @@
|
||||
¥{{ record.price }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">
|
||||
{{ record.status === 1 ? '上架' : '下架' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
@@ -81,8 +77,8 @@
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="商品名称" name="name">
|
||||
<a-input v-model:value="formState.name" placeholder="请输入商品名称" />
|
||||
<a-form-item label="商品名称" name="title">
|
||||
<a-input v-model:value="formState.title" placeholder="请输入商品名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="商品描述" name="description">
|
||||
<a-textarea
|
||||
@@ -91,8 +87,8 @@
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品图片" name="image">
|
||||
<a-input v-model:value="formState.image" placeholder="请输入图片URL" />
|
||||
<a-form-item label="图片ID" name="imageFileIds">
|
||||
<a-input v-model:value="formState.imageFileIds" placeholder="请输入图片文件ID,多个用逗号分隔" />
|
||||
</a-form-item>
|
||||
<a-form-item label="价格" name="price">
|
||||
<a-input-number
|
||||
@@ -103,23 +99,14 @@
|
||||
placeholder="请输入价格"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="预计时长(分钟)" name="estimatedTime">
|
||||
<a-input-number
|
||||
v-model:value="formState.estimatedTime"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
placeholder="请输入预计时长"
|
||||
/>
|
||||
<a-form-item label="预计时长" name="approximateDuration">
|
||||
<a-input v-model:value="formState.approximateDuration" placeholder="例如:30分钟" />
|
||||
</a-form-item>
|
||||
<a-form-item label="分类" name="category">
|
||||
<a-select v-model:value="formState.category" placeholder="请选择分类">
|
||||
<a-select-option value="美甲">美甲</a-select-option>
|
||||
<a-select-option value="美睫">美睫</a-select-option>
|
||||
<a-select-option value="手足护理">手足护理</a-select-option>
|
||||
</a-select>
|
||||
<a-form-item label="标签ID" name="tags">
|
||||
<a-input v-model:value="formState.tags" placeholder="请输入标签ID,多个用分号分隔" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="status">
|
||||
<a-switch v-model:checked="formState.status" checked-children="上架" un-checked-children="下架" />
|
||||
<a-form-item label="店铺ID" name="shopId">
|
||||
<a-input-number v-model:value="formState.shopId" :min="1" style="width: 100%" placeholder="请输入店铺ID" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
@@ -132,16 +119,16 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import { productApi, type ProductVO } from '@/api/product'
|
||||
import { adminProductApi, type Product } from '@/api/admin'
|
||||
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<ProductVO[]>([])
|
||||
const productList = ref<Product[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentProduct = ref<ProductVO | null>(null)
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -153,31 +140,32 @@ const pagination = reactive({
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
name: '',
|
||||
shopId: 1,
|
||||
title: '',
|
||||
description: '',
|
||||
image: '',
|
||||
imageFileIds: '',
|
||||
price: 0,
|
||||
estimatedTime: 30,
|
||||
category: '美甲',
|
||||
status: true,
|
||||
shopId: null as number | null
|
||||
tags: '',
|
||||
approximateDuration: '',
|
||||
bookableArtists: '',
|
||||
availableCoupons: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入商品描述', trigger: 'blur' }],
|
||||
price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
|
||||
estimatedTime: [{ required: true, message: '请输入预计时长', trigger: 'blur' }],
|
||||
category: [{ required: true, message: '请选择分类', trigger: 'change' }]
|
||||
shopId: [{ required: true, message: '请输入店铺ID', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '图片', key: 'image', width: 100 },
|
||||
{ title: '商品名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '分类', dataIndex: 'category', key: 'category', width: 100 },
|
||||
{ title: '商品名称', dataIndex: 'title', key: 'title' },
|
||||
{ title: '描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '价格', key: 'price', width: 100 },
|
||||
{ title: '预计时长', dataIndex: 'estimatedTime', key: 'estimatedTime', width: 120, customRender: ({ text }: { text: number }) => `${text}分钟` },
|
||||
{ title: '状态', key: 'status', width: 80 },
|
||||
{ title: '预计时长', dataIndex: 'approximateDuration', key: 'approximateDuration', width: 120 },
|
||||
{ title: '点赞', dataIndex: 'likeCount', key: 'likeCount', width: 80 },
|
||||
{ title: '收藏', dataIndex: 'collectCount', key: 'collectCount', width: 80 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
@@ -185,7 +173,7 @@ const columns = [
|
||||
const fetchProductList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await productApi.listProducts({
|
||||
const res = await adminProductApi.listProducts({
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
@@ -213,30 +201,32 @@ const handleTableChange = (pag: any) => {
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
name: '',
|
||||
shopId: 1,
|
||||
title: '',
|
||||
description: '',
|
||||
image: '',
|
||||
imageFileIds: '',
|
||||
price: 0,
|
||||
estimatedTime: 30,
|
||||
category: '美甲',
|
||||
status: true,
|
||||
shopId: null
|
||||
tags: '',
|
||||
approximateDuration: '',
|
||||
bookableArtists: '',
|
||||
availableCoupons: ''
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: ProductVO) => {
|
||||
const showEditModal = (record: Product) => {
|
||||
isEdit.value = true
|
||||
currentProduct.value = record
|
||||
Object.assign(formState, {
|
||||
name: record.name,
|
||||
shopId: record.shopId,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
image: record.image,
|
||||
imageFileIds: record.imageFileIds,
|
||||
price: record.price,
|
||||
estimatedTime: record.estimatedTime,
|
||||
category: record.category,
|
||||
status: record.status === 1,
|
||||
shopId: record.shopId
|
||||
tags: record.tags,
|
||||
approximateDuration: record.approximateDuration,
|
||||
bookableArtists: record.bookableArtists,
|
||||
availableCoupons: record.availableCoupons
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -246,16 +236,11 @@ const handleModalOk = async () => {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
const data = {
|
||||
...formState,
|
||||
status: formState.status ? 1 : 0
|
||||
}
|
||||
|
||||
if (isEdit.value && currentProduct.value) {
|
||||
await productApi.updateProduct(currentProduct.value.id, data)
|
||||
await adminProductApi.updateProduct(currentProduct.value.id, formState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await productApi.createProduct(data)
|
||||
await adminProductApi.createProduct(formState)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
@@ -273,9 +258,9 @@ const handleModalCancel = () => {
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = async (record: ProductVO) => {
|
||||
const handleDelete = async (record: Product) => {
|
||||
try {
|
||||
await productApi.deleteProduct(record.id)
|
||||
await adminProductApi.deleteProduct(record.id)
|
||||
message.success('删除成功')
|
||||
fetchProductList()
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user