暫無描述

repositoryClass.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. $(function(){
  2. var token = $.cookie("token");
  3. var pid; //当前父节点ID
  4. var addId;
  5. TreeList();
  6. function TreeList(){
  7. $.ajax({
  8. type:"get",
  9. url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/gettypetreelist',
  10. async:true,
  11. dataType: 'json',
  12. data:{
  13. "token": $.cookie("token"),
  14. "pid": pid
  15. },
  16. success: function(data) {
  17. if(data.state == "success") {
  18. if (data.data.length>0) {
  19. var a=0,b=0,c=0,d=0,e=0,f=0;
  20. //一级
  21. function firstTree(){
  22. if (data.data) {
  23. var res =data.data;
  24. for(var i in res) {
  25. if (res[i].parentid="null") {
  26. res[i].parentid=""
  27. }
  28. var sort =i;
  29. var children_s1 = res[i].children;
  30. if(children_s1){
  31. $('<dt><div class="after">'
  32. +'<span class="treeDt" attr-index="'+res[i].parentid
  33. +'" rank="'+sort+'" idIndex="1" thisId="'+res[i].id+'">'+res[i].name
  34. +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
  35. +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
  36. +'<div class="underway edit-icon">'
  37. +'<input class="saveInput" value="222"/>'
  38. +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
  39. +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
  40. +'</div></dt>').appendTo('.treeMenu1');
  41. }
  42. }
  43. }
  44. }
  45. //二级
  46. function secondTree(){
  47. if(data.data){
  48. if(data.data[a].children!=undefined){
  49. var resCildren =data.data[a].children;
  50. for(var i in resCildren) {
  51. var sort =i;
  52. var children_s2 = resCildren[i];
  53. if(children_s2){
  54. if(children_s2.length != 0) {
  55. $('<dt><div class="after">'
  56. +'<span class="treeDt" attr-index="'+resCildren[i].parentid
  57. +'" rank="'+sort+'" idIndex="2" thisId="'+resCildren[i].id+'">'+resCildren[i].name
  58. +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
  59. +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
  60. +'<div class="underway edit-icon">'
  61. +'<input class="saveInput" value="222"/>'
  62. +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
  63. +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
  64. +'</div></dt>').appendTo('.treeMenu2');
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. //三级
  72. function thirdTree(){
  73. if(data.data){
  74. if(data.data[a].children!=undefined){
  75. if (data.data[a].children[b]!=undefined) {
  76. var resCildren3 =data.data[a].children[b].children;
  77. for(var i in resCildren3) {
  78. var sort =i;
  79. var children_s3 = resCildren3[i];
  80. if(children_s3){
  81. if(children_s3.length != 0) {
  82. $('<dt><div class="after">'
  83. +'<span class="treeDt" attr-index="'+resCildren3[i].parentid
  84. +'" rank="'+sort+'" idIndex="3" thisId="'+resCildren3[i].id+'">'+resCildren3[i].name
  85. +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
  86. +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
  87. +'<div class="underway edit-icon">'
  88. +'<input class="saveInput" value="222"/>'
  89. +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
  90. +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
  91. +'</div></dt>').appendTo('.treeMenu3');
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. //四级
  100. function fourTree(){
  101. if(data.data){
  102. if(data.data[a].children!=undefined){
  103. if (data.data[a].children[b]!=undefined) {
  104. if (data.data[a].children[b].children[c]!=undefined) {
  105. var resCildren4 =data.data[a].children[b].children[c].children;
  106. for(var i in resCildren4) {
  107. var sort =i;
  108. var children_s4 = resCildren4[i];
  109. if(children_s4){
  110. if(children_s4.length != 0) {
  111. $('<dt><div class="after">'
  112. +'<span class="treeDt" attr-index="'+resCildren4[i].parentid
  113. +'" rank="'+sort+'" idIndex="4" thisId="'+resCildren4[i].id+'">'+resCildren4[i].name
  114. +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
  115. +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
  116. +'<div class="underway edit-icon">'
  117. +'<input class="saveInput" value="222"/>'
  118. +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
  119. +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
  120. +'</div></dt>').appendTo('.treeMenu4');
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. //五级
  130. function fiveTree(){
  131. if(data.data){
  132. if(data.data[a].children!=undefined){
  133. if (data.data[a].children[b]!=undefined) {
  134. if (data.data[a].children[b].children[c]!=undefined) {
  135. if (data.data[a].children[b].children[c].children[d]!=undefined) {
  136. var resCildren5 =data.data[a].children[b].children[c].children[d].children;
  137. for(var i in resCildren5) {
  138. var sort =i;
  139. var children_s5 = resCildren5[i];
  140. if(children_s5){
  141. if(children_s5.length != 0) {
  142. $('<dt><div class="after">'
  143. +'<span class="treeDt" attr-index="'+resCildren5[i].parentid
  144. +'" rank="'+sort+'" idIndex="5" thisId="'+resCildren5[i].id+'">'+resCildren5[i].name
  145. +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
  146. +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
  147. +'<div class="underway edit-icon">'
  148. +'<input class="saveInput" value="222"/>'
  149. +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
  150. +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
  151. +'</div></dt>').appendTo('.treeMenu5');
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. //六级
  162. function sixTree(){
  163. if(data.data){
  164. if(data.data[a].children!=undefined){
  165. if (data.data[a].children[b]!=undefined) {
  166. if (data.data[a].children[b].children[c]!=undefined) {
  167. if (data.data[a].children[b].children[c].children[d]!=undefined) {
  168. if (data.data[a].children[b].children[c].children[d].children[e]!=undefined) {
  169. var resCildren6 =data.data[a].children[b].children[c].children[d].children[e].children;
  170. for(var i in resCildren6) {
  171. var sort =i;
  172. var children_s6 = resCildren6[i];
  173. if(children_s6){
  174. if(children_s6.length != 0) {
  175. $('<dt><div class="after">'
  176. +'<span class="treeDt" attr-index="'+resCildren6[i].parentid
  177. +'" rank="'+sort+'" idIndex="6" thisId="'+resCildren6[i].id+'">'+resCildren6[i].name
  178. +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
  179. +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
  180. +'<div class="underway edit-icon">'
  181. +'<input class="saveInput" value="222"/>'
  182. +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
  183. +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
  184. +'</div></dt>').appendTo('.treeMenu6');
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. function tree(){firstTree();secondTree();thirdTree();
  196. fourTree();fiveTree();sixTree();}
  197. tree();
  198. $(".reposiClass ul li dl").on("click",".treeDt",function(){
  199. $(this).parent("after").parent("dt").css("background","#eeeef1")
  200. var rank=$(this).attr('rank');
  201. var IdIndex=$(this).attr('idIndex');
  202. addId=$(this).attr('thisid');
  203. if (rank&&IdIndex==1){
  204. $(".treeMenu").html("");
  205. a=rank;
  206. tree();
  207. $(".treeMenu1 dt:eq("+rank+")").css("background","#eeeef1");
  208. }else if(rank&&IdIndex==2){
  209. $(".treeMenu").html("");
  210. b=rank;
  211. tree();
  212. $(".treeMenu2 dt:eq("+rank+")").css("background","#eeeef1");
  213. }else if(rank&&IdIndex==3){
  214. $(".treeMenu").html("");
  215. c=rank;
  216. tree();
  217. $(".treeMenu3 dt:eq("+rank+")").css("background","#eeeef1");
  218. }else if(rank&&IdIndex==4){
  219. $(".treeMenu").html("");
  220. d=rank;
  221. tree();
  222. $(".treeMenu4 dt:eq("+rank+")").css("background","#eeeef1");
  223. }else if(rank&&IdIndex==5){
  224. $(".treeMenu").html("");
  225. e=rank;
  226. tree();
  227. $(".treeMenu5 dt:eq("+rank+")").css("background","#eeeef1");
  228. }
  229. })
  230. }
  231. }
  232. }
  233. });
  234. }
  235. // hover效果 修改删除图标
  236. $(".reposiClass ul li dl").on({
  237. mouseenter:function(){
  238. $(this).children(".after").children(".icon_edit").css("display","block");
  239. $(this).children(".after").children(".icon_del").css("display","block");
  240. },
  241. mouseleave:function(){
  242. $(this).children(".after").children(".icon_edit").css("display","none");
  243. $(this).children(".after").children(".icon_del").css("display","none");
  244. }
  245. },"dt")
  246. // hover效果 添加分类之后的修改删除图标
  247. hover();
  248. function hover(){
  249. $(".underway-text").hover(
  250. function(){
  251. $(this).children(".underway-list").children(".icon_edit").css("display","block");
  252. $(this).children(".underway-list").children(".icon_del").css("display","block");
  253. },function () {
  254. $(this).children(".underway-list").children(".icon_edit").css("display","none");
  255. $(this).children(".underway-list").children(".icon_del").css("display","none");
  256. });
  257. $(".underway-text").hover(
  258. function(){
  259. $(this).children(".icon_edit").css("display","block");
  260. $(this).children(".icon_del").css("display","block");
  261. },function () {
  262. $(this).children(".icon_edit").css("display","none");
  263. $(this).children(".icon_del").css("display","none");
  264. });
  265. }
  266. // 修改出现input框
  267. $(".reposiClass ul li dl").on("click",".icon_edit",function(){
  268. $(this).parent(".after").hide();
  269. var text_edit=$(this).parent(".after").children(".treeDt").text();
  270. var text_id=$(this).parent(".after").children(".treeDt").attr("thisId");
  271. $(this).parent(".after").next(".underway").show();
  272. $(this).parent(".after").next(".underway").children(".saveInput").val(text_edit);
  273. })
  274. // 修改input框里的内的保存按钮
  275. $(".reposiClass ul li dl").on("click",".icon_save",function(){
  276. var text_edit1=$(this).siblings(".saveInput").val();
  277. var iD=$(this).parents(".underway").siblings(".after").children(".treeDt").attr("thisid");
  278. parentId=$(this).parents(".underway").siblings(".after").children(".treeDt").attr("attr-index");
  279. var sort=$(this).parents(".underway").siblings(".after").children(".treeDt").attr("rank");
  280. if (text_edit1=="") {
  281. layer.msg("不能为空");
  282. }else{
  283. $(this).parent(".underway").hide();
  284. $(this).parent(".underway").prev(".after").show();
  285. $(this).parent(".underway").prev(".after").children(".treeDt").text(text_edit1);
  286. editTree(parentId,iD,sort,text_edit1);
  287. }
  288. })
  289. $(".reposiClass ul li dl").on("click",".icon_del",function(){
  290. $(this).parent(".after").parent("dt").remove();
  291. var iD=$(this).siblings(".treeDt").attr("thisId");
  292. deleteTree(iD);
  293. });
  294. $(".reposiClass ul li dl").on("click",".icon_cancel",function(){
  295. $(this).parent(".underway").hide();
  296. $(this).parent(".underway").prev(".after").show();
  297. })
  298. // 保存
  299. $(".reposiClass ul li .icon_save").on("click",function(){
  300. var saveInput=$(this).siblings(".saveInput").val();
  301. var addIdIndex=$(this).parent(".underway").siblings("dl").find(".treeDt");
  302. if (typeof(addId)!="undefined"&&addIdIndex.text()=="") {
  303. addTree(saveInput,addId)
  304. } else if(addIdIndex.text()==""){
  305. layer.msg("请选择上级分类");
  306. }else{
  307. addId=addIdIndex.attr("attr-index");
  308. addTree(saveInput,addId)
  309. }
  310. $(this).parents(".underway").hide();
  311. });
  312. $(".add-class").click(function () {
  313. $(this).siblings(".underway").show();
  314. })
  315. // 添加
  316. function addTree(saveInput,addId){
  317. $.ajax({
  318. type:"post",
  319. url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/addtype',
  320. async:true,
  321. dataType: 'json',
  322. data:{
  323. token: $.cookie("token"),
  324. name: saveInput,
  325. parentid: addId
  326. },
  327. success:function (data) {
  328. if(data.state == "success") {
  329. debugger
  330. // $(".treeMenu1 dt").remove();
  331. // TreeList();
  332. var index = parent.layer.getFrameIndex(window.name);
  333. parent.layer.close(index);
  334. parent.initTable();
  335. parent.layer.msg("保存成功");
  336. }
  337. }
  338. });
  339. }
  340. // 修改
  341. function editTree(parentId,iD,sort,text_edit1){
  342. $.ajax({
  343. type:"post",
  344. url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/updatetype',
  345. async:true,
  346. dataType: 'json',
  347. data:{
  348. token: $.cookie("token"),
  349. id:iD,
  350. name:text_edit1,
  351. sort:sort,
  352. parentid:parentId
  353. },
  354. success:function (data) {
  355. if(data.state == "success") {
  356. debugger
  357. var index = parent.layer.getFrameIndex(window.name);
  358. parent.layer.close(index);
  359. parent.initTable();
  360. parent.layer.msg("修改成功");
  361. }
  362. }
  363. });
  364. }
  365. function deleteTree(iD){
  366. $.ajax({
  367. type:"post",
  368. url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/deletetype',
  369. async:true,
  370. dataType: 'json',
  371. data:{
  372. token: $.cookie("token"),
  373. ids: iD
  374. },
  375. success:function (data) {
  376. if(data.state == "success") {
  377. debugger
  378. var index = parent.layer.getFrameIndex(window.name);
  379. parent.layer.close(index);
  380. parent.initTable();
  381. parent.layer.msg("删除成功");
  382. }
  383. }
  384. });
  385. }
  386. })