Commit 03b7a48bc2f3ffdd7da437b5550c463a2c42c8b7

Authored by vking
1 parent 39efd02f

search

@@ -104,6 +104,9 @@ Page({ @@ -104,6 +104,9 @@ Page({
104 if(data.fun=='setSuggestion'){ 104 if(data.fun=='setSuggestion'){
105 this.setSuggestion(data.suggestion); 105 this.setSuggestion(data.suggestion);
106 } 106 }
  107 + if(data.fun=='moveToLocation'){
  108 + this.moveToLocation();
  109 + }
107 } 110 }
108 ) 111 )
109 PubSub.on( 112 PubSub.on(
@@ -886,7 +889,7 @@ Page({ @@ -886,7 +889,7 @@ Page({
886 tags:this.param.tags, 889 tags:this.param.tags,
887 centre_pos:this.param.centre_pos, 890 centre_pos:this.param.centre_pos,
888 hasSuggestion:this.data.hasSuggestion?1:'', 891 hasSuggestion:this.data.hasSuggestion?1:'',
889 - keywordTip:this.data.hasSuggestion?this.data.suggestion.title:'', 892 + keyword:this.data.hasSuggestion?this.data.suggestion.title:'',
890 },'./indexList'), 893 },'./indexList'),
891 success: res=> { 894 success: res=> {
892 // 通过eventChannel向被打开页面传送数据 895 // 通过eventChannel向被打开页面传送数据
@@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
27 <view class="searchAddr flex-ll"> 27 <view class="searchAddr flex-ll">
28 <image class="icon" src="http://nosqn.colorcun.com/custom/lite-online/image/search26.png"></image> 28 <image class="icon" src="http://nosqn.colorcun.com/custom/lite-online/image/search26.png"></image>
29 <view class="title">{{hasSuggestion?suggestion.title:'搜索餐厅/位置'}}</view> 29 <view class="title">{{hasSuggestion?suggestion.title:'搜索餐厅/位置'}}</view>
  30 + <view class="clean" catchtap="moveToLocation" wx:if="{{hasSuggestion}}"></view>
30 </view> 31 </view>
31 <view class="searchList flex-tb" catchtap="listShow"> 32 <view class="searchList flex-tb" catchtap="listShow">
32 <image class="icon" src="http://nosqn.colorcun.com/mapmenu/maplist.png"></image> 33 <image class="icon" src="http://nosqn.colorcun.com/mapmenu/maplist.png"></image>
@@ -379,4 +379,21 @@ page{ @@ -379,4 +379,21 @@ page{
379 width: 100%; 379 width: 100%;
380 padding-top: 20rpx; 380 padding-top: 20rpx;
381 height: 426rpx; 381 height: 426rpx;
  382 +}
  383 +.searchAddr .clean{
  384 + position: relative;
  385 + width: 100rpx;
  386 + height: 60rpx;
  387 + min-width: 100rpx;
  388 +}
  389 +.searchAddr .clean:after{
  390 + background-image: url("http://nosqn.colorcun.com/clean.png");
  391 + background-size: 100% 100%;
  392 + display: block;
  393 + content: "";
  394 + width:28rpx;
  395 + height:28rpx;
  396 + position: absolute;
  397 + top:16rpx;
  398 + left:32rpx;
382 } 399 }
@@ -32,11 +32,20 @@ Page({ @@ -32,11 +32,20 @@ Page({
32 eventChannel:null, 32 eventChannel:null,
33 onLoad: async function (options) { 33 onLoad: async function (options) {
34 //lat=34.21719&lng=108.89155&map={"errMsg":"getMapRegion:ok","southwest":{"longitude":108.87545674591064,"latitude":34.204520114013846},"northeast":{"longitude":108.90764325408935,"latitude":34.229857981005225},"scale":15}&multiIndex=1&tags=1,2 34 //lat=34.21719&lng=108.89155&map={"errMsg":"getMapRegion:ok","southwest":{"longitude":108.87545674591064,"latitude":34.204520114013846},"northeast":{"longitude":108.90764325408935,"latitude":34.229857981005225},"scale":15}&multiIndex=1&tags=1,2
  35 + //lat=39.65273&lng=118.15813&map={"errMsg":"getMapRegion:ok","southwest":{"longitude":118.11012337295534,"latitude":39.61934377763755},"northeast":{"longitude":118.1262166270447,"latitude":39.63137569933196},"scale":15}&multiIndex=0&centre_pos=39.625360,118.118170&hasSuggestion=1&keywordTip=唐山站
35 this.options=options; 36 this.options=options;
36 if(options.hasSuggestion){ 37 if(options.hasSuggestion){
  38 + let pos=options.centre_pos.split(',')
  39 + this.suggestion={
  40 + latitude:pos[0],
  41 + longitude:pos[1],
  42 + title:options.keyword,
  43 + }
37 this.setData({ 44 this.setData({
38 - hasSuggestion:true 45 + hasSuggestion:true,
  46 + suggestion:this.suggestion
39 }) 47 })
  48 + delete this.options.keyword
40 } 49 }
41 let tags=[ 50 let tags=[
42 {id:1,name:'环境好'}, 51 {id:1,name:'环境好'},
@@ -106,7 +115,9 @@ Page({ @@ -106,7 +115,9 @@ Page({
106 * 生命周期函数--监听页面卸载 115 * 生命周期函数--监听页面卸载
107 */ 116 */
108 onUnload: function () { 117 onUnload: function () {
109 - PubSub.off('searchParamList') 118 + if(this.hasOneListPage()){
  119 + PubSub.off('searchParamList')
  120 + }
110 }, 121 },
111 122
112 /** 123 /**
@@ -122,20 +133,28 @@ Page({ @@ -122,20 +133,28 @@ Page({
122 onReachBottom: function () { 133 onReachBottom: function () {
123 this.getListMore() 134 this.getListMore()
124 }, 135 },
  136 + hasOneListPage(){//判断是否只有一个列表页面
  137 + let pages = getCurrentPages();
  138 + let pc=0
  139 + pages.forEach(p=>{
  140 + if(p.route=='pages/reserve/indexList'){
  141 + pc++;
  142 + }
  143 + })
  144 + if(pc==1){//只有一个列表页
  145 + return true
  146 + }
  147 + return false
  148 + },
125 hasGetSellerEnd:false, 149 hasGetSellerEnd:false,
  150 + hasCleanSuggestion:false,
126 async getList(){ 151 async getList(){
127 let mapParam=this.options 152 let mapParam=this.options
128 this.offset=1 //page 153 this.offset=1 //page
129 this.size=20 //page size 154 this.size=20 //page size
130 - if(mapParam.keywordTip){  
131 - this.setData({  
132 - keyword:mapParam.keywordTip,  
133 - })  
134 - }else{  
135 - this.setData({  
136 - keyword:mapParam.keyword||'',  
137 - })  
138 - } 155 + this.setData({
  156 + keyword:mapParam.keyword||'',
  157 + })
139 158
140 if(mapParam.keyword){ 159 if(mapParam.keyword){
141 this.param={ 160 this.param={
@@ -161,7 +180,11 @@ Page({ @@ -161,7 +180,11 @@ Page({
161 this.setData({ 180 this.setData({
162 keyword:this.suggestion.title, 181 keyword:this.suggestion.title,
163 }) 182 })
164 - }else{ 183 + }else if(this.hasCleanSuggestion){//清理地标使用人的位置
  184 + lat=this.location.latitude
  185 + lng=this.location.longitude
  186 + }
  187 + if(!lat || !lng){//不完整时,使用地图中心点
165 let map=JSON.parse(mapParam.map); 188 let map=JSON.parse(mapParam.map);
166 lat=map.northeast.latitude-(map.northeast.latitude-map.southwest.latitude)/2; 189 lat=map.northeast.latitude-(map.northeast.latitude-map.southwest.latitude)/2;
167 lng=map.northeast.longitude-(map.northeast.longitude-map.southwest.longitude)/2; 190 lng=map.northeast.longitude-(map.northeast.longitude-map.southwest.longitude)/2;
@@ -175,7 +198,7 @@ Page({ @@ -175,7 +198,7 @@ Page({
175 size:this.size, 198 size:this.size,
176 distance:50, 199 distance:50,
177 }; 200 };
178 - if(this.suggestion){ 201 + if(this.suggestion || this.hasCleanSuggestion){
179 this.param.centre_pos=`${lat},${lng}` 202 this.param.centre_pos=`${lat},${lng}`
180 }else{ 203 }else{
181 if(mapParam.centre_pos){ 204 if(mapParam.centre_pos){
@@ -260,13 +283,15 @@ Page({ @@ -260,13 +283,15 @@ Page({
260 value:[e.detail] 283 value:[e.detail]
261 } 284 }
262 }) 285 })
263 - PubSub.emit(  
264 - 'searchParam',  
265 - {  
266 - fun:'caixiActive',  
267 - e:e,  
268 - }  
269 - ) 286 + if(this.hasOneListPage()){
  287 + PubSub.emit(
  288 + 'searchParam',
  289 + {
  290 + fun:'caixiActive',
  291 + e:e,
  292 + }
  293 + )
  294 + }
270 }, 295 },
271 bindMultiPickerChange(e){ 296 bindMultiPickerChange(e){
272 console.log(e); 297 console.log(e);
@@ -292,13 +317,15 @@ Page({ @@ -292,13 +317,15 @@ Page({
292 this.setData({ 317 this.setData({
293 tags:tags, 318 tags:tags,
294 }) 319 })
295 - PubSub.emit(  
296 - 'searchParam',  
297 - {  
298 - fun:'tagsChange',  
299 - e:e,  
300 - }  
301 - ) 320 + if(this.hasOneListPage()) {
  321 + PubSub.emit(
  322 + 'searchParam',
  323 + {
  324 + fun: 'tagsChange',
  325 + e: e,
  326 + }
  327 + )
  328 + }
302 setTimeout(()=>{this.getList();},0) 329 setTimeout(()=>{this.getList();},0)
303 }, 330 },
304 gotoDetail(e){ 331 gotoDetail(e){
@@ -404,4 +431,15 @@ Page({ @@ -404,4 +431,15 @@ Page({
404 }) 431 })
405 this.getList() 432 this.getList()
406 }, 433 },
  434 + moveToLocation(){
  435 + this.suggestion=null
  436 + this.hasCleanSuggestion=true,
  437 + this.setData({
  438 + suggestion:null,
  439 + hasSuggestion:false,
  440 + keyword:'',
  441 + })
  442 + PubSub.emit('searchParam', {fun:'moveToLocation'})
  443 + setTimeout(()=>{this.getList()},0)
  444 + },
407 }) 445 })
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 <input style="width: 100%;" placeholder="{{search_placeholder}}" 17 <input style="width: 100%;" placeholder="{{search_placeholder}}"
18 type="text" disabled placeholder-class="placeholder" 18 type="text" disabled placeholder-class="placeholder"
19 value="{{keyword}}"/> 19 value="{{keyword}}"/>
  20 + <view class="clean" catchtap="moveToLocation" wx:if="{{keyword && hasSuggestion}}"></view>
20 </view> 21 </view>
21 </view> 22 </view>
22 <view class="transverse-search flex-ll {{hasDisabled?'disabled':''}}"> 23 <view class="transverse-search flex-ll {{hasDisabled?'disabled':''}}">
@@ -197,4 +197,21 @@ @@ -197,4 +197,21 @@
197 width:22rpx; 197 width:22rpx;
198 height: 22rpx; 198 height: 22rpx;
199 margin: 0 10rpx 0 40rpx; 199 margin: 0 10rpx 0 40rpx;
  200 +}
  201 +.searchAddr .clean{
  202 + position: relative;
  203 + width: 100rpx;
  204 + height: 60rpx;
  205 + min-width: 100rpx;
  206 +}
  207 +.searchAddr .clean:after{
  208 + background-image: url("http://nosqn.colorcun.com/clean.png");
  209 + background-size: 100% 100%;
  210 + display: block;
  211 + content: "";
  212 + width:28rpx;
  213 + height:28rpx;
  214 + position: absolute;
  215 + top:16rpx;
  216 + left:32rpx;
200 } 217 }