blob: f19972eec3484ee1c0b99e347e77ae58a5d80c6d [file] [log] [blame]
qiaoweif044a742019-07-10 16:04:20 +08001var app = {
guangchao.xu5ed58252020-07-21 18:15:56 +08002 // Application Constructor
3 initialize: function() {
4 this.initTab();
5 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
6 document.addEventListener('jpush.receiveRegistrationId', function(event) {
7 console.log(event.registrationId)
8 }, false)
9 document.addEventListener("jpush.openNotification", function(event) {
10 var refno
11 console.log("openNotify:" + event);
12 if (device.platform == "Android") {
13 refno = event.extras.refno
14 } else {
15 refno = event.refno
16 window.JPush.setApplicationIconBadgeNumber(0);
17 }
18 app.openBill(refno);
19 console.log("openNotify:" + refno);
20 }, false)
21 },
22 openBill: function(billno) {
23 window.localStorage.setItem("currentrefno", billno);
24 window.location = 'billdetail.html';
25 },
26 initJpush: function() {
27 if (device.platform == "Android") {} else {
28 window.JPush.setApplicationIconBadgeNumber(0);
29 }
30 window.JPush.init();
31 window.JPush.setDebugMode(true);
32 window.JPush.isPushStopped(function(result) {
33 if (result == 0) {
34 //window.JPush.resumePush();
35 } else {
36 window.JPush.resumePush();
37 }
38 });
39 window.JPush.getUserNotificationSettings(function(result) {
40 if (result == 0) {} else if (result > 0) {}
41 });
42 var uid = window.localStorage.getItem("uid");
qiaoweif044a742019-07-10 16:04:20 +080043
guangchao.xu5ed58252020-07-21 18:15:56 +080044 window.JPush.setAlias({
45 sequence: 1,
46 alias: uid
47 },
48 (result) => {
49 var sequence = result.sequence
50 var alias = result.alias
51 //alert(JSON.stringify(result))
52 }, (error) => {
53 var sequence = error.sequence
54 var errorCode = error.code
55 //alert(JSON.stringify(error))
56 })
57 },
qiaowei98635db2020-06-28 17:41:21 +080058
guangchao.xu5ed58252020-07-21 18:15:56 +080059 onDeviceReady: function() {
60 var uid = window.localStorage.getItem("token");
61 this.initJpush();
62 $('#scanBtn').click(function() {
63 //window.location = "scan.html";
64 app.checkBefore(function() {
65 app.checkOther(function() {
66 window.location = "scan.html";
67 })
68 })
69 });
70 $('#qrcodeBtn').click(function() {
71 app.checkBefore(function() {
72 app.checkOther(function() {
73 window.location = "qrcode.html";
74 })
75 })
76 });
77 $('#cardBtn').click(function() {
78 app.checkBefore(function() {
79 app.checkOther(function() {
80 window.location = "card.html";
81 })
82 })
83 });
84 $('#billBtn').click(function() {
85 app.checkBefore(function() {
86 window.location = "bill.html";
87 })
88 });
89 $('#moreBtn').click(function() {
90 app.checkBefore(function() {
91 window.location = "bill.html";
92 })
93 });
94 $('#secBtn').click(function() {
95 //window.location = "security.html";
96 app.checkBefore(function() {
97 app.checkOther(function() {
98 window.location = "security.html";
99 })
100 })
101 });
102 $("#doorBtn").click(function() {
103 app.checkBefore(function() {
104 showRet(DOOR_URl);
105 })
106 })
107 $('#usersec').click(function() {
108 app.checkBefore(function() {
109 app.checkOther(function() {
110 window.location = "security.html";
111 })
112 })
113 });
114 $('#accsignbtn').click(function() {
115 app.checkBefore(function() {
116 var signed = window.localStorage.getItem("signed");
117 var cum = new auiDialog({});
118 if (isEmpty(signed) || signed != 'yes') {
119 var confirm = cum.alert({
120 title: "提示",
121 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
122 buttons: ['取消', '去签约']
123 }, function(ret) {
124 if (ret.buttonIndex == 2) {
125 app.toSignCode();
126 }
127 })
128 } else {
129 window.location = 'signxycheck.html'
130 }
131 })
132 });
133 this.initData();
134 this.backBtn();
135 },
136 backBtn: function() {
137 document.addEventListener("backbutton", function(e) {
138 e.preventDefault();
139 navigator.app.exitApp();
140 }, false);
141 },
142 initTab: function() {
143 $("#maincontent").css("top", $("#maintop").height())
144 var tab = new auiTab({
145 element: document.getElementById("footer"),
146 }, function(ret) {
147 window.localStorage.setItem("tabindex", ret.index);
qiaoweif044a742019-07-10 16:04:20 +0800148
guangchao.xu5ed58252020-07-21 18:15:56 +0800149 changeTab(ret.index);
150 });
151 var tabindex = window.localStorage.getItem("tabindex");
152 if (!tabindex || tabindex == 0) {
153 tabindex = 1
154 }
155 changeTab(tabindex);
156 tab.setActive(tabindex)
qiaowei22e23f82019-09-26 11:15:57 +0800157
guangchao.xu5ed58252020-07-21 18:15:56 +0800158 function changeTab(index) {
159 if (index == 1) {
160 $("#main1").show();
161 $("#main2").hide();
162 } else if (index == 2) {
163 $("#main1").hide();
164 $("#main2").show();
165 }
166 }
167 },
168 initData: function() {
169 this.loadBill()
170 },
171 loadBill: function() {
172 $("#loaddata").show()
173 $("#nodata").hide();
174 var param = {
175 "pageno": 1,
176 "platform": device.platform
177 }
178 V1Bills(param, function(ok, ret) {
179 if (ok) {
180 console.log(ret)
181 if (ret.code == 200) {
182 app.checkVersion(ret.version, ret.minversion, ret.versionmsg, ret.versionurl);
183 //app.checkVersion("1.3.9","1","new func","https://shouji.baidu.com/software/26706357.html");
184 $("#maingt").text(ret.t + "!")
185 $("#user-amount").text(ret.amount)
186 $("#user-point").text(ret.point)
187 if (ret.needrebind) {
188 window.localStorage.removeItem("userid");
189 } else {
190 window.localStorage.setItem("userid", ret.userid);
191 }
192 window.localStorage.setItem("signed", ret.signed);
193 window.localStorage.setItem("paypwdset", ret.paypwdset);
194 window.localStorage.setItem("name", ret.name);
195 if (ret.page && ret.page.count > 0) {
196 GLOBAL_TODAY = ret.today;
197 GLOBAL_YESTERDAY = ret.yesterday;
198 app.initBillView(ret.page)
199 app.initView();
200 } else {
201 $("#loaddata").hide()
202 $("#nodatahint").text("暂无数据")
203 $("#nodata").show();
204 app.initView();
205 }
206 } else {
207 $("#loaddata").hide()
208 $("#nodatahint").text("数据加载异常")
209 $("#nodata").show();
210 app.initView();
211 }
212 } else {
213 $("#loaddata").hide()
214 $("#nodatahint").text("请求数据失败")
215 $("#nodata").show();
216 app.initView();
217 }
218 })
219 },
220 checkVersion: function(ver, minver, m, url) {
221 cordova.getAppVersion.getVersionNumber(function(version) {
222 //alert(version);
223 //alert(version);
224 if (ver > version) {
225 var cum = new auiDialog({});
226 var confirm = cum.alert({
227 title: "有新的版本",
228 msg: m,
229 buttons: ['取消', '去更新']
230 }, function(ret) {
231 if (ret.buttonIndex == 2) {
232 cordova.InAppBrowser.open(url, '_system',
233 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');
234 }
235 })
236 }
237 });
238 },
239 initBillView: function(page) {
240 var html = '';
241 for (var i = 0; i < page.data.length; i++) {
242 var bean = page.data[i]
243 html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">';
244 html +=
245 '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
246 html += '</div><div class="aui-card-list-user-name">';
247 html += '<div>' + bean.transdesc + '</div>';
248 if (bean.tradeflag == 'in') {
249 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
250 } else {
251 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
252 }
253 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) +
254 '</div></div>';
255 }
256 $("#billcontent").html(html);
257 $("#loaddata").hide()
258 $("#nodata").hide();
259 $("#billcontent").show();
qiaowei22e23f82019-09-26 11:15:57 +0800260
guangchao.xu5ed58252020-07-21 18:15:56 +0800261 },
262 initView: function() {
263 var userid = window.localStorage.getItem("userid");
264 var signed = window.localStorage.getItem("signed");
265 if (isEmpty(userid)) {
266 $("#userbank").text("未绑定");
267 $("#userbank").css("color", "red")
268 } else {
269 $("#userbank").text("已绑定");
270 $("userbank").css("color", "#757575");
271 }
272 if (isEmpty(signed) || signed != 'yes') {
273 $("#usersign").text("未签约");
274 $("#usersign").css("color", "red")
275 } else {
276 $("#usersign").text("已签约");
277 $("usersign").css("color", "#757575");
278 }
279 var phone = window.localStorage.getItem("phoneX");
280 if (!isEmpty(phone)) {
281 $("#userphone").text(phone)
282 }
283 var name = window.localStorage.getItem("name");
284 if (isEmpty(name)) {
285 $("#username").text("匿名")
286 } else {
287 $("#username").text(name)
288 $("#homename").text(name)
289 }
290 },
291 checkBefore: function(callback) {
292 var uid = window.localStorage.getItem("token");
293 if (isEmpty(uid)) {
294 window.location = "login.html";
295 } else {
296 var userid = window.localStorage.getItem("userid");
297 if (isEmpty(userid)) {
298 var cum = new auiDialog({});
299 var confirm = cum.alert({
300 title: "提示",
301 msg: '为了不影响您正常使用相关功能,请先绑定银行卡',
302 buttons: ['取消', '去绑卡']
303 }, function(ret) {
304 if (ret.buttonIndex == 2) {
305 window.location = 'bindcard.html'
306 }
307 })
308 } else {
309 if (callback) {
310 callback()
311 }
312 }
313 }
314 },
315 checkOther: function(callback) {
316 var signed = window.localStorage.getItem("signed");
317 var cum = new auiDialog({});
qiaowei60c27e42019-07-11 16:43:54 +0800318
guangchao.xu5ed58252020-07-21 18:15:56 +0800319 if (isEmpty(signed) || signed != 'yes') {
320 var confirm = cum.alert({
321 title: "提示",
322 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
323 buttons: ['取消', '去签约']
324 }, function(ret) {
325 if (ret.buttonIndex == 2) {
326 app.toSignCode();
327 }
328 })
329 } else {
330 if (callback) {
331 callback()
332 }
333 }
334 },
335 toSignCode: function() {
336 var param = {}
337 V1Bindcardcode(param, function(ok, ret) {
338 if (ok) {
339 if (ret.code == 200) {
340 window.location = 'bindcheck.html'
341 } else {
342 $.alert(ret.msg, "错误");
343 }
344 } else {
345 $.alert("请求失败了 " + ret.status + ",请稍后再试", "错误");
346 }
347 })
348 },
349 toSign: function() {
350 window.location = 'signxycheck.html'
351 },
352 toBillDetail: function(refno) {
353 window.localStorage.setItem("currentrefno", refno);
354 window.location = 'billdetail.html';
355 },
356 toCard: function() {
357 var userid = window.localStorage.getItem("userid");
358 if (isEmpty(userid)) {
359 window.location = 'bindcard.html'
360 } else {
361 window.location = 'cardinfor.html'
362 }
363 },
364 logout: function() {
365 window.localStorage.removeItem("token");
366 window.location = "login.html";
367 }
qiaoweif044a742019-07-10 16:04:20 +0800368};
qiaowei22e23f82019-09-26 11:15:57 +0800369app.initialize();
qiaowei5f8f92f2019-11-15 10:27:57 +0800370
371function showRet(url) {
guangchao.xu5ed58252020-07-21 18:15:56 +0800372 if (isEmpty(url)) {
373 return;
374 }
375 var userid = window.localStorage.getItem("userid");
376 //if (url.indexOf("yy.dlsmk.cn")>=0) {
377 if (url.indexOf("?") > 0) {
378 url = url + '&userid=' + userid;
379 } else {
380 url = url + '?userid=' + userid;
381 }
382 //}
383 console.log(url)
384 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
385 statusbar: {
386 color: '#03a9f4ff'
387 },
388 toolbar: {
389 height: 44,
390 color: '#03a9f4ff'
391 },
392 title: {
393 color: '#ffffffff',
394 showPageTitle: true
395 },
396 backButton: {
397 image: 'back.png',
398 imagePressed: 'back.png',
399 align: 'left',
400 event: 'backPressed'
401 },
402 closeButton: {
403 image: 'close.png',
404 imagePressed: 'close.png',
405 align: 'left',
406 event: 'closePressed'
407 },
408 // menu: {
409 // image: 'share.png',
410 // imagePressed: 'share.png',
411 // align: 'right',
412 // items: [{
413 // event: 'shareQQ',
414 // label: '分享至QQ好友'
415 // },
416 // {
417 // event: 'shareWX',
418 // label: '分享至微信好友'
419 // }
420 // ]
421 // },
422 backButtonCanClose: true
423 }).addEventListener('closePressed', function(params) {
424 inAppBrowserRef.close();
425 //window.location = "main.html"
426 })
427 // .addEventListener('shareQQ', function(e) {
428 // // alert(1)
429 // var args = {};
430 // args.client = QQSDK.ClientType.QQ; //QQSDK.ClientType.QQ,QQSDK.ClientType.TIM;
431 // args.scene = QQSDK.Scene.QQ; //QQSDK.Scene.QQZone,QQSDK.Scene.Favorite
432 // args.url = 'https://yy.dlsmk.cn/wisdompolice/app/getapplyqrcode?visitorid=' + vistorId;
433 // args.title = '大理APP';
434 // args.description = '访客二维码';
435 // // args.image = 'https://cordova.apache.org/static/img/cordova_bot.png';
436 // QQSDK.shareNews(function() {
437 // alert('分享成功');
438 // }, function(failReason) {
439 // alert(failReason);
440 // }, args);
441 // }).addEventListener('shareWX', function(e) {
442 // // alert(2)
443 // Wechat.share({
444 // message: {
445 // title: "大理App分享",
446 // description: "访客二维码",
447 // thumb: "www/img/thumbnail.png",
448 // media: {
449 // type: Wechat.Type.WEBPAGE,
450 // webpageUrl: 'https://yy.dlsmk.cn/wisdompolice/app/getapplyqrcode?visitorid=' + vistorId
451 // }
452 // },
453 // scene: Wechat.Scene.SESSION // share to Timeline
454 // }, function() {
455 // alert("分享成功");
456 // }, function(reason) {
457 // alert("Failed: " + reason);
458 // });
459 // });
460}