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 | 596b36b | 2019-12-02 14:14:09 +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 | 596b36b | 2019-12-02 14:14:09 +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 | }); |
| 114 | this.initData(); |
qiaowei | 5f8f92f | 2019-11-15 10:27:57 +0800 | [diff] [blame] | 115 | this.backBtn(); |
| 116 | }, |
| 117 | backBtn: function(){ |
| 118 | document.addEventListener("backbutton", function(e){ |
| 119 | e.preventDefault(); |
| 120 | navigator.app.exitApp(); |
| 121 | }, false); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 122 | }, |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 123 | initTab: function() { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 124 | $("#maincontent").css("top", $("#maintop").height()) |
| 125 | var tab = new auiTab({ |
| 126 | element: document.getElementById("footer"), |
| 127 | }, function(ret) { |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 128 | window.localStorage.setItem("tabindex", ret.index); |
| 129 | |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 130 | changeTab(ret.index); |
| 131 | }); |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 132 | var tabindex = window.localStorage.getItem("tabindex"); |
| 133 | if (!tabindex || tabindex == 0) { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 134 | tabindex = 1 |
| 135 | } |
| 136 | changeTab(tabindex); |
| 137 | tab.setActive(tabindex) |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 138 | |
| 139 | function changeTab(index) { |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 140 | if (index == 1) { |
| 141 | $("#main1").show(); |
| 142 | $("#main2").hide(); |
| 143 | } else if (index == 2) { |
| 144 | $("#main1").hide(); |
| 145 | $("#main2").show(); |
| 146 | } |
| 147 | } |
| 148 | }, |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 149 | initData: function() { |
| 150 | this.loadBill() |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 151 | }, |
| 152 | loadBill: function() { |
| 153 | $("#loaddata").show() |
| 154 | $("#nodata").hide(); |
| 155 | var param = { |
| 156 | "pageno": 1 |
| 157 | } |
| 158 | V1Bills(param, function(ok, ret) { |
| 159 | if (ok) { |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 160 | //console.log(ret) |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 161 | if (ret.code == 200) { |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 162 | app.checkVersion(ret.version,ret.minversion,ret.versionmsg); |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 163 | $("#maingt").text(ret.t + "!") |
| 164 | $("#user-amount").text(ret.amount) |
| 165 | $("#user-point").text(ret.point) |
| 166 | if (ret.needrebind) { |
| 167 | window.localStorage.removeItem("userid"); |
| 168 | } else { |
| 169 | window.localStorage.setItem("userid", ret.userid); |
| 170 | } |
| 171 | window.localStorage.setItem("signed", ret.signed); |
| 172 | window.localStorage.setItem("paypwdset", ret.paypwdset); |
| 173 | window.localStorage.setItem("name", ret.name); |
| 174 | if (ret.page && ret.page.count > 0) { |
| 175 | GLOBAL_TODAY = ret.today; |
| 176 | GLOBAL_YESTERDAY = ret.yesterday; |
| 177 | app.initBillView(ret.page) |
| 178 | app.initView(); |
| 179 | } else { |
| 180 | $("#loaddata").hide() |
| 181 | $("#nodatahint").text("暂无数据") |
| 182 | $("#nodata").show(); |
| 183 | app.initView(); |
| 184 | } |
| 185 | } else { |
| 186 | $("#loaddata").hide() |
| 187 | $("#nodatahint").text("数据加载异常") |
| 188 | $("#nodata").show(); |
| 189 | app.initView(); |
| 190 | } |
| 191 | } else { |
| 192 | $("#loaddata").hide() |
| 193 | $("#nodatahint").text("请求数据失败") |
| 194 | $("#nodata").show(); |
| 195 | app.initView(); |
| 196 | } |
| 197 | }) |
| 198 | }, |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 199 | checkVersion:function(ver,minver,msg){ |
| 200 | cordova.getAppVersion.getVersionNumber(function (version) { |
| 201 | //alert(version); |
| 202 | if(version<minver){ |
| 203 | //TODO 强制升级 |
| 204 | alert("当前版本过低,为了不影响您的使用,请先升级"); |
| 205 | }else if(ver>version){ |
| 206 | alert("有新的版本"); |
| 207 | } |
| 208 | }); |
| 209 | }, |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 210 | initBillView: function(page) { |
| 211 | var html = ''; |
| 212 | for (var i = 0; i < page.data.length; i++) { |
| 213 | var bean = page.data[i] |
| 214 | html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">'; |
| 215 | html += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />'; |
| 216 | html += '</div><div class="aui-card-list-user-name">'; |
| 217 | html += '<div>' + bean.transdesc + '</div>'; |
| 218 | if (bean.tradeflag == 'in') { |
| 219 | html += '<div class="aui-list-item-right">+' + bean.amount + '</div>'; |
| 220 | } else { |
| 221 | html += '<div class="aui-list-item-right">' + bean.amount + '</div>'; |
| 222 | } |
| 223 | html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>'; |
| 224 | } |
| 225 | $("#billcontent").html(html); |
| 226 | $("#loaddata").hide() |
| 227 | $("#nodata").hide(); |
| 228 | $("#billcontent").show(); |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 229 | |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 230 | }, |
| 231 | initView: function() { |
| 232 | var userid = window.localStorage.getItem("userid"); |
| 233 | var signed = window.localStorage.getItem("signed"); |
| 234 | if (isEmpty(userid)) { |
| 235 | $("#userbank").text("未绑定"); |
| 236 | $("#userbank").css("color", "red") |
| 237 | } else { |
| 238 | $("#userbank").text("已绑定"); |
| 239 | $("userbank").css("color", "#757575"); |
| 240 | } |
| 241 | if (isEmpty(signed) || signed != 'yes') { |
| 242 | $("#usersign").text("未签约"); |
| 243 | $("#usersign").css("color", "red") |
| 244 | } else { |
| 245 | $("#usersign").text("已签约"); |
| 246 | $("usersign").css("color", "#757575"); |
| 247 | } |
| 248 | var phone = window.localStorage.getItem("phoneX"); |
| 249 | if (!isEmpty(phone)) { |
| 250 | $("#userphone").text(phone) |
| 251 | } |
| 252 | var name = window.localStorage.getItem("name"); |
| 253 | if (isEmpty(name)) { |
| 254 | $("#username").text("匿名") |
| 255 | } else { |
| 256 | $("#username").text(name) |
| 257 | $("#homename").text(name) |
| 258 | } |
| 259 | }, |
| 260 | checkBefore: function(callback) { |
| 261 | var uid = window.localStorage.getItem("token"); |
| 262 | if (isEmpty(uid)) { |
| 263 | window.location = "login.html"; |
| 264 | } else { |
| 265 | var userid = window.localStorage.getItem("userid"); |
| 266 | if (isEmpty(userid)) { |
| 267 | var cum = new auiDialog({}); |
| 268 | var confirm = cum.alert({ |
| 269 | title: "提示", |
| 270 | msg: '为了不影响您正常使用相关功能,请先绑定银行卡', |
| 271 | buttons: ['取消', '去绑卡'] |
| 272 | }, function(ret) { |
| 273 | if (ret.buttonIndex == 2) { |
| 274 | window.location = 'bindcard.html' |
| 275 | } |
| 276 | }) |
| 277 | } else { |
| 278 | if (callback) { |
| 279 | callback() |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | }, |
| 284 | checkOther: function(callback) { |
| 285 | var payseted = window.localStorage.getItem("paypwdset"); |
| 286 | var signed = window.localStorage.getItem("signed"); |
| 287 | var cum = new auiDialog({}); |
| 288 | console.log(payseted, signed) |
| 289 | if (isEmpty(payseted) || !payseted || payseted != 'true') { |
| 290 | var confirm = cum.alert({ |
| 291 | title: "提示", |
| 292 | msg: '您还没有设置支付密码,无法使用该功能', |
| 293 | buttons: ['取消', '去设置'] |
| 294 | }, function(ret) { |
| 295 | if (ret.buttonIndex == 2) { |
| 296 | window.location = 'paypwdset.html' |
| 297 | } |
| 298 | }) |
| 299 | } else { |
| 300 | if (isEmpty(signed) || signed != 'yes') { |
| 301 | var confirm = cum.alert({ |
| 302 | title: "提示", |
| 303 | msg: '您尚未签约代扣免密付协议,无法使用该功能', |
| 304 | buttons: ['取消', '去签约'] |
| 305 | }, function(ret) { |
| 306 | if (ret.buttonIndex == 2) { |
| 307 | window.location = 'signxy.html' |
| 308 | } |
| 309 | }) |
| 310 | } else { |
| 311 | if (callback) { |
| 312 | callback() |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | }, |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 317 | toSign: function() { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 318 | window.location = 'signxycheck.html' |
| 319 | }, |
| 320 | toBillDetail: function(refno) { |
| 321 | window.localStorage.setItem("currentrefno", refno); |
| 322 | window.location = 'billdetail.html'; |
| 323 | }, |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 324 | toCard: function() { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 325 | var userid = window.localStorage.getItem("userid"); |
| 326 | if (isEmpty(userid)) { |
| 327 | window.location = 'bindcard.html' |
qiaowei | 60c27e4 | 2019-07-11 16:43:54 +0800 | [diff] [blame] | 328 | } else { |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 329 | window.location = 'cardinfor.html' |
| 330 | } |
qiaowei | 8055aa7 | 2019-12-05 11:40:00 +0800 | [diff] [blame] | 331 | }, |
| 332 | logout:function(){ |
| 333 | window.localStorage.removeItem("token"); |
| 334 | window.location = "login.html"; |
qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 335 | } |
| 336 | }; |
qiaowei | 22e23f8 | 2019-09-26 11:15:57 +0800 | [diff] [blame] | 337 | app.initialize(); |
qiaowei | 5f8f92f | 2019-11-15 10:27:57 +0800 | [diff] [blame] | 338 | |
| 339 | function showRet(url) { |
| 340 | if(isEmpty(url)){ |
| 341 | return; |
| 342 | } |
| 343 | var userid = window.localStorage.getItem("userid"); |
| 344 | //if (url.indexOf("yy.dlsmk.cn")>=0) { |
| 345 | if(url.indexOf("?")>0){ |
| 346 | url=url+'&userid='+userid; |
| 347 | }else{ |
| 348 | url=url+'?userid='+userid; |
| 349 | } |
| 350 | //} |
| 351 | console.log(url) |
| 352 | var inAppBrowserRef = cordova.ThemeableBrowser.open(url, '_blank', { |
| 353 | statusbar: { |
| 354 | color: '#03a9f4ff' |
| 355 | }, |
| 356 | toolbar: { |
| 357 | height: 44, |
| 358 | color: '#03a9f4ff' |
| 359 | }, |
| 360 | title: { |
| 361 | color: '#ffffffff', |
| 362 | showPageTitle: true |
| 363 | }, |
| 364 | backButton: { |
| 365 | image: 'back.png', |
| 366 | imagePressed: 'back.png', |
| 367 | align: 'left', |
| 368 | event: 'backPressed' |
| 369 | }, |
| 370 | closeButton: { |
| 371 | image: 'close.png', |
| 372 | imagePressed: 'close.png', |
| 373 | align: 'left', |
| 374 | event: 'closePressed' |
| 375 | }, |
| 376 | backButtonCanClose: true |
| 377 | }).addEventListener('closePressed', function(params){ |
| 378 | inAppBrowserRef.close(); |
| 379 | //window.location = "main.html" |
| 380 | }); |
| 381 | } |