blob: f30203380051056c3cfc281e84c9987cebbb4682 [file] [log] [blame]
qiaoweif044a742019-07-10 16:04:20 +08001var app = {
2
3 // Application Constructor
4 initialize: function() {
qiaowei60c27e42019-07-11 16:43:54 +08005 this.initTab();
qiaoweif044a742019-07-10 16:04:20 +08006 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
qiaowei22e23f82019-09-26 11:15:57 +08007 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");
qiaowei98635db2020-06-28 17:41:21 +080047
qiaowei22e23f82019-09-26 11:15:57 +080048 window.JPush.setAlias({ sequence: 1, alias: uid },
49 (result) => {
50 var sequence = result.sequence
51 var alias = result.alias
52 //alert(JSON.stringify(result))
53 }, (error) => {
54 var sequence = error.sequence
55 var errorCode = error.code
56 //alert(JSON.stringify(error))
57 })
qiaoweif044a742019-07-10 16:04:20 +080058 },
59
60 onDeviceReady: function() {
61 var uid = window.localStorage.getItem("token");
qiaowei22e23f82019-09-26 11:15:57 +080062 this.initJpush();
qiaoweif044a742019-07-10 16:04:20 +080063 $('#scanBtn').click(function() {
64 //window.location = "scan.html";
65 app.checkBefore(function() {
66 app.checkOther(function() {
67 window.location = "scan.html";
68 })
69 })
70 });
71 $('#qrcodeBtn').click(function() {
72 app.checkBefore(function() {
73 app.checkOther(function() {
74 window.location = "qrcode.html";
75 })
76 })
77 });
78 $('#cardBtn').click(function() {
79 app.checkBefore(function() {
80 app.checkOther(function() {
81 window.location = "card.html";
82 })
83 })
84 });
85 $('#billBtn').click(function() {
86 app.checkBefore(function() {
87 window.location = "bill.html";
88 })
89 });
90 $('#moreBtn').click(function() {
91 app.checkBefore(function() {
92 window.location = "bill.html";
93 })
94 });
95 $('#secBtn').click(function() {
qiaowei596b36b2019-12-02 14:14:09 +080096 //window.location = "security.html";
97 app.checkBefore(function() {
qiaowei60c27e42019-07-11 16:43:54 +080098 app.checkOther(function() {
99 window.location = "security.html";
100 })
qiaowei596b36b2019-12-02 14:14:09 +0800101 })
qiaoweif044a742019-07-10 16:04:20 +0800102 });
qiaowei240e3442020-03-24 09:51:35 +0800103 $("#doorBtn").click(function(){
qiaowei5f8f92f2019-11-15 10:27:57 +0800104 app.checkBefore(function() {
105 showRet(DOOR_URl);
106 })
qiaowei240e3442020-03-24 09:51:35 +0800107 })
qiaoweif044a742019-07-10 16:04:20 +0800108 $('#usersec').click(function() {
109 app.checkBefore(function() {
qiaowei60c27e42019-07-11 16:43:54 +0800110 app.checkOther(function() {
111 window.location = "security.html";
112 })
qiaoweif044a742019-07-10 16:04:20 +0800113 })
114 });
qiaoweic5a87f72020-03-27 12:40:19 +0800115 $('#accsignbtn').click(function() {
116 app.checkBefore(function() {
117 var signed = window.localStorage.getItem("signed");
118 var cum = new auiDialog({});
119 if (isEmpty(signed) || signed != 'yes') {
120 var confirm = cum.alert({
121 title: "提示",
122 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
123 buttons: ['取消', '去签约']
124 }, function(ret) {
125 if (ret.buttonIndex == 2) {
126 app.toSignCode();
127 }
128 })
129 }else{
130 window.location = 'signxycheck.html'
131 }
132 })
133 });
qiaoweif044a742019-07-10 16:04:20 +0800134 this.initData();
qiaowei5f8f92f2019-11-15 10:27:57 +0800135 this.backBtn();
136 },
137 backBtn: function(){
138 document.addEventListener("backbutton", function(e){
139 e.preventDefault();
140 navigator.app.exitApp();
141 }, false);
qiaoweif044a742019-07-10 16:04:20 +0800142 },
qiaowei22e23f82019-09-26 11:15:57 +0800143 initTab: function() {
qiaowei60c27e42019-07-11 16:43:54 +0800144 $("#maincontent").css("top", $("#maintop").height())
145 var tab = new auiTab({
146 element: document.getElementById("footer"),
147 }, function(ret) {
qiaowei22e23f82019-09-26 11:15:57 +0800148 window.localStorage.setItem("tabindex", ret.index);
149
qiaowei60c27e42019-07-11 16:43:54 +0800150 changeTab(ret.index);
151 });
qiaowei22e23f82019-09-26 11:15:57 +0800152 var tabindex = window.localStorage.getItem("tabindex");
153 if (!tabindex || tabindex == 0) {
qiaowei60c27e42019-07-11 16:43:54 +0800154 tabindex = 1
155 }
156 changeTab(tabindex);
157 tab.setActive(tabindex)
qiaowei22e23f82019-09-26 11:15:57 +0800158
159 function changeTab(index) {
qiaowei60c27e42019-07-11 16:43:54 +0800160 if (index == 1) {
161 $("#main1").show();
162 $("#main2").hide();
163 } else if (index == 2) {
164 $("#main1").hide();
165 $("#main2").show();
166 }
167 }
168 },
qiaoweif044a742019-07-10 16:04:20 +0800169 initData: function() {
170 this.loadBill()
qiaoweif044a742019-07-10 16:04:20 +0800171 },
172 loadBill: function() {
173 $("#loaddata").show()
174 $("#nodata").hide();
175 var param = {
qiaoweic5a87f72020-03-27 12:40:19 +0800176 "pageno": 1,
177 "platform":device.platform
qiaoweif044a742019-07-10 16:04:20 +0800178 }
179 V1Bills(param, function(ok, ret) {
180 if (ok) {
qiaoweic5a87f72020-03-27 12:40:19 +0800181 console.log(ret)
qiaoweif044a742019-07-10 16:04:20 +0800182 if (ret.code == 200) {
qiaoweic5a87f72020-03-27 12:40:19 +0800183 app.checkVersion(ret.version,ret.minversion,ret.versionmsg,ret.versionurl);
184 //app.checkVersion("1.3.9","1","new func","https://shouji.baidu.com/software/26706357.html");
qiaoweif044a742019-07-10 16:04:20 +0800185 $("#maingt").text(ret.t + "!")
186 $("#user-amount").text(ret.amount)
187 $("#user-point").text(ret.point)
188 if (ret.needrebind) {
189 window.localStorage.removeItem("userid");
190 } else {
191 window.localStorage.setItem("userid", ret.userid);
192 }
193 window.localStorage.setItem("signed", ret.signed);
194 window.localStorage.setItem("paypwdset", ret.paypwdset);
195 window.localStorage.setItem("name", ret.name);
196 if (ret.page && ret.page.count > 0) {
197 GLOBAL_TODAY = ret.today;
198 GLOBAL_YESTERDAY = ret.yesterday;
199 app.initBillView(ret.page)
200 app.initView();
201 } else {
202 $("#loaddata").hide()
203 $("#nodatahint").text("暂无数据")
204 $("#nodata").show();
205 app.initView();
206 }
207 } else {
208 $("#loaddata").hide()
209 $("#nodatahint").text("数据加载异常")
210 $("#nodata").show();
211 app.initView();
212 }
213 } else {
214 $("#loaddata").hide()
215 $("#nodatahint").text("请求数据失败")
216 $("#nodata").show();
217 app.initView();
218 }
219 })
220 },
qiaoweic5a87f72020-03-27 12:40:19 +0800221 checkVersion:function(ver,minver,m,url){
qiaowei22e23f82019-09-26 11:15:57 +0800222 cordova.getAppVersion.getVersionNumber(function (version) {
223 //alert(version);
qiaoweic5a87f72020-03-27 12:40:19 +0800224 //alert(version);
225 if(ver>version){
226 var cum = new auiDialog({});
227 var confirm = cum.alert({
228 title: "有新的版本",
229 msg: m,
230 buttons: ['取消', '去更新']
231 }, function(ret) {
232 if (ret.buttonIndex == 2) {
233 cordova.InAppBrowser.open(url, '_system', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');
234 }
235 })
qiaowei22e23f82019-09-26 11:15:57 +0800236 }
237 });
238 },
qiaoweif044a742019-07-10 16:04:20 +0800239 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 += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
245 html += '</div><div class="aui-card-list-user-name">';
246 html += '<div>' + bean.transdesc + '</div>';
247 if (bean.tradeflag == 'in') {
248 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
249 } else {
250 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
251 }
252 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>';
253 }
254 $("#billcontent").html(html);
255 $("#loaddata").hide()
256 $("#nodata").hide();
257 $("#billcontent").show();
qiaowei60c27e42019-07-11 16:43:54 +0800258
qiaoweif044a742019-07-10 16:04:20 +0800259 },
260 initView: function() {
261 var userid = window.localStorage.getItem("userid");
262 var signed = window.localStorage.getItem("signed");
263 if (isEmpty(userid)) {
264 $("#userbank").text("未绑定");
265 $("#userbank").css("color", "red")
266 } else {
267 $("#userbank").text("已绑定");
268 $("userbank").css("color", "#757575");
269 }
270 if (isEmpty(signed) || signed != 'yes') {
271 $("#usersign").text("未签约");
272 $("#usersign").css("color", "red")
273 } else {
274 $("#usersign").text("已签约");
275 $("usersign").css("color", "#757575");
276 }
277 var phone = window.localStorage.getItem("phoneX");
278 if (!isEmpty(phone)) {
279 $("#userphone").text(phone)
280 }
281 var name = window.localStorage.getItem("name");
282 if (isEmpty(name)) {
283 $("#username").text("匿名")
284 } else {
285 $("#username").text(name)
286 $("#homename").text(name)
287 }
288 },
289 checkBefore: function(callback) {
290 var uid = window.localStorage.getItem("token");
291 if (isEmpty(uid)) {
292 window.location = "login.html";
293 } else {
294 var userid = window.localStorage.getItem("userid");
295 if (isEmpty(userid)) {
296 var cum = new auiDialog({});
297 var confirm = cum.alert({
298 title: "提示",
299 msg: '为了不影响您正常使用相关功能,请先绑定银行卡',
300 buttons: ['取消', '去绑卡']
301 }, function(ret) {
302 if (ret.buttonIndex == 2) {
303 window.location = 'bindcard.html'
304 }
305 })
306 } else {
307 if (callback) {
308 callback()
309 }
310 }
311 }
312 },
313 checkOther: function(callback) {
qiaoweif044a742019-07-10 16:04:20 +0800314 var signed = window.localStorage.getItem("signed");
315 var cum = new auiDialog({});
qiaoweic5a87f72020-03-27 12:40:19 +0800316
317 if (isEmpty(signed) || signed != 'yes') {
qiaoweif044a742019-07-10 16:04:20 +0800318 var confirm = cum.alert({
319 title: "提示",
qiaoweic5a87f72020-03-27 12:40:19 +0800320 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
321 buttons: ['取消', '去签约']
qiaoweif044a742019-07-10 16:04:20 +0800322 }, function(ret) {
323 if (ret.buttonIndex == 2) {
qiaoweic5a87f72020-03-27 12:40:19 +0800324 app.toSignCode();
qiaoweif044a742019-07-10 16:04:20 +0800325 }
326 })
327 } else {
qiaoweic5a87f72020-03-27 12:40:19 +0800328 if (callback) {
329 callback()
qiaoweif044a742019-07-10 16:04:20 +0800330 }
331 }
332 },
qiaoweic5a87f72020-03-27 12:40:19 +0800333 toSignCode: function(){
334 var param = {
335 }
336 V1Bindcardcode(param, function(ok, ret) {
337 if (ok) {
338 if (ret.code == 200) {
339 window.location = 'bindcheck.html'
340 } else {
341 $.alert(ret.msg, "错误");
342 }
343 } else {
344 $.alert("请求失败了 " + ret.status + ",请稍后再试", "错误");
345 }
346 })
347 },
qiaowei60c27e42019-07-11 16:43:54 +0800348 toSign: function() {
qiaoweif044a742019-07-10 16:04:20 +0800349 window.location = 'signxycheck.html'
350 },
351 toBillDetail: function(refno) {
352 window.localStorage.setItem("currentrefno", refno);
353 window.location = 'billdetail.html';
354 },
qiaowei60c27e42019-07-11 16:43:54 +0800355 toCard: function() {
qiaoweif044a742019-07-10 16:04:20 +0800356 var userid = window.localStorage.getItem("userid");
357 if (isEmpty(userid)) {
358 window.location = 'bindcard.html'
qiaowei60c27e42019-07-11 16:43:54 +0800359 } else {
qiaoweif044a742019-07-10 16:04:20 +0800360 window.location = 'cardinfor.html'
361 }
qiaowei8055aa72019-12-05 11:40:00 +0800362 },
363 logout:function(){
364 window.localStorage.removeItem("token");
365 window.location = "login.html";
qiaoweif044a742019-07-10 16:04:20 +0800366 }
367};
qiaowei22e23f82019-09-26 11:15:57 +0800368app.initialize();
qiaowei5f8f92f2019-11-15 10:27:57 +0800369
370function showRet(url) {
371 if(isEmpty(url)){
372 return;
373 }
374 var userid = window.localStorage.getItem("userid");
375 //if (url.indexOf("yy.dlsmk.cn")>=0) {
376 if(url.indexOf("?")>0){
377 url=url+'&userid='+userid;
378 }else{
379 url=url+'?userid='+userid;
380 }
381 //}
382 console.log(url)
383 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
384 statusbar: {
385 color: '#03a9f4ff'
386 },
387 toolbar: {
388 height: 44,
389 color: '#03a9f4ff'
390 },
391 title: {
392 color: '#ffffffff',
393 showPageTitle: true
394 },
395 backButton: {
396 image: 'back.png',
397 imagePressed: 'back.png',
398 align: 'left',
399 event: 'backPressed'
400 },
401 closeButton: {
402 image: 'close.png',
403 imagePressed: 'close.png',
404 align: 'left',
405 event: 'closePressed'
406 },
407 backButtonCanClose: true
408 }).addEventListener('closePressed', function(params){
409 inAppBrowserRef.close();
410 //window.location = "main.html"
411 });
412 }