feat:商品

main
tian 2 years ago
parent 81ea6ce81e
commit 9cd7f4d5b8

3
.gitignore vendored

@ -1,6 +1,7 @@
.idea/
/web/node_modules
/web/dist
/server/log
.DS_Store
@ -21,5 +22,5 @@ yarn-error.log*
*.njsproj
*.sln
*.sw?
.log
*.iml

@ -2,12 +2,14 @@ package v1
import (
"pychr/api/v1/example"
"pychr/api/v1/goods"
"pychr/api/v1/system"
)
type ApiGroup struct {
SystemApiGroup system.ApiGroup
ExampleApiGroup example.ApiGroup
GoodsApiGroup goods.ApiGroup
}
var ApiGroupApp = new(ApiGroup)

@ -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)
}
}

@ -9,6 +9,7 @@ import (
"go.uber.org/zap"
"gorm.io/gorm"
"pychr/model/goods"
)
func Gorm() *gorm.DB {
@ -46,11 +47,12 @@ func RegisterTables() {
system.SysAuthorityBtn{},
system.SysAutoCode{},
system.SysExportTemplate{},
system.GoodsShow{},
example.ExaFile{},
example.ExaCustomer{},
example.ExaFileChunk{},
example.ExaFileUploadAndDownload{},
example.ExaFileUploadAndDownload{}, goods.GoodsShow{},
)
if err != nil {
global.GVA_LOG.Error("register table failed", zap.Error(err))

@ -98,6 +98,10 @@ func Routers() *gin.Engine {
exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
}
{
goodsRouter := router.RouterGroupApp.Goods
goodsRouter.InitGoodsShowRouter(PrivateGroup)
}
global.GVA_LOG.Info("router register success")
return Router

@ -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
}

@ -29,20 +29,15 @@ func (SysUser) TableName() string {
type GoodsShow struct {
global.GVA_MODEL
UUID uuid.UUID `json:"uuid" gorm:"index;comment:用户UUID"` // 用户UUID
Name string `json:"name" gorm:"index;comment:用户登录名"` // 用户登录名
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
SideMode string `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"` // 用户侧边主题
HeaderImg string `json:"headerImg" gorm:"default:'';comment:用户头像"` // 用户头像
BaseColor string `json:"baseColor" gorm:"default:#fff;comment:基础颜色"` // 基础颜色
ActiveColor string `json:"activeColor" gorm:"default:#1890ff;comment:活跃颜色"` // 活跃颜色
AuthorityId uint64 `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
Enable int `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"` // 用户是否被冻结 1正常 2冻结
LangType int `json:"langType" gorm:"default:1;comment:语言类型 1中文 2英文"` // 语言类型 1中文 2英文
GoodsMainPic string `json:"goodsMainPic" gorm:"comment:商品主图"` // 商品主图
Name string `json:"name" gorm:"index;comment:商品名称"` // 商品名称
BriefIntroduction string `json:"briefIntroduction" gorm:"comment:简介"` // 简介
Type int `json:"type" gorm:"default:1;comment:类型"` // 类型
MainIntroduction string `json:"mainIntroduction" gorm:"default:dark;comment:主介绍"` // 主介绍
GoodsAssistantPic string `json:"goodsAssistantPic" gorm:"default:'';comment:商品副图"` // 商品副图
SecondIntroductionTitle string `json:"secondIntroductionTitle" gorm:"default:'';comment:副介绍标题"` // 副介绍标题
SecondIntroduction string `json:"secondIntroduction" gorm:"comment:副介绍"` // 副介绍,逗号拼接
}
func (GoodsShow) TableName() string {

@ -2,12 +2,14 @@ package router
import (
"pychr/router/example"
"pychr/router/goods"
"pychr/router/system"
)
type RouterGroup struct {
System system.RouterGroup
Example example.RouterGroup
Goods goods.RouterGroup
}
var RouterGroupApp = new(RouterGroup)

@ -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) // 获取商品列表
}
}

@ -2,12 +2,14 @@ package service
import (
"pychr/service/example"
"pychr/service/goods"
"pychr/service/system"
)
type ServiceGroup struct {
SystemServiceGroup system.ServiceGroup
ExampleServiceGroup example.ServiceGroup
GoodsServiceGroup goods.ServiceGroup
}
var ServiceGroupApp = new(ServiceGroup)

@ -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,485 @@
<template>
<div>
<div class="search-box">
<el-form ref="elSearchFormRef" :inline="true" :model="searchInfo" class="demo-form-inline" :rules="searchRule" @keyup.enter="onSubmit">
<el-form-item label="创建日期" prop="createdAt">
<template #label>
<span>
创建日期
<el-tooltip content="搜索范围是开始日期(包含)至结束日期(不包含)">
<el-icon><QuestionFilled /></el-icon>
</el-tooltip>
</span>
</template>
<el-date-picker v-model="searchInfo.startCreatedAt" type="datetime" placeholder="开始日期" :disabled-date="time=> searchInfo.endCreatedAt ? time.getTime() > searchInfo.endCreatedAt.getTime() : false"></el-date-picker>
<el-date-picker v-model="searchInfo.endCreatedAt" type="datetime" placeholder="结束日期" :disabled-date="time=> searchInfo.startCreatedAt ? time.getTime() < searchInfo.startCreatedAt.getTime() : false"></el-date-picker>
</el-form-item>
<el-form-item label="语言类型 1中文 2英文" prop="langType">
<el-input v-model.number="searchInfo.langType" placeholder="搜索条件" />
</el-form-item>
<el-form-item label="商品名称" prop="name">
<el-input v-model="searchInfo.name" placeholder="搜索条件" />
</el-form-item>
<el-form-item label="类型" prop="type">
<el-input v-model.number="searchInfo.type" placeholder="搜索条件" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="search" @click="onSubmit"></el-button>
<el-button icon="refresh" @click="onReset"></el-button>
</el-form-item>
</el-form>
</div>
<div class="table-box">
<div class="btn-list">
<el-button type="primary" icon="plus" @click="openDialog"></el-button>
<el-popover v-model:visible="deleteVisible" :disabled="!multipleSelection.length" placement="top" width="160">
<p>确定要删除吗</p>
<div style="text-align: right; margin-top: 8px;">
<el-button type="primary" link @click="deleteVisible = false">取消</el-button>
<el-button type="primary" @click="onDelete"></el-button>
</div>
<template #reference>
<el-button icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="deleteVisible = true">删除</el-button>
</template>
</el-popover>
</div>
<el-table
ref="multipleTable"
style="width: 100%"
tooltip-effect="dark"
:data="tableData"
row-key="ID"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column align="left" label="日期" width="180">
<template #default="scope">{{ formatDate(scope.row.CreatedAt) }}</template>
</el-table-column>
<el-table-column align="left" label="语言类型 1中文 2英文" prop="langType" width="120" />
<el-table-column align="left" label="商品主图" prop="goodsMainPic" width="120" />
<el-table-column align="left" label="商品名称" prop="name" width="120" />
<el-table-column align="left" label="简介" prop="briefIntroduction" width="120" />
<el-table-column align="left" label="类型" prop="type" width="120" />
<el-table-column align="left" label="主介绍" prop="mainIntroduction" width="120" />
<el-table-column align="left" label="商品副图" prop="goodsAssistantPic" width="120" />
<el-table-column align="left" label="副介绍标题" prop="secondIntroductionTitle" width="120" />
<el-table-column align="left" label="副介绍,逗号拼接" prop="secondIntroduction" width="120" />
<el-table-column align="left" label="操作" fixed="right" min-width="240">
<template #default="scope">
<el-button type="primary" link class="table-button" @click="getDetails(scope.row)">
<el-icon style="margin-right: 5px"><InfoFilled /></el-icon>
查看详情
</el-button>
<el-button type="primary" link icon="edit" class="table-button" @click="updateGoodsShowFunc(scope.row)"></el-button>
<el-button type="primary" link icon="delete" @click="deleteRow(scope.row)"></el-button>
</template>
</el-table-column>
</el-table>
<div class="pagination">
<el-pagination
layout="total, sizes, prev, pager, next, jumper"
:current-page="page"
:page-size="pageSize"
:page-sizes="[10, 30, 50, 100]"
:total="total"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
/>
</div>
</div>
<el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="type==='create'?'添加':'修改'" destroy-on-close>
<el-scrollbar height="500px">
<el-form :model="formData" label-position="right" ref="elFormRef" :rules="rule" label-width="80px">
<el-form-item label="语言类型 1中文 2英文:" prop="langType" >
<el-input v-model.number="formData.langType" :clearable="true" placeholder="请输入语言类型 1中文 2英文" />
</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>
</el-scrollbar>
<template #footer>
<div class="dialog-footer">
<el-button @click="closeDialog"> </el-button>
<el-button type="primary" @click="enterDialog"> </el-button>
</div>
</template>
</el-dialog>
<el-dialog v-model="detailShow" style="width: 800px" lock-scroll :before-close="closeDetailShow" title="查看详情" destroy-on-close>
<el-scrollbar height="550px">
<el-descriptions column="1" border>
<el-descriptions-item label="语言类型 1中文 2英文">
{{ formData.langType }}
</el-descriptions-item>
<el-descriptions-item label="商品主图">
{{ formData.goodsMainPic }}
</el-descriptions-item>
<el-descriptions-item label="商品名称">
{{ formData.name }}
</el-descriptions-item>
<el-descriptions-item label="简介">
{{ formData.briefIntroduction }}
</el-descriptions-item>
<el-descriptions-item label="类型">
{{ formData.type }}
</el-descriptions-item>
<el-descriptions-item label="主介绍">
{{ formData.mainIntroduction }}
</el-descriptions-item>
<el-descriptions-item label="商品副图">
{{ formData.goodsAssistantPic }}
</el-descriptions-item>
<el-descriptions-item label="副介绍标题">
{{ formData.secondIntroductionTitle }}
</el-descriptions-item>
<el-descriptions-item label="副介绍,逗号拼接">
{{ formData.secondIntroduction }}
</el-descriptions-item>
</el-descriptions>
</el-scrollbar>
</el-dialog>
</div>
</template>
<script setup>
import {
createGoodsShow,
deleteGoodsShow,
deleteGoodsShowByIds,
updateGoodsShow,
findGoodsShow,
getGoodsShowList
} from '@/api/goodsShow'
//
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'
defineOptions({
name: 'GoodsShow'
})
//
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'],
},
{
whitespace: true,
message: '不能只输入空格',
trigger: ['input', 'blur'],
}
],
type : [{
required: true,
message: '',
trigger: ['input','blur'],
},
],
})
const searchRule = reactive({
createdAt: [
{ validator: (rule, value, callback) => {
if (searchInfo.value.startCreatedAt && !searchInfo.value.endCreatedAt) {
callback(new Error('请填写结束日期'))
} else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
callback(new Error('请填写开始日期'))
} else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
callback(new Error('开始日期应当早于结束日期'))
} else {
callback()
}
}, trigger: 'change' }
],
})
const elFormRef = ref()
const elSearchFormRef = ref()
// =========== ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})
//
const onReset = () => {
searchInfo.value = {}
getTableData()
}
//
const onSubmit = () => {
elSearchFormRef.value?.validate(async(valid) => {
if (!valid) return
page.value = 1
pageSize.value = 10
getTableData()
})
}
//
const handleSizeChange = (val) => {
pageSize.value = val
getTableData()
}
//
const handleCurrentChange = (val) => {
page.value = val
getTableData()
}
//
const getTableData = async() => {
const table = await getGoodsShowList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
if (table.code === 0) {
tableData.value = table.data.list
total.value = table.data.total
page.value = table.data.page
pageSize.value = table.data.pageSize
}
}
getTableData()
// ============== ===============
//
const setOptions = async () =>{
}
//
setOptions()
//
const multipleSelection = ref([])
//
const handleSelectionChange = (val) => {
multipleSelection.value = val
}
//
const deleteRow = (row) => {
ElMessageBox.confirm('确定要删除吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteGoodsShowFunc(row)
})
}
//
const deleteVisible = ref(false)
//
const onDelete = async() => {
const IDs = []
if (multipleSelection.value.length === 0) {
ElMessage({
type: 'warning',
message: '请选择要删除的数据'
})
return
}
multipleSelection.value &&
multipleSelection.value.map(item => {
IDs.push(item.ID)
})
const res = await deleteGoodsShowByIds({ IDs })
if (res.code === 0) {
ElMessage({
type: 'success',
message: '删除成功'
})
if (tableData.value.length === IDs.length && page.value > 1) {
page.value--
}
deleteVisible.value = false
getTableData()
}
}
//
const type = ref('')
//
const updateGoodsShowFunc = async(row) => {
const res = await findGoodsShow({ ID: row.ID })
type.value = 'update'
if (res.code === 0) {
formData.value = res.data.regoodsShow
dialogFormVisible.value = true
}
}
//
const deleteGoodsShowFunc = async (row) => {
const res = await deleteGoodsShow({ ID: row.ID })
if (res.code === 0) {
ElMessage({
type: 'success',
message: '删除成功'
})
if (tableData.value.length === 1 && page.value > 1) {
page.value--
}
getTableData()
}
}
//
const dialogFormVisible = ref(false)
//
const detailShow = ref(false)
//
const openDetailShow = () => {
detailShow.value = true
}
//
const getDetails = async (row) => {
//
const res = await findGoodsShow({ ID: row.ID })
if (res.code === 0) {
formData.value = res.data.regoodsShow
openDetailShow()
}
}
//
const closeDetailShow = () => {
detailShow.value = false
formData.value = {
langType: 0,
goodsMainPic: '',
name: '',
briefIntroduction: '',
type: 0,
mainIntroduction: '',
goodsAssistantPic: '',
secondIntroductionTitle: '',
secondIntroduction: '',
}
}
//
const openDialog = () => {
type.value = 'create'
dialogFormVisible.value = true
}
//
const closeDialog = () => {
dialogFormVisible.value = false
formData.value = {
langType: 0,
goodsMainPic: '',
name: '',
briefIntroduction: '',
type: 0,
mainIntroduction: '',
goodsAssistantPic: '',
secondIntroductionTitle: '',
secondIntroduction: '',
}
}
//
const enterDialog = 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: '创建/更改成功'
})
closeDialog()
getTableData()
}
})
}
</script>
<style>
</style>

@ -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 () => {
// urlID find createupdate idurl
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…
Cancel
Save