studentEva.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <div class="pb_content" style="background: unset" v-loading="ExcelLoading">
  3. <div
  4. class="pb_content_body"
  5. style="
  6. background: #fff;
  7. padding: 0px 25px;
  8. box-sizing: border-box;
  9. border-radius: 5px;
  10. "
  11. >
  12. <div class="pb_head top">
  13. <span>查看学生</span>
  14. <div style="border-radius: 4px">
  15. <el-button
  16. type="primary"
  17. class="bgColor student_button"
  18. @click="backPath"
  19. >返回</el-button
  20. >
  21. </div>
  22. </div>
  23. <div class="student_head">
  24. <div class="head_left">
  25. <el-input
  26. v-model="sName"
  27. class="student_input"
  28. @change="searchStudent"
  29. placeholder="请输入用户名"
  30. ></el-input>
  31. <el-select
  32. disabled
  33. v-model="cid"
  34. placeholder="请选择班级"
  35. class="student_input"
  36. @change="searchStudent"
  37. >
  38. <el-option
  39. v-for="(c, cIndex) in classJuri"
  40. :key="cIndex"
  41. :label="c.name"
  42. :value="c.id"
  43. ></el-option>
  44. </el-select>
  45. <el-select
  46. v-model="year"
  47. placeholder="请选择学期"
  48. class="student_input"
  49. @change="searchStudent"
  50. >
  51. <el-option
  52. v-for="(y, yIndex) in yearJuri"
  53. :key="yIndex"
  54. :label="y.name"
  55. :value="y.id"
  56. ></el-option>
  57. </el-select>
  58. <el-button type="primary" class="student_button" @click="resetting"
  59. >重置</el-button
  60. >
  61. </div>
  62. <div>
  63. <el-button type="primary" class="student_button" @click="downloadData"
  64. >下载数据</el-button
  65. >
  66. </div>
  67. </div>
  68. </div>
  69. <div class="pb_content_body">
  70. <div class="student_table">
  71. <el-table
  72. ref="table"
  73. :key="1"
  74. :data="tableData"
  75. border
  76. :height="tableHeight"
  77. :fit="true"
  78. v-loading="isLoading"
  79. style="width: 100%; height: 60%"
  80. :header-cell-style="{ background: '#f1f1f1' }"
  81. :row-class-name="tableRowClassName"
  82. >
  83. <el-table-column prop="name" label="姓名" align="center">
  84. </el-table-column>
  85. <el-table-column prop="accNumber" label="学生账号" align="center">
  86. </el-table-column>
  87. <el-table-column prop="rcount" label="观察记录总数" align="center">
  88. </el-table-column>
  89. <el-table-column prop="oneScore" label="学期前" align="center">
  90. </el-table-column>
  91. <el-table-column prop="twoScore" label="学期中" align="center">
  92. </el-table-column>
  93. <el-table-column prop="threeScore" label="学期末" align="center">
  94. </el-table-column>
  95. <el-table-column prop="sum" label="综合评分" align="center">
  96. </el-table-column>
  97. <el-table-column label="操作" width="400px">
  98. <template slot-scope="scope">
  99. <div class="classButtonBox">
  100. <el-button
  101. class="de_button"
  102. type="primary"
  103. size="small"
  104. @click="
  105. goTo(
  106. '/kindStudentEva?userid=' +
  107. userid +
  108. '&oid=' +
  109. oid +
  110. '&org=' +
  111. org +
  112. '&cid=' +
  113. cid +
  114. '&suid=' +
  115. scope.row.userid +
  116. '&role=' +
  117. role +
  118. '&fathType=' +
  119. fathType
  120. )
  121. "
  122. >查看评价</el-button
  123. >
  124. </div>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. </div>
  129. <div class="student_page">
  130. <el-pagination
  131. background
  132. layout="prev, pager, next"
  133. :page-size="10"
  134. :total="total"
  135. v-if="page"
  136. @current-change="handleCurrentChange"
  137. >
  138. </el-pagination>
  139. </div>
  140. </div>
  141. </div>
  142. </template>
  143. <script>
  144. export default {
  145. data() {
  146. return {
  147. tableHeight: "500px",
  148. isLoading: false,
  149. ExcelLoading: false,
  150. formLabelWidth: "100px",
  151. userid: this.$route.query.userid,
  152. org: this.$route.query.org,
  153. oid: this.$route.query.oid,
  154. cid: this.$route.query.cid,
  155. role: this.$route.query.role,
  156. tableData: [],
  157. sName: "",
  158. year: "",
  159. classJuri: [],
  160. yearJuri: [],
  161. page: 1,
  162. total: 0,
  163. // 储存判断跳转路由
  164. fathType: null
  165. };
  166. },
  167. methods: {
  168. goTo(path) {
  169. this.$router.push(path);
  170. },
  171. tableRowClassName({ row, rowIndex }) {
  172. if ((rowIndex + 1) % 2 === 0) {
  173. return "even_row";
  174. } else {
  175. return "";
  176. }
  177. },
  178. // 判断返回上级页面
  179. backPath() {
  180. if (this.fathType) {
  181. this.$router.push(
  182. "/record" +
  183. "?userid=" +
  184. this.userid +
  185. "&oid=" +
  186. this.oid +
  187. "&org=" +
  188. this.org +
  189. "&role=" +
  190. this.role
  191. );
  192. } else {
  193. this.$router.push(
  194. "/class" +
  195. "?userid=" +
  196. this.userid +
  197. "&oid=" +
  198. this.oid +
  199. "&org=" +
  200. this.org +
  201. "&role=" +
  202. this.role
  203. );
  204. }
  205. },
  206. //获取班级列表
  207. getClass() {
  208. // this.isLoading = true;
  209. let params = {
  210. oid: this.oid
  211. };
  212. this.ajax
  213. .get(this.$store.state.api + "selectClassBySchool", params)
  214. .then(res => {
  215. // this.isLoading = false;
  216. this.classJuri = res.data[0];
  217. // console.log( this.classJuri);
  218. })
  219. .catch(err => {
  220. // this.isLoading = false;
  221. console.error(err);
  222. });
  223. },
  224. getYear() {
  225. // this.isLoading = true;
  226. this.ajax
  227. .get(this.$store.state.api + "selectTerm")
  228. .then(res => {
  229. this.isLoading = false;
  230. var yearJuri = res.data[0];
  231. for (var i = 0; i < yearJuri.length; i++) {
  232. if (yearJuri[i].defaultC == 1) {
  233. this.year = yearJuri[i].id;
  234. }
  235. }
  236. this.yearJuri = yearJuri;
  237. // console.log(this.yearJuri);
  238. this.searchStudent();
  239. })
  240. .catch(err => {
  241. // this.isLoading = false;
  242. console.error(err);
  243. });
  244. },
  245. handleCurrentChange(val) {
  246. this.page = val;
  247. this.searchStudent();
  248. },
  249. // 导出数据提示
  250. downloadData() {
  251. // console.log('导出数据');
  252. this.$confirm("是否导出Excel?", "提示", {
  253. confirmButtonText: "确定",
  254. cancelButtonText: "取消"
  255. })
  256. .then(() => {
  257. this.ExcelLoading = true;
  258. let params = {
  259. cid: this.cid,
  260. id: this.year
  261. };
  262. this.ajax
  263. .get(this.$store.state.api + "selectClassAllRecord", params)
  264. .then(res => {
  265. // console.log(res.data[0]);
  266. // 发现导出的数据不对,是因为导出是按学期分的,进入学生主页显示的是全部
  267. this.exportExcel(res.data[0]);
  268. });
  269. })
  270. .catch(() => {});
  271. },
  272. // 导出数据
  273. exportExcel(val) {
  274. let resList = val;
  275. let termName = "";
  276. let className = "";
  277. this.yearJuri.forEach(i => {
  278. if (i.id == this.year) {
  279. termName = i.name;
  280. }
  281. });
  282. this.classJuri.forEach(i => {
  283. if (i.id == this.cid) {
  284. className = i.name;
  285. }
  286. });
  287. // console.log('导出数据',res);
  288. //如果value的json字段的key值和想要的headers值不一致时,可做如下更改
  289. //将和下面的Object.fromEntries结合,将json字段的key值改变为要求的excel的header值
  290. var array = [];
  291. for (var i = 0; i < resList.length; i++) {
  292. var _json = {};
  293. _json["姓名"] = resList[i].name;
  294. _json["关联同学"] = resList[i].constus;
  295. _json["班级"] = resList[i].cname;
  296. _json["记录时间"] = resList[i].recordDate;
  297. _json["学期"] = resList[i].tName;
  298. _json["维度"] = resList[i].VeidooList;
  299. _json["观察地点"] = resList[i].place;
  300. _json["观察内容"] = resList[i].recordTit;
  301. _json["内容"] = resList[i].recordContent;
  302. // _json["创建时间"] = res[i].create_at;
  303. array.push(_json);
  304. }
  305. var XLSX = require("xlsx");
  306. const workbook = XLSX.utils.book_new(); //创建一个新的工作簿对象
  307. let ws = XLSX.utils.json_to_sheet(array); //将json对象数组转化成工作表
  308. ws["!cols"] = [
  309. //设置每一列的宽度
  310. { wch: 10 },
  311. { wch: 30 },
  312. { wch: 10 },
  313. { wch: 20 },
  314. { wch: 20 },
  315. { wch: 30 },
  316. { wch: 30 },
  317. { wch: 30 },
  318. { wch: 30 }
  319. ];
  320. XLSX.utils.book_append_sheet(workbook, ws, "sheet1"); //把sheet添加到workbook里,第三个参数是sheet名
  321. XLSX.writeFile(workbook, className + "-" + termName + "观察记录.xlsx");
  322. // const wopts = { bookType: "xlsx", bookSST: false, type: "array" };//写入的样式bookType:输出的文件类型,type:输出的数据类型,bookSST: 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
  323. // const wbout = XLSX.write(workbook, wopts);// 浏览器端和node共有的API,实际上node可以直接使用xlsx.writeFile来写入文件,但是浏览器没有该API
  324. // FileSaver.saveAs(new Blob([wbout], { type: "application/octet-stream" }), `${title} demo.xlsx`);//保存文件
  325. this.ExcelLoading = false;
  326. this.$message({
  327. message: "下载成功",
  328. type: "success"
  329. });
  330. },
  331. // 数据相同下标相加组成一个新数组
  332. combineArrays(arrays) {
  333. const result = [];
  334. // 获取数组中的最大长度
  335. const maxLength = Math.max(...arrays.map(arr => arr.length));
  336. // 遍历每个下标
  337. for (let i = 0; i < maxLength; i++) {
  338. const combinedItem = [];
  339. // 遍历每个数组
  340. for (let j = 0; j < arrays.length; j++) {
  341. const array = arrays[j];
  342. // 检查当前下标是否存在于数组中
  343. if (i < array.length) {
  344. const item = array[i];
  345. // 将当前下标的字段添加到组合数组中
  346. combinedItem.push(item);
  347. }
  348. }
  349. // 将组合数组添加到结果数组中
  350. result.push(combinedItem);
  351. }
  352. return result;
  353. },
  354. // 数组相加
  355. addArrays(array1, array2) {
  356. const result = [];
  357. for (let i = 0; i < array2.length; i++) {
  358. const sum = (array1[i] || 0) + array2[i];
  359. result.push(sum);
  360. }
  361. return result;
  362. },
  363. resetting() {
  364. this.sName = "";
  365. for (var i = 0; i < this.yearJuri.length; i++) {
  366. if (this.yearJuri[i].defaultC == 1) {
  367. this.year = this.yearJuri[i].id;
  368. }
  369. }
  370. this.searchStudent()
  371. },
  372. searchStudent() {
  373. this.isLoading = true;
  374. let params = {
  375. cid: this.cid,
  376. cu: this.sName,
  377. cn: this.year,
  378. oid: this.oid,
  379. org: this.org,
  380. page: this.page
  381. };
  382. this.ajax
  383. .get(this.$store.state.api + "selectStudentAndRecord", params)
  384. .then(res => {
  385. this.isLoading = false;
  386. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  387. var tableData = res.data[0];
  388. // console.log('tableData',tableData);
  389. var ftype = res.data[1]; //公共父级分类
  390. var stype = res.data[2]; //公共子级分类
  391. var sctype = res.data[3]; //该学校子级分类
  392. var fctype = res.data[4]; //该学校父级分类
  393. var fotype = res.data[5]; //组织父级分类
  394. var sotype = res.data[6]; //组织子级分类
  395. var allfType = [];
  396. var allsType = [];
  397. if (fotype.length == 0 && sotype.length == 0) {
  398. if (fctype.length == 0 && sctype.length == 0) {
  399. for (var i = 0; i < ftype.length; i++) {
  400. allfType.push(ftype[i]);
  401. }
  402. for (var i = 0; i < stype.length; i++) {
  403. allsType.push(stype[[i]]);
  404. }
  405. } else {
  406. for (var i = 0; i < fctype.length; i++) {
  407. allfType.push(fctype[i]);
  408. }
  409. for (var i = 0; i < sctype.length; i++) {
  410. allsType.push(sctype[[i]]);
  411. }
  412. }
  413. } else {
  414. for (var i = 0; i < fotype.length; i++) {
  415. allfType.push(fotype[i]);
  416. }
  417. for (var i = 0; i < sotype.length; i++) {
  418. allsType.push(sctysotypepe[[i]]);
  419. }
  420. }
  421. for (var i = 0; i < tableData.length; i++) {
  422. var json = JSON.parse(tableData[i].json);
  423. if (json) {
  424. var count = 0;
  425. var sum = 0;
  426. // console.log("json", json);
  427. allfType.forEach(e => {
  428. // console.log(e);
  429. let fid = e.id;
  430. e.child = json[fid];
  431. });
  432. // 将每个大分类下的小分类数据提取出来,在大分类下创建一个child2来存储
  433. allfType.forEach((e, k) => {
  434. e.child2 = [];
  435. e.child.forEach((i, index) => {
  436. e.child2.push(i[i.id]);
  437. });
  438. });
  439. // 不按分类储存所有分数在allScore里
  440. let allScore = [];
  441. // 最后平均分
  442. let croMapData = [];
  443. // 将所有分数添加到allScore里
  444. allfType.forEach((e, k) => {
  445. allScore = [...allScore, ...e.child2];
  446. });
  447. // 计算每个小分类的平均分,并添加到croMapData里
  448. allScore.forEach(e => {
  449. // console.log(e);
  450. croMapData = this.addArrays(croMapData, e);
  451. });
  452. // 最后除以小分类长度得出分数
  453. croMapData = croMapData.map(function(item) {
  454. return (item / allScore.length).toFixed(1);
  455. });
  456. tableData[i].oneScore = croMapData[0];
  457. tableData[i].twoScore = croMapData[1];
  458. tableData[i].threeScore = croMapData[2];
  459. // let aaa = this.combineArrays(allScore);
  460. // console.log("tableData", tableData[i]);
  461. // console.log("allfType", allfType);
  462. for (var k = 0; k < allfType.length; k++) {
  463. for (var j = 0; j < json[allfType[k].id].length; j++) {
  464. for (
  465. var q = 0;
  466. q <
  467. json[allfType[k].id][j][json[allfType[k].id][j].id].length;
  468. q++
  469. ) {
  470. count +=
  471. json[allfType[k].id][j][json[allfType[k].id][j].id][q];
  472. }
  473. }
  474. }
  475. sum = parseFloat((count / (allsType.length * 3)).toFixed(1));
  476. tableData[i].sum = sum;
  477. } else {
  478. tableData[i].sum = 0;
  479. tableData[i].oneScore = 0;
  480. tableData[i].twoScore = 0;
  481. tableData[i].threeScore = 0;
  482. }
  483. }
  484. this.tableData = tableData;
  485. })
  486. .catch(err => {
  487. this.isLoading = false;
  488. console.error(err);
  489. });
  490. }
  491. },
  492. beforeRouteEnter(to, from, next) {
  493. next(vm => {
  494. // console.log("从哪进", to.query.fathType, from.path);
  495. vm.fathType = to.query.fathType * 1;
  496. });
  497. },
  498. created() {
  499. this.page = 1;
  500. this.getClass();
  501. this.getYear();
  502. }
  503. };
  504. </script>
  505. <style scoped>
  506. .pb_head {
  507. margin: 0 !important;
  508. width: 100% !important;
  509. padding: 10px 0 !important;
  510. }
  511. .top {
  512. display: flex;
  513. justify-content: space-between;
  514. }
  515. .bgColor {
  516. background: #2167bc;
  517. }
  518. .student_button {
  519. color: #fff;
  520. background: #2268bc;
  521. width: 60px;
  522. height: 30px;
  523. padding: 0 !important;
  524. font-size: 12px;
  525. line-height: 30px;
  526. }
  527. .student_head >>> .el-button--primary {
  528. background-color: #2268bc;
  529. }
  530. .student_head {
  531. margin-top: 10px;
  532. padding-bottom: 10px;
  533. display: flex;
  534. justify-content: space-between;
  535. }
  536. .head_left {
  537. display: flex;
  538. align-items: center;
  539. line-height: 40px;
  540. }
  541. .student_input >>> .el-input__inner {
  542. height: 30px;
  543. width: 190px;
  544. font-size: 13px;
  545. padding: 0 10px;
  546. }
  547. .student_input.el-input {
  548. width: auto;
  549. }
  550. .student_input {
  551. margin-right: 10px;
  552. }
  553. .student_input >>> .el-input__icon {
  554. line-height: unset;
  555. }
  556. .student_page {
  557. margin-top: 10px;
  558. float: right;
  559. }
  560. .el-table >>> .even_row {
  561. background-color: #f1f1f1;
  562. }
  563. .student_table >>> .el-table--border td {
  564. border-right: 0px !important;
  565. }
  566. .student_table >>> .el-table,
  567. .student_table >>> .el-table__body-wrapper {
  568. height: auto !important;
  569. }
  570. </style>