anxiao_web/pages/starrating/js/pop/starRatingDataTotal.js

225 lines
8.3 KiB
JavaScript
Raw Normal View History

2024-07-24 09:22:32 +08:00
import {layuiObj } from "../index.js";
import { schoolStarRatingHistoryGetlist } from "../orgApi/starRatingHistoryData.js";
import { getYearOption } from "../centerPage.js";
let starRatingHistoryList=[];
function showStarRatingDataTotal(){
layuiObj.layer.open({
type: 1,
title: '星级评定-数据统计', //不显示标题栏
area: ['960px', '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;">
<div class="legalitySchoolInfo">
<form class="layui-form" action="" id="legalitySchoolForm" lay-filter="legalitySchoolForm" >
<div class="layui-input-inline">
<select name="interest" lay-filter="historyYearSelect" id="historyYearSelect" lay-search></select>
</div>
<div class="layui-input-inline">
<button class="layui-btn" id="starRatingHistoryBtn" style="height:38px !important;line-height:38px !important;">查询</button>
</div>
<div class="layui-input-inline">
<button class="layui-btn" id="starRatingHistoryExportBtn" style="height:38px !important;line-height:38px !important;display:none">导出</button>
</div>
</form>
</div>
<div class="starRatingDataTotalContent">
<table class="layui-hide" id="starRatingDataTotalTable" lay-filter="starRatingDataTotalTable"></table>
</div>
</div>`,
success: function(layero){
$("#historyYearSelect").html(getYearOption());
layuiObj.layuiForm.render()
addStarRatingHistoryDataEvent();
var year=$("#historyYearSelect").find("option:selected").val();
selectYearStarRatingData(year)
}
});
}
function addStarRatingHistoryDataEvent(){
$("#starRatingHistoryBtn").on('click',function(e){
e.preventDefault();
var year=$("#historyYearSelect").find("option:selected").val();
selectYearStarRatingData(year)
})
$("#starRatingHistoryExportBtn").on('click',function(e){
e.preventDefault();
export2TroubleExcel()
})
}
function export2TroubleExcel() {
var tableName=$("#historyYearSelect").find("option:selected").val()+"校园星级评定数据统计表"
// 添加表头信息
let thead = `
<thead>
<tr style="font-size:22px;">
<td colspan="7" style="text-align:center;">校园星级评定数据统计表</td>
</tr>
<tr style="font-size:18px;">
<th>序号</th>
<th>派出所</th>
<th>五星学校</th>
<th>四星学校</th>
<th>三星学校</th>
<th>二星学校</th>
<th>一星学校</th>
</tr>
</thead>`;
var data=getStarRatingBoroughData();
var levelBrigade5Total=0;
var levelBrigade4Total=0;
var levelBrigade3Total=0;
var levelBrigade2Total=0;
var levelBrigade1Total=0;
var tr=``;
for(var i=0;i<data.length;i++){
tr+=`<tr style="font-size:16px;">
<td>${data[i]["index"]}</td>
<td>${data[i]["borough"]}</td>
<td>${data[i]["levelBrigade5"].length}</td>
<td>${data[i]["levelBrigade4"].length}</td>
<td>${data[i]["levelBrigade3"].length}</td>
<td>${data[i]["levelBrigade2"].length}</td>
<td>${data[i]["levelBrigade1"].length}</td>
</tr>`
levelBrigade5Total+=data[i]["levelBrigade5"].length
levelBrigade4Total+=data[i]["levelBrigade4"].length
levelBrigade3Total+=data[i]["levelBrigade3"].length
levelBrigade2Total+=data[i]["levelBrigade2"].length
levelBrigade1Total+=data[i]["levelBrigade1"].length
}
tr+=`<tr style="font-size:16px;">
<td colspan="2" style="text-align:center;">合计</td>
<td>${levelBrigade5Total}</td>
<td>${levelBrigade4Total}</td>
<td>${levelBrigade3Total}</td>
<td>${levelBrigade2Total}</td>
<td>${levelBrigade1Total}</td>
</tr>`
// 添加每一行数据
let tbody = `<tbody>${tr}</tbody>`;
let table = thead + tbody;
// 导出表格
exportToExcel(table, tableName);
};
function selectYearStarRatingData(year){
starRatingHistoryList=[];
var obj={
schoolTime:year
}
schoolStarRatingHistoryGetlist(obj).then(res=>{
var code=res["data"]["code"];
if(code==0){
var data=res["data"]["data"];
for(var i=0;i<data.length;i++){
data[i]["scoreTotalBrigade"]=data[i]["scoreTotalBrigade"]/10
data[i]["ratingBonusBrigade"]=data[i]["ratingBonusBrigade"]/10
data[i]["ratingBonusStation"]=data[i]["ratingBonusStation"]/10
data[i]["scoreTotalStation"]=data[i]["scoreTotalStation"]/10
}
starRatingHistoryList=data;
}
if(starRatingHistoryList.length==0){
$("#starRatingHistoryExportBtn").css("display","none");
}else{
$("#starRatingHistoryExportBtn").css("display","block");
}
showStarRatingHistoryTable();
})
}
function showStarRatingHistoryTable(){
var data=getStarRatingBoroughData();
layuiObj.layuitable.render({
elem:'#starRatingDataTotalTable',
data:data,
cols:[[
{field:'index', width:"10%", title: '序号'},
{field:'borough', width:"15%", title: '派出所'},
{field:'levelBrigade5', width:"15%", title: '五星学校',templet : function(data) {// 替换数据
return data["levelBrigade5"].length;
}},
{field:'levelBrigade4', width:"15%", title: '四星学校',templet : function(data) {// 替换数据
return data["levelBrigade4"].length;
}},
{field:'levelBrigade3', width:"15%", title: '三星学校',templet : function(data) {// 替换数据
return data["levelBrigade3"].length;
}},
{field:'levelBrigade2', width:"15%", title: '二星学校',templet : function(data) {// 替换数据
return data["levelBrigade2"].length;
}},
{field:'levelBrigade1', width:"15%", title: '一星学校',templet : function(data) {// 替换数据
return data["levelBrigade1"].length;
}},
]],
limit:Number.MAX_VALUE, // 数据表格默认全部显示
});
}
function getStarRatingBoroughData(){
var starRatingHash={};
for(var i=0;i<starRatingHistoryList.length;i++){
var borough=starRatingHistoryList[i]["borough"];
var levelBrigade=starRatingHistoryList[i]["levelBrigade"];
if(!(borough in starRatingHash)){
starRatingHash[borough]={
"borough":borough,
"levelBrigade5":[],
"levelBrigade4":[],
"levelBrigade3":[],
"levelBrigade2":[],
"levelBrigade1":[],
};
}
switch(levelBrigade){
case 1:
starRatingHash[borough]["levelBrigade1"].push(starRatingHistoryList[i]);
break;
case 2:
starRatingHash[borough]["levelBrigade2"].push(starRatingHistoryList[i]);
break;
case 3:
starRatingHash[borough]["levelBrigade3"].push(starRatingHistoryList[i]);
break;
case 4:
starRatingHash[borough]["levelBrigade4"].push(starRatingHistoryList[i]);
break;
case 5:
starRatingHash[borough]["levelBrigade5"].push(starRatingHistoryList[i]);
break;
default:
break;
}
}
var starRatingList=[];
var index=1;
for(var i in starRatingHash){
starRatingHash[i]["index"]=index;
starRatingList.push(starRatingHash[i]);
index++;
}
return starRatingList;
}
export {
showStarRatingDataTotal,
}