index.js 18.8 KB
Newer Older
1 2 3
define(
	[ 'zepto', 'medtap' /* ,'https://review-formal.iplusmed.com/Common/javaScript/beforeSubmitForLung.js?v=2.0' */ ],
	function($, medtap /* ,beforeSubmit */) {
hanpeng committed
4 5
		var index = {
			wechatId: medtap.getRequest('wechatId'),
6
			groupId: 0,
hanpeng committed
7
			limit: 10,
8
			offset: 1,
hanpeng committed
9
			hasMore: false,
10
			firstLoad: false,
hanpeng committed
11 12 13 14
			init: function() {
				index.getUserToken();
			},
			bindEve: function() {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
				// 浮动菜单切换
				$('.more').on('click', function() {
					$(this).hide();
					$('.my-text').show();
					$('.release').show();
					$('.close').show();
				});
				$('.close').on('click', function() {
					$(this).hide();
					$('.my-text').hide();
					$('.release').hide();
					$('.more').show();
				});
				// 浮动菜单点击跳转
				// 点击我的图标跳转到我的页面
				$('.my-text').on('click', function() {
					medtap.pushWindow('pages/myCardList.html');
				});
				// 点击发布图标跳转到发布页面
				$('.release').on('click', function() {
					medtap.pushWindow("pages/newCard.html?groupId="+ index.groupId +"")
				});
hanpeng committed
37 38 39 40 41 42 43 44 45
				$('.user_nickName').on('click', function() {
					medtap.pushWindow('pages/myCardList.html');
				});

				//取消
				$('.change_name_warp').on('click', '.change_btn_cancle', function() {
					$('.content_mod').hide();
					$('.change_name_warp').hide();
					$('.new_nick').val('');
46
				});
hanpeng committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

				//确定
				$('.change_name_warp').on('click', '.change_btn_confirm', function() {
					var newNick = $('.new_nick').val();
					index.upDateUserInfo(newNick);
				});

				//tab分类查询帖子列表
				$('.silder_tap_item').on('click', function() {
					$(this).addClass('on');
					$(this).siblings().removeClass('on');
					var type = '';
					var id = $(this).attr('id');
					if (id == 'recommend') {
						$('.list_warp').html('');
						index.firstLoad = false;
						index.offset = 1;
						type = 1;
					} else if (id == 'newest') {
						$('.list_warp').html('');
						index.firstLoad = false;
						index.offset = 1;
						type = '';
					}
71
					index.getForumList(type);
hanpeng committed
72
				});
73

hanpeng committed
74
				//add
hanpeng committed
75 76 77 78 79 80

				//滚动加载
				$(window).scroll(function() {
					var scrollTop = $(this).scrollTop(); //滚动条距离顶部的高度
					var scrollHeight = $(document).height(); //当前页面的总高度
					var clientHeight = $(this).height(); //当前可视的页面高度
81 82
					if (scrollTop + clientHeight >= scrollHeight) {
						//距离顶部+当前高度 >=文档总高度 即代表滑动到底部
hanpeng committed
83 84
						//滚动条到达底部
						if (index.hasMore == true) {
85
							var type = '';
hanpeng committed
86 87 88 89 90 91 92 93 94
							if ($('#recommend').hasClass('on')) {
								index.firstLoad = true;
								index.offset += 1;
								type = 1;
							} else if ($('#newest').hasClass('on')) {
								index.firstLoad = true;
								index.offset += 1;
								type = '';
							}
95
							index.getForumList(type);
hanpeng committed
96 97 98 99
						} else {
						}
					} else if (scrollTop <= 0) {
						//滚动条到达顶部
100
						return;
hanpeng committed
101 102 103 104 105 106 107 108
					}
				});
			},
			//换取微信token
			getUserToken: function() {
				localStorage.wxLungToken = '';
				medtap.loading(1);
				medtap.submitAjax({
109
					url: 'https://gateway.medtap.cn/user/auth/token',
hanpeng committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
					type: 'POST',
					async: false,
					contentType: 'application/json',
					data: {
						wechatId: index.wechatId
					},
					success: function(res) {
						medtap.loading(0);
						if (res.success == true) {
							var token = res.content.token;
							localStorage.setItem('wxLungToken', token);
							index.getForumInfo();
							index.getUserInfo();
						} else {
						}
					},
					error: function(res) {
						console.log(res.resultDesc);
					}
129
				});
hanpeng committed
130 131 132 133 134
			},
			//获取用户信息
			getUserInfo: function() {
				medtap.loading(1);
				medtap.submitAjax({
135
					url: 'https://gateway.medtap.cn/user/getUserDetail',
hanpeng committed
136 137
					type: 'GET',
					async: false,
138
					data: {},
hanpeng committed
139 140 141
					success: function(res) {
						medtap.loading(0);
						var userInfo = res.content.userInfo;
142 143
						$('.user_nickName').html(userInfo.nickname);
						$('.change_name_nickname').html(userInfo.nickname);
hanpeng committed
144
					}
145
				});
hanpeng committed
146 147 148 149 150
			},
			//更新用户信息
			upDateUserInfo: function(name) {
				medtap.loading(1);
				medtap.submitAjax({
151
					url: 'https://gateway.medtap.cn/user/saveUserInfo',
hanpeng committed
152 153 154 155 156 157 158 159 160 161 162 163
					type: 'POST',
					async: false,
					contentType: 'application/json',
					data: {
						nickname: name
					},
					success: function(res) {
						medtap.loading(0);
						setTimeout(function() {
							medtap.toast({
								message: '修改成功',
								time: 2000
164
							});
hanpeng committed
165 166 167 168
							index.getUserInfo();
							$('.content_mod').hide();
							$('.change_name_warp').hide();
							$('.new_nick').val('');
169
						}, 1000);
hanpeng committed
170
					}
171
				});
hanpeng committed
172 173 174 175 176
			},
			//获取论坛信息
			getForumInfo: function() {
				medtap.loading(1);
				medtap.submitAjax({
177
					url: 'https://gateway.medtap.cn/operation/pubbbs/getGruop',
hanpeng committed
178
					type: 'POST',
hanpeng committed
179
					async: false,
hanpeng committed
180
					contentType: 'application/json',
hanpeng committed
181
					data: {
182
						codeVal: 'LUNG'
hanpeng committed
183 184 185 186 187
					},
					success: function(res) {
						medtap.loading(0);
						if (res.success == true) {
							var forumInfo = res.content.publishGroup;
hanpeng committed
188
							index.groupId = forumInfo.id;
hanpeng committed
189 190 191 192
							$('.bbs_title').html(forumInfo.name); //社区名
							$('.bbs_profile_img').attr('src', forumInfo.icon); //社区icon
							$('.bbs_attentionNum').html(forumInfo.userCount); //社区关注人数
							$('.bbs_cardNum').html(forumInfo.publishCount); //社区帖子数量
hanpeng committed
193
							index.getForumList(1);
194 195 196
							$('.add').unbind().bind('click', function() {
								medtap.pushWindow('pages/newCard.html?groupId=' + index.groupId);
							});
hanpeng committed
197
							index.joinPublish();
hanpeng committed
198 199
						}
					}
200
				});
hanpeng committed
201 202 203 204 205
			},
			//根据分类获取论坛信息
			getForumList: function(listType) {
				medtap.loading(1);
				medtap.submitAjax({
206
					url: 'https://gateway.medtap.cn/operation/pubbbs/publish',
hanpeng committed
207 208 209 210 211 212
					type: 'GET',
					async: false,
					data: {
						offset: index.offset,
						limit: index.limit,
						good: listType,
213
						groupId: index.groupId
hanpeng committed
214 215 216 217 218 219 220 221 222 223 224
					},
					success: function(res) {
						medtap.loading(0);
						if (res.success == true) {
							var forumList = res.content.list;
							if (forumList.length == 0) {
								index.hasMore = false;
								setTimeout(function() {
									medtap.toast({
										message: '没有更多了',
										time: 2000
225 226
									});
								}, 1000);
hanpeng committed
227 228 229 230
							} else {
								index.hasMore = true;
								//dealData
								var str = '';
231
								for (var i = 0; i < forumList.length; i++) {
hanpeng committed
232
									//当前帖子用户未点赞
233
									if (forumList[i].upStatus == 0) {
hanpeng committed
234 235
										var picUrl = forumList[i].picUrls || '';
										//单张图片
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
										if (picUrl.length != 0 && picUrl.length < 2) {
											str +=
												'<div class="list_item" data-id="' +
												forumList[i].id +
												'">' +
												'<div class="list_item_header clearfix">' +
												'<img src="' +
												forumList[i].profile +
												'" class="user_profile">' +
												'<div class="user_info">' +
												'<p class="user_name">' +
												forumList[i].nickname +
												'</p>' +
												'<p class="txt_gray post_card_time">' +
												forumList[i].updateTime.substring(5, 16) +
												'</p>' +
												'</div>' +
												'</div>' +
												'<div class="list_item_content">' +
												'<div class="list_item_content_desc">' +
												forumList[i].content +
												'</div>' +
												'<div class="list_item_content_img">' +
												'<img src="' +
												picUrl +
												'">' +
												'</div>' +
												'</div>' +
												'<div class="list_item_tools clearfix">' +
												'<div class="tools clearfix seen">' +
												'<img src="images/post_seen_png@2x.png">' +
												'<span class="seenNum">' +
												forumList[i].viewCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix reply">' +
												'<img src="images/post_reply_png@2x.png">' +
												'<span class="replyNum">' +
												forumList[i].commentCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix like">' +
												'<img src="images/post_unlike_png@2x.png">' +
												'<span class="likeNum">' +
												forumList[i].upCount +
												'</span>' +
												'</div>' +
												'</div>' +
												'</div>';
										} else if (picUrl.length > 1) {
hanpeng committed
286 287
											//多张图片
											var imgStr = '';
288 289
											for (var j = 0; j < picUrl.length; j++) {
												imgStr += '<img src="' + picUrl[j] + '">';
hanpeng committed
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
											str +=
												'<div class="list_item" data-id="' +
												forumList[i].id +
												'">' +
												'<div class="list_item_header clearfix">' +
												'<img src="' +
												forumList[i].profile +
												'" class="user_profile">' +
												'<div class="user_info">' +
												'<p class="user_name">' +
												forumList[i].nickname +
												'</p>' +
												'<p class="txt_gray post_card_time">' +
												forumList[i].updateTime.substring(5, 16) +
												'</p>' +
												'</div>' +
												'</div>' +
												'<div class="list_item_content">' +
												'<div class="list_item_content_desc">' +
												forumList[i].content +
												'</div>' +
												'<div class="list_item_content_imgMore clearfix">' +
												imgStr +
												'</div>' +
												'<div class="list_item_tools clearfix">' +
												'<div class="tools clearfix seen">' +
												'<img src="images/post_seen_png@2x.png">' +
												'<span class="seenNum">' +
												forumList[i].viewCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix reply">' +
												'<img src="images/post_reply_png@2x.png">' +
												'<span class="replyNum">' +
												forumList[i].commentCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix like">' +
												'<img src="images/post_unlike_png@2x.png">' +
												'<span class="likeNum">' +
												forumList[i].upCount +
												'</span>' +
												'</div>' +
												'</div>' +
												'</div>' +
												'</div>';
										} else {
											str +=
												'<div class="list_item" data-id="' +
												forumList[i].id +
												'">' +
												'<div class="list_item_header clearfix">' +
												'<img src="' +
												forumList[i].profile +
												'" class="user_profile">' +
												'<div class="user_info">' +
												'<p class="user_name">' +
												forumList[i].nickname +
												'</p>' +
												'<p class="txt_gray post_card_time">' +
												forumList[i].updateTime.substring(5, 16) +
												'</p>' +
												'</div>' +
												'</div>' +
												'<div class="list_item_content">' +
												'<div class="list_item_content_desc">' +
												forumList[i].content +
												'</div>' +
												'</div>' +
												'<div class="list_item_tools clearfix">' +
												'<div class="tools clearfix seen">' +
												'<img src="images/post_seen_png@2x.png">' +
												'<span class="seenNum">' +
												forumList[i].viewCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix reply">' +
												'<img src="images/post_reply_png@2x.png">' +
												'<span class="replyNum">' +
												forumList[i].commentCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix like">' +
												'<img src="images/post_unlike_png@2x.png">' +
												'<span class="likeNum">' +
												forumList[i].upCount +
												'</span>' +
												'</div>' +
												'</div>' +
												'</div>';
hanpeng committed
381
										}
382
									} else if (forumList[i].upStatus == 1) {
hanpeng committed
383 384
										var picUrl = forumList[i].picUrls || '';
										//单张图片
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
										if (picUrl.length != 0 && picUrl.length < 2) {
											str +=
												'<div class="list_item" data-id="' +
												forumList[i].id +
												'">' +
												'<div class="list_item_header clearfix">' +
												'<img src="' +
												forumList[i].profile +
												'" class="user_profile">' +
												'<div class="user_info">' +
												'<p class="user_name">' +
												forumList[i].nickname +
												'</p>' +
												'<p class="txt_gray post_card_time">' +
												forumList[i].updateTime.substring(5, 16) +
												'</p>' +
												'</div>' +
												'</div>' +
												'<div class="list_item_content">' +
												'<div class="list_item_content_desc">' +
												forumList[i].content +
												'</div>' +
												'<div class="list_item_content_img">' +
												'<img src="' +
												picUrl +
												'">' +
												'</div>' +
												'</div>' +
												'<div class="list_item_tools clearfix">' +
												'<div class="tools clearfix seen">' +
												'<img src="images/post_seen_png@2x.png">' +
												'<span class="seenNum">' +
												forumList[i].viewCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix reply">' +
												'<img src="images/post_reply_png@2x.png">' +
												'<span class="replyNum">' +
												forumList[i].commentCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix like">' +
												'<img src="images/post_like_png@2x.png">' +
												'<span class="likeNum">' +
												forumList[i].upCount +
												'</span>' +
												'</div>' +
												'</div>' +
												'</div>';
										} else if (picUrl.length > 1) {
hanpeng committed
435 436
											//多张图片
											var imgStr = '';
437 438
											for (var j = 0; j < picUrl.length; j++) {
												imgStr += '<img src="' + picUrl[j] + '">';
hanpeng committed
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
											str +=
												'<div class="list_item" data-id="' +
												forumList[i].id +
												'">' +
												'<div class="list_item_header clearfix">' +
												'<img src="' +
												forumList[i].profile +
												'" class="user_profile">' +
												'<div class="user_info">' +
												'<p class="user_name">' +
												forumList[i].nickname +
												'</p>' +
												'<p class="txt_gray post_card_time">' +
												forumList[i].updateTime.substring(5, 16) +
												'</p>' +
												'</div>' +
												'</div>' +
												'<div class="list_item_content">' +
												'<div class="list_item_content_desc">' +
												forumList[i].content +
												'</div>' +
												'<div class="list_item_content_imgMore clearfix">' +
												imgStr +
												'</div>' +
												'<div class="list_item_tools clearfix">' +
												'<div class="tools clearfix seen">' +
												'<img src="images/post_seen_png@2x.png">' +
												'<span class="seenNum">' +
												forumList[i].viewCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix reply">' +
												'<img src="images/post_reply_png@2x.png">' +
												'<span class="replyNum">' +
												forumList[i].commentCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix like">' +
												'<img src="images/post_like_png@2x.png">' +
												'<span class="likeNum">' +
												forumList[i].upCount +
												'</span>' +
												'</div>' +
												'</div>' +
												'</div>' +
												'</div>';
										} else {
											str +=
												'<div class="list_item" data-id="' +
												forumList[i].id +
												'">' +
												'<div class="list_item_header clearfix">' +
												'<img src="' +
												forumList[i].profile +
												'" class="user_profile">' +
												'<div class="user_info">' +
												'<p class="user_name">' +
												forumList[i].nickname +
												'</p>' +
												'<p class="txt_gray post_card_time">' +
												forumList[i].updateTime.substring(5, 16) +
												'</p>' +
												'</div>' +
												'</div>' +
												'<div class="list_item_content">' +
												'<div class="list_item_content_desc">' +
												forumList[i].content +
												'</div>' +
												'</div>' +
												'<div class="list_item_tools clearfix">' +
												'<div class="tools clearfix seen">' +
												'<img src="images/post_seen_png@2x.png">' +
												'<span class="seenNum">' +
												forumList[i].viewCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix reply">' +
												'<img src="images/post_reply_png@2x.png">' +
												'<span class="replyNum">' +
												forumList[i].commentCount +
												'</span>' +
												'</div>' +
												'<div class="tools clearfix like">' +
												'<img src="images/post_like_png@2x.png">' +
												'<span class="likeNum">' +
												forumList[i].upCount +
												'</span>' +
												'</div>' +
												'</div>' +
												'</div>';
										}
hanpeng committed
531 532
									}
								}
533
								if (index.offset > 1) {
hanpeng committed
534
									$('.list_warp').append(str);
535
								} else {
hanpeng committed
536 537
									$('.list_warp').html(str);
								}
538 539
								$('.like').on('click', function(event) {
									event.stopPropagation();
hanpeng committed
540 541 542
									var id = $(this).parents('.list_item').attr('data-id');
									var num = $(this).children('.likeNum').html();
									var status = index.publishUp(id);
543
									if (status == 0) {
hanpeng committed
544
										var newNum = parseInt(num) - 1;
545
										$(this).children('img').attr('src', 'images/post_unlike_png@2x.png');
hanpeng committed
546
										$(this).children('.likeNum').html(newNum);
547
									} else if (status == 1) {
hanpeng committed
548
										var newNum = parseInt(num) + 1;
549
										$(this).children('img').attr('src', 'images/post_like_png@2x.png');
hanpeng committed
550 551
										$(this).children('.likeNum').html(newNum);
									}
552 553 554
								});

								$('.list_item').on('click', function() {
hanpeng committed
555
									var id = $(this).attr('data-id');
556 557 558 559
									medtap.pushWindow(
										'pages/cardDetail.html?cardId=' + id + '&wechatId=' + index.wechatId
									);
								});
hanpeng committed
560 561 562
							}
						}
					}
563
				});
hanpeng committed
564 565
			},
			//点赞
566
			publishUp: function(publishId) {
hanpeng committed
567 568 569
				var status;
				medtap.loading(1);
				medtap.submitAjax({
570
					url: 'https://gateway.medtap.cn/operation/pubbbs/publish/up',
571
					type: 'POST',
hanpeng committed
572 573 574 575 576
					async: false,
					contentType: 'application/json',
					data: {
						publishId: publishId
					},
577
					success: function(res) {
hanpeng committed
578
						medtap.loading(0);
579
						if (res.success == true) {
hanpeng committed
580 581 582
							status = res.content.upStatus;
						}
					}
583
				});
hanpeng committed
584 585 586
				return status;
			},
			//加入社区(便于后台统计人数)
587
			joinPublish: function() {
hanpeng committed
588 589
				medtap.loading(1);
				medtap.submitAjax({
590
					url: 'https://gateway.medtap.cn/operation/pubbbs/groupUser',
591
					type: 'POST',
hanpeng committed
592 593
					async: false,
					contentType: 'application/json',
594 595
					data: {
						groupId: index.groupId
hanpeng committed
596
					},
597
					success: function(res) {
hanpeng committed
598 599
						medtap.loading(0);
					}
600
				});
hanpeng committed
601
			}
602
		};
hanpeng committed
603 604
		index.init();
		index.bindEve();
605 606
	}
);