blob: a8a5e2dd8c11a71831fda3085763711ad1d4d37d [file] [log] [blame]
qiaowei9579db42020-04-14 13:08:35 +08001var app = {
2
3 // 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) {
guangchao.xu5f13fea2020-07-16 10:35:20 +080011 var refno,msgtype
12 var userid = window.localStorage.getItem("userid");
13 var baseUrl = "https://yy.dlsmk.cn/wisdompolice/app"
qiaowei9579db42020-04-14 13:08:35 +080014 console.log("openNotify:"+event);
15 if(device.platform == "Android") {
guangchao.xu5f13fea2020-07-16 10:35:20 +080016 msgtype = event.extras.msgtype
17 if (msgtype ==="conference"){
18 window.location= baseUrl + "/conference/signupconference?custid="+userid;
19 }else if(msgtype ==="atte1"){
20 window.location= baseUrl + "/atte/reviewindex?custid="+userid;
21 }else if(msgtype ==="atte2"){
22 window.location= baseUrl + "/atte/searchindex?custid="+userid;
23 }else if(msgtype ==="atte3"){
24 window.location= baseUrl + "/atte/reviewClock?custid="+userid;
25 }else if(msgtype ==="atte4"){
26 window.location= baseUrl + "/atte/clockhisindex?custid="+userid;
27 }else{
28 refno = event.extras.refno
29 app.openBill(refno);
30 }
qiaowei9579db42020-04-14 13:08:35 +080031 } else {
32 refno = event.refno
33 window.JPush.setApplicationIconBadgeNumber(0);
guangchao.xu5f13fea2020-07-16 10:35:20 +080034 app.openBill(refno);
qiaowei9579db42020-04-14 13:08:35 +080035 }
guangchao.xu5f13fea2020-07-16 10:35:20 +080036 //console.log("openNotify:"+refno);
qiaowei9579db42020-04-14 13:08:35 +080037 }, false)
38 },
39 openBill:function(billno){
40 window.localStorage.setItem("currentrefno",billno);
41 window.location='billdetail.html';
42 },
43 initJpush: function() {
44 if(device.platform == "Android") {
45 } 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) {
59 } else if(result > 0) {
60 }
61 });
62 var uid = window.localStorage.getItem("uid");
63 window.JPush.setAlias({ sequence: 1, alias: uid },
64 (result) => {
65 var sequence = result.sequence
66 var alias = result.alias
67 //alert(JSON.stringify(result))
68 }, (error) => {
69 var sequence = error.sequence
70 var errorCode = error.code
71 //alert(JSON.stringify(error))
72 })
73 },
74
75 onDeviceReady: function() {
76 var uid = window.localStorage.getItem("token");
77 this.initJpush();
78 $('#scanBtn').click(function() {
79 //window.location = "scan.html";
80 app.checkBefore(function() {
81 app.checkOther(function() {
82 window.location = "scan.html";
83 })
84 })
85 });
86 $('#qrcodeBtn').click(function() {
87 app.checkBefore(function() {
88 app.checkOther(function() {
89 window.location = "qrcode.html";
90 })
91 })
92 });
qiaoweibd656ad2020-06-11 15:12:03 +080093 var userid = window.localStorage.getItem("userid");
qiaowei9579db42020-04-14 13:08:35 +080094 $('#qrcodeBtn1').click(function() {
qiaoweibd656ad2020-06-11 15:12:03 +080095 showRet("https://yy.dlsmk.cn/wisdompolice/app/doorappvisitor?custid="+userid);
96 });
97
98 $('#qingjiaBtn').click(function() {
99
100 //window.location = "https://yy.dlsmk.cn/wisdompolice/app/doorappindex?custid="+userid;
101 });
102 $('#accessBtn').click(function() {
103 //window.location = "https://yy.dlsmk.cn/wisdompolice/app/doorappvisitor?custid="+userid;
qiaowei9579db42020-04-14 13:08:35 +0800104 });
105 /*$('#cardBtn').click(function() {
106 app.checkBefore(function() {
107 app.checkOther(function() {
108 window.location = "card.html";
109 })
110 })
111 });
112 $('#billBtn').click(function() {
113 app.checkBefore(function() {
114 window.location = "bill.html";
115 })
116 });
117 $('#moreBtn').click(function() {
118 app.checkBefore(function() {
119 window.location = "bill.html";
120 })
121 });
122 $('#secBtn').click(function() {
123 //window.location = "security.html";
124 app.checkBefore(function() {
125 app.checkOther(function() {
126 window.location = "security.html";
127 })
128 })
129 });
130
131 $("#doorBtn").click(function(){
132 app.checkBefore(function() {
133 showRet(DOOR_URl);
134 })
135 })*/
136 $("#moreFuncBtn").click(function(){
137 window.location = "more.html";
qiaoweibd656ad2020-06-11 15:12:03 +0800138 //showRet("https://yy.dlsmk.cn/wisdompolice/app/doorappindex?custid="+userid);
qiaowei9579db42020-04-14 13:08:35 +0800139 })
140 $('#usersec').click(function() {
141 app.checkBefore(function() {
142 app.checkOther(function() {
143 window.location = "security.html";
144 })
145 })
146 });
147 $('#accsignbtn').click(function() {
148 app.checkBefore(function() {
149 var signed = window.localStorage.getItem("signed");
150 var cum = new auiDialog({});
151 if (isEmpty(signed) || signed != 'yes') {
152 var confirm = cum.alert({
153 title: "提示",
154 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
155 buttons: ['取消', '去签约']
156 }, function(ret) {
157 if (ret.buttonIndex == 2) {
158 app.toSignCode();
159 }
160 })
161 }else{
162 window.location = 'signxycheck.html'
163 }
164 })
165 });
166 this.initSlider();
167 this.initData();
168 this.backBtn();
169 },
170 backBtn: function(){
171 document.addEventListener("backbutton", function(e){
172 e.preventDefault();
173 navigator.app.exitApp();
174 }, false);
175 },
176 initTab: function() {
177 //$("#maincontent").css("top", $("#maintop").height())
178 var tab = new auiTab({
179 element: document.getElementById("footer"),
180 }, function(ret) {
181 window.localStorage.setItem("tabindex", ret.index);
182
183 changeTab(ret.index);
184 });
185 var tabindex = window.localStorage.getItem("tabindex");
186 if (!tabindex || tabindex == 0) {
187 tabindex = 1
188 }
189 changeTab(tabindex);
190 tab.setActive(tabindex)
191
192 function changeTab(index) {
193 if (index == 1) {
194 $("#main1").show();
195 $("#main2").hide();
196 $("#main3").hide();
197 } else if (index == 2) {
198 $("#main1").hide();
199 $("#main2").show();
200 $("#main3").hide();
201 } else if (index == 3) {
202 $("#main1").hide();
203 $("#main2").hide();
204 $("#main3").show();
205 }
206 }
207 },
208 initSlider:function(){
209 var slide = new auiSlide({
210 container:document.getElementById("startslider"),
qiaowei66edadb2020-04-20 16:51:56 +0800211 "height":240,
qiaowei9579db42020-04-14 13:08:35 +0800212 "speed":500,
213 "pageShow":true,
214 "autoPlay":3000,
215 "pageStyle":'dot',
qiaoweibd656ad2020-06-11 15:12:03 +0800216 "loop":true,
qiaowei9579db42020-04-14 13:08:35 +0800217 'dotPosition':'center',
218 currentPage:currentFun
219 });
220 function currentFun(index){
221 //console.log(index)
222 }
223 },
224 initData: function() {
225 this.loadBill()
226 },
227 loadBill: function() {
228 //$("#loaddata").show()
229 //$("#nodata").hide();
230 var param = {
231 "pageno": 1,
qiaoweibd656ad2020-06-11 15:12:03 +0800232 "type":"police",
qiaowei9579db42020-04-14 13:08:35 +0800233 "platform":device.platform
234 }
235 V1Bills(param, function(ok, ret) {
236 if (ok) {
qiaowei9579db42020-04-14 13:08:35 +0800237 if (ret.code == 200) {
qiaoweibd656ad2020-06-11 15:12:03 +0800238 console.log(ret)
239 //ret.version='1.3.9';
240 //ret.versionmsg='新版本';
241 //ret.versionurl='https://yy.dlsmk.cn/app/download/wisdompolice.apk';
qiaowei9579db42020-04-14 13:08:35 +0800242 app.checkVersion(ret.version,ret.minversion,ret.versionmsg,ret.versionurl);
243 //app.checkVersion("1.3.9","1","new func","https://shouji.baidu.com/software/26706357.html");
244 //$("#maingt").text(ret.t + "!")
245 $("#user-amount").text(ret.amount)
246 $("#user-point").text(ret.point)
247 if (ret.needrebind) {
248 window.localStorage.removeItem("userid");
249 } else {
250 window.localStorage.setItem("userid", ret.userid);
251 }
252 window.localStorage.setItem("signed", ret.signed);
253 window.localStorage.setItem("paypwdset", ret.paypwdset);
254 window.localStorage.setItem("name", ret.name);
255 if (ret.page && ret.page.count > 0) {
256 GLOBAL_TODAY = ret.today;
257 GLOBAL_YESTERDAY = ret.yesterday;
258 //app.initBillView(ret.page)
259 app.initView();
260 } else {
261 //$("#loaddata").hide()
262 //$("#nodatahint").text("暂无数据")
263 //$("#nodata").show();
264 app.initView();
265 }
266 } else {
267 //$("#loaddata").hide()
268 //$("#nodatahint").text("数据加载异常")
269 //$("#nodata").show();
270 app.initView();
271 }
272 } else {
273 //$("#loaddata").hide()
274 //$("#nodatahint").text("请求数据失败")
275 //$("#nodata").show();
276 app.initView();
277 }
278 })
279 },
280 checkVersion:function(ver,minver,m,url){
281 cordova.getAppVersion.getVersionNumber(function (version) {
282 //alert(version);
283 //alert(version);
284 if(ver>version){
qiaoweibd656ad2020-06-11 15:12:03 +0800285 $("#versioncheck").html('<div class="aui-dot" style="position:relative;top:0; right:0;display:inline-block;"></div>新版本'+ver);
qiaowei9579db42020-04-14 13:08:35 +0800286 var cum = new auiDialog({});
287 var confirm = cum.alert({
288 title: "有新的版本",
289 msg: m,
290 buttons: ['取消', '去更新']
291 }, function(ret) {
292 if (ret.buttonIndex == 2) {
qiaoweibd656ad2020-06-11 15:12:03 +0800293 //cordova.InAppBrowser.open(url, '_system', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');
294 window.open(url,"_system",'');
qiaowei9579db42020-04-14 13:08:35 +0800295 }
296 })
qiaoweibd656ad2020-06-11 15:12:03 +0800297 }else{
298 $("#versioncheck").html('已是最新版'+version);
qiaowei9579db42020-04-14 13:08:35 +0800299 }
300 });
301 },
302 initBillView: function(page) {
303 var html = '';
304 for (var i = 0; i < page.data.length; i++) {
305 var bean = page.data[i]
306 html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">';
307 html += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
308 html += '</div><div class="aui-card-list-user-name">';
309 html += '<div>' + bean.transdesc + '</div>';
310 if (bean.tradeflag == 'in') {
311 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
312 } else {
313 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
314 }
315 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>';
316 }
317 $("#billcontent").html(html);
318 $("#loaddata").hide()
319 $("#nodata").hide();
320 $("#billcontent").show();
321
322 },
323 initView: function() {
324 var userid = window.localStorage.getItem("userid");
325 var signed = window.localStorage.getItem("signed");
326 if (isEmpty(userid)) {
327 $("#userbank").text("未绑定");
328 $("#userbank").css("color", "red")
329 } else {
330 $("#userbank").text("已绑定");
331 $("userbank").css("color", "#757575");
332 }
333 if (isEmpty(signed) || signed != 'yes') {
334 $("#usersign").text("未签约");
335 $("#usersign").css("color", "red")
336 } else {
337 $("#usersign").text("已签约");
338 $("usersign").css("color", "#757575");
339 }
340 var phone = window.localStorage.getItem("phoneX");
341 if (!isEmpty(phone)) {
342 $("#userphone").text(phone)
343 }
344 var name = window.localStorage.getItem("name");
345 if (isEmpty(name)) {
346 $("#username").text("匿名")
347 } else {
348 $("#username").text(name)
349 $("#homename").text(name)
350 }
351 },
352 checkBefore: function(callback) {
353 var uid = window.localStorage.getItem("token");
354 if (isEmpty(uid)) {
355 window.location = "login.html";
356 } else {
357 var userid = window.localStorage.getItem("userid");
358 if (isEmpty(userid)) {
359 var cum = new auiDialog({});
360 var confirm = cum.alert({
361 title: "提示",
sijun.li09bd57a2020-04-21 18:52:28 +0800362 msg: '为了不影响您正常使用相关功能,请先进行市民卡签约',
363 buttons: ['取消', '去签约']
qiaowei9579db42020-04-14 13:08:35 +0800364 }, function(ret) {
365 if (ret.buttonIndex == 2) {
366 window.location = 'bindcard.html'
367 }
368 })
369 } else {
370 if (callback) {
371 callback()
372 }
373 }
374 }
375 },
376 checkOther: function(callback) {
377 var signed = window.localStorage.getItem("signed");
378 var cum = new auiDialog({});
379
380 if (isEmpty(signed) || signed != 'yes') {
381 var confirm = cum.alert({
382 title: "提示",
383 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
384 buttons: ['取消', '去签约']
385 }, function(ret) {
386 if (ret.buttonIndex == 2) {
387 app.toSignCode();
388 }
389 })
390 } else {
391 if (callback) {
392 callback()
393 }
394 }
395 },
396 toSignCode: function(){
397 var param = {
398 }
399 V1Bindcardcode(param, function(ok, ret) {
400 if (ok) {
401 if (ret.code == 200) {
402 window.location = 'bindcheck.html'
403 } else {
404 $.alert(ret.msg, "错误");
405 }
406 } else {
407 $.alert("请求失败了 " + ret.status + ",请稍后再试", "错误");
408 }
409 })
410 },
411 toSign: function() {
412 window.location = 'signxycheck.html'
413 },
414 toBillDetail: function(refno) {
415 window.localStorage.setItem("currentrefno", refno);
416 window.location = 'billdetail.html';
417 },
418 toCard: function() {
sijun.li09bd57a2020-04-21 18:52:28 +0800419 var signed = window.localStorage.getItem("signed");
420 if (isEmpty(signed) || signed != 'yes') {
qiaowei9579db42020-04-14 13:08:35 +0800421 window.location = 'bindcard.html'
sijun.li09bd57a2020-04-21 18:52:28 +0800422 }else{
qiaowei9579db42020-04-14 13:08:35 +0800423 window.location = 'cardinfor.html'
424 }
425 },
426 logout:function(){
427 window.localStorage.removeItem("token");
428 window.location = "login.html";
qiaoweibd656ad2020-06-11 15:12:03 +0800429 },
430 verisonCheck:function(){
431 var param = {
432 "pageno": 1,
433 "type":"police",
434 "platform":device.platform
435 }
436 V1Bills(param, function(ok, ret) {
437 if (ok) {
438 if (ret.code == 200) {
439 console.log(ret)
440 //ret.version='1.3.9';
441 //ret.versionmsg='新版本';
442 //ret.versionurl='https://yy.dlsmk.cn/app/download/wisdompolice.apk';
443 app.checkVersion(ret.version,ret.minversion,ret.versionmsg,ret.versionurl);
444 } else {
445 }
446 } else {
447 }
448 })
qiaowei9579db42020-04-14 13:08:35 +0800449 }
450};
451app.initialize();
452
453function showRet(url) {
454 if(isEmpty(url)){
455 return;
456 }
457 var userid = window.localStorage.getItem("userid");
458 //if (url.indexOf("yy.dlsmk.cn")>=0) {
459 if(url.indexOf("?")>0){
460 url=url+'&userid='+userid;
461 }else{
462 url=url+'?userid='+userid;
463 }
464 //}
465 console.log(url)
466 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
467 statusbar: {
468 color: '#03a9f4ff'
469 },
470 toolbar: {
471 height: 44,
472 color: '#03a9f4ff'
473 },
474 title: {
475 color: '#ffffffff',
476 showPageTitle: true
477 },
478 backButton: {
qiaoweibd656ad2020-06-11 15:12:03 +0800479 wwwImage: 'img/back.png',
480 wwwImagePressed: 'img/back.png',
qiaowei9579db42020-04-14 13:08:35 +0800481 align: 'left',
482 event: 'backPressed'
483 },
qiaowei9579db42020-04-14 13:08:35 +0800484 backButtonCanClose: true
qiaoweibd656ad2020-06-11 15:12:03 +0800485 }).addEventListener('backPressed', function(e) {
486 //alert('back pressed');
487 }).addEventListener('closePressed', function(e) {
488 //alert('closePressed pressed');
qiaowei9579db42020-04-14 13:08:35 +0800489 inAppBrowserRef.close();
qiaoweibd656ad2020-06-11 15:12:03 +0800490 window.location = "main.html"
491 });
qiaowei9579db42020-04-14 13:08:35 +0800492 }