123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- mui.init();
- mui('.mui-scroll-wrapper').scroll();
- var pageNumber = 1;
- var pageSize=10;
- var sort="";
- var category="";
- var map;
- var pointA;
- /**
- *初始化、添加监听
- */
- mui.ready(function(){
- wx.ready(function(){
- var l = layer.open({type: 3,shadeClose:false,content: '定位中...'});
- 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){
- layer.close(l);
- if (json.status=='0'){
- var latitude=json.result[0].y;
- var longitude=json.result[0].x;
- map = new BMap.Map("allmap");
- pointA = new BMap.Point(longitude,latitude);
- }
- getMerchant();
- },
- error:function(XMLHttpRequest, textStatus, errorThrown) {
- layer.close(l);
- getMerchant();
- layer.msg('坐标转换失败');
- }
- });
- },
- cancel:function(json){
- layer.close(l);
- getMerchant();
- }
- });
- });
- getCategory();
- $('.mui-bar-tab').on('tap', 'a', function(e) {
- location.href=$(this).attr("href");
- });
- $("#tab1").on("tap",function(){
- if($(this).hasClass("active")){
- $(this).removeClass("active");
- }else{
- $(this).addClass("active");
- $(this).siblings().removeClass("active");
- }
- mui('#topPopover').popover('toggle');
- });
- $("#tab2").on("tap",function(){
- if($(this).hasClass("active")){
- $(this).removeClass("active");
- }else{
- $(this).addClass("active");
- $(this).siblings().removeClass("active");
- }
- mui('#middlePopover').popover('toggle');
- });
- $("#tab3").on("tap",function(){
- if($(this).hasClass("active")){
- $(this).removeClass("active");
- }else{
- $(this).addClass("active");
- $(this).siblings().removeClass("active");
- }
- mui('#bottomPopover').popover('toggle');
- });
-
- $("body").on("tap",".mui-backdrop",function(e){
- e.stopPropagation();
- $(".mui-table-cell").removeClass("active");
- });
-
- $("#topPopover").on("tap","li",function(){
- if($(this).attr("data")=="10"&&!pointA){
- layer.open({content:'定位失败,无法按距离排序',time:3});
- return;
- }
- $("#tab1 span:eq(0)").html($(this).find("a").html());
- mui('#topPopover').popover('toggle');
- $('#tab1').removeClass("active");
- sort=$(this).attr("data");
- pageNumber=1;
- $("#merchantList").empty();
- $(".dropload-down").remove();
- getMerchant();
- });
- $("#middlePopover").on("tap","li",function(){
- $("#tab2 span:eq(0)").html($(this).find("a").html());
- mui('#middlePopover').popover('toggle');
- $('#tab2').removeClass("active");
- category=$(this).attr("data");
- pageNumber=1;
- $("#merchantList").empty();
- $(".dropload-down").remove();
- getMerchant();
- });
- $("#bottomPopover").on("tap","li",function(){
- $("#tab3 span:eq(0)").html($(this).find("a").html());
- mui('#bottomPopover').popover('toggle');
- $('#tab3').removeClass("active");
- });
-
- $("#merchantList").on("tap","ul",function(){
- location.href=base+'/mobile/merchantDetail.jsp?id='+$(this).attr("data-id");
- });
- });
- function getCategory(){
- mobile.ajaxPost(base+'/productCategory/getList',{},function(json){
- $.each(json.data,function(id,item){
- $("#middlePopover ul").append('<li class="mui-table-view-cell" data="'+item.id+'">'+
- '<a href="javascript:void(0)">'+item.cat_name+'</a></li>');
- });
- });
- }
- function getMerchant(){
- $('.merchant-content').dropload({
- scrollArea : window,
- loadDownFn : function(me){
- mobile.ajaxPost(base+'/merchant/getList',{
- longitude: pointA.lng,
- latitude: pointA.lat,
- sort: sort,
- category: category,
- 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('<ul class="mui-table-view mt10 product fs14 line-left" data-id="'+item.id+'">');
- html.push('<li class="mui-table-view-cell mui-media">');
- html.push('<img class="mui-media-object mui-pull-left product-lazy" data-original="'+imgUrl+item.merchant_img1+'">');
- html.push('<div class="items items-top fs16" style="height: 0.7rem">');
- html.push('<span class="item pr15 mui-ellipsis-2 fs14">'+item.merchant_name+'</span>');
- if(pointA){
- var pointB = new BMap.Point(item.longitude,item.latitude);
- var distance = parseInt(map.getDistance(pointA,pointB));
- html.push('<span class="color2 distance fs14">'+getDistance(distance)+'</span>');
- }
- html.push('</div>');
- html.push('<p class="mt10 main-color"><span class="mui-icon iconfont icon-huo pr5 fs16"></span>');
- html.push(''+item.visit_num+'人关注</p></li>');
- if(item.product_name){
- html.push('<li class="mui-table-view-cell mui-media" style="padding: 0.15rem 0.3rem;"><div class="mui-ellipsis fs13">');
- html.push('<span class="mui-icon iconfont icon-qiang main-color fs16 pr5"></span>'+item.product_name+'</div></li>');
- }
- html.push('</ul>');
- });
- $("#merchantList").append(html.join(""));
- me.resetload();
- $("img.product-lazy").lazyload({
- threshold : 200,
- effect: "fadeIn",
- placeholder: base+'/static/mobile/image/500.gif',
- skip_invisible : false
- });
- }else{
- me.lock();
- me.noData();
- me.resetload();
- }
- });
- }
- });
- }
- 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+"公里";
- }
- }
|