新增商品分组

This commit is contained in:
gyq 2024-01-16 17:24:35 +08:00
parent 6e62895adb
commit 26425e7f57
5 changed files with 488 additions and 108 deletions

View File

@ -167,3 +167,64 @@ export function tbProductSpecPut(data) {
}) })
} }
/**
* 规格更改
* @returns
*/
export function tbProductSpecDelete(data) {
return request({
url: `/api/tbProductSpec`,
method: 'DELETE',
data
})
}
/**
* 新增分组
* @returns
*/
export function tbProductGroupPost(data) {
return request({
url: `/api/tbProductGroup`,
method: 'post',
data
})
}
/**
* 更改分组
* @returns
*/
export function tbProductGroupPut(data) {
return request({
url: `/api/tbProductGroup`,
method: 'PUT',
data
})
}
/**
* 商品分组列表
* @returns
*/
export function tbProductGroupGet(params) {
return request({
url: `/api/tbProductGroup`,
method: 'get',
params
})
}
/**
* 商品列表根据分组中的商品id
* @returns
*/
export function productListGet(params) {
return request({
url: `/api/tbProduct/productList`,
method: 'get',
params
})
}

View File

@ -0,0 +1,194 @@
<template>
<div>
<el-dialog title="添加分组" :visible.sync="dialogVisible" @close="reset">
<el-form ref="form" :model="form" :rules="rules" label-width="120px" label-position="left">
<el-form-item label="分组名称" prop="name">
<el-input v-model="form.name" placeholder="请输入分组名称"></el-input>
</el-form-item>
<el-form-item label="选择商品">
<div>
<el-button type="primary" icon="el-icon-plus" @click="$refs.shopListRef.show()">
添加商品
</el-button>
</div>
<div class="shop_list">
<div class="item" v-for="(item, index) in productIds" :key="item.id" :data-index="index + 1"
@click="productIds.splice(index, 1)">
<el-image :src="item.coverImg" style="width: 100%;height: 100%;"></el-image>
</div>
</div>
</el-form-item>
<el-form-item label="分组状态">
<el-radio-group v-model="form.isShow">
<el-radio :label="1">启用</el-radio>
<el-radio :label="0">禁用</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="分组排序">
<el-input-number v-model="form.sort" controls-position="right" :min="0"></el-input-number>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" :loading="loading" @click="onSubmitHandle"> </el-button>
</span>
</el-dialog>
<shopList ref="shopListRef" @success="res => productIds = res" />
</div>
</template>
<script>
import { tbProductGroupPost, tbProductGroupPut, productListGet } from '@/api/shop'
import shopList from './shopList'
export default {
components: {
shopList
},
data() {
return {
dialogVisible: false,
loading: false,
form: {
id: '',
name: '',
isShow: 1,
sort: 0,
productIds: [],
shopId: localStorage.getItem('shopId')
},
rules: {
name: [
{
required: true,
message: ' ',
trigger: 'blur'
}
]
},
productIds: []
}
},
methods: {
onSubmitHandle() {
this.$refs.form.validate(async valid => {
if (valid) {
this.loading = true
try {
this.form.productIds = this.productIds.map(item => item.id);
let res = null
if (!this.form.id) {
await tbProductGroupPost(this.form)
} else {
await tbProductGroupPut(this.form)
}
this.loading = false
this.$emit('success', res)
this.close()
this.$notify({
title: '成功',
message: `${this.form.id ? '编辑' : '添加'}成功`,
type: 'success'
});
} catch (error) {
console.log(error)
}
}
})
},
async getProduts() {
try {
const res = await productListGet({
productList: this.form.productIds
})
} catch (error) {
console.log(error)
}
},
show(obj) {
if (obj && obj.id) {
this.form.id = obj.id
this.form.isShow = obj.isShow
this.form.name = obj.name
this.form.sort = obj.sort
this.form.productIds = obj.productIds
this.getProduts()
}
this.dialogVisible = true
},
close() {
this.dialogVisible = false
},
reset() {
this.form.isShow = 1
this.form.name = ''
this.form.sort = 0
this.form.productIds = []
this.productIds = []
}
}
}
</script>
<style scoped lang="scss">
.shop_list {
display: flex;
flex-wrap: wrap;
.item {
$size: 80px;
$radius: 4px;
width: $size;
height: $size;
border-radius: $radius;
overflow: hidden;
position: relative;
margin-right: 10px;
margin-top: 10px;
&:hover {
cursor: pointer;
&::before {
transform: translateY(0);
}
}
&::after {
content: attr(data-index);
font-size: 12px;
height: 20px;
display: flex;
padding: 0 10px;
border-radius: 0 0 $radius 0;
align-items: center;
background-color: rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
color: #fff;
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
&::before {
content: '删除';
font-size: 12px;
width: 100%;
height: 20px;
display: flex;
padding: 0 10px;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
color: #fff;
position: absolute;
bottom: 0;
left: 0;
z-index: 10;
transform: translateY(100%);
transition: all .1s ease-in-out;
}
}
}
</style>

View File

@ -0,0 +1,141 @@
<template>
<el-dialog title="选择商品" :visible.sync="dialogVisible" @open="resetHandle()">
<el-form :model="searhForm" inline>
<el-form-item>
<el-input v-model="searhForm.name" placeholder="商品名称"></el-input>
</el-form-item>
<el-form-item>
<el-select v-model="searhForm.category" placeholder="商品分类">
<el-option :label="item.name" :value="item.id" v-for="item in categoryList" :key="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary">查询</el-button>
<el-button>重置</el-button>
</el-form-item>
</el-form>
<div class="head-container">
<el-table ref="table" :data="tableData.list" v-loading="tableData.loading">
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column label="商品信息">
<template v-slot="scope">
<div class="shop_info">
<el-image :sr="scope.row.coverImg" style="width: 30px;height: 30px;"></el-image>
<span>{{ scope.row.name }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="售价">
<template v-slot="scope">
{{ scope.row.lowPrice }}
</template>
</el-table-column>
<el-table-column label="销量/库存">
<template v-slot="scope">
0/0
</template>
</el-table-column>
<el-table-column label="分类" prop="categoryId"></el-table-column>
</el-table>
</div>
<el-pagination :total="tableData.total" :current-page="tableData.page + 1" :page-size="tableData.size"
@current-change="paginationChange" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="confirmHandle"> </el-button>
</span>
</el-dialog>
</template>
<script>
import { tbShopCategoryGet, tbProduct } from "@/api/shop";
export default {
data() {
return {
dialogVisible: false,
searhForm: {
name: '',
category: ''
},
categoryList: [],
tableData: {
page: 0,
size: 10,
total: 0,
loading: false,
list: []
}
}
},
mounted() {
this.tbShopCategoryGet()
},
methods: {
//
confirmHandle() {
let res = this.$refs.table.selection
this.$emit('success', res)
this.close()
},
//
resetHandle() {
this.searhForm.name = ''
this.searhForm.category = ''
this.tableData.page = 0;
this.getTableData()
},
//
paginationChange(e) {
this.tableData.page = e
this.getTableData()
},
//
async getTableData() {
this.tableData.loading = true
try {
const res = await tbProduct({
page: this.tableData.page,
size: this.tableData.size,
sort: 'id',
})
this.tableData.loading = false
this.tableData.list = res.content
this.tableData.total = res.totalElements
} catch (error) {
console.log(error)
}
},
//
async tbShopCategoryGet() {
try {
const res = await tbShopCategoryGet({
page: 0,
size: 100,
sort: 'id',
shopId: localStorage.getItem('shopId')
})
this.categoryList = res.content
} catch (error) {
console.log(error)
}
},
show() {
this.dialogVisible = true
},
close() {
this.dialogVisible = false
}
}
}
</script>
<style scoped lang="scss">
.shop_info {
display: flex;
align-items: center;
span {
margin-left: 10px;
}
}
</style>

View File

@ -1,128 +1,99 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!--工具栏-->
<div class="head-container"> <div class="head-container">
<!--如果想在工具栏加入更多按钮可以使用插槽方式 slot = 'left' or 'right'--> <el-button type="primary" icon="el-icon-plus" @click="$refs.addGroupRef.show()">
<crudOperation :permission="permission" /> 添加分组
<!--表单组件(增改)--> </el-button>
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px"> <addGroup ref="addGroupRef" @success="resetHandle" />
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px"> </div>
<el-form-item label="分组名称" prop="name"> <div class="head-container">
<el-input v-model="form.name" style="width: 370px;" /> <el-table :data="tableData.list" v-loading="tableData.loading">
</el-form-item> <el-table-column label="排序" sortable prop="sort"></el-table-column>
<el-form-item label="图标"> <el-table-column label="分组名称" prop="name"></el-table-column>
<el-input v-model="form.pic" style="width: 370px;" /> <el-table-column label="状态">
</el-form-item> <template v-slot="scope">
<el-form-item label="是否显示:" prop="isShow"> <el-switch v-model="scope.row.isShow" :active-value="1" :inactive-value="0"></el-switch>
<el-input v-model="form.isShow" style="width: 370px;" /> </template>
</el-form-item> </el-table-column>
<el-form-item label="分类描述"> <el-table-column label="操作" width="200">
<el-input v-model="form.detail" style="width: 370px;" /> <template v-slot="scope">
</el-form-item> <el-button type="text" size="mini" round icon="el-icon-edit"
<el-form-item label="添加商品"> @click="$refs.addGroupRef.show(scope.row)">编辑</el-button>
<el-input v-model="form.productIds" style="width: 370px;" /> <el-popconfirm title="确定删除吗?" @confirm="delHandle([scope.row.id])">
</el-form-item> <el-button type="text" size="mini" round icon="el-icon-delete" slot="reference">
删除
<el-button type="primary" @click="addProduct">+添加商品 </el-button>
<el-dialog title="选择商品" :visible.sync="productClick"> </el-popconfirm>
<el-table :data="productList.content" style="width: 100%;">
<el-table-column type="selection" width="55" />
<el-table-column property="name" label="商品信息" width="150" />
<el-table-column property="lowPrice" label="售价" width="200" />
<el-table-column property="address" label="地址" />
</el-table>
<span slot="footer" class="dialog-footer">
<el-button @click="centerDialogVisible = false"> </el-button>
<el-button type="primary" @click="addProduct"> </el-button>
</span>
</el-dialog>
</el-button>
<el-form-item label="创建时间">
<el-input v-model="form.createdAt" style="width: 370px;" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column prop="name" label="分组名称" />
<el-table-column prop="pic" label="图标" />
<el-table-column prop="isShow" label="是否显示" />
<el-table-column prop="detail" label="分类描述" />
<el-table-column prop="productIds" label="商品列表" />
<el-table-column prop="createdAt" label="创建时间" />
<el-table-column v-if="checkPer(['admin','tbProductGroup:edit','tbProductGroup:del'])" label="操作" width="150px" align="center">
<template slot-scope="scope">
<udOperation
:data="scope.row"
:permission="permission"
/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!--分页组件-->
<pagination />
</div> </div>
<el-pagination :total="tableData.total" :current-page="tableData.page + 1" :page-size="tableData.size"
@current-change="paginationChange" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
</div> </div>
</template> </template>
<script> <script>
import crudTbProductGroup from '@/api/tbProductGroup' import addGroup from '../components/addGroup'
import CRUD, { presenter, header, form, crud } from '@crud/crud' import { tbProductGroupGet, tbProductSpecDelete } from '@/api/shop'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import { addProduct } from '@/api/tbProductGroup'
const defaultForm = { id: null, name: null, merchantId: null, shopId: null, pic: null, isShow: null, detail: null, style: null, sort: null, productIds: null, createdAt: null, updatedAt: null }
export default { export default {
name: 'TbProductGroup', components: {
components: { pagination, crudOperation, rrOperation, udOperation }, addGroup
mixins: [presenter(), header(), form(defaultForm), crud()],
cruds() {
return CRUD({ title: 'product/group', url: 'api/tbProductGroup', idField: 'id', sort: 'id,desc', crudMethod: { ...crudTbProductGroup }})
}, },
data() { data() {
return { return {
permission: { tableData: {
add: ['admin', 'tbProductGroup:add'], page: 0,
edit: ['admin', 'tbProductGroup:edit'], size: 10,
del: ['admin', 'tbProductGroup:del'] total: 0,
}, loading: false,
rules: { list: []
name: [ }
{ required: true, message: '分组名称不能为空', trigger: 'blur' }
],
isShow: [
{ required: true, message: '是否显示1显示 0不显示不能为空', trigger: 'blur' }
]
},
productList: [],
productClick: false
} }
}, },
mounted() {
this.getTableData()
},
methods: { methods: {
// false //
[CRUD.HOOK.beforeRefresh]() { resetHandle() {
return true this.tableData.page = 0;
this.getTableData()
}, },
addProduct(data) { //
this.productClick = true paginationChange(e) {
addProduct(data).then(res => { this.tableData.page = e
this.productList = res this.getTableData()
}) },
//
async delHandle(ids) {
try {
await tbProductSpecDelete(ids)
this.$notify({
title: '成功',
message: `删除成功`,
type: 'success'
});
this.getTableData()
} catch (error) {
console.log(error)
}
},
//
async getTableData() {
this.tableData.loading = true
try {
const res = await tbProductGroupGet({
page: this.tableData.page,
size: this.tableData.size,
sort: 'id',
shopId: localStorage.getItem('shopId')
})
this.tableData.loading = false
this.tableData.list = res.content
this.tableData.total = res.totalElements
} catch (error) { }
} }
} }
} }
</script> </script>
<style scoped>
</style>

View File

@ -50,7 +50,7 @@
<script> <script>
import addSpecification from './components/addSpecification' import addSpecification from './components/addSpecification'
import { tbProductSpecGet } from '@/api/shop' import { tbProductSpecGet, tbProductSpecDelete } from '@/api/shop'
export default { export default {
components: { components: {
addSpecification addSpecification
@ -68,7 +68,6 @@ export default {
list: [] list: []
} }
} }
}, },
mounted() { mounted() {
this.getTableData() this.getTableData()
@ -85,6 +84,20 @@ export default {
this.tableData.page = e this.tableData.page = e
this.getTableData() this.getTableData()
}, },
//
async delHandle(ids) {
try {
const res = await tbProductSpecDelete(ids)
this.$notify({
title: '成功',
message: `删除成功`,
type: 'success'
});
this.getTableData()
} catch (error) {
console.log(error)
}
},
// //
async getTableData() { async getTableData() {
this.tableData.loading = true this.tableData.loading = true