-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
executable file
·648 lines (593 loc) · 17.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
<!doctype html>
<html id="error">
<head>
<meta charset="UTF-8">
<title>大神</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link href="css/mui.min.css" rel="stylesheet" />
<link href="css/font-awesome.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<style>
.check {
background: #fff;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
display: none;
z-index: 99;
}
.check img {
margin-top: 25%;
width: 5em;
}
.check p {
margin-top: 10px;
}
.mui-icon-refreshempty {
padding: 10px;
color: gray;
font-size: 3em;
}
.btn-float {
position: fixed;
bottom: 6%;
right: 4%;
height: 2.2em;
width: 2.2em;
font-size: 1.5em;
text-align: center;
border-radius: 100em;
z-index: 10;
box-shadow: 0px 0px 3px 2px #CCCCCC;
}
#list {
display: none;
}
.price {
color: #FF0000;
font-weight: 600;
font-size: 1.2em;
}
#tab {
display: none;
white-space: nowrap;
}
#search-box {
display: none;
}
#search-box .mui-row:first-child {
background: #fff;
}
#search-box .mui-row:last-child .mui-col-xs-4 {
padding-top: 8px;
font-size: 16px;
color: dodgerblue;
}
#tab a {
color: #000000;
}
#tab a.active {
color: #007aff;
border-bottom: solid 2px #007aff;
}
#news_box {
margin-top: 10px;
text-align: center;
display: none;
}
#touch_news {
color: #fff;
opacity: .5;
border-radius: 10px;
background: #222222;
font-size: 12px;
padding: 8px 12px;
}
</style>
</head>
<body>
<!--
作者:devilyouwei@gmail.com
时间:2017-08-13
描述:主页,列出需求单,预加载地图页
-->
<div class="mui-content" id="content">
<!-- 错误页面 -->
<div class="check" id="check">
<img src="images/cloud-error.png" />
<p>连接服务器失败,请重试</p>
<div class="mui-row">
<i id="refresh" class="mui-icon mui-icon-refreshempty"></i>
</div>
</div>
<!--顶部分类选项卡-->
<div id="tab" class="mui-scroll-wrapper mui-padding-vertical-xs">
<div class="mui-scroll">
<a class="mui-padding-horizontal-xs" data-tab-id="0">全部</a>
<a class="mui-padding-horizontal-xs" v-for="item in tabs" v-bind:data-tab-id="item.id">{{item.title}}</a>
</div>
</div>
<div id="search-box">
<div class="mui-row mui-padding-xs">
<div class="mui-col-xs-7">
<input class="mui-margin-0" id="search" type="search" placeholder="搜索内容" />
</div>
<div class="mui-col-xs-5">
<button class="mui-btn mui-btn-grey mui-margin-left" id="search_confirm">搜索</button>
<button class="mui-btn mui-btn-default mui-pull-right" id="search_cancel">取消</button>
</div>
</div>
<div class="mui-row mui-padding-top-sm mui-padding-horizontal-sm">
<div class="mui-col-xs-4">
最新需求列表
</div>
<div class="mui-col-xs-8">
<button class="mui-btn mui-btn-primary" id="myLoc"><i class="icon-location-arrow"> </i>我的位置</button>
<button class="mui-btn mui-btn-primary mui-pull-right" id="showMap"><i class="icon-location-arrow"> </i>订单分布图</button>
</div>
</div>
</div>
<div id="list">
<div id="news_box">
<span id="touch_news"></span>
</div>
<div class="cards">
<div class="mui-card" v-for="item in items">
<div class="mui-card-header mui-card-media">
<img v-bind:src="item.my_icon_sm" onerror="this.src='images/my_icon.jpg'" />
<div class="mui-media-body">
发单方:{{item.user_name}}
<p>{{item.create_time}}</p>
<p>服务编号:{{item.format_id}}</p>
</div>
</div>
<div class="mui-card-content">
<div class="mui-card-content-inner">
<p>需求类别:{{item.title}}</p>
<p style="color: #333;">概述:{{item.content}}</p>
<p v-show="!item.loc==''"><i class="mui-icon mui-icon-location-filled"> </i>{{item.loc}}</p>
</div>
</div>
<div class="mui-card-footer">
<span class="price" href="#">{{item.reward}}<span v-show="item.price">:¥{{item.price}}</span></span>
<a href="#" class="mui-card-link" v-bind:data-id="item.id" v-bind:data-title="item.title">查看详情</a>
</div>
</div>
</div>
</div>
</div>
<script src="js/mui.min.js"></script>
<script src="js/app.js"></script>
<script src="js/vue.min.js"></script>
<script type="text/javascript">
(function($, doc) {
$.init({
pullRefresh: {
container: '#list',
down: {
style: 'circle',
callback: init_index_ques
},
up: {
contentrefresh: '加载中...',
callback: more_index_ques
}
}
});
var TAB_ID = 0; //当前分类ID
var _self = null; //当前主窗口
var _map = null;
var _offcanvas = null; //offcanvas子窗口
var MIN_ID = 0;
var MAX_ID = 0;
var news_interval = null; //循环新消息计时器
var state = app.getState();
var vue = new Vue({
el: '.mui-content',
data: {
items: [],
tabs: []
}
});
$.plusReady(function() {
app.log();
//本地检测
if(!state.token) {
mui.toast("登陆状态失效");
return app.toLogin();
}
init_title(); //初始化头部
//初始化两大子页面
setTimeout(init_offcanvs, 300)
setTimeout(check_login, 400)
//返回按钮退出
var backButtonPress = 0;
mui.back = function(event) {
//如果offcanvas开着先关闭
if(parseInt(_self.getStyle().left) > 0) {
closeMenu();
return;
}
backButtonPress++;
if(backButtonPress > 1) {
plus.runtime.quit();
} else {
mui.toast('再按一次退出应用');
}
setTimeout(function() {
backButtonPress = 0;
}, 1000);
return false;
};
});
mui(".cards").on("tap", "a", function() {
var id = this.getAttribute("data-id");
var title = this.getAttribute("data-title");
$.openWindow({
id: "ques/detail",
url: "/ques/detail.html",
styles: {
popGesture: "none",
render: "always",
titleNView: { //详情页原生导航配置
backgroundColor: '#3d80da', //导航栏背景色
titleText: title, //导航栏标题
titleColor: '#fff', //文字颜色
autoBackButton: true, //自动绘制返回箭头
}
},
show: {
aniShow: 'slide-in-right',
},
waiting: {
autoShow: false
},
extras: {
ques_id: id
}
});
});
window.addEventListener("checkLogin", check_login); //其他页面刷新本地数据
//绘制头部
function init_title() {
//绘制顶部图标
_self = plus.webview.currentWebview();
var titleView = _self.getNavigationbar();
if(!titleView) {
titleView = plus.webview.getLaunchWebview().getNavigationbar();
}
titleView.drawRect("#cccccc", {
top: "43px",
height: "1px",
left: "0px"
}); //绘制底部边线
//绘制左上角menu图标
var bitmap_menu = new plus.nativeObj.Bitmap("menu");
bitmap_menu.loadBase64Data("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAKlBMVEUAAAAAev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8AAABINtoqAAAADHRSTlMA/fPQ0M/e3tzs7OjgY5g4AAAAAWJLR0QAiAUdSAAAAAd0SU1FB+EBFwEbOGGUPSIAAAA2SURBVDjLY2AY9oDxDBZwCJ8EswsW4DrQ/hicgPTQZSvHAioG2h+DE5AeupyrsIDVA+0PqgEAu36BkQX5nBQAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDEtMjNUMDE6Mjc6NTYrMDg6MDC8FK1uAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTAxLTIzVDAxOjI3OjU2KzA4OjAwzUkV0gAAAABJRU5ErkJggg==");
titleView.drawBitmap(bitmap_menu, {}, {
top: "10px",
left: "10px",
width: "24px",
height: "24px"
});
titleView.interceptTouchEvent(true);
titleView.addEventListener("click", function(e) {
var x = e.clientX;
if(x < 44) { //触发menu菜单
var _left = parseInt(_self.getStyle().left);
if(_left > 0) { //处于显示状态
closeMenu();
} else {
openMenu();
}
}
}, false);
}
//初始化分类卡
function init_tabs() {
app.request("Ques", "getQuesTitle", {}, function(res) {
if(res.status == 1) {
vue.tabs = res.data;
doc.getElementById("tab").style.display = "block";
doc.getElementById("search-box").style.display = "block";
//分类选择
mui("#tab").on("tap", "a", function() {
//去除已经激活tab的样式
var active = doc.querySelector(".active");
if(active)
active.classList.remove("active");
//激活当前tab卡
this.classList.add("active");
//清空内容
vue.items = [];
search.value = ""; //重置搜素哦
TAB_ID = this.getAttribute("data-tab-id");
init_index_ques();
});
} else {
mui.toast(res.info);
}
}, function(xhr) {
});
}
var search = doc.getElementById("search");
//监听搜索
search.addEventListener("keyup", function(e) {
var self = this;
if(e && e.keyCode == 13) {
init_index_ques();
setTimeout(function() {
self.blur();
}, 300);
}
});
//搜索按钮
doc.getElementById("search_confirm").addEventListener("tap", function() {
init_index_ques();
});
doc.getElementById("search_cancel").addEventListener("tap", function() {
search.value = "";
init_index_ques();
});
//检测登陆状态,并刷新本地数据
function check_login() {
//直到检查登陆状态结束后才关闭载入界面和全屏
app.request('User', 'checkLogin', {}, function(res) {
//关闭载入界面和全屏
plus.navigator.closeSplashscreen();
unfullscreen();
if(res.status == 1 && res.data.token == state.token) {
//如果检测服务器存在且本地相对应不操作
app.setUserInfo(res.data); //存储服务器获取的个人信息
mui.fire(_offcanvas, "updateHeadInfo"); //策划菜单更新信息
//update_user_position();
init_tabs();
init_index_ques();
//尚未完善资料
if(res.data.is_authentic == 0) {
toPersonal();
}
} else {
mui.toast(res.info);
return app.toLogin();
}
}, function(xhr) {
//关闭载入界面和全屏
plus.navigator.closeSplashscreen();
unfullscreen();
doc.getElementById("check").style.display = "block"; //显示重试按钮
}, "none");
}
//初始化侧滑菜单
function init_offcanvs() {
var menu_style = {
left: "-70%",
width: '70%',
popGesture: "none",
render: "always",
};
_offcanvas = plus.webview.create("offcanvas.html", "offcanvas", menu_style, {});
_offcanvas.show(); //显示offcanvas
//启用侧滑拖拽操作,延时的原因是menu页是延时创建的,所以这里需要相应延时
/*
setTimeout(function() {
_self.drag({
direction: "right",
moveMode: "followFinger"
}, {
view: _offcanvas,
moveMode: "follow"
}, function(e) {});
}, 350);
*/
}
window.addEventListener("updateQues", init_index_ques);
document.addEventListener("resume", init_index_ques, false);
//初始化主页的需求单
function init_index_ques() {
app.request("Index", "getQues", {
min_id: 0,
tab_id: TAB_ID,
search: trim(search.value)
}, function(res) {
document.getElementById("list").style.display = "block";
$('#list').pullRefresh().endPulldown();
//playRefresh();
if(res.login == 0) {
mui.toast(res.info);
return app.toLogin();
}
if(res.status == 1) {
vue.items = convert(res.data);
if(vue.items[0] && MAX_ID<vue.items[0].id)
MAX_ID = vue.items[0].id;
doc.getElementById("news_box").style.display = "none"; //关闭新需求消息盒子
//传入当前最新的需求单id。也就是最大的id
//clearInterval(news_interval); //关闭原来的计时器
//start_news_interval();
}
}, function(xhr) {
$('#list').pullRefresh().endPulldown();
//error.innerHTML = xhr.response;
}, "none");
}
//加载更多主页需求单
function more_index_ques() {
app.request("Index", "getQues", {
min_id: MIN_ID,
tab_id: TAB_ID,
search: trim(search.value)
}, function(res) {
$('#list').pullRefresh().endPullup();
if(res.login == 0) {
mui.toast(res.info);
return app.toLogin();
}
if(res.status == 1) {
vue.items = vue.items.concat(convert(res.data));
}
}, function(xhr) {
$('#list').pullRefresh().endPullup();
}, "none");
}
function convert(items) {
//已经加载到没有可加载数据,结束
if(items.length == 0) {
//mui('#list').pullRefresh().endPullup(true);
return items;
}
items.forEach(function(item) {
item.create_time = dateUtils.format(item.create_time);
item.format_id = format_id(item.id);
});
MIN_ID = items[items.length - 1].id;
return items;
}
doc.getElementById("refresh").addEventListener("tap", function() {
doc.getElementById("check").style.display = "none";
check_login();
}, false);
/*---------------------------------------------地图页相关---------------------------------------------------*/
//创建地图页面
function create_map() {
if(!plus.webview.getWebviewById("service/map")) {
_map = plus.webview.create("service/map.html", "service/map", {
titleNView: { //详情页原生导航配置
titleText: '附近需求',
backgroundColor: '#3d80da', //导航栏背景色
titleColor: '#fff', //文字颜色
type: 'transparent', //透明渐变样式
autoBackButton: true, //自动绘制返回箭头
}
});
}
}
doc.getElementById("showMap").addEventListener("tap", function() {
plus.nativeUI.showWaiting("定位启动中...", {
back: 'none'
}); //显示加载等待
create_map();
}, false);
doc.getElementById("myLoc").addEventListener("tap", function() {
plus.nativeUI.showWaiting("定位启动中...", {
back: 'none'
}); //显示加载等待
create_map();
}, false);
//为了避免闪屏,等到地图隐藏后才绑定跳转按钮
window.addEventListener("showMapNow", function() {
_map.show("slide-in-right", 200);
plus.nativeUI.closeWaiting();
//推迟地图刷新,防止卡顿
setTimeout(function() {
mui.fire(_map, "updateMap");
}, 300);
});
/*----------------------------------offcanvas----------------------------------------------------*/
/**
* 显示侧滑菜单
*/
function openMenu() {
plus.webview.startAnimation({
'view': _self,
'styles': {
'fromLeft': '0',
'toLeft': "70%"
},
'action': 'show'
}, {
'view': _offcanvas,
'styles': {
'fromLeft': "-70%",
'toLeft': '0'
},
'action': 'show'
},
function(e) {
//console.log(JSON.stringify(e));
//if(e.id == _self.id) {}
}.bind(this)
)
};
/**
* 关闭菜单
*/
function closeMenu() {
plus.webview.startAnimation({
'view': _self,
'styles': {
'fromLeft': '70%',
'toLeft': "0"
},
'action': 'show'
}, {
'view': _offcanvas,
'styles': {
'fromLeft': "0",
'toLeft': '-70%'
},
'action': 'show'
},
function(e) {
//console.log(JSON.stringify(e));
//if(e.id == _self.id) {}
}.bind(this)
)
};
function toPersonal() {
mui.confirm("您还没有完善您的众帮个人资料,请点击侧滑栏个人资料进行编辑!<br><font color='red'>未完善资料情况下,您不能进行发单接单操作!</font>", "完善资料", ['稍微等等', '好的,带我去'], function(e) {
if(e.index == 1) {
$.openWindow({
id: 'user/personal',
url: 'user/personal.html'
});
}
}, "div");
}
//进图app立即先更新一下坐标
function update_user_position() {
plus.geolocation.getCurrentPosition(function(p) {
updatePos(new plus.maps.Point(p.coords.longitude, p.coords.latitude));
}, function(e) {}, {
enableHighAccuracy: true,
provider: "baidu"
});
}
doc.getElementById("touch_news").addEventListener("tap", function() {
doc.getElementById("news_box").style.display = "none";
init_index_ques();
});
//获取最新需求数
function start_news_interval() {
news_interval = setInterval(function() {
app.request("Index", "countNewQues", {
max_id: MAX_ID
}, function(res) {
if(res.login == 0) {
mui.toast(res.info);
return app.toLogin();
}
if(res.status == 1) {
if(res.data > 0) {
doc.getElementById("touch_news").innerText = res.data + "条新需求";
doc.getElementById("news_box").style.display = "block";
plus.audio.createPlayer("/audio/yao.mp3").play();
//clearInterval(news_interval);
} else {}
} else {
mui.toast("获取最新需求数目失败!");
}
}, function(xhr) {
error.innerHTML = xhr.response;
}, "none");
}, 5000);
}
}(mui, document));
</script>
</body>
</html>