feat: 分类管理添加是否可跨分类购物选项
This commit is contained in:
@@ -49,16 +49,17 @@ func (h *CategoryHandler) Create(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
category := models.Category{
|
category := models.Category{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
ParentID: req.ParentID,
|
ParentID: req.ParentID,
|
||||||
MinAmount: req.MinAmount,
|
MinAmount: req.MinAmount,
|
||||||
MaxAmount: req.MaxAmount,
|
MaxAmount: req.MaxAmount,
|
||||||
MinQuantity: req.MinQuantity,
|
MinQuantity: req.MinQuantity,
|
||||||
MaxQuantity: req.MaxQuantity,
|
MaxQuantity: req.MaxQuantity,
|
||||||
MinWeight: req.MinWeight,
|
MinWeight: req.MinWeight,
|
||||||
MaxWeight: req.MaxWeight,
|
MaxWeight: req.MaxWeight,
|
||||||
SortOrder: req.SortOrder,
|
AllowCrossCategory: req.AllowCrossCategory != nil && *req.AllowCrossCategory,
|
||||||
|
SortOrder: req.SortOrder,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.DB.Create(&category).Error; err != nil {
|
if err := utils.DB.Create(&category).Error; err != nil {
|
||||||
@@ -122,6 +123,9 @@ func (h *CategoryHandler) Update(c *gin.Context) {
|
|||||||
if req.SortOrder != nil {
|
if req.SortOrder != nil {
|
||||||
updates["sort_order"] = *req.SortOrder
|
updates["sort_order"] = *req.SortOrder
|
||||||
}
|
}
|
||||||
|
if req.AllowCrossCategory != nil {
|
||||||
|
updates["allow_cross_category"] = *req.AllowCrossCategory
|
||||||
|
}
|
||||||
|
|
||||||
utils.DB.Model(&category).Updates(updates)
|
utils.DB.Model(&category).Updates(updates)
|
||||||
c.JSON(http.StatusOK, gin.H{"data": category})
|
c.JSON(http.StatusOK, gin.H{"data": category})
|
||||||
|
|||||||
@@ -7,22 +7,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
ID uint `gorm:"primaryKey" json:"id"`
|
ID uint `gorm:"primaryKey" json:"id"`
|
||||||
Name string `gorm:"size:100;not null;uniqueIndex" json:"name"`
|
Name string `gorm:"size:100;not null;uniqueIndex" json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ParentID *uint `json:"parent_id"`
|
ParentID *uint `json:"parent_id"`
|
||||||
MinAmount *float64 `json:"min_amount"`
|
MinAmount *float64 `json:"min_amount"`
|
||||||
MaxAmount *float64 `json:"max_amount"`
|
MaxAmount *float64 `json:"max_amount"`
|
||||||
MinQuantity *int `json:"min_quantity"`
|
MinQuantity *int `json:"min_quantity"`
|
||||||
MaxQuantity *int `json:"max_quantity"`
|
MaxQuantity *int `json:"max_quantity"`
|
||||||
MinWeight *float64 `json:"min_weight"`
|
MinWeight *float64 `json:"min_weight"`
|
||||||
MaxWeight *float64 `json:"max_weight"`
|
MaxWeight *float64 `json:"max_weight"`
|
||||||
SortOrder int `gorm:"default:0" json:"sort_order"`
|
AllowCrossCategory bool `gorm:"default:false" json:"allow_cross_category"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
SortOrder int `gorm:"default:0" json:"sort_order"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
ProductCount int64 `gorm:"-" json:"product_count"`
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||||
Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
ProductCount int64 `gorm:"-" json:"product_count"`
|
||||||
|
Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Category) TableName() string {
|
func (Category) TableName() string {
|
||||||
|
|||||||
@@ -1,29 +1,31 @@
|
|||||||
package schemas
|
package schemas
|
||||||
|
|
||||||
type CreateCategoryRequest struct {
|
type CreateCategoryRequest struct {
|
||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" binding:"required"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ParentID *uint `json:"parent_id"`
|
ParentID *uint `json:"parent_id"`
|
||||||
MinAmount *float64 `json:"min_amount"`
|
MinAmount *float64 `json:"min_amount"`
|
||||||
MaxAmount *float64 `json:"max_amount"`
|
MaxAmount *float64 `json:"max_amount"`
|
||||||
MinQuantity *int `json:"min_quantity"`
|
MinQuantity *int `json:"min_quantity"`
|
||||||
MaxQuantity *int `json:"max_quantity"`
|
MaxQuantity *int `json:"max_quantity"`
|
||||||
MinWeight *float64 `json:"min_weight"`
|
MinWeight *float64 `json:"min_weight"`
|
||||||
MaxWeight *float64 `json:"max_weight"`
|
MaxWeight *float64 `json:"max_weight"`
|
||||||
SortOrder int `json:"sort_order"`
|
AllowCrossCategory *bool `json:"allow_cross_category"`
|
||||||
|
SortOrder int `json:"sort_order"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCategoryRequest struct {
|
type UpdateCategoryRequest struct {
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
ParentID *uint `json:"parent_id"`
|
ParentID *uint `json:"parent_id"`
|
||||||
MinAmount *float64 `json:"min_amount"`
|
MinAmount *float64 `json:"min_amount"`
|
||||||
MaxAmount *float64 `json:"max_amount"`
|
MaxAmount *float64 `json:"max_amount"`
|
||||||
MinQuantity *int `json:"min_quantity"`
|
MinQuantity *int `json:"min_quantity"`
|
||||||
MaxQuantity *int `json:"max_quantity"`
|
MaxQuantity *int `json:"max_quantity"`
|
||||||
MinWeight *float64 `json:"min_weight"`
|
MinWeight *float64 `json:"min_weight"`
|
||||||
MaxWeight *float64 `json:"max_weight"`
|
MaxWeight *float64 `json:"max_weight"`
|
||||||
SortOrder *int `json:"sort_order"`
|
AllowCrossCategory *bool `json:"allow_cross_category"`
|
||||||
|
SortOrder *int `json:"sort_order"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateProductRequest struct {
|
type CreateProductRequest struct {
|
||||||
|
|||||||
@@ -14,6 +14,13 @@
|
|||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="跨分类购物" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag :type="row.allow_cross_category ? 'success' : 'info'" size="small">
|
||||||
|
{{ row.allow_cross_category ? '允许' : '不允许' }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="操作" width="120">
|
<el-table-column label="操作" width="120">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button link type="primary" size="small" @click="editCat(row)">编辑</el-button>
|
<el-button link type="primary" size="small" @click="editCat(row)">编辑</el-button>
|
||||||
@@ -41,6 +48,9 @@
|
|||||||
<el-form-item label="最大数量"><el-input-number v-model="form.max_quantity" /></el-form-item>
|
<el-form-item label="最大数量"><el-input-number v-model="form.max_quantity" /></el-form-item>
|
||||||
<el-form-item label="最小重量"><el-input-number v-model="form.min_weight" :precision="2" /></el-form-item>
|
<el-form-item label="最小重量"><el-input-number v-model="form.min_weight" :precision="2" /></el-form-item>
|
||||||
<el-form-item label="最大重量"><el-input-number v-model="form.max_weight" :precision="2" /></el-form-item>
|
<el-form-item label="最大重量"><el-input-number v-model="form.max_weight" :precision="2" /></el-form-item>
|
||||||
|
<el-form-item label="跨分类购物">
|
||||||
|
<el-switch v-model="form.allow_cross_category" active-text="允许" inactive-text="不允许" />
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="showAdd = false">取消</el-button>
|
<el-button @click="showAdd = false">取消</el-button>
|
||||||
@@ -65,7 +75,7 @@ const paginatedCategories = computed(() => {
|
|||||||
const start = (page.value - 1) * pageSize
|
const start = (page.value - 1) * pageSize
|
||||||
return categories.value.slice(start, start + pageSize)
|
return categories.value.slice(start, start + pageSize)
|
||||||
})
|
})
|
||||||
const form = reactive({ name: '', description: '', min_amount: undefined as number | undefined, max_amount: undefined as number | undefined, min_quantity: undefined as number | undefined, max_quantity: undefined as number | undefined, min_weight: undefined as number | undefined, max_weight: undefined as number | undefined })
|
const form = reactive({ name: '', description: '', min_amount: undefined as number | undefined, max_amount: undefined as number | undefined, min_quantity: undefined as number | undefined, max_quantity: undefined as number | undefined, min_weight: undefined as number | undefined, max_weight: undefined as number | undefined, allow_cross_category: false })
|
||||||
|
|
||||||
function handlePageChange() {
|
function handlePageChange() {
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
@@ -78,13 +88,13 @@ async function fetchCategories() {
|
|||||||
|
|
||||||
function openAdd() {
|
function openAdd() {
|
||||||
editing.value = null
|
editing.value = null
|
||||||
Object.assign(form, { name: '', description: '', min_amount: undefined, max_amount: undefined, min_quantity: undefined, max_quantity: undefined, min_weight: undefined, max_weight: undefined })
|
Object.assign(form, { name: '', description: '', min_amount: undefined, max_amount: undefined, min_quantity: undefined, max_quantity: undefined, min_weight: undefined, max_weight: undefined, allow_cross_category: false })
|
||||||
showAdd.value = true
|
showAdd.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function editCat(row: any) {
|
function editCat(row: any) {
|
||||||
editing.value = row
|
editing.value = row
|
||||||
Object.assign(form, { name: row.name, description: row.description || '', min_amount: row.min_amount, max_amount: row.max_amount, min_quantity: row.min_quantity, max_quantity: row.max_quantity, min_weight: row.min_weight, max_weight: row.max_weight })
|
Object.assign(form, { name: row.name, description: row.description || '', min_amount: row.min_amount, max_amount: row.max_amount, min_quantity: row.min_quantity, max_quantity: row.max_quantity, min_weight: row.min_weight, max_weight: row.max_weight, allow_cross_category: row.allow_cross_category || false })
|
||||||
showAdd.value = true
|
showAdd.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user