finish district

wechat_user_type
Ge Hao 8 years ago
parent e8c17d26c7
commit 9ce7e59784
  1. 73
      pages/address/address.js
  2. 15
      pages/address/address.wxml
  3. 45
      utils/address_data.js
  4. 1
      utils/address_data.json

@ -1,49 +1,62 @@
const address = require('../../utils/address.js') const address = require('../../utils/address.js')
const district = require('../../utils/address_data.json') const district = require('../../utils/address_data.js')
Page({ Page({
data: { data: {
arraySheng: ['a', 'b'], address: {},
indexSheng: 0, arrayProvince: [],
indexProvince: 0,
arrayCity: [],
indexCity: 0,
arrayCounty: [],
indexCounty: 0
}, },
bindPickerChange: function(e) { bindChangeProvince: function(e) {
console.log('picker发送选择改变,携带值为', e.detail.value) var p = this.data.arrayProvince[this.data.indexProvince]
var currentAddress = this.data.address
currentAddress.province = p
this.setData({ this.setData({
indexSheng: e.detail.value indexProvince: e.detail.value,
arrayCity: district.cities(p),
address: currentAddress
})
},
bindChangeCity: function(e) {
var p = this.data.arrayProvince[this.data.indexProvince]
var c = this.data.arrayCity[this.data.indexCity]
var currentAddress = this.data.address
currentAddress.city = c
this.setData({
indexCity: e.detail.value,
arrayCounty: district.counties(p,c),
address: currentAddress
})
},
bindChangeCounty: function(e) {
var county = this.data.arrayCounty[this.data.indexCounty]
var currentAddress = this.data.address
currentAddress.county = county
this.setData({
indexCounty: e.detail.value,
address: currentAddress
}) })
}, },
formSubmit: function(e) { formSubmit: function(e) {
address.postAddress(e.detail.value) var currentAddress = this.data.address
console.log('form 发生了 submit 事件,携带数据为:', e.detail.value) currentAddress.detail = e.detail.value.input
this.setData({'address': currentAddress})
wx.setStorage({key:'address', data:currentAddress})
wx.navigateBack()
}, },
formReset: function(e) { formReset: function(e) {
console.log('form 发生了 reset 事件') console.log('form 发生了 reset 事件')
}, },
onLoad (params) { onLoad (params) {
//this.data.sku = params.sku this.setData({'arrayProvince': district.provinces()})
this.setData({'arraySheng': district.keys()})
},
getAddressMenu: function() {
var that = this
wx.request({
method: 'POST',
url: `cities?province=${that.data.arraySheng[indexSheng]}`,
data: Object.assign({}, data),
header: { 'Content-Type': 'application/json' },
success (res) {
console.log('success')
wx.setStorageSync('addrss', res.data)
wx.navigateBack()
},
fail (e) {
console.log('error')
console.error(e)
}
})
} }
}) })

@ -1,24 +1,29 @@
<form bindsubmit="formSubmit" bindreset="formReset"> <form bindsubmit="formSubmit" bindreset="formReset">
<view class="section"> <view class="section">
<view class="section__title">省</view> <view class="section__title">省</view>
<picker bindchange="bindPickerChange" value="{{indexSheng}}" range="{{arraySheng}}"> <picker bindchange="bindChangeProvince" value="{{indexProvince}}" range="{{arrayProvince}}">
<view class="picker"> <view class="picker">
当前选择:{{arraySheng[indexSheng]}} 当前选择:{{arrayProvince[indexProvince]}}
</view> </view>
</picker> </picker>
</view> </view>
<view class="section"> <view class="section">
<view class="section__title">市</view> <view class="section__title">市</view>
<picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}"> <picker bindchange="bindChangeCity" value="{{indexCity}}" range="{{arrayCity}}">
<view class="picker"> <view class="picker">
当前选择:{{array[index]}} 当前选择:{{arrayCity[indexCity]}}
</view> </view>
</picker> </picker>
</view> </view>
<view> <view>
<view class="section__title">区</view>
<picker bindchange="bindChangeCounty" value="{{indexCounty}}" range="{{arrayCounty}}">
<view class="picker">
当前选择:{{arrayCounty[indexCounty]}}
</view>
</picker>
</view> </view>
<view class="section"> <view class="section">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save