qiaowei | f044a74 | 2019-07-10 16:04:20 +0800 | [diff] [blame] | 1 | var app = { |
| 2 | |
| 3 | // Application Constructor |
| 4 | initialize: function() { |
| 5 | document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); |
| 6 | }, |
| 7 | |
| 8 | onDeviceReady: function() { |
| 9 | var uid = window.localStorage.getItem("token"); |
| 10 | console.log(CURRENT_INDEX); |
| 11 | $('#scanBtn').click(function() { |
| 12 | //window.location = "scan.html"; |
| 13 | app.checkBefore(function() { |
| 14 | app.checkOther(function() { |
| 15 | window.location = "scan.html"; |
| 16 | }) |
| 17 | }) |
| 18 | }); |
| 19 | $('#qrcodeBtn').click(function() { |
| 20 | app.checkBefore(function() { |
| 21 | app.checkOther(function() { |
| 22 | window.location = "qrcode.html"; |
| 23 | }) |
| 24 | }) |
| 25 | }); |
| 26 | $('#cardBtn').click(function() { |
| 27 | app.checkBefore(function() { |
| 28 | app.checkOther(function() { |
| 29 | window.location = "card.html"; |
| 30 | }) |
| 31 | }) |
| 32 | }); |
| 33 | $('#billBtn').click(function() { |
| 34 | app.checkBefore(function() { |
| 35 | window.location = "bill.html"; |
| 36 | }) |
| 37 | }); |
| 38 | $('#moreBtn').click(function() { |
| 39 | app.checkBefore(function() { |
| 40 | window.location = "bill.html"; |
| 41 | }) |
| 42 | }); |
| 43 | $('#secBtn').click(function() { |
| 44 | app.checkBefore(function() { |
| 45 | window.location = "security.html"; |
| 46 | }) |
| 47 | }); |
| 48 | $('#usersec').click(function() { |
| 49 | app.checkBefore(function() { |
| 50 | window.location = "security.html"; |
| 51 | }) |
| 52 | }); |
| 53 | this.initData(); |
| 54 | }, |
| 55 | initData: function() { |
| 56 | this.loadBill() |
| 57 | |
| 58 | }, |
| 59 | loadBill: function() { |
| 60 | $("#loaddata").show() |
| 61 | $("#nodata").hide(); |
| 62 | var param = { |
| 63 | "pageno": 1 |
| 64 | } |
| 65 | V1Bills(param, function(ok, ret) { |
| 66 | if (ok) { |
| 67 | console.log(ret) |
| 68 | if (ret.code == 200) { |
| 69 | $("#maingt").text(ret.t + "!") |
| 70 | $("#user-amount").text(ret.amount) |
| 71 | $("#user-point").text(ret.point) |
| 72 | if (ret.needrebind) { |
| 73 | window.localStorage.removeItem("userid"); |
| 74 | } else { |
| 75 | window.localStorage.setItem("userid", ret.userid); |
| 76 | } |
| 77 | window.localStorage.setItem("signed", ret.signed); |
| 78 | window.localStorage.setItem("paypwdset", ret.paypwdset); |
| 79 | window.localStorage.setItem("name", ret.name); |
| 80 | if (ret.page && ret.page.count > 0) { |
| 81 | GLOBAL_TODAY = ret.today; |
| 82 | GLOBAL_YESTERDAY = ret.yesterday; |
| 83 | app.initBillView(ret.page) |
| 84 | app.initView(); |
| 85 | } else { |
| 86 | $("#loaddata").hide() |
| 87 | $("#nodatahint").text("暂无数据") |
| 88 | $("#nodata").show(); |
| 89 | app.initView(); |
| 90 | } |
| 91 | } else { |
| 92 | $("#loaddata").hide() |
| 93 | $("#nodatahint").text("数据加载异常") |
| 94 | $("#nodata").show(); |
| 95 | app.initView(); |
| 96 | } |
| 97 | } else { |
| 98 | $("#loaddata").hide() |
| 99 | $("#nodatahint").text("请求数据失败") |
| 100 | $("#nodata").show(); |
| 101 | app.initView(); |
| 102 | } |
| 103 | }) |
| 104 | }, |
| 105 | |
| 106 | initBillView: function(page) { |
| 107 | var html = ''; |
| 108 | for (var i = 0; i < page.data.length; i++) { |
| 109 | var bean = page.data[i] |
| 110 | html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">'; |
| 111 | html += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />'; |
| 112 | html += '</div><div class="aui-card-list-user-name">'; |
| 113 | html += '<div>' + bean.transdesc + '</div>'; |
| 114 | if (bean.tradeflag == 'in') { |
| 115 | html += '<div class="aui-list-item-right">+' + bean.amount + '</div>'; |
| 116 | } else { |
| 117 | html += '<div class="aui-list-item-right">' + bean.amount + '</div>'; |
| 118 | } |
| 119 | html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>'; |
| 120 | } |
| 121 | $("#billcontent").html(html); |
| 122 | $("#loaddata").hide() |
| 123 | $("#nodata").hide(); |
| 124 | $("#billcontent").show(); |
| 125 | |
| 126 | }, |
| 127 | initView: function() { |
| 128 | var userid = window.localStorage.getItem("userid"); |
| 129 | var signed = window.localStorage.getItem("signed"); |
| 130 | if (isEmpty(userid)) { |
| 131 | $("#userbank").text("未绑定"); |
| 132 | $("#userbank").css("color", "red") |
| 133 | } else { |
| 134 | $("#userbank").text("已绑定"); |
| 135 | $("userbank").css("color", "#757575"); |
| 136 | } |
| 137 | if (isEmpty(signed) || signed != 'yes') { |
| 138 | $("#usersign").text("未签约"); |
| 139 | $("#usersign").css("color", "red") |
| 140 | } else { |
| 141 | $("#usersign").text("已签约"); |
| 142 | $("usersign").css("color", "#757575"); |
| 143 | } |
| 144 | var phone = window.localStorage.getItem("phoneX"); |
| 145 | if (!isEmpty(phone)) { |
| 146 | $("#userphone").text(phone) |
| 147 | } |
| 148 | var name = window.localStorage.getItem("name"); |
| 149 | if (isEmpty(name)) { |
| 150 | $("#username").text("匿名") |
| 151 | } else { |
| 152 | $("#username").text(name) |
| 153 | $("#homename").text(name) |
| 154 | } |
| 155 | }, |
| 156 | checkBefore: function(callback) { |
| 157 | var uid = window.localStorage.getItem("token"); |
| 158 | if (isEmpty(uid)) { |
| 159 | window.location = "login.html"; |
| 160 | } else { |
| 161 | var userid = window.localStorage.getItem("userid"); |
| 162 | if (isEmpty(userid)) { |
| 163 | var cum = new auiDialog({}); |
| 164 | var confirm = cum.alert({ |
| 165 | title: "提示", |
| 166 | msg: '为了不影响您正常使用相关功能,请先绑定银行卡', |
| 167 | buttons: ['取消', '去绑卡'] |
| 168 | }, function(ret) { |
| 169 | if (ret.buttonIndex == 2) { |
| 170 | window.location = 'bindcard.html' |
| 171 | } |
| 172 | }) |
| 173 | } else { |
| 174 | if (callback) { |
| 175 | callback() |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | }, |
| 180 | checkOther: function(callback) { |
| 181 | var payseted = window.localStorage.getItem("paypwdset"); |
| 182 | var signed = window.localStorage.getItem("signed"); |
| 183 | var cum = new auiDialog({}); |
| 184 | console.log(payseted, signed) |
| 185 | if (isEmpty(payseted) || !payseted || payseted != 'true') { |
| 186 | var confirm = cum.alert({ |
| 187 | title: "提示", |
| 188 | msg: '您还没有设置支付密码,无法使用该功能', |
| 189 | buttons: ['取消', '去设置'] |
| 190 | }, function(ret) { |
| 191 | if (ret.buttonIndex == 2) { |
| 192 | window.location = 'paypwdset.html' |
| 193 | } |
| 194 | }) |
| 195 | } else { |
| 196 | if (isEmpty(signed) || signed != 'yes') { |
| 197 | var confirm = cum.alert({ |
| 198 | title: "提示", |
| 199 | msg: '您尚未签约代扣免密付协议,无法使用该功能', |
| 200 | buttons: ['取消', '去签约'] |
| 201 | }, function(ret) { |
| 202 | if (ret.buttonIndex == 2) { |
| 203 | window.location = 'signxy.html' |
| 204 | } |
| 205 | }) |
| 206 | } else { |
| 207 | if (callback) { |
| 208 | callback() |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | }, |
| 213 | toSign:function(){ |
| 214 | window.location = 'signxycheck.html' |
| 215 | }, |
| 216 | toBillDetail: function(refno) { |
| 217 | window.localStorage.setItem("currentrefno", refno); |
| 218 | window.location = 'billdetail.html'; |
| 219 | }, |
| 220 | toCard:function(){ |
| 221 | var userid = window.localStorage.getItem("userid"); |
| 222 | if (isEmpty(userid)) { |
| 223 | window.location = 'bindcard.html' |
| 224 | }else{ |
| 225 | window.location = 'cardinfor.html' |
| 226 | } |
| 227 | } |
| 228 | }; |
| 229 | app.initialize(); |