Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit ba03982

Browse files
committed
_
1 parent 4e7d3e6 commit ba03982

File tree

4 files changed

+51
-16618
lines changed

4 files changed

+51
-16618
lines changed

pages/driver/driver.js

+35-97
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// pages/driver/driver.js
2-
var tcity = require("../../utils/citys.js");
32
var app = getApp()
43
Page({
54

@@ -14,15 +13,15 @@ Page({
1413
truckTypeIndex: 0,
1514
lengthIndex: 0,
1615
axlesIndex: 0,
17-
provinces: [],
18-
originProvince: "",
19-
citys: [],
20-
originCity: "",
21-
countys: [],
22-
originCounty: '',
16+
cityArray: ['成都', '上海', '深圳', '广州', '重庆', '北京', '石家庄', '天津', '青岛', '昆明', '西安', '乌鲁木齐', '长沙', '武汉', '厦门', '杭州', '南京', '太原', '呼和浩特', '沈阳'],
17+
originCityIndex: 0,
2318
value: [0, 0, 0],
2419
values: [0, 0, 0],
25-
condition: false
20+
condition: false,
21+
destination: false,
22+
destinationCityIndex: 0,
23+
originCity: '成都',
24+
destinationCity: '成都'
2625
},
2726

2827

@@ -47,70 +46,39 @@ Page({
4746
});
4847
},
4948

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})
7955
}
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+
},
8757

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+
})
10567
},
106-
open: function () {
68+
69+
bindDestinationChange: function (e) {
70+
let page = this;
10771
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]
10977
})
11078
},
11179

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]
11482

11583
let page = this;
11684
var url = `https://restapi.amap.com/v3/geocode/geo?key=0b085d826757c57521465d4faa3f05be&address=${locationString}`
@@ -119,9 +87,7 @@ Page({
11987
success(res) {
12088
console.log(res.data.geocodes.location)
12189
var location = res.data.geocodes.location
122-
page.setData({
123-
location: location
124-
})
90+
return location
12591
}
12692
})
12793
},
@@ -138,35 +104,7 @@ Page({
138104
console.log("onLoad");
139105
var that = this;
140106

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+
170108
},
171109

172110

pages/driver/driver.wxml

+8-26
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
<!--pages/driver/driver.wxml-->
22
<view class="container">
3+
<view class='city-picker'>
4+
<picker bindchange="bindOriginChange" value="{{originCityIndex}}" range="{{cityArray}}">{{originCity}}</picker>
5+
</view>
6+
<button bindtap='chooseDestination' class="{{destination ? 'selected' : 'not-selected' }}">选择目的地</button>
7+
<view wx:if="{{destination}}" class='city-picker'>
8+
<picker bindchange="bindDestinationChange" value="{{destinationCityIndex}}" range="{{cityArray}}">{{destinationCity}}
9+
</picker>
10+
</view>
311
<form bindsubmit="formSubmit">
412
<view class="form-container col">
513

614
<view><input name="Driver License" class="" placeholder="Driver License #" /></view>
7-
origin destination
8-
<view class="loc-picker">
9-
10-
<view class="input">
11-
<input placeholder="选择地址" value="{{originProvince}}-{{originCity}}-{{originCounty}}" focus="{{focus}}" bindfocus="open" />
12-
</view>
13-
</view>
14-
15-
<view wx:if="{{condition}}" class="citypicker">
16-
<picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" value="{{value}}" bindchange="bindChangeOrigin" class="citybody">
17-
<view class="cityheader">
18-
<view bindtap="open" class="city-cancel">取消</view>
19-
<view bindtap="open" class="city-true">确定</view>
20-
</view>
21-
<picker-view-column>
22-
<view wx:for="{{provinces}}" wx:key="item" style="line-height: 50px;padding-left:10px;">{{item}}</view>
23-
</picker-view-column>
24-
<picker-view-column>
25-
<view wx:for="{{citys}}" wx:key="item" style="line-height: 50px;padding-left:10px;">{{item}}</view>
26-
</picker-view-column>
27-
<picker-view-column>
28-
<view wx:for="{{countys}}" wx:key="item" style="line-height: 50px;padding-left:10px;">{{item}}</view>
29-
</picker-view-column>
30-
</picker-view>
31-
</view>
32-
3315
<view class="row">
3416
truck type:
3517
<view>

pages/driver/driver.wxss

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ input {
88
border: 1px solid black;
99
}
1010

11+
.selected {
12+
background-color: peachpuff;
13+
}
14+
15+
.not-selected {
16+
background-color: white;
17+
}
18+
1119
.picker-view {
1220
width: 100%;
1321
display: flex;

0 commit comments

Comments
 (0)