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