Files
h5/src/views/PrincipalsMailbox/ResponsiblePersonManagement/index.vue
T
2024-01-30 09:30:56 +08:00

338 lines
9.0 KiB
Vue

<template>
<div class="home">
<!-- charts -->
<el-row :gutter="15" class="mt15">
<el-col :md="24" :lg="8" :xl="8" class="mb15">
<el-card shadow="hover">
<div slot="header">
<span>今年信件占比</span>
</div>
<div class="charts">
<div class="charts-right">
<div ref="homeStockRef" class="h100"></div>
</div>
</div>
</el-card>
</el-col>
<el-col :md="24" :lg="16" :xl="16" class="mb15">
<el-card shadow="hover">
<div slot="header">
<span>信件数据分析</span>
</div>
<div class="charts">
<div class="charts-left mr7">
<div ref="homeLaboratoryRef" class="h100"></div>
</div>
</div>
</el-card>
</el-col>
</el-row>
<el-card class="box-card">
<el-button @click="addResponsiblePerson" type="primary" icon="el-icon-plus"
>添加负责人</el-button
>
<PersonInCharge
v-loading="loading"
:delete-func="deleteData"
:columns="columns"
:data="listOfResponsiblePersonnel"
></PersonInCharge>
<!-- 添加负责人对话框 -->
<el-dialog
title="添加负责人"
:visible.sync="dialogVisible"
width="20%"
:before-close="handleClose"
>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="请选择老师" label-width="100px">
<el-select v-model="form.teacherId" placeholder="请选择老师">
<el-option
v-for="(ion, index) in teacherList"
:key="index"
:label="ion.name"
:value="ion.userId"
></el-option> </el-select
></el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="addOwnerButton">确 定</el-button>
</span>
</el-dialog>
</el-card>
</div>
</template>
<script>
import * as echarts from "echarts";
import { columns } from "./columns";
import { Message } from "element-ui";
import PersonInCharge from "../components/PersonInCharge.vue";
import {
rqQieChartInformation,
getLineChartData,
getTeacherInformation,
rqaddResponsiblePerson,
getTheListOfExistingResponsiblePersons,
cancelResponsiblePerson,
} from "../api.js";
export default {
name: "ResponsiblePersonManagement",
data() {
return {
global: {
homeChartOne: null,
homeChartTwo: null,
homeCharThree: null,
dispose: [null, "", undefined],
},
dialogVisible: false,
columns,
charts: {
theme: "",
bgColor: "",
},
// 饼图数据
pieChartData: [],
// 折线图数据
lineChartDatas: [],
// 折线图左侧年份数据
yearData: [],
// 添加老师的信息
form: {
teacherId: null,
},
loading: false,
// 教师列表
teacherList: [],
// 负责人列表
listOfResponsiblePersonnel: [],
};
},
components: {
PersonInCharge,
},
created() {
this.obtainTheListOfResponsiblePersons();
this.obtainTeacherListData();
this.lineChartData();
this.obtainPieChartInformation();
},
mounted() {},
methods: {
// 库存作业
initHomeStock() {
console.log(this.pieChartData);
if (!this.global.dispose.some((b) => b === this.global.homeChartOne))
this.global.homeChartOne.dispose();
this.global.homeChartOne = echarts.init(this.$refs.homeStockRef, this.charts.theme);
const option = {
backgroundColor: this.charts.bgColor,
grid: {
top: 50,
right: 20,
bottom: 30,
left: 30,
},
tooltip: {
trigger: "item",
},
legend: {
left: "center",
},
series: [
{
name: "信件占比",
type: "pie",
radius: ["40%", "70%"],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: "#fff",
borderWidth: 2,
},
data: this.pieChartData,
top: 30,
},
],
};
this.global.homeChartOne.setOption(option);
window.addEventListener("resize", () => {
this.global.homeChartOne.resize();
});
},
initHomeLaboratory() {
if (!this.global.dispose.some((b) => b === this.global.homeChartTwo))
this.global.homeChartTwo.dispose();
this.global.homeChartTwo = echarts.init(
this.$refs.homeLaboratoryRef,
this.charts.theme
);
const option = {
backgroundColor: this.charts.bgColor,
grid: {
top: 50,
right: 20,
bottom: 30,
left: 30,
},
tooltip: {
trigger: "axis",
},
legend: {
data: this.yearData,
right: 13,
},
xAxis: {
data: [
"一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月",
],
},
yAxis: [
{
type: "value",
name: "信件",
},
],
series: this.lineChartDatas,
};
this.global.homeChartTwo.setOption(option);
window.addEventListener("resize", () => {
this.global.homeChartTwo.resize();
});
},
// 取消负责人
async deleteData(row) {
try {
let res = await cancelResponsiblePerson(row.userId);
if (res.code == 200) {
this.obtainTheListOfResponsiblePersons();
Message.success("负责人已取消");
} else {
Message.error("网络错误");
}
} catch (error) {
Message.error("网络错误");
}
},
// 获取饼状图信息
async obtainPieChartInformation() {
let res = await rqQieChartInformation();
if (res.code == 200) {
const newArray = res.data.map((item) => {
let roleName;
switch (item.roleId) {
case 0:
roleName = "学生发送";
break;
case 1:
roleName = "教职工发送";
break;
case 2:
roleName = "教师发送";
break;
default:
roleName = "";
}
return { numid: item.numid, name: roleName };
});
const newArrays = newArray.map((item) => {
return { value: item.numid, name: item.name };
});
this.pieChartData = newArrays;
this.initHomeStock();
}
},
// 折线图
async lineChartData() {
let result = await getLineChartData();
if (result.code == 200) {
let array = result.data;
const newProperty = "type";
for (let i = 0; i < array.length; i++) {
array[i][newProperty] = "line";
}
this.lineChartDatas = array;
const newArray = array.map((item) => item.name);
this.yearData = newArray;
this.initHomeLaboratory();
}
},
// 获取教师人员名单
async obtainTeacherListData() {
try {
let result = await getTeacherInformation();
if (result.code == 200) {
this.teacherList = result.data;
}
} catch (error) {
Message.error("网络错误");
}
},
handleClose(done) {
this.$confirm("确认关闭?")
.then((_) => {
done();
})
.catch((_) => {});
},
// 添加负责人
addResponsiblePerson() {
this.dialogVisible = true;
},
// 确认添加负责人
async addOwnerButton() {
try {
let result = await rqaddResponsiblePerson(this.form.teacherId);
if (result.code == 200) {
this.dialogVisible = false;
this.obtainTheListOfResponsiblePersons();
Message.success("添加成功");
} else if (result.code == 201) {
Message.error(result.msg);
} else {
Message.error("网络错误");
}
} catch (error) {
Message.error("网络错误");
}
},
// 获取负责人列表
async obtainTheListOfResponsiblePersons() {
this.loading = true;
try {
let result = await getTheListOfExistingResponsiblePersons();
if (result.code == 200) {
this.loading = false;
this.listOfResponsiblePersonnel = result.data;
} else {
this.loading = false;
Message.error("网络错误");
}
} catch (error) {
this.loading = false;
Message.error("网络错误");
}
},
},
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>