序:项目中需要用到三级联动,自己试着写了下,也查了一些资料,现在把这个记录一下,里面地区数据,可根据个人需要做一些更改,我比较懒就不改了。

wxml

{{province}} {{city}} {{county}}

选择城市

取消

确定

{{sheng.name}}

{{item.name}}

{{item.name}}

js

//index.js

//获取应用实例

// var app = getApp()

// var util = require('../../utils/util.js')

var area = require('../../utils/area.js')

var areaInfo = [];//所有省市区县数据

var provinces = [];//省

var citys = [];//城市

var countys = [];//区县

var index = [0, 0, 0];

var cellId;

var t = 0;

var show = false;

var moveY = 200;

Page({

data: {

show: show,

provinces: provinces,

citys: citys,

countys: countys,

value: [0, 0, 0]

},

//滑动事件

bindChange: function (e) {

var val = e.detail.value

// console.log(e)

//判断滑动的是第几个column

//若省份column做了滑动则定位到地级市和区县第一位

if (index[0] != val[0]) {

val[1] = 0;

val[2] = 0;

getCityArr(val[0], this);//获取地级市数据

getCountyInfo(val[0], val[1], this);//获取区县数据

} else { //若省份column未做滑动,地级市做了滑动则定位区县第一位

if (index[1] != val[1]) {

val[2] = 0;

getCountyInfo(val[0], val[1], this);//获取区县数据

}

}

index = val;

console.log(index + " => " + val);

//更新数据

this.setData({

value: [val[0], val[1], val[2]],

province: provinces[val[0]].name,

city: citys[val[1]].name,

county: countys[val[2]].name

})

},

onLoad: function (options) {

cellId = options.cellId;

var that = this;

var date = new Date()

console.log(date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日");

//获取省市区县数据

area.getAreaInfo(function (arr) {

areaInfo = arr;

//获取省份数据

getProvinceData(that);

});

},

// ------------------- 分割线 --------------------

onReady: function () {

this.animation = wx.createAnimation({

transformOrigin: "50% 50%",

duration: 0,

timingFunction: "ease",

delay: 0

}

)

this.animation.translateY(200 + 'vh').step();

this.setData({

animation: this.animation.export(),

show: show

})

},

//移动按钮点击事件

translate: function (e) {

if (t == 0) {

moveY = 0;

show = false;

t = 1;

} else {

moveY = 200;

show = true;

t = 0;

}

// this.animation.translate(arr[0], arr[1]).step();

animationEvents(this,moveY, show);

},

//隐藏弹窗浮层

hiddenFloatView(e){

console.log(e);

moveY = 200;

show = true;

t = 0;

animationEvents(this,moveY, show);

},

//页面滑至底部事件

onReachBottom: function () {

// Do something when page reach bottom.

},

tiaozhuan(){

wx.navigateTo({

url: '../../pages/modelTest/modelTest',

})

}

})

//动画事件

function animationEvents(that,moveY,show){

console.log("moveY:" + moveY + "\nshow:" + show);

that.animation = wx.createAnimation({

transformOrigin: "50% 50%",

duration: 400,

timingFunction: "ease",

delay: 0

}

)

that.animation.translateY(moveY + 'vh').step()

that.setData({

animation: that.animation.export(),

show: show

})

}

// ---------------- 分割线 ----------------

//获取省份数据

function getProvinceData(that) {

var s;

provinces = [];

var num = 0;

for (var i = 0; i < areaInfo.length; i++) {

s = areaInfo[i];

if (s.di == "00" && s.xian == "00") {

provinces[num] = s;

num++;

}

}

that.setData({

provinces: provinces

})

//初始化调一次可更改

getCityArr(0, that);

getCountyInfo(0, 0, that);

that.setData({

province: "北京市",

city: "市辖区",

county: "东城区",

})

}

// 获取地级市数据

function getCityArr(count, that) {

var c;

citys = [];

var num = 0;

for (var i = 0; i < areaInfo.length; i++) {

c = areaInfo[i];

if (c.xian == "00" && c.sheng == provinces[count].sheng && c.di != "00") {

citys[num] = c;

num++;

}

}

if (citys.length == 0) {

citys[0] = { name: '' };

}

that.setData({

city: "",

citys: citys,

value: [count, 0, 0]

})

}

// 获取区县数据

function getCountyInfo(column0, column1, that) {

var c;

countys = [];

var num = 0;

for (var i = 0; i < areaInfo.length; i++) {

c = areaInfo[i];

if (c.xian != "00" && c.sheng == provinces[column0].sheng && c.di == citys[column1].di) {

countys[num] = c;

num++;

}

}

if(countys.length == 0){

countys[0] = {name:''};

}

that.setData({

county: "",

countys: countys,

value: [column0, column1, 0]

})

}

wxss

/**index.wxss**/

page{

background-color: rgba(255, 255, 255, 1);

}

.infoText{

margin-top: 20rpx;

text-align: center;

width: 100%;

justify-content: center;

}

picker-view{

background-color: white;

padding: 0;

width: 100%;

height: 380rpx;

bottom: 0;

position: fixed;

}

picker-view-column view{

vertical-align:middle;

font-size: 28rpx;

line-height: 28rpx;

height: 100%;

display: flex;

align-items: center;

justify-content: center;

}

/* ----------------------------------------- */

.animation-element-wrapper {

display: flex;

position: fixed;

left: 0;

top:0;

height: 100%;

width: 100%;

background-color: rgba(0, 0, 0, 0.6);

}

.animation-element {

display: flex;

position: fixed;

width: 100%;

height: 470rpx;

bottom: 0;

background-color: rgba(255, 255, 255, 1);

}

.animation-button {

margin-top: 20rpx;

top:20rpx;

width: 400rpx;

height: 100rpx;

line-height: 100rpx;

align-items:center;

}

text{

color: #999999;

display: inline-flex;

position: fixed;

margin-top: 20rpx;

height: 50rpx;

text-align: center;

line-height: 50rpx;

font-size: 34rpx;

font-family: Arial, Helvetica, sans-serif;

}

.left-bt{

left: 30rpx;

}

.right-bt {

right: 30rpx;

}

.line{

display: block;

position: fixed;

height: 1rpx;

width: 100%;

margin-top: 89rpx;

background-color: #eeeeee;

}

这个是没有进行封装的处理

项目里已经封装好,可直接通过模板调用使用。

微信小程序的省市区三级地址mysql_微信小程序 实现三级联动-省市区相关推荐

  1. 微信小程序的省市区三级地址mysql_微信小程序picker实现的省市区三级联动

    微信小程序的省市区三级联动需要使用到的是Picker多列选择器,参考文档:https://www.w3cschool.cn/weix..., 案例中用到的省市区的json文件在文后发出出来. 废话不多 ...

  2. 如何在微信小程序中使用php和mysql_微信小程序php后台实现

    这里简单介绍用php后台实现获取openid并保存到数据库: 微信的登陆流程是这样的 首先前端发送请求到服务器: wx.login({ success: function (res) { var co ...

  3. 打开微信显示wifi连接到服务器地址,打开微信就能连接附近wifi,可惜大家都不知道,赶紧告诉家人...

    大家好,谢谢观看本期生活小妙招,我是生活当当家,一切妙招都来于生活. Wi-Fi是一种可以将个人电脑.手持设备(如PDA.手机)等终端以无线方式互相连接的技术. 就是可以通过wifi功能(wlan)使 ...

  4. 微信微网站的服务器ip地址查询,微信开发之(三)获取微信服务器IP地址

    官方文档解析:获取微信服务器IP地址html 在上面的官方文档中咱们能够直接在最浏览器里面进行测试例如:json 是否必须 说明 access_token 是 公众号的access_token C#代 ...

  5. 微信小程序如何获取手机地址定位

    微信小程序如何获取手机地址定位 微信小程序中,经常需要获取地址定位. 微信小程序中如何获取地址定位. wx.getLocation({success: function (res) {console. ...

  6. 微信小程序:最新wordpress黑金壁纸微信小程序 二开修复版源码下载支持流量主收益

    这是一款wordpress系统框架的壁纸小程序源码 相信很多人以前也有用过这类的壁纸小程序源码吧 现在给大家发的这一款是二开修复版的 和以前的安装方式差不多,支持流量主收益模式 介绍: WordPre ...

  7. 【小程序源码】检讨书生成微信小程序工具源码-安装搭建简单

    对于经常写检讨的小伙伴来说,福音来了 因为这是一款检讨书生成小程序 所以再也不用为了写检讨而烦恼了哦 支持自定义字数下线,主题自定义 支持多种类型检讨比如:学生党的,男朋友,领导演讲稿,共青团申请书等 ...

  8. 微信小程序:自动采集头像大全微信小程序源码

    这是一款以头像为主的一款微信小程序源码 该小程序内包含了各种分类,各种样式都有 可以说是目前最全的一款头像小程序源码 五大分类情侣,女生,男生,卡通,风景 每大分类下面都有N个小分类,每个小分类下面有 ...

  9. 微信小程序:流量主头像组合微信小程序

    这是一个头像类型的小程序源码 支持多种流量主 比如激励视频,Banner,视频,插屏,原生模板等 小程序内包含多种头像非类,都是自动采集 比如男生头像,男声头像,动漫头像等等 另外该小程序还支持姓氏头 ...

最新文章

  1. 实操教程|Pytorch常用损失函数拆解
  2. PhotoshopCS6-视觉特效插画技法-1-什么是视觉特效(1)
  3. 英特尔:80%的边缘数据都是视频数据!新成立物联网视频事业部,总部base中国...
  4. linux 监控进程是否存在并重启进程、打印进程日志
  5. echart 坐标数字间隔_用LaTeX优雅地绘制数字电路
  6. 【转载】请问Silverlight 获取客户端网卡mac码
  7. 制作centos6的启动光盘boot.iso
  8. cfree运行程序错误_C/C++程序调试和内存检测
  9. spring security oauth2 资源服务器配置
  10. C++中sizeof详解
  11. python爬虫代码示例 动态_python动态爬虫的实例分享
  12. git常用命令,冲突
  13. [PYTHON] 核心编程笔记之八-Python条件和循环
  14. 进程线程之pid,tid
  15. 罗技G29方向盘linux下的开发
  16. window.opener 与 window.dialogArguments的用法
  17. 基站查询网址、软件、API接口汇总
  18. PostgreSQL下载安装教程以及官网下载包出现的问题
  19. html方框打勾字段,word文档怎么输入带方框的对勾
  20. 多用户商城app小程序开发的功能有哪些

热门文章

  1. 读写EXCEL的例子
  2. Asp.net中的两种刷新父窗体方法
  3. MySQL utf8mb4与emoji表情
  4. HTML5 Canvas 绘制佛教万字
  5. linux下VNC配置详解
  6. es6 - 解构赋值
  7. Google Palette算法详解以及OC化
  8. 关于Java招聘那点事
  9. 实例化Layout中的布局文件(xml)
  10. Linux新手要了解的十个知识点