pageHome.js
7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
layui.use('carousel', function () {
var carousel = layui.carousel;
//建造实例
carousel.render({
elem: '#banner_swiper'
, width: '100%' //设置容器宽度
, arrow: 'always' //始终显示箭头
, autoplay: true
, height: '500px'
});
});
//注意:导航 依赖 element 模块,否则无法进行功能性操作
layui.use('element', function () {
var element = layui.element;
});
layui.use('util', function () {
var util = layui.util;
//执行
util.fixbar({
bar1: true,
bar2: true,
top: true
, click: function (type) {
if (type === 'bar1') {
alert('点击了bar1')
}
}
});
});
var recentlyDay;
function getDate() {
var date = new Date();
var base = new Date(date).getTime();
var oneDay = 24 * 3600 * 1000;
var date = [];
var data = [Math.random() * 300];
var time = new Date(base);
var mon = (time.getMonth() + 1) >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
var day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
date.push([time.getFullYear(), mon, day].join('/'));
for (var i = 1; i < 7; i++) {//控制需要的天数
var now = new Date(base -= oneDay); //这里控制往前一周还是往后一周
var nowMon = (now.getMonth() + 1) >= 10 ? now.getMonth() + 1 : '0' + (now.getMonth() + 1);
var nowDay = now.getDate() >= 10 ? now.getDate() : '0' + now.getDate();
date.push([now.getFullYear(), nowMon, nowDay].join('/'));
data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
}
return date.reverse();
}
//初始化方法
$(function () {
$('.loadheader').hide();
addTabs('#index');
initData();
recentlyDay = getDate();
// NewsData();
// NoticeData();
// LawsData();
// policiesData();
});
function initData() {
$('#appointment_inquiry').click(function () {
if (isLogin()) {
window.open('./staticViews/wdyy.html', '_self')
}
})
$('#onlineBooking').click(function () {
if (isLogin()) {
window.open('./staticViews/wdyy.html', '_self')
}
})
}
//加载新闻数据
function NewsData() {
var ulNews = $("#ulNews");
ulNews.empty();
var li, publishTime;
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhNews/getNewsList",//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
if (result.data[0].preViewUrl) {
$('.news-img img').attr('src', result.data[0].preViewUrl);
} else {
$('.news-img img').attr('src', './staticImages/news_demo.jpg');
}
for (var i = 0; i < result.data.length; i++) {
if (i == 6) return;
publishTime = CutDate(result.data[i].publishTime);
if (result.data[i].preViewUrl) {
li = '<li url="' + result.data[i].preViewUrl + '"><a href="./staticViews/news/' + result.data[i].id + '.html" title="' + result.data[i].headline + '" target="_blank">';
} else {
li = '<li><a href="./staticViews/news/' + result.data[i].id + '.html" title="' + result.data[i].headline + '" target="_blank">';
}
li += '<div class="news_item">';
if (recentlyDay.indexOf(publishTime) > -1) {
li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#iconzuixin"></use> </svg>';
}
li += result.data[i].headline + '</div>';
li += '<span>' + publishTime + '</span></a></li>';
ulNews.append(li);
}
}
}
});
$(document).on("mouseover", "#ulNews li", function (e) {
if ($(this).attr('url')) {
$('.news-img img').attr('src', $(this).attr('url'));
} else {
$('.news-img img').attr('src', './staticImages/news_demo.jpg');
}
})
}
//加载公告数据
function NoticeData() {
var ulTag = $("#ulNotice");
ulTag.empty();
var li;
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhNotice/getMHNotice",//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
for (var i = 0; i < result.data.length; i++) {
if (i == 6) return;
li = '<li class="item_notice"><a href="./staticViews/notice/' + result.data[i].id + '.html" title="' + result.data[i].title + '" target="_blank">';
li += '<p>' + result.data[i].title + '</P>';
if (result.data[i].noticeType == 1) {
li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#icongongshi"></use> </svg>';
}
else {
li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#icongonggao1"></use> </svg>';
}
li += '</a></li>';
ulTag.append(li);
}
}
}
});
}
//加载法律法规数据
function LawsData() {
var ulTag = $("#ulLaws");
ulTag.empty();
var li;
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhLaws/getLawsList",//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
for (var i = 0; i < result.data.length; i++) {
if (i == 6) return;
li = '<li><a href="./staticViews/law/' + result.data[i].id + '.html" title="' + result.data[i].headline + '" target="_blank">' + result.data[i].headline;
li += '</a></li>';
ulTag.append(li);
}
}
}
});
}
//加载相应政策数据
function policiesData() {
var policies = $("#policies");
policies.empty();
var li;
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/portal/MhPolicy/getPolicyList",//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
for (var i = 0; i < result.data.length; i++) {
if (i == 6) return;
li = '<li><a href="./staticViews/policy/' + result.data[i].id + '.html" title="' + result.data[i].headline + '" target="_blank">' + result.data[i].headline;
li += '</a></li>';
policies.append(li);
}
}
}
});
}