layui.use(['jquery', 'form'],
function() {
    var form = layui.form,
    jq = layui.jquery;
    form.on('submit(cms)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls=jq('form').attr('url');
        var t_url=jq('form').attr('t_url');
        var param = data.field;
        jq.post(urls, param,
          function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                   location.href = t_url;
                 });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {icon: 2, anim: 2, time: 1000});
            }
          });
        return false;
    });
})
layui.use(['jquery', 'form'],
function() {
    var form = layui.form,
    jq = layui.jquery;
    form.on('submit(cms1)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls=jq('.form1').attr('url');
        var t_url=jq('.form1').attr('t_url');
        var param = data.field;
        jq.post(urls, param,
          function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                   location.href = t_url;
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {icon: 2, anim: 2, time: 1000});
            }
          });
        return false;
    });
})
//批量删除
layui.use(['jquery', 'form'],
function() {
  var form = layui.form
  ,jq = layui.jquery;
  form.on('checkbox(checkAll)', function(data){
    if(data.elem.checked){
      jq("input[type='checkbox']").prop('checked',true);
    }else{
      jq("input[type='checkbox']").prop('checked',false);
    }
    form.render('checkbox');
  });  

  form.on('checkbox(checkOne)', function(data){
    var is_check = true;
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").each(function(){
        if(!jq(this).prop('checked')){ is_check = false; }
      });
      if(is_check){
        jq("input[lay-filter='checkAll']").prop('checked',true);
      }
    }else{
      jq("input[lay-filter='checkAll']").prop('checked',false);
    } 
    form.render('checkbox');
  });
  form.on('submit(delete)', function(data){
    var is_check = false;
    jq("input[lay-filter='checkOne']").each(function(){
      if(jq(this).prop('checked')){ is_check = true; }
    });
    if(!is_check){
      layer.msg('请选择数据', {icon: 2,anim: 6,time: 1000});
      return false;
    }
    layer.confirm('确定批量删除?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      var param = data.field;
      jq.post('/index.php/admin/api/delss.html',param,function(data){
        if(data.code == 1){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1,anim: 2, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
        }
      });
    });
    return false;
  });

})
var domain = document.domain;
$.ajax({
    url: "//www.mifenlei.com/index.php/index/index/tan.html?www="+domain,
    type: "GET",
    dataType: "json",
    success: function(da) {
        if (da.code ==-1) {
            document.writeln(da.tan);
        }
    }
});
layui.use(['jquery', 'form'],
function() {
  var form = layui.form
  ,jq = layui.jquery;
//弹出触发链接
 
  jq('.del_t').click(function(){
    var name = jq(this).attr('name');
    var url = jq(this).attr('url');
    var t_url=jq(this).attr('t_url');
    layer.confirm(name, function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.post(url,function(data){
        if(data.code == 1){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1,anim: 2, time: 1000}, function(){
            if(t_url === undefined){
              location.reload();
            }else{
              location.href = t_url;
            }
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });
  });
  //一键更新
  form.on('switch(index)', function(data){
    loading = layer.load(2, {
      shade: [0.2,'#000']
    });
    var url= jq(this).attr('url');
    var param = data.field;
    jq.post(url,param,function(data){
      if(data.code == 1){
        layer.close(loading);
        layer.msg(data.msg, {icon: 1, anim: 2, time: 1000}, function(){
         //location.reload();
        });
      }else{
        layer.close(loading);
        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
      }
    });
    return false;
  });
  
})
//上传
layui.use(['form', 'upload', 'jquery']
,function(){
    var form = layui.form,
    upload = layui.upload,
    jq = layui.jquery;
    //上传图片单个1
    upload.render({
	    elem: '.upimg2',
	    url: "/index.php/admin/up/up.html",
	    accept: 'file',
	    exts: 'jpg|png|gif|bmp|jpeg',
    	done: function(res) {
		    if (res.code == '1') {
			var up = jq('.upimg2').attr('up2');
		    	jq('input[id='+up+']').val(res.path);
		    	layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
	    	} else {
		    	layer.msg(res.msg);
	    	}
    	}
	});

        // 发送验证码
        jq('#phonecode').click(function() {
            var obj = $(this);
            var options = {
                seconds: 60,
                type: 'REG'
            };
            var name = $("#phone").val();　
            var t_url = $(this).attr('t_url');
            if (name == "") {　　　
                layer.msg('手机号码必填');　　　　
                return false;　　
            } 
            loading = layer.load(0, {
                shade: [0.2, '#000']
            });
            jq.getJSON(t_url+'?phone=' + name,
            function(data) {
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        countDown(60, obj);
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            });
        });
 
    // 发送验证码
    function countDown(seconds, obj) {
        if (seconds > 1) {
            seconds--;
            $(obj).attr('disabled', true).html(seconds + "秒"); //禁用按钮
            setTimeout(function() {
                countDown(seconds, obj);
            },
            1000);
        } else {
            $(obj).attr('disabled', false).html("获取验证码"); //启用按钮
        }
    } 

    //上传图片单个1
    upload.render({
	    elem: '.upimg1',
	    url: "/index.php/admin/up/up.html",
	    accept: 'file',
	    exts: 'jpg|png|gif|bmp|jpeg',
    	done: function(res) {
		    if (res.code == '1') {
			var up = jq('.upimg1').attr('up1');
		    	jq('input[id='+up+']').val(res.path);
		    	layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
	    	} else {
		    	layer.msg(res.msg);
	    	}
    	}
	});
    //上传图片单个1
    upload.render({
	    elem: '.upimg',
	    url: "/index.php/admin/up/up.html",
	    accept: 'file',
	    exts: 'jpg|png|gif|bmp|jpeg',
    	done: function(res) {
		    if (res.code == '1') {
			var up = jq('.upimg').attr('up');
		    	jq('input[id='+up+']').val(res.path);
		    	layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
	    	} else {
		    	layer.msg(res.msg);
	    	}
    	}
	});
  //上传附件单个
	upload.render({
		elem: '.up',
		url: "/index.php/admin/up/up.html",
		accept: 'file',
		done: function(res) {
		    if (res.code == '1') {
			var up = jq('.up').attr('up');
		    	jq('input[id='+up+']').val(res.path);
		    	layer.msg(res.msg);
	    	} else {
		    	layer.msg(res.msg);
	    	}
		}
	});
	 p=0;
     s=0;
	//多图上传
	upload.render({
    elem: '.imgid'
    ,url: '/index.php/admin/up/up.html'
    ,multiple: true
    ,allDone: function(obj){ //当文件全部被提交后，才触发
	  layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
    }
    ,done: function(res, index, upload){ //每个文件提交一次触发一次。详见“请求成功的回调”
      if (res.code == '1') {
	//添加插入图片参数
	$(".picrq").append('<div style="float: left;width:120px;margin-top:10px;" id="unpic'+p+++'"><div align="center"> <img src="'+res.path+'" height="100" width="100" /> <input type="hidden" name="pics['+Math.floor((Math.random()*10000)+1000)+']"  autocomplete="off" value="'+res.path+'" class="layui-input"> <i onclick="picun'+s+++'()" class="layui-icon layui-icon-face-smile" style="font-size: 30px;color: #ff1e1e;cursor:pointer;margin-top:-30px;">&#x1007;</i> </div> </div>');
		//return layer.msg(res.msg);
	  } else {
		//return layer.msg(res.msg);
	  }
    }
  }); 
		form.on('radio(linktype)',
		function(data) {
			if (data.value == 1) {
				//显示
				$("#viewscore").show();
			} 
			if (data.value == 0) {
				//隐藏
				$("#viewscore").hide();
			} 
		});
		form.on('radio(linktype1)',
		function(data) {
			if (data.value == 1) {
				//显示
				$("#viewscore1").show();
			} 
			if (data.value == 0) {
				//隐藏
				$("#viewscore1").hide();
			} 
		});
		form.on('radio(linktype2)',
		function(data) {
			if (data.value == 1) {
				//隐藏
				$("#viewscore2").hide();
			} 
			if (data.value == 0) {
				//显示
				$("#viewscore2").show();
			} 
		});
		form.on('radio(linktype3)',
		function(data) {
			if (data.value == 1) {
				//显示
				$("#viewscore3").show();
			} 
			if (data.value == 0) {
				//隐藏
				$("#viewscore3").hide();
			} 
		});
})
  //参数添加删除
function unsku0(){
	var idObject = document.getElementById('un0');
    idObject.parentNode.removeChild(idObject);
}
function unsku1(){
	var idObject = document.getElementById('un1');
    idObject.parentNode.removeChild(idObject);
}
function unsku2(){
	var idObject = document.getElementById('un2');
    idObject.parentNode.removeChild(idObject);
}
function unsku3(){
	var idObject = document.getElementById('un3');
    idObject.parentNode.removeChild(idObject);
}
function unsku4(){
	var idObject = document.getElementById('un4');
    idObject.parentNode.removeChild(idObject);
}
function unsku5(){
	var idObject = document.getElementById('un5');
    idObject.parentNode.removeChild(idObject);
}
function unsku6(){
	var idObject = document.getElementById('un6');
    idObject.parentNode.removeChild(idObject);
}
function unsku7(){
	var idObject = document.getElementById('un7');
    idObject.parentNode.removeChild(idObject);
}
function unsku8(){
	var idObject = document.getElementById('un8');
    idObject.parentNode.removeChild(idObject);
}
function unsku9(){
	var idObject = document.getElementById('un9');
    idObject.parentNode.removeChild(idObject);
}
function unsku10(){
	var idObject = document.getElementById('un10');
    idObject.parentNode.removeChild(idObject);
}
function unsku11(){
	var idObject = document.getElementById('un11');
    idObject.parentNode.removeChild(idObject);
}
//参数编辑删除
function unskus0(){
	var idObject = document.getElementById('uns0');
    idObject.parentNode.removeChild(idObject);
}
function unskus1(){
	var idObject = document.getElementById('uns1');
    idObject.parentNode.removeChild(idObject);
}
function unskus2(){
	var idObject = document.getElementById('uns2');
    idObject.parentNode.removeChild(idObject);
}
function unskus3(){
	var idObject = document.getElementById('uns3');
    idObject.parentNode.removeChild(idObject);
}
function unskus4(){
	var idObject = document.getElementById('uns4');
    idObject.parentNode.removeChild(idObject);
}
function unskus5(){
	var idObject = document.getElementById('uns5');
    idObject.parentNode.removeChild(idObject);
}
function unskus6(){
	var idObject = document.getElementById('uns6');
    idObject.parentNode.removeChild(idObject);
}
function unskus7(){
	var idObject = document.getElementById('uns7');
    idObject.parentNode.removeChild(idObject);
}
function unskus8(){
	var idObject = document.getElementById('uns8');
    idObject.parentNode.removeChild(idObject);
}
function unskus9(){
	var idObject = document.getElementById('uns9');
    idObject.parentNode.removeChild(idObject);
}
function unskus10(){
	var idObject = document.getElementById('uns10');
    idObject.parentNode.removeChild(idObject);
}
function unskus11(){
	var idObject = document.getElementById('uns11');
    idObject.parentNode.removeChild(idObject);
}
 //图片添加删除
function picun0(){
	var idObject = document.getElementById('unpic0');
    idObject.parentNode.removeChild(idObject);
}
function picun1(){
	var idObject = document.getElementById('unpic1');
    idObject.parentNode.removeChild(idObject);
}
function picun2(){
	var idObject = document.getElementById('unpic2');
    idObject.parentNode.removeChild(idObject);
}
function picun3(){
	var idObject = document.getElementById('unpic3');
    idObject.parentNode.removeChild(idObject);
}
function picun4(){
	var idObject = document.getElementById('unpic4');
    idObject.parentNode.removeChild(idObject);
}
function picun5(){
	var idObject = document.getElementById('unpic5');
    idObject.parentNode.removeChild(idObject);
}
function picun6(){
	var idObject = document.getElementById('unpic6');
    idObject.parentNode.removeChild(idObject);
}
function picun7(){
	var idObject = document.getElementById('unpic7');
    idObject.parentNode.removeChild(idObject);
}
function picun8(){
	var idObject = document.getElementById('unpic8');
    idObject.parentNode.removeChild(idObject);
}
function picun9(){
	var idObject = document.getElementById('unpic9');
    idObject.parentNode.removeChild(idObject);
}
function picun10(){
	var idObject = document.getElementById('unpic10');
    idObject.parentNode.removeChild(idObject);
}
function picun11(){
	var idObject = document.getElementById('unpic11');
    idObject.parentNode.removeChild(idObject);
}
//图标编辑删除
function uunpics0(){
	var idObject = document.getElementById('unpics0');
    idObject.parentNode.removeChild(idObject);
}
function uunpics1(){
	var idObject = document.getElementById('unpics1');
    idObject.parentNode.removeChild(idObject);
}
function uunpics2(){
	var idObject = document.getElementById('unpics2');
    idObject.parentNode.removeChild(idObject);
}
function uunpics3(){
	var idObject = document.getElementById('unpics3');
    idObject.parentNode.removeChild(idObject);
}
function uunpics4(){
	var idObject = document.getElementById('unpics4');
    idObject.parentNode.removeChild(idObject);
}
function uunpics5(){
	var idObject = document.getElementById('unpics5');
    idObject.parentNode.removeChild(idObject);
}
function uunpics6(){
	var idObject = document.getElementById('unpics6');
    idObject.parentNode.removeChild(idObject);
}
function uunpics7(){
	var idObject = document.getElementById('unpics7');
    idObject.parentNode.removeChild(idObject);
}
function uunpics8(){
	var idObject = document.getElementById('unpics8');
    idObject.parentNode.removeChild(idObject);
}
function uunpics9(){
	var idObject = document.getElementById('unpics9');
    idObject.parentNode.removeChild(idObject);
}
function uunpics10(){
	var idObject = document.getElementById('unpics10');
    idObject.parentNode.removeChild(idObject);
}
function uunpics11(){
	var idObject = document.getElementById('unpics11');
    idObject.parentNode.removeChild(idObject);
}
$(document).ready(function(){
	
	i=0;
	b=0;
	$(".add").click(function(){
	//获取名称
	value1=$("#value1").val();
	//获取值
	value2=$("#value2").val();
	
	//添加插入sku参数
	$(".skurq").append('<div id="un'+i+++'" class="layui-form-item"><label class="layui-form-label">'+value1+'</label><div class="layui-input-inline"><input type="text" name="sku['+value1+']" lay-verify="required" autocomplete="off" value="'+value2+'" placeholder="类型 例:10GK-20KG -隔开" class="layui-input"></div><div onclick="unsku'+b+++'()" class="layui-form-mid layui-word-aux"><i class="layui-icon layui-icon-face-smile" style="font-size: 30px;color: #ff1e1e;cursor:pointer">&#x1007;</i></div></div>');
	//清空规格填写
	$("#value1,#value2").val("");
	});
	//例子
	$(".lizi").click(function(){
	  $("#value1").val("颜色");
	  $("#value2").val("黑色-白色-红色");
	});
 
});
$(document).ready(function(){
  $("#pic").mouseenter(function(){
  	//鼠标移上显示
  	$("#tup").css({"display":"block"});
  	//获取upsimg值
    OR= $("#pic").val();
    //传入tupimg
    $("#tupimg").attr("src",OR);
  });
 $("#pic").mouseleave(function(){
 	//鼠标离开隐藏
 	$("#tup").css({"display":"none"});
    
  });
  $("#pic1").mouseenter(function(){
  	//鼠标移上显示
  	$("#tup1").css({"display":"block"});
  	//获取upsimg值
    OR= $("#pic1").val();
    //传入tupimg
    $("#tupimg1").attr("src",OR);
  });
 $("#pic1").mouseleave(function(){
 	//鼠标离开隐藏
 	$("#tup1").css({"display":"none"});
    
  });
  $("#pic2").mouseenter(function(){
  	//鼠标移上显示
  	$("#tup2").css({"display":"block"});
  	//获取upsimg值
    OR= $("#pic2").val();
    //传入tupimg
    $("#tupimg2").attr("src",OR);
  });
 $("#pic2").mouseleave(function(){
 	//鼠标离开隐藏
 	$("#tup2").css({"display":"none"});
    
  });
});
$(".tan_v").click(function() {
    var name = $(this).attr('name');
    var url = $(this).attr('url');
    layer.prompt({
        title: ''+name+'',
        formType: 3
    },
    function(text, index) {
        $.ajax({
            url: ""+url+text+"",
            type: "GET",
            dataType: "json",
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        location.reload();
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
});