blob: a0e4fca942332805e8163adcb315ba4ccc3dcbfb [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) {
11 var refno
12 console.log("openNotify:"+event);
13 if(device.platform == "Android") {
14 refno = event.extras.refno
15 } else {
16 refno = event.refno
17 window.JPush.setApplicationIconBadgeNumber(0);
18 }
19 app.openBill(refno);
20 console.log("openNotify:"+refno);
21 }, false)
22 },
23 openBill:function(billno){
24 window.localStorage.setItem("currentrefno",billno);
25 window.location='billdetail.html';
26 },
27 initJpush: function() {
28 if(device.platform == "Android") {
29 } else {
30 window.JPush.setApplicationIconBadgeNumber(0);
31 }
32 window.JPush.init();
33 window.JPush.setDebugMode(true);
34 window.JPush.isPushStopped(function(result) {
35 if (result == 0) {
36 //window.JPush.resumePush();
37 } else {
38 window.JPush.resumePush();
39 }
40 });
41 window.JPush.getUserNotificationSettings(function(result) {
42 if(result == 0) {
43 } else if(result > 0) {
44 }
45 });
46 var uid = window.localStorage.getItem("uid");
47 window.JPush.setAlias({ sequence: 1, alias: uid },
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 },
58
59 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 $('#qrcodeBtn1').click(function() {
78 app.checkBefore(function() {
79 app.checkOther(function() {
80 window.location = "qrcode.html";
81 })
82 })
83 });
84 /*$('#cardBtn').click(function() {
85 app.checkBefore(function() {
86 app.checkOther(function() {
87 window.location = "card.html";
88 })
89 })
90 });
91 $('#billBtn').click(function() {
92 app.checkBefore(function() {
93 window.location = "bill.html";
94 })
95 });
96 $('#moreBtn').click(function() {
97 app.checkBefore(function() {
98 window.location = "bill.html";
99 })
100 });
101 $('#secBtn').click(function() {
102 //window.location = "security.html";
103 app.checkBefore(function() {
104 app.checkOther(function() {
105 window.location = "security.html";
106 })
107 })
108 });
109
110 $("#doorBtn").click(function(){
111 app.checkBefore(function() {
112 showRet(DOOR_URl);
113 })
114 })*/
115 $("#moreFuncBtn").click(function(){
116 window.location = "more.html";
117 })
118 $('#usersec').click(function() {
119 app.checkBefore(function() {
120 app.checkOther(function() {
121 window.location = "security.html";
122 })
123 })
124 });
125 $('#accsignbtn').click(function() {
126 app.checkBefore(function() {
127 var signed = window.localStorage.getItem("signed");
128 var cum = new auiDialog({});
129 if (isEmpty(signed) || signed != 'yes') {
130 var confirm = cum.alert({
131 title: "提示",
132 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
133 buttons: ['取消', '去签约']
134 }, function(ret) {
135 if (ret.buttonIndex == 2) {
136 app.toSignCode();
137 }
138 })
139 }else{
140 window.location = 'signxycheck.html'
141 }
142 })
143 });
144 this.initSlider();
145 this.initData();
146 this.backBtn();
147 },
148 backBtn: function(){
149 document.addEventListener("backbutton", function(e){
150 e.preventDefault();
151 navigator.app.exitApp();
152 }, false);
153 },
154 initTab: function() {
155 //$("#maincontent").css("top", $("#maintop").height())
156 var tab = new auiTab({
157 element: document.getElementById("footer"),
158 }, function(ret) {
159 window.localStorage.setItem("tabindex", ret.index);
160
161 changeTab(ret.index);
162 });
163 var tabindex = window.localStorage.getItem("tabindex");
164 if (!tabindex || tabindex == 0) {
165 tabindex = 1
166 }
167 changeTab(tabindex);
168 tab.setActive(tabindex)
169
170 function changeTab(index) {
171 if (index == 1) {
172 $("#main1").show();
173 $("#main2").hide();
174 $("#main3").hide();
175 } else if (index == 2) {
176 $("#main1").hide();
177 $("#main2").show();
178 $("#main3").hide();
179 } else if (index == 3) {
180 $("#main1").hide();
181 $("#main2").hide();
182 $("#main3").show();
183 }
184 }
185 },
186 initSlider:function(){
187 var slide = new auiSlide({
188 container:document.getElementById("startslider"),
qiaowei66edadb2020-04-20 16:51:56 +0800189 "height":240,
qiaowei9579db42020-04-14 13:08:35 +0800190 "speed":500,
191 "pageShow":true,
192 "autoPlay":3000,
193 "pageStyle":'dot',
qiaowei743de0d2020-05-07 15:06:58 +0800194 "loop":false,
qiaowei9579db42020-04-14 13:08:35 +0800195 'dotPosition':'center',
196 currentPage:currentFun
197 });
198 function currentFun(index){
199 //console.log(index)
200 }
201 },
202 initData: function() {
203 this.loadBill()
204 },
205 loadBill: function() {
206 //$("#loaddata").show()
207 //$("#nodata").hide();
208 var param = {
209 "pageno": 1,
210 "platform":device.platform
211 }
212 V1Bills(param, function(ok, ret) {
213 if (ok) {
214 console.log(ret)
215 if (ret.code == 200) {
216 app.checkVersion(ret.version,ret.minversion,ret.versionmsg,ret.versionurl);
217 //app.checkVersion("1.3.9","1","new func","https://shouji.baidu.com/software/26706357.html");
218 //$("#maingt").text(ret.t + "!")
219 $("#user-amount").text(ret.amount)
220 $("#user-point").text(ret.point)
221 if (ret.needrebind) {
222 window.localStorage.removeItem("userid");
223 } else {
224 window.localStorage.setItem("userid", ret.userid);
225 }
226 window.localStorage.setItem("signed", ret.signed);
227 window.localStorage.setItem("paypwdset", ret.paypwdset);
228 window.localStorage.setItem("name", ret.name);
229 if (ret.page && ret.page.count > 0) {
230 GLOBAL_TODAY = ret.today;
231 GLOBAL_YESTERDAY = ret.yesterday;
232 //app.initBillView(ret.page)
233 app.initView();
234 } else {
235 //$("#loaddata").hide()
236 //$("#nodatahint").text("暂无数据")
237 //$("#nodata").show();
238 app.initView();
239 }
240 } else {
241 //$("#loaddata").hide()
242 //$("#nodatahint").text("数据加载异常")
243 //$("#nodata").show();
244 app.initView();
245 }
246 } else {
247 //$("#loaddata").hide()
248 //$("#nodatahint").text("请求数据失败")
249 //$("#nodata").show();
250 app.initView();
251 }
252 })
253 },
254 checkVersion:function(ver,minver,m,url){
255 cordova.getAppVersion.getVersionNumber(function (version) {
256 //alert(version);
257 //alert(version);
258 if(ver>version){
259 var cum = new auiDialog({});
260 var confirm = cum.alert({
261 title: "有新的版本",
262 msg: m,
263 buttons: ['取消', '去更新']
264 }, function(ret) {
265 if (ret.buttonIndex == 2) {
266 cordova.InAppBrowser.open(url, '_system', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');
267 }
268 })
269 }
270 });
271 },
272 initBillView: function(page) {
273 var html = '';
274 for (var i = 0; i < page.data.length; i++) {
275 var bean = page.data[i]
276 html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">';
277 html += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
278 html += '</div><div class="aui-card-list-user-name">';
279 html += '<div>' + bean.transdesc + '</div>';
280 if (bean.tradeflag == 'in') {
281 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
282 } else {
283 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
284 }
285 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>';
286 }
287 $("#billcontent").html(html);
288 $("#loaddata").hide()
289 $("#nodata").hide();
290 $("#billcontent").show();
291
292 },
293 initView: function() {
294 var userid = window.localStorage.getItem("userid");
295 var signed = window.localStorage.getItem("signed");
296 if (isEmpty(userid)) {
297 $("#userbank").text("未绑定");
298 $("#userbank").css("color", "red")
299 } else {
300 $("#userbank").text("已绑定");
301 $("userbank").css("color", "#757575");
302 }
303 if (isEmpty(signed) || signed != 'yes') {
304 $("#usersign").text("未签约");
305 $("#usersign").css("color", "red")
306 } else {
307 $("#usersign").text("已签约");
308 $("usersign").css("color", "#757575");
309 }
310 var phone = window.localStorage.getItem("phoneX");
311 if (!isEmpty(phone)) {
312 $("#userphone").text(phone)
313 }
314 var name = window.localStorage.getItem("name");
315 if (isEmpty(name)) {
316 $("#username").text("匿名")
317 } else {
318 $("#username").text(name)
319 $("#homename").text(name)
320 }
321 },
322 checkBefore: function(callback) {
323 var uid = window.localStorage.getItem("token");
324 if (isEmpty(uid)) {
325 window.location = "login.html";
326 } else {
327 var userid = window.localStorage.getItem("userid");
328 if (isEmpty(userid)) {
329 var cum = new auiDialog({});
330 var confirm = cum.alert({
331 title: "提示",
sijun.li09bd57a2020-04-21 18:52:28 +0800332 msg: '为了不影响您正常使用相关功能,请先进行市民卡签约',
333 buttons: ['取消', '去签约']
qiaowei9579db42020-04-14 13:08:35 +0800334 }, function(ret) {
335 if (ret.buttonIndex == 2) {
336 window.location = 'bindcard.html'
337 }
338 })
339 } else {
340 if (callback) {
341 callback()
342 }
343 }
344 }
345 },
346 checkOther: function(callback) {
347 var signed = window.localStorage.getItem("signed");
348 var cum = new auiDialog({});
349
350 if (isEmpty(signed) || signed != 'yes') {
351 var confirm = cum.alert({
352 title: "提示",
353 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
354 buttons: ['取消', '去签约']
355 }, function(ret) {
356 if (ret.buttonIndex == 2) {
357 app.toSignCode();
358 }
359 })
360 } else {
361 if (callback) {
362 callback()
363 }
364 }
365 },
366 toSignCode: function(){
367 var param = {
368 }
369 V1Bindcardcode(param, function(ok, ret) {
370 if (ok) {
371 if (ret.code == 200) {
372 window.location = 'bindcheck.html'
373 } else {
374 $.alert(ret.msg, "错误");
375 }
376 } else {
377 $.alert("请求失败了 " + ret.status + ",请稍后再试", "错误");
378 }
379 })
380 },
381 toSign: function() {
382 window.location = 'signxycheck.html'
383 },
384 toBillDetail: function(refno) {
385 window.localStorage.setItem("currentrefno", refno);
386 window.location = 'billdetail.html';
387 },
388 toCard: function() {
sijun.li09bd57a2020-04-21 18:52:28 +0800389 var signed = window.localStorage.getItem("signed");
390 if (isEmpty(signed) || signed != 'yes') {
qiaowei9579db42020-04-14 13:08:35 +0800391 window.location = 'bindcard.html'
sijun.li09bd57a2020-04-21 18:52:28 +0800392 }else{
qiaowei9579db42020-04-14 13:08:35 +0800393 window.location = 'cardinfor.html'
394 }
395 },
396 logout:function(){
397 window.localStorage.removeItem("token");
398 window.location = "login.html";
399 }
400};
401app.initialize();
402
403function showRet(url) {
404 if(isEmpty(url)){
405 return;
406 }
407 var userid = window.localStorage.getItem("userid");
408 //if (url.indexOf("yy.dlsmk.cn")>=0) {
409 if(url.indexOf("?")>0){
410 url=url+'&userid='+userid;
411 }else{
412 url=url+'?userid='+userid;
413 }
414 //}
415 console.log(url)
416 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
417 statusbar: {
418 color: '#03a9f4ff'
419 },
420 toolbar: {
421 height: 44,
422 color: '#03a9f4ff'
423 },
424 title: {
425 color: '#ffffffff',
426 showPageTitle: true
427 },
428 backButton: {
429 image: 'back.png',
430 imagePressed: 'back.png',
431 align: 'left',
432 event: 'backPressed'
433 },
434 closeButton: {
435 image: 'close.png',
436 imagePressed: 'close.png',
437 align: 'left',
438 event: 'closePressed'
439 },
440 backButtonCanClose: true
441 }).addEventListener('closePressed', function(params){
442 inAppBrowserRef.close();
443 //window.location = "main.html"
444 });
445 }