feat:商品
parent
81ea6ce81e
commit
9cd7f4d5b8
@ -0,0 +1,5 @@
|
|||||||
|
package goods
|
||||||
|
|
||||||
|
type ApiGroup struct {
|
||||||
|
GoodsShowApi
|
||||||
|
}
|
||||||
@ -0,0 +1,151 @@
|
|||||||
|
package goods
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"pychr/global"
|
||||||
|
"pychr/model/common/response"
|
||||||
|
"pychr/model/goods"
|
||||||
|
goodsReq "pychr/model/goods/request"
|
||||||
|
"pychr/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GoodsShowApi struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var goodsShowService = service.ServiceGroupApp.GoodsServiceGroup.GoodsShowService
|
||||||
|
|
||||||
|
// CreateGoodsShow 创建商品
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 创建商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body goods.GoodsShow true "创建商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||||
|
// @Router /goodsShow/createGoodsShow [post]
|
||||||
|
func (goodsShowApi *GoodsShowApi) CreateGoodsShow(c *gin.Context) {
|
||||||
|
var goodsShow goods.GoodsShow
|
||||||
|
err := c.ShouldBindJSON(&goodsShow)
|
||||||
|
if err != nil {
|
||||||
|
response.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := goodsShowService.CreateGoodsShow(&goodsShow); err != nil {
|
||||||
|
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("创建失败", c)
|
||||||
|
} else {
|
||||||
|
response.OkWithMessage("创建成功", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGoodsShow 删除商品
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 删除商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body goods.GoodsShow true "删除商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||||
|
// @Router /goodsShow/deleteGoodsShow [delete]
|
||||||
|
func (goodsShowApi *GoodsShowApi) DeleteGoodsShow(c *gin.Context) {
|
||||||
|
ID := c.Query("ID")
|
||||||
|
if err := goodsShowService.DeleteGoodsShow(ID); err != nil {
|
||||||
|
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("删除失败", c)
|
||||||
|
} else {
|
||||||
|
response.OkWithMessage("删除成功", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGoodsShowByIds 批量删除商品
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 批量删除商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
|
||||||
|
// @Router /goodsShow/deleteGoodsShowByIds [delete]
|
||||||
|
func (goodsShowApi *GoodsShowApi) DeleteGoodsShowByIds(c *gin.Context) {
|
||||||
|
IDs := c.QueryArray("IDs[]")
|
||||||
|
if err := goodsShowService.DeleteGoodsShowByIds(IDs); err != nil {
|
||||||
|
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("批量删除失败", c)
|
||||||
|
} else {
|
||||||
|
response.OkWithMessage("批量删除成功", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGoodsShow 更新商品
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 更新商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body goods.GoodsShow true "更新商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||||
|
// @Router /goodsShow/updateGoodsShow [put]
|
||||||
|
func (goodsShowApi *GoodsShowApi) UpdateGoodsShow(c *gin.Context) {
|
||||||
|
var goodsShow goods.GoodsShow
|
||||||
|
err := c.ShouldBindJSON(&goodsShow)
|
||||||
|
if err != nil {
|
||||||
|
response.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := goodsShowService.UpdateGoodsShow(goodsShow); err != nil {
|
||||||
|
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("更新失败", c)
|
||||||
|
} else {
|
||||||
|
response.OkWithMessage("更新成功", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindGoodsShow 用id查询商品
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 用id查询商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data query goods.GoodsShow true "用id查询商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||||
|
// @Router /goodsShow/findGoodsShow [get]
|
||||||
|
func (goodsShowApi *GoodsShowApi) FindGoodsShow(c *gin.Context) {
|
||||||
|
ID := c.Query("ID")
|
||||||
|
if regoodsShow, err := goodsShowService.GetGoodsShow(ID); err != nil {
|
||||||
|
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("查询失败", c)
|
||||||
|
} else {
|
||||||
|
response.OkWithData(gin.H{"regoodsShow": regoodsShow}, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsShowList 分页获取商品列表
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 分页获取商品列表
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data query goodsReq.GoodsShowSearch true "分页获取商品列表"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||||
|
// @Router /goodsShow/getGoodsShowList [get]
|
||||||
|
func (goodsShowApi *GoodsShowApi) GetGoodsShowList(c *gin.Context) {
|
||||||
|
var pageInfo goodsReq.GoodsShowSearch
|
||||||
|
err := c.ShouldBindQuery(&pageInfo)
|
||||||
|
if err != nil {
|
||||||
|
response.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if list, total, err := goodsShowService.GetGoodsShowInfoList(pageInfo); err != nil {
|
||||||
|
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("获取失败", c)
|
||||||
|
} else {
|
||||||
|
response.OkWithDetailed(response.PageResult{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
Page: pageInfo.Page,
|
||||||
|
PageSize: pageInfo.PageSize,
|
||||||
|
}, "获取成功", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package common
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
// 自动生成模板GoodsShow
|
||||||
|
package goods
|
||||||
|
|
||||||
|
import (
|
||||||
|
"pychr/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 商品 结构体 GoodsShow
|
||||||
|
type GoodsShow struct {
|
||||||
|
global.GVA_MODEL
|
||||||
|
LangType int `json:"langType" form:"langType" gorm:"column:lang_type;comment:语言类型 1中文 2英文;size:10;" binding:"required"` // 语言类型 1中文 2英文
|
||||||
|
GoodsMainPic string `json:"goodsMainPic" form:"goodsMainPic" gorm:"column:goods_main_pic;comment:商品主图;size:191;"` // 商品主图
|
||||||
|
Name string `json:"name" form:"name" gorm:"column:name;comment:商品名称;size:191;" binding:"required"` // 商品名称
|
||||||
|
BriefIntroduction string `json:"briefIntroduction" form:"briefIntroduction" gorm:"column:brief_introduction;comment:简介;size:191;"` // 简介
|
||||||
|
Type int `json:"type" form:"type" gorm:"column:type;comment:类型;size:10;" binding:"required"` // 类型
|
||||||
|
MainIntroduction string `json:"mainIntroduction" form:"mainIntroduction" gorm:"column:main_introduction;comment:主介绍;size:191;"` // 主介绍
|
||||||
|
GoodsAssistantPic string `json:"goodsAssistantPic" form:"goodsAssistantPic" gorm:"column:goods_assistantPic;comment:商品副图;size:191;"` // 商品副图
|
||||||
|
SecondIntroductionTitle string `json:"secondIntroductionTitle" form:"secondIntroductionTitle" gorm:"column:second_introduction_title;comment:副介绍标题;size:191;"` // 副介绍标题
|
||||||
|
SecondIntroduction string `json:"secondIntroduction" form:"secondIntroduction" gorm:"column:second_introduction;comment:副介绍,逗号拼接;size:191;"` // 副介绍,逗号拼接
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName 商品 GoodsShow自定义表名 goods_show
|
||||||
|
func (GoodsShow) TableName() string {
|
||||||
|
return "goods_show"
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package request
|
||||||
|
|
||||||
|
import (
|
||||||
|
"pychr/model/common/request"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GoodsShowSearch struct {
|
||||||
|
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
|
||||||
|
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
|
||||||
|
LangType int `json:"langType" form:"langType" `
|
||||||
|
Name string `json:"name" form:"name" `
|
||||||
|
Type int `json:"type" form:"type" `
|
||||||
|
request.PageInfo
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package goods
|
||||||
|
|
||||||
|
type RouterGroup struct {
|
||||||
|
GoodsShowRouter
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package goods
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"pychr/api/v1"
|
||||||
|
"pychr/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GoodsShowRouter struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitGoodsShowRouter 初始化 商品 路由信息
|
||||||
|
func (s *GoodsShowRouter) InitGoodsShowRouter(Router *gin.RouterGroup) {
|
||||||
|
goodsShowRouter := Router.Group("goodsShow").Use(middleware.OperationRecord())
|
||||||
|
goodsShowRouterWithoutRecord := Router.Group("goodsShow")
|
||||||
|
var goodsShowApi = v1.ApiGroupApp.GoodsApiGroup.GoodsShowApi
|
||||||
|
{
|
||||||
|
goodsShowRouter.POST("createGoodsShow", goodsShowApi.CreateGoodsShow) // 新建商品
|
||||||
|
goodsShowRouter.DELETE("deleteGoodsShow", goodsShowApi.DeleteGoodsShow) // 删除商品
|
||||||
|
goodsShowRouter.DELETE("deleteGoodsShowByIds", goodsShowApi.DeleteGoodsShowByIds) // 批量删除商品
|
||||||
|
goodsShowRouter.PUT("updateGoodsShow", goodsShowApi.UpdateGoodsShow) // 更新商品
|
||||||
|
}
|
||||||
|
{
|
||||||
|
goodsShowRouterWithoutRecord.GET("findGoodsShow", goodsShowApi.FindGoodsShow) // 根据ID获取商品
|
||||||
|
goodsShowRouterWithoutRecord.GET("getGoodsShowList", goodsShowApi.GetGoodsShowList) // 获取商品列表
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package goods
|
||||||
|
|
||||||
|
type ServiceGroup struct {
|
||||||
|
GoodsShowService
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
package goods
|
||||||
|
|
||||||
|
import (
|
||||||
|
"pychr/global"
|
||||||
|
"pychr/model/goods"
|
||||||
|
goodsReq "pychr/model/goods/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GoodsShowService struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateGoodsShow 创建商品记录
|
||||||
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
|
func (goodsShowService *GoodsShowService) CreateGoodsShow(goodsShow *goods.GoodsShow) (err error) {
|
||||||
|
err = global.GVA_DB.Create(goodsShow).Error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGoodsShow 删除商品记录
|
||||||
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
|
func (goodsShowService *GoodsShowService) DeleteGoodsShow(ID string) (err error) {
|
||||||
|
err = global.GVA_DB.Delete(&goods.GoodsShow{}, "id = ?", ID).Error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGoodsShowByIds 批量删除商品记录
|
||||||
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
|
func (goodsShowService *GoodsShowService) DeleteGoodsShowByIds(IDs []string) (err error) {
|
||||||
|
err = global.GVA_DB.Delete(&[]goods.GoodsShow{}, "id in ?", IDs).Error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGoodsShow 更新商品记录
|
||||||
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
|
func (goodsShowService *GoodsShowService) UpdateGoodsShow(goodsShow goods.GoodsShow) (err error) {
|
||||||
|
err = global.GVA_DB.Save(&goodsShow).Error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsShow 根据ID获取商品记录
|
||||||
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
|
func (goodsShowService *GoodsShowService) GetGoodsShow(ID string) (goodsShow goods.GoodsShow, err error) {
|
||||||
|
err = global.GVA_DB.Where("id = ?", ID).First(&goodsShow).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsShowInfoList 分页获取商品记录
|
||||||
|
// Author [piexlmax](https://github.com/piexlmax)
|
||||||
|
func (goodsShowService *GoodsShowService) GetGoodsShowInfoList(info goodsReq.GoodsShowSearch) (list []goods.GoodsShow, total int64, err error) {
|
||||||
|
limit := info.PageSize
|
||||||
|
offset := info.PageSize * (info.Page - 1)
|
||||||
|
// 创建db
|
||||||
|
db := global.GVA_DB.Model(&goods.GoodsShow{})
|
||||||
|
var goodsShows []goods.GoodsShow
|
||||||
|
// 如果有条件搜索 下方会自动创建搜索语句
|
||||||
|
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
|
||||||
|
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
||||||
|
}
|
||||||
|
if info.LangType != 0 {
|
||||||
|
db = db.Where("lang_type = ?", info.LangType)
|
||||||
|
}
|
||||||
|
if info.Name != "" {
|
||||||
|
db = db.Where("name LIKE ?", "%"+info.Name+"%")
|
||||||
|
}
|
||||||
|
if info.Type != 0 {
|
||||||
|
db = db.Where("type = ?", info.Type)
|
||||||
|
}
|
||||||
|
err = db.Count(&total).Error
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if limit != 0 {
|
||||||
|
db = db.Limit(limit).Offset(offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Find(&goodsShows).Error
|
||||||
|
return goodsShows, total, err
|
||||||
|
}
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
import service from '@/utils/request'
|
||||||
|
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 创建商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body model.GoodsShow true "创建商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
||||||
|
// @Router /goodsShow/createGoodsShow [post]
|
||||||
|
export const createGoodsShow = (data) => {
|
||||||
|
return service({
|
||||||
|
url: '/goodsShow/createGoodsShow',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 删除商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body model.GoodsShow true "删除商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||||
|
// @Router /goodsShow/deleteGoodsShow [delete]
|
||||||
|
export const deleteGoodsShow = (params) => {
|
||||||
|
return service({
|
||||||
|
url: '/goodsShow/deleteGoodsShow',
|
||||||
|
method: 'delete',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 批量删除商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body request.IdsReq true "批量删除商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||||
|
// @Router /goodsShow/deleteGoodsShow [delete]
|
||||||
|
export const deleteGoodsShowByIds = (params) => {
|
||||||
|
return service({
|
||||||
|
url: '/goodsShow/deleteGoodsShowByIds',
|
||||||
|
method: 'delete',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 更新商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data body model.GoodsShow true "更新商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||||
|
// @Router /goodsShow/updateGoodsShow [put]
|
||||||
|
export const updateGoodsShow = (data) => {
|
||||||
|
return service({
|
||||||
|
url: '/goodsShow/updateGoodsShow',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 用id查询商品
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data query model.GoodsShow true "用id查询商品"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||||
|
// @Router /goodsShow/findGoodsShow [get]
|
||||||
|
export const findGoodsShow = (params) => {
|
||||||
|
return service({
|
||||||
|
url: '/goodsShow/findGoodsShow',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Tags GoodsShow
|
||||||
|
// @Summary 分页获取商品列表
|
||||||
|
// @Security ApiKeyAuth
|
||||||
|
// @accept application/json
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param data query request.PageInfo true "分页获取商品列表"
|
||||||
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||||
|
// @Router /goodsShow/getGoodsShowList [get]
|
||||||
|
export const getGoodsShowList = (params) => {
|
||||||
|
return service({
|
||||||
|
url: '/goodsShow/getGoodsShowList',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -0,0 +1,142 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="form-box">
|
||||||
|
<el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
|
||||||
|
<el-form-item label="语言类型 1中文 2英文:" prop="langType">
|
||||||
|
<el-input v-model.number="formData.langType" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="商品主图:" prop="goodsMainPic">
|
||||||
|
<el-input v-model="formData.goodsMainPic" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="商品名称:" prop="name">
|
||||||
|
<el-input v-model="formData.name" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="简介:" prop="briefIntroduction">
|
||||||
|
<el-input v-model="formData.briefIntroduction" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="类型:" prop="type">
|
||||||
|
<el-input v-model.number="formData.type" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="主介绍:" prop="mainIntroduction">
|
||||||
|
<el-input v-model="formData.mainIntroduction" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="商品副图:" prop="goodsAssistantPic">
|
||||||
|
<el-input v-model="formData.goodsAssistantPic" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="副介绍标题:" prop="secondIntroductionTitle">
|
||||||
|
<el-input v-model="formData.secondIntroductionTitle" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="副介绍,逗号拼接:" prop="secondIntroduction">
|
||||||
|
<el-input v-model="formData.secondIntroduction" :clearable="true" placeholder="请输入" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="save">保存</el-button>
|
||||||
|
<el-button type="primary" @click="back">返回</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import {
|
||||||
|
createGoodsShow,
|
||||||
|
updateGoodsShow,
|
||||||
|
findGoodsShow
|
||||||
|
} from '@/api/goodsShow'
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'GoodsShowForm'
|
||||||
|
})
|
||||||
|
|
||||||
|
// 自动获取字典
|
||||||
|
import { getDictFunc } from '@/utils/format'
|
||||||
|
import { useRoute, useRouter } from "vue-router"
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { ref, reactive } from 'vue'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const type = ref('')
|
||||||
|
const formData = ref({
|
||||||
|
langType: 0,
|
||||||
|
goodsMainPic: '',
|
||||||
|
name: '',
|
||||||
|
briefIntroduction: '',
|
||||||
|
type: 0,
|
||||||
|
mainIntroduction: '',
|
||||||
|
goodsAssistantPic: '',
|
||||||
|
secondIntroductionTitle: '',
|
||||||
|
secondIntroduction: '',
|
||||||
|
})
|
||||||
|
// 验证规则
|
||||||
|
const rule = reactive({
|
||||||
|
langType : [{
|
||||||
|
required: true,
|
||||||
|
message: '',
|
||||||
|
trigger: ['input','blur'],
|
||||||
|
}],
|
||||||
|
name : [{
|
||||||
|
required: true,
|
||||||
|
message: '',
|
||||||
|
trigger: ['input','blur'],
|
||||||
|
}],
|
||||||
|
type : [{
|
||||||
|
required: true,
|
||||||
|
message: '',
|
||||||
|
trigger: ['input','blur'],
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
|
||||||
|
const elFormRef = ref()
|
||||||
|
|
||||||
|
// 初始化方法
|
||||||
|
const init = async () => {
|
||||||
|
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
|
||||||
|
if (route.query.id) {
|
||||||
|
const res = await findGoodsShow({ ID: route.query.id })
|
||||||
|
if (res.code === 0) {
|
||||||
|
formData.value = res.data.regoodsShow
|
||||||
|
type.value = 'update'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
type.value = 'create'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init()
|
||||||
|
// 保存按钮
|
||||||
|
const save = async() => {
|
||||||
|
elFormRef.value?.validate( async (valid) => {
|
||||||
|
if (!valid) return
|
||||||
|
let res
|
||||||
|
switch (type.value) {
|
||||||
|
case 'create':
|
||||||
|
res = await createGoodsShow(formData.value)
|
||||||
|
break
|
||||||
|
case 'update':
|
||||||
|
res = await updateGoodsShow(formData.value)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
res = await createGoodsShow(formData.value)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (res.code === 0) {
|
||||||
|
ElMessage({
|
||||||
|
type: 'success',
|
||||||
|
message: '创建/更改成功'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回按钮
|
||||||
|
const back = () => {
|
||||||
|
router.go(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue