$(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 merchant; mui.init(); /** *初始化、添加监听 */ mui.ready(function(){ getMerchant(); $(".productList").on("tap", "li", function(){ if ($(this).attr("product_type")=="10"){ location.href=base+"/mobile/productDetail.jsp?id="+$(this).attr("data-id"); }else if ($(this).attr("product_type")=="20"){ location.href=base+"/mobile/cutProductDetail.jsp?id="+$(this).attr("data-id"); } }); $(".icon-dianhua").on("tap",function(){ location.href = 'tel:'+merchant.mobile; }); $(".address").on("tap",function(){ var locations=bd09togcj02(merchant.longitude,merchant.latitude); wx.ready(function(){ wx.openLocation({ latitude: locations[1], // 纬度,浮点数,范围为90 ~ -90 longitude: locations[0], // 经度,浮点数,范围为180 ~ -180。 name: merchant.merchant_name, // 位置名 address: merchant.address, // 地址详情说明 scale: 28, // 地图缩放级别,整形值,范围从1~28。默认为最大 infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转 }); }); }); }); //获取商品信息 function getMerchant(){ mobile.ajaxPost(base+"/merchant/getMerchant",{id:id},function(json){ merchant = json.data; console.info(json); share.title=merchant.merchant_name; //share.link=location.href; share.imgUrl=imgUrl+merchant.merchant_img1; $("title").html(merchant.merchant_name); $(".visit_num").html(merchant.visit_num); $(".merchant_name").html(merchant.merchant_name); $(".open_time").html("营业时间:"+merchant.start_hour+"-"+merchant.end_hour); $(".address").html(''+ merchant.address); if(merchant.has_wifi=="1"){ $(".has_wifi").removeClass("mui-hidden"); } if(merchant.has_park=="1"){ $(".has_park").removeClass("mui-hidden"); } if(merchant.has_ac=="1"){ $(".has_ac").removeClass("mui-hidden"); } if(merchant.has_box=="1"){ $(".has_box").removeClass("mui-hidden"); } if(merchant.has_wifi=="0"&&merchant.has_park=="0"&&merchant.has_ac=="0"&&merchant.has_box=="0"){ $(".has_wifi").parents("ul").remove(); } var arr = []; if(merchant.merchant_img1){ arr.push(merchant.merchant_img1); } if(merchant.merchant_img2){ arr.push(merchant.merchant_img2); } if(merchant.merchant_img3){ arr.push(merchant.merchant_img3); } if(merchant.product&&merchant.product.length>0){ var html=[]; jQuery.each(merchant.product,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{ $(".productList").remove(); } if (merchant.cut&&merchant.cut.length>0){ var html = []; $.each(merchant.cut,function (id,item) { html.push('
'); html.push(''); html.push(''); html.push('

'+item.product_name+'

'); html.push('
'); html.push('
'); html.push('¥'+item.product_price+''); html.push(''+item.product_old_price+'元'); html.push('
'); html.push('
'); html.push('关注:'+item.visit_num+' '); html.push('立即参与'); html.push('
'); html.push('
'); html.push('
'); html.push('
'); }); $("#cut .swiper-wrapper").html(html.join("")); swiper(); }else{ $("#cut").hide(); } initSlider(arr); if(merchant.merchant_detail){ $("#detail").html(merchant.merchant_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'); }); } 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 getCollect(){ mobile.ajaxPost(base+"/userCollect/getById",{productId:id},function(json){ if(json.data){ data.collect="1"; $("#collect .mui-icon").removeClass('mui-icon-star'); $("#collect .mui-icon").addClass('mui-icon-star-filled price-color'); $("#collect .mui-tab-label").html('已收藏'); } },""); } //获取评价 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 swiper() { if ($("#cut .swiper-slide").length>1){ var mySwiper2 = new Swiper ('#cut-swiper', { loop: true, autoplay: 3000,//可选选项,自动滑动 // 如果需要分页器 pagination: '#cut-pagination', paginationType : 'fraction', autoplayDisableOnInteraction : false }); } }