choosecountry.js
1.39 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
import { API_HOST } from '../../../libs/config';
import { GET } from '../../../libs/request';
import { getYHStorageSync } from '../../../utils/util';
let CACH_KEY = 'country_cach';
let CHOOSED_COUNTRY_ID = 'CHOOSED_COUNTRY_ID'
let CHOOSED_COUNTRY_NAME = 'CHOOSED_COUNTRY_NAME'
Page({
data: {
list:[]
},
getArea: function () {
let param={
method: 'app.passport.getArea'
}
GET(API_HOST,param)
.then(json=>{
if(json && json.code == 200){
let datalist = json.data;
if(datalist && datalist.length>0){
this.setData({
list: datalist
})
wx.setStorage({
key: CACH_KEY,
data: datalist,
})
}
}else{
this.useCache();
}
})
.catch(error=>{
this.useCache();
})
},
useCache:function(){
let datalist = getYHStorageSync(CACH_KEY,'choosecountry');
this.setData({
list: datalist
})
},
chooseCountry:function(e){
let country = e.currentTarget.dataset.country;
let country_area = e.currentTarget.dataset.area;
let country_id = e.currentTarget.dataset.id;
wx.setStorage({
key: CHOOSED_COUNTRY_ID,
data: country_area,
})
wx.setStorage({
key: CHOOSED_COUNTRY_NAME,
data: country,
})
wx.navigateBack({
delta: 1
})
},
onLoad: function (options) {
this.getArea();
}
})