1
1
// pages/driver/driver.js
2
- var tcity = require ( "../../utils/citys.js" ) ;
3
2
var app = getApp ( )
4
3
Page ( {
5
4
@@ -14,15 +13,15 @@ Page({
14
13
truckTypeIndex : 0 ,
15
14
lengthIndex : 0 ,
16
15
axlesIndex : 0 ,
17
- provinces : [ ] ,
18
- originProvince : "" ,
19
- citys : [ ] ,
20
- originCity : "" ,
21
- countys : [ ] ,
22
- originCounty : '' ,
16
+ cityArray : [ '成都' , '上海' , '深圳' , '广州' , '重庆' , '北京' , '石家庄' , '天津' , '青岛' , '昆明' , '西安' , '乌鲁木齐' , '长沙' , '武汉' , '厦门' , '杭州' , '南京' , '太原' , '呼和浩特' , '沈阳' ] ,
17
+ originCityIndex : 0 ,
23
18
value : [ 0 , 0 , 0 ] ,
24
19
values : [ 0 , 0 , 0 ] ,
25
- condition : false
20
+ condition : false ,
21
+ destination : false ,
22
+ destinationCityIndex : 0 ,
23
+ originCity : '成都' ,
24
+ destinationCity : '成都'
26
25
} ,
27
26
28
27
@@ -47,70 +46,39 @@ Page({
47
46
} ) ;
48
47
} ,
49
48
50
- bindChangeOrigin : function ( e ) {
51
- var val = e . detail . value
52
- console . log ( 'val' , val )
53
- var t = this . data . values ;
54
- var cityData = this . data . cityData ;
55
-
56
- if ( val [ 0 ] != t [ 0 ] ) {
57
- console . log ( 'province' ) ;
58
- const citys = [ ] ;
59
- const countys = [ ] ;
60
-
61
- for ( let i = 0 ; i < cityData [ val [ 0 ] ] . sub . length ; i ++ ) {
62
- citys . push ( cityData [ val [ 0 ] ] . sub [ i ] . name )
63
- }
64
- for ( let i = 0 ; i < cityData [ val [ 0 ] ] . sub [ 0 ] . sub . length ; i ++ ) {
65
- countys . push ( cityData [ val [ 0 ] ] . sub [ 0 ] . sub [ i ] . name )
66
- }
67
-
68
- this . setData ( {
69
- originProvince : this . data . provinces [ val [ 0 ] ] ,
70
- originCity : cityData [ val [ 0 ] ] . sub [ 0 ] . name ,
71
- citys : citys ,
72
- originCounty : cityData [ val [ 0 ] ] . sub [ 0 ] . sub [ 0 ] . name ,
73
- countys : countys ,
74
- values : val ,
75
- value : [ val [ 0 ] , 0 , 0 ]
76
- } )
77
-
78
- return ;
49
+ chooseDestination : function ( ) {
50
+ let page = this ;
51
+ if ( page . data . destination ) {
52
+ page . setData ( { destination : false } )
53
+ } else {
54
+ page . setData ( { destination : true } )
79
55
}
80
- if ( val [ 1 ] != t [ 1 ] ) {
81
- console . log ( 'city' ) ;
82
- const countys = [ ] ;
83
-
84
- for ( let i = 0 ; i < cityData [ val [ 0 ] ] . sub [ val [ 1 ] ] . sub . length ; i ++ ) {
85
- countys . push ( cityData [ val [ 0 ] ] . sub [ val [ 1 ] ] . sub [ i ] . name )
86
- }
56
+ } ,
87
57
88
- this . setData ( {
89
- originCity : this . data . citys [ val [ 1 ] ] ,
90
- originCounty : cityData [ val [ 0 ] ] . sub [ val [ 1 ] ] . sub [ 0 ] . name ,
91
- countys : countys ,
92
- values : val ,
93
- value : [ val [ 0 ] , val [ 1 ] , 0 ]
94
- } )
95
- return ;
96
- }
97
- if ( val [ 2 ] != t [ 2 ] ) {
98
- console . log ( 'county' ) ;
99
- this . setData ( {
100
- originCounty : this . data . countys [ val [ 2 ] ] ,
101
- values : val
102
- } )
103
- return ;
104
- }
58
+ bindOriginChange : function ( e ) {
59
+ let page = this ;
60
+ this . setData ( {
61
+ originCityIndex : e . detail . value
62
+ } )
63
+ console . log ( this . data . cityArray [ this . data . originCityIndex ] )
64
+ this . setData ( {
65
+ originCity : page . data . cityArray [ page . data . originCityIndex ]
66
+ } )
105
67
} ,
106
- open : function ( ) {
68
+
69
+ bindDestinationChange : function ( e ) {
70
+ let page = this ;
107
71
this . setData ( {
108
- condition : ! this . data . condition
72
+ destinationCityIndex : e . detail . value
73
+ } )
74
+ console . log ( this . data . cityArray [ this . data . destinationCityIndex ] )
75
+ this . setData ( {
76
+ destinationCity : page . data . cityArray [ page . data . destinationCityIndex ]
109
77
} )
110
78
} ,
111
79
112
- getLocation : function ( ) {
113
- var locationString = this . data . originProvince + this . data . originCity + this . data . originCounty
80
+ getLocation : function ( e ) {
81
+ var locationString = this . data . cityArray [ e ]
114
82
115
83
let page = this ;
116
84
var url = `https://restapi.amap.com/v3/geocode/geo?key=0b085d826757c57521465d4faa3f05be&address=${ locationString } `
@@ -119,9 +87,7 @@ Page({
119
87
success ( res ) {
120
88
console . log ( res . data . geocodes . location )
121
89
var location = res . data . geocodes . location
122
- page . setData ( {
123
- location : location
124
- } )
90
+ return location
125
91
}
126
92
} )
127
93
} ,
@@ -138,35 +104,7 @@ Page({
138
104
console . log ( "onLoad" ) ;
139
105
var that = this ;
140
106
141
- tcity . init ( that ) ;
142
-
143
- var cityData = that . data . cityData ;
144
-
145
- const provinces = [ ] ;
146
- const citys = [ ] ;
147
- const countys = [ ] ;
148
-
149
- for ( let i = 0 ; i < cityData . length ; i ++ ) {
150
- provinces . push ( cityData [ i ] . name ) ;
151
- }
152
- console . log ( '省份完成' ) ;
153
- for ( let i = 0 ; i < cityData [ 0 ] . sub . length ; i ++ ) {
154
- citys . push ( cityData [ 0 ] . sub [ i ] . name )
155
- }
156
- console . log ( '城市完成' ) ;
157
- for ( let i = 0 ; i < cityData [ 0 ] . sub [ 0 ] . sub . length ; i ++ ) {
158
- countys . push ( cityData [ 0 ] . sub [ 0 ] . sub [ i ] . name )
159
- }
160
-
161
- that . setData ( {
162
- 'provinces' : provinces ,
163
- 'citys' : citys ,
164
- 'countys' : countys ,
165
- 'originProvince' : cityData [ 0 ] . name ,
166
- 'originCity' : cityData [ 0 ] . sub [ 0 ] . name ,
167
- 'originCounty' : cityData [ 0 ] . sub [ 0 ] . sub [ 0 ] . name
168
- } )
169
- console . log ( '初始化完成' ) ;
107
+
170
108
} ,
171
109
172
110
0 commit comments