mainController.js
6.72 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
212
213
214
215
216
217
218
219
220
angular.module('myApp')
.controller('mainController',['$scope','$rootScope','dingdaService','$state','globalService',function($scope,$rootScope,dingdaService,$state,globalService){
$rootScope.isRendBike = false;
$rootScope.isLoadFinish = true;
$scope.unfinishOrder = {};
var init = function() {
// globalService.init();
$scope.userinfo = globalService.getData("user");
if(!$scope.userinfo) {
$scope.userinfo = {};
$scope.userinfo.userName = "未登录";
$scope.userinfo.loginState = false;
} else {
$scope.userinfo.loginState = true;
// alert("getUnfinishedOrder")
dingdaService.getUnfinishedOrder().success(function(data , status){
// alert(JSON.stringify(data))
if(data.data.unfinishedOrder.id) {
$rootScope.isRendBike = true;
$scope.unfinishOrder = data.data.unfinishedOrder;
}
if(data.data.unfinishedOrder.status == 200) {
layer.open({
content: '您有未支付的订单,是否前往支付?',
btn: ['确认', '取消'],
shadeClose: false,
yes: function(index){
layer.close(index);
$state.go('tripDetail' , { orderId : $scope.unfinishOrder.id});
return;
},no: function(index){
layer.close(index);
}
});
}
}).error(function(data , status) {
console.log(JSON.stringify(data))
})
}
$scope.moduleList = [];
$scope.moduleList.push({
name : "行程记录",
icon : "images/trip.png",
state : "trip"
});
$scope.moduleList.push({
name : "钱包",
icon : "images/wallet.png",
state : "wallet"
});
$scope.moduleList.push({
name : "保证金",
icon : "images/bond.png",
state : "bond"
});
$scope.moduleList.push({
name : "联系我们",
icon : "images/contact.png",
state : "contact"
});
$scope.moduleList.push({
name : "意见反馈",
icon : "images/opinion.png",
state : "opinion"
});
}
$scope.doAction = function(index) {
if($scope.checkLogin()) {
var arg = {};
if(index == 2 || index == 4) {
arg = {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude };
}
if(index == 3) {
location.href = "http://wx.dy.dingdatech.com/contactUs.html";
} else {
$state.go($scope.moduleList[index].state, arg);
}
}
}
$scope.checkLogin = function() {
if(!globalService.getData("user")) {
$state.go('login', {}, {reload: true});
return false;
}
return true;
}
$scope.logout = function() {
$scope.userinfo = {};
$scope.userinfo.userName = "未登录";
$scope.userinfo.loginState = false;
globalService.clearData("user");
location.reload()
}
var initScan = function() {
$rootScope.openScan = false;
$rootScope.openDetail = false;
$rootScope.openMenu = false;
$rootScope.openRing = false;
$rootScope.$watch("openScan",function(newVal, oldVal){
if(newVal !== oldVal && newVal) {
// if(!$scope.checkLogin()) {
// return;
// }
// if($scope.unfinishOrder.status == 200) {
// $state.go('tripDetail' , { orderId : $scope.unfinishOrder.id});
// return;
// }
$rootScope.openScan = false;
if(appClient){
appClient.getERCode('postERCode', function (res) {
layer.open({
content: JSON.stringify(res) + 'cb',
time: 10
});
}, '')
} else {
layer.open({
content: 'JSBridge 初始化失败',
time:2
});
}
// wx.scanQRCode({
// needResult: 1, // 默认为1,扫描结果由微信处理,1则直接返回扫描结果,
// scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
// success: function (res) {
// var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
// // alert(result);
// dingdaService.verifyScanCode(result).success(function(data , status){
// // alert(JSON.stringify(data))
// if(data.meta.code == 200) {
// if(data.data.orderDetail.id) {
//
// layer.open({
// content: "租车成功,订单号为:" + data.data.orderDetail.id,
// time:2
// });
// // alert("租车成功,订单号为:" + data.data.orderDetail.id);
// $rootScope.isRendBike = true;
//
// $state.go('rentDetail', {}, {reload: true});
//
// }
// } else if(data.meta.code == 202) {
// layer.open({
// content: data.meta.message,
// time:2
// });
// $state.go('bond', {longitude: $rootScope.currentPoint.longitude , latitude: $rootScope.currentPoint.latitude });
// } else {
// layer.open({
// content: data.meta.message,
// time:2
// });
// }
// }).error(function(data , status){
// layer.open({
// content: "租车失败" + JSON.stringify(data),
// time:2
// });
// });
// }
// });
}
})
$rootScope.$watch("openDetail",function(newVal, oldVal){
if(newVal === oldVal) return;
if(newVal) {
dingdaService.getUnfinishedOrder().success(function(data , status){
if(data.meta.code == 200) {
if(!data.data.unfinishedOrder.id) {
layer.open({
content: '租车完成',
time:2
});
// alert("租车完成")
$state.go('main');
}
}
if(data.data.unfinishedOrder.status == 200) {
$state.go('tripDetail' , { orderId : data.data.unfinishedOrder.id});
} else {
$state.go('rentDetail', {}, {reload: true});
}
}).error(function(data , status) {
console.log(JSON.stringify(data))
})
}
})
$rootScope.$watch("openRing",function(newVal, oldVal){
// TODO open new message
})
$rootScope.$watch("isLoadFinish" , function(newVal , oldVal){
if(newVal === oldVal) return;
if(newVal) {
document.getElementById("sliderMenu").style.display = "block";
}
})
document.getElementById("sliderMenu").addEventListener("touchmove", function(){
return;
} , false);
}
// mui.init();
initScan();
init();
}]);