anxiao_web/pages/starrating/js/pop/starRatingHistoryData.js

272 lines
11 KiB
JavaScript
Raw Normal View History

2024-07-24 09:22:32 +08:00
import {boroughList, layuiObj,schoolBasicInfo } from "../index.js";
import { schoolStarRatingHistoryGetlist } from "../orgApi/starRatingHistoryData.js";
import { getYearOption } from "../centerPage.js";
let starRatingHistoryList=[];
function showStarRatingHistoryData(){
layuiObj.layer.open({
type: 1,
title: '星级评定-历史数据', //不显示标题栏
area: ['1360px', '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">
<select name="interest" lay-filter="historyBoroughSelect" id="historyBoroughSelect" lay-search></select>
</div>
<div class="layui-input-inline">
<select name="interest" lay-filter="historyStationSelect" id="historyStationSelect" 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="staffSignSelectContent">
<table class="layui-hide" id="starRatingHistoryDataTable" lay-filter="starRatingHistoryDataTable"></table>
</div>
</div>`,
success: function(layero){
$("#historyYearSelect").html(getYearOption());
$("#historyBoroughSelect").html(starRatingBoroughSelectOptions());
$("#historyStationSelect").html(starRatingStationSelectOptions(schoolBasicInfo));
layuiObj.layuiForm.render("select","legalitySchoolForm")
addStarRatingHistoryDataEvent();
var year=$("#historyYearSelect").find("option:selected").val();
var obj={
schoolTime:year
}
selectYearStarRatingData(obj)
boroughOptionsChange();
}
});
}
//监听borough的改变
function boroughOptionsChange(){
layuiObj.layuiForm.on('select(historyBoroughSelect)', function(data){
var value=data["value"];
if(value=="000"){
$("#historyStationSelect").html(starRatingStationSelectOptions(schoolBasicInfo));
}else{
var temp=[];
for(var i=0;i<schoolBasicInfo.length;i++){
if(value==schoolBasicInfo[i]["borough"]){
temp.push(schoolBasicInfo[i]);
}
}
$("#historyStationSelect").html(starRatingStationSelectOptions(temp));
}
layuiObj.layuiForm.render("select","legalitySchoolForm")
})
}
function starRatingBoroughSelectOptions(){
var options=`<option value="000">请选择派出所</option>`;
for(var i=0;i<boroughList.length;i++){
var borough=boroughList[i]["borough"]
options+=`<option value="${borough}">${borough}</option>`;
}
return options;
}
function starRatingStationSelectOptions(list){
var options=`<option value="000">请选择学校</option>`;
for(var i=0;i<list.length;i++){
var name=list[i]["name"]
options+=`<option value="${name}" >${name}</option>`;
}
return options;
}
function addStarRatingHistoryDataEvent(){
$("#starRatingHistoryBtn").on('click',function(e){
e.preventDefault();
var year=$("#historyYearSelect").find("option:selected").val();
var borough=$("#historyBoroughSelect").find("option:selected").val();
var station=$("#historyStationSelect").find("option:selected").val();
var obj={
schoolTime:year
}
if(borough!="000"){
obj["borough"]=borough
}
if(station!="000"){
obj["station"]=station
}
selectYearStarRatingData(obj)
})
$("#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="9" style="text-align:center;">校园星级评定数据统计表</td>
</tr>
<tr style="font-size:16px;">
<th>序号</th>
<th>所属派出所</th>
<th>校园名称</th>
<th>自评扣分</th>
<th>得分</th>
<th>自评加分</th>
<th>分局评定扣分</th>
<th>分局评定加分</th>
<th>最终得分</th>
</tr>
</thead>`;
var tr=``;
for(var i=0;i<starRatingHistoryList.length;i++){
tr+=`<tr style="font-size:16px;" rowspan="2">
<td>${i+1}</td>
<td>${starRatingHistoryList[i]["borough"]}</td>
<td>${starRatingHistoryList[i]["station"]}</td>
<td>${starRatingHistoryList[i]["ratingBonusStation"]}</td>
<td
style="
background:#fff;
border:0.5px solid #C3CBDD;
text-align:center;
">
${getStationLevel(starRatingHistoryList[i])}
</td>
<td>${starRatingHistoryList[i]["ratingBonusStation"]}</td>
<td>${starRatingHistoryList[i]["ratingDescriptionBrigade"]}</td>
<td>${starRatingHistoryList[i]["ratingBonusBrigade"]}</td>
<td
style="
background:#fff;
border:0.5px solid #C3CBDD;
text-align:center;
">${getBrigadeLevel(starRatingHistoryList[i])}</td>
</tr>`
}
// 添加每一行数据
let tbody = `<tbody>${tr}</tbody>`;
let table = thead + tbody;
// 导出表格
exportToExcel(table,tableName);
};
function selectYearStarRatingData(obj){
starRatingHistoryList=[];
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]["index"]=i+1;
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(){
layuiObj.layuitable.render({
elem:'#starRatingHistoryDataTable',
data:starRatingHistoryList,
cols:[[
{field:'index', width:"5%", title: '序号'},
{field:'borough', width:"15%", title: '所属派出所'},
{field:'station', width:"10%", title: '校园名称'},
{field:'ratingDescriptionStation', width:"15%", title: '自评扣分',type:"scoreTotal"},
{field:'scoreTotalStation', width:"10%", title: '得分',type:"scoreDesire",templet:function(data) {// 替换数据
return getStationLevel(data)
}},
{field:'ratingBonusStation', width:"10%", title: '自评加分',type:"scoreHuman"},
{field:'ratingDescriptionBrigade', width:"15%", title: '分局评定扣分',type:"scoreDevices"},
{field:'ratingBonusBrigade', width:"10%", title: '分局评定加分',type:"scoreTech"},
{field:'scoreTotalBrigade', width:"10%", title: '最终得分',type:"scoreDesire",templet:function(data) {// 替换数据
return getBrigadeLevel(data)
}},
]],
limit:Number.MAX_VALUE // 数据表格默认全部显示
});
}
function getStationLevel(data){
var levelStation=parseInt(data["levelStation"]);
switch(levelStation){
case 1:
var span=`<p style="line-height:27px;">${data["scoreTotalStation"]}<br/>(一星)</p>`;
break;
case 2:
var span=`<p style="line-height:27px;">${data["scoreTotalStation"]}<br/>(二星)</p>`;
break;
case 3:
var span=`<p style="line-height:27px;">${data["scoreTotalStation"]}<br/>(三星)</p>`;
break;
case 4:
var span=`<p style="line-height:27px;">${data["scoreTotalStation"]}<br/>(四星)</p>`;
break;
case 5:
var span=`<p style="line-height:27px;">${data["scoreTotalStation"]}<br/>(五星)</p>`;
break;
default:
var span=`<p style="line-height:27px;">${data["scoreTotalStation"]}<br/>(五星)<p/>`;
break;
}
return span;
}
function getBrigadeLevel(data){
var levelBrigade=parseInt(data["levelBrigade"]);
switch(levelBrigade){
case 1:
var span=`<p style="line-height:27px; ">${data["scoreTotalBrigade"]}<br/>(一星)</p>`;
break;
case 2:
var span=`<p style="line-height:27px;">${data["scoreTotalBrigade"]}<br/>(二星)</p>`;
break;
case 3:
var span=`<p style="line-height:27px;">${data["scoreTotalBrigade"]}<br/>(三星)</p>`;
break;
case 4:
var span=`<p style="line-height:27px;">${data["scoreTotalBrigade"]}<br/>(四星)</p>`;
break;
case 5:
var span=`<p style="line-height:27px;">${data["scoreTotalBrigade"]}<br/>(五星)</p>`;
break;
default:
var span=`<p style="line-height:27px;">${data["scoreTotalBrigade"]}<br/>(五星)</p>`;
break;
}
return span;
}
export {
showStarRatingHistoryData,
}