图书标签

This commit is contained in:
2024-03-22 13:36:10 +08:00
parent b3970683dd
commit 4ee5176ee8
7 changed files with 3549 additions and 2 deletions

View File

@@ -1,8 +1,8 @@
<script type="text/javascript">
// const baseUrl = "http://192.168.110.100:9200/pb"; //张川川后端
const baseUrl = "http://192.168.110.100:9200/pb"; //张川川后端
// const baseUrl = 'http://59.110.212.44:9100/pb'
// const baseUrl = 'https://testapi.nuttyreading.com'
const baseUrl = 'https://api.nuttyreading.com'
// const baseUrl = 'https://api.nuttyreading.com'
// function commonFun() {
// console.log("公共方法")
// }

View File

@@ -0,0 +1,799 @@
<template>
<div class="mod-config">
<div class="tree_box">
<div>
<el-input
placeholder="请输入关键字进行查询"
v-model="filterText"
style="width: calc(100% - 70px)"
clearable
>
</el-input>
<el-button
type="primary"
@click="addOrUpdateHandle()"
style="margin-bottom: 20px; margin-left: 10px"
size="small"
>新增</el-button
>
</div>
<p class="info_bg">
当前选中营销标签<span style="color: #17b3a3; font-weight: 600">{{
currentNode ? currentNode.data.title : ""
}}</span>
</p>
<!-- show-checkbox -->
<div class="custom-tree-container">
<el-tree
:highlight-current="true"
class="filter-tree"
node-key="id"
:data="treeDataList"
:props="defaultProps"
default-expand-all
:filter-node-method="filterNode"
ref="tree"
:draggable="true"
:allow-drop="allowDrop"
@node-click="handleNodeClick"
:expand-on-click-node="false"
>
<!-- @click="handleClickNodes(node, data)" -->
<span
class="custom-tree-node"
slot-scope="{ node, data }"
@click="handleClickNodes(node, data, 'edit')"
>
<span>{{ node.label }}</span>
<span>
<!-- v-if="node.level <= 1" -->
<el-button
type="text"
size="mini"
@click.stop="handleClickNodes(node, data, 'addChildren')"
>
添加下级
</el-button>
<!-- <el-button
type="text"
size="mini"
@click.stop="handleClickNodes(node, data, 'edit')"
>
修改
</el-button> -->
<!-- v-if="node.childNodes.length == 0" -->
<el-button type="text" size="mini" @click.stop="remove(data)">
删除
</el-button>
</span>
</span>
</el-tree>
</div>
</div>
<div
style="width: calc(100% - 420px); height: 100%; float: right"
v-if="isFresh"
>
<div class="border_box info_box">
<div class="title"><span class="line"></span>基本标签信息</div>
<div class="addFormBox">
<el-form :model="addForm" ref="addForm" label-width="80px">
<el-form-item label="标签名称" prop="title" class="form_item">
<el-input
placeholder="请输入标签名称"
style="width: 100%"
v-model="addForm.title"
clearable
>
</el-input>
</el-form-item>
<el-form-item label="排序" prop="sort" class="form_item">
<el-input-number
placeholder="请输入标签排序"
style="width: 100%"
v-model="addForm.sort"
clearable
>
</el-input-number>
</el-form-item>
</el-form>
</div>
</div>
<div class="border_box tree_content_box">
<div class="title"><span class="line"></span>关联商品列表</div>
<commonShop
ref="commonShop"
style="height: calc(100% - 50px)"
></commonShop>
<div class="submitButton">
<!-- <el-button @click="handlereset" size="small">取消</el-button> -->
<el-button size="small" @click.stop="handlereset()">
取消
</el-button>
<el-button
type="primary"
@click="dataFormSubmit('addForm')"
size="small"
>确定</el-button
>
</div>
</div>
</div>
<!-- <el-form
:inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()"
>
</el-form> -->
<add-or-update
v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"
></add-or-update>
</div>
</template>
<script>
import AddOrUpdate from "./commonBookTags/bookTagsForm.vue";
import commonShop from "./commonBookTags/shopproduct.vue";
// import dialogComponent from './seckillprodrelation'
export default {
data() {
return {
addForm: {},
isFresh: false,
dataRule: {
name: [
{
required: true,
message: "标签名称不能为空",
// trigger: "change",
},
],
},
currentNode: null,
treeDataList: [],
isact: "", //当前hover的节点
isactTitle: "", //记录修改节点名称
curNode: undefined, //当前选中节点
isUpdateGroup: false, //是否在修改模板组
filterText: "",
indexRecord: [], //记录节点轨迹
isBreak: false, //是否结束循环
defaultProps: {
children: "children",
label: "title",
},
dataForm: {
key: "",
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
};
},
components: {
AddOrUpdate,
commonShop,
},
watch: {
filterText(val) {
this.$refs.tree.filter(val);
},
},
activated() {
this.getDataList();
},
methods: {
allowDrop(draggingNode, dropNode, type) {
console.log(draggingNode.level, dropNode.level);
//注掉的是同级拖拽
if (draggingNode.level === dropNode.level) {
return type === "prev" || type === "next";
} else {
// 不同级进行处理
return false;
}
},
async correlationShop(bookLabelId) {
var status;
var productId = this.$refs.commonShop.multipleSelection.map(
(e) => e.productId
);
console.log("🚀 ~ correlationShop ~ productId:", productId);
await this.$http({
url: this.$http.adornUrl(`/book/labelAndMarket/saveToLabel`),
method: "post",
data: this.$http.adornData({
productId: productId.toString(","),
bookLabelId: bookLabelId,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
status = true;
} else {
this.$message.error(data.msg);
status = false;
}
});
return status;
},
//新增修改
async dataFormSubmit(formName) {
// return false
if (this.addForm.title == "") {
this.$message.error("请输入标签名称");
return false;
}
await this.$refs[formName].validate(async (valid) => {
if (valid) {
await this.$http({
url: this.$http.adornUrl(`/book/labelAndMarket/saveOrUpdateMarket`),
method: "post",
data: this.$http.adornData({
...this.addForm,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
var status = await this.correlationShop(data.result.id);
if (status) {
await this.getDataList();
var newNodeData = await this.$refs.tree.getNode(data.result.id);
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(data.result.id);
});
await this.handleClickNodes(
newNodeData,
newNodeData.data,
"edit"
);
this.$message({
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.visible = false;
this.$refs.tree.setCheckedKeys([data.result.id]);
// console.log(this.$refs.tree.getCheckedKeys([this.addForm.id]),'88888');
// this.$refs["addForm"].resetFields();
// this.addForm={}
// this.$emit("refreshDataList");
},
});
}
} else {
this.$message.error(data.msg);
}
});
}
});
},
setCheckedKeys() {
this.$refs.tree.setCheckedKeys([0]);
},
handlereset() {
this.currentNode = null;
this.isFresh = false;
this.isFresh = true;
this.$refs.commonShop.clear();
this.$refs.commonShop.bookMarketId = null;
},
handleClickNodes(node, data, type) {
this.addForm = {};
// console.log(this.$refs.tree.handleClickNodes(), "当前选中节点");
console.log(node, data, "当前选中节点");
this.currentNode = node;
this.isFresh = false;
this.isFresh = true;
var form = {};
switch (type) {
case "add":
form = { ...data };
break;
case "edit":
form = { ...node.data };
break;
case "addChildren":
form = {
children: [],
delFlag: 0,
isLast: 0,
pid: data.id,
sort: 0,
title: "",
};
break;
}
this.addForm = { ...form };
this.$nextTick(() => {
this.$refs.commonShop.clear();
this.$refs.commonShop.bookMarketId = null;
this.$refs.commonShop.getDataList(type == "edit" ? form.id : "");
});
},
addOrUpdateHandle() {
var addform = {
children: [],
delFlag: 0,
isLast: 0,
pid: 0,
sort: 0,
title: "",
};
this.handleClickNodes({ data: addform }, addform, "add");
// if (!this.currentNode) {
// this.$message.error("请先选择分类");
// return;
// }
},
async remove(data) {
var ids = { productId: data.productId };
this.$confirm(`是否删除标签【${data.title}】?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
this.$http({
url: this.$http.adornUrl(
`/book/labelAndMarket/delMarket?id=` + data.id
),
method: "post",
data: {},
}).then(async ({ data }) => {
this.$message({
type: "success",
message: "删除成功!",
});
this.currentNode = null;
this.isFresh = false;
this.addForm = {};
this.$nextTick(() => {
this.isFresh = true;
});
await this.addOrUpdateHandle();
// this.expandedkey = [node.parent.data.catId]
});
})
.catch(() => {});
},
filterNode(value, data) {
if (!value) return true;
return data.title.indexOf(value) !== -1;
},
// renderContent(h, { node, data, store }) {
// return;
// `<span
// style="flex: 1; display: flex; align-items: center; justify-content: space-between; padding-right: 8px;"
// on-mouseenter={() => this.mouseenteract(data)}
// on-mouseleave={() => this.mouseleaveact(data)}
// >
// <span>
// <span>{node.label}</span>
// </span>
// {this.isact == data ? (
// <span>
// {this.isact.typeName == "模板组" ? (
// <el-button
// class="m-r-10"
// type="text"
// icon="el-icon-edit"
// on-click={() => this.handleUpdateGroup(node, data)}
// ></el-button>
// ) : (
// <span></span>
// )}
// <el-button
// type="text"
// icon="el-icon-delete"
// on-click={(e) => this.handleDelete(node, data, e)}
// ></el-button>
// </span>
// ) : (
// <span></span>
// )}
// </span>`;
// },
updateRenderContent(h, { node, data, store }) {
return `
<span style="flex: 1; display: flex; align-items: center; justify-content: space-between; padding-right: 8px;">
<span>
{this.isact == data ? (
<input
type="text"
onChange={this.handleChangeTitle.bind(this)}
value={node.label}
/>
) : (
<span>{node.label}</span>
)}
</span>
{this.isact == data ? (
<span>
{this.isact.typeName == "模板组" ? (
<span>
<el-button
class="m-r-10"
type="text"
icon="el-icon-check"
on-click={() => this.updateGroup(node, data)}
></el-button>
<el-button
class="m-r-10"
type="text"
icon="el-icon-close"
on-click={(e) => this.cancelUpdate(node, data, e)}
></el-button>
</span>
) : (
<span></span>
)}
</span>
) : (
<span></span>
)}
</span>`;
},
//获取鼠标进入节点的数据
mouseenteract(da) {
this.isact = da;
},
mouseleaveact(da) {
this.isact = "";
},
handleNodeClick(pdata) {
this.curNode = pdata;
document
.getElementsByClassName("el-tree-node__content")[0]
.setAttribute("class", "el-tree-node__content");
},
handleDelete(node, data, e) {
e.stopPropagation();
//存在则添加到子级
const parent = node.parent;
const children = parent.data.nodes || parent.data;
//若parent.data是对象操作的是子级如果是数组操作的是最外层
if (Array.isArray(parent.data)) {
const parentIndex = parent.data.findIndex((d) => d.id === data.id);
parent.data.splice(parentIndex, 1);
} else {
const childIndex = children.findIndex((d) => d.id === data.id);
children.splice(childIndex, 1);
}
this.curNode = undefined;
},
//新增组
handleAddGroup() {
/**
* 如果模版深度最多两层,取消该部分注释
* //最多只有两层组 不可能添加在dept2的组上 curNode存在 并且 深度超过1
if (this.curNode != undefined && this.curNode.depth != 1) {
this.$message.warning("不能添加超过两层");
return;
}
*/
//如果isUpdateGroup 已经是true了 说明重复点击了
if (this.isUpdateGroup) {
return;
}
let id = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
let newChild = {
parentId: "", //如果有这个id 是插入第二层 否则是第一层 可有可无
text: "", //必须有 this.templateContent.tempName
nodes: [],
id: id,
typeName: "模板组",
temporaryData: "1", //用来区分临时数据
};
/* 如果模版深度最多两层,以下条件改成该部分注释
this.curNode && this.curNode.depth == 1
*/
this.indexRecord = [];
if (this.curNode) {
if (!this.curNode.nodes) {
this.$message.warning("模板不可添加");
return;
}
newChild.parentId = this.curNode.id;
/* 如果模版深度最多两层,以下条件改成该部分注释
const index = this.treeDataList.findIndex(
item => item.id == this.curNode.id
);
this.treeDataList[index].nodes.push(newChild);
*/
//找到tree中的index轨迹
this.getTemplateTreeNode(this.curNode.id, this.treeDataList, 0);
//按照index轨迹插入节点
this.insertNode(
newChild,
this.treeDataList,
this.indexRecord,
this.indexRecord.length
);
this.isBreak = false;
} else if (this.curNode == undefined) {
//没有选中的时候 添加到最外层
newChild.depth = 1;
this.treeDataList.push(newChild);
}
//调用出updateRender的input
this.isact = newChild;
this.isUpdateGroup = true;
},
//递归遍历获得选中node
getTemplateTreeNode(target, list, dept) {
//空数组直接返回
if (list.length == 0) return;
let dataLen = list.length;
for (let i = 0; i < dataLen; i++) {
//如果不匹配
if (target != list[i].id) {
//存在nodes 遍历nodes里的节点
if (list[i].nodes) {
this.indexRecord[dept] = i;
let recordDept = dept + 1;
this.getTemplateTreeNode(target, list[i].nodes, recordDept);
} else {
//不存在nodes 继续遍历
continue;
}
} else {
//匹配,则修改下标数组
this.indexRecord[dept] = i;
this.isBreak = true;
break;
}
//删除不匹配的轨迹 如果已经break了说明已经找到正确的节点就不用再删了
if (!this.isBreak) {
this.indexRecord.pop();
}
}
},
//插入节点
insertNode(insertChild, tree, indexArr, len) {
let index = indexArr.length - len;
if (len == 0) {
tree.push(insertChild);
} else {
this.insertNode(
insertChild,
tree[indexArr[index]].nodes,
indexArr,
len - 1
);
}
},
//修改组
handleUpdateGroup() {
this.isUpdateGroup = true;
},
//修改组名时获取title
handleChangeTitle(e) {
let value = e.target.value;
this.isactTitle = value;
},
updateGroup(node, data) {
//先handleChangeTitle获取title 再调用
setTimeout(() => {
if (this.isactTitle.trim() == "") {
this.$message.warning("名称不能为空");
return;
}
//修改数据组
this.isUpdateGroup = false;
const parent = node.parent;
const children = parent.data.nodes || parent.data;
const index = children.findIndex((d) => d.id === data.id);
let temp = data;
temp.text = this.isactTitle;
children.splice(index, 1, temp);
}, 500);
},
cancelUpdate(node, data, e) {
this.$message.info("已取消");
this.isUpdateGroup = false;
//如果是插入操作 需要移除数据
if (this.isact.temporaryData) {
this.handleDelete(node, data, e);
}
},
// 获取数据列表
async getDataList() {
this.dataListLoading = true;
await this.$http({
url: this.$http.adornUrl("/book/labelAndMarket/marketTree"),
method: "get",
// params: this.$http.adornParams({
// 'page': this.pageIndex,
// 'limit': this.pageSize,
// 'key': this.dataForm.key
// })
}).then(({ data }) => {
console.log("🚀 ~ getDataList ~ data:", data);
if (data && data.code === 0) {
this.treeDataList = data.result;
// this.totalPage = data.page.totalCount
} else {
this.treeDataList = [];
// 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(row) {
// this.addOrUpdateVisible = true;
// this.$nextTick(() => {
// this.$refs.addOrUpdate.init(row);
// });
// },
// 删除
},
};
</script>
<style lang="less" scoped>
.tree_box {
width: 400px;
height: 100%;
float: left;
border: 1px solid #bababa;
border-radius: 10px;
padding: 15px;
box-sizing: border-box;
// background: #fafafa;
}
.border_box {
height: 100px;
margin-bottom: 10px;
.title {
display: flex;
align-items: center;
font-weight: 600;
font-size: 16px;
margin-bottom: 10px;
// color: #17b3a3;
.line {
width: 4px;
height: 20px;
margin-right: 8px;
background: #17b3a3;
}
}
}
.border_box {
width: 100%;
float: right;
background: #fffefe;
border: 1px solid #bababa;
border-radius: 10px;
padding: 15px 15px;
box-sizing: border-box;
}
.tree_content_box {
height: calc(100% - 110px) !important;
}
.mod-config {
width: 100%;
height: 82vh;
overflow: hidden;
}
.el-tree-node__content {
.el-button {
display: none;
}
}
.el-tree-node__content:hover {
.el-button {
display: inline;
}
}
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
background-color: #eaebed;
color: #4796ec;
font-weight: bold;
}
.el-tree {
height: 350px;
overflow-y: auto !important;
.el-tree-node__content span {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
// .el-card {
// background: none !important;
// }
p {
margin: 0;
margin-bottom: 10px;
}
.submitButton {
float: right;
margin-top: 20px;
}
// .el-tree-node__content .el-button {
// // width: 120px !important;
// display: block !important;
// }
// ::v-deep .el-tree .el-tree-node__content span:nth-child(2) {
// width: 120px;
// display: flex !important;
// align-items: center !important;
// justify-content: space-between !important;
// }
// /deep/.el-table__row--level-1 {
// display: block !important;
// }
.addFormBox {
.form_item {
width: 49%;
float: left;
}
}
.custom-tree-container {
height: calc(100% - 100px);
.filter-tree {
height: 100%;
}
}
.info_bg {
background: #e0dede;
padding: 8px 5px;
box-sizing: border-box;
margin-top: -10px;
border-radius: 4px;
font-size: 14px;
}
</style>

View File

@@ -0,0 +1,807 @@
<template>
<div class="mod-config">
<commonTree
ref="commonTree"
:dataList="treeDataList"
@getCommonShopDataList="getCommonShopDataList"
:urlList="urlList"
></commonTree>
<div style="width: calc(100% - 420px); height: 100%; float: right">
<div class="border_box info_box">
<div class="title_box">
<div class="title">
<span class="line"></span>基本标签信息
</div>
</div>
<div class="addFormBox">
<el-form :model="addForm" ref="addForm" label-width="80px">
<el-form-item label="标签名称" prop="title" class="form_item">
<el-input
placeholder="请输入标签名称"
style="width: 100%"
v-model="addForm.title"
clearable
>
</el-input>
</el-form-item>
<el-form-item label="排序" prop="sort" class="form_item">
<el-input-number
placeholder="请输入标签排序"
style="width: 100%"
v-model="addForm.sort"
clearable
>
</el-input-number>
</el-form-item>
<el-form-item
label="是否为最终级"
prop="isLast"
label-width="120px"
class="form_item"
>
<el-switch
v-model="addForm.isLast"
active-color="#13ce66"
:active-value="1"
:inactive-value="0"
active-text=""
inactive-text=""
@change="handleChangeIsLast"
>
</el-switch>
</el-form-item>
</el-form>
</div>
</div>
<div class="border_box tree_content_box" v-if="addForm.isLast == 1">
<div class="title_box" style="margin-bottom:20px">
<div class="title">
<span class="line"></span>已关联商品列表
<el-button
plain
type="primary"
style="margin-left:20px"
@click="dataFormSubmit('addForm')"
size="mini"
>新增关联商品</el-button
>
</div>
<div style="" class="button_box">
<el-button
plain
type="primary"
@click="dataFormSubmit('addForm')"
size="mini"
>修改</el-button
>
</div>
</div>
<commonShop
:dataList="associatedGoodsList"
:urlList="urlList"
ref="commonShop"
style="height: calc(100% - 100px); overflow: auto"
></commonShop>
<div class="submitButton">
<!-- <el-button @click="handlereset" size="small">取消</el-button> -->
<el-button size="small" @click.stop="handlereset()"> 取消 </el-button>
<el-button
type="primary"
@click="dataFormSubmit('addForm')"
size="small"
>确定</el-button
>
</div>
</div>
</div>
<!-- <el-form
:inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()"
>
</el-form> -->
<add-or-update
v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"
></add-or-update>
</div>
</template>
<script>
import AddOrUpdate from "./commonBookTags/bookTagsForm.vue";
import commonShop from "./commonBookTags/shopproduct.vue";
import commonTree from "./commonBookTags/tags.vue";
// import dialogComponent from './seckillprodrelation'
export default {
data() {
return {
urlList: {
delete: "/book/labelAndMarket/delLabel",
add: "/book/labelAndMarket/saveOrUpdateLabel",
getAssociatedGoodsList: "/book/labelAndMarket/getToLabelList",
},
addForm: {},
isFresh: false,
dataRule: {
name: [
{
required: true,
message: "标签名称不能为空",
// trigger: "change",
},
],
},
currentNode: null,
treeDataList: [],
associatedGoodsList: [], //已关联商品列表
isact: "", //当前hover的节点
isactTitle: "", //记录修改节点名称
curNode: undefined, //当前选中节点
isUpdateGroup: false, //是否在修改模板组
filterText: "",
indexRecord: [], //记录节点轨迹
isBreak: false, //是否结束循环
defaultProps: {
children: "children",
label: "title",
},
dataForm: {
key: "",
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
};
},
components: {
AddOrUpdate,
commonShop,
commonTree,
},
watch: {
filterText(val) {
this.$refs.tree.filter(val);
},
},
activated() {
this.getDataList();
},
methods: {
handleChangeIsLast(e) {
console.log("🚀 ~ handleChangeIsLast ~ e:", e);
this.$nextTick(() => {
if (e == 1) {
this.$refs.commonShop.getAssociatedGoodsList(this.addForm.id);
}
});
},
getCommonShopDataList(type, id, form) {
console.log("🚀 ~ getCommonShopDataList ~ type, id:", type, id);
this.addForm = form;
this.$nextTick(() => {
// this.$refs.commonShop.clear();
this.$refs.commonShop.bookMarketId = null;
if (form.isLast == 1) {
this.$refs.commonShop.getAssociatedGoodsList(id);
}
});
},
async correlationShop(bookLabelId) {
var status;
var productId = this.$refs.commonShop.multipleSelection.map(
(e) => e.productId
);
console.log("🚀 ~ correlationShop ~ productId:", productId);
await this.$http({
url: this.$http.adornUrl(`/book/labelAndMarket/saveToLabel`),
method: "post",
data: this.$http.adornData({
productId: productId.toString(","),
bookLabelId: bookLabelId,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
status = true;
} else {
this.$message.error(data.msg);
status = false;
}
});
return status;
},
//新增修改
async dataFormSubmit(formName) {
// return false
if (this.addForm.title == "") {
this.$message.error("请输入标签名称");
return false;
}
await this.$refs[formName].validate(async (valid) => {
if (valid) {
await this.$http({
url: this.$http.adornUrl(`/book/labelAndMarket/saveOrUpdateLabel`),
method: "post",
data: this.$http.adornData({
...this.addForm,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
var status = await this.correlationShop(data.result.id);
if (status) {
await this.getDataList();
var newNodeData = await this.$refs.tree.getNode(data.result.id);
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(data.result.id);
});
await this.handleClickNodes(
newNodeData,
newNodeData.data,
"edit"
);
this.$message({
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.visible = false;
this.$refs.tree.setCheckedKeys([data.result.id]);
// console.log(this.$refs.tree.getCheckedKeys([this.addForm.id]),'88888');
// this.$refs["addForm"].resetFields();
// this.addForm={}
// this.$emit("refreshDataList");
},
});
}
} else {
this.$message.error(data.msg);
}
});
}
});
},
setCheckedKeys() {
this.$refs.tree.setCheckedKeys([0]);
},
handlereset() {
this.currentNode = null;
this.isFresh = false;
this.isFresh = true;
},
handleClickNodes(node, data, type) {
this.addForm = {};
// console.log(this.$refs.tree.handleClickNodes(), "当前选中节点");
console.log(node, data, "当前选中节点");
this.currentNode = node;
this.isFresh = false;
this.isFresh = true;
var form = {};
switch (type) {
case "add":
form = { ...data };
break;
case "edit":
form = { ...node.data };
break;
case "addChildren":
form = {
children: [],
delFlag: 0,
isLast: 0,
pid: data.id,
sort: 0,
title: "",
};
break;
}
this.addForm = { ...form };
this.$nextTick(() => {
this.$refs.commonShop.clear();
this.$refs.commonShop.bookMarketId = null;
this.$refs.commonShop.getDataList(type == "edit" ? form.id : "");
});
},
addOrUpdateHandle() {
var addform = {
children: [],
delFlag: 0,
isLast: 0,
pid: 0,
sort: 0,
title: "",
};
this.handleClickNodes({ data: addform }, addform, "add");
// if (!this.currentNode) {
// this.$message.error("请先选择分类");
// return;
// }
},
async remove(data) {
var ids = { productId: data.productId };
this.$confirm(`是否删除标签【${data.title}】?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
this.$http({
url: this.$http.adornUrl(
`/book/labelAndMarket/delLabel?id=` + data.id
),
method: "post",
data: {},
}).then(async ({ data }) => {
this.$message({
type: "success",
message: "删除成功!",
});
this.currentNode = null;
this.isFresh = false;
this.addForm = {};
this.$nextTick(() => {
this.isFresh = true;
});
await this.addOrUpdateHandle();
// this.expandedkey = [node.parent.data.catId]
});
})
.catch(() => {});
},
filterNode(value, data) {
if (!value) return true;
return data.title.indexOf(value) !== -1;
},
// renderContent(h, { node, data, store }) {
// return;
// `<span
// style="flex: 1; display: flex; align-items: center; justify-content: space-between; padding-right: 8px;"
// on-mouseenter={() => this.mouseenteract(data)}
// on-mouseleave={() => this.mouseleaveact(data)}
// >
// <span>
// <span>{node.label}</span>
// </span>
// {this.isact == data ? (
// <span>
// {this.isact.typeName == "模板组" ? (
// <el-button
// class="m-r-10"
// type="text"
// icon="el-icon-edit"
// on-click={() => this.handleUpdateGroup(node, data)}
// ></el-button>
// ) : (
// <span></span>
// )}
// <el-button
// type="text"
// icon="el-icon-delete"
// on-click={(e) => this.handleDelete(node, data, e)}
// ></el-button>
// </span>
// ) : (
// <span></span>
// )}
// </span>`;
// },
updateRenderContent(h, { node, data, store }) {
return `
<span style="flex: 1; display: flex; align-items: center; justify-content: space-between; padding-right: 8px;">
<span>
{this.isact == data ? (
<input
type="text"
onChange={this.handleChangeTitle.bind(this)}
value={node.label}
/>
) : (
<span>{node.label}</span>
)}
</span>
{this.isact == data ? (
<span>
{this.isact.typeName == "模板组" ? (
<span>
<el-button
class="m-r-10"
type="text"
icon="el-icon-check"
on-click={() => this.updateGroup(node, data)}
></el-button>
<el-button
class="m-r-10"
type="text"
icon="el-icon-close"
on-click={(e) => this.cancelUpdate(node, data, e)}
></el-button>
</span>
) : (
<span></span>
)}
</span>
) : (
<span></span>
)}
</span>`;
},
//获取鼠标进入节点的数据
mouseenteract(da) {
this.isact = da;
},
mouseleaveact(da) {
this.isact = "";
},
handleNodeClick(pdata) {
this.curNode = pdata;
document
.getElementsByClassName("el-tree-node__content")[0]
.setAttribute("class", "el-tree-node__content");
},
handleDelete(node, data, e) {
e.stopPropagation();
//存在则添加到子级
const parent = node.parent;
const children = parent.data.nodes || parent.data;
//若parent.data是对象操作的是子级如果是数组操作的是最外层
if (Array.isArray(parent.data)) {
const parentIndex = parent.data.findIndex((d) => d.id === data.id);
parent.data.splice(parentIndex, 1);
} else {
const childIndex = children.findIndex((d) => d.id === data.id);
children.splice(childIndex, 1);
}
this.curNode = undefined;
},
//新增组
handleAddGroup() {
/**
* 如果模版深度最多两层,取消该部分注释
* //最多只有两层组 不可能添加在dept2的组上 curNode存在 并且 深度超过1
if (this.curNode != undefined && this.curNode.depth != 1) {
this.$message.warning("不能添加超过两层");
return;
}
*/
//如果isUpdateGroup 已经是true了 说明重复点击了
if (this.isUpdateGroup) {
return;
}
let id = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
let newChild = {
parentId: "", //如果有这个id 是插入第二层 否则是第一层 可有可无
text: "", //必须有 this.templateContent.tempName
nodes: [],
id: id,
typeName: "模板组",
temporaryData: "1", //用来区分临时数据
};
/* 如果模版深度最多两层,以下条件改成该部分注释
this.curNode && this.curNode.depth == 1
*/
this.indexRecord = [];
if (this.curNode) {
if (!this.curNode.nodes) {
this.$message.warning("模板不可添加");
return;
}
newChild.parentId = this.curNode.id;
/* 如果模版深度最多两层,以下条件改成该部分注释
const index = this.treeDataList.findIndex(
item => item.id == this.curNode.id
);
this.treeDataList[index].nodes.push(newChild);
*/
//找到tree中的index轨迹
this.getTemplateTreeNode(this.curNode.id, this.treeDataList, 0);
//按照index轨迹插入节点
this.insertNode(
newChild,
this.treeDataList,
this.indexRecord,
this.indexRecord.length
);
this.isBreak = false;
} else if (this.curNode == undefined) {
//没有选中的时候 添加到最外层
newChild.depth = 1;
this.treeDataList.push(newChild);
}
//调用出updateRender的input
this.isact = newChild;
this.isUpdateGroup = true;
},
//递归遍历获得选中node
getTemplateTreeNode(target, list, dept) {
//空数组直接返回
if (list.length == 0) return;
let dataLen = list.length;
for (let i = 0; i < dataLen; i++) {
//如果不匹配
if (target != list[i].id) {
//存在nodes 遍历nodes里的节点
if (list[i].nodes) {
this.indexRecord[dept] = i;
let recordDept = dept + 1;
this.getTemplateTreeNode(target, list[i].nodes, recordDept);
} else {
//不存在nodes 继续遍历
continue;
}
} else {
//匹配,则修改下标数组
this.indexRecord[dept] = i;
this.isBreak = true;
break;
}
//删除不匹配的轨迹 如果已经break了说明已经找到正确的节点就不用再删了
if (!this.isBreak) {
this.indexRecord.pop();
}
}
},
//插入节点
insertNode(insertChild, tree, indexArr, len) {
let index = indexArr.length - len;
if (len == 0) {
tree.push(insertChild);
} else {
this.insertNode(
insertChild,
tree[indexArr[index]].nodes,
indexArr,
len - 1
);
}
},
//修改组
handleUpdateGroup() {
this.isUpdateGroup = true;
},
//修改组名时获取title
handleChangeTitle(e) {
let value = e.target.value;
this.isactTitle = value;
},
updateGroup(node, data) {
//先handleChangeTitle获取title 再调用
setTimeout(() => {
if (this.isactTitle.trim() == "") {
this.$message.warning("名称不能为空");
return;
}
//修改数据组
this.isUpdateGroup = false;
const parent = node.parent;
const children = parent.data.nodes || parent.data;
const index = children.findIndex((d) => d.id === data.id);
let temp = data;
temp.text = this.isactTitle;
children.splice(index, 1, temp);
}, 500);
},
cancelUpdate(node, data, e) {
this.$message.info("已取消");
this.isUpdateGroup = false;
//如果是插入操作 需要移除数据
if (this.isact.temporaryData) {
this.handleDelete(node, data, e);
}
},
// 获取数据列表
async getDataList() {
this.dataListLoading = true;
await this.$http({
url: this.$http.adornUrl("/book/labelAndMarket/labelTree"),
method: "get",
// params: this.$http.adornParams({
// 'page': this.pageIndex,
// 'limit': this.pageSize,
// 'key': this.dataForm.key
// })
}).then(({ data }) => {
console.log("🚀 ~ getDataList ~ data:", data);
if (data && data.code === 0) {
this.treeDataList = data.result;
// this.totalPage = data.page.totalCount
} else {
this.treeDataList = [];
// 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(row) {
// this.addOrUpdateVisible = true;
// this.$nextTick(() => {
// this.$refs.addOrUpdate.init(row);
// });
// },
},
};
</script>
<style lang="less" scoped>
.tree_box {
width: 400px;
height: 100%;
float: left;
border: 1px solid #bababa;
border-radius: 10px;
padding: 15px;
box-sizing: border-box;
// background: #fafafa;
}
.border_box {
height: 100px;
margin-bottom: 10px;
.title_box {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
.button_box {
// width: 200px;
float: right;
}
}
.title {
width: 100%;
float: left;
display: flex;
align-items: center;
font-weight: 600;
font-size: 16px;
// color: #17b3a3;
.line {
width: 4px;
height: 20px;
margin-right: 8px;
background: #17b3a3;
}
}
}
.border_box {
width: 100%;
float: right;
background: #fffefe;
border: 1px solid #bababa;
border-radius: 10px;
padding: 15px 15px;
box-sizing: border-box;
}
.tree_content_box {
height: calc(100% - 110px) !important;
}
.mod-config {
width: 100%;
height: 82vh;
overflow: hidden;
}
.el-tree-node__content {
.el-button {
display: none;
}
}
.el-tree-node__content:hover {
.el-button {
display: inline;
}
}
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
background-color: #eaebed;
color: #4796ec;
font-weight: bold;
}
.el-tree {
height: 350px;
overflow-y: auto !important;
.el-tree-node__content span {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
// .el-card {
// background: none !important;
// }
p {
margin: 0;
margin-bottom: 10px;
}
.submitButton {
float: right;
margin-top: 20px;
}
// .el-tree-node__content .el-button {
// // width: 120px !important;
// display: block !important;
// }
// ::v-deep .el-tree .el-tree-node__content span:nth-child(2) {
// width: 120px;
// display: flex !important;
// align-items: center !important;
// justify-content: space-between !important;
// }
// /deep/.el-table__row--level-1 {
// display: block !important;
// }
.addFormBox {
.form_item {
width: 33%;
float: left;
}
}
.custom-tree-container {
height: calc(100% - 100px);
.filter-tree {
height: 100%;
}
}
.info_bg {
background: #e0dede;
height: 28px;
line-height: 28px;
padding-left: 10px;
// padding: 8px 5px;
box-sizing: border-box;
// margin-top: -10px;
border-radius: 4px;
font-size: 14px;
width: calc(100% - 120px);
float: left;
}
</style>

View File

@@ -0,0 +1,597 @@
<template>
<el-dialog
:title="!dataForm.productId ? '新增' : '修改'"
:close-on-click-modal="false"
:visible.sync="visible"
@close="handlereset"
lock-scroll
width="750px"
>
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
label-width="100px"
>
<el-form-item label="所属分类" prop="poids">
<el-cascader
v-model="dataForm.poids"
:options="categorys"
:props="props"
clearable
></el-cascader>
</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>
import { quillEditor } from "vue-quill-editor";
import global from "@/views/common/common.vue"; //引入共用组间
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
const toolbarOptions = [
["bold", "italic", "underline", "strike"], // 加粗,斜体,下划线,删除线
["blockquote", "code-block"], //引用,代码块
[{ header: 1 }, { header: 2 }], // 几级标题
[{ list: "ordered" }, { list: "bullet" }], // 有序列表,无序列表
[{ script: "sub" }, { script: "super" }], // 下角标,上角标
[{ indent: "-1" }, { indent: "+1" }], // 缩进
[{ direction: "rtl" }], // 文字输入方向
[{ size: ["small", false, "large", "huge"] }], // 字体大小
[{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
[{ color: [] }, { background: [] }], // 颜色选择
[
{
font: [
"SimSun",
"SimHei",
"Microsoft-YaHei",
"KaiTi",
"FangSong",
"Arial",
],
},
], // 字体
[{ align: [] }], // 居中
["clean"], // 清除样式,
["link", "image"], // 上传图片、上传视频
];
export default {
data() {
return {
pointMemery: [], // 花生币操作记录
baseUrl: global.baseUrl,
goodsTypeList: [],
visible: false,
categorys: [],
fileList: [], // 封面图
swiperfileList: [],
dialogVisible: false,
props: {
value: "catId",
label: "name",
children: "children",
checkStrictly: true,
},
dataForm: {
tags: [], // 商品标签
hDprice: 0, // 活动价
productId: 0,
limitCountImg: 1, // 图片数量
productImageList: "", // 轮播图
showBtnDealImg: true,
noneBtnImg: false,
productName: "",
productStock: null, // 商品库存
price: "",
author: "",
publisher: "",
weight: "",
pubDate: "",
// format: '', // 开本
isFreeMail: 1, // 是否包邮
// pageNum: '',
// quality: '', // 内文用纸
isNew: 0,
sumSales: null, // 总销量
publishStatus: "",
productPid: "",
productImages: "",
createTime: "",
updateTime: "",
delFlag: "",
sort: "",
goodsType: "", // 商品类型
poids: [],
Books: [], // 关联的图书
},
bookidsd: [],
dataRule: {
productName: [
{
required: true,
message: "商品名称不能为空",
trigger: "blur",
},
],
price: [
{
required: true,
message: "商品价格不能为空",
trigger: "blur",
},
],
weight: [
{
required: true,
message: "商品重量不能为空",
trigger: "blur",
},
],
goodsType: [
{
required: true,
message: "商品类型不能为空",
trigger: "blur",
},
],
poids: [
{
required: true,
message: "商品父id不能为空",
trigger: "blur",
},
],
productImages: [
{
required: true,
message: "商品图不能为空",
trigger: "blur",
},
],
// productDetails: [{
// required: true,
// message: '商品详情不能为空',
// trigger: 'blur'
// }],
productStock: [
{
required: true,
message: "商品库存不能为空",
trigger: "blur",
},
],
// updateTime: [
// { required: true, message: '更新时间不能为空', trigger: 'blur' }
// ],
// delFlag: [
// { required: true, message: '删除标记不能为空', trigger: 'blur' }
// ],
// sort: [
// { required: true, message: '排序不能为空', trigger: 'blur' }
// ]
},
// 富文本编辑器配置
editorOption: {
modules: {
history: {
delay: 1000,
maxStack: 50,
userOnly: false,
},
toolbar: {
container: toolbarOptions,
handlers: {
image: function (value) {
if (value) {
// 调用element的图片上传组件
document.querySelector(".avatar-uploader input").click();
} else {
this.quill.format("image", false);
}
},
},
},
},
placeholder: "请输入正文",
},
tagList: [],
};
},
created() {
this.getTreeList();
this.getTags();
},
methods: {
contentUploadSuccess(res, file) {
// console.log(res)
let quill = this.$refs.myQuillEditor.quill;
// 如果上传成功
if (res) {
// 获取光标所在位置
let length = quill.getSelection().index;
// 插入图片res为服务器返回的图片链接地址
quill.insertEmbed(length, "image", res.url);
// 调整光标到最后
quill.setSelection(length + 1);
} else {
// 提示信息需引入Message
this.$message.error("图片插入失败!");
}
},
handleCheckedCitiesChange(value) {
// console.log(value, 'value')
},
// 获取商品标签
getTags() {
this.$http({
url: this.$http.adornUrl("/book/label/getLabels"),
method: "post",
}).then(({ data }) => {
if (data && data.code === 0) {
this.tagList = data.result.labels;
// this.totalPage = data.page.totalCount
} else {
this.tagList = [];
// this.totalPage = 0
}
});
},
showChooseBook() {
// 显示图书列表
this.$emit("showchooseBookf", { bookIds: this.dataForm.Books });
// console.log('发送指令')
this.$bus.$emit("showchooseBook", { bookIds: this.dataForm.Books });
},
init(id) {
this.dataForm.productId = id || 0;
this.visible = true;
this.getTags();
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.tags = data.labels;
// console.log('收到的值', this.dataForm.tags)
this.dataForm.productName = data.shopProduct.productName;
this.dataForm.price = data.shopProduct.price;
this.dataForm.goodsType = data.shopProduct.goodsType;
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.publisher = data.shopProduct.publisher;
this.dataForm.author = data.shopProduct.author;
this.dataForm.pubDate = data.shopProduct.pubDate;
// this.dataForm.pageNum = data.shopProduct.pageNum
// this.dataForm.quality = data.shopProduct.quality
// this.dataForm.format = data.shopProduct.format
this.dataForm.isFreeMail = data.shopProduct.isFreeMail;
this.dataForm.isNew = data.shopProduct.isNew;
this.dataForm.productDetails = data.shopProduct.productDetails;
this.dataForm.poids = data.shopProduct.poids;
this.dataForm.productStock = data.shopProduct.productStock;
this.dataForm.hDprice = data.shopProduct.activityPrice;
let arrArr = [];
if (data.shopProduct.bookidsimages !== "") {
this.dataForm.Books = data.shopProduct.bookidsimages;
}
sessionStorage.setItem(
"Books",
JSON.stringify(this.dataForm.Books)
);
if (data.shopProduct.productImages != "") {
var img = {
name: "",
url: data.shopProduct.productImages,
};
var attr = [];
attr.push(img);
this.fileList = attr;
}
if (
data.shopProduct.productImageList == null ||
data.shopProduct.productImageList[0] == "" ||
data.shopProduct.productImageList == ""
) {
this.swiperfileList = [];
// console.log('走这')
} else {
// 有轮播图
// console.log(data.shopProduct.productImageList)
let arr = [];
let arr1 = [];
arr = data.shopProduct.productImageList.split(",");
// console.log(arr, '处理后得轮播图数组')
arr.forEach((item, index) => {
arr1.push({
name: index,
url: item,
});
});
this.swiperfileList = arr1;
}
}
});
}
});
},
// 获取商品类型
getGoodsTypeList() {
this.$http({
url: this.$http.adornUrl("/book/sysdictdata/selectByType/goodsType"),
method: "get",
}).then(({ data }) => {
// console.log(data.dataList)
this.goodsTypeList = data.dataList;
});
},
// 删除图书
deliteBook(index) {
this.dataForm.Books.splice(index, 1);
sessionStorage.setItem("Books", JSON.stringify(this.dataForm.Books));
},
dealImgChange(file, fileList) {
this.dataForm.noneBtnImg = fileList.length >= this.dataForm.limitCountImg;
},
// 表单提交
dataFormSubmit() {
this.getBookIds();
// console.log(this.bookidsd,'this.bookidsd')
// return false
this.$refs["dataForm"].validate((valid) => {
this.dataForm.productImageList = this.getStringImgUrl();
var bookIDS = this.getBookIds();
// console.log(this.dataForm.productImageList)
if (valid) {
if (!this.dataForm.hDprice || this.dataForm.hDprice == 0) {
// console.log('没有值')
this.dataForm.hDprice = 0;
}
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,
productImageList: this.dataForm.productImageList,
createTime: this.dataForm.createTime,
updateTime: this.dataForm.updateTime,
delFlag: this.dataForm.delFlag,
sort: this.dataForm.sort,
goodsType: this.dataForm.goodsType,
productDetails: this.dataForm.productDetails,
author: this.dataForm.author,
publisher: this.dataForm.publisher,
pubDate: this.dataForm.pubDate,
shoproudLabels: this.dataForm.tags,
// 'format': this.dataForm.format, // 开本
isFreeMail: this.dataForm.isFreeMail,
isNew: this.dataForm.isNew,
// 'pageNum': this.dataForm.pageNum,
// 'quality': this.dataForm.quality, // 内文用纸
productStock: this.dataForm.productStock, // 库存
activityPrice: this.dataForm.hDprice,
bookids: this.bookidsd, // 关联的图书[12,13,45]
// 'bookidsimages': this.dataForm.Books // 关联的图书对象
}),
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.visible = false;
this.$refs["dataForm"].resetFields();
// this.$refs['dataForm'].reset()
this.$emit("refreshDataList");
},
});
} else {
this.$message.error(data.msg);
}
});
}
});
},
changeTime(e) {
console.log(e);
},
getBookIds() {
// 图书ids
// console.log(this.dataForm.Books,'Books')
this.bookidsd = this.dataForm.Books.map((item) => {
return item.id;
});
},
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;
},
bannerHandlePicSuccess(res, file) {
// 轮播图上传成功
if (res.msg == "success") {
this.swiperfileList.push({
name: file.name,
url: res.url,
});
// console.log(this.swiperfileList)
this.$message.success("上传成功");
} else {
this.$message.error("上传失败");
}
},
// 字符串图片地址
getStringImgUrl() {
let arr = this.swiperfileList.map((item) => item.url);
if (arr.length <= 0) {
return null;
} else {
return arr.toString();
}
},
handlePicSuccess(res, file) {
// console.log(res,'res')
if (res.msg == "success") {
this.dataForm.productImages = res.url;
this.fileList.push({
name: file.name,
url: res.url,
});
// console.log(this.dataForm.productImages,'productImages')
this.$message.success("上传成功");
} else {
this.$message.error("上传失败");
}
},
bannerHandleRemove(file, fileList) {
// 轮播图删除操作
this.swiperfileList = fileList;
},
handleRemove(file, fileList) {
this.dataForm.productImages = "";
this.fileList = [];
this.dataForm.noneBtnImg = fileList.length >= this.dataForm.limitCountImg;
},
handlereset() {
(this.fileList = []), (this.visible = false);
this.dataForm.tagList = [];
this.dataForm.Books = [];
this.swiperfileList = [];
this.$refs["dataForm"].resetFields();
sessionStorage.setItem("Books", JSON.stringify([]));
// this.$refs['dataForm'].reset()
},
// 失去焦点事件
onEditorBlur(quill) {
// console.log('editor blur!', quill)
},
// 获得焦点事件
onEditorFocus(quill) {
//console.log('editor focus!', quill)
},
// 准备富文本编辑器
onEditorReady(quill) {
// console.log('editor ready!', quill)
},
},
components: {
quillEditor,
},
mounted() {
this.$bus.$on("haveBookIds", (data) => {
sessionStorage.setItem("Books", JSON.stringify(data.bookIds));
// console.log('haveBookIds',data)
//console.log(data.bookIds, '收到的数据')
var newarr = [];
var ids = []; //哨兵数组
if (data.bookIds && data.bookIds.length > 0) {
ids[0] = data.bookIds[0].id;
newarr[0] = data.bookIds[0];
// console.log(ids,'ids')
// newarr.push(data.bookIds[0])
for (let index = 0; index < data.bookIds.length; index++) {
if (!ids.includes(data.bookIds[index].id)) {
// console.log(data.bookIds[index].id, 'data.bookIds[index].id')
newarr.push(data.bookIds[index]);
ids.push(data.bookIds[index].id);
}
}
}
// console.log(newarr,'newarr',ids)
data.bookIds.length > 0
? (this.dataForm.Books = newarr)
: (this.dataForm.Books = []);
});
},
watch: {
visible: {
handler(val, oldVal) {
this.getGoodsTypeList();
},
deep: true,
},
},
};
</script>
<style lang="less">
// .disUoloadSty {
// .el-upload--picture-card {
// display: none;
// /* 上传按钮隐藏 */
// }
// }
// .el-form-item {
// /deep/ .el-form-item__label {
// font-size: 12px;
// }
// }
.el-uploadfeng {
.el-upload-list__item {
width: 95px;
height: 95px;
}
.el-upload--picture-card {
width: 95px;
height: 95px;
line-height: 95px;
}
}
.shangpin_editor .ql-editor {
height: 150px;
}
</style>

View File

@@ -0,0 +1,317 @@
<template>
<div style="width: 100%; height: 100%; margin-top: -30px">
<el-form
:inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()"
style="float: right"
>
<el-form-item>
<el-input
v-model="dataForm.key"
placeholder="商品名称"
clearable
size="small"
></el-input>
</el-form-item>
<el-form-item>
<el-button
@click="
pageIndex = 1;
getDataList(bookMarketId);
"
size="small"
>查询</el-button
>
</el-form-item>
</el-form>
<!-- {{ multipleSelectionAll }} -->
<el-table
ref="table"
height="82%"
:data="dataList"
:row-key="getRowKeys"
border
size="mini"
v-loading="dataListLoading"
@selection-change="handleSelectionChange"
style="width: 100%"
>
<el-table-column
:reserve-selection="true"
type="selection"
header-align="center"
align="center"
width="50"
>
</el-table-column>
<!-- -->
<el-table-column
label="商品ID"
width="70"
align="center"
prop="productId"
>
<!-- <template slot-scope="scope">
{{ (pageIndex - 1) * pageSize + scope.$index + 1 }}
</template> -->
</el-table-column>
<el-table-column
prop="productName"
header-align="center"
align="center"
label="商品名称"
>
</el-table-column>
<el-table-column
prop="price"
width="120"
header-align="center"
align="center"
sortable
label="商品价格"
>
</el-table-column>
<el-table-column
header-align="center"
align="center"
label="商品图"
width="120"
>
<template slot-scope="scope">
<img
v-if="scope.row.productImages != ''"
:src="scope.row.productImages"
width="25"
height="35"
class="tableImg"
/>
</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" @showchooseBookf = "showchooseBookf"></add-or-update>
<choose-book v-if="chooseBookVisible" :bookIds = bookIds ref="chooseBook" :chooseBookVisible = chooseBookVisible @closeBookf = "closeBookf"></choose-book> -->
</div>
</template>
<script>
// import chooseBook from './chooseBook.vue'
// import AddOrUpdate from './shopproduct-add-or-update'
export default {
data() {
return {
multipleSelectionAll: [], // 所有选中的数据包含跨页数据
multipleSelection: [], // 当前页选中的数据
idKey: "productId", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
dataForm: {
key: "",
},
bookMarketId:null,
dataList: [],
publishStatus: false,
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
chooseBookVisible: false,
bookIds: [],
};
},
components: {
// AddOrUpdate,
// chooseBook
},
activated() {
this.getDataList();
},
methods: {
getRowKeys(row) {
return row.productId;
},
handleSelectionChange(val) {
console.log("🚀 ~ handleSelectionChange ~ val:", val);
// table组件选中事件,记得加上@selection-change="handleSelectionChange"
this.multipleSelection = val;
// this.changePageCoreRecordData();
},
closeBookf() {
this.chooseBookVisible = false;
},
showchooseBookf(e) {
// 显示图书列表
this.chooseBookVisible = true;
// console.log(this.bookIds,'this.bookIds')
// this.$nextTick(() => {
// this.$refs.chooseBook.getBookList()
// this.bookIds = e.bookIds
// })
},
// 获取数据列表
async getDataList(bookMarketId) {
this.bookMarketId=bookMarketId
this.dataListLoading = true;
this.clear();
if (bookMarketId) {
await this.getCorrelationArr(bookMarketId);
}
await 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;
}
// setTimeout(async () => {
// await this.setSelectRow();
// }, 200);
this.dataListLoading = false;
});
},
clear() {
this.$refs.table.clearSelection();
this.multipleSelection=[]
},
// 获取关联数据列表
async getCorrelationArr(bookLabelId) {
await this.$http({
url: this.$http.adornUrl("/book/labelAndMarket/getToLabelList"),
method: "post",
data: this.$http.adornData({
current: 1,
limit: 99999999,
// productName: "",
productId: "",
bookLabelId: bookLabelId,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
this.multipleSelection = data.result.records;
if (this.multipleSelection.length > 0) {
this.multipleSelection.forEach((row) => {
this.$refs.table.toggleRowSelection(row);
});
} else {
this.clear();
}
} else {
this.multipleSelection = [];
}
// await this.changePageCoreRecordData();
});
},
// 每页数
sizeChangeHandle(val) {
// this.changePageCoreRecordData();
this.pageSize = val;
this.pageIndex = 1;
this.getDataList();
},
// 当前页
currentChangeHandle(val) {
// 改变页的时候调用一次
// this.changePageCoreRecordData();
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>

View File

@@ -0,0 +1,329 @@
<template>
<div style="width: 100%; height: 100%" v-loading="dataListLoading">
<!-- <el-form
:inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()"
style="float: right"
>
<el-form-item>
<el-input
v-model="dataForm.key"
placeholder="商品名称"
clearable
size="small"
></el-input>
</el-form-item>
<el-form-item>
<el-button
@click="
pageIndex = 1;
getDataList(bookMarketId);
"
size="small"
>查询</el-button
>
</el-form-item>
</el-form> -->
<div class="shop_box">
<li v-for="(v, i) in associatedGoodsList" class="shop_box_item">
<img
class="shop_box_item_img img-loaded"
style="object-fit: cover"
data-lazy-collect="1"
:src="v.product.productImages"
/>
<div class="shop_box_item_title">
<el-tooltip placement="top">
<div slot="content">{{ v.product.productName }}</div>
<div class="title-text">{{ v.product.productName }}</div>
</el-tooltip>
</div>
<!-- <div class="price-con">
<span class="coupon-price-title">¥</span
><span class="coupon-price-afterCoupon">356</span>
</div> -->
</li>
</div>
<!-- 弹窗, 新增 / 修改 -->
<!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" @showchooseBookf = "showchooseBookf"></add-or-update>
<choose-book v-if="chooseBookVisible" :bookIds = bookIds ref="chooseBook" :chooseBookVisible = chooseBookVisible @closeBookf = "closeBookf"></choose-book> -->
</div>
</template>
<script>
// import chooseBook from './chooseBook.vue'
// import AddOrUpdate from './shopproduct-add-or-update'
export default {
props: ["urlList"],
data() {
return {
multipleSelectionAll: [], // 所有选中的数据包含跨页数据
multipleSelection: [], // 当前页选中的数据
idKey: "productId", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
dataForm: {
key: "",
},
bookMarketId: null,
dataList: [],
associatedGoodsList: [],
publishStatus: false,
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
chooseBookVisible: false,
bookIds: [],
};
},
components: {
// AddOrUpdate,
// chooseBook
},
activated() {
this.getDataList();
},
methods: {
getRowKeys(row) {
return row.productId;
},
handleSelectionChange(val) {
console.log("🚀 ~ handleSelectionChange ~ val:", val);
// table组件选中事件,记得加上@selection-change="handleSelectionChange"
this.multipleSelection = val;
// this.changePageCoreRecordData();
},
closeBookf() {
this.chooseBookVisible = false;
},
showchooseBookf(e) {
// 显示图书列表
this.chooseBookVisible = true;
// console.log(this.bookIds,'this.bookIds')
// this.$nextTick(() => {
// this.$refs.chooseBook.getBookList()
// this.bookIds = e.bookIds
// })
},
// 获取数据列表
async getDataList(bookMarketId) {
this.bookMarketId = bookMarketId;
this.dataListLoading = true;
this.clear();
// if (bookMarketId) {
// await this.getCorrelationArr(bookMarketId);
// }
await 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;
}
// setTimeout(async () => {
// await this.setSelectRow();
// }, 200);
this.dataListLoading = false;
});
},
clear() {
this.$refs.table.clearSelection();
this.multipleSelection = [];
},
// 获取关联数据列表
async getAssociatedGoodsList(bookLabelId) {
this.dataListLoading = true;
await this.$http({
url: this.$http.adornUrl(`${this.urlList.getAssociatedGoodsList}`),
method: "post",
data: this.$http.adornData({
current: 1,
limit: 99999999,
// productName: "",
productId: "",
bookLabelId: bookLabelId,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
this.associatedGoodsList = [...data.result.records,...data.result.records,...data.result.records,...data.result.records,...data.result.records];
this.dataListLoading = false;
console.log(
"🚀 ~ getAssociatedGoodsList ~ this.associatedGoodsList:",
this.associatedGoodsList
);
// if (this.multipleSelection.length > 0) {
// this.multipleSelection.forEach((row) => {
// this.$refs.table.toggleRowSelection(row);
// });
// } else {
// this.clear();
// }
// } else {
// this.multipleSelection = [];
}
// await this.changePageCoreRecordData();
});
},
// 每页数
sizeChangeHandle(val) {
// this.changePageCoreRecordData();
this.pageSize = val;
this.pageIndex = 1;
this.getDataList();
},
// 当前页
currentChangeHandle(val) {
// 改变页的时候调用一次
// this.changePageCoreRecordData();
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>
<style lang="less" scoped>
li {
padding: 0;
margin: 0;
list-style: none;
}
.shop_box {
width: 100%;
height: 100%;
// margin-left: -10px;
padding-bottom: 20px;
// margin-top: 20px;
.shop_box_item {
width: 80px;
height: 120px;
padding: 6px;
box-sizing: border-box;
margin-left: 10px;
margin-bottom: 20px;
float: left;
// margin: 20px;
// background: #f5f5f5;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
border-radius: 4px;
.shop_box_item_img {
margin: 0 auto;
display: flex;
width: 50px;
height: 70px;
object-fit: contain;
background: #bababa;
}
.shop_box_item_title {
color: #333;
font-size: 12px;
font-weight: 600;
margin-top: 10px;
.title-text{
overflow:hidden;
text-overflow:ellipsis;
display:-webkit-box;
-webkit-box-orient:vertical;
-webkit-line-clamp:2;
width: 100%;
}
}
}
}
</style>

View File

@@ -0,0 +1,698 @@
<template>
<div class="tree_box">
<div style="overflow: hidden">
<p class="info_bg">
当前选中标签<span style="color: #17b3a3; font-weight: 600">{{
currentNode ? currentNode.data.title : ""
}}</span>
</p>
<el-button
type="primary"
@click="addOrUpdateHandle()"
style="float: right"
size="mini"
>新增顶级标签</el-button
>
</div>
<!-- show-checkbox -->
<!-- :allow-drop="allowDrop" -->
<div class="custom-tree-container">
<el-tree
:highlight-current="true"
class="filter-tree"
node-key="id"
:data="treeDataList"
:props="defaultProps"
default-expand-all
:filter-node-method="filterNode"
ref="tree"
:draggable="true"
@node-click="handleNodeClick"
:expand-on-click-node="false"
>
<!-- @click="handleClickNodes(node, data)" -->
<span
class="custom-tree-node"
slot-scope="{ node, data }"
@click="handleClickNodes(node, data, 'edit')"
>
<span>{{ node.label }}</span>
<span>
<!-- v-if="node.level <= 1" -->
<el-button
type="text"
size="mini"
@click.stop="handleClickNodes(node, data, 'addChildren')" v-if="data.isLast==1"
>
添加下级
</el-button>
<!-- <el-button
type="text"
size="mini"
@click.stop="handleClickNodes(node, data, 'edit')"
>
修改
</el-button> -->
<!-- v-if="node.childNodes.length == 0" -->
<el-button type="text" size="mini" @click.stop="remove(data)">
删除
</el-button>
</span>
</span>
</el-tree>
</div>
</div>
</template>
<script>
// import dialogComponent from './seckillprodrelation'
export default {
props: ["dataList","urlList"],
data() {
return {
currentNode: null,
treeDataList: [],
defaultProps: {
children: "children",
label: "title",
},
};
},
components: {},
watch: {
dataList(val) {
this.treeDataList = val;
},
filterText(val) {
this.$refs.tree.filter(val);
},
},
activated() {
// this.getDataList();
},
methods: {
allowDrop(draggingNode, dropNode, type) {
console.log(draggingNode.level, dropNode.level);
//注掉的是同级拖拽
if (draggingNode.level === dropNode.level) {
return type === "prev" || type === "next";
} else {
// 不同级进行处理
return false;
}
},
async correlationShop(bookLabelId) {
var status;
var productId = this.$refs.commonShop.multipleSelection.map(
(e) => e.productId
);
console.log("🚀 ~ correlationShop ~ productId:", productId);
await this.$http({
url: this.$http.adornUrl(`/book/labelAndMarket/saveToLabel`),
method: "post",
data: this.$http.adornData({
productId: productId.toString(","),
bookLabelId: bookLabelId,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
status = true;
} else {
this.$message.error(data.msg);
status = false;
}
});
return status;
},
//新增修改
async dataFormSubmit(formName) {
// return false
if (this.addForm.title == "") {
this.$message.error("请输入标签名称");
return false;
}
await this.$refs[formName].validate(async (valid) => {
if (valid) {
await this.$http({
url: this.$http.adornUrl(`${this.urlList.add}`),
method: "post",
data: this.$http.adornData({
...this.addForm,
}),
}).then(async ({ data }) => {
if (data && data.code === 0) {
var status = await this.correlationShop(data.result.id);
if (status) {
await this.getDataList();
var newNodeData = await this.$refs.tree.getNode(data.result.id);
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(data.result.id);
});
await this.handleClickNodes(
newNodeData,
newNodeData.data,
"edit"
);
this.$message({
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.visible = false;
this.$refs.tree.setCheckedKeys([data.result.id]);
// console.log(this.$refs.tree.getCheckedKeys([this.addForm.id]),'88888');
// this.$refs["addForm"].resetFields();
// this.addForm={}
// this.$emit("refreshDataList");
},
});
}
} else {
this.$message.error(data.msg);
}
});
}
});
},
setCheckedKeys() {
this.$refs.tree.setCheckedKeys([0]);
},
handlereset() {
this.currentNode = null;
this.isFresh = false;
this.isFresh = true;
},
handleClickNodes(node, data, type) {
this.addForm = {};
// console.log(this.$refs.tree.handleClickNodes(), "当前选中节点");
console.log(node, data, "当前选中节点");
this.currentNode = node;
this.isFresh = false;
this.isFresh = true;
var form = {};
switch (type) {
case "add":
form = { ...data };
break;
case "edit":
form = { ...node.data };
break;
case "addChildren":
form = {
children: [],
delFlag: 0,
isLast: 0,
pid: data.id,
sort: 0,
title: "",
};
break;
}
this.addForm = { ...form };
this.$nextTick(() => {
this.$emit('getCommonShopDataList',type,type == "edit" ? form.id : null,this.addForm)
// this.$refs.commonShop.clear();
// this.$refs.commonShop.bookMarketId = null;
// this.$refs.commonShop.getDataList();
});
},
addOrUpdateHandle() {
var addform = {
children: [],
delFlag: 0,
isLast: 0,
pid: 0,
sort: 0,
title: "",
};
this.handleClickNodes({ data: addform }, addform, "add");
// if (!this.currentNode) {
// this.$message.error("请先选择分类");
// return;
// }
},
async remove(data) {
var ids = { productId: data.productId };
this.$confirm(`是否删除标签【${data.title}】?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
this.$http({
url: this.$http.adornUrl(
`${urlList.delete}?id=` + data.id
),
method: "post",
data: {},
}).then(async ({ data }) => {
this.$message({
type: "success",
message: "删除成功!",
});
this.currentNode = null;
this.isFresh = false;
this.addForm = {};
this.$nextTick(() => {
this.isFresh = true;
});
await this.addOrUpdateHandle();
// this.expandedkey = [node.parent.data.catId]
});
})
.catch(() => {});
},
filterNode(value, data) {
if (!value) return true;
return data.title.indexOf(value) !== -1;
},
// renderContent(h, { node, data, store }) {
// return;
// `<span
// style="flex: 1; display: flex; align-items: center; justify-content: space-between; padding-right: 8px;"
// on-mouseenter={() => this.mouseenteract(data)}
// on-mouseleave={() => this.mouseleaveact(data)}
// >
// <span>
// <span>{node.label}</span>
// </span>
// {this.isact == data ? (
// <span>
// {this.isact.typeName == "模板组" ? (
// <el-button
// class="m-r-10"
// type="text"
// icon="el-icon-edit"
// on-click={() => this.handleUpdateGroup(node, data)}
// ></el-button>
// ) : (
// <span></span>
// )}
// <el-button
// type="text"
// icon="el-icon-delete"
// on-click={(e) => this.handleDelete(node, data, e)}
// ></el-button>
// </span>
// ) : (
// <span></span>
// )}
// </span>`;
// },
updateRenderContent(h, { node, data, store }) {
return `
<span style="flex: 1; display: flex; align-items: center; justify-content: space-between; padding-right: 8px;">
<span>
{this.isact == data ? (
<input
type="text"
onChange={this.handleChangeTitle.bind(this)}
value={node.label}
/>
) : (
<span>{node.label}</span>
)}
</span>
{this.isact == data ? (
<span>
{this.isact.typeName == "模板组" ? (
<span>
<el-button
class="m-r-10"
type="text"
icon="el-icon-check"
on-click={() => this.updateGroup(node, data)}
></el-button>
<el-button
class="m-r-10"
type="text"
icon="el-icon-close"
on-click={(e) => this.cancelUpdate(node, data, e)}
></el-button>
</span>
) : (
<span></span>
)}
</span>
) : (
<span></span>
)}
</span>`;
},
//获取鼠标进入节点的数据
mouseenteract(da) {
this.isact = da;
},
mouseleaveact(da) {
this.isact = "";
},
handleNodeClick(pdata) {
this.curNode = pdata;
document
.getElementsByClassName("el-tree-node__content")[0]
.setAttribute("class", "el-tree-node__content");
},
handleDelete(node, data, e) {
e.stopPropagation();
//存在则添加到子级
const parent = node.parent;
const children = parent.data.nodes || parent.data;
//若parent.data是对象操作的是子级如果是数组操作的是最外层
if (Array.isArray(parent.data)) {
const parentIndex = parent.data.findIndex((d) => d.id === data.id);
parent.data.splice(parentIndex, 1);
} else {
const childIndex = children.findIndex((d) => d.id === data.id);
children.splice(childIndex, 1);
}
this.curNode = undefined;
},
//新增组
handleAddGroup() {
/**
* 如果模版深度最多两层,取消该部分注释
* //最多只有两层组 不可能添加在dept2的组上 curNode存在 并且 深度超过1
if (this.curNode != undefined && this.curNode.depth != 1) {
this.$message.warning("不能添加超过两层");
return;
}
*/
//如果isUpdateGroup 已经是true了 说明重复点击了
if (this.isUpdateGroup) {
return;
}
let id = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
let newChild = {
parentId: "", //如果有这个id 是插入第二层 否则是第一层 可有可无
text: "", //必须有 this.templateContent.tempName
nodes: [],
id: id,
typeName: "模板组",
temporaryData: "1", //用来区分临时数据
};
/* 如果模版深度最多两层,以下条件改成该部分注释
this.curNode && this.curNode.depth == 1
*/
this.indexRecord = [];
if (this.curNode) {
if (!this.curNode.nodes) {
this.$message.warning("模板不可添加");
return;
}
newChild.parentId = this.curNode.id;
/* 如果模版深度最多两层,以下条件改成该部分注释
const index = this.treeDataList.findIndex(
item => item.id == this.curNode.id
);
this.treeDataList[index].nodes.push(newChild);
*/
//找到tree中的index轨迹
this.getTemplateTreeNode(this.curNode.id, this.treeDataList, 0);
//按照index轨迹插入节点
this.insertNode(
newChild,
this.treeDataList,
this.indexRecord,
this.indexRecord.length
);
this.isBreak = false;
} else if (this.curNode == undefined) {
//没有选中的时候 添加到最外层
newChild.depth = 1;
this.treeDataList.push(newChild);
}
//调用出updateRender的input
this.isact = newChild;
this.isUpdateGroup = true;
},
//递归遍历获得选中node
getTemplateTreeNode(target, list, dept) {
//空数组直接返回
if (list.length == 0) return;
let dataLen = list.length;
for (let i = 0; i < dataLen; i++) {
//如果不匹配
if (target != list[i].id) {
//存在nodes 遍历nodes里的节点
if (list[i].nodes) {
this.indexRecord[dept] = i;
let recordDept = dept + 1;
this.getTemplateTreeNode(target, list[i].nodes, recordDept);
} else {
//不存在nodes 继续遍历
continue;
}
} else {
//匹配,则修改下标数组
this.indexRecord[dept] = i;
this.isBreak = true;
break;
}
//删除不匹配的轨迹 如果已经break了说明已经找到正确的节点就不用再删了
if (!this.isBreak) {
this.indexRecord.pop();
}
}
},
//插入节点
insertNode(insertChild, tree, indexArr, len) {
let index = indexArr.length - len;
if (len == 0) {
tree.push(insertChild);
} else {
this.insertNode(
insertChild,
tree[indexArr[index]].nodes,
indexArr,
len - 1
);
}
},
//修改组
handleUpdateGroup() {
this.isUpdateGroup = true;
},
//修改组名时获取title
handleChangeTitle(e) {
let value = e.target.value;
this.isactTitle = value;
},
updateGroup(node, data) {
//先handleChangeTitle获取title 再调用
setTimeout(() => {
if (this.isactTitle.trim() == "") {
this.$message.warning("名称不能为空");
return;
}
//修改数据组
this.isUpdateGroup = false;
const parent = node.parent;
const children = parent.data.nodes || parent.data;
const index = children.findIndex((d) => d.id === data.id);
let temp = data;
temp.text = this.isactTitle;
children.splice(index, 1, temp);
}, 500);
},
cancelUpdate(node, data, e) {
this.$message.info("已取消");
this.isUpdateGroup = false;
//如果是插入操作 需要移除数据
if (this.isact.temporaryData) {
this.handleDelete(node, data, e);
}
},
// 获取数据列表
async getDataList() {
this.dataListLoading = true;
await this.$http({
url: this.$http.adornUrl("/book/labelAndMarket/labelTree"),
method: "get",
// params: this.$http.adornParams({
// 'page': this.pageIndex,
// 'limit': this.pageSize,
// 'key': this.dataForm.key
// })
}).then(({ data }) => {
console.log("🚀 ~ getDataList ~ data:", data);
if (data && data.code === 0) {
this.treeDataList = data.result;
// this.totalPage = data.page.totalCount
} else {
this.treeDataList = [];
// 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(row) {
// this.addOrUpdateVisible = true;
// this.$nextTick(() => {
// this.$refs.addOrUpdate.init(row);
// });
// },
},
};
</script>
<style lang="less" scoped>
.tree_box {
width: 400px;
height: 100%;
float: left;
border: 1px solid #bababa;
border-radius: 10px;
padding: 15px;
box-sizing: border-box;
// background: #fafafa;
}
.border_box {
height: 100px;
margin-bottom: 10px;
.title {
display: flex;
align-items: center;
font-weight: 600;
font-size: 16px;
margin-bottom: 10px;
// color: #17b3a3;
.line {
width: 4px;
height: 20px;
margin-right: 8px;
background: #17b3a3;
}
}
}
.border_box {
width: 100%;
float: right;
background: #fffefe;
border: 1px solid #bababa;
border-radius: 10px;
padding: 15px 15px;
box-sizing: border-box;
}
.tree_content_box {
height: calc(100% - 110px) !important;
}
.mod-config {
width: 100%;
height: 82vh;
overflow: hidden;
}
.el-tree-node__content {
.el-button {
display: none;
}
}
.el-tree-node__content:hover {
.el-button {
display: inline;
}
}
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
background-color: #eaebed;
color: #4796ec;
font-weight: bold;
}
.el-tree {
height: 350px;
overflow-y: auto !important;
.el-tree-node__content span {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
// .el-card {
// background: none !important;
// }
p {
margin: 0;
margin-bottom: 10px;
}
.submitButton {
float: right;
margin-top: 20px;
}
// .el-tree-node__content .el-button {
// // width: 120px !important;
// display: block !important;
// }
// ::v-deep .el-tree .el-tree-node__content span:nth-child(2) {
// width: 120px;
// display: flex !important;
// align-items: center !important;
// justify-content: space-between !important;
// }
// /deep/.el-table__row--level-1 {
// display: block !important;
// }
.addFormBox {
.form_item {
width: 49%;
float: left;
}
}
.custom-tree-container {
height: calc(100% - 100px);
.filter-tree {
height: 100%;
}
}
.info_bg {
background: #e0dede;
height: 28px;
line-height: 28px;
padding-left: 10px;
// padding: 8px 5px;
box-sizing: border-box;
// margin-top: -10px;
border-radius: 4px;
font-size: 14px;
width: calc(100% - 120px);
float: left;
}
</style>