$(function(){ pushHistory(); window.addEventListener("popstate", function(e) { location.href=base+"/mobile/index.jsp"; }, false); }); function pushHistory() { var state = { title: "title", url: "#" }; if(window.history.length==1){ window.history.pushState(state, "title", "#"); } } var id=mobile.getUrlVars("id"); var data; var custom; var pageNumber = 1; var pageSize=10; mui.init(); /** *初始化、添加监听 */ mui.ready(function(){ getCustom(); getProductDetail(); $("#sendCode").html(Math.floor(Math.random()*9000)+1000); $(".header").on("tap",".icon-cha",function(e){ $(".header .mui-table-view").hide(); $(".mui-content").css("padding-top","0"); }); $(".header").on("tap",".guanzhu",function(e){ var html=[]; html.push(''); mui.alert(html.join(""), '关注“'+custom.wechat_name+'”'); }); $("#custom").on("tap",function(){ var html=[]; html.push(''+ '
客服电话'+custom.custom_mobile+'
'); mui.alert(html.join(""), '客服二维码'); }); $("#user").on("tap",function(){ location.href=base+'/mobile/userCenter.jsp'; }); $(".merchant").on("tap",function(){ location.href=base+'/mobile/merchantDetail.jsp?id='+data.merchant.id; }); $("#merchant").on("tap",function(){ location.href=base+'/mobile/merchantDetail.jsp?id='+data.merchant.id; }); $(".tel").on("tap",function(){ location.href = 'tel:'+data.merchant.mobile; }); $(".map").on("tap",function(){ var locations=bd09togcj02(data.merchant.longitude,data.merchant.latitude); wx.ready(function(){ wx.openLocation({ latitude: locations[1], // 纬度,浮点数,范围为90 ~ -90 longitude: locations[0], // 经度,浮点数,范围为180 ~ -180。 name: data.merchant.merchant_name, // 位置名 address: data.merchant.address, // 地址详情说明 scale: 25, // 地图缩放级别,整形值,范围从1~28。默认为最大 infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转 }); }); }); $(".comment").on("tap",function(){ location.href = base+'/mobile/merchantComment.jsp?id='+data.merchant.id; }); $(".complain").on("tap",function(){ location.href = base+'/mobile/userComplain.jsp?id='+id; }); $(".mui-bar-tab").on("tap",".main-bgcolor",function(e){ e.stopPropagation(); if($("#toOrder").html()=="去评价"){ location.href=base+"/mobile/userOrderComment.jsp?id="+data.order.id; }else if($("#toOrder").html()=="立即抢购"){ buy(); }else if($("#toOrder").html()=="点击登录"){ $('#login').addClass('mui-active'); }else{ location.href=base+"/mobile/userOrderDetail.jsp?id="+data.order.id; } }); $("#login").on("tap",'.mui-icon-left-nav',function(){ $('#login').removeClass('mui-active'); }); $("#sendCode").on("tap",function(e){ $("#sendCode").html(Math.floor(Math.random()*9000)+1000); }); $("#login-btn").on("tap",function(e){ var mobilePhone = $.trim($('#mobile').val()); var code = $.trim($('#code').val()); if(!mobile.checkMobile(mobilePhone)){ layer.open({content:'请输入正确手机号码',time:3}); return; } if(code!=$("#sendCode").html()){ layer.open({content:'验证码错误',time:3}); return; } user.mobile = mobilePhone; mobile.ajaxPost(base+'/users/save',user, function(json) { layer.open({content: '登录成功', time: 3}); setTimeout(function() { $("#toOrder").html("立即抢购"); $('#login').removeClass('mui-active'); }, 1000); }); }); $("#use .icon-chucuo1").on("click",function(){ $("#use").remove(); }); $("#use .main").on("tap",function(){ location.href=base+"/mobile/index.jsp"; }); $("#use .order").on("tap",function(){ location.href=base+"/mobile/userOrderDetail.jsp?id="+data.order.id; }); //推广 $("#tuiguang").on('tap',function(){ if(user.is_share=='1'){ $("#share").show(); }else{ location.href=base+'/mobile/userInfo.jsp?flag=1'; } }); $("#kefu").on("tap",function(e){ var html=[]; html.push('' + '电话:'+mobile.getParam('customer_tel')+''); mui.alert(html.join(""), '长按二维码联系客服'); }); //分享 $(".share-bg").on('tap',function(){ $("#share").hide(); }); //分享 $(".share-img").on('tap',function(){ $("#share").hide(); }); $("#saveOrder").on('tap',function(){ saveOrder($('.mui-input-numbox').val()); }); $(".haibao").on("tap",function(){ if($("#myImg").attr("src")){ $(".poster").show(); $(".qr-mask").show(); $(".pic-box").hide(); }else{ var l = layer.open({type: 3,shadeClose:false,content: '生成中...'}); $(".poster").show(); html2canvas(document.querySelector("#pic-box"),{useCORS: true}).then(function(canvas) { // $("#myImg").css("height",$(window).height()-120); $("#myImg").css("width","100%"); $("#myImg").attr("src",getBase64Image(canvas)); $(".qr-mask").show(); $(".pic-box").hide(); layer.close(l); }); } }); $(".qr-mask").on("tap",function(){ $(".poster").hide(); $(".qr-mask").hide(); $(".pic-box").show(); }) $('#myImg').on('tap', function(event) { event.preventDefault(); event.stopPropagation(); }); }); /** * 抢购 * @returns */ function buy(){ if(!user.mobile){ $('#login').addClass('mui-active'); }else{ if(data.limit_num!=1){ mui('#popover').popover('toggle'); }else{ saveOrder(1); } } } function saveOrder(num){ mobile.ajaxPost(base+'/userOrder/save',{ productId: id, company: sessionStorage.getItem("company"), shareUser: sessionStorage.getItem("shareUser"), productNum: num },function(json){ if(json.success){ location.href=base+"/mobile/userOrderDetail.jsp?id="+json.data.id; }else{ layer.open({content:json.msg,time:3}); } }); } function getDistance(distance){ var i= parseInt(distance); if(i<1000){ return i+"米"; }else{ var f = parseFloat(i/1000); if (isNaN(f)) { return; } f = Math.round(i/1000 * 10) / 10; return f+"公里"; } } //获取商品信息 function getCustom(){ mobile.ajaxPost(base+"/sysCustom/getById",{},function(json){ custom = json.data; $(".wechat_logo").attr("src",imgUrl+custom.wechat_logo); $(".wechat_name").html(custom.wechat_name); $(".wechat_summary").html(custom.wechat_summary); }); } //获取商品信息 function getProductDetail(){ mobile.ajaxPost(base+"/product/getProduct",{id:id},function(json){ if(json.success){ data = json.data; if(data.time_status==3){ $("#toOrder").html("已结束"); $("#toOrder").removeClass("main-bgcolor").addClass("bgcolor3"); }else{ if (data.product_type=="10"){ $(".time").removeClass("mui-hidden"); 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); $(".time").html("距"+typeName+days+"天" + hours+"小时" + minutes+"分"+seconds+"秒"); }, 1000); } if(data.time_status==0){ var nbox = mui('.mui-numbox').numbox(); //nbox.options["max"]=data.limit_num-data.orderNum; if(data.order){ if(data.orderNum¥'+data.product_price+''+ '¥'+data.product_old_price+''); $(".pic-price .del-line").html(data.product_old_price+"元"); $(".pic-price .color-red").html(data.product_price+"元"); $(".product_integral").html(parseInt(data.product_price)+"积分"); $(".old_price").html(data.product_old_price+"元"); $(".visit_num").html(data.visit_num+"人关注"); $(".limit_num").html("限购"+data.limit_num+""+unit) $(".integral").html("返"+parseInt(data.product_price)+"积分"); var left_num = data.product_num-data.sale_num-data.init_num; if (left_num<0){ left_num=0; } if(data.payNum>0){ $(".product_num").html("总"+data.product_num+unit+"/剩"+(left_num)+unit+"" + ""+data.payNum+"人正在付款 "); }else{ $(".product_num").html("总"+data.product_num+unit+"/剩"+(left_num)+unit+""); } if(data.order_hour<=0){ $(".order_hour").html("免预约"); }else{ $(".order_hour").html("提前"+data.order_hour+"小时预约"); } if(data.is_pack==1){ $(".pack").html("提供打包"); }else{ $(".pack").html("店内使用"); } $(".merchant img").attr("src", imgUrl+data.merchant.merchant_img1); $(".merchant_name").html(data.merchant.merchant_name); $(".address").html(data.merchant.address); if(data.merchant.comment_num!=0){ $(".comment_num").html(data.merchant.comment_num+"人评价") } var qrtext = location.href.replace('#',''); if(qrtext.indexOf("shareUser")!=-1){ qrtext = mobile.changeUrlParam(qrtext,"shareUser",user.openid); }else{ qrtext+="&shareUser="+user.openid; } $("#qrcode img").attr("src",siteUrl+"/common/qrcode?width=80&height=80&content="+escape(qrtext)); if(data.product_notice){ $("#notice").html(data.product_notice); }else{ $("#notice").html('暂无信息'); } if(data.product_detail){ $("#detail").html(data.product_detail); $("img.lazy").lazyload({ threshold : 50, effect: "fadeIn", placeholder: base+'/static/mobile/image/500.gif', skip_invisible : false }); }else{ $("#detail").html('暂无信息'); } $('.mui-content').removeClass('mui-hidden'); $('.mui-bar-tab').removeClass('mui-hidden'); initSlider(arr); //获取评价 getHot(); wx.ready(function(){ wx.getLocation({ type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function (res) { $.ajax({ url:'http://api.map.baidu.com/geoconv/v1/?coords='+res.longitude+','+res.latitude+'&from=1&to=5&ak=3Q4laSROftZI4chFMPVUno90', dataType:'jsonp', processData: false, type:'get', success:function(json){ if (json.status=='0'){ var latitude=json.result[0].y; var longitude=json.result[0].x; var map = new BMap.Map("allmap"); var pointA = new BMap.Point(longitude,latitude); var pointB = new BMap.Point(data.merchant.longitude,data.merchant.latitude); var distance = parseInt(map.getDistance(pointA,pointB)); $(".distance").html(getDistance(distance)); } }, error:function(XMLHttpRequest, textStatus, errorThrown) { layer.msg('坐标转换失败'); } }); } }); }); }else{ layer.open({content: json.msg,time: 3}); } }); } function initSlider(arr){ $("#slider .mui-slider-group").append('
'+ ''+ ''+ ''+ '
'); if(arr.length>1){//数量大于1定时滚动 for(var i=0;i'+ ''+ ''+ ''+ ''); if(i==0){ $("#slider .mui-slider-indicator").append('
'); }else{ $("#slider .mui-slider-indicator").append('
'); } } }else{//数量等于1 $("#slider .mui-slider-group").append('
'+ ''+ ''+ ''+ '
'); } $("#slider .mui-slider-group").append('
'+ ''+ ''+ ''+ '
'); if(arr.length>1){ var slider = mui("#slider"); slider.slider({ interval: 3000 }); } $("img.slider-lazy").lazyload({ threshold : 200, placeholder: base+'/static/mobile/image/500.gif', skip_invisible : false }); } //获取评价 function getUserMsg(){ $('.userMsg-content').dropload({ scrollArea : window, loadDownFn : function(me){ mobile.ajaxPost(base+'/userOrder/getUserMsgList',{ productId: id, pageSize: pageSize, pageNumber: pageNumber },function(json){ if(json.list&&json.list.length>0){ if(pageNumber==json.totalPage){ me.lock(); me.noData(); }else{ pageNumber++; } var html=[]; jQuery.each(json.list,function(id,item){ html.push('
  • '); html.push('
    '); html.push('
    '+getName(item.nickname)+'
    '); html.push('
    '+item.user_msg+'
    '); html.push('
    '+new Date(item.create_time.replace(/-/g, "/")).format("MM-dd hh:mm")+'
    '); html.push('
    '); html.push('
  • '); }) $("#userMsg").append(html.join("")); me.resetload(); }else{ me.lock(); me.noData(); me.resetload(); } },""); } }); } function checkTime(i){ // 将0-9的数字前面加上0,例1变为01 if(i<10) { i = "0" + i; } return i; } function getName(name){ if(name){ if(name.length==1){ return "*"; }else if(name.length==2){ return name.substring(0,1)+"*"; }else{ return name.substring(0,1)+"*"+name.substring(name.length-1); } }else{ return "*"; } } function getBase64Image(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, img.width, img.height); var dataURL = canvas.toDataURL("image/png"); return dataURL } function getHot() { mobile.ajaxPost(base+'/product/getHot',{id:id},function(json){ if(json.data&&json.data.length>0){ var html=[]; jQuery.each(json.data,function(id,item){ html.push(''); html.push('
    '); html.push(''); html.push('
    '); html.push('
    '); html.push('
    '+item.product_name+'
    '); html.push('
    '); html.push('
    ¥'+item.product_price+''+item.product_old_price+'元
    ') html.push('
    关注:'+item.visit_num+'
    ') html.push('
    '); html.push('
    '); }); $(".section-list").append(html.join("")); $("img.product-lazy").lazyload({ threshold : 200, effect: "fadeIn", placeholder: base+'/static/mobile/image/100.gif', skip_invisible : false }); }else{ } }); }