|
@@ -12,7 +12,7 @@
|
|
|
</div>
|
|
|
|
|
|
<div class="part-box part-box-pad">
|
|
|
- <el-table :data="dataList" border>
|
|
|
+ <el-table :data="dataList" border :cell-style="cellStyleHandle">
|
|
|
<el-table-column label="课程名称" min-width="200" fixed="left">
|
|
|
<template slot-scope="scope">
|
|
|
{{ scope.row.courseName }}
|
|
@@ -42,8 +42,7 @@
|
|
|
step-strictly
|
|
|
:controls="false"
|
|
|
@change="
|
|
|
- (val) =>
|
|
|
- unitChange(scope.row[`${column.name}_${subr}`].id, val)
|
|
|
+ () => unitChange(scope.row, `${column.name}_${subr}`)
|
|
|
"
|
|
|
></el-input-number>
|
|
|
</template>
|
|
@@ -67,10 +66,7 @@
|
|
|
:step="0.01"
|
|
|
step-strictly
|
|
|
:controls="false"
|
|
|
- @change="
|
|
|
- (val) =>
|
|
|
- unitChange(scope.row[`${column.name}_null`].id, val)
|
|
|
- "
|
|
|
+ @change="() => unitChange(scope.row, `${column.name}_null`)"
|
|
|
></el-input-number>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
@@ -88,6 +84,7 @@ import {
|
|
|
professionalMatrixDownload,
|
|
|
} from "../../api";
|
|
|
import { downloadByApi } from "@/plugins/download";
|
|
|
+import { calcSum } from "@/plugins/utils";
|
|
|
|
|
|
export default {
|
|
|
name: "professional-matrix",
|
|
@@ -105,6 +102,7 @@ export default {
|
|
|
columns: [],
|
|
|
hasSubRequirements: false,
|
|
|
loading: false,
|
|
|
+ errorIndexs: [],
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
@@ -153,11 +151,71 @@ export default {
|
|
|
};
|
|
|
});
|
|
|
},
|
|
|
- async unitChange(id, val) {
|
|
|
- await professionalMatrixSave({
|
|
|
- id,
|
|
|
- content: val,
|
|
|
- });
|
|
|
+ updateErrorIndexs([rowIndex, columnIndex]) {
|
|
|
+ const pos = this.errorIndexs.findIndex((item) => item[1] === columnIndex);
|
|
|
+ if (pos !== -1) {
|
|
|
+ this.errorIndexs.splice(pos, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.errorIndexs.push([rowIndex, columnIndex]);
|
|
|
+ },
|
|
|
+ clearErrorIndexs(columnIndex) {
|
|
|
+ this.errorIndexs = this.errorIndexs.filter(
|
|
|
+ (item) => item[1] !== columnIndex
|
|
|
+ );
|
|
|
+ },
|
|
|
+ async unitChange(row, key) {
|
|
|
+ const fieldName = key.split("_")[0];
|
|
|
+ let columnIndex = this.columns.findIndex(
|
|
|
+ (item) => item.name === fieldName
|
|
|
+ );
|
|
|
+ columnIndex += 1;
|
|
|
+ const totalVal = calcSum(this.dataList.map((item) => item[key].value));
|
|
|
+ if (totalVal > 1) {
|
|
|
+ this.$message.error(`${fieldName}列总和大于1,当前修改值将不会保存!`);
|
|
|
+
|
|
|
+ const rowIndex = this.dataList.findIndex(
|
|
|
+ (item) => item.courseCode === row.courseCode
|
|
|
+ );
|
|
|
+
|
|
|
+ this.updateErrorIndexs([rowIndex, columnIndex]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let saveData = [];
|
|
|
+ const curColumnHasError = this.errorIndexs.some(
|
|
|
+ (item) => item[1] === columnIndex
|
|
|
+ );
|
|
|
+ if (curColumnHasError) {
|
|
|
+ saveData = this.dataList.map((item) => {
|
|
|
+ return {
|
|
|
+ id: item[key].id,
|
|
|
+ content: item[key].value,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ saveData = [
|
|
|
+ {
|
|
|
+ id: row[key].id,
|
|
|
+ content: row[key].value,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ this.clearErrorIndexs(columnIndex);
|
|
|
+ await professionalMatrixSave(saveData);
|
|
|
+ },
|
|
|
+ cellStyleHandle({ rowIndex, columnIndex }) {
|
|
|
+ if (!this.errorIndexs.length) return;
|
|
|
+ if (
|
|
|
+ this.errorIndexs.some(
|
|
|
+ (item) => rowIndex === item[0] && columnIndex === item[1]
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ backgroundColor: "#fde2e2",
|
|
|
+ };
|
|
|
+ }
|
|
|
},
|
|
|
async toDownload(row) {
|
|
|
if (this.loading) return;
|