最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序城市選擇及搜索功能的方法

 更新時(shí)間:2019年03月22日 11:22:01   作者:嘉煠  
這篇文章主要介紹了微信小程序城市選擇及搜索功能的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

實(shí)現(xiàn)搜索城市功能

參考 微信小程序 之『仿美團(tuán)城市選擇 城市切換』
https://github.com/cinoliu/-selectCity

js文件

// pages/address/address.js
var app = getApp()

Page({
 data: {
  searchLetter: [],
  showLetter: "",
  winHeight: 0,
  cityList: [],
  isShowLetter: false,
  scrollTop: 0,//置頂高度
  scrollTopId: '',//置頂id
  city: "",
  cityList_search:[],
  address_show:false,
  search_city:[],
  is_data:true,
  empty:'',
 },
 onLoad: function (options) {
  console.log(options.currentcity)
  
  // 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
  let that = this;
  that.setData({
   city: options.currentcity
  })
  var searchLetter = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"];
  new Promise(function (resolve) {
   that.getCity(function (data) {
    console.log(data)
    let cityObj = data.cityList;
    var tempObj = [];
    for (var i = 0; i < searchLetter.length; i++) {
     var initial = searchLetter[i];
     var cityInfo = [];
     var tempArr = {};
     tempArr.initial = initial;
     for (var j = 0; j < cityObj.length; j++) {
      if (initial == cityObj[j].initial) {
       cityInfo.push(cityObj[j]);
      }
     }
     tempArr.cityInfo = cityInfo;
     tempObj.push(tempArr);
    }
    console.log(tempObj)
    that.setData({
     cityList: tempObj
    })
    resolve(tempObj); 
   })
   
  }).then(function(res){
   console.log(res)
   let cityObj = [];
   var sysInfo = wx.getSystemInfoSync();
   var winHeight = sysInfo.windowHeight;
   var itemH = winHeight / searchLetter.length;
   var tempObj = [];
   for (var i = 0; i < searchLetter.length; i++) {
    var temp = {};
    temp.name = searchLetter[i];
    temp.tHeight = i * itemH;
    temp.bHeight = (i + 1) * itemH;
    tempObj.push(temp)
   }
   that.setData({
    winHeight: winHeight,
    itemH: itemH,
    searchLetter: tempObj,
   })  
  })
 },
 getCity: function (callBack){
  let that = this;
  app.commonRequest('wxapp/public/getCityList', 'POST', {}, function (data) {
    console.log(data);
     if (data.status == '200') {
      that.setData({
       cityList: data.datainfo.list,
       // city: data.datainfo.getcode,     
      })
      callBack({
       cityList: data.datainfo.list
      })
     } else {
      callBack({
       cityList: data.datainfo.list
      })
     }
  })
 },
 set_current_city:function(set_city,callBack){
  let that = this;
  app.commonRequest('wxapp/public/getCityList', 'POST', {
   area_name: set_city,
   cityCheckType:1,
  }, function (data) {
   console.log(data)
   if (data.status == "200") {
    callBack({
     data: data
    })
   }else {
    callBack({
     data: data
    })
   }
  })  
 },
 search_city:function(e){
  let that =this;
  that.setData({
   address_show:true
  })

 },
 cancel_city:function(e){
  let that = this;
  that.setData({
   search_city:[],
   address_show: false,
   empty:'',
  })
 },
 seacrch_city:function(e){
  let that =this;
  let search_val = e.detail.value;
  console.log(search_val);
  app.commonRequest('wxapp/public/getCityList', 'POST', {
   area_name: search_val
  }, function (data) {
   console.log(data)
   if(data.status == "200"){
    if (data.datainfo.list.length >0){
     that.setData({
      search_city: data.datainfo.list,
      is_data: true
     })
    }
    else{
     that.setData({
      search_city: data.datainfo.list,
      is_data:false
     })
    }
   }   
  })  
  
 },
 clickLetter: function (e) {
  console.log(e.currentTarget.dataset.letter)
  var showLetter = e.currentTarget.dataset.letter;
  this.setData({
   showLetter: showLetter,
   isShowLetter: true,
   scrollTopId: showLetter,
  })
  var that = this;
  setTimeout(function () {
   that.setData({
    isShowLetter: false
   })
  }, 1000)
 },
 //選擇城市
 bindCity: function (e) {
  let that = this;
  console.log("bindCity");
  that.set_current_city(e.currentTarget.dataset.city,function(data){
   console.log(data)
  });
  wx.setStorageSync('currentcity', e.currentTarget.dataset.city)
  // that.onLoad();
  this.setData({
   city: e.currentTarget.dataset.city,
   // scrollTop: 0, 
  })
  // 回到首頁(yè)
  wx.switchTab({
   url: '/pages/index/index' 
  })
 },
})

wxml文件

<!--pages/address/address.wxml-->
<view class="searchLetter touchClass">
 <view class="thishotText" bindtap="hotCity">
  <view style="margin-top:0;">當(dāng)前</view>
  <!-- <view style="margin-top:0;">熱門</view> -->
 </view>
 <view wx:for="{{searchLetter}}" style="color:#53985F;font-size:20rpx;" wx:key="index" data-letter="{{item.name}}" catchtouchend="clickLetter" >{{item.name}}</view>
</view>
<block wx:if="{{isShowLetter}}">
 <view class="showSlectedLetter">
  {{showLetter}}
 </view>
</block>
<scroll-view scroll-y="true" style="height:{{winHeight}}px" 
 scroll-into-view="{{scrollTopId}}" scroll-top="{{scrollTop}}">
 <view class='searchbox'>
   <view class='input_box'>
    <image class='search' src='/images/search.png'></image>
    <input placeholder='城市' onchange="seacrch_city" oninput="seacrch_city" onblur="seacrch_city" value='{{empty}}' bindtap='search_city'></input>
    <view class='close' bindtap='cancel_city'>×</view>
   </view>
   <view class='cancel' bindtap='cancel_city'>取消</view>
  </view>
 <view id='address' hidden='{{address_show}}'>
  <view class='current_city li_style'>當(dāng)前:{{city}}</view>
  <view class='all_city'>
   <view class='li_style'>所有城市</view>  
  </view> 
  <view class="selection" wx:for="{{cityList}}" wx:key="{{item.initial}}">
   <view class="item_letter" id="{{item.initial}}">{{item.initial}}</view>
   <view class="item_city" wx:for="{{item.cityInfo}}" wx:for-item="ct" wx:key="{{ct.id}}" data-cityCode="{{ct.area_code}}" data-city="{{ct.area_name}}" bindtap="bindCity">
    {{ct.area_name}}
   </view>
  </view>
 </view>
 <view id='address_search' hidden='{{!address_show}}'>  
  <view>
   <view class="item_city" wx:for="{{search_city}}" wx:for-item="ct" wx:key="{{ct.id}}" data-cityCode="{{ct.area_code}}" data-city="{{ct.area_name}}" bindtap="bindCity">
    {{ct.area_name}}
   </view>
   <view class='noData' hidden='{{is_data}}'>暫無(wú)數(shù)據(jù)</view>
  </view>
 </view>
</scroll-view>

wxss文件

/* pages/address/address.wxss */

.searchbox{
 overflow: hidden;
 margin: 0 20rpx;
}
.search{
 width: 20px;
 height: 20px;
 float: left;
 margin:7rpx 10rpx;
}
.input_box{
 width: 630rpx;
 height: 50rpx;
 background: #efefef;
 border-radius: 30rpx;
 float: left;
}
.input_box input{
 font-size: 25rpx;
 width: 450rpx;
 float: left;
}
.input_box .close{
 width:30rpx;
 height:30rpx;
 background:#aaa;
 color:#fff;
 border-radius:50%;
 float:right;
 margin-right:20rpx;
 margin-top:10rpx;
 line-height:27rpx;
 font-size:30rpx;
 text-align:center;
}
.searchbox .cancel{
 font-size: 25rpx;
 color: #53985F;
 width: 80rpx;
 text-align: right;
 float: right;
 line-height: 50rpx;
}
.current_city{
 border-bottom: 1rpx solid #eee; 
}
.li_style{
 height: 50rpx;
 padding: 20rpx 0;
 width: 710rpx;
 line-height: 50rpx;
 font-size: 29rpx;
 margin:0 20rpx;
}

.searchLetter {
 position: fixed;
 right: 0;
 width: 50rpx;
 text-align: center;
 justify-content: center;
 display: flex;
 flex-direction: column;
 color: #666;
 z-index: 1;
}

.searchLetter view {
 margin-top: 20rpx;
}

.touchClass {
 background-color: #fff;
 color: #fff;
 top: 100rpx;
}

.showSlectedLetter {
 background-color: rgba(0, 0, 0, 0.5);
 color: #fff;
 display: flex;
 justify-content: center;
 align-items: center;
 position: fixed;
 top: 50%;
 left: 50%;
 margin: -100rpx;
 width: 200rpx;
 height: 200rpx;
 border-radius: 20rpx;
 font-size: 52rpx;
 z-index: 1;
}

.selection {
 display: flex;
 width: 100%;
 flex-direction: column;
 margin-top: 10rpx;
}

.item_letter {
 display: flex;
 background-color: #f5f5f5;
 height: 50rpx;
 padding-left: 34rpx;
 align-items: center;
 font-size: 24rpx;
 color: #666;
}

.item_city {
 display: flex;
 background-color: #fff;
 height: 100rpx;
 padding-left: 34rpx;
 align-items: center;
 border-bottom: 1rpx solid #ededed;
 font-size: 24rpx;
 color: #666;
}

.hotcity-common {
 font-size: 24rpx;
 color: #666;
 padding: 0 0 0 30rpx;
}

.thisCity {
 padding-top: 30rpx;
}

.thisCityName {
 display: inline-block;
 border: 1rpx solid #2ab4ff;
 border-radius: 8rpx;
 padding: 10rpx 0;
 font-size: 24rpx;
 color: #2ab4ff;
 text-align: center;
 min-width: 149.5rpx;
 margin: 20rpx 0 20rpx 30rpx;
}

.thishotText {
 color: #53985F;
 font-size: 20rpx;
 margin: 0 !important;
}

.slectCity {
 border-color: #2ab4ff !important;
}

.slectCity view {
 color: #2ab4ff !important;
}

.weui-grid {
 position: relative;
 float: left;
 padding: 10rpx 0;
 width: 149.5rpx;
 box-sizing: border-box;
 border: 1rpx solid #ececec;
 border-radius: 8rpx;
 margin: 10rpx 12rpx;
}

.weui-grid__label {
 display: block;
 text-align: center;
 color: #333;
 font-size: 24rpx;
 white-space: nowrap;
 text-overflow: ellipsis;
 overflow: hidden;
}
.noData{
 text-align: center;
 font-size: 30rpx;
 color: #aaa;
 line-height: 60rpx;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 微信小程序自定義可滑動(dòng)的tab切換

    微信小程序自定義可滑動(dòng)的tab切換

    這篇文章主要為大家詳細(xì)介紹了微信小程序自定義tab切換,可滑動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • canvas實(shí)現(xiàn)十二星座星空?qǐng)D

    canvas實(shí)現(xiàn)十二星座星空?qǐng)D

    本文主要分享了canvas實(shí)現(xiàn)十二星座星空?qǐng)D的示例代碼。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • JS實(shí)現(xiàn)的適合做faq或menu滑動(dòng)效果示例

    JS實(shí)現(xiàn)的適合做faq或menu滑動(dòng)效果示例

    這篇文章主要介紹了JS實(shí)現(xiàn)的適合做faq或menu滑動(dòng)效果,結(jié)合實(shí)例形式分析了基于JS實(shí)現(xiàn)的頁(yè)面元素滑動(dòng)漸變效果的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-11-11
  • 微信小程序開發(fā)探究

    微信小程序開發(fā)探究

    這篇文章主要介紹了微信小程序開發(fā)探究,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。
    2016-12-12
  • webpack常用配置總覽(小結(jié))

    webpack常用配置總覽(小結(jié))

    這篇文章主要介紹了webpack常用配置總覽(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • JavaScript日期格式化技巧分享

    JavaScript日期格式化技巧分享

    在 JavaScript 中,日期和時(shí)間的處理與格式化是非常常見的需求,JavaScript 提供了內(nèi)置的 Date 對(duì)象用于操作日期和時(shí)間,但它的格式化功能較為有限,為了更方便地格式化日期,通常需要結(jié)合一些額外的工具或庫(kù),本文涵蓋了從基礎(chǔ)到進(jìn)階的日期格式化技巧
    2024-10-10
  • Bootstrap CDN和本地化環(huán)境搭建

    Bootstrap CDN和本地化環(huán)境搭建

    這篇文章主要介紹了Bootstrap CDN和本地化環(huán)境搭建的方法,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友跟著小編一起學(xué)習(xí)吧
    2016-10-10
  • js獲取視頻時(shí)長(zhǎng)代碼

    js獲取視頻時(shí)長(zhǎng)代碼

    下面的這段js獲取視頻時(shí)長(zhǎng)代碼是網(wǎng)上找的,還沒有測(cè)試,需要的朋友可以參考下
    2014-04-04
  • javascript中返回頂部按鈕的實(shí)現(xiàn)

    javascript中返回頂部按鈕的實(shí)現(xiàn)

    這篇文章主要介紹了使用javascript實(shí)現(xiàn)博客園頁(yè)面右下角返回頂部按鈕的思路及源碼,非常不錯(cuò),這里推薦給小伙伴們
    2015-05-05
  • JavaScript操縱窗口的方法小結(jié)

    JavaScript操縱窗口的方法小結(jié)

    一旦你得到了表示窗口的變量,你就能通過(guò)各種方法來(lái)操縱它。下面介紹一下對(duì)窗口的各種操作
    2013-06-06

最新評(píng)論

青海省| 察隅县| 鲜城| 武乡县| 太康县| 和田县| 成武县| 昌都县| 通化县| 芷江| 三门县| 天门市| 蓝山县| 措勤县| 和平区| 墨竹工卡县| 澄城县| 专栏| 榆社县| 镇康县| 丰镇市| 江油市| 玉溪市| 织金县| 汤原县| 红河县| 双辽市| 麻江县| 巴彦淖尔市| 土默特右旗| 拉萨市| 龙游县| 宾阳县| 银川市| 常熟市| 新邵县| 丰原市| 雷波县| 涟水县| 湟中县| 西贡区|