1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- $(function () {
- $(".header_root").load("./comm/header.html");
- $(".footer_root").load("./comm/footer.html");
- // nav传值显示下划线
- $(".header_root").data("nav_info", 5);
- // 新闻资讯搜索信息
- let newsInfo = {
- page: 1,
- size: 9,
- newstitle: "",
- total: 0,
- };
- // 加载新闻资讯列表
- function loadNewsList(params) {
- let newsItemHtml = "";
- $.each(params.list, function (newsIndex, newsItem) {
- 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 * 1000) +
- "</div></div>";
- });
- $(".news_list_box").html(newsItemHtml);
- }
- // 加载新闻资讯页码
- function loadNewsPages(params) {
- newsInfo.total = params.total || 0;
- let newsPageHtml = "";
- for (let _page = 0; _page < Math.ceil(params.total / 9); _page++) {
- newsPageHtml +=
- '<div class="news_page_prev"><img src="../img/home/scheme/jiantou_right.png" /></div><div class="news_page_num ' +
- (_page === 0 ? "selected" : "") +
- '">' +
- (_page + 1) +
- '</div><div class="news_page_next"><img src="../img/home/scheme/jiantou_right.png" /></div>';
- }
- $(".news_page_box").html(newsPageHtml);
- }
- // 搜索新闻列表
- function searchList() {
- let _url = $.baseUrl + "n/listc";
- $.ajax({
- type: "POST",
- url: _url,
- dataType: "json",
- contentType: "application/json; charset=utf-8",
- data: JSON.stringify({
- page: newsInfo.page,
- size: newsInfo.size,
- newstitle: newsInfo.newstitle,
- }),
- success: function (data) {
- if (data.code === 0) {
- loadNewsList(data.obj);
- loadNewsPages(data.obj);
- } else {
- alert(data.msg);
- }
- },
- });
- }
- // 回车搜索
- function enterSearch(event) {
- // 兼容FF和IE和Opera
- let theEvent = event || window.event;
- let code = theEvent.keyCode || theEvent.which || theEvent.charCode;
- let content = theEvent.target.value;
- newsInfo.newstitle = content;
- if (code == 13) {
- searchList();
- }
- }
- // 输入内容改变
- function searchInputChange(event) {
- let theEvent = event || window.event;
- newsInfo.newstitle = theEvent.target.value;
- }
- $(".news_info #search_help").on("change", searchInputChange);
- $(".news_info #search_help").on("keydown", enterSearch);
- $(".news_info .search_box").click(searchList);
- searchList();
- });
|