$(function () { $("#the_new_suit_img").html(''); $(".new_suit").show(400); var token=$.cookie('sku_access_token'); var role_id=$.cookie('sku_role_id'); if(token==undefined){ window.location.href = "login.html"; } var url=http+"cku_suit/query_all"; var data_string = JSON.stringify({token:token}); if(role_id=="admin"){ }else{ $(".new_suit_a").hide(); } // 首次获取 $.ajax({ url: url, type: "post", dataType:"JSON", data: data_string, success: function (data) { console.log(data); if(data.code==0){ for(let k=0;k'; suit_html=suit_html + '
'; suit_html=suit_html + '
'+data.res[k].suitName+'
'; suit_html=suit_html + '
'; suit_html=suit_html + '
'; if(role_id=="admin"){ suit_html=suit_html + '
' + '
' + '
' + '' + '
' + '
新增规则
' + '
' + '
' + ''; }else{ suit_html=suit_html + '
' + '
' + '
' + '
' + '
' + '
' + '
' + ''; } suit_html=suit_html + '
'; for(var i=0;i'; }else{ suit_html=suit_html + '
'; } var no_num=9; suit_html=suit_html+ '
'+data.res[k].sr_qs[i].ruleName+'
'; let math_num = Math.ceil(data.res[k].sr_qs[i].cr_qs.length/9==1?2:data.res[k].sr_qs[i].cr_qs.length/9)*10-Math.ceil(data.res[k].sr_qs[i].cr_qs.length/9==1?2:data.res[k].sr_qs[i].cr_qs.length/9)-1; for(let j=0;j
'; no_num=no_num+9; } if(j'+data.res[k].sr_qs[i].cr_qs[j].numName+':'+data.res[k].sr_qs[i].cr_qs[j].conditionName+'
'; }else{ suit_html=suit_html+ '
'; } } if(role_id=="admin"){ suit_html=suit_html + '
' + '
' + '
' + '
' + '
保存
' + '
添加
' + '
' + '
' }else{ suit_html=suit_html + '
' + '
' } suit_html=suit_html+''; } suit_html=suit_html+ ''; $("#suit_html").append(suit_html); } for(let k=0;k1){ $('.suit_title').eq(k).parent().parent().children().eq(1).hide(); $('.suit_title').eq(k).parent().children().eq(1).children().hide(); $('.suit_title').eq(k).children().eq(1).children().attr('src','img/pack_up.png'); } } }else{ } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); var suit_exit_value; // 添加套装 $(document).on('click','.new_suit_b', function() { console.log('添加套装'); $('#suit_add_id').fadeIn(100); $('#suit_add').slideDown(200); suit_exit_value=$(this); }); // 保存套装 $(document).on('click','#suit_exit_value', function() { let suit_name = $("#suit_name").val().trim(); if(suit_name==""){ alert("套装名称不可以为空!"); return; } let url=http+"cku_suit/add"; let data_string = JSON.stringify({token:token,name:suit_name}); $.ajax({ url: url, type: "post", dataType:"JSON", data: data_string, async: true,//同步 success: function (data) { console.log(data); if(data.code==0){ let id = data.res[0].id; var suit_html='
'; suit_html=suit_html + '
'; suit_html=suit_html + '
'; suit_html=suit_html + '
'+suit_name+'
'; suit_html=suit_html + '
'; suit_html=suit_html + '
'; suit_html=suit_html+ '
' + '
' + '
' + '' + '
' + '
新增规则
' + '
' + '
' + '
'; suit_html=suit_html + '
'; suit_html=suit_html + '
'; suit_html=suit_html+'
'; console.log(suit_exit_value.parent()); suit_exit_value.parent().parent().parent().children().eq(0).append(suit_html); }else{ alert("该用户没有权限!") return; } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); $('#suit_add_id').fadeOut(100); $('#suit_add').slideUp(200); }); var add_rule; var add_i=0; var suit_rid; // 添加规则和添加条件 $(document).on('click','.add_rule_a', function() { if(role_id=="admin"){ suit_rid = $(this).attr("rid"); add_i=0; add_rule = $(this).parent().parent().parent().children().eq(1); $(".add_role_div").parent().children().eq(0).html(''); var html_ = '
' +'
' +' :' +'
' +'
' +' ' +'
' +'
' $(".add_role_div").parent().children().eq(0).append(html_); add_i=add_i+1; $('#rule_add_id').fadeIn(100); $('#rule_add').slideDown(200); } }); // 编辑 $(document).on('click','.compile', function() { // console.log('编辑'); let a = $(this).parent().parent().parent().children().length; $(this).parent().parent().children().eq(0).hide(); $(this).parent().parent().children().eq(1).hide(); $(this).parent().parent().children().eq(2).show(); console.log(a); for(let i=0;i '; $(this).parent().parent().parent().children().eq(i).html(html_); html_vla=false; break; } } } } if(html_vla){ var suit_html=''; for(let i=0;i<10;i++){ suit_html=suit_html+ '
'; } var lastChild = $(this).parent().parent().parent().children().last().html(); var length = $(this).parent().parent().parent().children().length; $(this).parent().parent().parent().append(suit_html); length = length+10; console.log(length); $(this).parent().parent().parent().children().last().html(lastChild); var html_=' '; $(this).parent().parent().parent().children().eq(length-11).html(html_); html_vla=false; } }); // 保存 $(document).on('click','.rule_save', function() { // console.log('编辑'); //获取保存的长度 let a = $(this).parent().parent().parent().children().length; // 显示和隐藏 $(this).parent().parent().children().eq(0).show(); $(this).parent().parent().children().eq(1).show(); $(this).parent().parent().children().eq(2).hide(); // console.log(a); for(let i=0;i' +' :' +' ' +'
' +' ' +'
' +' ' $(this).parent().children().eq(0).append(html_); add_i=add_i+1; }); // 保存添加的规则和条件 $(document).on('click','#role_add_value', function() { // console.log(suit_rid); let role_edit_name = $("#role_edit_name").val().trim(); let condition_number=[]; let condition_that=[]; let condition_id=[]; if(role_edit_name==""){ add_i=0; add_i=add_i+1; alert("规则名称不可以为空!") return; }else{ $('#rule_add_id').fadeOut(100); $('#rule_add').slideUp(200); } let url=http+"cku_rule/add"; let rule_id=""; let data_string = JSON.stringify({token:token,name:role_edit_name,id:suit_rid}); $.ajax({ url: url, type: "post", dataType:"JSON", data: data_string, async: false,//同步 success: function (data) { console.log(data); if(data.code==0){ // console.log(data); rule_id = data.res[0].id; for(let i=0;i'; }else{ suit_html=suit_html + '
'; } suit_html=suit_html+ '
'+role_edit_name+'
'; if (condition_that.length>8){ num=17 } if (condition_that.length>18){ num=26 } for(let j=0;j
'; try{ if(condition_number[j]!=undefined){ suit_html=suit_html+ '
'+condition_number[j]+':'+condition_that[j]+'
'; }else{ suit_html=suit_html+ '
'; } }catch(e){ //TODO handle the exception suit_html=suit_html+ '
'; } }else{ if(j'+condition_number[j]+':'+condition_that[j]+' '; }else{ suit_html=suit_html+ '
'; } } } suit_html=suit_html+ '
' + '
' + '
' + '
' + '
保存
' + '
添加
' + '
' + '
' + ''; } add_rule.append(suit_html); add_i=0; //重置为0 }else{ alert("该用户没有权限!"); return; } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); }); // 套装的显示隐藏 $(document).on('click','.suit_title', function() { // console.log($(this).parent().parent().children().eq(1).is(':hidden')) if($(this).parent().children().eq(1).children().is(':hidden')){ $(this).parent().parent().children().eq(1).show(); $(this).parent().children().eq(1).children().show(); // 切换图标 $(this).children().eq(1).children().attr('src','img/spread.png'); }else{ $(this).parent().parent().children().eq(1).hide(); $(this).parent().children().eq(1).children().hide(); // 切换图标 $(this).children().eq(1).children().attr('src','img/pack_up.png'); } }); // 删除 $(document).on('click','.remove', function() { let html__=$(this).parent().parent().parent().children().eq(0).html(); let r = confirm("你确定删除"+html__+"吗?"); if (r == true) { let id=$(this).parent().parent().parent().children().eq(0).attr("rid"); let url=http+"cku_rule/delete"; let data_string = JSON.stringify({token:token,id:id}); $.ajax({ url: url, type: "post", dataType:"JSON", data: data_string, async: true,//同步 success: function (data) { if(data.code==0){ console.log("删除成功!"); }else{ return; } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); if($(this).parent().parent().parent().prev().length==1){//前面有节点就不处理 }else{// 如果是第一个那么就添加下一个节点的上边框颜色 $(this).parent().parent().parent().next().css("border-top","1px solid #e4e7e9"); } $(this).parent().parent().parent().remove();// 直接删除该div } else { return; } }); //取消 $('.closes').click(function(){ $('#suit_add_id').fadeOut(100); $('#suit_add').slideUp(200); $('#rule_add_id').fadeOut(100); $('#rule_add').slideUp(200); }); // 注销登录 $("#logout").on('click',function(){ //清空cookie $.cookie("sku_access_token", "", {expires: -1}); $.cookie("sku_refresh_token", "", {expires: -1}); $.cookie("sku_role_id", "", {expires: -1}); //回到首页 window.location.href = "login.html"; }); // var dele = http+'cku_suit/delete?token='+$.cookie('sku_access_token')+'&id='; // console.log(dele); });