qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 1 | var app = { |
| 2 | |
| 3 | // Application Constructor |
| 4 | initialize: function() { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 5 | this.initTab(); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 6 | document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 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 | }) |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 57 | }, |
| 58 | |
| 59 | onDeviceReady: function() { |
| 60 | var uid = window.localStorage.getItem("token"); |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 61 | this.initJpush(); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 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() { |
qiaowei | 596b36b | 2019-12-02 14:14:09 +0800 | [diff] [blame] | 95 | //window.location = "security.html"; |
| 96 | app.checkBefore(function() { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 97 | app.checkOther(function() { |
| 98 | window.location = "security.html"; |
| 99 | }) |
qiaowei | 596b36b | 2019-12-02 14:14:09 +0800 | [diff] [blame] | 100 | }) |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 101 | }); |
qiaowei | 240e344 | 2020-03-24 09:51:35 +0800 | [diff] [blame] | 102 | $("#doorBtn").click(function(){ |
qiaowei | 5f8f92f | 2019-11-15 10:27:57 +0800 | [diff] [blame] | 103 | app.checkBefore(function() { |
| 104 | showRet(DOOR_URl); |
| 105 | }) |
qiaowei | 240e344 | 2020-03-24 09:51:35 +0800 | [diff] [blame] | 106 | }) |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 107 | $('#usersec').click(function() { |
| 108 | app.checkBefore(function() { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 109 | app.checkOther(function() { |
| 110 | window.location = "security.html"; |
| 111 | }) |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 112 | }) |
| 113 | }); |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 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 | }); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 133 | this.initData(); |
qiaowei | 5f8f92f | 2019-11-15 10:27:57 +0800 | [diff] [blame] | 134 | this.backBtn(); |
| 135 | }, |
| 136 | backBtn: function(){ |
| 137 | document.addEventListener("backbutton", function(e){ |
| 138 | e.preventDefault(); |
| 139 | navigator.app.exitApp(); |
| 140 | }, false); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 141 | }, |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 142 | initTab: function() { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 143 | $("#maincontent").css("top", $("#maintop").height()) |
| 144 | var tab = new auiTab({ |
| 145 | element: document.getElementById("footer"), |
| 146 | }, function(ret) { |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 147 | window.localStorage.setItem("tabindex", ret.index); |
| 148 | |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 149 | changeTab(ret.index); |
| 150 | }); |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 151 | var tabindex = window.localStorage.getItem("tabindex"); |
| 152 | if (!tabindex || tabindex == 0) { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 153 | tabindex = 1 |
| 154 | } |
| 155 | changeTab(tabindex); |
| 156 | tab.setActive(tabindex) |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 157 | |
| 158 | function changeTab(index) { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 159 | if (index == 1) { |
| 160 | $("#main1").show(); |
| 161 | $("#main2").hide(); |
| 162 | } else if (index == 2) { |
| 163 | $("#main1").hide(); |
| 164 | $("#main2").show(); |
| 165 | } |
| 166 | } |
| 167 | }, |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 168 | initData: function() { |
| 169 | this.loadBill() |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 170 | }, |
| 171 | loadBill: function() { |
| 172 | $("#loaddata").show() |
| 173 | $("#nodata").hide(); |
| 174 | var param = { |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 175 | "pageno": 1, |
| 176 | "platform":device.platform |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 177 | } |
| 178 | V1Bills(param, function(ok, ret) { |
| 179 | if (ok) { |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 180 | console.log(ret) |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 181 | if (ret.code == 200) { |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 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"); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 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 | }, |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 220 | checkVersion:function(ver,minver,m,url){ |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 221 | cordova.getAppVersion.getVersionNumber(function (version) { |
| 222 | //alert(version); |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 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', 'location=no,toolbar=yes,toolbarposition=top,closebuttoncaption=关闭'); |
| 233 | } |
| 234 | }) |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 235 | } |
| 236 | }); |
| 237 | }, |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 238 | 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(); |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 257 | |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 258 | }, |
| 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) { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 313 | var signed = window.localStorage.getItem("signed"); |
| 314 | var cum = new auiDialog({}); |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 315 | |
| 316 | if (isEmpty(signed) || signed != 'yes') { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 317 | var confirm = cum.alert({ |
| 318 | title: "提示", |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 319 | msg: '您尚未签约市民卡免密代扣签约协议,无法使用该功能', |
| 320 | buttons: ['取消', '去签约'] |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 321 | }, function(ret) { |
| 322 | if (ret.buttonIndex == 2) { |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 323 | app.toSignCode(); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 324 | } |
| 325 | }) |
| 326 | } else { |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 327 | if (callback) { |
| 328 | callback() |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | }, |
qiaowei | c5a87f7 | 2020-03-27 12:40:19 +0800 | [diff] [blame^] | 332 | 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 | }, |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 347 | toSign: function() { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 348 | window.location = 'signxycheck.html' |
| 349 | }, |
| 350 | toBillDetail: function(refno) { |
| 351 | window.localStorage.setItem("currentrefno", refno); |
| 352 | window.location = 'billdetail.html'; |
| 353 | }, |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 354 | toCard: function() { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 355 | var userid = window.localStorage.getItem("userid"); |
| 356 | if (isEmpty(userid)) { |
| 357 | window.location = 'bindcard.html' |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 358 | } else { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 359 | window.location = 'cardinfor.html' |
| 360 | } |
qiaowei | 8055aa7 | 2019-12-05 11:40:00 +0800 | [diff] [blame] | 361 | }, |
| 362 | logout:function(){ |
| 363 | window.localStorage.removeItem("token"); |
| 364 | window.location = "login.html"; |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 365 | } |
| 366 | }; |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 367 | app.initialize(); |
qiaowei | 5f8f92f | 2019-11-15 10:27:57 +0800 | [diff] [blame] | 368 | |
| 369 | function 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 | } |