|
@@ -5,17 +5,20 @@ $(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: "",
|
|
10
|
+ newstitle: $.getQueryVariable("newstitle") || "",
|
11
|
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
|
17
|
$.each(params.list, function (newsIndex, newsItem) {
|
17
|
18
|
newsItemHtml =
|
18
|
|
- '<div class="news_list_item"><img class="news_item_img" src="' +
|
|
19
|
+ '<div class="news_list_item" data-newsid="' +
|
|
20
|
+ newsItem.newsid +
|
|
21
|
+ '"><img class="news_item_img" src="' +
|
19
|
22
|
$.showImageUrl +
|
20
|
23
|
newsItem.newspic +
|
21
|
24
|
'" /><div class="news_item_title">' +
|
|
@@ -25,20 +28,81 @@ $(function () {
|
25
|
28
|
"</div></div>";
|
26
|
29
|
});
|
27
|
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
|
+ });
|
28
|
35
|
}
|
29
|
36
|
// 加载新闻资讯页码
|
30
|
37
|
function loadNewsPages(params) {
|
31
|
38
|
newsInfo.total = params.total || 0;
|
32
|
|
- let newsPageHtml = "";
|
33
|
|
- for (let _page = 0; _page < Math.ceil(params.total / 9); _page++) {
|
|
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++) {
|
34
|
46
|
newsPageHtml +=
|
35
|
|
- '<div class="news_page_prev"><img src="../img/home/scheme/jiantou_right.png" /></div><div class="news_page_num ' +
|
36
|
|
- (_page === 0 ? "selected" : "") +
|
|
47
|
+ '<div data-page="' +
|
|
48
|
+ (_page + 1) +
|
|
49
|
+ '" class="news_page_num ' +
|
|
50
|
+ (_page + 1 === newsInfo.page ? "selected" : "") +
|
37
|
51
|
'">' +
|
38
|
52
|
(_page + 1) +
|
39
|
|
- '</div><div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
|
|
53
|
+ "</div>";
|
40
|
54
|
}
|
|
55
|
+ newsPageHtml +=
|
|
56
|
+ '<div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
|
41
|
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
|
+ }
|
|
105
|
+ });
|
42
|
106
|
}
|
43
|
107
|
// 搜索新闻列表
|
44
|
108
|
function searchList() {
|
|
@@ -55,8 +119,13 @@ $(function () {
|
55
|
119
|
}),
|
56
|
120
|
success: function (data) {
|
57
|
121
|
if (data.code === 0) {
|
58
|
|
- loadNewsList(data.obj);
|
59
|
|
- loadNewsPages(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
|
+ }
|
60
|
129
|
} else {
|
61
|
130
|
alert(data.msg);
|
62
|
131
|
}
|
|
@@ -71,7 +140,8 @@ $(function () {
|
71
|
140
|
let content = theEvent.target.value;
|
72
|
141
|
newsInfo.newstitle = content;
|
73
|
142
|
if (code == 13) {
|
74
|
|
- searchList();
|
|
143
|
+ // searchList();
|
|
144
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
75
|
145
|
}
|
76
|
146
|
}
|
77
|
147
|
// 输入内容改变
|
|
@@ -81,6 +151,9 @@ $(function () {
|
81
|
151
|
}
|
82
|
152
|
$(".news_info #search_help").on("change", searchInputChange);
|
83
|
153
|
$(".news_info #search_help").on("keydown", enterSearch);
|
84
|
|
- $(".news_info .search_box").click(searchList);
|
|
154
|
+ $(".news_info .search_box").click(function () {
|
|
155
|
+ // searchList();
|
|
156
|
+ window.location.href = "/sections/news.html?page=" + newsInfo.page + "&newstitle=" + newsInfo.newstitle;
|
|
157
|
+ });
|
85
|
158
|
searchList();
|
86
|
159
|
});
|