
這里只上部分js代碼:
var city = require('../../utils/city.js');
Page({
data: {
searchLetter: [],
showLetter: "",
winHeight: 0,
tHeight: 0,
bHeight: 0,
startPageY: 0,
cityList: [],
isShowLetter: false,
scrollTop: 0,
city: ""
},
onLoad: function (options) {
// 生命周期函數--監聽頁面加載
var searchLetter = city.searchLetter;
var cityList = city.cityList();
// console.log(cityInfo);
var sysInfo = wx.getSystemInfoSync();
console.log(sysInfo);
var winHeight = sysInfo.windowHeight;
//添加要匹配的字母范圍值
//1、更加屏幕高度設置子元素的高度
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)
}
this.setData({
winHeight: winHeight,
itemH: itemH,
searchLetter: tempObj,
cityList: cityList
})
console.log(this.data.cityInfo);
},
onReady: function () {
// 生命周期函數--監聽頁面初次渲染完成
},
onShow: function () {
// 生命周期函數--監聽頁面顯示
},
onHide: function () {
// 生命周期函數--監聽頁面隱藏
},
onUnload: function () {
// 生命周期函數--監聽頁面卸載
},
onPullDownRefresh: function () {
// 頁面相關事件處理函數--監聽用戶下拉動作
},
onReachBottom: function () {
// 頁面上拉觸底事件的處理函數
},
onShareAppMessage: function () {
// 用戶點擊右上角分享
return {
title: 'title', // 分享標題
desc: 'desc', // 分享描述
path: 'path' // 分享路徑
}
},
searchStart: function (e) {
var showLetter = e.currentTarget.dataset.letter;
var pageY = e.touches[0].pageY;
this.setScrollTop(this, showLetter);
this.nowLetter(pageY, this);
this.setData({
showLetter: showLetter,
startPageY: pageY,
isShowLetter: true,
})
},
searchMove: function (e) {
var pageY = e.touches[0].pageY;
var startPageY = this.data.startPageY;
var tHeight = this.data.tHeight;
var bHeight = this.data.bHeight;
var showLetter = 0;
console.log(pageY);
if (startPageY - pageY > 0) { //向上移動
if (pageY < tHeight) {
// showLetter=this.mateLetter(pageY,this);
this.nowLetter(pageY, this);
}
} else {//向下移動
if (pageY > bHeight) {
// showLetter=this.mateLetter(pageY,this);
this.nowLetter(pageY, this);
}
}
},
searchEnd: function (e) {
// console.log(e);
// var showLetter=e.currentTarget.dataset.letter;
var that = this;
setTimeout(function () {
that.setData({
isShowLetter: false
})
}, 1000)
},
nowLetter: function (pageY, that) {//當前選中的信息
var letterData = this.data.searchLetter;
var bHeight = 0;
var tHeight = 0;
var showLetter = "";
for (var i = 0; i < letterData.length; i++) {
if (letterData[i].tHeight <= pageY && pageY <= letterData[i].bHeight) {
bHeight = letterData[i].bHeight;
tHeight = letterData[i].tHeight;
showLetter = letterData[i].name;
break;
}
}
this.setScrollTop(that, showLetter);
that.setData({
bHeight: bHeight,
tHeight: tHeight,
showLetter: showLetter,
startPageY: pageY
})
},
bindScroll: function (e) {
console.log(e.detail)
},
setScrollTop: function (that, showLetter) {
var scrollTop = 0;
var cityList = that.data.cityList;
var cityCount = 0;
var initialCount = 0;
for (var i = 0; i < cityList.length; i++) {
if (showLetter == cityList[i].initial) {
scrollTop = initialCount * 30 + cityCount * 41;
break;
} else {
initialCount++;
cityCount += cityList[i].cityInfo.length;
}
}
that.setData({
scrollTop: scrollTop
})
},
bindCity: function (e) {
var city = e.currentTarget.dataset.city;
this.setData({ city: city })
}
})
詳細代碼下載地址請點擊這里:[城市切換](http://www.see-source.com/weixinwidget/downloadZip.html?wid=81)
- 商城api接口
- 首頁數據獲取
- 分類接口
- 購物車接口
- 商品信息接口
- 搜索接口
- 訂單列表接口
- 店鋪接口
- 收藏接口
- 收貨地址接口
- 生成訂單接口
- 支付接口
- 會員中心接口
- 登錄注冊接口
- 關于我們
- 圖片上傳
- 分銷中心
- 分銷明細
- 代金券
- 平臺紅包列表
- 分銷申請列表
- 我的推廣
- 微信小程序
- 簡介
- 開發前準備
- 目錄結構介紹
- 發起請求
- 網絡請求提交表單
- 代碼及開發所遇到問題總結
- 導航跳轉時所遇到的問題
- 緩存數據與數據取得的問題
- 如何引入外部css
- 如何定義與使用全局變量
- 如何定義新的界面
- 微信小程序支付
- 小程序的手機驗證碼登錄
- 上傳,下載
- 提示框
- app.json配置
- 配置demo
- pages
- window
- tabBar
- networkTimeout
- debug
- page.json
- 緩存
- 特效
- 滑動方式
- 城市切換
- 五星好評
- Switch
- 上拉加載
- wxml 標簽
- 視圖容器
- 基礎內容
- 表單組件
- 導航
- 媒體組件
- 自定義提示框
- 小程序內訪問網頁
- 倒計時顯示
- 微信小程序,如何在返回前一個頁面時,執行前一個頁面的方法
- 在本地可以請求到數據,但手機上是請求不到的
- curl請求失敗
- 代碼同步
- 短信平臺更換