editAddress.js 2.45 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
// packageA/pages/editAddress/editAddress.js
import { AreaPicker } from "../../../utils/areaSelector/selector.js"
import api from "../../../utils/apiFile.js";
var networkUtil = require('../../../utils/network_util.js')
Page(Object.assign({}, AreaPicker,{
data: {
currentAddress: {},
babyAddress: ''
},
onLoad: function (options) {
if (options.id) {
this.setData({
id: options.id
})
}
},
onAreaCommit(locationList, e) {//当用户更换地区
console.log('选择地址后', locationList)
var self = this;
self.addrInfo = {
province: locationList[0] || {},
city: locationList[1] || {},
area: locationList[2] || {},
street: locationList[3] || {},
}
var address = {}
address.details = ''
for (var i in locationList){
address.details += locationList[i].name
}
address.addEntry = locationList
self.setData({
isShow: 0,
currentAddress: address
});
},
bindKeyInput: function (e) {
console.log(e.detail.value)
this.data.babyAddress = e.detail.value
this.setData({
babyAddress: this.data.babyAddress
})
},
onShow: function () {},
submitData: function () {
if(!this.data.currentAddress.addEntry) {
wx.showToast({
title: '请选择户籍地址',
icon: 'none',
duration: 2000
})
return;
}
if(!this.data.babyAddress) {
wx.showToast({
title: '请输入街道门牌',
icon: 'none',
duration: 2000
})
return;
}
let data = {};
data.id = this.data.id;
if (this.data.currentAddress.addEntry) {
data.babyProvinceId = this.data.currentAddress.addEntry[0].id;
data.babyCityId = this.data.currentAddress.addEntry[1].id;
data.babyAreaId = this.data.currentAddress.addEntry[2].id;
data.babyStreetId = this.data.currentAddress.addEntry[3].id;
}
data.babyAddress = this.data.babyAddress;
networkUtil._get(api.editAddress,data, function(res) {
if(0 == res.data.errorcode){
wx.showModal({
title: '提示',
content: '修改成功!',
showCancel: false,
success (res) {
if (res.confirm) {
wx.reLaunch({url: '/pages/home/home'})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
}, function(res) {
networkUtil.showErrorToast(res.errormsg)
})
}
}))