This commit is contained in:
Sakura9701
2022-09-14 10:24:19 +08:00
parent 71d5a097e0
commit 9c6cc6a683
37 changed files with 4322 additions and 38 deletions

View File

@@ -0,0 +1,170 @@
<template>
<div>
<el-tree :data="menus" :props="defaultProps" @node-click="handleNodeClick" show-checkbox node-key="catId"
:default-expanded-keys="expandedkey" :expand-on-click-node="false">
<span class="custom-tree-node" slot-scope="{ node, data }">
<span>{{ node.label }}</span>
<span>
<el-button v-if="node.level <= 2" type="text" size="mini" @click="() => append(data)">
Append
</el-button>
<el-button type="text" size="mini" @click="() => edit(data)">
edit
</el-button>
<el-button v-if="node.childNodes.length == 0" type="text" size="mini" @click="() => remove(node, data)">
Delete
</el-button>
</span>
</span>
</el-tree>
<el-dialog
:title="title"
:visible.sync="dialogVisible"
width="30%"
>
<el-form :model="category">
<el-form-item label="分类目录">
<el-input v-model="category.name" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="submitData"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import { SSL_OP_NO_TLSv1_1 } from 'constants'
export default {
data() {
return {
category:{name:"", parentCid: 0, catLevel: 0, showStatus: 1, sort: 0 ,catId: null},
dialogVisible:false,
dialogType:"",
menus: [],
title:'',
expandedkey: [],
defaultProps: {
children: 'children',
label: 'name'
}
}
},
created() {
this.getTreeList()
},
methods: {
handleNodeClick(data) {
console.log(data)
},
addLevel(){
console.log("提交的三级分类数据",this.category)
this.$http({
url: this.$http.adornUrl(`/book/shopcategory/save`),
method: 'post',
data: this.$http.adornData(this.category, false)
}).then(({ data }) => {
this.$message({
type: 'success',
message: '目录添加成功!'
});
this.dialogVisible = false
this.getTreeList()
this.expandedkey = [this.category.parentCid]
this.category = {}
})
},
getTreeList() {
this.$http({
url: this.$http.adornUrl(`/book/shopcategory/listTree`),
method: 'get',
params: this.$http.adornParams()
}).then(({ data }) => {
this.menus = data.data;
})
},
append(data) {
this.dialogVisible = true
this.dialogType = 'add'
this.title = '添加分类'
this.category.parentCid = data.catId
this.category.showStatus = data.showStatus
this.category.catLevel = data.catLevel*1 + 1
},
edit(data){
this.dialogVisible = true
this.dialogType = 'edit'
this.title = '修改分类'
this.$http({
url: this.$http.adornUrl(`/book/shopcategory/info/${data.catId}`),
method: 'get',
params: this.$http.adornParams()
}).then(({ data }) => {
this.category.name = data.shopCategory.name
this.category.catId = data.shopCategory.catId
this.category.parentCid = data.shopCategory.parentCid
this.category.catLevel = data.shopCategory.catLevel
})
},
submitData(){
console.log(this.dialogType)
if(this.dialogType == 'add'){
this.addLevel()
}
if(this.dialogType == 'edit'){
this.editData()
}
},
editData(){
console.log("修改的三级分类数据",this.category)
this.$http({
url: this.$http.adornUrl(`/book/shopcategory/update`),
method: 'post',
data: this.$http.adornData(this.category, false)
}).then(({ data }) => {
this.$message({
type: 'success',
message: '目录修改成功!'
});
this.dialogVisible = false
this.getTreeList()
this.expandedkey = [this.category.parentCid]
this.category = {}
})
},
remove(node, data) {
console.log("remove",node,data)
var ids = [data.catId]
this.$confirm(`是否删除【${data.name}】目录?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$http({
url: this.$http.adornUrl(`/book/shopcategory/deleteCheck`),
method: 'post',
data: this.$http.adornData(ids, false)
}).then(({ data }) => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getTreeList();
this.expandedkey = [node.parent.data.catId]
})
})
.catch(() => { });
},
}
}
</script>
<style>
</style>

View File

@@ -0,0 +1,228 @@
<template>
<el-dialog
:title="!dataForm.productId ? '新增' : '修改'"
:close-on-click-modal="false"
:visible.sync="visible"
@close="handlereset">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<el-form-item label="所属分类" prop="productPid">
<el-cascader v-model="dataForm.poids" :options="categorys" :props="props" @change="handleChange" clearable></el-cascader>
</el-form-item>
<el-form-item label="商品名称" prop="productName">
<el-input v-model="dataForm.productName" placeholder="商品名称"></el-input>
</el-form-item>
<el-form-item label="商品价格" prop="price">
<el-input v-model="dataForm.price" placeholder="商品价格"></el-input>
</el-form-item>
<el-form-item label="商品重量" prop="weight">
<el-input v-model="dataForm.weight" placeholder="商品重量"></el-input>
</el-form-item>
<el-form-item label="上架状态" prop="publishStatus">
<el-input v-model="dataForm.publishStatus" placeholder="上架状态"></el-input>
</el-form-item>
<el-form-item label="商品图" prop="productImages">
<el-upload
action="http://localhost:9100/pb/oss/fileoss"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:file-list="fileList"
:on-success="handlePicSuccess"
:on-remove="handleRemove">
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible" :append-to-body="true">
<img width="100%" :src="dataForm.productImages" alt="">
</el-dialog>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
</el-form-item>
<el-form-item label="更新时间" prop="updateTime">
<el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
</el-form-item>
<el-form-item label="删除标记" prop="delFlag">
<el-input v-model="dataForm.delFlag" placeholder="删除标记"></el-input>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input v-model="dataForm.sort" placeholder="排序"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="handlereset">取消</el-button>
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
</span>
</el-dialog>
</template>
<script>
export default {
data () {
return {
visible: false,
categorys:'',
fileList:[],
dialogVisible: false,
props: {
value: "catId",
label: "name",
children: "children",
checkStrictly: true
},
dataForm: {
productId: 0,
productName: '',
price: '',
weight: '',
publishStatus: '',
productPid: '',
productImages: '',
createTime: '',
updateTime: '',
delFlag: '',
sort: '',
poids:[]
},
dataRule: {
// productName: [
// { required: true, message: '商品名称不能为空', trigger: 'blur' }
// ],
// price: [
// { required: true, message: '商品价格不能为空', trigger: 'blur' }
// ],
// weight: [
// { required: true, message: '商品重量不能为空', trigger: 'blur' }
// ],
// publishStatus: [
// { required: true, message: '上架状态不能为空', trigger: 'blur' }
// ],
// productPid: [
// { required: true, message: '商品父id不能为空', trigger: 'blur' }
// ],
// productImages: [
// { required: true, message: '商品图不能为空', trigger: 'blur' }
// ],
// level: [
// { required: true, message: '层级不能为空', trigger: 'blur' }
// ],
// createTime: [
// { required: true, message: '创建时间不能为空', trigger: 'blur' }
// ],
// updateTime: [
// { required: true, message: '更新时间不能为空', trigger: 'blur' }
// ],
// delFlag: [
// { required: true, message: '删除标记不能为空', trigger: 'blur' }
// ],
// sort: [
// { required: true, message: '排序不能为空', trigger: 'blur' }
// ]
}
}
},
created (){
this.getTreeList()
},
methods: {
init (id) {
this.dataForm.productId = id || 0
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.productId) {
this.$http({
url: this.$http.adornUrl(`/book/shopproduct/info/${this.dataForm.productId}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
if (data && data.code === 0) {
this.dataForm.productName = data.shopProduct.productName
this.dataForm.price = data.shopProduct.price
this.dataForm.weight = data.shopProduct.weight
this.dataForm.publishStatus = data.shopProduct.publishStatus
this.dataForm.productPid = data.shopProduct.productPid
this.dataForm.productImages = data.shopProduct.productImages
this.dataForm.createTime = data.shopProduct.createTime
this.dataForm.updateTime = data.shopProduct.updateTime
this.dataForm.delFlag = data.shopProduct.delFlag
this.dataForm.sort = data.shopProduct.sort
this.dataForm.poids = data.shopProduct.poids
if (data.shopProduct.productImages != "") {
var img = { name: '', url: data.shopProduct.productImages }
var attr = []
attr.push(img)
this.fileList = attr
}
}
})
}
})
},
// 表单提交
dataFormSubmit () {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.$http({
url: this.$http.adornUrl(`/book/shopproduct/${!this.dataForm.productId ? 'save' : 'update'}`),
method: 'post',
data: this.$http.adornData({
'productId': this.dataForm.productId || undefined,
'productName': this.dataForm.productName,
'price': this.dataForm.price,
'weight': this.dataForm.weight,
'publishStatus': this.dataForm.publishStatus,
'productPid': this.dataForm.poids[this.dataForm.poids.length-1],
'productImages': this.dataForm.productImages,
'createTime': this.dataForm.createTime,
'updateTime': this.dataForm.updateTime,
'delFlag': this.dataForm.delFlag,
'sort': this.dataForm.sort
})
}).then(({data}) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
} else {
this.$message.error(data.msg)
}
})
}
})
},
getTreeList() {
this.$http({
url: this.$http.adornUrl(`/book/shopcategory/listTree`),
method: 'get',
params: this.$http.adornParams()
}).then(({ data }) => {
this.categorys = data.data;
})
},
handlePictureCardPreview(file) {
this.dataForm.productImages = file.url;
this.dialogVisible = true;
},
handlePicSuccess(res, file) {
if (res.msg == "success") {
this.dataForm.productImages = res.url;
this.$message.success("上传成功");
} else {
this.$message.error("上传失败");
}
},
handleRemove(file) {
this.dataForm.productImages = '';
},
handlereset(){
this.fileList = [],
this.visible = false
},
}
}
</script>

View File

@@ -0,0 +1,248 @@
<template>
<div class="mod-config">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">查询</el-button>
<el-button v-if="isAuth('book:shopproduct:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
<el-button v-if="isAuth('book:shopproduct:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
</el-form-item>
</el-form>
<el-table
:data="dataList"
border
v-loading="dataListLoading"
@selection-change="selectionChangeHandle"
style="width: 100%;">
<el-table-column
type="selection"
header-align="center"
align="center"
width="50">
</el-table-column>
<el-table-column label="序号" width="70" align="center">
<template slot-scope="scope">
{{ (pageIndex - 1) * pageSize + scope.$index + 1 }}
</template>
</el-table-column>
<el-table-column prop="publishStatus" header-align="center" align="center" label="状态">
<template slot-scope="scope">
<el-switch :active-value=1 :inactive-value=0 style="display: block" v-model="scope.row.publishStatus"
@change="SwitchChange(scope.row)" active-color="#13ce66" inactive-color="#ff4949" active-text="上架"
inactive-text="下架">
</el-switch>
</template>
</el-table-column>
<el-table-column
prop="productName"
header-align="center"
align="center"
label="商品名称">
</el-table-column>
<el-table-column
prop="price"
header-align="center"
align="center"
label="商品价格">
</el-table-column>
<el-table-column
prop="weight"
header-align="center"
align="center"
label="商品重量">
</el-table-column>
<!-- <el-table-column
prop="productPid"
header-align="center"
align="center"
label="商品父id">
</el-table-column> -->
<el-table-column header-align="center" align="center" label="商品图">
<template slot-scope="scope">
<img v-if="scope.row.productImages != ''" :src="scope.row.productImages" width="70" height="100" class="tableImg" />
</template>
</el-table-column>
<!-- <el-table-column
prop="level"
header-align="center"
align="center"
label="层级">
</el-table-column> -->
<el-table-column
prop="createTime"
header-align="center"
align="center"
label="创建时间">
</el-table-column>
<el-table-column
prop="updateTime"
header-align="center"
align="center"
label="更新时间">
</el-table-column>
<!-- <el-table-column
prop="delFlag"
header-align="center"
align="center"
label="删除标记">
</el-table-column>
<el-table-column
prop="sort"
header-align="center"
align="center"
label="排序">
</el-table-column> -->
<el-table-column
fixed="right"
header-align="center"
align="center"
width="150"
label="操作">
<template slot-scope="scope">
<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.productId)">修改</el-button>
<el-button type="text" size="small" @click="deleteHandle(scope.row.productId)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
</div>
</template>
<script>
import AddOrUpdate from './shopproduct-add-or-update'
export default {
data () {
return {
dataForm: {
key: ''
},
dataList: [],
publishStatus: false,
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false
}
},
components: {
AddOrUpdate
},
activated () {
this.getDataList()
},
methods: {
// 获取数据列表
getDataList () {
this.dataListLoading = true
this.$http({
url: this.$http.adornUrl('/book/shopproduct/list'),
method: 'get',
params: this.$http.adornParams({
'page': this.pageIndex,
'limit': this.pageSize,
'key': this.dataForm.key
})
}).then(({data}) => {
if (data && data.code === 0) {
this.dataList = data.page.list
this.totalPage = data.page.totalCount
} else {
this.dataList = []
this.totalPage = 0
}
this.dataListLoading = false
})
},
// 每页数
sizeChangeHandle (val) {
this.pageSize = val
this.pageIndex = 1
this.getDataList()
},
// 当前页
currentChangeHandle (val) {
this.pageIndex = val
this.getDataList()
},
// 多选
selectionChangeHandle (val) {
this.dataListSelections = val
},
// 新增 / 修改
addOrUpdateHandle (id) {
this.addOrUpdateVisible = true
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id)
})
},
// 删除
deleteHandle (id) {
var ids = id ? [id] : this.dataListSelections.map(item => {
return item.productId
})
this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$http({
url: this.$http.adornUrl('/book/shopproduct/delete'),
method: 'post',
data: this.$http.adornData(ids, false)
}).then(({data}) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.getDataList()
}
})
} else {
this.$message.error(data.msg)
}
})
})
},
SwitchChange(event) {
/*点击时他会自动把你绑定的值变更,直接去请求数据就可以了*/
var parms = {
publishStatus: event.publishStatus,
productId: event.productId
}
console.log(parms)
this.$http({
url: this.$http.adornUrl('/book/shopproduct/update'),
method: 'post',
data: parms
}).then(res => {
this.$message({
message: '成功',
type: 'success'
})
this.loading = false
this.getDataList()
}).catch(error => {
this.loading = false
console.log(error)
})
console.log(event)
},
}
}
</script>