hopeaddress.js
4.7 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
new Vue({
el:'#hopeaddress',
data: {
province:[],
city:[],
county:[],
street:[],
detailaddress:'',
sureinfo:{
province:"",
city:"",
county:"",
town:"",
province_id:"",
city_id:"",
county_id:"",
town_id:""
},
proce:{},
ci:{},
coun:{},
stre:{}
},
created: function() {
this.details();
},
methods: {
//获取信息
details: function() {
var that = this;
//默认市
var obcity={
province_id:'000',
city_name:'市'
};
that.city.push(obcity);
var len=that.city.length;
that.ci=that.city[len-1];
console.log( that.ci);
//默认区
var obscounty={
county_id:'000',
county_name:'区'
};
that.county.push(obscounty);
var len1=that.county.length;
that.coun=that.county[len1-1];
//默认街道
var obstreet={
town_id:'000',
town_name:'街道'
};
that.street.push(obstreet);
var len2=that.street.length;
that.stre=that.street[len2-1];
var url = '/AjaxPosition/province'
var params = {
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
that.province=data;
var ob={
province_id:'000',
province_name:'省'
}
that.province.push(ob);
console.log(that.province);
that.proce=that.province[31];
})
},
//选择城市
selectcity:function(res){
var that = this;
//var el = event.currentTarget;
//省
var proce_name=that.proce.province_name;
var provinceid =that.proce.province_id;
that.sureinfo.province=proce_name;
that.sureinfo.province_id=provinceid;
//var provinceid=res.value;
// console.log(province[index].province_id)
// var adnum=parseInt(that.carlist[index].goods_num);
console.log(provinceid)
var url = '/AjaxPosition/city'
var params = {
province_id:provinceid
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
that.city=res.data;
})
},
//选择县
selectcounty:function(res){
var that = this;
//市
var ci_name=that.ci.city_name;
var cityid=that.ci.city_id;
that.sureinfo.city=ci_name;
that.sureinfo.city_id= cityid;
var url = '/AjaxPosition/county'
var params = {
city_id:cityid
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
that.county=res.data;
})
},
selectstreet:function(res){
var that = this;
console.log(that.coun);
//区
var countyid=that.coun.county_id;
var coun_name=that.coun.county_name;
that.sureinfo.county=coun_name;
that.sureinfo.county_id=countyid;
var url = '/AjaxPosition/town';
var params = {
county_id:countyid
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
that.street=res.data;
})
},
//街道
select:function(res){
var that=this;
var town_id=that.stre.town_id;
var town=that.stre.town_name;
that.sureinfo.town=town;
that.sureinfo.town_id=town_id;
},
sure:function(){
var that=this;
var county_id=that.sureinfo.county_id;
var county=that.sureinfo.county;
var province=that.sureinfo.province;
var province_id=that.sureinfo.province_id;
var city=that.sureinfo.city;
var city_id=that.sureinfo.city_id;
var town =that.sureinfo.town;
var town_id=that.sureinfo.town_id;
if(province==''){
alert("请选择省");
return false;
}
if(city==""){
alert("请选择市");
return false;
}
if(county==""){
alert("请选择区");
return false;
}
if(town==""){
alert("请选择街道");
return false;
}
if(that.detailaddress==""){
alert("请选择详细地址");
return false;
}
var url = '/SurveySpot/updateMyHopeSpot'
var params = {
county_id:county_id,
county: county,
province:province,
province_id:province_id,
city:city,
city_id:city_id,
town:town,
town_id:town_id,
detailaddress:that.detailaddress,
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
if(res.status==true){
alert("更新成功");
window.location.reload();
}else if(res.state==false){
alert("更新失败")
}
})
}
}
});
//});