小程序实现城市列表的选择

这篇博客详细介绍了如何在微信小程序中实现城市列表的选择功能,包括按中文、拼音、首字母搜索,以及首字字母快速定位。内容涵盖从目录结构到各主要代码文件如app.js, app.json, index.wxml, index.js, index.wxss, citys.wxml, citys.js, citys.wxss的实现细节。" 86039439,8256847,matlab实现图像局部熵的误区与纠正,"['matlab', '图像分析', '算法实现', '计算机视觉']
摘要由CSDN通过智能技术生成

微信小程序实战—实现城市列表的选择

实现效果预览

首页 
城市列表

实现功能简介
  • 城市的选择
  • 中文/拼音/首字母条件搜索
  • 按首字字母快速定位到城市位置
目录结构

这里写图片描述

主要代码
app.js
App({
  globalData: {
    trainBeginCity: '杭州',
    trainEndCity: '北京'
  }
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
app.json
{
  "pages":[
    "pages/index/index",
    "pages/citys/citys"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle":"black",
    "enablePullDownRefresh": true
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
index.wxml
<view class='warning-top'>测试消息消息这是测试消息啊啊啊</view>
<form bindsubmit="formSubmit" bindreset="formReset" class='form-content'>
  <view class='flex-box' data-id='出发城市'>
    <view class='flex-box-header'>出发城市</view>
    <view class="flex-box-content">
      <input name='beginCity' value='{
  {begin}}' disabled='disabled' placeholder="" bindtap='bindBeginCityView' class='input-city'/>
    </view>
  </view>

  <view class="flex-box" data-id='目的城市'>
    <view class='flex-box-header'>目的城市</view>
    <view class="flex-box-content">
      <input name='endCity' value='{
  {end}}' placeholder="" disabled='disabled' bindtap='bindEndCityView' class='input-city'/>
    </view>
  </view>

  <view class="flex-box">
    <view class='flex-box-header'>出发日期</view>
    <picker mode="date" name='leaveDate' class='flex-box-content-pricker' value="{
  {date}}" start="2018-01-01" end="2019-09-01" bindchange="bindDateChange" >
      <view class='input-city'>{
  {date}}</view>
    </picker>
  </view>

  <view class="btn-area">
    <button formType="submit" class='btn-query'>查询</button>
  </view>
</form>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
index.js
const app = getApp()

Page({
  data: {
    begin: '',
    end: '',
    date: null
  },

  formSubmit: function (e) {
    // console.log('form发生了submit事件,携带数据为:', e.detail.value)
    wx.navigateTo({
      url: '../trains/trains?beginCity=' + e.detail.value.beginCity + "&endCity=" + e.detail.value.endCity + "&leaveDate=" + e.detail.value.leaveDate,
    })
  },
  formReset: function () {
    console.log('form发生了reset事件')
  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  onLoad: function (options) {
    // wx.navigateTo({
    //   url: '../citys/citys?cityType=begin',
    // })


    if (this.data.date == null || this.data.date.trim() == "") {
      var day = new Date()
      day.setTime(day.getTime() + 24 * 60 * 60 * 1000);
      var year = day.getFullYear();       //年
      var month = day.getMonth() + 1;     //月
      var day = day.getDate();            //日

      if (month < 10) { month = "0" + month; }
      if (day < 10) { day = "0" + day; }
      this.setData({ date: year + '-' + month + '-' + day })
    }
  }, onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  }, bindBeginCityView: function () {
    wx.navigateTo({
      url: '../citys/citys?cityType=begin',
    })
  }, bindEndCityView: function () {
    wx.navigateTo({
      url: '../citys/citys?cityType=end',
    })
  }, onShow: function () {
    this.setData({ begin: app.globalData.trainBeginCity })
    this.setData({ end: app.globalData.trainEndCity })
  }


})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值