merchantList.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. mui.init();
  2. mui('.mui-scroll-wrapper').scroll();
  3. var pageNumber = 1;
  4. var pageSize=10;
  5. var sort="";
  6. var category="";
  7. var map;
  8. var pointA;
  9. /**
  10. *初始化、添加监听
  11. */
  12. mui.ready(function(){
  13. wx.ready(function(){
  14. var l = layer.open({type: 3,shadeClose:false,content: '定位中...'});
  15. wx.getLocation({
  16. type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  17. success: function (res) {
  18. $.ajax({
  19. url:'http://api.map.baidu.com/geoconv/v1/?coords='+res.longitude+','+res.latitude+'&from=1&to=5&ak=3Q4laSROftZI4chFMPVUno90',
  20. dataType:'jsonp',
  21. processData: false,
  22. type:'get',
  23. success:function(json){
  24. layer.close(l);
  25. if (json.status=='0'){
  26. var latitude=json.result[0].y;
  27. var longitude=json.result[0].x;
  28. map = new BMap.Map("allmap");
  29. pointA = new BMap.Point(longitude,latitude);
  30. }
  31. getMerchant();
  32. },
  33. error:function(XMLHttpRequest, textStatus, errorThrown) {
  34. layer.close(l);
  35. getMerchant();
  36. layer.msg('坐标转换失败');
  37. }
  38. });
  39. },
  40. cancel:function(json){
  41. layer.close(l);
  42. getMerchant();
  43. }
  44. });
  45. });
  46. getCategory();
  47. $('.mui-bar-tab').on('tap', 'a', function(e) {
  48. location.href=$(this).attr("href");
  49. });
  50. $("#tab1").on("tap",function(){
  51. if($(this).hasClass("active")){
  52. $(this).removeClass("active");
  53. }else{
  54. $(this).addClass("active");
  55. $(this).siblings().removeClass("active");
  56. }
  57. mui('#topPopover').popover('toggle');
  58. });
  59. $("#tab2").on("tap",function(){
  60. if($(this).hasClass("active")){
  61. $(this).removeClass("active");
  62. }else{
  63. $(this).addClass("active");
  64. $(this).siblings().removeClass("active");
  65. }
  66. mui('#middlePopover').popover('toggle');
  67. });
  68. $("#tab3").on("tap",function(){
  69. if($(this).hasClass("active")){
  70. $(this).removeClass("active");
  71. }else{
  72. $(this).addClass("active");
  73. $(this).siblings().removeClass("active");
  74. }
  75. mui('#bottomPopover').popover('toggle');
  76. });
  77. $("body").on("tap",".mui-backdrop",function(e){
  78. e.stopPropagation();
  79. $(".mui-table-cell").removeClass("active");
  80. });
  81. $("#topPopover").on("tap","li",function(){
  82. if($(this).attr("data")=="10"&&!pointA){
  83. layer.open({content:'定位失败,无法按距离排序',time:3});
  84. return;
  85. }
  86. $("#tab1 span:eq(0)").html($(this).find("a").html());
  87. mui('#topPopover').popover('toggle');
  88. $('#tab1').removeClass("active");
  89. sort=$(this).attr("data");
  90. pageNumber=1;
  91. $("#merchantList").empty();
  92. $(".dropload-down").remove();
  93. getMerchant();
  94. });
  95. $("#middlePopover").on("tap","li",function(){
  96. $("#tab2 span:eq(0)").html($(this).find("a").html());
  97. mui('#middlePopover').popover('toggle');
  98. $('#tab2').removeClass("active");
  99. category=$(this).attr("data");
  100. pageNumber=1;
  101. $("#merchantList").empty();
  102. $(".dropload-down").remove();
  103. getMerchant();
  104. });
  105. $("#bottomPopover").on("tap","li",function(){
  106. $("#tab3 span:eq(0)").html($(this).find("a").html());
  107. mui('#bottomPopover').popover('toggle');
  108. $('#tab3').removeClass("active");
  109. });
  110. $("#merchantList").on("tap","ul",function(){
  111. location.href=base+'/mobile/merchantDetail.jsp?id='+$(this).attr("data-id");
  112. });
  113. });
  114. function getCategory(){
  115. mobile.ajaxPost(base+'/productCategory/getList',{},function(json){
  116. $.each(json.data,function(id,item){
  117. $("#middlePopover ul").append('<li class="mui-table-view-cell" data="'+item.id+'">'+
  118. '<a href="javascript:void(0)">'+item.cat_name+'</a></li>');
  119. });
  120. });
  121. }
  122. function getMerchant(){
  123. $('.merchant-content').dropload({
  124. scrollArea : window,
  125. loadDownFn : function(me){
  126. mobile.ajaxPost(base+'/merchant/getList',{
  127. longitude: pointA.lng,
  128. latitude: pointA.lat,
  129. sort: sort,
  130. category: category,
  131. pageSize: pageSize,
  132. pageNumber: pageNumber
  133. },function(json){
  134. if(json.list&&json.list.length>0){
  135. if(pageNumber==json.totalPage){
  136. me.lock();
  137. me.noData();
  138. }else{
  139. pageNumber++;
  140. }
  141. var html=[];
  142. jQuery.each(json.list,function(id,item){
  143. html.push('<ul class="mui-table-view mt10 product fs14 line-left" data-id="'+item.id+'">');
  144. html.push('<li class="mui-table-view-cell mui-media">');
  145. html.push('<img class="mui-media-object mui-pull-left product-lazy" data-original="'+imgUrl+item.merchant_img1+'">');
  146. html.push('<div class="items items-top fs16" style="height: 0.7rem">');
  147. html.push('<span class="item pr15 mui-ellipsis-2 fs14">'+item.merchant_name+'</span>');
  148. if(pointA){
  149. var pointB = new BMap.Point(item.longitude,item.latitude);
  150. var distance = parseInt(map.getDistance(pointA,pointB));
  151. html.push('<span class="color2 distance fs14">'+getDistance(distance)+'</span>');
  152. }
  153. html.push('</div>');
  154. html.push('<p class="mt10 main-color"><span class="mui-icon iconfont icon-huo pr5 fs16"></span>');
  155. html.push(''+item.visit_num+'人关注</p></li>');
  156. if(item.product_name){
  157. html.push('<li class="mui-table-view-cell mui-media" style="padding: 0.15rem 0.3rem;"><div class="mui-ellipsis fs13">');
  158. html.push('<span class="mui-icon iconfont icon-qiang main-color fs16 pr5"></span>'+item.product_name+'</div></li>');
  159. }
  160. html.push('</ul>');
  161. });
  162. $("#merchantList").append(html.join(""));
  163. me.resetload();
  164. $("img.product-lazy").lazyload({
  165. threshold : 200,
  166. effect: "fadeIn",
  167. placeholder: base+'/static/mobile/image/500.gif',
  168. skip_invisible : false
  169. });
  170. }else{
  171. me.lock();
  172. me.noData();
  173. me.resetload();
  174. }
  175. });
  176. }
  177. });
  178. }
  179. function getDistance(distance){
  180. var i= parseInt(distance);
  181. if(i<1000){
  182. return i+"米";
  183. }else{
  184. var f = parseFloat(i/1000);
  185. if (isNaN(f)) {
  186. return;
  187. }
  188. f = Math.round(i/1000 * 10) / 10;
  189. return f+"公里";
  190. }
  191. }