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