diff --git a/pages/address/address.js b/pages/address/address.js index 9f5f3fc..c05bf18 100644 --- a/pages/address/address.js +++ b/pages/address/address.js @@ -11,7 +11,10 @@ Page({ arrayCounty: [], indexProvince: 0, indexCity: 0, - indexCounty: 0 + indexCounty: 0, + + errorHidden: true, + msg: '不能为空' }, bindChangeProvince: function(e) { @@ -45,15 +48,33 @@ Page({ }, formSubmit: function(e) { - this.setData({'detailAddress': e.detail.value.input}) - wx.setStorage({key:'detailAddress', data: e.detail.value.inputDetail}) - wx.setStorage({key:'receiverName', data: e.detail.value.inputName}) - wx.setStorage({key:'receiverMobile', data: e.detail.value.inputMobile}) + // this.setData({'detailAddress': e.detail.value.inputDetail}) + wx.setStorage({key:'detailAddress', data: e.detail.value.inputDetail.trim()}) + + var receiverName = e.detail.value.inputName.trim() + var receiverMobile = e.detail.value.inputMobile.trim() + if (!(receiverName && receiverMobile)) { + this.setData({ + msg: '收货人姓名和手机号不能为空', + errorHidden: false + }) + return + } + if (!receiverMobile.match(/^1[3-9][0-9]\d{8}/)) { + this.setData({ + msg: '手机号格式不正确,仅支持国内手机号码', + errorHidden: false + }) + return + } + wx.setStorage({key:'receiverName', data: receiverName}) + wx.setStorage({key:'receiverMobile', data: receiverMobile}) wx.navigateBack() }, - // formReset: function(e) { - // console.log('form 发生了 reset 事件') - // }, + + confirmError: function(){ + this.setData({errorHidden: true}) + }, onLoad (params) { var currentDistrict = wx.getStorageSync('currentDistrict') || [0, 0, 0] diff --git a/pages/address/address.wxml b/pages/address/address.wxml index ad30393..945b5f2 100644 --- a/pages/address/address.wxml +++ b/pages/address/address.wxml @@ -46,3 +46,7 @@ + + \ No newline at end of file diff --git a/utils/address_data.js b/utils/address_data.js index 148d35b..6559dfe 100644 --- a/utils/address_data.js +++ b/utils/address_data.js @@ -17,6 +17,27 @@ function counties (province, city) { return counties.county } +function findProvince (name) { + var index = procinces().findIndex(function(ele){ + return ele === name + }) + return index +} + +function findCity (p, name) { + var index = cities(p).findIndex(function(ele){ + return ele === name + }); + return index +} + +function findCounty (p, c, name) { + var index = counties(p,c).findIndex(function(ele){ + return ele === name + }); + return index +} + module.exports = { provinces () { return provinces() @@ -26,6 +47,16 @@ module.exports = { }, counties (p,c) { return counties(p,c) + }, + + findProvince (name) { + return findProvince(name) + }, + findCity (p, name) { + return findCity(p, name) + }, + findCounty (p, c, name) { + return findCounty(p, c, name) } }