anxiao_web/pages/schoolStyle/js/orgApi/schoolNewsGetlist.js

209 lines
6.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { stationurl,brigade } from "../../../../public/js/url.js";
import {stationInfoTableList,layuiObj } from "../index.js";
import { getCurrData } from "../../../../public/js/timestamp.js";
let currentStation="";//五一中路小学
let schoolNewslist=[];
async function selectSchoolNewsGetlist() {
schoolNewslist=[];
var schoolNewsReq=await getSchoolNewsGetlist();
schoolNewslist=schoolNewsReq.data.data;
schoolNewslist.reverse();
showSchoolNewslist(schoolNewslist);
showBasicSchoolInfo();
//初始化时间
$("#schoolstyle_time").val(getCurrData());
layuiObj.laydate.render({
elem: '#schoolstyle_time',
done:function(value, date){
updateSchoolStyleTimeInfo(value);
}
});
}
function getSchoolNewsGetlist(){
var data={
"brigade":brigade,
"station":currentStation
}
var loginurl=stationurl+"/firectrl/school/news/getlist";
return axios({
method: 'post',
url:loginurl,
data: data
})
}
function showSchoolNewslist(newslist){
var div="";
newslist.forEach(item=>{
if(item["imageUrls"].length>0){
var imgUrl=JSON.parse(item["imageUrls"]);
var url=stationurl+imgUrl[0];
}else{
var url="";
}
div+=`<div class="campusStyle-list">
<img src="${url}">
<ul>
<li>
<span>${item["station"]}</span>
</li>
<li>
<a>${item["title"]}</a><span>【${item["timestamp"]}】</span>
</li>
<li newsId='${item["newsId"]}'>
<span>${item["comment"]}</span>
<a class="showMore">(查看更多)</a>
</li>
</ul>
</div>`;
})
if(div.length==0){
$(".campusStyle-list_box").html(`<p>暂无风采</p>`);
}else{
$(".campusStyle-list_box").html(div);
}
$(".school_name_style").html(currentStation);
addSchoolNewslistEvent();
}
function showBasicSchoolInfo(){
stationInfoTableList.forEach(item=>{
var station=item["name"];
if(currentStation==station){
$(".schoolName").html(item["nickname"]);
$(".schoolAddress").html(item["address"]);
$(".schoolPersonPhone").html(item["legal_person"]+"("+item["legal_person_phone"]+")");
$(".schoolDetachment").html(item["detachment"]);
$(".schoolBorough").html(item["borough"]);
$(".teacherCount").html(item["teacherCount"]);
$(".roomCount").html(item["roomCount"]);
$(".studentCount").html(item["studentCount"]);
$(".guarderCount").html(item["guarderCount"]);
//显示学校大门口图片
var src=`${stationurl}/mdev/pic/download?creator=学校简介和图片/${station}&file=gate.jpg`
$(".schoolInfo_right").html(`<img src="${src}" alt="" id="${station}gate"/>`)
//图片放大
new Viewer(document.getElementById(`${station}gate`),{
url: 'data-original'
});
getStationmDesc(station);
}
})
}
//获取学校的简介
function getStationmDesc(station){
const url = `${stationurl}/mdev/pic/download?creator=学校简介和图片/${station}&file=简介.txt`
//const url = `${stationurl}/mdev/pic/download?creator=geo&file=430000.json`
fetch(url).then(response=>{
var status=response["status"]
if(status=="500"){
return new Promise((resovle)=>{
resovle("无数据");
})
}else{
//return response.json();
return response.text();
}
}).then(data => {
console.log(data);
$(".stationDesc").html(data);
});
}
function updateBasicSchoolInfo(station){
currentStation=station;
if(station=="000"){
currentStation="";
}
selectSchoolNewsGetlist();
}
function updateSchoolStyleTimeInfo(time){
var timearr=[];
time=time+" 23:59:59";
schoolNewslist.forEach(item=>{
var timestamp=new Date(item["timestamp"]).getTime();
var currTimestamp=new Date(time).getTime();
if(currTimestamp>timestamp){
timearr.push(item);
}
})
showSchoolNewslist(timearr)
}
function addSchoolNewslistEvent(){
$(".campusStyle-list>ul>li>.showMore").on('click',function(){
var newsId=$(this).parent().attr("newsId");
getSchoolStyleInfo(newsId,schoolNewslist)
})
}
export function getSchoolStyleInfo(newsId,schoolNewslist){
var imgs="";
var div="";
var imgUrlArr=[];
schoolNewslist.forEach(item=>{
if(item["newsId"]==newsId){
var timestamp=item["timestamp"]
var title=item["title"];
var comment=item["comment"];
var creator=item["creator"];
var station=item["station"];
div+=`<div class="schoolStyle_pop_info">
<p><span>学校: </span><span>${station}</span></p>
<p><span>标题: </span><span>${title}</span></p>
<p><span>内容: </span><span>${comment}</span></p>
<p><span>发布时间: </span><span>${timestamp}</span></p>
<p><span>发布者: </span><span>${creator}</span></p>
</div>`
if(item["imageUrls"].length>0){
var imgUrl=JSON.parse(item["imageUrls"]);
for(var i=0;i<imgUrl.length;i++){
var url=stationurl+imgUrl[i];
imgUrlArr.push(url);
imgs+=`<div class="schoolStyle_pop_img"><img src="${url}" id='hiddenDangerImg${url}'></div>`
}
}else{
imgs+=`<div class="schoolStyle_pop_img"><img src="/" id='hiddenDangerImg${url}'></div>`
}
}
})
div+=imgs;
popSchoolNewsDetail(div,imgUrlArr)
}
function popSchoolNewsDetail(div,imgUrlArr){
layuiObj.layer.open({
type: 1,
title: "详情", //不显示标题栏
area: ['600px', '600px'],
shade: 0.6,
id:new Date().getTime(), //设定一个id防止重复弹出
btnAlign: 'c',
moveType: 1, //拖拽模式0或者1
content: `<div style="padding:10px;color:#fff;background:#032357;height:calc(100% - 20px);overflow-y:auto; id='hiddenDangerImg'">
${div}
</div>`,
success: function(layero){
for(var i=0;i<imgUrlArr.length;i++){
new Viewer(document.getElementById(`hiddenDangerImg${imgUrlArr[i]}`),{
url: 'data-original'
});
}
}
});
}
export {selectSchoolNewsGetlist,updateBasicSchoolInfo,popSchoolNewsDetail}