|
@@ -1,21 +1,4 @@
|
|
|
// pages/addAddress/addAddress.js
|
|
|
-const date = new Date()
|
|
|
-const years = []
|
|
|
-const months = []
|
|
|
-const days = []
|
|
|
-
|
|
|
-for (let i = 1990; i <= date.getFullYear(); i++) {
|
|
|
- years.push(i)
|
|
|
-}
|
|
|
-
|
|
|
-for (let i = 1; i <= 12; i++) {
|
|
|
- months.push(i)
|
|
|
-}
|
|
|
-
|
|
|
-for (let i = 1; i <= 31; i++) {
|
|
|
- days.push(i)
|
|
|
-}
|
|
|
-
|
|
|
const getReq = require('./../../config.js').getReq
|
|
|
|
|
|
Page({
|
|
@@ -27,19 +10,17 @@ Page({
|
|
|
checked: true,
|
|
|
areas: [],
|
|
|
tree: [],
|
|
|
- cityIndex: 0,
|
|
|
- districtIndex: 0,
|
|
|
- region: [],
|
|
|
- years: years,
|
|
|
- year: date.getFullYear(),
|
|
|
- months: months,
|
|
|
- month: 2,
|
|
|
- days: days,
|
|
|
- day: 2,
|
|
|
value: [0, 0, 0],
|
|
|
oldval: [0, 0, 0],
|
|
|
citys: [],
|
|
|
- districts: []
|
|
|
+ districts: [],
|
|
|
+ animation_flag: false,
|
|
|
+ province: '',
|
|
|
+ city: '',
|
|
|
+ district: '',
|
|
|
+ name: '',
|
|
|
+ mob_phone: '',
|
|
|
+ address: ''
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -53,20 +34,8 @@ Page({
|
|
|
checked: !this.data.checked
|
|
|
})
|
|
|
},
|
|
|
- bindRegionChange: function (e) {
|
|
|
- // console.log('picker发送选择改变,携带值为', e.detail.value)
|
|
|
- this.setData({
|
|
|
- region: e.detail.value
|
|
|
- })
|
|
|
- },
|
|
|
bindChange: function (e) {
|
|
|
- console.log(e)
|
|
|
const val = e.detail.value
|
|
|
-
|
|
|
-
|
|
|
- // if (districtIndex != this.data.oldval[1] && cityIndex != 0) {
|
|
|
- // districtIndex = 0
|
|
|
- // }
|
|
|
if (this.data.oldval[0] != val[0]) {
|
|
|
val[1] = 0
|
|
|
val[2] = 0
|
|
@@ -75,18 +44,11 @@ Page({
|
|
|
val[2] = 0
|
|
|
}
|
|
|
}
|
|
|
- let cityIndex = val[0]
|
|
|
- let districtIndex = val[1]
|
|
|
this.setData({
|
|
|
- oldval: val,
|
|
|
+ value: val,
|
|
|
citys: this.data.tree[val[0]].children,
|
|
|
districts: this.data.tree[val[0]].children[val[1]].children
|
|
|
})
|
|
|
- // this.setData({
|
|
|
- // oldval: val,
|
|
|
- // citys: this.data.tree[val[0]],
|
|
|
- // districts: this.data.tree[val[0].children[val[1]]
|
|
|
- // })
|
|
|
},
|
|
|
getDatas() {
|
|
|
wx.showLoading({
|
|
@@ -100,12 +62,12 @@ Page({
|
|
|
}, function (res) {
|
|
|
wx.hideLoading()
|
|
|
if (res.code == 200) {
|
|
|
- console.log(res.datas.areas)
|
|
|
let tree = self.arrayToTree(res.datas.areas)
|
|
|
- console.log(tree)
|
|
|
self.setData({
|
|
|
areas: res.datas.areas,
|
|
|
- tree
|
|
|
+ tree,
|
|
|
+ citys: tree[0].children,
|
|
|
+ districts: tree[0].children[0].children
|
|
|
})
|
|
|
}
|
|
|
else {
|
|
@@ -138,6 +100,145 @@ Page({
|
|
|
})
|
|
|
return result
|
|
|
},
|
|
|
+ animation_flag(e) {
|
|
|
+ let flag = e.currentTarget.dataset.flag
|
|
|
+ let animation_flag = flag == 'true' ? true : false
|
|
|
+ let val = this.data.oldval
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ animation_flag,
|
|
|
+ value: val,
|
|
|
+ citys: this.data.tree[val[0]].children,
|
|
|
+ districts: this.data.tree[val[0]].children[val[1]].children
|
|
|
+ })
|
|
|
+ },
|
|
|
+ setAddress() {
|
|
|
+ let val = this.data.value
|
|
|
+ let province = this.data.tree[val[0]]
|
|
|
+ let city = province.children[val[1]]
|
|
|
+ let district = province.children[val[1]].children[val[2]]
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ animation_flag: false,
|
|
|
+ oldval: val,
|
|
|
+ province,
|
|
|
+ city,
|
|
|
+ district
|
|
|
+ })
|
|
|
+ },
|
|
|
+ commmitAddress() {
|
|
|
+ let self = this
|
|
|
+ let name = this.trim(this.data.name)
|
|
|
+ let phone = this.trim(this.data.mob_phone)
|
|
|
+ let address = this.trim(this.data.address)
|
|
|
+ let province = this.data.province
|
|
|
+
|
|
|
+ if (!name) {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: "请填写您的收货人名称",
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!(/^1(3|4|5|7|8)\d{9}$/.test(phone))) {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: "请填写您的手机号",
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!province) {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: "请选择您的收货地址",
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!address) {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: "请填写的您的详细收货地址",
|
|
|
+ duration: 1500
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ getReq({
|
|
|
+ act: 'member_address',
|
|
|
+ op: 'address_add',
|
|
|
+ curpage: 1,
|
|
|
+ true_name: name,
|
|
|
+ address,
|
|
|
+ mob_phone: phone,
|
|
|
+ area_id: this.data.district.aid
|
|
|
+ }, function (res) {
|
|
|
+ wx.hideLoading()
|
|
|
+ if (res.code == 200) {
|
|
|
+ let address_id = res.datas.address_id
|
|
|
+ let is_default = self.data.checked ? 1 : 0
|
|
|
+ getReq({
|
|
|
+ act: 'member_address',
|
|
|
+ op: 'set_default',
|
|
|
+ curpage: 1,
|
|
|
+ address_id,
|
|
|
+ is_default
|
|
|
+ }, function (response) {
|
|
|
+ wx.hideLoading()
|
|
|
+ if (response.code == 200) {
|
|
|
+ wx.navigateBack()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: response.message,
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: res.message,
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ trim(str) {
|
|
|
+ str = str.replace(/\s+/g, "")
|
|
|
+ return str
|
|
|
+ },
|
|
|
+ bindKeyInput(e) {
|
|
|
+ let valueType = e.currentTarget.dataset.value
|
|
|
+ let value = e.detail.value
|
|
|
+ switch (valueType) {
|
|
|
+ case 'name':
|
|
|
+ this.setData({
|
|
|
+ name: value
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ case 'phone':
|
|
|
+ this.setData({
|
|
|
+ mob_phone: value
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ case 'address':
|
|
|
+ this.setData({
|
|
|
+ address: value
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|