blob: 6a8182a75a623d72f9fb53ef42f3c293894525f4 [file] [log] [blame]
qiaowei9579db42020-04-14 13:08:35 +08001var app = {
2
guangchao.xu5ed58252020-07-21 18:15:56 +08003 // Application Constructor
4 initialize: function() {
5 this.initTab();
6 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
7 document.addEventListener('jpush.receiveRegistrationId', function(event) {
8 console.log(event.registrationId)
9 }, false)
10 document.addEventListener("jpush.openNotification", function(event) {
11 var refno, msgtype
12 var userid = window.localStorage.getItem("userid");
13 var baseUrl = "https://yy.dlsmk.cn/wisdompolice/app"
14 console.log("openNotify:" + event);
15 if (device.platform == "Android") {
16 msgtype = event.extras.msgtype
17 // window.location = 'more.html'
18 if (msgtype === "conference") {
19 showRet(baseUrl + "/conference/signupconference?userId=" + userid);
20 } else if (msgtype === "atte1") {
21 showRet(baseUrl + "/atte/reviewindex?custid=" + userid);
22 } else if (msgtype === "atte2") {
23 showRet(baseUrl + "/atte/searchindex?custid=" + userid);
24 } else if (msgtype === "atte3") {
25 showRet(baseUrl + "/atte/reviewClock?custid=" + userid);
26 } else if (msgtype === "atte4") {
27 showRet(baseUrl + "/atte/clockhisindex?custid=" + userid);
28 } else {
29 refno = event.extras.refno
30 app.openBill(refno);
31 }
32 } else {
33 refno = event.refno
34 window.JPush.setApplicationIconBadgeNumber(0);
guangchao.xu5f13fea2020-07-16 10:35:20 +080035 app.openBill(refno);
36 }
guangchao.xu5ed58252020-07-21 18:15:56 +080037 //console.log("openNotify:"+refno);
38 }, false)
39 },
40 openBill: function(billno) {
41 window.localStorage.setItem("currentrefno", billno);
42 window.location = 'billdetail.html';
43 },
44 initJpush: function() {
45 if (device.platform == "Android") {} else {
46 window.JPush.setApplicationIconBadgeNumber(0);
47 }
48 window.JPush.init();
49 window.JPush.setDebugMode(true);
50 window.JPush.isPushStopped(function(result) {
51 if (result == 0) {
52 //window.JPush.resumePush();
53 } else {
54 window.JPush.resumePush();
55 }
56 });
57 window.JPush.getUserNotificationSettings(function(result) {
58 if (result == 0) {} else if (result > 0) {}
59 });
60 var uid = window.localStorage.getItem("uid");
61 window.JPush.setAlias({
62 sequence: 1,
63 alias: uid
64 },
65 (result) => {
66 var sequence = result.sequence
67 var alias = result.alias
68 //alert(JSON.stringify(result))
69 }, (error) => {
70 var sequence = error.sequence
71 var errorCode = error.code
72 //alert(JSON.stringify(error))
73 })
74 },
qiaowei9579db42020-04-14 13:08:35 +080075
guangchao.xu5ed58252020-07-21 18:15:56 +080076 onDeviceReady: function() {
77 var uid = window.localStorage.getItem("token");
78 this.initJpush();
79 $('#scanBtn').click(function() {
80 //window.location = "scan.html";
81 app.checkBefore(function() {
82 app.checkOther(function() {
83 window.location = "scan.html";
84 })
85 })
86 });
87 $('#qrcodeBtn').click(function() {
88 app.checkBefore(function() {
89 app.checkOther(function() {
90 window.location = "qrcode.html";
91 })
92 })
93 });
94 var userid = window.localStorage.getItem("userid");
95 $('#qrcodeBtn1').click(function() {
96 showRet("https://yy.dlsmk.cn/wisdompolice/app/doorappvisitor?custid=" + userid);
97 });
98
99 $('#qingjiaBtn').click(function() {
100
101 //window.location = "https://yy.dlsmk.cn/wisdompolice/app/doorappindex?custid="+userid;
102 });
103 $('#accessBtn').click(function() {
104 //window.location = "https://yy.dlsmk.cn/wisdompolice/app/doorappvisitor?custid="+userid;
105 });
106 /*$('#cardBtn').click(function() {
107 app.checkBefore(function() {
108 app.checkOther(function() {
109 window.location = "card.html";
110 })
111 })
112 });
113 $('#billBtn').click(function() {
114 app.checkBefore(function() {
115 window.location = "bill.html";
116 })
117 });
118 $('#moreBtn').click(function() {
119 app.checkBefore(function() {
120 window.location = "bill.html";
121 })
122 });
123 $('#secBtn').click(function() {
124 //window.location = "security.html";
125 app.checkBefore(function() {
126 app.checkOther(function() {
127 window.location = "security.html";
128 })
129 })
130 });
qiaoweibd656ad2020-06-11 15:12:03 +0800131
guangchao.xu5ed58252020-07-21 18:15:56 +0800132 $("#doorBtn").click(function(){
133 app.checkBefore(function() {
134 showRet(DOOR_URl);
135 })
136 })*/
137 $("#moreFuncBtn").click(function() {
138 window.location = "more.html";
139 //showRet("https://yy.dlsmk.cn/wisdompolice/app/doorappindex?custid="+userid);
140 })
141 $('#usersec').click(function() {
142 app.checkBefore(function() {
143 app.checkOther(function() {
144 window.location = "security.html";
145 })
146 })
147 });
148 $('#accsignbtn').click(function() {
149 app.checkBefore(function() {
150 var signed = window.localStorage.getItem("signed");
151 var cum = new auiDialog({});
152 if (isEmpty(signed) || signed != 'yes') {
153 var confirm = cum.alert({
154 title: "提示",
155 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
156 buttons: ['取消', '去签约']
157 }, function(ret) {
158 if (ret.buttonIndex == 2) {
159 app.toSignCode();
160 }
161 })
162 } else {
163 window.location = 'signxycheck.html'
164 }
165 })
166 });
167 this.initSlider();
168 this.initData();
169 this.backBtn();
170 },
171 backBtn: function() {
172 document.addEventListener("backbutton", function(e) {
173 e.preventDefault();
174 navigator.app.exitApp();
175 }, false);
176 },
177 initTab: function() {
178 //$("#maincontent").css("top", $("#maintop").height())
179 var tab = new auiTab({
180 element: document.getElementById("footer"),
181 }, function(ret) {
182 window.localStorage.setItem("tabindex", ret.index);
qiaowei9579db42020-04-14 13:08:35 +0800183
guangchao.xu5ed58252020-07-21 18:15:56 +0800184 changeTab(ret.index);
185 });
186 var tabindex = window.localStorage.getItem("tabindex");
187 if (!tabindex || tabindex == 0) {
188 tabindex = 1
189 }
190 changeTab(tabindex);
191 tab.setActive(tabindex)
qiaowei9579db42020-04-14 13:08:35 +0800192
guangchao.xu5ed58252020-07-21 18:15:56 +0800193 function changeTab(index) {
194 if (index == 1) {
195 $("#main1").show();
196 $("#main2").hide();
197 $("#main3").hide();
198 } else if (index == 2) {
199 $("#main1").hide();
200 $("#main2").show();
201 $("#main3").hide();
202 } else if (index == 3) {
203 $("#main1").hide();
204 $("#main2").hide();
205 $("#main3").show();
206 }
207 }
208 },
209 initSlider: function() {
210 var slide = new auiSlide({
211 container: document.getElementById("startslider"),
212 "height": 240,
213 "speed": 500,
214 "pageShow": true,
215 "autoPlay": 3000,
216 "pageStyle": 'dot',
217 "loop": true,
218 'dotPosition': 'center',
219 currentPage: currentFun
220 });
qiaowei9579db42020-04-14 13:08:35 +0800221
guangchao.xu5ed58252020-07-21 18:15:56 +0800222 function currentFun(index) {
223 //console.log(index)
224 }
225 },
226 initData: function() {
227 this.loadBill()
228 },
229 loadBill: function() {
230 //$("#loaddata").show()
231 //$("#nodata").hide();
232 var param = {
233 "pageno": 1,
234 "type": "police",
235 "platform": device.platform
236 }
237 V1Bills(param, function(ok, ret) {
238 if (ok) {
239 if (ret.code == 200) {
240 console.log(ret)
241 //ret.version='1.3.9';
242 //ret.versionmsg='新版本';
243 //ret.versionurl='https://yy.dlsmk.cn/app/download/wisdompolice.apk';
244 app.checkVersion(ret.version, ret.minversion, ret.versionmsg, ret.versionurl);
245 //app.checkVersion("1.3.9","1","new func","https://shouji.baidu.com/software/26706357.html");
246 //$("#maingt").text(ret.t + "!")
247 $("#user-amount").text(ret.amount)
248 $("#user-point").text(ret.point)
249 if (ret.needrebind) {
250 window.localStorage.removeItem("userid");
251 } else {
252 window.localStorage.setItem("userid", ret.userid);
253 }
254 window.localStorage.setItem("signed", ret.signed);
255 window.localStorage.setItem("paypwdset", ret.paypwdset);
256 window.localStorage.setItem("name", ret.name);
257 if (ret.page && ret.page.count > 0) {
258 GLOBAL_TODAY = ret.today;
259 GLOBAL_YESTERDAY = ret.yesterday;
260 //app.initBillView(ret.page)
261 app.initView();
262 } else {
263 //$("#loaddata").hide()
264 //$("#nodatahint").text("暂无数据")
265 //$("#nodata").show();
266 app.initView();
267 }
268 } else {
269 //$("#loaddata").hide()
270 //$("#nodatahint").text("数据加载异常")
271 //$("#nodata").show();
272 app.initView();
273 }
274 } else {
275 //$("#loaddata").hide()
276 //$("#nodatahint").text("请求数据失败")
277 //$("#nodata").show();
278 app.initView();
279 }
280 })
281 },
282 checkVersion: function(ver, minver, m, url) {
283 cordova.getAppVersion.getVersionNumber(function(version) {
284 //alert(version);
285 //alert(version);
286 if (ver > version) {
287 $("#versioncheck").html(
288 '<div class="aui-dot" style="position:relative;top:0; right:0;display:inline-block;"></div>新版本' + ver);
289 var cum = new auiDialog({});
290 var confirm = cum.alert({
291 title: "有新的版本",
292 msg: m,
293 buttons: ['取消', '去更新']
294 }, function(ret) {
295 if (ret.buttonIndex == 2) {
296 //cordova.InAppBrowser.open(url, '_system', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');
297 window.open(url, "_system", '');
298 }
299 })
300 } else {
301 $("#versioncheck").html('已是最新版' + version);
302 }
303 });
304 },
305 initBillView: function(page) {
306 var html = '';
307 for (var i = 0; i < page.data.length; i++) {
308 var bean = page.data[i]
309 html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">';
310 html +=
311 '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
312 html += '</div><div class="aui-card-list-user-name">';
313 html += '<div>' + bean.transdesc + '</div>';
314 if (bean.tradeflag == 'in') {
315 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
316 } else {
317 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
318 }
319 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) +
320 '</div></div>';
321 }
322 $("#billcontent").html(html);
323 $("#loaddata").hide()
324 $("#nodata").hide();
325 $("#billcontent").show();
qiaowei9579db42020-04-14 13:08:35 +0800326
guangchao.xu5ed58252020-07-21 18:15:56 +0800327 },
328 initView: function() {
329 var userid = window.localStorage.getItem("userid");
330 var signed = window.localStorage.getItem("signed");
331 if (isEmpty(userid)) {
332 $("#userbank").text("未绑定");
333 $("#userbank").css("color", "red")
334 } else {
335 $("#userbank").text("已绑定");
336 $("userbank").css("color", "#757575");
337 }
338 if (isEmpty(signed) || signed != 'yes') {
339 $("#usersign").text("未签约");
340 $("#usersign").css("color", "red")
341 } else {
342 $("#usersign").text("已签约");
343 $("usersign").css("color", "#757575");
344 }
345 var phone = window.localStorage.getItem("phoneX");
346 if (!isEmpty(phone)) {
347 $("#userphone").text(phone)
348 }
349 var name = window.localStorage.getItem("name");
350 if (isEmpty(name)) {
351 $("#username").text("匿名")
352 } else {
353 $("#username").text(name)
354 $("#homename").text(name)
355 }
356 },
357 checkBefore: function(callback) {
358 var uid = window.localStorage.getItem("token");
359 if (isEmpty(uid)) {
360 window.location = "login.html";
361 } else {
362 var userid = window.localStorage.getItem("userid");
363 if (isEmpty(userid)) {
364 var cum = new auiDialog({});
365 var confirm = cum.alert({
366 title: "提示",
367 msg: '为了不影响您正常使用相关功能,请先进行市民卡签约',
368 buttons: ['取消', '去签约']
369 }, function(ret) {
370 if (ret.buttonIndex == 2) {
371 window.location = 'bindcard.html'
372 }
373 })
374 } else {
375 if (callback) {
376 callback()
377 }
378 }
379 }
380 },
381 checkOther: function(callback) {
382 var signed = window.localStorage.getItem("signed");
383 var cum = new auiDialog({});
384
385 if (isEmpty(signed) || signed != 'yes') {
386 var confirm = cum.alert({
387 title: "提示",
388 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
389 buttons: ['取消', '去签约']
390 }, function(ret) {
391 if (ret.buttonIndex == 2) {
392 app.toSignCode();
393 }
394 })
395 } else {
396 if (callback) {
397 callback()
398 }
399 }
400 },
401 toSignCode: function() {
402 var param = {}
403 V1Bindcardcode(param, function(ok, ret) {
404 if (ok) {
405 if (ret.code == 200) {
406 window.location = 'bindcheck.html'
407 } else {
408 $.alert(ret.msg, "错误");
409 }
410 } else {
411 $.alert("请求失败了 " + ret.status + ",请稍后再试", "错误");
412 }
413 })
414 },
415 toSign: function() {
416 window.location = 'signxycheck.html'
417 },
418 toBillDetail: function(refno) {
419 window.localStorage.setItem("currentrefno", refno);
420 window.location = 'billdetail.html';
421 },
422 toCard: function() {
423 var signed = window.localStorage.getItem("signed");
424 if (isEmpty(signed) || signed != 'yes') {
425 window.location = 'bindcard.html'
426 } else {
427 window.location = 'cardinfor.html'
428 }
429 },
430 logout: function() {
431 window.localStorage.removeItem("token");
432 window.location = "login.html";
433 },
434 verisonCheck: function() {
435 var param = {
436 "pageno": 1,
437 "type": "police",
438 "platform": device.platform
439 }
440 V1Bills(param, function(ok, ret) {
441 if (ok) {
442 if (ret.code == 200) {
443 console.log(ret)
444 //ret.version='1.3.9';
445 //ret.versionmsg='新版本';
446 //ret.versionurl='https://yy.dlsmk.cn/app/download/wisdompolice.apk';
447 app.checkVersion(ret.version, ret.minversion, ret.versionmsg, ret.versionurl);
448 } else {}
449 } else {}
450 })
451 }
qiaowei9579db42020-04-14 13:08:35 +0800452};
453app.initialize();
454
455function showRet(url) {
guangchao.xu5ed58252020-07-21 18:15:56 +0800456 if (isEmpty(url)) {
457 return;
458 }
459 var userid = window.localStorage.getItem("userid");
460 //if (url.indexOf("yy.dlsmk.cn")>=0) {
461 if (url.indexOf("?") > 0) {
462 url = url + '&userid=' + userid;
463 } else {
464 url = url + '?userid=' + userid;
465 }
466 //}
467 console.log(url)
468 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
469 statusbar: {
470 color: '#03a9f4ff'
471 },
472 toolbar: {
473 height: 44,
474 color: '#03a9f4ff'
475 },
476 title: {
477 color: '#ffffffff',
478 showPageTitle: true
479 },
480 backButton: {
481 wwwImage: 'img/back.png',
482 wwwImagePressed: 'img/back.png',
483 align: 'left',
484 event: 'backPressed'
485 },
486 menu: {
487 wwwImage: 'img/share.png',
488 wwwImagePressed: 'img/share.png',
489 align: 'right',
490 items: [{
491 event: 'shareQQ',
492 label: '分享至QQ好友'
493 },
494 {
495 event: 'shareWX',
496 label: '分享至微信好友'
497 }
498 ]
499 },
500 backButtonCanClose: true
501 }).addEventListener('backPressed', function(e) {
502 // if (window.localStorage.getItem("share") === 1) {
503 // alert("share")
504 // inAppBrowserRef.close();
505 // window.location = "share.html"
506 // }
507 }).addEventListener('closePressed', function(e) {
508 //alert('closePressed pressed');
509 inAppBrowserRef.close();
510 window.location = "main.html"
511 })
512 .addEventListener('shareQQ', function(e) {
513 var visitorid = e.url.split("=")[1]
514 var path = 'https://yy.dlsmk.cn/wisdompolice/app/getapplyqrcode?visitorid=' + visitorid
515 var args = {};
516 args.client = QQSDK.ClientType.QQ; //QQSDK.ClientType.QQ,QQSDK.ClientType.TIM;
517 args.scene = QQSDK.Scene.QQ; //QQSDK.Scene.QQZone,QQSDK.Scene.Favorite
518 args.title = '大理APP';
519 args.description = '访客二维码';
520 args.url = path;
521 // args.image = 'https://cordova.apache.org/static/img/cordova_bot.png';
522 QQSDK.shareNews(function() {
523 alert('分享成功');
524 }, function(failReason) {
525 alert(failReason);
526 }, args);
527 })
528 .addEventListener('shareWX', function(e) {
529 var visitorid = e.url.split("=")[1]
530 var path = 'https://yy.dlsmk.cn/wisdompolice/app/getapplyqrcode?visitorid=' + visitorid
531 Wechat.share({
532 message: {
533 title: "大理App分享",
534 description: "访客二维码",
535 thumb: "www/img/thumbnail.png",
536 media: {
537 type: Wechat.Type.WEBPAGE,
538 webpageUrl: path
539 }
540 },
541 scene: Wechat.Scene.SESSION, // share to Timeline
542 }, function() {
543 alert("分享成功");
544 }, function(reason) {
545 alert("Failed: " + reason);
546 })
547 });
548}