var id=mobile.getUrlVars("id"); var data; var custom; /** *初始化、添加监听 */ $(document).ready(function(){ //document.onkeydown=jumpPage; document.onkeydown = function(event) { var evt = event ? event : (window.event ? window.event : null); return jumpPage(Event.mapping(evt)); }; document.onirkeypress = function(event) { var evt = event ? event : (window.event ? window.event : null); return jumpPage(Event.mapping(evt)); }; document.onsystemevent = function(event) { var evt = event ? event : (window.event ? window.event : null); return jumpPage(Event.mapping(evt)); }; getProductDetail(); }); //获取商品信息 function getProductDetail(){ mobile.ajaxPost(base+"/product/getById",{id:id},function(json){ data = json.data; if(data.time_status==3){ $(".end-time").html("已过期"); $(".mui-btn").html("已过期"); $(".mui-btn").addClass("mui-btn-grey"); }else{ if (data.product_type!="30") { var interval = setInterval(function () { var typeName; var time; var leftTime if (new Date(data.end_time.replace(/-/g, "/")) > new Date()) { leftTime = (new Date(data.end_time.replace(/-/g, "/"))) - (new Date()); //计算剩余的毫秒数 typeName = "结束"; } else { leftTime = (new Date(data.use_time.replace(/-/g, "/"))) - (new Date()); //计算剩余的毫秒数 typeName = "过期"; } var days = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数 var hours = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟 var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数 hours = checkTime(hours); minutes = checkTime(minutes); seconds = checkTime(seconds); $(".end-time").html("距" + typeName + days + "天" + hours + "小时" + minutes + "分" + seconds + "秒"); }, 1000); } if(data.time_status==0){ $(".mui-btn").addClass("mui-btn-primary").addClass("active"); }else if(data.time_status==1){ $(".mui-btn").html("已抢完"); $(".mui-btn").addClass("mui-btn-grey"); }else { $(".mui-btn").html("已结束"); $(".mui-btn").addClass("mui-btn-grey"); } } $(".merchant-name").html(data.merchant_name); $(".product-name").html(data.product_name); $(".product-price").html("¥"+data.product_price); $(".product-old-price .del-line").html(data.product_old_price+"元"); $(".product-num").html(data.visit_num+"人关注"); if(data.payNum>0){ $(".product-num").html("总"+data.product_num+"份/剩"+(data.product_num-data.sale_num)+"份" + ""+data.payNum+"人正在付款 "); }else{ $(".product-num").html("总"+data.product_num+"份/剩"+(data.product_num-data.sale_num)+"份"); } $(".visit-num").html(data.visit_num+"人关注"); if(data.product_img_1){ $(".product-detail").append(''); } if(data.product_img_2){ $(".product-detail").append(''); } if(data.product_img_3){ $(".product-detail").append(''); } if(data.product_detail){ $(".product-detail").append(data.product_detail); } $(".product-detail").append(""); var qrtext = "http://www.3water.cn/buying/mobile/productDetail.jsp?company=1&id="+id $("#qrcode img").attr("src",base+"/common/qrcode?width=360&height=360&content="+escape(qrtext)); }); } //获取评价 function getComment(){ mobile.ajaxPost(base+"/userOrderComment/getList",{productId:id},function(json){ if(json.success){ if(json.data&&json.data.length>0){ var html=[]; $.each(json.data,function(id,item){ if(!item.nickname){ item.nickname="匿名用户"; } if(!item.headimgurl){ item.headimgurl=base+"static/mobile/image/avatar.png"; } html.push('
  • '); html.push('
    '); html.push(''); html.push('
    '+item.nickname+'
    '); html.push('
    '); for(var i=0;i'); } for(var i=0;i<5-parseInt(item.comment_rank);i++){ html.push(''); } html.push('
    '); html.push('

    '+item.comment_content+'

    '); html.push('

    '+item.create_time+'

    '); html.push('
    '); html.push('
  • '); }); $("#item3 ul").html(html.join("")); }else{ $("#item3").html('
    暂无评价
    '); } }else{ layer.open({content: json.msg,time: 3}); } },""); } function checkTime(i){ // 将0-9的数字前面加上0,例1变为01 if(i<10) { i = "0" + i; } return i; } function jumpPage(event) { if (event.code==37 || event.code=="KEY_LEFT")//左 fun_left(); if (event.code==38 || event.code=="KEY_UP")//上 fun_up(); if (event.code==39 || event.code=="KEY_RIGHT" )//右 fun_right(); if (event.code==40 || event.code=="KEY_DOWN" )//下 fun_down(); if (event.code==13 || event.code=="KEY_SELECT")//enter fun_enter(); if (event.code==640 || event.code=="KEY_BACK")//enter fun_back(); } var h=360; function fun_left(){ } function fun_right(){ } function fun_up(){ var p = h/($(".footer").position().top+720)*640; if($(".product-detail").position().top+h>0){ $(".product-detail").css("top",'0px'); $(".page-btn").css("top","0px"); }else{ $(".product-detail").css("top",$(".product-detail").position().top+h+'px'); $(".page-btn").css("top",$(".page-btn").position().top-p+"px"); } } function fun_down(){ var p = h/($(".footer").position().top+720)*640; if(-($(".product-detail").position().top-h)+720>$(".footer").position().top){ $(".product-detail").css("top",-$(".footer").position().top+720+"px"); $(".page-btn").css("top","640px"); }else{ $(".product-detail").css("top",$(".product-detail").position().top-h+"px"); $(".page-btn").css("top",$(".page-btn").position().top+p+"px"); } } function fun_enter(){ if($("#code").is(":hidden")&&$(".mui-btn").hasClass("active")){ $("#main").hide(); $("#code").show(); } } function fun_back(){ if($("#code").is(":hidden")){ history.back(); }else{ $("#code").hide(); $("#main").show(); return true; } }