地址基本完成

wechat_user_type
Ge Hao 8 years ago
parent 7b66c133b3
commit e7b14865ce
  1. 28
      pages/address/address.js
  2. 2
      pages/address/address.wxml
  3. 16
      pages/cart/cart.js

@ -3,7 +3,7 @@ const district = require('../../utils/address_data.js')
Page({ Page({
data: { data: {
address: {}, detailAddress: '',
arrayProvince: [], arrayProvince: [],
indexProvince: 0, indexProvince: 0,
arrayCity: [], arrayCity: [],
@ -16,13 +16,11 @@ Page({
var p = this.data.arrayProvince[e.detail.value] var p = this.data.arrayProvince[e.detail.value]
var arrayCity = district.cities(p) var arrayCity = district.cities(p)
var c = arrayCity[0] var c = arrayCity[0]
var currentAddress = this.data.address
currentAddress.province = p
this.setData({ this.setData({
indexProvince: e.detail.value, indexProvince: e.detail.value,
arrayCity: arrayCity, arrayCity: arrayCity,
arrayCounty:district.counties(p,c), arrayCounty:district.counties(p,c)
address: currentAddress
}) })
wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty]) wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty])
}, },
@ -30,32 +28,24 @@ Page({
bindChangeCity: function(e) { bindChangeCity: function(e) {
var p = this.data.arrayProvince[this.data.indexProvince] var p = this.data.arrayProvince[this.data.indexProvince]
var c = this.data.arrayCity[e.detail.value] var c = this.data.arrayCity[e.detail.value]
var currentAddress = this.data.address
currentAddress.city = c
this.setData({ this.setData({
indexCity: e.detail.value, indexCity: e.detail.value,
arrayCounty: district.counties(p,c), arrayCounty: district.counties(p,c)
address: currentAddress
}) })
wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty]) wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty])
}, },
bindChangeCounty: function(e) { bindChangeCounty: function(e) {
var county = this.data.arrayCounty[this.data.indexCounty] var county = this.data.arrayCounty[this.data.indexCounty]
var currentAddress = this.data.address
currentAddress.county = county
this.setData({ this.setData({
indexCounty: e.detail.value, indexCounty: e.detail.value
address: currentAddress
}) })
wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty]) wx.setStorageSync('currentDistrict', [this.data.indexProvince, this.data.indexCity, this.data.indexCounty])
}, },
formSubmit: function(e) { formSubmit: function(e) {
var currentAddress = this.data.address this.setData({'detailAddress': e.detail.value.input})
currentAddress.detail = e.detail.value.input wx.setStorage({key:'detailAddress', data: e.detail.value.input})
this.setData({'address': currentAddress})
wx.setStorage({key:'address', data:currentAddress})
wx.navigateBack() wx.navigateBack()
}, },
formReset: function(e) { formReset: function(e) {
@ -63,8 +53,8 @@ Page({
}, },
onLoad (params) { onLoad (params) {
var address = wx.getStorageSync('address') var detailAddress = wx.getStorageSync('detailAddress')
this.setData({'address': address}) this.setData({'detailAddress': detailAddress})
var currentDistrict = wx.getStorageSync('currentDistrict') || [0, 0, 0] var currentDistrict = wx.getStorageSync('currentDistrict') || [0, 0, 0]
var arrayProvince = district.provinces() var arrayProvince = district.provinces()

@ -28,7 +28,7 @@
<view class="section"> <view class="section">
<view class="section_title">详细地址</view> <view class="section_title">详细地址</view>
<input name="input" placeholder="输入地址信息" /> <input name="input" placeholder="输入地址信息" value="{{detailAddress}}" />
</view> </view>
<view class="btn-area"> <view class="btn-area">

@ -1,14 +1,24 @@
const district = require('../../utils/address_data.js')
Page({ Page({
data: { data: {
address: null address:{}
}, },
onLoad: function (params) { onLoad: function (params) {
}, },
onShow: function (params) { onShow: function (params) {
var address = wx.getStorageSync('address') var address = {}
this.setData({'address': address}) var detailAddress = wx.getStorageSync('detailAddress')
address.detail = detailAddress
var districtIndex = wx.getStorageSync('currentDistrict')
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})
}, },
// bindBilling: function () { // bindBilling: function () {

Loading…
Cancel
Save