|
@@ -5,39 +5,131 @@ $(function () {
|
5
|
5
|
$(".header_root").data("nav_info", 5);
|
6
|
6
|
// 新闻资讯搜索信息
|
7
|
7
|
let newsInfo = {
|
8
|
|
- page: 1,
|
|
8
|
+ page: Number($.getQueryVariable("page") || 1),
|
9
|
9
|
size: 9,
|
10
|
|
- newstitle: "",
|
11
|
|
- total: 0
|
|
10
|
+ newstitle: $.getQueryVariable("newstitle") || "",
|
|
11
|
+ total: 0,
|
12
|
12
|
};
|
|
13
|
+ $(".news_info #search_help").val(newsInfo.newstitle);
|
13
|
14
|
// 加载新闻资讯列表
|
14
|
15
|
function loadNewsList(params) {
|
15
|
16
|
let newsItemHtml = "";
|
16
|
|
- $.each(params.list, function(newsIndex, newsItem) {
|
17
|
|
- newsItemHtml = '<div class="news_list_item"><img class="news_item_img" src="' + $.showImageUrl + newsItem.newspic + '" /><div class="news_item_title">' + newsItem.newstitle + '</div><div class="news_item_stitle">' + $.msToDateString(newsItem.createtime) + '</div></div>';
|
|
17
|
+ $.each(params.list, function (newsIndex, newsItem) {
|
|
18
|
+ newsItemHtml =
|
|
19
|
+ '<div class="news_list_item" data-newsid="' +
|
|
20
|
+ newsItem.newsid +
|
|
21
|
+ '"><img class="news_item_img" src="' +
|
|
22
|
+ $.showImageUrl +
|
|
23
|
+ newsItem.newspic +
|
|
24
|
+ '" /><div class="news_item_title">' +
|
|
25
|
+ newsItem.newstitle +
|
|
26
|
+ '</div><div class="news_item_stitle">' +
|
|
27
|
+ $.msToDateString(newsItem.createtime * 1000) +
|
|
28
|
+ "</div></div>";
|
|
29
|
+ });
|
|
30
|
+ $(".news_list_box").html(newsItemHtml);
|
|
31
|
+ $(".news_list_box").on("click", ".news_list_item", function () {
|
|
32
|
+ window.location.href =
|
|
33
|
+ "/sections/news_detail.html?newsid=" + $(this).data("newsid");
|
|
34
|
+ });
|
|
35
|
+ }
|
|
36
|
+ // 加载新闻资讯页码
|
|
37
|
+ function loadNewsPages(params) {
|
|
38
|
+ newsInfo.total = params.total || 0;
|
|
39
|
+ if (newsInfo.total === 0) {
|
|
40
|
+ $(".news_page_box").html("");
|
|
41
|
+ return;
|
|
42
|
+ }
|
|
43
|
+ let newsPageHtml =
|
|
44
|
+ '<div class="news_page_prev"><img src="../img/home/scheme/jiantou_right.png" /></div>';
|
|
45
|
+ for (let _page = 0; _page < Math.ceil(newsInfo.total / 9); _page++) {
|
|
46
|
+ newsPageHtml +=
|
|
47
|
+ '<div data-page="' +
|
|
48
|
+ (_page + 1) +
|
|
49
|
+ '" class="news_page_num ' +
|
|
50
|
+ (_page + 1 === newsInfo.page ? "selected" : "") +
|
|
51
|
+ '">' +
|
|
52
|
+ (_page + 1) +
|
|
53
|
+ "</div>";
|
|
54
|
+ }
|
|
55
|
+ newsPageHtml +=
|
|
56
|
+ '<div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
|
|
57
|
+ $(".news_page_box").html(newsPageHtml);
|
|
58
|
+ // 上下页禁止点击
|
|
59
|
+ function setNotAllowed() {
|
|
60
|
+ if (newsInfo.page === 1) {
|
|
61
|
+ $(".news_page_box .news_page_prev").addClass("disabled");
|
|
62
|
+ } else {
|
|
63
|
+ $(".news_page_box .news_page_prev.disabled").removeClass("disabled");
|
|
64
|
+ }
|
|
65
|
+ if (newsInfo.page === Math.ceil(newsInfo.total / 9)) {
|
|
66
|
+ $(".news_page_box .news_page_next").addClass("disabled");
|
|
67
|
+ } else {
|
|
68
|
+ $(".news_page_box .news_page_next.disabled").removeClass("disabled");
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+ setNotAllowed();
|
|
72
|
+ $(".news_page_box").on("click", ".news_page_prev", function () {
|
|
73
|
+ if (newsInfo.page > 1) {
|
|
74
|
+ newsInfo.page--;
|
|
75
|
+ $(".news_page_box .news_page_num.selected").removeClass("selected");
|
|
76
|
+ $(
|
|
77
|
+ ".news_page_box .news_page_num[data-page='" + newsInfo.page + "']"
|
|
78
|
+ ).addClass("selected");
|
|
79
|
+ setNotAllowed();
|
|
80
|
+ // searchList();
|
|
81
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
|
82
|
+ }
|
|
83
|
+ });
|
|
84
|
+ $(".news_page_box").on("click", ".news_page_num", function () {
|
|
85
|
+ newsInfo.page = $(this).data("page");
|
|
86
|
+ $(".news_page_box .news_page_num.selected").removeClass("selected");
|
|
87
|
+ $(
|
|
88
|
+ ".news_page_box .news_page_num[data-page='" + newsInfo.page + "']"
|
|
89
|
+ ).addClass("selected");
|
|
90
|
+ setNotAllowed();
|
|
91
|
+ // searchList();
|
|
92
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
|
93
|
+ });
|
|
94
|
+ $(".news_page_box").on("click", ".news_page_next", function () {
|
|
95
|
+ if (newsInfo.page < Math.ceil(newsInfo.total / 9)) {
|
|
96
|
+ newsInfo.page++;
|
|
97
|
+ $(".news_page_box .news_page_num.selected").removeClass("selected");
|
|
98
|
+ $(
|
|
99
|
+ ".news_page_box .news_page_num[data-page='" + newsInfo.page + "']"
|
|
100
|
+ ).addClass("selected");
|
|
101
|
+ setNotAllowed();
|
|
102
|
+ // searchList();
|
|
103
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
|
104
|
+ }
|
18
|
105
|
});
|
19
|
|
- $(".news_list_box").html(newsItem);
|
20
|
106
|
}
|
21
|
107
|
// 搜索新闻列表
|
22
|
108
|
function searchList() {
|
23
|
109
|
let _url = $.baseUrl + "n/listc";
|
24
|
110
|
$.ajax({
|
25
|
|
- type: 'POST',
|
|
111
|
+ type: "POST",
|
26
|
112
|
url: _url,
|
27
|
113
|
dataType: "json",
|
28
|
114
|
contentType: "application/json; charset=utf-8",
|
29
|
115
|
data: JSON.stringify({
|
30
|
116
|
page: newsInfo.page,
|
31
|
117
|
size: newsInfo.size,
|
32
|
|
- newstitle: newsInfo.newstitle
|
|
118
|
+ newstitle: newsInfo.newstitle,
|
33
|
119
|
}),
|
34
|
120
|
success: function (data) {
|
35
|
121
|
if (data.code === 0) {
|
36
|
|
- loadNewsList(data.obj);
|
|
122
|
+ if (data.obj.list.length === 0 && newsInfo.page > 1) {
|
|
123
|
+ newsInfo.page--;
|
|
124
|
+ searchList();
|
|
125
|
+ } else {
|
|
126
|
+ loadNewsList(data.obj);
|
|
127
|
+ loadNewsPages(data.obj);
|
|
128
|
+ }
|
37
|
129
|
} else {
|
38
|
130
|
alert(data.msg);
|
39
|
131
|
}
|
40
|
|
- }
|
|
132
|
+ },
|
41
|
133
|
});
|
42
|
134
|
}
|
43
|
135
|
// 回车搜索
|
|
@@ -46,17 +138,22 @@ $(function () {
|
46
|
138
|
let theEvent = event || window.event;
|
47
|
139
|
let code = theEvent.keyCode || theEvent.which || theEvent.charCode;
|
48
|
140
|
let content = theEvent.target.value;
|
49
|
|
- search_helpcomm = content;
|
|
141
|
+ newsInfo.newstitle = content;
|
50
|
142
|
if (code == 13) {
|
51
|
|
- searchList();
|
|
143
|
+ // searchList();
|
|
144
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
52
|
145
|
}
|
53
|
146
|
}
|
54
|
147
|
// 输入内容改变
|
55
|
148
|
function searchInputChange(event) {
|
56
|
149
|
let theEvent = event || window.event;
|
57
|
|
- search_helpcomm = theEvent.target.value;
|
|
150
|
+ newsInfo.newstitle = theEvent.target.value;
|
58
|
151
|
}
|
59
|
152
|
$(".news_info #search_help").on("change", searchInputChange);
|
60
|
153
|
$(".news_info #search_help").on("keydown", enterSearch);
|
61
|
|
- $(".news_info .search_box").click(searchList);
|
62
|
|
-});
|
|
154
|
+ $(".news_info .search_box").click(function () {
|
|
155
|
+ // searchList();
|
|
156
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
|
157
|
+ });
|
|
158
|
+ searchList();
|
|
159
|
+});
|