Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

484 Zeilen
17 KiB

  1. <template>
  2. <div class="box-center">
  3. <div class="center">
  4. <div style="display: flex;">
  5. <div style="font-weight: 400;font-size: 20px">
  6. 系统默认节点 &nbsp;&nbsp;&nbsp; <span style="font-size: 16px">(提示:拖拽同级类可以排序)</span>
  7. </div>
  8. <div style="height: 30px;margin-left: 100px;">
  9. <el-button style="" size="mini" type="primary" @click.stop="addBigNode">添加大类</el-button>
  10. </div>
  11. </div>
  12. <div style="margin-top: 16px;width: 100%; ">
  13. <el-tree ref="tree" :data="datalist" node-key="id" default-expand-all
  14. :allow-drop="allowDrop" @node-drop="Peerdrag" draggable>
  15. <span slot-scope="{ node, data }">
  16. <!-- <span>{{ node.label }}</span> -->
  17. <span v-if="node.level == 1" style="font-size: 18px; color: #32363d" >
  18. <img class="levelimg1" src="/img/level1.png" alt="" />
  19. {{ data.label }}
  20. </span>
  21. <span v-if="node.level == 2 " style="font-size: 16px; color: #32363d" >
  22. <img class="levelimg2" src="/img/level2.png" alt="" />
  23. {{ data.label }}
  24. </span>
  25. <span v-if="node.level == 3" style="font-size: 14px; color: #32363d" >
  26. <img class="levelimg3" src="/img/level3.png" alt="" />
  27. {{ node.label }}
  28. </span>
  29. <!-- <span v-if="node.level==1">
  30. <el-button style="color:red; margin-left: 20px;" type="text" size="mini"
  31. @click.stop="() => append(node,data)">添加二级</el-button>
  32. <el-button type="text" size="mini" @click.stop="() => remove(node,data)"> 删除 </el-button>
  33. <el-button type="text" size="mini" @click.stop="() => ddeditor(node,data)"> 编辑 </el-button>
  34. </span> -->
  35. <!-- <span v-if="node.level==2">
  36. <el-button type="text" size="mini" style=" margin-left: 20px;"
  37. @click.stop="() => append1(node,data)"> 添加三级 </el-button>
  38. <el-button type="text" size="mini" @click.stop="() => remove(node,data)"> 删除 </el-button>
  39. <el-button type="text" size="mini" @click.stop="() => ddeditor(node,data)"> 编辑 </el-button>
  40. </span>
  41. <span v-if="node.level==3">
  42. <el-button style=" margin-left: 20px;" type="text" size="mini" @click.stop="() => remove(node,data)"> 删除 </el-button>
  43. <el-button type="text" size="mini" @click.stop="() => ddeditor(node,data)"> 编辑 </el-button>
  44. </span> -->
  45. <span v-if="node.level == 1" >
  46. <span class="editorcd" @click="append(node, data)" >
  47. <img class="levelimg3" src="/img/add1.png" alt="" />
  48. <span>添加二级</span>
  49. </span>
  50. <el-button type="text" size="mini" @click.stop="() => remove(node,data)"> 删除 </el-button>
  51. <el-button type="text" size="mini" @click.stop="() => ddeditor(node,data)"> 编辑 </el-button>
  52. </span>
  53. <span v-if="node.level == 2" >
  54. <span class="editorcd2" @click="append1(node, data)" >
  55. <img class="levelimg3" src="/img/add2.png" alt="" />
  56. <span>添加三级</span>
  57. </span>
  58. <span style="margin-left: 10px">
  59. <el-button class="editorcd" type="text" size="mini" @click="ddeditor(node, data)">编辑</el-button>
  60. </span>
  61. <span style="margin-left: 10px">
  62. <el-button class="remove" type="text" size="mini" @click="remove(node, data)" >删除</el-button>
  63. </span>
  64. </span>
  65. <span v-if="node.level == 3">
  66. <span style="margin-left: 10px">
  67. <el-button class="editorcd" type="text" size="mini" @click="ddeditor(node, data)" >编辑</el-button>
  68. </span>
  69. <span style="margin-left: 10px">
  70. <el-button class="remove" type="text" size="mini" @click="remove(node, data)" >删除</el-button>
  71. </span>
  72. </span>
  73. </span>
  74. </el-tree>
  75. </div>
  76. </div>
  77. <!-- 删除确认弹框 -->
  78. <el-dialog title="提示" :visible.sync="dialogDelete" width="30%">
  79. <span>确定删除该条内容吗</span>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button @click="dialogDelete = false">取 消</el-button>
  82. <el-button type="primary" @click="checkDelete">确 定</el-button>
  83. </span>
  84. </el-dialog>
  85. <!-- 新增弹框 -->
  86. <el-dialog title="新增大类" :visible.sync="dialogShow">
  87. <el-form :model="addForm" label-position="left" label-width="80px">
  88. <el-row :gutter="10">
  89. <el-col :span="10">
  90. <el-form-item label="一级大类名称:" v-if="level==0" :label-width="formLabelWidth">
  91. <el-input v-model="addForm.name" autocomplete="off"></el-input>
  92. </el-form-item>
  93. <el-form-item label="二级小类名称:" v-if="level==1" :label-width="formLabelWidth">
  94. <el-input v-model="addForm.name" autocomplete="off"></el-input>
  95. </el-form-item>
  96. <el-form-item label="三级小类名称:" v-if="level==2" :label-width="formLabelWidth">
  97. <el-input v-model="addForm.name" autocomplete="off"></el-input>
  98. </el-form-item>
  99. </el-col>
  100. </el-row>
  101. </el-form>
  102. <div slot="footer" class="dialog-footer">
  103. <el-button @click="dialogShow = false">取 消</el-button>
  104. <el-button type="primary" @click="onSubmit">确 定</el-button>
  105. </div>
  106. </el-dialog>
  107. <!--?编辑弹框?-->
  108. <el-dialog title="编辑" :visible.sync="isshowage">
  109. <div style="display: flex;align-items: center;height: 40px;">
  110. <div>类名:</div>
  111. <div>
  112. <el-input type="text" v-model="frosasd.name" autocomplete="off"></el-input>
  113. </div>
  114. </div>
  115. <div slot="footer" class="dialog-footer">
  116. <el-button @click="submicll()">取 消</el-button>
  117. <el-button type="primary" @click="submiadd()">提交</el-button>
  118. </div>
  119. </el-dialog>
  120. </div>
  121. </template>
  122. <script>
  123. export default {
  124. data() {
  125. return {
  126. datalist: [],
  127. drag: false,
  128. activeNames: ['1'],
  129. dialogShow: false, // 大类新增
  130. addShow: false, // 小类新增
  131. dialogDelete: false, //删除提示弹框
  132. formLabelWidth: '120px',
  133. addItem: null, // 当前添加小类的项
  134. addForm: {
  135. name: '',
  136. house: '',
  137. company: ''
  138. },
  139. childDelete: null,
  140. level: 1, //操作节点的层级
  141. pid:0,
  142. deleteId: null, // 要删除的表单节点的ID
  143. isshowage:false,
  144. frosasd:{
  145. name: '',
  146. id:''
  147. },
  148. }
  149. },
  150. mounted() {
  151. this.templategetMarketingTree()
  152. },
  153. methods: {
  154. templategetMarketingTree(){
  155. this.$api.http.templategetMarketingTree({}).then((res) => {
  156. console.log(res);
  157. let data = res.data;
  158. data = JSON.stringify(data).replace(/name/g, "label");
  159. data = JSON.parse(data);
  160. this.datalist = data;
  161. })
  162. },
  163. //编辑
  164. ddeditor(node,data){
  165. this.frosasd.name=data.label;
  166. this.frosasd.id=data.id;
  167. this.isshowage=true;
  168. },
  169. submicll(){
  170. this.isshowage=false;
  171. },
  172. //编辑提交
  173. submiadd(){
  174. var that=this;
  175. this.$api.http.templategeupdate({
  176. name: that.frosasd.name,
  177. id:that.frosasd.id
  178. }).then((res) => {
  179. that.datalist.forEach((item,index)=>{
  180. if(item.id==that.frosasd.id){
  181. that.datalist[index].label=that.frosasd.name;
  182. that.isshowage=false;
  183. that.$message({
  184. message: '修改成功',
  185. type: 'success'
  186. });
  187. return
  188. }else{
  189. item.children.forEach((asd,indexesd)=>{
  190. if(asd.id==that.frosasd.id){
  191. that.datalist[index].children[indexesd].label=that.frosasd.name;
  192. that.isshowage=false;
  193. that.$message({
  194. message: '修改成功',
  195. type: 'success'
  196. });
  197. return
  198. }else{
  199. asd.children.forEach((zxc,indexzxc)=>{
  200. if(zxc.id==that.frosasd.id){
  201. that.datalist[index].children[indexesd].children[indexzxc].label=that.frosasd.name;
  202. that.isshowage=false;
  203. that.$message({
  204. message: '修改成功',
  205. type: 'success'
  206. });
  207. return
  208. }
  209. })
  210. }
  211. })
  212. }
  213. })
  214. })
  215. },
  216. //添加大类
  217. addBigNode() {
  218. this.level=0;
  219. this.addForm.name = '';
  220. this.dialogShow = true;
  221. },
  222. // 添加二级小类节点入口
  223. append(node, data) {
  224. this.level=1;
  225. this.addForm.name = '';
  226. this.pid = data.id;
  227. this.dialogShow = true
  228. },
  229. // 添加三级小类节点入口
  230. append1(node, data) {
  231. this.level=2;
  232. this.addForm.name = '';
  233. this.pid = data.id
  234. this.dialogShow = true
  235. },
  236. // 大类保存
  237. onSubmit() {
  238. if (this.addForm.name != "") {
  239. this.dialogShow = false
  240. this.addNode()
  241. } else {
  242. this.$message({
  243. message: '内容不能为空',
  244. type: 'warning'
  245. });
  246. return;
  247. }
  248. },
  249. // 新增的节点保存
  250. addNode() {
  251. this.$api.http.templategeadd({
  252. pid: this.pid,
  253. name: this.addForm.name,
  254. sign:0
  255. }).then((res) => {
  256. if (this.level == 0) { // 大类
  257. let newNode = {
  258. id: res.data,
  259. sign: 1,
  260. pid:0,
  261. sort: this.datalist.length + 1,
  262. label: this.addForm.name,
  263. fraction: '',
  264. children: []
  265. }
  266. this.datalist.push(newNode);
  267. } else if(this.level == 1) {
  268. // 二级
  269. let newChild = {
  270. id: res.data,
  271. pid:this.pid,
  272. sign: 1,
  273. fraction: '',
  274. sort: null,
  275. label: this.addForm.name,
  276. children: []
  277. };
  278. this.datalist.forEach((item,index)=>{
  279. if(item.id==this.pid){
  280. item.children.push(newChild)
  281. }
  282. })
  283. }else{
  284. let newChilds = {
  285. id: res.data,
  286. sign: 1,
  287. fraction: '',
  288. pid:this.pid,
  289. sort: null,
  290. label: this.addForm.name
  291. };
  292. this.datalist.forEach((item,index)=>{
  293. item.children.forEach((ite,inde)=>{
  294. if(ite.id==this.pid){
  295. ite.children.push(newChilds)
  296. }
  297. })
  298. })
  299. }
  300. })
  301. },
  302. // 删除标签
  303. remove(node, data) {
  304. this.deleteId = data.id
  305. this.dialogDelete = true;
  306. },
  307. // 删除自定义的节点
  308. checkDelete() {
  309. this.$api.http.templategedel({
  310. id: this.deleteId
  311. }).then((res) => {
  312. this.datalist.forEach((item,index)=>{
  313. if(item.id==this.deleteId){
  314. this.datalist.splice(index,1)
  315. }else{
  316. item.children.forEach((ite,inde)=>{
  317. if(ite.id==this.deleteId){
  318. this.datalist[index].children.splice(inde,1)
  319. }else{
  320. ite.children.forEach((it,ine)=>{
  321. if(it.id==this.deleteId){
  322. this.datalist[index].children[inde].children.splice(ine,1)
  323. }
  324. })
  325. }
  326. })
  327. }
  328. })
  329. this.dialogDelete = false;
  330. })
  331. },
  332. //同级节点才可以拖拽
  333. allowDrop(draggingNode, dropNode, type) {
  334. if (draggingNode.level === dropNode.level) {
  335. if (draggingNode.parent.id === dropNode.parent.id) {
  336. // 向上拖拽 || 向下拖拽
  337. return type === "prev" || type === "next";
  338. }
  339. } else {
  340. // 不同级进行处理
  341. return false;
  342. }
  343. },
  344. //拖拽排序
  345. Peerdrag(before) {
  346. let arr = [];
  347. this.datalist.forEach((item, index) => {
  348. if (before.data.pid == item.pid) {
  349. arr.push(item)
  350. } else {
  351. if (item.children.length == 0) {
  352. return
  353. } else {
  354. item.children.forEach((ite, inde) => {
  355. if (before.data.pid == ite.pid) {
  356. arr.push(ite)
  357. } else {
  358. if (ite.children.length == 0) {
  359. return
  360. } else {
  361. ite.children.forEach((it, ins) => {
  362. if (before.data.pid == it.pid) {
  363. arr.push(it)
  364. }
  365. })
  366. }
  367. }
  368. })
  369. }
  370. }
  371. })
  372. arr.forEach((item, index) => {
  373. item.sort = index
  374. })
  375. let params = {
  376. list: []
  377. }
  378. params.list = arr.map(item => {
  379. return {
  380. id: item.id,
  381. sort: item.sort
  382. }
  383. })
  384. this.dragSort(params.list)
  385. },
  386. dragSort(list){
  387. this.$api.http.templategeupdateSort({children:list}).then((res) => {
  388. })
  389. },
  390. },
  391. }
  392. </script>
  393. <style scoped="scoped" lang="scss" >
  394. .box-center {
  395. width: 100%;
  396. padding: 15px;
  397. padding-top: 0px;
  398. min-width: 1000px;
  399. padding-bottom: 100px;
  400. }
  401. .center{
  402. width: 100%;
  403. height: 100%;
  404. padding: 15px 15px;
  405. list-style: none;
  406. background: #ffffff;
  407. min-height: 80vh;
  408. border-radius: 4px;
  409. }
  410. .biaoti {
  411. font-size: 20px;
  412. font-family: PingFangSC-Semibold, PingFang SC;
  413. font-weight: 600;
  414. color: #32363d;
  415. line-height: 20px;
  416. padding-top: 25px;
  417. }
  418. .custom-tree-node {
  419. flex: 1;
  420. display: flex;
  421. align-items: center;
  422. justify-content: space-between;
  423. font-size: 14px;
  424. padding-right: 183px;
  425. }
  426. .remove {
  427. color: red;
  428. }
  429. .editorcd {
  430. color: #2671e2;
  431. }
  432. .editorcd2 {
  433. color: #e6a12f;
  434. }
  435. .levelimg1 {
  436. width: 18px;
  437. height: 18px;
  438. }
  439. .levelimg2 {
  440. width: 16px;
  441. height: 16px;
  442. }
  443. .levelimg3 {
  444. width: 14px;
  445. height: 14px;
  446. }
  447. </style>