169 lines
4.8 KiB
JavaScript
169 lines
4.8 KiB
JavaScript
|
import {schoolBasicInfo,starRatingArr,layuiObj} from "./index.js";
|
||
|
import { drawStarRatingTotalChart } from "./drawEchart.js";
|
||
|
let school_y_list=[];
|
||
|
let school_x_list=[];
|
||
|
let school_z_list=[];
|
||
|
function createSchoolInfo(){
|
||
|
for(let i=0;i<schoolBasicInfo.length;i++){
|
||
|
var type=schoolBasicInfo[i]["type"];
|
||
|
switch(type){
|
||
|
case "幼儿园":
|
||
|
school_y_list.push(schoolBasicInfo[i]);
|
||
|
break;
|
||
|
case "小学":
|
||
|
school_x_list.push(schoolBasicInfo[i]);
|
||
|
break;
|
||
|
case "中学":
|
||
|
school_z_list.push(schoolBasicInfo[i]);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
function showSchoolInfo(){
|
||
|
var school_span="";
|
||
|
school_span+=`<p>
|
||
|
<span>幼儿园</span>
|
||
|
<span>${school_y_list.length}</span>
|
||
|
<span style="width:${school_y_list.length}px"></span>
|
||
|
<span>${(school_y_list.length/schoolBasicInfo.length).toFixed(2)*100+"%"}</span>
|
||
|
</p>`
|
||
|
|
||
|
school_span+=`<p>
|
||
|
<span>小学</span>
|
||
|
<span>${school_x_list.length}</span>
|
||
|
<span style="width:${school_x_list.length}px"></span>
|
||
|
<span>${(school_x_list.length/schoolBasicInfo.length).toFixed(2)*100+"%"}</span>
|
||
|
</p>`
|
||
|
|
||
|
school_span+=` <p>
|
||
|
<span>中学</span>
|
||
|
<span>${school_z_list.length}</span>
|
||
|
<span style="width:${school_z_list.length}px"></span>
|
||
|
<span>${(school_z_list.length/schoolBasicInfo.length).toFixed(2)*100+"%"}</span>
|
||
|
</p>`
|
||
|
$(".schoolBasicInfo").html(school_span);
|
||
|
$(".schoolInfoTotal").html(schoolBasicInfo.length);
|
||
|
}
|
||
|
|
||
|
function showThreeColorInfo(){
|
||
|
$(".schoolInfo_y").html(school_y_list.length);
|
||
|
$(".schoolInfo_x").html(school_x_list.length);
|
||
|
$(".schoolInfo_z").html(school_z_list.length);
|
||
|
|
||
|
var threeColorTotalEchat = echarts.init(document.getElementById('threeColorTotalEchat'));
|
||
|
threeColorTotalEchat.setOption(drawStarRatingTotalChart(getSchoolLevelData(starRatingArr),"总数"));
|
||
|
|
||
|
var school_y_data=getArrEqual(school_y_list);
|
||
|
var threeColorYEchat = echarts.init(document.getElementById('threeColorYEchat'));
|
||
|
threeColorYEchat.setOption(drawStarRatingTotalChart(getSchoolLevelData(school_y_data),"幼儿园"));
|
||
|
|
||
|
var school_x_data=getArrEqual(school_x_list);
|
||
|
var threeColorXEchat = echarts.init(document.getElementById('threeColorXEchat'));
|
||
|
threeColorXEchat.setOption(drawStarRatingTotalChart(getSchoolLevelData(school_x_data),"小学"));
|
||
|
|
||
|
var school_z_data=getArrEqual(school_z_list);
|
||
|
var threeColorZEchat = echarts.init(document.getElementById('threeColorZEchat'));
|
||
|
threeColorZEchat.setOption(drawStarRatingTotalChart(getSchoolLevelData(school_z_data),"中学"));
|
||
|
|
||
|
}
|
||
|
|
||
|
function getSchoolLevelData(data){
|
||
|
var oneStar=[];
|
||
|
var twoStar=[]
|
||
|
var threeStar=[];
|
||
|
var fourStar=[];
|
||
|
var fiveStar=[];
|
||
|
for(var i=0;i<data.length;i++){
|
||
|
var total=data[i]["scoreTotal"];
|
||
|
if(total>=95){
|
||
|
fiveStar.push(data[i]);
|
||
|
}else if(total>=85){
|
||
|
fourStar.push(data[i]);
|
||
|
}else if(total>=75){
|
||
|
threeStar.push(data[i]);
|
||
|
}else if(total>=65){
|
||
|
twoStar.push(data[i]);
|
||
|
}else{
|
||
|
oneStar.push(data[i]);
|
||
|
}
|
||
|
}
|
||
|
return[
|
||
|
{ value:fiveStar.length,name:'五星'},
|
||
|
{ value:fourStar.length,name:'四星'},
|
||
|
{ value:threeStar.length,name:'三星'},
|
||
|
{ value:twoStar.length,name:'二星'},
|
||
|
{ value:oneStar.length,name:'一星'}
|
||
|
];
|
||
|
}
|
||
|
|
||
|
function getArrEqual(arr){
|
||
|
let newArr = [];
|
||
|
for (let j = 0; j < arr.length; j++) {
|
||
|
for (let i = 0; i < starRatingArr.length; i++) {
|
||
|
if(arr[j]["name"]==starRatingArr[i]["station"]){
|
||
|
newArr.push(starRatingArr[i]);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return newArr;
|
||
|
}
|
||
|
|
||
|
//排名后10
|
||
|
function showStarraingBottomTen(){
|
||
|
var data=[];
|
||
|
for(var i=0;i<starRatingArr.length;i++){
|
||
|
if(i>9){
|
||
|
break;
|
||
|
}
|
||
|
starRatingArr[i]["index"]=i+1
|
||
|
data.push(starRatingArr[i])
|
||
|
}
|
||
|
layuiObj.layuitable.render({
|
||
|
elem:'#starraingTopTen',
|
||
|
data:data,
|
||
|
cols: [[
|
||
|
{field:'index', width:"15%", title: '序号'},
|
||
|
{field:'station', width:"35%", title: '名称'},
|
||
|
{field:'scoreTotal', width:"15%", title: '评分'},
|
||
|
{field:'img', width:"35%", title: '等级',templet : function(data) {// 替换数据
|
||
|
var scoreTotal=data["scoreTotal"];
|
||
|
return getStartLevelText(scoreTotal)
|
||
|
}
|
||
|
},
|
||
|
]],
|
||
|
limit:Number.MAX_VALUE, // 数据表格默认全部显示
|
||
|
done:function(res, curr, count){
|
||
|
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function getStartLevelText(total){
|
||
|
if(total>=95){
|
||
|
var imgsrc="./image/five.png";
|
||
|
}else if(total>=85){
|
||
|
var imgsrc="./image/four.png";
|
||
|
}else if(total>=75){
|
||
|
var imgsrc="./image/three.png";
|
||
|
}else if(total>=65){
|
||
|
var imgsrc="./image/two.png";
|
||
|
}else{
|
||
|
var imgsrc="./image/one.png";
|
||
|
}
|
||
|
return `<img src="${imgsrc}"style="height:15px;">`;
|
||
|
}
|
||
|
|
||
|
export {
|
||
|
createSchoolInfo,
|
||
|
showSchoolInfo,
|
||
|
showThreeColorInfo,
|
||
|
showStarraingBottomTen,
|
||
|
getStartLevelText,
|
||
|
getSchoolLevelData
|
||
|
}
|
||
|
|