You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1085 lines
31 KiB

  1. <template>
  2. <div class="box-center">
  3. <div id="app">
  4. <div class="content-left">
  5. <div v-if="orgType!=3">
  6. <span style="color: red">*</span> 楼盘选择:
  7. <el-select v-model="houseId" size="mini" @change="selectChange" clearable :disabled="disabledcet" placeholder="请选择">
  8. <el-option v-for="item in houseList" :key="item.value" :label="item.label" :value="item.value">
  9. </el-option>
  10. </el-select>
  11. </div>
  12. <div class="select" style="display: flex;margin-top: 40px;">
  13. <div style="font-size:18px;font-weight: bold;">添加模板</div>
  14. <el-row>
  15. <el-col :offset="18" :span="6">
  16. <el-button size="mini" type="primary" @click="addBigNode">添加大类</el-button>
  17. </el-col>
  18. </el-row>
  19. </div>
  20. <input ref="input" style="display:none" value='${tempId}' />
  21. <el-tree ref="tree"
  22. :data="treeList"
  23. :default-checked-keys="defaultCheck" show-checkbox node-key="id"
  24. default-expand-all :check-on-click-node="true" :expand-on-click-node="false"
  25. draggable :allow-drop="allowDrop" :allow-drag="allowDrag"
  26. @node-drop="Peerdrag">
  27. <span class="custom-tree-node" slot-scope="{ node, data }">
  28. <span> <b v-if="data.sign==0 && data.houseId==null" style="color: red">*</b> {{ node.label }}</span>
  29. <span>
  30. <el-button style="color:red;" v-if="node.level==1" type="text" size="mini" @click.stop="() => append(node,data)">添加子类</el-button>
  31. <span v-if="data.houseId!=null">
  32. <el-button v-if="node.level==2" type="text" size="mini" @click.stop="() => append1(node,data)"> 添加子类 </el-button>
  33. <el-button type="text" size="mini" @click.stop="() => remove(node,data)"> 删除 </el-button>
  34. <el-button type="text" size="mini" @click.stop="() => ddeditor(node,data)"> 编辑 </el-button>
  35. </span>
  36. <el-button v-if="data.sign!=1" type="text" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</el-button>
  37. </span>
  38. </span>
  39. </el-tree>
  40. <div class="update-btn">
  41. <el-button type="primary" size="mini" @click="getCheckedNode">获取选中节点</el-button>
  42. </div>
  43. <!-- 新增弹框 -->
  44. <el-dialog title="新增" :visible.sync="dialogFormVisible">
  45. <el-form :model="addForm">
  46. <el-row :gutter="20">
  47. <el-col :span="12">
  48. <el-form-item label="一级大类名称:" v-if="level==0" :label-width="formLabelWidth">
  49. <el-input v-model="addForm.name" maxlength="8" autocomplete="off"></el-input>
  50. </el-form-item>
  51. <el-form-item label="二级小类名称:" v-if="level==1" :label-width="formLabelWidth">
  52. <el-input v-model="addForm.name" maxlength="8" autocomplete="off"></el-input>
  53. </el-form-item>
  54. <el-form-item label="三级小类名称:" v-if="level==2" :label-width="formLabelWidth">
  55. <el-input v-model="addForm.name" maxlength="8" autocomplete="off"></el-input>
  56. </el-form-item>
  57. </el-col>
  58. </el-row>
  59. </el-form>
  60. <div slot="footer" class="dialog-footer">
  61. <el-button @click="dialogFormVisible = false">取 消</el-button>
  62. <el-button type="primary" @click="addSubmit">确 定</el-button>
  63. </div>
  64. </el-dialog>
  65. <!-- 删除确认弹框 -->
  66. <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
  67. <span>确定删除该条内容吗</span>
  68. <span slot="footer" class="dialog-footer">
  69. <el-button @click="dialogVisible = false">取 消</el-button>
  70. <el-button type="primary" @click="checkDelete">确 定</el-button>
  71. </span>
  72. </el-dialog>
  73. </div>
  74. <!-- 评分 -->
  75. <div class="content-right">
  76. <el-row>
  77. <el-col :span="20">
  78. (提示:拖拽大类可以排序)
  79. </el-col>
  80. </el-row>
  81. <draggable
  82. class="list-group"
  83. tag="ul"
  84. v-model="newlist"
  85. v-bind="dragOptions"
  86. @start="drag = true"
  87. @end="drag = false"
  88. @change="onDragCallback">
  89. <div style="border: 2px dashed #CCCCCC;margin-top: 30px;padding:6px;border-radius: 6px;font-size: 14px;"
  90. v-for="(item,index) in newlist" :key="item.id">
  91. <div style="display: flex;align-items: center;height: 40px;">
  92. <div >{{item.name||''}}:</div>
  93. <div>
  94. <el-input @input="inputYiji($event,index)" style="width: 100px;" v-model.number="item.fraction" type="number" size="mini" ></el-input>
  95. </div>
  96. <div style="margin-left: 10px;">
  97. <el-button type="danger" size="mini" @click="Deletecategories(item,index)">删除</el-button>
  98. </div>
  99. </div>
  100. <div class="erji" style="margin-left: 30px;" v-for="(asd,idx) in item.children" :key="idx">
  101. <div style="display: flex;align-items: center;height: 40px;">
  102. <div>{{asd.name||''}}:</div>
  103. <div>
  104. <el-input @input="inputBlur($event,index,idx)" style="width: 100px;" v-model.number="asd.fraction" type="number" size="mini" ></el-input>
  105. </div>
  106. <div style="margin-left: 10px;">
  107. <el-button type="primary" size="mini" @click="Removethesecondary(index,idx,asd)">删除</el-button>
  108. </div>
  109. </div>
  110. <div class="sanji" style="width:90%;" >
  111. <div style="display: flex;align-items: center;height: 40px;" v-for="(sanji,indx) in asd.children" :key="indx">
  112. <div style="width:85% ;margin-left: 30px;">{{sanji.name||''}}</div>
  113. <div style="margin-left: 10px;">
  114. <el-button type="info" size="mini" @click="Deletethelevel(index,idx,indx,sanji)">删除</el-button>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </draggable>
  121. <div style="display: flex;align-items: center;margin-top:30px;">
  122. <el-button type="primary" size="mini" @click="cancel">取消</el-button>
  123. <el-button style="margin-left: 30px;" type="primary" size="mini" @click="submitForm">保存</el-button>
  124. </div>
  125. </div>
  126. <!--?编辑弹框?-->
  127. <el-dialog title="编辑" :visible.sync="isshowage">
  128. <div style="display: flex;align-items: center;height: 40px;">
  129. <div>类名:</div>
  130. <div>
  131. <el-input type="text" maxlength="8" v-model="frosasd.name" autocomplete="off"></el-input>
  132. </div>
  133. </div>
  134. <div slot="footer" class="dialog-footer">
  135. <el-button @click="submicll()">取 消</el-button>
  136. <el-button type="primary" @click="submiadd()">提交</el-button>
  137. </div>
  138. </el-dialog>
  139. </div>
  140. </div>
  141. </template>
  142. <script>
  143. import draggable from 'vuedraggable'
  144. export default {
  145. data() {
  146. return {
  147. drag: false,
  148. houseList: [],
  149. houseId: "", // 楼盘
  150. treeList: [], //树形数据
  151. newlist: [],
  152. nodelist: [],
  153. orgType:localStorage.getItem('orgType'),
  154. dialogFormVisible: false, // 弹框
  155. dialogVisible: false,
  156. isshowage: false,
  157. frosasd: {
  158. name: "",
  159. id: "",
  160. },
  161. addForm: {
  162. // 新增节点表单
  163. name: "",
  164. },
  165. rightform: {
  166. formData: [],
  167. },
  168. pid: 0,
  169. level: 1, //操作节点的层级
  170. treeData: null,
  171. formLabelWidth: "120px",
  172. deleteType: "form",
  173. checklist: [], // 树图,设置初始选中值
  174. defaultCheck: [], // 选中的id
  175. addid: null, // 新增的节点id(接口生成)
  176. deleteId: null, // 要删除的表单节点的ID
  177. disabledcet: false,
  178. Templateid:'',
  179. };
  180. },
  181. components: {
  182. draggable,
  183. },
  184. created() {
  185. this.allTreeListId = []; // 存储的当前树图所有的接单的ID集合,如:[1,3,4,6,7]
  186. this.noIds = []; // 左侧树没有,但右侧有的数据
  187. this.rateMap = new Map();
  188. this.sortMap = new Map();
  189. },
  190. mounted() {
  191. var isnull=this.$route.query.flag;
  192. this.Templateid=isnull.id;
  193. this.setInitCheck()
  194. },
  195. computed: {
  196. dragOptions() {
  197. return {
  198. animation: 200,
  199. group: "description",
  200. disabled: false,
  201. ghostClass: "ghost",
  202. };
  203. },
  204. },
  205. methods: {
  206. // 楼盘选择
  207. selectChange(e) {
  208. this.houseId = e;
  209. this.templategetMarketingTree();
  210. },
  211. // 获取楼盘下拉的数据
  212. getHouse() {
  213. this.$api.api.findHouseByUser({
  214. orgType: localStorage.getItem("orgType"),
  215. }).then((res) => {
  216. this.houseList = res.data.map((item) => {
  217. return {
  218. value: item.id,
  219. label: item.propertyName,
  220. };
  221. });
  222. if (this.houseId == "") {
  223. if(localStorage.getItem('orgType')==3){
  224. this.houseId=localStorage.getItem('houseId')
  225. }else{
  226. this.houseId = this.houseList[0].value;
  227. }
  228. // this.houseId = this.houseList[0].value;
  229. }
  230. this.templategetMarketingTree()
  231. })
  232. },
  233. //获取模板
  234. templategetMarketingTree(){
  235. let parmest={
  236. houseId:this.houseId,
  237. }
  238. this.$api.api.templategetMarketingTree(parmest).then((res) => {
  239. console.log(res);
  240. let data = res.data;
  241. data = JSON.stringify(data).replace(/name/g, "label");
  242. data = JSON.parse(data);
  243. this.treeList = data;
  244. this.getAllTreeListId(this.treeList);
  245. })
  246. },
  247. // 递归获取所有的ID
  248. getAllTreeListId(arr) {
  249. const setSelected = (arr) => {
  250. arr.forEach((item) => {
  251. this.allTreeListId.push(item.id);
  252. if (item.children) {
  253. setSelected(item.children);
  254. }
  255. });
  256. };
  257. setSelected(arr);
  258. },
  259. // ------获取选中的节点
  260. getCheckedNode() {
  261. let res = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys());
  262. console.log(res)
  263. let arr = [];
  264. let arr1 = JSON.parse(JSON.stringify(this.treeList));
  265. res.forEach((resd, index) => {
  266. var arrarys = this.familyTree(arr1, resd);
  267. arr.push(arrarys[0]);
  268. });
  269. arr.forEach((item, index) => {
  270. item.name = item.label;
  271. this.nodelist.push(item);
  272. });
  273. this.listCheckedchaifen();
  274. },
  275. // 树图,设置初始选中值及分数回显--编辑跳转过来的
  276. setInitCheck() {
  277. if(this.Templateid==''){
  278. //获取楼盘
  279. this.getHouse();
  280. }else{
  281. this.disabledcet = true;
  282. let parmest={
  283. tempId:this.Templateid,
  284. }
  285. this.$api.http.templatedelfindByTempId(parmest).then((res) => {
  286. this.houseId = res.data.houseId;
  287. this.checklist = res.data.list;
  288. this.nodelist = res.data.list;
  289. this.getHouse2();
  290. this.checklist.forEach((item) => {
  291. this.rateMap.set(item.id, item.fraction); // map维护分数
  292. this.sortMap.set(item.id, item.sort); // 排序维护
  293. if (item.pid !== 0) {
  294. this.defaultCheck.push(item.id);
  295. }
  296. });
  297. console.log(this.newlist,"99999999999999999999999999")
  298. this.listCheckedchaifen();
  299. })
  300. }
  301. },
  302. // 获取楼盘下拉的数据
  303. getHouse2() {
  304. this.$api.api.findHouseByUser({
  305. orgType: localStorage.getItem("orgType"),
  306. }).then((res) => {
  307. this.houseList = res.data.map((item) => {
  308. return {
  309. value: item.id,
  310. label: item.propertyName,
  311. };
  312. });
  313. this.templategetMarketingTree()
  314. })
  315. },
  316. inputYiji(e, index) {
  317. if (e < 0) {
  318. this.$message({
  319. message: "评分小于0,请重新评分",
  320. type: "warning",
  321. });
  322. this.newlist[index].fraction = Number(0);
  323. }
  324. },
  325. inputBlur(e, index, idx) {
  326. if (e < 0) {
  327. this.$message({
  328. message: "评分小于0,请重新评分",
  329. type: "warning",
  330. });
  331. this.newlist[index].children[idx].fraction = 0;
  332. var he = 0;
  333. this.newlist[index].children.forEach((item) => {
  334. he += item.fraction;
  335. });
  336. this.newlist[index].fraction = he;
  337. } else {
  338. var he = 0;
  339. this.newlist[index].children.forEach((item) => {
  340. he += Number(item.fraction);
  341. });
  342. this.newlist[index].fraction = he;
  343. var zohe = 0;
  344. this.newlist.forEach((item) => {
  345. zohe += item.fraction;
  346. });
  347. if (zohe > 100) {
  348. this.$message({
  349. message: "评分大于100,请重新评分",
  350. type: "warning",
  351. });
  352. this.newlist[index].children[idx].fraction = 0;
  353. var fenhe = 0;
  354. this.newlist[index].children.forEach((item) => {
  355. fenhe += item.fraction;
  356. });
  357. this.newlist[index].fraction = fenhe;
  358. }
  359. }
  360. },
  361. submicll() {
  362. this.isshowage = false;
  363. },
  364. // 拖拽变化事件
  365. onDragCallback(evt) {
  366. this.newlist.forEach((item, index) => {
  367. item.sort = index + 1;
  368. });
  369. },
  370. //删除评分大类
  371. Deletecategories(item, index) {
  372. if (this.newlist[index].children.length == 0) {
  373. this.newlist.splice(index, 1);
  374. this.nodelist.forEach((it, i) => {
  375. if (it.id == item.id) {
  376. this.nodelist.splice(i, 1);
  377. }
  378. });
  379. item.children.forEach((it, ia) => {
  380. this.nodelist.forEach((ite, i) => {
  381. if (ite.id == it.id) {
  382. this.nodelist.splice(i, 1);
  383. }
  384. });
  385. });
  386. item.children.forEach((it, ia) => {
  387. it.children.forEach((asz, ina) => {
  388. this.nodelist.forEach((ite, i) => {
  389. if (ite.id == asz.id) {
  390. this.nodelist.splice(i, 1);
  391. }
  392. });
  393. });
  394. });
  395. } else {
  396. this.$message({
  397. message: "请先清空子级",
  398. type: "warning",
  399. });
  400. }
  401. },
  402. //删除评分二级
  403. Removethesecondary(index, idx, asd) {
  404. if (this.newlist[index].children[idx].children.length == 0) {
  405. this.newlist[index].children.splice(idx, 1);
  406. asd.children.forEach((it, ia) => {
  407. this.nodelist.forEach((item, i) => {
  408. if (item.id == it.id) {
  409. this.nodelist.splice(i, 1);
  410. }
  411. });
  412. });
  413. this.nodelist.forEach((item, i) => {
  414. if (item.id == asd.id) {
  415. this.nodelist.splice(i, 1);
  416. }
  417. });
  418. } else {
  419. this.$message({
  420. message: "请先清空子级",
  421. type: "warning",
  422. });
  423. }
  424. },
  425. //删除评分三级
  426. Deletethelevel(index, idx, indx, sanji) {
  427. this.newlist[index].children[idx].children.splice(indx, 1);
  428. this.nodelist.forEach((item, i) => {
  429. if (item.id == sanji.id) {
  430. this.nodelist.splice(i, 1);
  431. }
  432. });
  433. },
  434. //删除评分同时删除this.nodelist里的单数据
  435. //拆分数据
  436. listCheckedchaifen() {
  437. let arr = [];
  438. let level2 = [];
  439. this.nodelist.forEach((item, index) => {
  440. if (item.pid == 0) {
  441. item.children = [];
  442. arr.push(item);
  443. } else {
  444. level2.push(item);
  445. }
  446. });
  447. let resultArr = []; //去重后的数组
  448. var flag;
  449. for (var i in arr) {
  450. flag = true;
  451. for (var j in resultArr) {
  452. if (resultArr[j].id == arr[i].id) {
  453. flag = false;
  454. break;
  455. }
  456. }
  457. if (flag) {
  458. resultArr.push(arr[i]);
  459. }
  460. }
  461. let resultArrlist = []; //去重后的数组
  462. var flags;
  463. for (var i in level2) {
  464. flags = true;
  465. for (var j in resultArrlist) {
  466. if (resultArrlist[j].id == level2[i].id) {
  467. flags = false;
  468. break;
  469. }
  470. }
  471. if (flags) {
  472. resultArrlist.push(level2[i]);
  473. }
  474. }
  475. let level3 = [];
  476. resultArrlist.forEach((res, index) => {
  477. resultArr.forEach((asd) => {
  478. if (res.pid == asd.id) {
  479. res.children = [];
  480. asd.children.push(res);
  481. }
  482. });
  483. });
  484. resultArrlist.forEach((xzd) => {
  485. resultArr.forEach((asd) => {
  486. asd.children.forEach((qwe) => {
  487. if (xzd.pid == qwe.id) {
  488. qwe.children.push(xzd);
  489. }
  490. });
  491. });
  492. });
  493. this.newlist = resultArr;
  494. },
  495. //递归处理选择的数据
  496. familyTree(arr1, id) {
  497. var temp = [];
  498. var forFn = function (arr, id) {
  499. for (var i = 0; i < arr.length; i++) {
  500. var item = arr[i];
  501. if (item.id === id) {
  502. temp.push(item);
  503. forFn(arr1, item.parentId);
  504. break;
  505. } else {
  506. if (item.children) {
  507. forFn(item.children, id);
  508. }
  509. }
  510. }
  511. };
  512. forFn(arr1, id);
  513. return temp;
  514. },
  515. //提交评分
  516. cancel() {
  517. window.history.back();
  518. },
  519. submitForm() {
  520. let list = this.newlist;
  521. if (list.length == 0) {
  522. this.$message({
  523. message: "评分不能为空,请选择!",
  524. type: "warning",
  525. });
  526. return;
  527. }
  528. //一级
  529. for (var i = 0; i < list.length; i++) {
  530. if (list[i].fraction == "") {
  531. this.$message({
  532. message: "(" + list[i].name + ")评分不能是空值,请重新评分",
  533. type: "warning",
  534. });
  535. return;
  536. } else if (list[i].fraction == null) {
  537. this.$message({
  538. message: "(" + list[i].name + ")评分不能是空值,请重新评分",
  539. type: "warning",
  540. });
  541. return;
  542. } else if (list[i].fraction < 0) {
  543. this.$message({
  544. message: "评分不能是负数,请重新评分",
  545. type: "warning",
  546. });
  547. return;
  548. }
  549. }
  550. //二级
  551. for (var i = 0; i < list.length; i++) {
  552. for (var j = 0; j < list[i].children.length; j++) {
  553. if (list[i].children[j].fraction == "") {
  554. this.$message({
  555. message:
  556. "(" + list[i].children[j].name + ")评分不能是空值,请重新评分",
  557. type: "warning",
  558. });
  559. return;
  560. } else if (list[i].children[j].fraction == null) {
  561. this.$message({
  562. message:
  563. "(" + list[i].children[j].name + ")评分不能是空值,请重新评分",
  564. type: "warning",
  565. });
  566. return;
  567. } else if (list[i].children[j].fraction < 0) {
  568. this.$message({
  569. message: "评分不能是负数,请重新评分",
  570. type: "warning",
  571. });
  572. return;
  573. }
  574. }
  575. }
  576. //三级
  577. // for(var i=0;i<list.length;i++){
  578. // for(var j=0;j<list[i].children.length;j++){
  579. // for(var g=0; g<list[i].children[j].children.length;g++){
  580. // if(list[i].children[j].children[g].fraction == ""){
  581. // this.$message({
  582. // message: '(' + list[i].children[j].children[g].name + ')评分不能是空值,请重新评分',
  583. // type: 'warning'
  584. // });
  585. // return
  586. //
  587. // }else if(list[i].children[j].children[g].fraction == null){
  588. // this.$message({
  589. // message: '(' + list[i].children[j].children[g].name + ')评分不能是空值,请重新评分',
  590. // type: 'warning'
  591. // });
  592. // return
  593. // }else if(list[i].children[j].children[g].fraction<0){
  594. // this.$message({
  595. // message: '评分不能是负数,请重新评分',
  596. // type: 'warning'
  597. // });
  598. // return
  599. // }
  600. // }
  601. // }
  602. // }
  603. this.suanzongfen(list);
  604. },
  605. suanzongfen(list) {
  606. //二级下三级总分
  607. // for(var i=0;i<list.length;i++){
  608. // for(var j=0;j<list[i].children.length;j++){
  609. // let sanjinum=0;
  610. // if(list[i].children[j].children.length==0){
  611. // sanjinum=list[i].children[j].fraction;
  612. // }else{
  613. // for(var g=0; g<list[i].children[j].children.length;g++){
  614. // sanjinum += list[i].children[j].children[g].fraction;
  615. // }
  616. // }
  617. // if (list[i].children[j].fraction != sanjinum) {
  618. // this.$message({
  619. // message: '(' +list[i].children[j].name + ')的二级小类评分错误,请重新评分',
  620. // type: 'warning'
  621. // });
  622. // return ;
  623. // }
  624. // }
  625. // }
  626. //大类下二级总分
  627. for (var i = 0; i < list.length; i++) {
  628. let subRate = 0;
  629. for (var j = 0; j < list[i].children.length; j++) {
  630. subRate += list[i].children[j].fraction;
  631. }
  632. if (list[i].fraction != subRate) {
  633. this.$message({
  634. message: "(" + list[i].name + ")的大类评分错误,请重新评分",
  635. type: "warning",
  636. });
  637. return;
  638. }
  639. }
  640. // 总分
  641. let level1Rate = 0;
  642. for (let i = 0; i < list.length; i++) {
  643. level1Rate += list[i].fraction; // 大类总分
  644. }
  645. if (level1Rate < 100) {
  646. this.$message({
  647. message: "您当前的大类总分小于100,请重新评分",
  648. type: "warning",
  649. });
  650. return;
  651. } else if (level1Rate > 100) {
  652. this.$message({
  653. message: "您当前的大类总分大于100,请重新评分",
  654. type: "warning",
  655. });
  656. return;
  657. }
  658. let params = {
  659. houseId: this.houseId,
  660. children: [],
  661. };
  662. list.forEach((item) => {
  663. params.children.push({
  664. id: item.id,
  665. pid: 0,
  666. sort: item.sort,
  667. fraction: item.fraction,
  668. name: item.name,
  669. level: 0,
  670. });
  671. item.children.forEach((child) => {
  672. params.children.push({
  673. pid: item.id,
  674. id: child.id,
  675. fraction: child.fraction,
  676. name: child.name,
  677. level: 1,
  678. });
  679. child.children.forEach((childse) => {
  680. params.children.push({
  681. pid: child.id,
  682. id: childse.id,
  683. name: childse.name,
  684. level: 2,
  685. });
  686. });
  687. });
  688. });
  689. if (this.houseId == "") {
  690. this.$message({
  691. message: "请选择楼盘",
  692. type: "warning",
  693. });
  694. return;
  695. }
  696. this.saveRate(params);
  697. },
  698. // 评分保存 新增模板
  699. saveRate(params) {
  700. if (this.Templateid!='') {
  701. params.tempId = this.Templateid;
  702. }
  703. this.$api.http.templategeaddTemplate(params).then((res) => {
  704. this.$message({
  705. message: "保存成功",
  706. type: "success",
  707. });
  708. window.history.back();
  709. })
  710. },
  711. //拖拽排序
  712. Peerdrag(before) {
  713. let arr = [];
  714. this.treeList.forEach((item, index) => {
  715. if (before.data.pid == item.pid) {
  716. arr.push(item);
  717. } else {
  718. if (item.children.length == 0) {
  719. return;
  720. } else {
  721. item.children.forEach((ite, inde) => {
  722. if (before.data.pid == ite.pid) {
  723. arr.push(ite);
  724. } else {
  725. if (ite.children.length == 0) {
  726. return;
  727. } else {
  728. ite.children.forEach((it, ins) => {
  729. if (before.data.pid == it.pid) {
  730. arr.push(it);
  731. }
  732. });
  733. }
  734. }
  735. });
  736. }
  737. }
  738. });
  739. arr.forEach((item, index) => {
  740. item.sort = index;
  741. });
  742. let params = {
  743. list: [],
  744. };
  745. params.list = arr.map((item) => {
  746. return {
  747. id: item.id,
  748. sort: item.sort,
  749. };
  750. });
  751. this.dragSort(params.list);
  752. },
  753. //排序提交
  754. dragSort(list) {
  755. this.$api.http.templategeupdateSort({children:list}).then((res) => {
  756. })
  757. },
  758. //控制那个可拖拽节点
  759. allowDrag(draggingNode, dropNode, type) {
  760. if (draggingNode.data.sign == 0) {
  761. return false;
  762. } else {
  763. return true;
  764. }
  765. },
  766. //同级节点才可以拖拽
  767. allowDrop(draggingNode, dropNode, type) {
  768. if (draggingNode.level === dropNode.level) {
  769. if (draggingNode.parent.id === dropNode.parent.id) {
  770. // 向上拖拽 || 向下拖拽
  771. return type === "prev" || type === "next";
  772. }
  773. } else {
  774. // 不同级进行处理
  775. return false;
  776. }
  777. },
  778. // 添加二级小类节点入口
  779. append(node, data) {
  780. this.addForm.name = "";
  781. this.pid = data.id;
  782. this.dialogFormVisible = true;
  783. this.level = node.level;
  784. this.treeData = data;
  785. },
  786. // 添加三级小类节点入口
  787. append1(node, data) {
  788. this.addForm.name = "";
  789. this.pid = data.id;
  790. this.dialogFormVisible = true;
  791. this.level = node.level;
  792. this.treeData = data;
  793. },
  794. // 添加大类入口
  795. addBigNode() {
  796. this.level = 0;
  797. this.pid = 0;
  798. this.addForm.name = "";
  799. this.dialogFormVisible = true;
  800. },
  801. // 点击添加节点确认按钮
  802. addSubmit() {
  803. if (this.addForm.name != "") {
  804. this.dialogFormVisible = false;
  805. this.addNode();
  806. } else {
  807. this.$message({
  808. message: "内容不能为空",
  809. type: "warning",
  810. });
  811. return;
  812. }
  813. },
  814. // 新增的节点保存
  815. addNode() {
  816. this.$api.http.templategeadd({
  817. pid: this.pid,
  818. name: this.addForm.name,
  819. houseId: this.houseId,
  820. sign:1
  821. }).then((res) => {
  822. if (this.level == 0) {
  823. // 大类
  824. let newNode = {
  825. id: res.data,
  826. sign: 1,
  827. pid: 0,
  828. sort: this.treeList.length + 1,
  829. label: this.addForm.name,
  830. fraction: "",
  831. children: [],
  832. houseId: this.houseId,
  833. };
  834. this.treeList.push(newNode);
  835. this.allTreeListId.push(res.data.obj);
  836. } else if (this.level == 1) {
  837. // 二级
  838. let newChild = {
  839. id: res.data,
  840. pid: this.pid,
  841. sign: 1,
  842. fraction: "",
  843. sort: null,
  844. label: this.addForm.name,
  845. children: [],
  846. houseId: this.houseId,
  847. };
  848. this.treeList.forEach((item, index) => {
  849. if (item.id == this.pid) {
  850. item.children.push(newChild);
  851. }
  852. });
  853. this.allTreeListId.push(res.data.obj);
  854. } else {
  855. let newChilds = {
  856. id: res.data,
  857. sign: 1,
  858. fraction: "",
  859. pid: this.pid,
  860. sort: null,
  861. label: this.addForm.name,
  862. houseId: this.houseId,
  863. };
  864. this.treeList.forEach((item, index) => {
  865. item.children.forEach((ite, inde) => {
  866. if (ite.id == this.pid) {
  867. ite.children.push(newChilds);
  868. }
  869. });
  870. });
  871. this.allTreeListId.push(res.data.obj);
  872. }
  873. })
  874. },
  875. //编辑提交
  876. submiadd() {
  877. var that = this;
  878. let parmest={
  879. name: that.frosasd.name,
  880. id: that.frosasd.id,
  881. }
  882. this.$api.http.templategeupdate(parmest).then((res) => {
  883. that.treeList.forEach((item, index) => {
  884. if (item.id == that.frosasd.id) {
  885. that.treeList[index].label = that.frosasd.name;
  886. that.isshowage = false;
  887. that.$message({
  888. message: "修改成功",
  889. type: "success",
  890. });
  891. return;
  892. } else {
  893. item.children.forEach((asd, indexesd) => {
  894. if (asd.id == that.frosasd.id) {
  895. that.treeList[index].children[indexesd].label =
  896. that.frosasd.name;
  897. that.isshowage = false;
  898. that.$message({
  899. message: "修改成功",
  900. type: "success",
  901. });
  902. return;
  903. } else {
  904. asd.children.forEach((zxc, indexzxc) => {
  905. if (zxc.id == that.frosasd.id) {
  906. that.treeList[index].children[indexesd].children[
  907. indexzxc
  908. ].label = that.frosasd.name;
  909. that.isshowage = false;
  910. that.$message({
  911. message: "修改成功",
  912. type: "success",
  913. });
  914. return;
  915. }
  916. });
  917. }
  918. });
  919. }
  920. });
  921. })
  922. },
  923. //编辑
  924. ddeditor(node, data) {
  925. this.frosasd.name = data.label;
  926. this.frosasd.id = data.id;
  927. this.isshowage = true;
  928. },
  929. // 删除自定义的节点
  930. checkDelete() {
  931. let parmest={
  932. id: this.deleteId,
  933. }
  934. this.$api.http.templategedel(parmest).then((res) => {
  935. this.treeList.forEach((item, index) => {
  936. if (item.id == this.deleteId) {
  937. this.treeList.splice(index, 1);
  938. } else {
  939. item.children.forEach((ite, inde) => {
  940. if (ite.id == this.deleteId) {
  941. this.treeList[index].children.splice(inde, 1);
  942. } else {
  943. ite.children.forEach((it, ine) => {
  944. if (it.id == this.deleteId) {
  945. this.treeList[index].children[inde].children.splice(
  946. ine,
  947. 1
  948. );
  949. }
  950. });
  951. }
  952. });
  953. }
  954. });
  955. this.dialogVisible = false;
  956. })
  957. },
  958. remove(node, data) {
  959. if (node.level == 3) {
  960. this.deleteType = "node";
  961. this.deleteId = data.id;
  962. this.dialogVisible = true;
  963. } else {
  964. if (data.children.length == 0) {
  965. this.deleteType = "node";
  966. this.deleteId = data.id;
  967. this.dialogVisible = true;findByTempId
  968. } else {
  969. this.$message({
  970. message: "请先清空子级",
  971. type: "warning",
  972. });
  973. }
  974. }
  975. },
  976. },
  977. };
  978. </script>
  979. <style scoped="scoped" lang="scss" >
  980. .box-center {
  981. width: 100%;
  982. padding: 15px;
  983. padding-top: 0px;
  984. min-width: 1000px;
  985. padding-bottom: 100px;
  986. }
  987. #app {
  988. width: 100%;
  989. height: 100%;
  990. padding: 15px 15px;
  991. list-style: none;
  992. display: flex;
  993. background: #ffffff;
  994. min-width: 1000px;
  995. min-height: 80vh;
  996. border-radius: 4px;
  997. }
  998. .content-left {
  999. width: 360px;
  1000. padding-right: 30px;
  1001. border-right: 1px solid #ccc;
  1002. }
  1003. .content-left .select {
  1004. margin: 20px 0;
  1005. }
  1006. .custom-tree-node {
  1007. flex: 1;
  1008. display: flex;
  1009. align-items: center;
  1010. justify-content: space-between;
  1011. font-size: 14px;
  1012. padding-right: 8px;
  1013. }
  1014. .update-btn {
  1015. margin-top: 30px;
  1016. text-align: center;
  1017. }
  1018. .content-right {
  1019. padding: 20px 30px;
  1020. flex: 1;
  1021. }
  1022. .form-box {
  1023. width: 100%;
  1024. border: 2px dashed #ddd;
  1025. margin-bottom: 20px;
  1026. padding: 10px;
  1027. border-radius: 8px;
  1028. }
  1029. .list-group-item {
  1030. cursor: move;
  1031. list-style: none;
  1032. border: 0;
  1033. }
  1034. </style>