blob: 90977da759a2b0f5233e65dc5331bc2d4ca69873 [file] [log] [blame]
qiaoweif044a742019-07-10 16:04:20 +08001var app = {
2
3 // Application Constructor
4 initialize: function() {
qiaowei60c27e42019-07-11 16:43:54 +08005 this.initTab();
qiaoweif044a742019-07-10 16:04:20 +08006 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
qiaowei22e23f82019-09-26 11:15:57 +08007 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 })
qiaoweif044a742019-07-10 16:04:20 +080057 },
58
59 onDeviceReady: function() {
60 var uid = window.localStorage.getItem("token");
qiaowei22e23f82019-09-26 11:15:57 +080061 this.initJpush();
qiaoweif044a742019-07-10 16:04:20 +080062 $('#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() {
qiaowei22e23f82019-09-26 11:15:57 +080095 window.location = "security.html";
96 /*app.checkBefore(function() {
qiaowei60c27e42019-07-11 16:43:54 +080097 app.checkOther(function() {
98 window.location = "security.html";
99 })
qiaowei22e23f82019-09-26 11:15:57 +0800100 })*/
qiaoweif044a742019-07-10 16:04:20 +0800101 });
102 $('#usersec').click(function() {
103 app.checkBefore(function() {
qiaowei60c27e42019-07-11 16:43:54 +0800104 app.checkOther(function() {
105 window.location = "security.html";
106 })
qiaoweif044a742019-07-10 16:04:20 +0800107 })
108 });
109 this.initData();
110 },
qiaowei22e23f82019-09-26 11:15:57 +0800111 initTab: function() {
qiaowei60c27e42019-07-11 16:43:54 +0800112 $("#maincontent").css("top", $("#maintop").height())
113 var tab = new auiTab({
114 element: document.getElementById("footer"),
115 }, function(ret) {
qiaowei22e23f82019-09-26 11:15:57 +0800116 window.localStorage.setItem("tabindex", ret.index);
117
qiaowei60c27e42019-07-11 16:43:54 +0800118 changeTab(ret.index);
119 });
qiaowei22e23f82019-09-26 11:15:57 +0800120 var tabindex = window.localStorage.getItem("tabindex");
121 if (!tabindex || tabindex == 0) {
qiaowei60c27e42019-07-11 16:43:54 +0800122 tabindex = 1
123 }
124 changeTab(tabindex);
125 tab.setActive(tabindex)
qiaowei22e23f82019-09-26 11:15:57 +0800126
127 function changeTab(index) {
qiaowei60c27e42019-07-11 16:43:54 +0800128 if (index == 1) {
129 $("#main1").show();
130 $("#main2").hide();
131 } else if (index == 2) {
132 $("#main1").hide();
133 $("#main2").show();
134 }
135 }
136 },
qiaoweif044a742019-07-10 16:04:20 +0800137 initData: function() {
138 this.loadBill()
qiaoweif044a742019-07-10 16:04:20 +0800139 },
140 loadBill: function() {
141 $("#loaddata").show()
142 $("#nodata").hide();
143 var param = {
144 "pageno": 1
145 }
146 V1Bills(param, function(ok, ret) {
147 if (ok) {
qiaowei22e23f82019-09-26 11:15:57 +0800148 //console.log(ret)
qiaoweif044a742019-07-10 16:04:20 +0800149 if (ret.code == 200) {
qiaowei22e23f82019-09-26 11:15:57 +0800150 app.checkVersion(ret.version,ret.minversion,ret.versionmsg);
qiaoweif044a742019-07-10 16:04:20 +0800151 $("#maingt").text(ret.t + "!")
152 $("#user-amount").text(ret.amount)
153 $("#user-point").text(ret.point)
154 if (ret.needrebind) {
155 window.localStorage.removeItem("userid");
156 } else {
157 window.localStorage.setItem("userid", ret.userid);
158 }
159 window.localStorage.setItem("signed", ret.signed);
160 window.localStorage.setItem("paypwdset", ret.paypwdset);
161 window.localStorage.setItem("name", ret.name);
162 if (ret.page && ret.page.count > 0) {
163 GLOBAL_TODAY = ret.today;
164 GLOBAL_YESTERDAY = ret.yesterday;
165 app.initBillView(ret.page)
166 app.initView();
167 } else {
168 $("#loaddata").hide()
169 $("#nodatahint").text("暂无数据")
170 $("#nodata").show();
171 app.initView();
172 }
173 } else {
174 $("#loaddata").hide()
175 $("#nodatahint").text("数据加载异常")
176 $("#nodata").show();
177 app.initView();
178 }
179 } else {
180 $("#loaddata").hide()
181 $("#nodatahint").text("请求数据失败")
182 $("#nodata").show();
183 app.initView();
184 }
185 })
186 },
qiaowei22e23f82019-09-26 11:15:57 +0800187 checkVersion:function(ver,minver,msg){
188 cordova.getAppVersion.getVersionNumber(function (version) {
189 //alert(version);
190 if(version<minver){
191 //TODO 强制升级
192 alert("当前版本过低,为了不影响您的使用,请先升级");
193 }else if(ver>version){
194 alert("有新的版本");
195 }
196 });
197 },
qiaoweif044a742019-07-10 16:04:20 +0800198 initBillView: function(page) {
199 var html = '';
200 for (var i = 0; i < page.data.length; i++) {
201 var bean = page.data[i]
202 html += '<div class="aui-card-list-header aui-card-list-user" onclick="app.toBillDetail(\'' + bean.refno + '\')">';
203 html += '<div class="aui-card-list-user-avatar"><img src="img/icon_meal.png" class="aui-margin-r-10 aui-img-round" />';
204 html += '</div><div class="aui-card-list-user-name">';
205 html += '<div>' + bean.transdesc + '</div>';
206 if (bean.tradeflag == 'in') {
207 html += '<div class="aui-list-item-right">+' + bean.amount + '</div>';
208 } else {
209 html += '<div class="aui-list-item-right">' + bean.amount + '</div>';
210 }
211 html += '</div><div class="aui-card-list-user-info">' + formatDateNoYear(bean.transdate, bean.transtime) + '</div></div>';
212 }
213 $("#billcontent").html(html);
214 $("#loaddata").hide()
215 $("#nodata").hide();
216 $("#billcontent").show();
qiaowei60c27e42019-07-11 16:43:54 +0800217
qiaoweif044a742019-07-10 16:04:20 +0800218 },
219 initView: function() {
220 var userid = window.localStorage.getItem("userid");
221 var signed = window.localStorage.getItem("signed");
222 if (isEmpty(userid)) {
223 $("#userbank").text("未绑定");
224 $("#userbank").css("color", "red")
225 } else {
226 $("#userbank").text("已绑定");
227 $("userbank").css("color", "#757575");
228 }
229 if (isEmpty(signed) || signed != 'yes') {
230 $("#usersign").text("未签约");
231 $("#usersign").css("color", "red")
232 } else {
233 $("#usersign").text("已签约");
234 $("usersign").css("color", "#757575");
235 }
236 var phone = window.localStorage.getItem("phoneX");
237 if (!isEmpty(phone)) {
238 $("#userphone").text(phone)
239 }
240 var name = window.localStorage.getItem("name");
241 if (isEmpty(name)) {
242 $("#username").text("匿名")
243 } else {
244 $("#username").text(name)
245 $("#homename").text(name)
246 }
247 },
248 checkBefore: function(callback) {
249 var uid = window.localStorage.getItem("token");
250 if (isEmpty(uid)) {
251 window.location = "login.html";
252 } else {
253 var userid = window.localStorage.getItem("userid");
254 if (isEmpty(userid)) {
255 var cum = new auiDialog({});
256 var confirm = cum.alert({
257 title: "提示",
258 msg: '为了不影响您正常使用相关功能,请先绑定银行卡',
259 buttons: ['取消', '去绑卡']
260 }, function(ret) {
261 if (ret.buttonIndex == 2) {
262 window.location = 'bindcard.html'
263 }
264 })
265 } else {
266 if (callback) {
267 callback()
268 }
269 }
270 }
271 },
272 checkOther: function(callback) {
273 var payseted = window.localStorage.getItem("paypwdset");
274 var signed = window.localStorage.getItem("signed");
275 var cum = new auiDialog({});
276 console.log(payseted, signed)
277 if (isEmpty(payseted) || !payseted || payseted != 'true') {
278 var confirm = cum.alert({
279 title: "提示",
280 msg: '您还没有设置支付密码,无法使用该功能',
281 buttons: ['取消', '去设置']
282 }, function(ret) {
283 if (ret.buttonIndex == 2) {
284 window.location = 'paypwdset.html'
285 }
286 })
287 } else {
288 if (isEmpty(signed) || signed != 'yes') {
289 var confirm = cum.alert({
290 title: "提示",
291 msg: '您尚未签约代扣免密付协议,无法使用该功能',
292 buttons: ['取消', '去签约']
293 }, function(ret) {
294 if (ret.buttonIndex == 2) {
295 window.location = 'signxy.html'
296 }
297 })
298 } else {
299 if (callback) {
300 callback()
301 }
302 }
303 }
304 },
qiaowei60c27e42019-07-11 16:43:54 +0800305 toSign: function() {
qiaoweif044a742019-07-10 16:04:20 +0800306 window.location = 'signxycheck.html'
307 },
308 toBillDetail: function(refno) {
309 window.localStorage.setItem("currentrefno", refno);
310 window.location = 'billdetail.html';
311 },
qiaowei60c27e42019-07-11 16:43:54 +0800312 toCard: function() {
qiaoweif044a742019-07-10 16:04:20 +0800313 var userid = window.localStorage.getItem("userid");
314 if (isEmpty(userid)) {
315 window.location = 'bindcard.html'
qiaowei60c27e42019-07-11 16:43:54 +0800316 } else {
qiaoweif044a742019-07-10 16:04:20 +0800317 window.location = 'cardinfor.html'
318 }
319 }
320};
qiaowei22e23f82019-09-26 11:15:57 +0800321app.initialize();