Sfoglia il codice sorgente

新增发现列表功能

xuchunyang 8 anni fa
parent
commit
03af942e5b
3 ha cambiato i file con 312 aggiunte e 6 eliminazioni
  1. 5 4
      app/html/discover.html
  2. 2 2
      app/index.html
  3. 305 0
      app/js/discover.js

+ 5 - 4
app/html/discover.html

@ -12,14 +12,14 @@
12 12
13 13
	<body>
14 14
		<header class="mui-bar mui-bar-nav toptitbox">
15
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left topback"></a>
16 15
			<h1 class="mui-title toptit">发现</h1>
17 16
		</header>
18 17
19 18
		<!-- 主界面具体展示内容 -->
20
		<div class="mui-content bodyBg mui-scroll-wrapper">
19
		<div class="mui-content mui-scroll-wrapper bodyBg" id="pullrefresh2" >	
21 20
			<div class="mui-scroll">
22
				<ul class="mui-table-view table-item">
21
				<ul class="mui-table-view table-item" id="discoverBox"></ul>
22
				<ul class="mui-table-view table-item" style="display: none;">
23 23
					<li class="mui-table-view-cell">
24 24
				        <div class="table-item-media mui-clearfix">
25 25
				        	<div class="table-item-logo userhead"></div><!--企业cmplogo--><!--企业标志authicon-com-ok-->
@ -70,10 +70,11 @@
70 70
			        </li>
71 71
			    </ul>
72 72
			</div>
73
				
74 73
		</div>
75 74
		<script src="../js/public/mui.min.js"></script>
76 75
		<script src="../js/public/base.js"></script>
76
		<script src="../js/public/zepto.min.js"></script>
77
		<script src="../js/discover.js" ></script>
77 78
	</body>
78 79
79 80
</html>

+ 2 - 2
app/index.html

@ -32,7 +32,7 @@
32 32
	<script src="js/public/base.js"></script>
33 33
	
34 34
<script type="text/javascript" charset="utf-8">
35
	var subpages = ['html/index_home.html', 'html/consult_home.html', 'html/myaccount.html'];
35
	var subpages = ['html/index_home.html', 'html/discover.html', 'html/consult_home.html', 'html/myaccount.html'];
36 36
	var subpage_style = {
37 37
		top: '0px',
38 38
		bottom: '51px'
@ -41,7 +41,7 @@
41 41
	//创建子页面,首个选项卡页面显示,其它均隐藏;
42 42
	mui.plusReady(function() {
43 43
		var self = plus.webview.currentWebview();
44
		for(var i = 0; i < 3; i++) {
44
		for(var i = 0; i < 4; i++) {
45 45
			var temp = {};
46 46
			var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
47 47
			if(i > 0) {

+ 305 - 0
app/js/discover.js

@ -0,0 +1,305 @@
1
//发现模块
2
var pageIndex = 1; // 页数
3
var allPages = 1; // 总页数
4
var discoverBox = document.body.querySelector('#discoverBox');
5

6
/*点击列表*/
7
$('#discoverBox').on('click', '.newsurl', function() {
8
	var id = $(this).attr("data-id");
9
	var datatype = $(this).attr("data-type");
10
	if(datatype == 1 || datatype == 2) {
11
		mui.openWindow({
12
			url: '../html/professorArticle.html',
13
			id: 'html/professorArticle.html',
14
			show: {
15
				autoShow: false,
16
				aniShow: "slide-in-right",
17
			},
18
			extras: {
19
				articleId: id,
20
			}
21
		});
22
	} else if(datatype == 3) {
23
		mui.openWindow({
24
			url: '../html/resinforbrow.html',
25
			id: 'html/resinforbrow.html',
26
			show: {
27
				autoShow: false,
28
				aniShow: "slide-in-right",
29
			},
30
			extras: {
31
				resourceId: id,
32
			}
33
		});
34
	}
35
});
36

37
/*点击头像*/
38
$('#discoverBox').on('click', '.gouserurl', function() {
39
	var id = $(this).parents(".mui-table-view-cell").find(".userurl").attr("data-id");
40
	var datatype = $(this).parents(".mui-table-view-cell").find(".newsurl").attr("data-type");
41
	var iftauth = $(this).parents(".mui-table-view-cell").find(".userurl").attr("data-iftauth");
42
	//alert(datatype)
43
	if(datatype == 1 || datatype == 3) {
44
		mui.openWindow({
45
			url: '../html/proinforbrow.html',
46
			id: 'html/proinforbrow.html',
47
			show: {
48
				autoShow: false,
49
				aniShow: "slide-in-right",
50
			},
51
			extras: {
52
				proid: id,
53
			}
54
		});
55
	} else if(datatype == 2) {
56
		if(iftauth == 3) {
57
			mui.openWindow({
58
				url: '../html/cmpinfor-index.html',
59
				id: 'cmpinfor-index.html',
60
				show: {
61
					//autoShow: false,
62
					aniShow: "slide-in-right",
63
				},
64
				extras: {
65
					orgId: id,
66
				}
67
			});
68
		} else {
69
			mui.openWindow({
70
				url: '../html/cmpinfor-Unindex.html',
71
				id: 'cmpinfor-Unindex.html',
72
				show: {
73
					autoShow: false,
74
					aniShow: "slide-in-right",
75
				},
76
				extras: {
77
					orgId: id,
78
					flag: 0
79
				}
80
			});
81
		}
82
	}
83
});
84

85
/*页面数据初始化*/
86
getOnePase();
87

88
mui.init({
89
	pullRefresh: {
90
		container: '#pullrefresh2',
91
		up: {
92
			contentrefresh: '正在加载...',
93
			//auto:true,
94
			//height:100, 
95
			callback: pullupRefresh
96
		}
97
	}
98
});
99

100
function pullupRefresh() {
101
	pageIndex = ++pageIndex;
102
	setTimeout(function() {
103
		getaData()
104
	}, 1000);
105
}
106
/*时间转换*/
107
function Time(dealtime) {
108
	var s = dealtime;
109
	var m = s.substr(4, 2);
110
	var d = s.substr(6, 2);
111
	var formatTime = m.replace(/\b(0+)/gi, "") + "月" + d + "日";
112
	return formatTime;
113
}
114

115
/*获取上拉加载更多数据*/
116
function getaData() {
117
	mui.plusReady(function() {
118
		mui.ajax(baseUrl + '/ajax/article/pqFind', {
119
			data: {
120
				"pageNo": pageIndex,
121
				"pageSize": 20,
122
			},
123
			dataType: 'json', //数据格式类型
124
			type: 'GET', //http请求类型
125
			timeout: 10000,
126
			async: true,
127
			success: function(data) {
128
				if(data.success) {
129
					//console.log("成功");
130
					var dice1 = data.data.total; //总条数
131
					var dice2 = data.data.pageSize; //每页条数
132
					var result = '';
133
					if(pageIndex == 1) { //下拉刷新需要先清空数据
134
						table.innerHTML = ''; // 在这里清空可以防止刷新时白屏
135
					}
136
					allPages = dice1 / dice2;
137
					var datalist = data.data.data;
138
					datalistEach(datalist);
139
					if(pageIndex < allPages) {
140
						mui('#pullrefresh2').pullRefresh().endPullupToRefresh(false); /*能上拉*/
141
					} else {
142
						mui('#pullrefresh2').pullRefresh().endPullupToRefresh(true); /*不能上拉*/
143
					}
144
				}
145
			},
146
			error: function() {
147
				plus.nativeUI.toast("服务器链接超时", toastStyle);
148
				mui('#pullrefresh2').pullRefresh().endPullupToRefresh(true);
149
			}
150
		});
151
	});
152
}
153

154
/*获取第一页数据*/
155
function getOnePase() {
156
	mui.plusReady(function() {
157
		mui.ajax(baseUrl + '/ajax/article/pqFind', {
158
			data: {
159
				"pageNo": 1,
160
				"pageSize": 20,
161
			},
162
			dataType: 'json', //数据格式类型
163
			type: 'GET', //http请求类型
164
			timeout: 10000,
165
			async: true,
166
			success: function(data) {
167
				console.log(data)
168
				discoverBox.innerHTML = "";
169
				if(data.success && data.data) {
170
					plus.nativeUI.closeWaiting();
171
					var datalist = data.data.data;
172
					datalistEach(datalist);
173
				}
174
			},
175
			error: function() {
176
				plus.nativeUI.toast("服务器链接超时", toastStyle);
177
			}
178
		});
179
	});
180
}
181

182
/*数据遍历*/
183
function datalistEach(datalist) {
184
	mui.each(datalist, function(index, item) {
185
		var itemlist = '';
186
		var itemlist = '<li class="mui-table-view-cell">';
187
		itemlist += '<div class="table-item-media mui-clearfix userurl" >';
188
		itemlist += '<div class="table-item-logo gouserurl" id="userimg"></div>';
189
		itemlist += '<div class="table-item-name mui-clearfix positionR"><span id="nameSpan" class="gouserurl"></span><em class="authicon"></em></div>';
190
		itemlist += '</div><div class="flexCenter table-item-cell newsurl">';
191
		itemlist += '<div class="table-item-img artical-default" id="newsimg"></div>';
192
		itemlist += '<div class="table-item-body"><p class="listtit mui-ellipsis-2" id="centent"></p></div>';
193
		itemlist += '</div><div><em class="cmpLable" id="newstype"></em>';
194
		itemlist += '<span class="timeLabel" id="time"></span></div></li>';
195
		$itemlist = $(itemlist);
196
		$("#discoverBox").append($itemlist);
197
		var type = item.type;
198
		$itemlist.find("#centent").text(item.name);
199
		$itemlist.find("#time").text(Time(item.createTime));
200
		$itemlist.find(".newsurl").attr("data-id", item.id);
201
		$itemlist.find(".newsurl").attr("data-type", item.type);
202
		if(item.image) {
203
			$itemlist.find("#newsimg").attr("style", "background-image: url(" + baseUrl + "/data/article/" + item.image + ");");
204
		}
205
		if(type == 1) { //专家文章
206
			$itemlist.find("#newstype").text("文章");
207
			$itemlist.find("#newstype").addClass("articalLabel");
208
			$itemlist.find("#newsimg").addClass("artical-default");
209
			$itemlist.find("#userimg").addClass("userhead");
210
			userFun(item.owner, $itemlist);
211
		} else if(type == 2) { //企业文章
212
			$itemlist.find("#newstype").text("文章");
213
			$itemlist.find("#newstype").addClass("articalLabel");
214
			$itemlist.find("#newsimg").addClass("artical-default");
215
			$itemlist.find("#userimg").addClass("cmplogo");
216
			cmpFun(item.owner, $itemlist)
217
		} else if(type == 3) { //专家资源
218
			$itemlist.find("#newstype").text("资源");
219
			$itemlist.find("#newstype").addClass("resourceLabel");
220
			$itemlist.find("#newsimg").addClass("resource-default");
221
			$itemlist.find("#userimg").addClass("userhead");
222
			userFun(item.owner, $itemlist);
223
		}
224

225
	});
226

227
}
228

229
/*用户信息*/
230
function userFun(id, $itemlist) {
231
	mui.ajax(baseUrl + '/ajax/professor/baseInfo/' + id, {
232
		"type": "get",
233
		"async": true,
234
		"success": function(data) {
235
			console.log(data);
236
			if(data.success && data.data) {
237
				$itemlist.find("#nameSpan").text(data.data.name);
238
				if(data.data.hasHeadImage == 1) {
239
					$itemlist.find("#userimg").attr("style", "background-image: url(" + baseUrl + "/images/head/" + data.data.id + "_m.jpg);");
240
				}
241
				$itemlist.find(".userurl").attr("data-id", data.data.id);
242
				var userType = autho(data.data.authType, data.data.orgAuth, data.data.authStatus);
243
				$itemlist.find(".authicon").attr("title", userType.title);
244
				$itemlist.find(".authicon").addClass(userType.sty);
245

246
			}
247
		},
248
		"error": function() {
249
			plus.nativeUI.toast("服务器链接超时", toastStyle);
250
		}
251
	});
252
}
253

254
/*企业用户信息*/
255
function cmpFun(id, $itemlist) {
256
	mui.ajax(baseUrl + '/ajax/org/' + id, {
257
		"type": "get",
258
		"async": true,
259
		"success": function(data) {
260
			console.log(data);
261
			if(data.success && data.data) {
262
				if(data.data.forShort) {
263
					$itemlist.find("#nameSpan").text(data.data.forShort);
264
				} else {
265
					$itemlist.find("#nameSpan").text(data.data.name);
266
				}
267
				if(data.data.hasOrgLogo) {
268
					$itemlist.find("#userimg").attr("style", "background-image: url(" + baseUrl + "/images/org/" + data.data.id + ".jpg);");
269
				}
270
				$itemlist.find(".userurl").attr("data-id", data.data.id);
271
				$itemlist.find(".userurl").attr("data-iftauth", data.data.authStatus);
272
				var userType = autho(data.data.authType, data.data.orgAuth, data.data.authStatus);
273
				$itemlist.find(".authicon").attr("title", userType.title);
274
				$itemlist.find(".authicon").addClass(userType.sty);
275
			}
276
		},
277
		"error": function() {
278
			plus.nativeUI.toast("服务器链接超时", toastStyle);
279
		}
280
	});
281
}
282

283
/*标志*/
284
function autho() {
285
	if(arguments[0] == 1) {
286
		return {
287
			"sty": "authicon-pro",
288
			"title": "科袖认证专家"
289
		}
290
	} else {
291
		if(arguments[1] == 1) {
292
			return {
293
				"sty": "authicon-staff-ok",
294
				"title": "企业认证员工"
295
			}
296
		} else {
297
			if(arguments[2] == 3) {
298
				return {
299
					"sty": "authicon-real",
300
					"title": "实名认证用户"
301
				}
302
			}
303
		}
304
	}
305
}