editAddress.js 6.62 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
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
// packageA/pages/editAddress/editAddress.js
import { AreaPicker } from "../../../utils/areaSelector/selector.js"
import { province } from "../../../utils/areaSelector/province.js"
// import api from "../../../utils/apiFile.js";
var networkUtil = require('../../../utils/network_util.js')
var api = require('../../../utils/apiFile.js')
Page(Object.assign({}, AreaPicker,{
data: {
currentAddress: {},
babyAddress: ''
},
onLoad: function (options) {
if (options.id) {
this.setData({
id: options.id
})
this.getdz(options.id)

}
},
findNameById(id,data) {
for (let i = 0; i < data.length; i++) {
if (data[i].id == id) {
return data[i].name;
}
}
return null;
},
getdz(id){
let self=this
networkUtil._get(api.getKosekiInfo,{babyId:id}, function(res) {
if(0 == res.data.errorcode){
if(res.data.object){
let hhh={}
let arr=[]
let str=''

var addr = 'https://app-member-api.healthbaby.com.cn/vqhdfy/archiveBuildRegions'
// debugger
if(res.data.object.babyProvinceId){
arr.push({id:res.data.object.babyProvinceId})
str=str+self.findNameById(res.data.object.babyProvinceId,province)
hhh.details=str
self.setData({
currentAddress: hhh
})
if(res.data.object.babyCityId){
arr.push({id:res.data.object.babyCityId})
networkUtil._getAddress(addr, { parentId: res.data.object.babyProvinceId, hospitalId: getApp().globalData.hospitalId ? getApp().globalData.hospitalId : ''}, function (res1) {
str=str+self.findNameById(res.data.object.babyCityId,res1.data.list)
hhh.details=str
self.setData({
currentAddress: hhh
})
if(res.data.object.babyAreaId){
arr.push({id:res.data.object.babyAreaId})
networkUtil._getAddress(addr, { parentId: res.data.object.babyCityId, hospitalId: getApp().globalData.hospitalId ? getApp().globalData.hospitalId : ''}, function (res2) {
str=str+self.findNameById(res.data.object.babyAreaId,res2.data.list)
hhh.details=str
self.setData({
currentAddress: hhh
})
if(res.data.object.babyStreetId){
arr.push({id:res.data.object.babyStreetId})
networkUtil._getAddress(addr, { parentId: res.data.object.babyAreaId, hospitalId: getApp().globalData.hospitalId ? getApp().globalData.hospitalId : ''}, function (res3) {
str=str+self.findNameById(res.data.object.babyStreetId,res3.data.list)
hhh.details=str
self.setData({
currentAddress: hhh
})
}, function (res3) {
wx.showToast({ title: `获取地区失败`})
})
}
}, function (res2) {
wx.showToast({ title: `获取地区失败`})
})
}
}, function (res1) {
wx.showToast({ title: `获取地区失败`})
})
}
}
if(res.data.object.babyAddress){
self.setData({
babyAddress:res.data.object.babyAddress
})
}
console.log('str',str);
hhh.addEntry=arr
hhh.details=str
self.setData({
currentAddress: hhh
})
}
console.log('res',res);
}
}, function(res) {
networkUtil.showErrorToast(res.errormsg)
})
},
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;
console.log('data',data);
console.log('data1',this.data.currentAddress);
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)
})
}
}))