$(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, beforeSend:function() { $("#suit_under_load").html('套装加载中 '); }, 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)*10-Math.ceil(data.res[k].sr_qs[i].cr_qs.length/9)-1; if(data.res[k].sr_qs[i].cr_qs.length%9==0){ math_num = ((data.res[k].sr_qs[i].cr_qs.length/9)+1)*10-Math.ceil(data.res[k].sr_qs[i].cr_qs.length/9)-2; } 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); // $("#suit_under_load").hide("slow"); $("#suit_under_load").animate({opacity:0},1500,function(){ $(this).css({display:"none"}) }) } 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() { 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; $(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;inew Date()){ last_value=$(this).parent().parent().parent().children().eq(i).children().eq(0).html(); }else{ last_value=num_name[0]+":"+num_name[1]; } if($(this).parent().parent().parent().children().eq(i).children().eq(1).val()==""){ $(this).parent().parent().parent().children().eq(i).children().eq(0).html(''); }else{ $(this).parent().parent().parent().children().eq(i).children().eq(0).html(num_name[0]+":"+num_name[1]); } let that=$(this); if (id!="default"){ // id不为空的时候我就走修改的请求 if($(this).parent().parent().parent().children().eq(i).children().eq(1).val()==""){//值等于空就直接删除掉 let url=http+"sku_condition/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('删除成功!'); that.parent().parent().parent().children().eq(i).html(""); }else{ return; } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); }else{ if($(this).parent().parent().parent().children().eq(i).children().eq(1).val()==last_value){ // console.log("没有编辑"); }else{ let url=http+"sku_condition/update"; let data_string = JSON.stringify({token:token,numName:num_name[0],name:num_name[1],id:id}); $.ajax({ url: url, type: "post", dataType:"JSON", data: data_string, async: true,//异步 success: function (data) { if(data.code==0){ // console.log(data); }else{ return; } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); } } }else{ // 添加 if($(this).parent().parent().parent().children().eq(i).children().eq(1).val()==""){ $(this).parent().parent().parent().children().eq(i).html(''); } let url=http+"sku_condition/add"; var rule_id=$(this).parent().parent().parent().children().eq(0).attr("rid"); // console.log(rule_id); let data_string = JSON.stringify({token:token,numName:num_name[0],name:num_name[1],id:rule_id}); // console.log(data_string); $.ajax({ url: url, type: "post", dataType:"JSON", data: data_string, async: false,//异步 success: function (data) { if(data.code==0){ // console.log(i); // console.log(data.res[0].id); that.parent().parent().parent().children().eq(i).children().eq(1).attr("rid",data.res[0].id); }else{ console.log(data.msg); return; } }, error:function (XMLHttpRequest) { console.log("失败!"); } }); } } // 显示隐藏 $(this).parent().parent().parent().children().eq(i).children().eq(1).hide(); $(this).parent().parent().parent().children().eq(i).children().eq(0).show(); } } }); // 添加一行的条件 $(document).on('click','.add_role_div', function() { // 添加一行条件并显示到页面 var html_ = '
' +'
' +' :' +'
' +'
' +' ' +'
' +'
' $(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+'
'; let num = Math.ceil(condition_that.length/9)*10-(Math.ceil(condition_that.length/9)==1?2:Math.ceil(condition_that.length/9)); if(condition_that.length%9==0){ num =Math.ceil(condition_that.length/9+1)*10-(Math.ceil(condition_that.length/9)==1?2:Math.ceil(condition_that.length/9)) } let no_num=9; var i_length=0; for(let j=0;j
'; no_num=no_num+9; }else{ if(i_length'+condition_number[i_length]+':'+condition_that[i_length]+' '; i_length=i_length+1; }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); });