pageHome.js
8.39 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//注意:导航 依赖 element 模块,否则无法进行功能性操作
layui.use('element', function () {
var element = layui.element;
});
layui.use('util', function () {
var util = layui.util;
//执行
util.fixbar({
top: true
});
});
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();
// NoticeData();
// LawsData();
// policiesData();
});
function initData() {
// 获取当前页面的url
setItem('indexUrl',window.location.pathname)
// 新闻模块
if ($('.hotspot-list li').eq(0).attr('url')) {
$('.news-img').attr('src', $('.hotspot-list li').eq(0).attr('url'));
} else {
$('.news-img').attr('src', '/staticImages/default-news.png');
}
$(document).on("mouseover", ".news-module-box .item-list li", function (e) {
if ($(this).attr('url')) {
$('.news-img').attr('src', $(this).attr('url'));
} else {
$('.news-img').attr('src', '/staticImages/default-news.png');
}
})
// 在这里处理置顶的头部
let topTitle = $('.top-title').html();
if (strLength(topTitle) > 7) {
let html = topTitle.slice(0, 7) + '<br/>' + topTitle.slice(7);
$('.top-title').html(html)
}
$('#appointment_inquiry').click(function () {
if (isLogin()) {
window.open('./staticViews/wdyy.html', '_self')
}
})
$('#onlineBooking').click(function () {
if (isLogin()) {
window.open('./staticViews/wdyy.html', '_self')
}
})
// 新闻头部切换
$('.news-title .item-title').click(function () {
$('.news-title .item-title').removeClass('news-active');
$(this).addClass('news-active');
let indexId = $(this).attr('data-id');
$('.item-list').hide();
if (indexId == '1') {
$('.hotspot-list').show();
$('.policies-regulations-href').attr('href','/staticViews/lawList/1.html');
} else {
$('.news-information-list').show();
$('.policies-regulations-href').attr('href','/staticViews/policyList/1.html');
}
})
// 便民服务
$(".convenient-service-list li").mouseover(function () {
$(this).find('img').attr('src', $(this).find('img').attr('url'));
})
$(".convenient-service-list li").mouseout(function () {
$(this).find('img').attr('src', $(this).find('img').attr('pre'));
})
if (getItem('myCookie') && getItem('myCookie').username) {
$('.login-list a').hide();
$('.login-list-subtitle').show();
}
// 业务列表进行跳转
$('.business-list-rightItem .business-search li').click(function () {
let urlId = $(this).attr('url-id');
if(urlId == 'appointment') {
if (isLogin()) {
window.open(getSearchUrl(urlId), '_self')
}
}else {
window.open(getSearchUrl(urlId), '_self')
}
})
// 政策法规
$('.policies-regulations-title .item-title').click(function () {
let index = $(this).attr('data-id');
$('.policies-regulations-title .item-title').removeClass('regulations-active');
$(this).addClass('regulations-active');
$('.item-policies').hide();
if (index =='2') {
$('.corresponding-policies').show();
}else {
$('.laws-regulations').show();
}
})
}
function getSearchUrl(level) {
const resultMap = {
archives: '/staticViews/convenienceService/fileQuery.html',
progress: '/staticViews/convenienceService/progressInquiry.html',
appointment : '/staticViews/yyxz.html',
certificate: '/staticViews/convenienceService/certificateVerification.html',
business: '/staticViews/convenienceService/businessInquiry.html',
guide: '/staticViews/bszn.html',
pay: '/staticViews/zxjf.html',
default: 'gologin',
}
return resultMap[level] || resultMap.default;
}
// 获取汉字长度
function strLength(str) {
///<summary>获得字符串实际长度,中文2,英文1</summary>
///<param name="str">要获得长度的字符串</param>
var realLength = 0, len = str.length, charCode = -1;
for (var i = 0; i < len; i++) {
charCode = str.charCodeAt(i);
if (charCode >= 0 && charCode <= 128)
realLength += 1;
else
realLength += 2;
}
return realLength;
};
//加载公告数据
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);
}
}
}
});
}