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