index.js 27.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
// pages/reservr/index.js
var mta = require('mta-wechat-analysis')
import util from '../../utils/util';
import App from '../../utils/api';
import DA from './data';
import reddot from '../../utils/reddot';
import PubSub from '../../utils/PubSub'
const {regeneratorRuntime} = global
const mapScale=15//18;
const barHeight=50;
const transverseViewHeight=253+barHeight;

const renNum=function(){
  let arr=[]
  for(let i=1;i<=30;i++){
    arr.push(i+'位')
  }
  return arr;
}
const cates_version='?1.2';
const hasSellerConcat=false;//变量存储所有商户
const def_latitude=39.684670;
const def_longitude=118.176300;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    map: {
      latitude: def_latitude+0.0001,
      longitude: def_longitude+0.0001,
      scale: mapScale,
      height: 300,
    },
    markers: [],
    //polygons:{},
    //sellers:[],
    multiArray: ['全部菜系'],
    multiIndex: [0],
    //scrollIntoView:'',
    suggestion:{},
    hasSuggestion:false,//搜索返回
    current:0,
    hasSellers:false,
    hasGetSellersEnd:false,
    hasSetActivity:false,
    tags:[
      {id:1,name:'环境好'},
      {id:2,name:'菜品有特色'},
      {id:3,name:'超大包间'},
    ],
    listMoreCount:0,
    hasSearchLimit:false,
    hasGetPos:false,
  },
  hasClickMoveToLocation:false,//点击回到我的位置
  hasSellerConcat:hasSellerConcat,
  transverseViewHeight:transverseViewHeight,//横向滚动高度,苹果要比安卓多20
  //qqmapsdk:null,
  sellers: [],
  sellersIds:[],
  sellersNow:[],//本次视图内商户
  searchAddrTop:50,
  user:{
    latitude: def_latitude,
    longitude: def_longitude,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  hasOnLoad:false,
  hasGetLocation:false,//定位信息
  hasAppHide:false,//app切至后台
  param:{},
  onLoad: async function (options) {
    this.reportTime=new Date()

    this.hasOnLoad=true;
    // this.qqmapsdk=new QQMapWX({
    //     key: 'SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ'
    // });
    this.setData({
      multiArray:[['全部菜系'].concat(await DA.getCates())]
    })
    mta.Page.init({
      "appID": "500667280",
      "eventID": "500667287",
      "statPullDownFresh": true,
      "statShareApp": true,
      "statReachBottom": true,
      "lauchOpts": options, //渠道分析
    });
    PubSub.on(
      'searchParam',
      data=>{
        console.log('searchParam.msg',data)
        if(data.fun=='tagsChange'){
          this.tagsChange(data.e);
        }
        if(data.fun=='caixiActive'){
          this.caixiActive(data.e);
        }
        if(data.fun=='setSuggestion'){
          this.setSuggestion(data.suggestion);
        }
        if(data.fun=='moveToLocation'){
          this.moveToLocation();
        }
      }
    )
    PubSub.on(
        'appHide',
        data=>{
          console.log('appHide');
          let pages=getCurrentPages();
          if(pages.length==1){//用户停留在首页
            this.hasGetLocation=false
            this.hasClickMoveToLocation=false
            this.hasAppHide=true
          }
        }
    )
    reddot.init()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  mapCtx: null,
  mapData:{
    lat:'',
    lng:'',
    latitude: 0,
    longitude: 0,
    scale: 18,
    hasRegionchange:false,
    region:{
      southwest:{},
      northeast:{},
    },
  },
  mapDataLast:null,//最后一次成功视角,防止地图视角丢失
  onReady: function () {
    if (wx.canIUse('reportPerformance')) {
      wx.reportPerformance(2002, new Date()-this.reportTime)
    }
    this.mapCtx = wx.createMapContext('map')
    // this.mapCtx.moveToLocation({
    //   success:(res)=>{
    //     console.log('moveToLocation',res)
    //   }
    // })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function (e) {
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
    console.log({
      'this.hasGetLocation':this.hasGetLocation,
      'this.hasOnLoad':this.hasOnLoad,
      'this.hasClickMoveToLocation':this.hasClickMoveToLocation,
      'this.data.hasSuggestion':this.data.hasSuggestion,
    })
    this.getClassNameFlag=true;
    //this.getPos();
    if(this.data.hasSuggestion) return;
    if(!this.hasOnLoad && this.hasGetLocation) return;
    this.hasOnLoad=false;
    //导航栏自适应
    let systemInfo = wx.getSystemInfoSync();
    console.log('systemInfo:',systemInfo)
    let reg = /ios/i;
    let pt = 20;//导航状态栏上内边距
    let h = 44;//导航状态栏高度
    if(reg.test(systemInfo.system)){
      pt = systemInfo.statusBarHeight;
      h = 44;
      if(systemInfo.pixelRatio>2){
        this.transverseViewHeight=transverseViewHeight+26;
      }
    }else{
      if(/xiaomi/i.test(systemInfo.brand)){
        this.transverseViewHeight=transverseViewHeight+15;
      }else{
        this.transverseViewHeight=transverseViewHeight-15;
      }
      pt = systemInfo.statusBarHeight;
      h = 48;
    }
    console.log('onShow',systemInfo,systemInfo.windowHeight,systemInfo.windowHeight-this.transverseViewHeight)
    this.setData({
      [`map.height`]: systemInfo.windowHeight-this.transverseViewHeight,
      statusBarHeight: pt,
      titleBarHeight:h,
    })
    //this.getPos(systemInfo);
    this.systemInfo=systemInfo
    //this.selectComponent('#getpos').getPos();
    if(!this.hasClickMoveToLocation){
      //this.getMarkers();
      //this.timeoutGetMarkers();
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function (e) {
    util.elog(null,'离开地图页')
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    PubSub.off('searchParam')
    PubSub.off('appHide')
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return{
      title:'请客订包间,就上周到安排'
    }
  },
  onpos(e){
    console.log('onpos',e);
    let res=e.detail;
    if(!res.latitude) return this.timeoutGetMarkers();
    this.hasGetLocation=true;
    this.sellersIds=[]
    this.sellers=[]
    let map = this.data.map;
    map.latitude = res.latitude;
    map.longitude = res.longitude;
    map.scale=mapScale;
    this.user.latitude = res.latitude;
    this.user.longitude = res.longitude;
    map.height = this.systemInfo.windowHeight-this.transverseViewHeight
    let sdobj={
      map: map,
      hasSuggestion:false,
    }
    if(!this.hasSellerConcat){
      sdobj.markers=[]
    }
    this.setData(sdobj)
    this.timeoutGetMarkers()
    /*
    if(this.mapCtx){
      //this.mapCtx.moveToLocation();
      this.mapCtx.getRegion({
        success:(res)=>{
          console.log('onpos.getRegion',res)
          if(this.mapData.region.southwest.latitude) {
            this.mapData.region = res
            this.timeoutGetMarkers()
          }
        },
      })
    }
    */
  },
  regionchange(e){
    if(e.type!='end') return;
    console.log('regionchange', e)
    if(typeof this.mapCtx=='undefined' || !this.mapCtx) return;
    this.getClassNameFlag=true;
    this.mapCtx.getScale({
      success: (res) => {
        this.mapData.scale = res.scale;
        console.log('regionchange.getScale', res, this.data.map.scale)
      },
    })
    this.mapCtx.getCenterLocation({
      success:(res)=>{
        console.log('regionchange.getCenterLocation',res)
        this.mapData.latitude=res.latitude;
        this.mapData.longitude=res.longitude;
        if(this.mapData.lat=='' && res.latitude.toString().length>6 && res.longitude.toString().length>6){
          this.mapData.lat=res.latitude;
          this.mapData.lng=res.longitude;
        }
      },
    });
    this.mapCtx.getRegion({
      success:(res)=>{
        console.log('regionchange.getRegion',res.southwest.latitude,this.mapData.region.southwest.latitude,res)
        this.hasClickMoveToLocation=false
        if(res.southwest.latitude) {
          this.mapData.region = res
        };
        this.timeoutGetMarkers();
      },
    })
  },
  setTimeoutGetMarkers:'',
  timeoutGetMarkers(){//延时获取
    if(this.setTimeoutGetMarkers){
      clearTimeout(this.setTimeoutGetMarkers);
      this.setTimeoutGetMarkers='';
    }
    this.setTimeoutGetMarkers=setTimeout(()=>{
      this.getMarkers();
    },300)
  },
  mapUpdated(e){
    console.log('mapUpdated', e)
    if(typeof this.mapCtx=='undefined' || !this.mapCtx) return;
    this.getClassNameFlag=true;
    this.mapCtx.getScale({
      success:(res)=>{
        this.mapData.scale=res.scale;
        console.log('mapUpdated.getScale',res,this.data.map.scale)
      },
    })
    this.mapCtx.getCenterLocation({
      success:(res)=>{
        console.log('mapUpdated.getCenterLocation',res)
        this.mapData.latitude=res.latitude;
        this.mapData.longitude=res.longitude;
        if(this.mapData.lat=='' && res.latitude.toString().length>6 && res.longitude.toString().length>6){
          this.mapData.lat=res.latitude;
          this.mapData.lng=res.longitude;
        }
      },
    });
    this.mapCtx.getRegion({
      success:(res)=>{
        if(this.mapData.region.southwest.latitude=='' || !res.southwest.latitude) return;
        console.log('mapUpdated.getRegion',[res.southwest.latitude,this.mapData.region.southwest.latitude])
        this.mapData.region=res
        //this.timeoutGetMarkers();
      },
    })
    this.setData({
      hasBoost:true,
    })
  },
  hasMarkertap:false,
  markertap(e,flag=true){
    if(e.markerId=='location' || e.markerId=='locationMe')return;
    this.hasMarkertap=false
    let markers=this.data.markers;
    console.log('markertap',e)
    this.activeSellerID=e.markerId
    let bl=1.2;
    let current=0,hasCurrent=true;
    markers.forEach((m,i)=>{
      m.iconPath=m.iconPath.replace('/cates-active/','/cates/')
      m.zIndex=m.zIndexBak
      if(m.width==20*bl){
        m.width=20;
        m.height=25;
      }
      if(m.width==12){
        m.width=8;
        m.height=8;
      }
      if(m.callout){
        m.callout.borderColor= '#cccccc';
        m.callout.bgColor= '#fefefe';
        m.callout.color= '#353535';
        m.callout.display=m.calloutDisplay;
      }
      if(m.id==e.markerId){
        m.iconPath=m.iconPath.replace('/cates/','/cates-active/')
        if(m.width==20){
          m.width=20*bl;
          m.height=25*bl;
        }else{
          m.width=12;
          m.height=12;
        }
        m.zIndex=9999
        if(m.callout){
          m.callout.borderColor= '#F05522';
          m.callout.bgColor= '#F05522';
          m.callout.color= '#fefefe';
          m.callout.display='ALWAYS';
        }
        hasCurrent=false
        if("markertap"==e.type){
          util.elog({id:m.seller.id,sellername:m.seller.sellername},'点击地图区域的店铺标记')
        }

      }
      if(m.display!='none' && hasCurrent){
        current++
      }
    })
    let obj={
      markers:markers,
    };
    console.log('markertap::current,',current);
    if(flag){
      //obj.scrollIntoView='seller-'+e.markerId;
      obj.current=current;
      //this.hasMarkertap=true;
    }
    this.setData(obj)
  },
  hasInRegionFlag:false,
  hasInRegion(){//定位是否在地图视野内
    let map = this.mapData;
    if(!map.region.northeast.latitude || !map.region.northeast.longitude) {//未获得视野
      if(this.mapDataLast){
        this.mapData=this.mapDataLast
      }
      return {flag:false,msg:'未获得视野',map:map,mapDataLast:this.mapDataLast};
    }
    if(!map.region.southwest.latitude || !map.region.southwest.longitude) {//未获得视野
      if(this.mapDataLast){
        this.mapData=this.mapDataLast
      }
      return {flag:false,msg:'未获得视野',map:map,mapDataLast:this.mapDataLast};
    }
    this.mapDataLast=JSON.parse(JSON.stringify(this.mapData));
    if(this.hasInRegionFlag) return {flag:true,msg:'二次获取'};
    if(!this.user.latitude) return {flag:false,msg:'用户无定位'};//用户无定位
    //if(this.user.latitude==def_latitude && this.user.longitude==def_longitude) return false;//默认位置
    ///判断定位 首次 进入视野
    if((this.user.latitude>map.region.southwest.latitude
      && this.user.longitude>map.region.southwest.longitude
      && this.user.latitude<map.region.northeast.latitude
      && this.user.longitude<map.region.northeast.longitude) || this.data.hasSuggestion){
      this.hasInRegionFlag=true;
      return {flag:true,msg:'用户首次或搜索地标'};
    }else{
      //视野不匹配
      this.mapCtx.getRegion({
        success:(res)=>{
          console.log('hasInRegion.getRegion',res)
          this.mapData.region=res
        },
      })
    }
    return {flag:false,msg:'视野不匹配'};
  },
  async getMarkers(){
    let cmap=this.data.map;
    let map = this.mapData;
    //console.log('getMarkers',map.region);
    let region=this.hasInRegion();
    console.log('this.hasInRegion',region)
    if(!region.flag) {
      return setTimeout(()=>{
        this.getMarkers();
      },300)
    }
    let markers = [];
    let param={
      lat: this.user.latitude==def_latitude?'':this.user.latitude,
      lng: this.user.longitude==def_longitude?'':this.user.longitude,
      offset: 0,
      rows: 50,
      distance: 100000,
      map:JSON.stringify({...this.mapData.region,scale:this.mapData.scale>=19?20:this.mapData.scale})
    }
    if(this.data.multiIndex[0]>0){
      param.cuisine=await DA.getCatesID(this.data.multiIndex[0]-1);
    }
    let tags=[];
    this.data.tags.forEach(t=>{
      if(t.active){
        tags.push(t.id)
      }
    })
    if(tags.length>0){
      param.tags=tags;
    }
    if(param.lat){
      param.centre_pos=`${param.lat},${param.lng}`
    }else{
      let lat=(this.mapData.region.southwest.latitude+this.mapData.region.northeast.latitude)/2
      let lng=(this.mapData.region.southwest.longitude+this.mapData.region.northeast.longitude)/2
      param.centre_pos=`${lat},${lng}`
    }
    if(this.data.hasSuggestion){
      param.centre_pos=`${this.data.suggestion.latitude},${this.data.suggestion.longitude}`
    }
    if(this.findSellerData){
      param=Object.assign(param,this.findSellerData.paramObj)
    }
    if(this.filterParams){//人均过滤
      let filterParams=this.filterParams.min+','+this.filterParams.max
      if(this.filterParams.min==this.filterParams.max && this.filterParams.min==300){
        filterParams=this.filterParams.min+','+parseInt(new Date()/1000)
      }
      param.filterParams=filterParams
    }
    //this.selectComponent('#list').getList(param);
    this.param=param;
    let now_sid=[];
    App.Customer.SellerList(param).then(async res => {
      //this.mapData.region.southwest.latitude='';
      if (res.ret == 200) {
        let sellersList=res.data.list;
        let sellersLength=sellersList.length;
        sellersList.forEach((seller,si) => {
          now_sid.push(seller.id);
          let hasMark=false;
          if(this.sellersIds._indexOf(seller.id)<0){
            // if(seller.distance || seller.distance===0){
            //   seller.distance=parseInt(seller.distance);
            //   if(seller.distance>1000){
            //     seller.distance=(seller.distance/1000).toFixed(2)+'km'
            //   }else{
            //     seller.distance+='m';
            //   }
            // }
            if(this.hasSellerConcat){
              this.sellersIds.push(seller.id);
            }
            hasMark=true;
          }
          if(hasMark){
            if(this.findSellerData){
              seller.findSellerParamObj=this.findSellerData.paramObj
            }
            let marker={
              id: seller.id,
              iconPath: "http://nosqn.colorcun.com/custom/lite-online/cates/circle1x5.png"+cates_version,
              latitude: seller.lat,
              longitude: seller.long,
              width: 8,
              height: 8,
              //title:seller.seller_name,
              zIndex:sellersLength-si,
              zIndexBak:sellersLength-si,
              seller:seller,
            };
            marker.callout={
              content: ' ' + seller.sellername + ' ',
              color: '#353535',
              fontSize: 12,
              borderWidth: 1,
              borderColor: '#cccccc',
              borderRadius: 50,
              bgColor: '#fefefe',
              padding: 5,
              textAlign: 'left',
              display:'BYCLICK',
            };
            marker.calloutDisplay='BYCLICK';
            if(seller.mode.length>0){
              seller.mode.forEach(x=>{
                if(x.id==1){//大图标
                  marker.iconPath="http://nosqn.colorcun.com/custom/lite-online/cates/其他菜品.png";
                  if(seller.cate.length>0){
                    marker.iconPath=seller.cate[0].icon
                  }
                  marker.iconPath=marker.iconPath.replace(/\/cates\/(.*)\.png/,function ($0,$1) {
                    return '/cates/'+encodeURI($1)+'.png'
                  })
                  marker.iconPath+=cates_version
                  marker.width=20;
                  marker.height=25;
                }
                if(x.id==2){//商家名
                  marker.callout.display='ALWAYS';
                  marker.calloutDisplay='ALWAYS';
                }
              })
            }
            markers.push(marker)
          }
        })
      } else {
        console.log('接口报错了');
      }
      this.sellersNow=now_sid;
      let obj={
        hasSellers:now_sid.length>0,
        hasGetSellersEnd:true,
        hasSearchLimit:(tags.length>0 || this.data.multiIndex[0]>0) || this.findSellerData,
        listMoreCount:res.data.flag
      }
      if(this.hasSellerConcat){
        obj.markers=this.data.markers.concat(markers);
      }else{
        obj.markers=markers;
      }
      obj.markers.forEach(mk=>{
        //mk.display='none';
        if(now_sid._indexOf(mk.id)>-1){
          mk.display='';
        }
      })
      obj.markers=await this.setLocationMarker(obj.markers);
      this.setData(obj)
      if(now_sid.length>0) {
        setTimeout(() => {
          this.markertap({
            markerId: now_sid._indexOf(this.activeSellerID) < 0?now_sid[0]:this.activeSellerID
          }, true)
        }, 100)
      }
      this.IsSetActivity();
    })

  },
  //seller box 通知
  sellerBoxEvent(e){
    wx.showTabBar();
  },
  moveToLocation(){
    this.hasClickMoveToLocation=true
    if(this.user.latitude==def_latitude && this.user.longitude==def_longitude){
      this.selectComponent('#getpos').getPos(true);
      return;
    }
    this.sellersIds=[]
    this.sellers=[]
    let map = this.data.map;
    map.latitude = this.user.latitude;
    map.longitude = this.user.longitude;
    map.scale=mapScale;
    map.height = this.systemInfo.windowHeight-this.transverseViewHeight
    let sdobj={
      map: map,
      hasSuggestion:false,
      hasGetSellersEnd:false,
    }
    if(!this.hasSellerConcat){
      sdobj.markers=[]
    }
    this.setData(sdobj)
    this.mapCtx.moveToLocation({
      success:(res)=>{
        console.log('moveToLocation',res)
      }
    })
  },
  bindMultiPickerChange(e){
    console.log(e);
    let val=util.val(e);
    this.setData({
      multiIndex:val
    })
    this.hasSellerConcat=hasSellerConcat;
    this.sellersIds=[];
    if(val[0]>0){
      this.hasSellerConcat=false;
    }else{
      if(!this.hasSellerConcat){
        this.setData({
          markers:[]
        })
      }
    }
    setTimeout(()=>{this.getMarkers();},0)
  },
  setSuggestion(suggestion){
    let map=this.data.map;
    //let pos=DA.gcj02towgs84(suggestion.longitude,suggestion.latitude)
    map.latitude=suggestion.latitude
    map.longitude=suggestion.longitude
    if(suggestion.type==-1){//平台商户
      this.activeSellerID=suggestion.id
      map.scale=20
    }else{
      map.scale=mapScale
    }
    this.sellersIds=[]
    this.sellers=[]
    let sdobj={
      map: map,
      hasSuggestion:true,
      suggestion:suggestion,
      hasGetSellersEnd:false,
    }
    if(!this.hasSellerConcat){
      sdobj.markers=[]
    }
    //this.findSellerData=null//清理搜索
    this.setData(sdobj)
  },

  getClassNameFlag:true,
  activeSellerID:'',
  bindscroll(e){
    if(!this.getClassNameFlag) return;
    this.getClassNameFlag=false;
    let w=e.detail.scrollWidth/this.sellers.length;
    let i=Math.round(e.detail.scrollLeft/w);
    console.log(e.detail,this.sellers,i);
    if(this.activeSellerID!=this.sellers[i].id){
      this.activeSellerID=this.sellers[i];
      this.markertap({
        markerId:this.sellers[i].id
      },false)
    }
    let that=this;
    setTimeout(function(){
      that.getClassNameFlag=true;
    },300)
  },
  bindtransition(e){
   if(this.hasMarkertap){
      this.hasMarkertap=false;
      return;
    }
    let i=e.detail.current
    if(typeof this.data.markers[i]=='undefined') return;
    this.activeSellerID=this.data.markers[i].id
    console.log('bindtransition',this.sellersNow,e.detail.current,this.sellersNow[e.detail.current],this.activeSellerID);
    // this.activeSellerID=this.sellersNow[i];
    // this.markertap({
    //   markerId:this.activeSellerID
    // },false)
    this.markertap({
      markerId:this.activeSellerID
    },false)
  },
  gotoDetail(e){
    wx.navigateTo({
      url:'/pages/reserve/detail?id='+util.attr(e,'sid')
    })
    util.elog({sid:util.attr(e,'sid')},'点击橱窗中的商家,进入店铺详情')
  },
  IsSetActivity(){
    let cmap=this.data.map;
    App.Customer.IsSetActivity({lat:cmap.latitude,lng:cmap.longitude,distance:50}).then(res=>{
      this.setData({
        hasSetActivity:res.data==1,
      })
    })
  },
  a2lshow(e){
    //console.log('a2lshow',e)
    let ds=this.selectComponent('#ds');
    if(!ds){
      return setTimeout(()=>{
        this.a2lshow(e)
      },500)
    }
    ds.setA2LHeight(e.type=='hide'?0:40);
  },
  async setMapRegion(){
    return new Promise((success,fail)=>{
      if(this.mapCtx){
        this.mapCtx.getRegion({
          success:(res)=>{
            if(res.southwest.latitude) {
              this.mapData.region = res
              success()
            }
          },
          fail:()=>{
            fail()
          }
        })
      }else{
        fail()
      }
    })
  },
  async setLocationMarker(markers){
    try{
      await this.setMapRegion();
    }catch (e){
      this.timeoutGetMarkers()
      return []
    }

    let map = this.mapData;
    let mks=[]
    let matchPosNum=1
    if(markers.length>0){
      markers.forEach(mk=>{
        if(mk.id!='location' && mk.id!='locationMe'
          && mk.latitude>map.region.southwest.latitude
          && mk.longitude>map.region.southwest.longitude
          && mk.latitude<map.region.northeast.latitude
          && mk.longitude<map.region.northeast.longitude){
          mks.push(mk);
        }
      })
    }
    if(mks.length-markers.length<0){
      this.timeoutGetMarkers()
      return []
    }

    if(this.data.hasSuggestion){
      map=this.data.suggestion
      mks.push({
        id: 'location',
        iconPath: "http://nosqn.colorcun.com/reserve/images/location.png"+cates_version,
        latitude: map.latitude,
        longitude: map.longitude,
        width: 20,
        height: 25,
      })
    }
    mks.push({
      id: 'locationMe',
      iconPath: "http://nosqn.colorcun.com/reserve/images/lme.png"+cates_version,
      latitude: this.user.latitude,
      longitude: this.user.longitude,
      width: 18,
      height: 30,
    })
    return mks;
  },
  tagsChange(e){
    if(this.data.listMoreCount<1 && !this.data.hasSearchLimit) return
    let id=util.attr(e,'id');
    let tags=this.data.tags;
    let activeNum=0;
    tags.forEach(t=>{
      if(t.id==id){
        t.active=!t.active
      }
      if(t.active){
        activeNum++
      }
    })
    this.setData({
      tags:tags,
    })
    this.hasSellerConcat=hasSellerConcat;
    this.sellersIds=[];
    if(activeNum>0){
      this.hasSellerConcat=false;
    }else{
      if(!this.hasSellerConcat){
        this.setData({
          markers:[]
        })
      }
    }
    setTimeout(()=>{this.getMarkers();},0)

  },
  caixiActive(e){
    console.log('caixiActive',e);
    this.bindMultiPickerChange({
      detail:{
        value:[e.detail]
      }
    })
  },
  caixiShow(){
    if(this.data.listMoreCount<1 && !this.data.hasSearchLimit) return
    this.selectComponent('#caixi').show();
  },
  listEvent(e){
    let d=e.detail
    console.log('listEvent',e);
    if(d.type=="getListEnd"){
      this.setData({
        listMoreCount:d.total
      });
    }else if(d.type=='caixiShow'){
      this.caixiShow();
    }else if(d.type=='tagsChange'){
      this.tagsChange(d.e);
    }
  },
  listShow(){
    //this.selectComponent('#list').show();
    if(!this.param.map) return;
    this.movableChangeInit()
    wx.navigateTo({
      url:util.http_build_query({
        lat:this.param.lat==def_latitude?'':this.param.lat,
        lng:this.param.lng==def_longitude?'':this.param.lng,
        map:this.param.map,
        multiIndex:this.data.multiIndex,
        tags:this.param.tags,
        centre_pos:this.param.centre_pos,
        hasSuggestion:this.data.hasSuggestion?1:'',
        keyword:this.data.hasSuggestion?this.data.suggestion.title:'',
      },'./indexList'),
      success: res=> {
        // 通过eventChannel向被打开页面传送数据
        if(this.findSellerData){
          res.eventChannel.emit('acceptDataFromMapPage', this.findSellerData)
        }
        res.eventChannel.on('findSellerData',findSellerData=>{
          console.log('findSellerData',findSellerData)
          this.findSellerData=findSellerData
          setTimeout(()=>{this.getMarkers();},0)
        })
        setTimeout(()=>{
          this.movableChangeInit()
          this.hasListShow=false
        },1500)
      }
    });
  },
  setTSLocal(){
    let map=this.data.map;
    map.latitude=def_latitude
    map.longitude=def_longitude
    map.scale=mapScale
    this.sellersIds=[]
    this.sellers=[]
    let sdobj={
      map: map,
      hasGetSellersEnd:false,
      hasSuggestion:false,
      suggestion:{},
    }
    if(!this.hasSellerConcat){
      sdobj.markers=[]
    }
    this.setData(sdobj)
  },
  findSellerData:null,
  findSeller(){
    if(this.data.listMoreCount<1 && !this.data.hasSearchLimit) return
    wx.navigateTo({
      url: './findSeller',
      success: res=> {
        // 通过eventChannel向被打开页面传送数据
        if(this.findSellerData){
          res.eventChannel.emit('acceptDataFromMapPage', this.findSellerData)
        }
        res.eventChannel.on('findSellerData',findSellerData=>{
          console.log('findSellerData',findSellerData)
          this.findSellerData=findSellerData
          setTimeout(()=>{this.getMarkers();},0)
        })
      }
    })
  },
  boostEvent(e){
    util.elog(e.detail,'强提醒')
    if(e.detail.act=='hide'){
      this.setData({
        hasGetPos:true,
      })
      this.selectComponent('#getpos').getPos();
    }
  },
  elog(e){
    util.elog({attr:util.attr(e),detail:e.detail},util.attr(e,'ename')||'点击')
  },
  sbtrEvent(e){
    console.log(e);
    if(e.detail.act=='oncall'){
      this.selectComponent('#as').show(e.detail.seller);
    }
  },
  movableY0:99,
  movableY1:0,
  hasListShow:false,
  movableChangeInit(){
    this.movableY0=99
    this.movableY1=0
  },
  movableChange(e){
    if(this.hasListShow) return;
    if(this.movableY0==99){
      this.movableY0=e.detail.y
    }else{
      if(e.detail.y!=this.movableY0){
        console.log('movableChange','上拉');
        this.listShow();
        this.movableChangeInit()
        this.hasListShow=true
      }
    }
  },
  filterShow(){
    this.selectComponent('#filter').show();
  },
  filterParams:null,
  filterEvent(e){
    console.log('filterEvent',e)
    if(e.detail.type=='clean'){
      this.filterParams=null
    }else{
      this.filterParams=e.detail.data
    }
    setTimeout(()=>{this.getMarkers();},0)
  },
})