| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- $(function(){
- var token = $.cookie("token");
- var pid; //当前父节点ID
- var addId;
- TreeList();
- function TreeList(){
- $.ajax({
- type:"get",
- url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/gettypetreelist',
- async:true,
- dataType: 'json',
- data:{
- "token": $.cookie("token"),
- "pid": pid
- },
- success: function(data) {
- if(data.state == "success") {
- if (data.data.length>0) {
- var a=0,b=0,c=0,d=0,e=0,f=0;
- //一级
- function firstTree(){
- if (data.data) {
- var res =data.data;
- for(var i in res) {
- if (res[i].parentid="null") {
- res[i].parentid=""
- }
- var sort =i;
- var children_s1 = res[i].children;
- if(children_s1){
- $('<dt><div class="after">'
- +'<span class="treeDt" attr-index="'+res[i].parentid
- +'" rank="'+sort+'" idIndex="1" thisId="'+res[i].id+'">'+res[i].name
- +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
- +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
- +'<div class="underway edit-icon">'
- +'<input class="saveInput" value="222"/>'
- +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
- +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
- +'</div></dt>').appendTo('.treeMenu1');
- }
- }
- }
- }
- //二级
- function secondTree(){
- if(data.data){
- if(data.data[a].children!=undefined){
- var resCildren =data.data[a].children;
- for(var i in resCildren) {
- var sort =i;
- var children_s2 = resCildren[i];
- if(children_s2){
- if(children_s2.length != 0) {
- $('<dt><div class="after">'
- +'<span class="treeDt" attr-index="'+resCildren[i].parentid
- +'" rank="'+sort+'" idIndex="2" thisId="'+resCildren[i].id+'">'+resCildren[i].name
- +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
- +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
- +'<div class="underway edit-icon">'
- +'<input class="saveInput" value="222"/>'
- +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
- +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
- +'</div></dt>').appendTo('.treeMenu2');
- }
- }
- }
- }
- }
- }
- //三级
- function thirdTree(){
- if(data.data){
- if(data.data[a].children!=undefined){
- if (data.data[a].children[b]!=undefined) {
- var resCildren3 =data.data[a].children[b].children;
- for(var i in resCildren3) {
- var sort =i;
- var children_s3 = resCildren3[i];
- if(children_s3){
- if(children_s3.length != 0) {
- $('<dt><div class="after">'
- +'<span class="treeDt" attr-index="'+resCildren3[i].parentid
- +'" rank="'+sort+'" idIndex="3" thisId="'+resCildren3[i].id+'">'+resCildren3[i].name
- +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
- +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
- +'<div class="underway edit-icon">'
- +'<input class="saveInput" value="222"/>'
- +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
- +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
- +'</div></dt>').appendTo('.treeMenu3');
- }
- }
- }
- }
- }
- }
- }
- //四级
- function fourTree(){
- if(data.data){
- if(data.data[a].children!=undefined){
- if (data.data[a].children[b]!=undefined) {
- if (data.data[a].children[b].children[c]!=undefined) {
- var resCildren4 =data.data[a].children[b].children[c].children;
- for(var i in resCildren4) {
- var sort =i;
- var children_s4 = resCildren4[i];
- if(children_s4){
- if(children_s4.length != 0) {
- $('<dt><div class="after">'
- +'<span class="treeDt" attr-index="'+resCildren4[i].parentid
- +'" rank="'+sort+'" idIndex="4" thisId="'+resCildren4[i].id+'">'+resCildren4[i].name
- +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
- +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
- +'<div class="underway edit-icon">'
- +'<input class="saveInput" value="222"/>'
- +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
- +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
- +'</div></dt>').appendTo('.treeMenu4');
- }
- }
- }
- }
- }
- }
- }
- }
- //五级
- function fiveTree(){
- if(data.data){
- if(data.data[a].children!=undefined){
- if (data.data[a].children[b]!=undefined) {
- if (data.data[a].children[b].children[c]!=undefined) {
- if (data.data[a].children[b].children[c].children[d]!=undefined) {
- var resCildren5 =data.data[a].children[b].children[c].children[d].children;
- for(var i in resCildren5) {
- var sort =i;
- var children_s5 = resCildren5[i];
- if(children_s5){
- if(children_s5.length != 0) {
- $('<dt><div class="after">'
- +'<span class="treeDt" attr-index="'+resCildren5[i].parentid
- +'" rank="'+sort+'" idIndex="5" thisId="'+resCildren5[i].id+'">'+resCildren5[i].name
- +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
- +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
- +'<div class="underway edit-icon">'
- +'<input class="saveInput" value="222"/>'
- +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
- +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
- +'</div></dt>').appendTo('.treeMenu5');
- }
- }
- }
- }
- }
- }
- }
- }
- }
- //六级
- function sixTree(){
- if(data.data){
- if(data.data[a].children!=undefined){
- if (data.data[a].children[b]!=undefined) {
- if (data.data[a].children[b].children[c]!=undefined) {
- if (data.data[a].children[b].children[c].children[d]!=undefined) {
- if (data.data[a].children[b].children[c].children[d].children[e]!=undefined) {
- var resCildren6 =data.data[a].children[b].children[c].children[d].children[e].children;
- for(var i in resCildren6) {
- var sort =i;
- var children_s6 = resCildren6[i];
- if(children_s6){
- if(children_s6.length != 0) {
- $('<dt><div class="after">'
- +'<span class="treeDt" attr-index="'+resCildren6[i].parentid
- +'" rank="'+sort+'" idIndex="6" thisId="'+resCildren6[i].id+'">'+resCildren6[i].name
- +'</span><span class="glyphicon glyphicon-pencil icon_edit"></span>'
- +'<span class="glyphicon glyphicon-remove icon_del"></span></div>'
- +'<div class="underway edit-icon">'
- +'<input class="saveInput" value="222"/>'
- +'<span class="glyphicon glyphicon-remove-sign icon_cancel"></span>'
- +'<span class="glyphicon glyphicon-ok-sign icon_save"></span>'
- +'</div></dt>').appendTo('.treeMenu6');
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- function tree(){firstTree();secondTree();thirdTree();
- fourTree();fiveTree();sixTree();}
- tree();
-
- $(".reposiClass ul li dl").on("click",".treeDt",function(){
- $(this).parent("after").parent("dt").css("background","#eeeef1")
- var rank=$(this).attr('rank');
- var IdIndex=$(this).attr('idIndex');
- addId=$(this).attr('thisid');
- if (rank&&IdIndex==1){
- $(".treeMenu").html("");
- a=rank;
- tree();
- $(".treeMenu1 dt:eq("+rank+")").css("background","#eeeef1");
- }else if(rank&&IdIndex==2){
- $(".treeMenu").html("");
- b=rank;
- tree();
- $(".treeMenu2 dt:eq("+rank+")").css("background","#eeeef1");
- }else if(rank&&IdIndex==3){
- $(".treeMenu").html("");
- c=rank;
- tree();
- $(".treeMenu3 dt:eq("+rank+")").css("background","#eeeef1");
- }else if(rank&&IdIndex==4){
- $(".treeMenu").html("");
- d=rank;
- tree();
- $(".treeMenu4 dt:eq("+rank+")").css("background","#eeeef1");
- }else if(rank&&IdIndex==5){
- $(".treeMenu").html("");
- e=rank;
- tree();
- $(".treeMenu5 dt:eq("+rank+")").css("background","#eeeef1");
- }
- })
- }
- }
- }
- });
- }
-
- // hover效果 修改删除图标
- $(".reposiClass ul li dl").on({
- mouseenter:function(){
- $(this).children(".after").children(".icon_edit").css("display","block");
- $(this).children(".after").children(".icon_del").css("display","block");
- },
- mouseleave:function(){
- $(this).children(".after").children(".icon_edit").css("display","none");
- $(this).children(".after").children(".icon_del").css("display","none");
- }
- },"dt")
- // hover效果 添加分类之后的修改删除图标
- hover();
- function hover(){
- $(".underway-text").hover(
- function(){
- $(this).children(".underway-list").children(".icon_edit").css("display","block");
- $(this).children(".underway-list").children(".icon_del").css("display","block");
- },function () {
- $(this).children(".underway-list").children(".icon_edit").css("display","none");
- $(this).children(".underway-list").children(".icon_del").css("display","none");
- });
- $(".underway-text").hover(
- function(){
- $(this).children(".icon_edit").css("display","block");
- $(this).children(".icon_del").css("display","block");
- },function () {
- $(this).children(".icon_edit").css("display","none");
- $(this).children(".icon_del").css("display","none");
- });
- }
- // 修改出现input框
- $(".reposiClass ul li dl").on("click",".icon_edit",function(){
- $(this).parent(".after").hide();
- var text_edit=$(this).parent(".after").children(".treeDt").text();
- var text_id=$(this).parent(".after").children(".treeDt").attr("thisId");
- $(this).parent(".after").next(".underway").show();
- $(this).parent(".after").next(".underway").children(".saveInput").val(text_edit);
- })
- // 修改input框里的内的保存按钮
- $(".reposiClass ul li dl").on("click",".icon_save",function(){
- var text_edit1=$(this).siblings(".saveInput").val();
- var iD=$(this).parents(".underway").siblings(".after").children(".treeDt").attr("thisid");
- parentId=$(this).parents(".underway").siblings(".after").children(".treeDt").attr("attr-index");
- var sort=$(this).parents(".underway").siblings(".after").children(".treeDt").attr("rank");
- if (text_edit1=="") {
- layer.msg("不能为空");
- }else{
- $(this).parent(".underway").hide();
- $(this).parent(".underway").prev(".after").show();
- $(this).parent(".underway").prev(".after").children(".treeDt").text(text_edit1);
-
-
- editTree(parentId,iD,sort,text_edit1);
- }
- })
- $(".reposiClass ul li dl").on("click",".icon_del",function(){
- $(this).parent(".after").parent("dt").remove();
- var iD=$(this).siblings(".treeDt").attr("thisId");
- deleteTree(iD);
- });
- $(".reposiClass ul li dl").on("click",".icon_cancel",function(){
- $(this).parent(".underway").hide();
- $(this).parent(".underway").prev(".after").show();
- })
-
- // 保存
- $(".reposiClass ul li .icon_save").on("click",function(){
- var saveInput=$(this).siblings(".saveInput").val();
- var addIdIndex=$(this).parent(".underway").siblings("dl").find(".treeDt");
- if (typeof(addId)!="undefined"&&addIdIndex.text()=="") {
- addTree(saveInput,addId)
- } else if(addIdIndex.text()==""){
- layer.msg("请选择上级分类");
- }else{
- addId=addIdIndex.attr("attr-index");
- addTree(saveInput,addId)
- }
- $(this).parents(".underway").hide();
- });
- $(".add-class").click(function () {
- $(this).siblings(".underway").show();
- })
- // 添加
- function addTree(saveInput,addId){
- $.ajax({
- type:"post",
- url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/addtype',
- async:true,
- dataType: 'json',
- data:{
- token: $.cookie("token"),
- name: saveInput,
- parentid: addId
- },
- success:function (data) {
- if(data.state == "success") {
- debugger
- // $(".treeMenu1 dt").remove();
- // TreeList();
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.initTable();
- parent.layer.msg("保存成功");
- }
- }
- });
- }
-
-
- // 修改
- function editTree(parentId,iD,sort,text_edit1){
- $.ajax({
- type:"post",
- url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/updatetype',
- async:true,
- dataType: 'json',
- data:{
- token: $.cookie("token"),
- id:iD,
- name:text_edit1,
- sort:sort,
- parentid:parentId
- },
- success:function (data) {
- if(data.state == "success") {
- debugger
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.initTable();
- parent.layer.msg("修改成功");
- }
- }
- });
- }
- function deleteTree(iD){
- $.ajax({
- type:"post",
- url:huayi.config.callcenter_url + 'callcenterapi/api/Knowledge/deletetype',
- async:true,
- dataType: 'json',
- data:{
- token: $.cookie("token"),
- ids: iD
- },
- success:function (data) {
- if(data.state == "success") {
- debugger
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.initTable();
- parent.layer.msg("删除成功");
- }
- }
- });
- }
-
- })
|