欢迎光临,了解微信小程序开发,就上易用通!

当前位置 : 易用通 > 小程序模板
仿美团分类菜单 swiper分类菜单,仿美团城市选择 城市切换仿美团分类菜单 swiper分类菜单,仿美团城市选择 城市切换
立即下载

仿美团分类菜单 swiper分类菜单,仿美团城市选择 城市切换

模板分类 : 小程序模板 模板编号 : Y277 源码文件 : 完全开源 下载权限 : VIP会员
模板大小 :  模板指数 :  更新时间 : 2018-01-17 09:58 模板等级 : ☆☆☆☆☆

模板截图:

一:仿美团城市选择 城市切换

原来的城市选择做了一些修改.

仿美团分类菜单 swiper分类菜单,仿美团城市选择 城市切换(图1)

代码很简单.

  1. var city = require('../../utils/city.js');
  2. var app = getApp()
  3. Page({
  4.   data: {
  5.     searchLetter: [],
  6.     showLetter: "",
  7.     winHeight: 0,
  8.     // tHeight: 0,
  9.     // bHeight: 0,
  10.     cityList: [],
  11.     isShowLetter: false,
  12.     scrollTop: 0,//置顶高度
  13.     scrollTopId: '',//置顶id
  14.     city: "上海市",
  15.     hotcityList: [{ cityCode: 110000, city: '北京市' }, { cityCode: 310000, city: '上海市' }, { cityCode: 440100, city: '广州市' }, { cityCode: 440300, city: '深圳市' }, { cityCode: 330100, city: '杭州市' }, { cityCode: 320100, city: '南京市' }, { cityCode: 420100, city: '武汉市' }, { cityCode: 410100, city: '郑州市' }, { cityCode: 120000, city: '天津市' }, { cityCode: 610100, city: '西安市' }, { cityCode: 510100, city: '成都市' }, { cityCode: 500000, city: '重庆市' }]
  16.   },
  17.   onLoad: function () {
  18.     // 生命周期函数--监听页面加载
  19.     var searchLetter = city.searchLetter;
  20.     var cityList = city.cityList();
  21.     var sysInfo = wx.getSystemInfoSync();
  22.     var winHeight = sysInfo.windowHeight;
  23.     var itemH = winHeight / searchLetter.length;
  24.     var tempObj = [];
  25.     for (var i = 0; i < searchLetter.length; i++) {
  26.       var temp = {};
  27.       temp.name = searchLetter[i];
  28.       temp.tHeight = i * itemH;
  29.       temp.bHeight = (i + 1) * itemH;
  30.       tempObj.push(temp)
  31.     }
  32.     this.setData({
  33.       winHeight: winHeight,
  34.       itemH: itemH,
  35.       searchLetter: tempObj,
  36.       cityList: cityList
  37.     })
  38.  
  39.   },
  40.   onReady: function () {
  41.     // 生命周期函数--监听页面初次渲染完成
  42.  
  43.   },
  44.   onShow: function () {
  45.     // 生命周期函数--监听页面显示
  46.  
  47.   },
  48.   onHide: function () {
  49.     // 生命周期函数--监听页面隐藏
  50.  
  51.   },
  52.   onUnload: function () {
  53.     // 生命周期函数--监听页面卸载
  54.  
  55.   },
  56.   onPullDownRefresh: function () {
  57.     // 页面相关事件处理函数--监听用户下拉动作
  58.  
  59.   },
  60.   onReachBottom: function () {
  61.     // 页面上拉触底事件的处理函数
  62.  
  63.   },
  64.   clickLetter: function (e) {
  65.     console.log(e.currentTarget.dataset.letter)
  66.     var showLetter = e.currentTarget.dataset.letter;
  67.     this.setData({
  68.       showLetter: showLetter,
  69.       isShowLetter: true,
  70.       scrollTopId: showLetter,
  71.     })
  72.     var that = this;
  73.     setTimeout(function () {
  74.       that.setData({
  75.         isShowLetter: false
  76.       })
  77.     }, 1000)
  78.   },
  79.   //选择城市
  80.   bindCity: function (e) {
  81.     console.log("bindCity")
  82.     this.setData({ city: e.currentTarget.dataset.city })
  83.   },
  84.   //选择热门城市
  85.   bindHotCity: function (e) {
  86.     console.log("bindHotCity")
  87.     this.setData({
  88.       city: e.currentTarget.dataset.city
  89.     })
  90.   },
  91.   //点击热门城市回到顶部
  92.   hotCity: function () {
  93.     this.setData({
  94.       scrollTop: 0,
  95.     })
  96.   }
  97. })
复制代码
二:仿美团分类菜单 swiper分类菜单

有同学要仿美团分类菜单.写了一个.  跟 微信小程序开发之选项卡(窗口顶部TabBar)页面切换很类似

仿美团分类菜单 swiper分类菜单,仿美团城市选择 城市切换(图2)

代码:  js就这么一点

  1. //index.js  
  2. //获取应用实例  
  3. var app = getApp()
  4. Page({
  5.   data: {
  6.     currentTab: 0,
  7.     grids: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
  8.     swiperList:[0, 1, 2, 3, 4]
  9.   },
  10.   onLoad: function () {
  11.   },
  12.   click: function (e) {
  13.     console.log(e.currentTarget.dataset.id)
  14.     console.log(e.currentTarget.dataset.index)
  15.     wx.showToast({
  16.       title: '第' + e.currentTarget.dataset.id + '栏' + '第' + e.currentTarget.dataset.index + '个',
  17.       icon: 'success',
  18.       duration: 1500
  19.     })
  20.   },
  21.   /** 
  22.      * 滑动切换tab 
  23.      */
  24.   bindChange: function (e) {
  25.     console.log(e.detail.current)
  26.     this.setData({ currentTab: e.detail.current });
  27.   },
  28. })

加入收藏
立即下载
分享到微信朋友圈
X

免责声明:

1. 本站所有素材(未指定商用),仅限学习交流,请勿用于商业用途。
2. 本站所有小程序模板Demo和图片均来自用户分享上传和网络收集,模板和图片版权归原作者及原出处所有。
3. 未经合法授权,会员不得以任何形式发布、传播、复制、转售该素材。