Showing
5 changed files
with
110 additions
and
2 deletions
static/js/product/detail/comments.js
deleted
100644 → 0
static/js/product/detail/loadmore.js
0 → 100644
1 | +/** | ||
2 | + * 商品详情 --滚动页面加载 | ||
3 | + * @author: Lynnic | ||
4 | + * @date: 2015/11/25 | ||
5 | + */ | ||
6 | +var $ = require('jquery'), | ||
7 | + loading = require('../../plugin/loading'), | ||
8 | + tip = require('../../plugin/tip'); | ||
9 | + | ||
10 | +var loadMoreUrl = $('#loadMoreUrl').val(), | ||
11 | + $commentsDiv = $('#goods-comments'), | ||
12 | + $consultsDiv = $('#goods-consults'), | ||
13 | + winH = $(window).height(), | ||
14 | + searching = false, | ||
15 | + end = false; | ||
16 | + | ||
17 | +var jsonObj; | ||
18 | + | ||
19 | +//插入评论列表底部 | ||
20 | +function insertCommentsDiv(json) { | ||
21 | + var html = ''; | ||
22 | + var i; | ||
23 | + | ||
24 | + | ||
25 | + for (i = 0; i < json.length; i++) { | ||
26 | + html += '<div class="comment-item">'; | ||
27 | + html += '<span class="user-name">' + json[i].userName + '</span>'; | ||
28 | + html += '<span class="goods-spec">' + json[i].desc + '</span>'; | ||
29 | + html += '<span class="goods-spec">' + json[i].content + '</span>'; | ||
30 | + html += '<span class="goods-spec">' + json[i].time + '</span>'; | ||
31 | + } | ||
32 | + $commentsDiv.append(html); | ||
33 | +} | ||
34 | + | ||
35 | +//插入咨询列表底部 | ||
36 | +function insertConsultsDiv(json) { | ||
37 | + var html = ''; | ||
38 | + var i; | ||
39 | + | ||
40 | + | ||
41 | + for (i = 0; i < json.length; i++) { | ||
42 | + html += '<div class="consult-item"> '; | ||
43 | + html += '<div class="question"> '; | ||
44 | + html += '<span class="iconfont"></span> '; | ||
45 | + html += '<p> '; | ||
46 | + html += json[i].question + '<br> '; | ||
47 | + html += '<span class="time">' + json[i].time + '</span> '; | ||
48 | + html += '</p> '; | ||
49 | + html += '</div> '; | ||
50 | + | ||
51 | + html += '<div class="answer"> '; | ||
52 | + html += '<span class="iconfont"></span> '; | ||
53 | + html += '<p>' + json[i].answer + '</p> '; | ||
54 | + html += '</div> '; | ||
55 | + html += '</div> '; | ||
56 | + } | ||
57 | + $consultsDiv.append(html); | ||
58 | +} | ||
59 | + | ||
60 | +function search() { | ||
61 | + if (searching || end) { | ||
62 | + return; | ||
63 | + } | ||
64 | + searching = true; | ||
65 | + | ||
66 | + loading.showLoadingMask(); | ||
67 | + | ||
68 | + $.ajax({ | ||
69 | + type: 'GET', | ||
70 | + url: loadMoreUrl, | ||
71 | + success: function(data) { | ||
72 | + if (data.length > 0) { | ||
73 | + jsonObj = JSON.parse(data); | ||
74 | + if ($commentsDiv.length > 0) { | ||
75 | + insertCommentsDiv(jsonObj); | ||
76 | + } else if ($consultsDiv.length > 0) { | ||
77 | + insertConsultsDiv(jsonObj); | ||
78 | + } | ||
79 | + } | ||
80 | + searching = false; | ||
81 | + end = true; | ||
82 | + loading.hideLoadingMask(); | ||
83 | + }, | ||
84 | + error: function() { | ||
85 | + tip.show('网络断开连接了~'); | ||
86 | + searching = false; | ||
87 | + loading.hideLoadingMask(); | ||
88 | + } | ||
89 | + }); | ||
90 | +} | ||
91 | + | ||
92 | + | ||
93 | +function scrollHandler() { | ||
94 | + if (!end || $(window).scrollTop() + winH >= $(document).height() - 50) { | ||
95 | + search(); | ||
96 | + } | ||
97 | +} | ||
98 | + | ||
99 | +//srcoll to load more | ||
100 | +$(window).scroll(function() { | ||
101 | + window.requestAnimationFrame(scrollHandler); | ||
102 | +}); | ||
103 | + |
-
Please register or login to post a comment