blob: 78b896fe0eec66756cdd589d7a7f06bb510fed96 [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");
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 })
qiaoweif044a742019-07-10 16:04:20 +080057 },
58
59 onDeviceReady: function() {
60 var uid = window.localStorage.getItem("token");
qiaowei22e23f82019-09-26 11:15:57 +080061 this.initJpush();
qiaoweif044a742019-07-10 16:04:20 +080062 $('#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() {
qiaowei596b36b2019-12-02 14:14:09 +080095 //window.location = "security.html";
96 app.checkBefore(function() {
qiaowei60c27e42019-07-11 16:43:54 +080097 app.checkOther(function() {
98 window.location = "security.html";
99 })
qiaowei596b36b2019-12-02 14:14:09 +0800100 })
qiaoweif044a742019-07-10 16:04:20 +0800101 });
qiaowei240e3442020-03-24 09:51:35 +0800102 $("#doorBtn").click(function(){
qiaowei5f8f92f2019-11-15 10:27:57 +0800103 app.checkBefore(function() {
104 showRet(DOOR_URl);
105 })
qiaowei240e3442020-03-24 09:51:35 +0800106 })
qiaoweif044a742019-07-10 16:04:20 +0800107 $('#usersec').click(function() {
108 app.checkBefore(function() {
qiaowei60c27e42019-07-11 16:43:54 +0800109 app.checkOther(function() {
110 window.location = "security.html";
111 })
qiaoweif044a742019-07-10 16:04:20 +0800112 })
113 });
qiaoweic5a87f72020-03-27 12:40:19 +0800114 $('#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 });
qiaoweif044a742019-07-10 16:04:20 +0800133 this.initData();
qiaowei5f8f92f2019-11-15 10:27:57 +0800134 this.backBtn();
135 },
136 backBtn: function(){
137 document.addEventListener("backbutton", function(e){
138 e.preventDefault();
139 navigator.app.exitApp();
140 }, false);
qiaoweif044a742019-07-10 16:04:20 +0800141 },
qiaowei22e23f82019-09-26 11:15:57 +0800142 initTab: function() {
qiaowei60c27e42019-07-11 16:43:54 +0800143 $("#maincontent").css("top", $("#maintop").height())
144 var tab = new auiTab({
145 element: document.getElementById("footer"),
146 }, function(ret) {
qiaowei22e23f82019-09-26 11:15:57 +0800147 window.localStorage.setItem("tabindex", ret.index);
148
qiaowei60c27e42019-07-11 16:43:54 +0800149 changeTab(ret.index);
150 });
qiaowei22e23f82019-09-26 11:15:57 +0800151 var tabindex = window.localStorage.getItem("tabindex");
152 if (!tabindex || tabindex == 0) {
qiaowei60c27e42019-07-11 16:43:54 +0800153 tabindex = 1
154 }
155 changeTab(tabindex);
156 tab.setActive(tabindex)
qiaowei22e23f82019-09-26 11:15:57 +0800157
158 function changeTab(index) {
qiaowei60c27e42019-07-11 16:43:54 +0800159 if (index == 1) {
160 $("#main1").show();
161 $("#main2").hide();
162 } else if (index == 2) {
163 $("#main1").hide();
164 $("#main2").show();
165 }
166 }
167 },
qiaoweif044a742019-07-10 16:04:20 +0800168 initData: function() {
169 this.loadBill()
qiaoweif044a742019-07-10 16:04:20 +0800170 },
171 loadBill: function() {
172 $("#loaddata").show()
173 $("#nodata").hide();
174 var param = {
qiaoweic5a87f72020-03-27 12:40:19 +0800175 "pageno": 1,
176 "platform":device.platform
qiaoweif044a742019-07-10 16:04:20 +0800177 }
178 V1Bills(param, function(ok, ret) {
179 if (ok) {
qiaoweic5a87f72020-03-27 12:40:19 +0800180 console.log(ret)
qiaoweif044a742019-07-10 16:04:20 +0800181 if (ret.code == 200) {
qiaoweic5a87f72020-03-27 12:40:19 +0800182 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");
qiaoweif044a742019-07-10 16:04:20 +0800184 $("#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 },
qiaoweic5a87f72020-03-27 12:40:19 +0800220 checkVersion:function(ver,minver,m,url){
qiaowei22e23f82019-09-26 11:15:57 +0800221 cordova.getAppVersion.getVersionNumber(function (version) {
222 //alert(version);
qiaoweic5a87f72020-03-27 12:40:19 +0800223 //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', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭');
233 }
234 })
qiaowei22e23f82019-09-26 11:15:57 +0800235 }
236 });
237 },
qiaoweif044a742019-07-10 16:04:20 +0800238 initBillView: function(page) {
239 var html = '';
240 for (var i = 0; i < page.data.length; i++) {
241 var bean = page.data[i]
242 html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">';
243 html += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
244 html += '</div><div class="aui-card-list-user-name">';
245 html += '<div>' + bean.transdesc + '</div>';
246 if (bean.tradeflag == 'in') {
247 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
248 } else {
249 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
250 }
251 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>';
252 }
253 $("#billcontent").html(html);
254 $("#loaddata").hide()
255 $("#nodata").hide();
256 $("#billcontent").show();
qiaowei60c27e42019-07-11 16:43:54 +0800257
qiaoweif044a742019-07-10 16:04:20 +0800258 },
259 initView: function() {
260 var userid = window.localStorage.getItem("userid");
261 var signed = window.localStorage.getItem("signed");
262 if (isEmpty(userid)) {
263 $("#userbank").text("未绑定");
264 $("#userbank").css("color", "red")
265 } else {
266 $("#userbank").text("已绑定");
267 $("userbank").css("color", "#757575");
268 }
269 if (isEmpty(signed) || signed != 'yes') {
270 $("#usersign").text("未签约");
271 $("#usersign").css("color", "red")
272 } else {
273 $("#usersign").text("已签约");
274 $("usersign").css("color", "#757575");
275 }
276 var phone = window.localStorage.getItem("phoneX");
277 if (!isEmpty(phone)) {
278 $("#userphone").text(phone)
279 }
280 var name = window.localStorage.getItem("name");
281 if (isEmpty(name)) {
282 $("#username").text("匿名")
283 } else {
284 $("#username").text(name)
285 $("#homename").text(name)
286 }
287 },
288 checkBefore: function(callback) {
289 var uid = window.localStorage.getItem("token");
290 if (isEmpty(uid)) {
291 window.location = "login.html";
292 } else {
293 var userid = window.localStorage.getItem("userid");
294 if (isEmpty(userid)) {
295 var cum = new auiDialog({});
296 var confirm = cum.alert({
297 title: "提示",
298 msg: '为了不影响您正常使用相关功能,请先绑定银行卡',
299 buttons: ['取消', '去绑卡']
300 }, function(ret) {
301 if (ret.buttonIndex == 2) {
302 window.location = 'bindcard.html'
303 }
304 })
305 } else {
306 if (callback) {
307 callback()
308 }
309 }
310 }
311 },
312 checkOther: function(callback) {
qiaoweif044a742019-07-10 16:04:20 +0800313 var signed = window.localStorage.getItem("signed");
314 var cum = new auiDialog({});
qiaoweic5a87f72020-03-27 12:40:19 +0800315
316 if (isEmpty(signed) || signed != 'yes') {
qiaoweif044a742019-07-10 16:04:20 +0800317 var confirm = cum.alert({
318 title: "提示",
qiaoweic5a87f72020-03-27 12:40:19 +0800319 msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能',
320 buttons: ['取消', '去签约']
qiaoweif044a742019-07-10 16:04:20 +0800321 }, function(ret) {
322 if (ret.buttonIndex == 2) {
qiaoweic5a87f72020-03-27 12:40:19 +0800323 app.toSignCode();
qiaoweif044a742019-07-10 16:04:20 +0800324 }
325 })
326 } else {
qiaoweic5a87f72020-03-27 12:40:19 +0800327 if (callback) {
328 callback()
qiaoweif044a742019-07-10 16:04:20 +0800329 }
330 }
331 },
qiaoweic5a87f72020-03-27 12:40:19 +0800332 toSignCode: function(){
333 var param = {
334 }
335 V1Bindcardcode(param, function(ok, ret) {
336 if (ok) {
337 if (ret.code == 200) {
338 window.location = 'bindcheck.html'
339 } else {
340 $.alert(ret.msg, "错误");
341 }
342 } else {
343 $.alert("请求失败了 " + ret.status + ",请稍后再试", "错误");
344 }
345 })
346 },
qiaowei60c27e42019-07-11 16:43:54 +0800347 toSign: function() {
qiaoweif044a742019-07-10 16:04:20 +0800348 window.location = 'signxycheck.html'
349 },
350 toBillDetail: function(refno) {
351 window.localStorage.setItem("currentrefno", refno);
352 window.location = 'billdetail.html';
353 },
qiaowei60c27e42019-07-11 16:43:54 +0800354 toCard: function() {
qiaoweif044a742019-07-10 16:04:20 +0800355 var userid = window.localStorage.getItem("userid");
356 if (isEmpty(userid)) {
357 window.location = 'bindcard.html'
qiaowei60c27e42019-07-11 16:43:54 +0800358 } else {
qiaoweif044a742019-07-10 16:04:20 +0800359 window.location = 'cardinfor.html'
360 }
qiaowei8055aa72019-12-05 11:40:00 +0800361 },
362 logout:function(){
363 window.localStorage.removeItem("token");
364 window.location = "login.html";
qiaoweif044a742019-07-10 16:04:20 +0800365 }
366};
qiaowei22e23f82019-09-26 11:15:57 +0800367app.initialize();
qiaowei5f8f92f2019-11-15 10:27:57 +0800368
369function showRet(url) {
370 if(isEmpty(url)){
371 return;
372 }
373 var userid = window.localStorage.getItem("userid");
374 //if (url.indexOf("yy.dlsmk.cn")>=0) {
375 if(url.indexOf("?")>0){
376 url=url+'&userid='+userid;
377 }else{
378 url=url+'?userid='+userid;
379 }
380 //}
381 console.log(url)
382 var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', {
383 statusbar: {
384 color: '#03a9f4ff'
385 },
386 toolbar: {
387 height: 44,
388 color: '#03a9f4ff'
389 },
390 title: {
391 color: '#ffffffff',
392 showPageTitle: true
393 },
394 backButton: {
395 image: 'back.png',
396 imagePressed: 'back.png',
397 align: 'left',
398 event: 'backPressed'
399 },
400 closeButton: {
401 image: 'close.png',
402 imagePressed: 'close.png',
403 align: 'left',
404 event: 'closePressed'
405 },
406 backButtonCanClose: true
407 }).addEventListener('closePressed', function(params){
408 inAppBrowserRef.close();
409 //window.location = "main.html"
410 });
411 }