Commit 577234db25b4445d5de9f552f414efc08b2faeae

Authored by wangfan
1 parent dcb27e51

地图优化

@@ -4,7 +4,7 @@ import util from '../../utils/util'; @@ -4,7 +4,7 @@ import util from '../../utils/util';
4 import App from '../../utils/api'; 4 import App from '../../utils/api';
5 import DA from './data'; 5 import DA from './data';
6 const {regeneratorRuntime} = global 6 const {regeneratorRuntime} = global
7 -const mapScale=18; 7 +const mapScale=16//18;
8 const transverseViewHeight=172; 8 const transverseViewHeight=172;
9 const renNum=function(){ 9 const renNum=function(){
10 let arr=[] 10 let arr=[]
@@ -40,6 +40,7 @@ Page({ @@ -40,6 +40,7 @@ Page({
40 //qqmapsdk:null, 40 //qqmapsdk:null,
41 sellers: [], 41 sellers: [],
42 sellersIds:[], 42 sellersIds:[],
  43 + sellersNow:[],//本次视图内商户
43 searchAddrTop:50, 44 searchAddrTop:50,
44 user:{ 45 user:{
45 latitude: 23.099994, 46 latitude: 23.099994,
@@ -253,11 +254,12 @@ Page({ @@ -253,11 +254,12 @@ Page({
253 }, 254 },
254 }) 255 })
255 }, 256 },
  257 + hasMarkertap:false,
256 markertap(e,flag=true){ 258 markertap(e,flag=true){
  259 + this.hasMarkertap=false
257 let markers=this.data.markers; 260 let markers=this.data.markers;
258 - console.log(e) 261 + console.log('markertap',e)
259 let bl=1.2; 262 let bl=1.2;
260 - let current=0;  
261 markers.forEach((m,i)=>{ 263 markers.forEach((m,i)=>{
262 m.iconPath=m.iconPath.replace('/cates-active/','/cates/') 264 m.iconPath=m.iconPath.replace('/cates-active/','/cates/')
263 m.zIndex=m.zIndexBak 265 m.zIndex=m.zIndexBak
@@ -274,7 +276,6 @@ Page({ @@ -274,7 +276,6 @@ Page({
274 m.callout.bgColor= '#626262'; 276 m.callout.bgColor= '#626262';
275 } 277 }
276 if(m.id==e.markerId){ 278 if(m.id==e.markerId){
277 - current=i;  
278 m.iconPath=m.iconPath.replace('/cates/','/cates-active/') 279 m.iconPath=m.iconPath.replace('/cates/','/cates-active/')
279 if(m.width==20){ 280 if(m.width==20){
280 m.width=20*bl; 281 m.width=20*bl;
@@ -294,8 +295,17 @@ Page({ @@ -294,8 +295,17 @@ Page({
294 markers:markers, 295 markers:markers,
295 }; 296 };
296 if(flag){ 297 if(flag){
  298 + let current=0;
297 //obj.scrollIntoView='seller-'+e.markerId; 299 //obj.scrollIntoView='seller-'+e.markerId;
298 - obj.current=current 300 + this.sellers.forEach(se=>{
  301 + if(se.id==e.markerId){
  302 + obj.current=current;
  303 + return true;
  304 + }else if(se.display!='none'){
  305 + current++;
  306 + }
  307 + })
  308 + this.hasMarkertap=true;
299 } 309 }
300 this.setData(obj) 310 this.setData(obj)
301 }, 311 },
@@ -336,7 +346,7 @@ Page({ @@ -336,7 +346,7 @@ Page({
336 },300) 346 },300)
337 } 347 }
338 let markers = []; 348 let markers = [];
339 - let sellers=[]; 349 + let sellers=this.data.sellers;
340 let param={ 350 let param={
341 lat: this.user.latitude, 351 lat: this.user.latitude,
342 lng: this.user.longitude, 352 lng: this.user.longitude,
@@ -351,79 +361,88 @@ Page({ @@ -351,79 +361,88 @@ Page({
351 if(this.data.multiIndex[1]>0){ 361 if(this.data.multiIndex[1]>0){
352 param.cuisine=await DA.getCatesID(this.data.multiIndex[1]-1); 362 param.cuisine=await DA.getCatesID(this.data.multiIndex[1]-1);
353 } 363 }
  364 + let now_sid=[];
354 App.Customer.SellerList(param).then(res => { 365 App.Customer.SellerList(param).then(res => {
355 this.mapData.region.southwest.latitude=''; 366 this.mapData.region.southwest.latitude='';
356 if (res.ret == 200) { 367 if (res.ret == 200) {
357 - // let sellersIds=["scale"+this.mapData.scale];  
358 - // res.data.forEach(seller=>{  
359 - // sellersIds.push(seller.id);  
360 - // })  
361 - // if(sellersIds.toString()==this.sellersIds.toString()) {  
362 - // return;  
363 - // }  
364 - // this.sellersIds=sellersIds;  
365 - sellers=res.data;  
366 - let sellersLength=sellers.length;  
367 - sellers.forEach((seller,si) => {  
368 - seller.distance=parseInt(seller.distance);  
369 - if(seller.distance>1000){  
370 - seller.distance=(seller.distance/1000).toFixed(2)+'公里'  
371 - }else{  
372 - seller.distance+='米'; 368 + let sellersList=res.data;
  369 + let sellersLength=sellersList.length;
  370 + sellersList.forEach((seller,si) => {
  371 + now_sid.push(seller.id);
  372 + let hasMark=false;
  373 + if(this.sellersIds._indexOf(seller.id)<0){
  374 + seller.distance=parseInt(seller.distance);
  375 + if(seller.distance>1000){
  376 + seller.distance=(seller.distance/1000).toFixed(2)+'公里'
  377 + }else{
  378 + seller.distance+='米';
  379 + }
  380 + this.sellersIds.push(seller.id);
  381 + hasMark=true;
  382 + sellers.push(seller);
373 } 383 }
374 -  
375 - let namelength = seller.sellername.replace(/[^\x00-\xff]/g, "01").length + 8;  
376 - let marker={  
377 - id: seller.id,  
378 - iconPath: "http://qn.colorcun.com/custom/lite-online/cates/circle1x5.png"+cates_version,  
379 - latitude: seller.lat,  
380 - longitude: seller.long,  
381 - width: 8,  
382 - height: 8,  
383 - //title:seller.seller_name,  
384 - zIndex:sellersLength-si,  
385 - zIndexBak:sellersLength-si,  
386 - };  
387 - if(seller.mode.length>0){  
388 - seller.mode.forEach(x=>{  
389 - if(x.id==1){//大图标  
390 - marker.iconPath="http://qn.colorcun.com/custom/lite-online/cates/其他菜品.png";  
391 - if(seller.cate.length>0){  
392 - marker.iconPath=seller.cate[0].icon 384 + if(hasMark){
  385 + let marker={
  386 + id: seller.id,
  387 + iconPath: "http://qn.colorcun.com/custom/lite-online/cates/circle1x5.png"+cates_version,
  388 + latitude: seller.lat,
  389 + longitude: seller.long,
  390 + width: 8,
  391 + height: 8,
  392 + //title:seller.seller_name,
  393 + zIndex:sellersLength-si,
  394 + zIndexBak:sellersLength-si,
  395 + };
  396 + if(seller.mode.length>0){
  397 + seller.mode.forEach(x=>{
  398 + if(x.id==1){//大图标
  399 + marker.iconPath="http://qn.colorcun.com/custom/lite-online/cates/其他菜品.png";
  400 + if(seller.cate.length>0){
  401 + marker.iconPath=seller.cate[0].icon
  402 + }
  403 + marker.iconPath=marker.iconPath.replace(/\/cates\/(.*)\.png/,function ($0,$1) {
  404 + return '/cates/'+encodeURI($1)+'.png'
  405 + })
  406 + marker.iconPath+=cates_version
  407 + marker.width=20;
  408 + marker.height=25;
  409 + }
  410 + if(x.id==2){//商家名
  411 + marker.callout={
  412 + content: ' ' + seller.sellername + ' ',
  413 + color: '#fefefe',
  414 + fontSize: 12,
  415 + borderWidth: 0,
  416 + borderColor: '#626262',
  417 + borderRadius: 50,
  418 + bgColor: '#626262',
  419 + padding: 5,
  420 + textAlign: 'left',
  421 + display:'ALWAYS',
  422 + };
393 } 423 }
394 - marker.iconPath=marker.iconPath.replace(/\/cates\/(.*)\.png/,function ($0,$1) {  
395 - return '/cates/'+encodeURI($1)+'.png'  
396 - })  
397 - marker.iconPath+=cates_version  
398 - marker.width=20;  
399 - marker.height=25;  
400 - }  
401 - if(x.id==2){//商家名  
402 - marker.callout={  
403 - content: ' ' + seller.sellername + ' ',  
404 - color: '#fefefe',  
405 - fontSize: 12,  
406 - borderWidth: 0,  
407 - borderColor: '#626262',  
408 - borderRadius: 50,  
409 - bgColor: '#626262',  
410 - padding: 5,  
411 - textAlign: 'left',  
412 - display:'ALWAYS',  
413 - };  
414 - }  
415 - }) 424 + })
  425 + }
  426 + markers.push(marker)
416 } 427 }
417 - markers.push(marker)  
418 }) 428 })
419 } else { 429 } else {
420 console.log('接口报错了'); 430 console.log('接口报错了');
421 } 431 }
  432 + this.sellersNow=now_sid;
  433 + sellers.forEach(se=>{
  434 + se.display='none'
  435 + if(now_sid._indexOf(se.id)>-1){
  436 + se.display='';
  437 + }
  438 + })
422 this.sellers = sellers; 439 this.sellers = sellers;
423 let obj={ 440 let obj={
424 - markers: markers,  
425 sellers:sellers, 441 sellers:sellers,
426 } 442 }
  443 + if(markers.length>0){
  444 + obj.markers=this.data.markers.concat(markers);
  445 + }
427 if(sellers.length<this.data.current){ 446 if(sellers.length<this.data.current){
428 obj.current=0 447 obj.current=0
429 } 448 }
@@ -489,11 +508,15 @@ Page({ @@ -489,11 +508,15 @@ Page({
489 },300) 508 },300)
490 }, 509 },
491 bindtransition(e){ 510 bindtransition(e){
492 - console.log(e.detail.current); 511 + console.log('bindtransition',this.sellersNow,e.detail.current,this.sellersNow[e.detail.current]);
  512 + if(this.hasMarkertap){
  513 + this.hasMarkertap=false;
  514 + return;
  515 + }
493 let i=e.detail.current 516 let i=e.detail.current
494 - this.activeSellerID=this.sellers[i]; 517 + this.activeSellerID=this.sellersNow[i];
495 this.markertap({ 518 this.markertap({
496 - markerId:this.sellers[i].id 519 + markerId:this.activeSellerID
497 },false) 520 },false)
498 }, 521 },
499 gotoDetail(e){ 522 gotoDetail(e){
@@ -51,7 +51,7 @@ @@ -51,7 +51,7 @@
51 previous-margin="{{20}}px" next-margin="{{20}}px" 51 previous-margin="{{20}}px" next-margin="{{20}}px"
52 current="{{current}}" bindchange="bindtransition"> 52 current="{{current}}" bindchange="bindtransition">
53 <block wx:for="{{sellers}}" wx:key="sellers.key"> 53 <block wx:for="{{sellers}}" wx:key="sellers.key">
54 - <swiper-item bindtap="gotoDetail" data-sid="{{item.id}}"> 54 + <swiper-item bindtap="gotoDetail" data-sid="{{item.id}}" wx:if="{{item.display!='none'}}">
55 <view class="seller" id="seller-{{item.id}}"> 55 <view class="seller" id="seller-{{item.id}}">
56 <sb-tr seller="{{item}}" hasActivity="{{true}}"></sb-tr> 56 <sb-tr seller="{{item}}" hasActivity="{{true}}"></sb-tr>
57 </view> 57 </view>