• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
    當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

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

    來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 21:59:50
    文檔

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

    微信小程序城市選擇及搜索功能的方法:實(shí)現(xiàn)搜索城市功能 參考 微信小程序 之『仿美團(tuán)城市選擇 城市切換』 https://github.com/cinoliu/-selectCity js文件 // pages/address/address.js var app = getApp() Page({ data: { searchLetter: [], show
    推薦度:
    導(dǎo)讀微信小程序城市選擇及搜索功能的方法:實(shí)現(xiàn)搜索城市功能 參考 微信小程序 之『仿美團(tuán)城市選擇 城市切換』 https://github.com/cinoliu/-selectCity js文件 // pages/address/address.js var app = getApp() Page({ data: { searchLetter: [], show

    實(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;
    }

    聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

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

    微信小程序城市選擇及搜索功能的方法:實(shí)現(xiàn)搜索城市功能 參考 微信小程序 之『仿美團(tuán)城市選擇 城市切換』 https://github.com/cinoliu/-selectCity js文件 // pages/address/address.js var app = getApp() Page({ data: { searchLetter: [], show
    推薦度:
    標(biāo)簽: 小程序 搜索 查找
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 青春草无码精品视频在线观| 国产精品成人观看视频网站| 国产精品第一页在线| 国产成人精品视频2021| 国产精品成人一区二区| 国精品产露脸自拍| 无码人妻精品一区二区蜜桃AV| 一本一道精品欧美中文字幕| 国产精品女同一区二区久久 | 青青草国产精品欧美成人| 九九热在线视频观看这里只有精品| 性色精品视频网站在线观看 | 亚洲国产精品婷婷久久| 精品久久久久中文字| 日韩精品人妻系列无码专区| 精品999在线| 香港三级精品三级在线专区| 日本伊人精品一区二区三区| 亚洲愉拍自拍欧美精品| 中文字幕久久精品无码| 伊人久久精品线影院| 亚洲国产精品成人久久| 99精品福利国产在线| 亚洲av永久无码精品漫画| 亚洲精品国产成人专区| 午夜精品久久久久久毛片| 国产成人精品日本亚洲专区| 精品国产乱码久久久久久1区2区| 国产成人精品高清不卡在线| 精品少妇人妻av无码久久| 国产精品最新国产精品第十页| 蜜芽亚洲av无码精品色午夜| 国产精品无码免费播放| 国产精品爱啪在线线免费观看| 无码国产亚洲日韩国精品视频一区二区三区 | 99国产精品无码| 亚洲av无码精品网站| 久久精品国产一区二区电影| 精品少妇一区二区三区视频| 午夜DY888国产精品影院| 日韩精品一区二三区中文|