$(function(){
  	 var html='';
  	 
  	 $("#mobilepr").change(function(){
  	     window.location.href=$(this).val()
         window.event.returnValue=false;
        
  	 })
	 //
	 $('.user_tab_act_sec li a').click(function(){
						$(this).addClass('on').parent().siblings().find('a').removeClass('on');
						$('.logintab').hide();
						$('.logintab').eq($(this).attr('lang')).show();
						if($(this).attr('lang')==1){
							$('.login_1_right').show();	
						}else{
							$('.login_1_right').hide();
						}
	 });
  	 //
	 $("body").on("click",".calert",function(){
		 $('.alertbox').remove();
	  });
	 //
	 $("body").on("click",".secpro_mid_close",function(){
		 $(this).parent().remove();
	  });
	 //
	 $(".usericon").click(function(){
	      //首先登录
           let token = $("#is_login_token").val()
           console.log(token)
           if(token == 0){
               // $('.maskfix').fadeIn();
           }else{
               //这里跳转一下
               
           }
	 });
	 $('.maskfix_mid_mid_mid_close a').click(function(){
		$('.maskfix').fadeOut();
	 });
	 $('.add_4_mid_3 a').click(function(){
							 $(this).toggleClass("on");
	 });
	 $('.order_2_mid_3 dl dd').click(function(){
		$(this).addClass('on').siblings().removeClass('on');
	 });
	 $('.add_list').click(function(){
		html=$('.secpro .secpro_mid').eq(0).html();
		$('.secpro').append('<div class="secpro_mid">'+html+'</div>')	
		
		$('.secpro .secpro_mid').eq($('.secpro .secpro_mid').length-1).find('.sjbd_mid_4 dl dd.daxuan .sjbd_mid_4_right span').removeClass('on'); 	
		$('.secpro .secpro_mid').eq($('.secpro .secpro_mid').length-1).find('.sjbd_mid_4 dl dd.duxuan .sjbd_mid_4_right span').removeClass('on'); 
		
		$('.secpro .secpro_mid').eq($('.secpro .secpro_mid').length-1).find('.up3 img').hide(); 
		
		$('.secpro .secpro_mid').eq($('.secpro .secpro_mid').length-1).find('.ccc').hide(); 
		$('.secpro .secpro_mid').eq($('.secpro .secpro_mid').length-1).find('.vvv').hide(); 
		
	 });
	 
	 $("body").on("click",".sjbd_mid_4 dl dd.daxuan .sjbd_mid_4_right span",function(){
		 $(this).toggleClass("on").siblings().removeClass('on');
	  });
	 $("body").on("click",".sjbd_mid_4 dl dd.duxuan .sjbd_mid_4_right span",function(){
		 $(this).toggleClass("on")
	  });
	 
	 
	 
	  
});
//
function alertmsg(msg){
	 
	var ht='<div class="alertbox" style="z-index:99999999999999999999;display:block;"><Div class="cell_mid"><div class="cell_h"><Div class="alertbox_mid"><Div class="alertbox_mid_jj"><div class="alertbox_mid_jj_close"><a href="javascript:;" class="calert"><img src="/template/images/shop/c5.png"></a></div><Div class="alertbox_mid_jj_1"><img src="/template/images/shop/c4.png"></Div><div class="alertbox_mid_jj_2">'+msg+'</div><div class="alertbox_mid_jj_3"><a href="javascript:;" class="calert">确认</a></div></Div></Div></div></Div></div>';
	$('body').append(ht);
	 
	
}
//输入订单号 baogao.php
function shurudingdanhao()
{
    let token = $("#is_login_token").val()
    if(token == 0){
        $('.maskfix').fadeIn();
        return false;
    }
    let order_id = $("#dingdan_id").val();
    let yundan_sn = $("#shurudingdan").val();
	$('#wlbg').submit();
    /*$.ajax({
         url:"/api/user/submitReportWuliu",
         method:'POST',
         data:{
          order_id: order_id,
		  yundan_sn:yundan_sn
         },
         success:function(result){
            let data = result.data
            if(result.code == 1){
                window.location.href="/p/jiancebaogaos.html"
                window.event.returnValue=false;
            }else{
                alertmsg(result.msg)
            }
            // $("#div1").html(result);
        }
     });*/
    
}

//去送检第二个页面
function goSongjianSecondPage()
{
    let token = $("#is_login_token").val()
    if(token == 0){
        $('.maskfix').fadeIn();
        return false;
    }
    window.location.href="/p/woyaosongjiantwo.html"
    window.event.returnValue=false;
}

function goSongjianToupiSecondPage()
{
    let token = $("#is_login_token").val()
    if(token == 0){
        $('.maskfix').fadeIn();
        return false;
    }
    window.location.href="/p/woyaosongjiantoupitwo.html"
    window.event.returnValue=false;
}

//送检提交
function songjianTijiao()
{   
    let data = $(".sjbd_mid_1");
    let info = {};
    let shuru = $("#shuru").val();
    let danxuan = $("#danxuan").val();
    let duoxuan = $("#duoxuan").val();
    var v1=true;
    $(".sjbd_mid_3 ul li input").each(function(i){
		if($(this).val()==""){
			v1=false;	
		}
        //获取下标
        let index = parseInt(i/shuru)
		
        if(!info[index]){
            info[index] = {};
        }
        if(!info[index]['shuru']){
            info[index]['shuru'] = {};
        }
        info[index]['shuru'][$(this).attr('name')] = $(this).val()
        
    })
	if(v1==false){
		//alert("带*的问题为必答");
		alertmsg("带*的问题为必答！")
		return false
	}
	var v2=true;
	$(".sjbd_mid_pic input.piclist").each(function(i){
		if($(this).val()==""){
			v2=false;	
		}
        //获取下标
        let index = parseInt(i/1)
        if(!info[index]){
            info[index] = {};
        }
        if(!info[index]['pic']){
            info[index]['pic'] = {};
        }
        info[index]['pic']['图片上传'] = $(this).val()
        
    })
	
    var v3=true; 
    $(".daxuan .sjbd_mid_4_right").each(function(i){
        //获取下标
        let index = parseInt(i/danxuan)
        if(!info[index]){
            info[index] = {};
        }
        if(!info[index]['danxuan']){
            info[index]['danxuan'] = {};
        }
        let wenti = $(this).attr('id')
        info[index]['danxuan'][wenti] = {};
        
        var wenti_arr = {};
        //怎么样获取他下面的span
        let a = $(this).find('span').each(function(j){
            var tep = {};
            tep['checked'] = 0;
            if($(this).attr('class') == 'on'){
                tep['checked'] = 1;
				 
            }else{
				 
			}
            tep['text'] = $(this).html();
            wenti_arr[j] = tep
        });
        info[index]['danxuan'][wenti] = wenti_arr
		if(!$(this).find('span').hasClass('on')){
			v3=false;
		}
        
    })
    if(v3==false){
		//alert("带*的问题为必答");
		alertmsg("带*的问题为必答！")
		return false
	}
	var v4=true;
    $(".duxuan .sjbd_mid_4_right").each(function(i){
        //获取下标
        let index = parseInt(i/duoxuan)
        if(!info[index]){
            info[index] = {};
        }
        if(!info[index]['duoxuan']){
            info[index]['duoxuan'] = {}
        }
        let wenti = $(this).attr('id')
        info[index]['duoxuan'][wenti] = {}
        
        var wenti_arr = {};
        //怎么样获取他下面的span
        let a = $(this).find('span').each(function(j){
            var tep = {};
            tep['checked'] = 0;
            if($(this).attr('class') == 'on'){
                tep['checked'] = 1;
            }
            tep['text'] = $(this).html();
            wenti_arr[j] = tep
        });
        info[index]['duoxuan'][wenti] = wenti_arr
		if(!$(this).find('span').hasClass('on')){
			v4=false;
		}
        
    })
	if(v4==false){
		//alert("带*的问题为必答");
		 alertmsg("带*的问题为必答！")
		return false
	}
	  if(v2==false){
		//alert("请上传面部图片！");
		 alertmsg("请上传面部图片！")
		return false
	} 
	
	
    
    console.log(info)
     console.log(JSON.stringify(info))
    let info_json = JSON.stringify(info)
    info_json = htmlEncode(info_json)
	//return false;
    $.ajax({
         url:"/api/user/submitReport",
         method:'POST',
         data:{
          info: JSON.stringify(info),
         },
         success:function(result){
            let data = result.data
            if(result.code == 1){
                window.location.href="/p/jiancebaogaos.html"
                window.event.returnValue=false;
            }else{
                alertmsg(result.msg)
            }
            // $("#div1").html(result);
        }
     });
}

function htmlEncode(str) {
  str = str.replace(/s+/ig, '');
  str = str.replace(/&/g, '');
  str = str.replace(/</g, '');
  str = str.replace(/>/g, '');
  str = str.replace(/(?:t| |v|r)*n/g, '<br />');
  str = str.replace(/t/g, '    ');
  str = str.replace(/x22/g, '"');
  str = str.replace(/"/g, "");
  return str;
}
//送检页面 获取报告 
function bindReportPhone(){
    let token = $("#is_login_token").val()
    if(token == 0){
        $('.maskfix').fadeIn();
        return false;
    }
    let phone = $('#report_phone').val();
    let code = $('#report_phone_code').val();
    $.ajax({
         url:"/api/user/bindReportPhone",
         method:'POST',
         data:{
          mobile:phone,
          captcha:code
         },
         success:function(result){
            let data = result.data
            if(result.code == 1){
                if(data == 0){
                    alertmsg("暂无报告")
                }else{
                    window.location.href="/p/jiancebaogaos.html"
                    window.event.returnValue=false;
                }
                
            }else{
                alertmsg("验证码错误")
            }
            // $("#div1").html(result);
        }
     });
}

//送检页面 获取报告 
function getRoportPhoneCode(){
    let token = $("#is_login_token").val()
    if(token == 0){
        $('.maskfix').fadeIn();
        return false;
    }
    let phone = $('#report_phone').val();
    $.ajax({
         url:"/api/sms/send",
         method:'POST',
         data:{
          mobile:phone,
          event:'notice'
         },
         success:function(result){
             let data = result.data
             if(result.code == 1){
                 alertmsg("短信已发送")
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
}


//订单页面
function goPayPage(orderid){
    if(orderid){
        if(browserRedirect() == 'H5'){
            window.location.href="/p/zhifufangshi_h5.html?orderid="+orderid
            window.event.returnValue=false;
        }else{
            window.location.href="/p/zhifufangshi.html?orderid="+orderid
            window.event.returnValue=false;
        }
    }
}

//取消订单
function cannelOrder(id){
    $.ajax({
         url:"/addons/cms/order/orderExpres",
         method:'POST',
         data:{
            id:id
         },
         success:function(result){
             
             
             if(result.code == 1){
                $("#order_"+id).remove();
             }
            
        }
     });
}

//区分环境是 H5 还是PC
function browserRedirect() { 
    var sUserAgent= navigator.userAgent.toLowerCase(); 
    var bIsIpad= sUserAgent.match(/ipad/i) == "ipad"; 
    var bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os"; 
    var bIsMidp= sUserAgent.match(/midp/i) == "midp"; 
    var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; 
    var bIsUc= sUserAgent.match(/ucweb/i) == "ucweb"; 
    var bIsUcs= sUserAgent.match(/ucbrowser/i) == "ucbrowser"; 
    var bIsAndroid= sUserAgent.match(/android/i) == "android"; 
    var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce"; 
    var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile"; 
    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || bIsUcs) { 
         return 'H5';
    } else { 
         return "PC";
    } 
} 

//区分是否是微信环境
function is_weixin(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}



//地址删除
function addressDel(id)
{
    
    $.ajax({
         url:"/api/user/address",
         method:'POST',
         data:{
            action:'delete',
            id:id
         },
         success:function(result){
             let data = result.data
             
             if(result.code == 1){
                 $("#address_"+id).remove();
             }
            
        }
     });
}


function queryExpress(){
    let token = $("#is_login_token").val()
    if(token == 0){
        $('.maskfix').fadeIn();
        return false;
    }
    let query_order = $("#wuliu_ordersn").val()
    let phone = $("#wuliu_phone").val()
	if(phone==""){
		alertmsg("收货人手机号后四位不能为空");	
		return false;
	}
    if(query_order){
        $.ajax({
             url:"/addons/cms/order/queryExpress",
             method:'POST',
             data:{
                express_order_sn:query_order,
                phone:phone
             },
             success:function(result){
                 let data = result.data
                 if(result.code == 1){
					  
                  //  data = "<span>"+data+"</span>";
                   // $("#wuliu_info").empty();
                    //$("#wuliu_info").append(data)
					$('.wl_1_mid_3 ul').html(result.data.html);
                 }else{
					 alertmsg(result.msg);			 
				 }
                
            }
         });
    }else{
        alertmsg("请输入订单号");
    }
    
}

function goPayTypePage(){
    let address_id = $("#address_id").val();
    console.log(11)
    if(address_id != 0){
        if(browserRedirect() == 'H5'){
            window.location.href="/p/zhifufangshi_h5.html"
            window.event.returnValue=false;
        }else{
            window.location.href="/p/zhifufangshi.html"
            window.event.returnValue=false;
        }
        
    }else{
        alertmsg('请选择地址');
    }
}

function payType_H5(){
    let weixin = $("#weixin_zhifu").attr("class");
    // console.log(weixin)
    if(weixin == 'on'){
        if(is_weixin()){
            //走微信公众号
            payType('wechat_mp')
        }else{
            //走H5
            payType('wechat_h5')
        }
    }else{
        //走阿里H5
        payType('alipay_h5')
    }
}

function payType(paytype){
    let order_id = $("#orderidvalue").val()
	//alert("/api/pay/pay?pay_type=wechat_h5&orderid="+order_id);
	//return false;
    if(paytype == 'alipay_web'){
        window.location.href="/api/pay/pay?pay_type=alipay_web&orderid="+order_id
        window.event.returnValue=false;
    }else if(paytype == 'alipay_h5'){
        window.location.href="/api/pay/pay?pay_type=alipay_h5&orderid="+order_id
        window.event.returnValue=false;
    }else if(paytype == 'wechat_h5'){
        window.location.href="/api/pay/pay?pay_type=wechat_h5&orderid="+order_id
        window.event.returnValue=false;
    }else if(paytype == 'wechat_mp'){
        window.location.href="/api/pay/pay?pay_type=wechat_mp&orderid="+order_id
        window.event.returnValue=false;
    }
}

function checkAddress(id){
    let token = getCookie('token')
    $.ajax({
         url:"/api/user/address",
         method:'POST',
         headers:{
           token: token 
         },
         data:{
            action:'is_default',
            id:id
         },
         success:function(result){
             let data = result.data
             
             if(result.code == 1){
                 window.location.href="/p/quedingdingdan.html"
                 window.event.returnValue=false;
             }
            
        }
     });
}

function addAddress()
{
    let consigee = $('#consigee').val();
    let phone = $('#phone').val();
    let province = $('#province').val();
    let address = $('#address').val();
    let is_default_class = $('#is_default').attr('class');
    let is_default = 0 
    if(is_default_class == 'on'){
        is_default = 1
    }
    let token = getCookie('token')
	if(consigee==""){
		alertmsg("收货人姓名不能为空");
		return false;
	}
	if(phone==""){
		alertmsg("手机号码不能为空");
		return false;
	}
	if(province==""){
		alertmsg("省市不能为空");
		return false;
	}
	if(address==""){
		alertmsg("详细地址不能为空");
		return false;
	}
    $.ajax({
         url:"/api/user/address",
         method:'POST',
         headers:{
           token: token 
         },
         data:{
            action:'add',
            consigee:consigee,
            phone:phone,
            province:province,
            city:'',
            name:address,
            is_default:is_default,
         },
         success:function(result){
             let data = result.data
             
             if(result.code == 1){
                 window.location.href="/p/dizhiliebiao.html"
                 window.event.returnValue=false;
             }
            
        }
     });
    
}

function wuliulogin(){
    let token = $("#is_login_token").val()
    if(token == 0){
        //$('.maskfix').fadeIn();
		window.location.href="/index/user/login";
    }
    
}

function gobuy(goods_id){
   //首先登录
//   let token = getCookie('token')
   let token = $("#is_login_token").val()
   if(token == 0){
        $('.maskfix').fadeIn();
   }else{
       let goods_id = $('#goods_id').val();
       $.ajax({
             url:"/api/user/cart",
             method:'POST',
             headers:{
               token: token 
             },
             data:{
                action:'add',
                goods_id:goods_id
             },
             success:function(result){
                 
                 let data = result.data
                 if(result.code == 1){
                     console.log('跳转页面')
                       window.location.href="/p/quedingdingdan.html"
                       window.event.returnValue=false;
                 }else{
                     alertmsg(result.msg)
                 }
                // $("#div1").html(result);
            }
         });
       
   }
  
}

var count = 30; //间隔函数，1秒执行
			var InterValObj1; //timer变量，控制时间
			var curCount1;//当前剩余秒数
function sendSmsCode(){
    let phone = $('#login_moblie').val();
	var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;//手机号正则 
			
	curCount1 = count;	
	if (!phoneReg.test(phone)) {
					alertmsg(" 请输入有效的手机号码"); 
					return false;
				}
	
    $.ajax({
         url:"/api/sms/send",
         method:'POST',
         data:{
          mobile:phone,
          event:'mobilelogin'
         },
         success:function(result){
             console.log(result)
             console.log(result.code)
             let data = result.data
             if(result.code == 1){
                 alertmsg("短信已发送");
				 //设置button效果，开始计时
						$(".getv input").attr("disabled", "true");
						$(".getv input").val( + curCount1 + "秒再获取");
						InterValObj1 = window.setInterval(SetRemainTime1, 1000); //启动计时器，1秒执行一次
				 
				 
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
}

function SetRemainTime1() {
				if (curCount1 == 0) {                
					window.clearInterval(InterValObj1);//停止计时器
					$(".getv input").removeAttr("disabled");//启用按钮
					$(".getv input").val("重新发送");
				}
				else {
					curCount1--;
					$(".getv input").val( + curCount1 + "秒再获取");
				}
			} 

function sendSmsCode2(){
    let phone = $('#reg_moblie').val();
    $.ajax({
         url:"/api/sms/send",
         method:'POST',
         data:{
          mobile:phone,
          event:'register'
         },
         success:function(result){
             console.log(result)
             console.log(result.code)
             let data = result.data
             if(result.code == 1){
                 alertmsg("短信已发送")
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
}

function sendSmsCode3(){
    let phone = $('#reg_moblie').val();
    $.ajax({
         url:"/api/sms/send",
         method:'POST',
         data:{
          mobile:phone,
          event:'resetpwd'
         },
         success:function(result){
             console.log(result)
             console.log(result.code)
             let data = result.data
             if(result.code == 1){
                 alertmsg("短信已发送")
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
}
 

 
function gologin()
 {
    let phone = $('#login_moblie').val();
    let code = $('#login_code').val();
    
    $.ajax({
         url:"/api/user/mobilelogin",
         method:'POST',
         data:{
            mobile:phone,
            captcha:code
         },
         success:function(result){
             
             let data = result.data
             if(result.code == 1){
                //  alertmsg("登录成功")
                 setCookie('token',data.userinfo.token);
                 console.log($(".loginbtn").attr('class'))
                 if($(".loginbtn").attr('class')){
                    let id =  $(".loginbtn").attr('id');
                    id = id.replace("archives_",""); 
                    $("#is_login_token").val(1)
                   // gobuy(id)
				   // location.reload();
                       window.location.href="/p/dingdanquanbu.html";
                     window.event.returnValue=false;
				   
                 }else{
                    // location.reload();
                      window.location.href="/p/dingdanquanbu.html";
                     window.event.returnValue=false;
                 }
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
 }
function gopass()
 {
    let phone = $('#reg_moblie').val();
    let pass = $('#reg_pass').val();
	let pass2 = $('#reg_pass2').val();
	let code = $('#reg_code').val();
    if(phone==""){
		alertmsg("手机号码不能为空");
		return false;
	}
	if(code==""){
		alertmsg("验证码不能为空");
		return false;
	}
	if(pass==""){
		alertmsg("密码不能为空");
		return false;
	}
	if(pass2==""){
		alertmsg("确认密码不能为空");
		return false;
	}
	if(pass!=pass2){
		alertmsg("两次输入密码不一致");
		return false;
	}
    $.ajax({
         url:"/index/user/resetpwd",
         method:'POST',
         data:{
            mobile:phone,
            code:code,
			pass:pass,
			pass2:pass2
         },
         success:function(result){
             
             
             if(result.code == 1){
				 alertmsg(result.msg);
				 setTimeout('window.location.href="/index/user/login";',2000);
				// 
                 
                 
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
 } 
 function goreg()
 {
    let phone = $('#reg_moblie').val();
    let pass = $('#reg_pass').val();
	let pass2 = $('#reg_pass2').val();
	let code = $('#reg_code').val();
    if(phone==""){
		alertmsg("手机号码不能为空");
		return false;
	}
	if(pass==""){
		alertmsg("密码不能为空");
		return false;
	}
	if(pass2==""){
		alertmsg("确认密码不能为空");
		return false;
	}
	if(pass!=pass2){
		alertmsg("两次输入密码不一致");
		return false;
	}
    $.ajax({
         url:"/index/user/ajaxreg",
         method:'POST',
         data:{
            mobile:phone,
            code:code,
			pass:pass,
			pass2:pass2
         },
         success:function(result){
             
             let data = result.data;
             if(result.code == 1){
				 
				 setCookie('token',data.userinfo.token);	
				 window.location.href='/p/dingdanquanbu.html';
                 
                 
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
 }
 
 function gologin_pass()
 {
    let phone = $('#login_moblie_passphone').val();
    let pass = $('#login_moblie_passpass').val();
    
    $.ajax({
         url:"/index/user/ajaxlogin",
         method:'POST',
         data:{
            mobile:phone,
            pass:pass
         },
         success:function(result){
             
             let data = result.data
             if(result.code == 1){
                //  alertmsg("登录成功")
                 setCookie('token',data.userinfo.token);
				 
                  window.location.href=result.url;
                  
				   
                  
             }else{
                 alertmsg(result.msg)
             }
            // $("#div1").html(result);
        }
     });
 }
 
//确定订单页面
 //加
function plus(){
    var num = $("#num").val();
     num = Number(num)+1;
     $("#num").attr('value',num);
     var price = $("#price").val();
     var totlal = Number(price) * num
     var type = $("#type").val();
     $("#total_num").empty();
     $("#total_num").append("共"+String(num)+"件");
     $(".mn").empty();
     $(".mn").append(totlal);
     
     //修改购物车的数量
     let goods_id = $("#goods_id").val()
     editCart(goods_id,num,type)
}
 
 //减
 function reduce(){
     var num = $("#num").val();
     num = Number(num)-1;
     if(num <= 1){
         num = 1
     }
     $("#num").attr('value',num);
     var price = $("#price").val();
	  var type = $("#type").val();
     var totlal = Number(price) * num
     $("#total_num").empty();
     $("#total_num").append("共"+String(num)+"件");
     $(".mn").empty();
     $(".mn").append(totlal);
     let goods_id = $("#goods_id").val()
     editCart(goods_id,num,type)
 }
 
 //修改购物车的数量
 function editCart(goods_id,num,type){
     let token = getCookie('token')
     $.ajax({
         url:"/api/user/cart",
         method:'POST',
         headers:{
           token: token 
         },
         data:{
            action:'edit',
            goods_id:goods_id,
            num:num,
			type:type
         },
         success:function(result){
             
        }
     });
 }
 
 
 //存储cookie 修改cookie也可调用次方法，覆盖
function setCookie(name, value, iTime) { //name是cookie中的名，value是其值，iTime来预定过期的时间（以天为单位）
    var iDate = new Date();
    iDate.setDate(iDate.getDate() + iTime); //以天为单位,存储是需要将Date对象存储为格林威治时间形式的字符串
    document.cookie = name + '=' + value + ';expires=' + iDate.toGMTString();
}

//获取cookie
function getCookie(name) {
    //web中cookie是以分号+空格隔开的
    var res = document.cookie.split('; ');
    for (let i = 0; i < res.length; i++)
        if (res[i].split('=')[0] === name) return res[i].split('=')[1];
        //未找到
    return '';
}
 
 
