改写地址选择,使用API来获取市、区数据

wechat_user_type
Ge Hao 8 years ago
parent 964de9f233
commit 9a9663f7e6
  1. 34
      pages/address/address.js
  2. 19
      pages/cart/cart.js
  3. 4
      utils/address.js
  4. 62
      utils/address_data.js

@ -1,4 +1,3 @@
const address = require('../../utils/address.js')
const district = require('../../utils/address_data.js')
Page({
@ -15,25 +14,27 @@ Page({
},
bindChangeProvince: function(e) {
var that = this
var p = this.data.arrayProvince[e.detail.value]
var arrayCity = district.cities(p)
var c = arrayCity[0]
this.setData({
indexProvince: e.detail.value,
arrayCity: arrayCity,
arrayCounty: district.counties(p,c)
district.cities(p, function(arrayCity){
that.setData({arrayCity: arrayCity})
district.counties(p, arrayCity[0], function(arrayCounty){
that.setData({arrayCounty: arrayCounty})
})
})
this.setData({indexProvince: e.detail.value})
wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty])
},
bindChangeCity: function(e) {
var that = this
var p = this.data.arrayProvince[this.data.indexProvince]
var c = this.data.arrayCity[e.detail.value]
this.setData({
indexCity: e.detail.value,
arrayCounty: district.counties(p,c)
district.counties(p, c, function(arrayCounty){
that.setData({arrayCounty: arrayCounty})
})
this.setData({indexCity: e.detail.value})
wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty])
},
@ -64,18 +65,21 @@ Page({
},
onLoad (params) {
var that = this
var currentDistrict = wx.getStorageSync('currentDistrict') || [1, 0, 0]
var arrayProvince = district.provinces()
var arrayCity = district.cities(arrayProvince[currentDistrict[0]])
var arrayCounty = district.counties(arrayProvince[currentDistrict[0]], arrayCity[currentDistrict[1]])
district.cities(arrayProvince[currentDistrict[0]], function(arrayCity){
that.setData({arrayCity: arrayCity})
district.counties(arrayProvince[currentDistrict[0]], arrayCity[currentDistrict[1]], function(arrayCounty){
that.setData({arrayCounty: arrayCounty})
})
})
this.setData({
indexProvince: currentDistrict[0],
indexCity: currentDistrict[1],
indexCounty: currentDistrict[2],
arrayProvince: arrayProvince,
arrayCity: arrayCity,
arrayCounty: arrayCounty,
detailAddress: wx.getStorageSync('detailAddress'),
receiverName: wx.getStorageSync('receiverName'),
receiverMobile: wx.getStorageSync('receiverMobile')

@ -10,13 +10,15 @@ Page({
cartItems: [],
amount: 0,
accountType: '',
coupon: null
coupon: null,
address: {}
},
onLoad: function (params) {
},
onShow: function (params) {
var that = this
if (app.globalData.currentCustomer) {
var accountType = app.globalData.currentCustomer.account_type
this.setData({accountType: accountType})
@ -31,12 +33,17 @@ Page({
var receiverMobile = wx.getStorageSync('receiverMobile')
var address = {detail_address: detailAddress, customer_name: receiverName, customer_mobile: receiverMobile}
var districtIndex = wx.getStorageSync('currentDistrict') || [0,0,0]
var districtIndex = wx.getStorageSync('currentDistrict') || [1,0,0]
address.province = district.provinces()[districtIndex[0]]
address.city = district.cities(address.province)[districtIndex[1]]
address.county = district.counties(address.province, address.city)[districtIndex[2]]
this.setData({address: address})
that.setData({address: address})
district.cities(address.province, function(arrayCity){
address.city = arrayCity[districtIndex[1]]
that.setData({address: address})
district.counties(address.province, address.city, function(arrayCounty){
address.county = arrayCounty[districtIndex[2]]
that.setData({address: address})
})
})
},
bindSelectCoupon: function() {

@ -1,4 +0,0 @@
const app = getApp()
module.exports = {
}

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