|
@@ -43,7 +43,7 @@
|
|
|
<el-button
|
|
|
class="btn-primary"
|
|
|
type="text"
|
|
|
- :disabled="loading || scope.row.isFirstSec"
|
|
|
+ :disabled="loading || scope.row.secondInd === 1"
|
|
|
@click="toUp(scope)"
|
|
|
>上移</el-button
|
|
|
>
|
|
@@ -74,38 +74,24 @@
|
|
|
<modify-knowledge-dim
|
|
|
ref="ModifyKnowledgeDim"
|
|
|
:instance="curRow"
|
|
|
- :dict-data="dataDict"
|
|
|
@modified="modified"
|
|
|
></modify-knowledge-dim>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { mapState, mapActions, mapMutations } from "vuex";
|
|
|
import ImportFile from "@/components/ImportFile";
|
|
|
import ModifyKnowledgeDim from "./ModifyKnowledgeDim.vue";
|
|
|
-import { paperDimensionExport, paperDimensionList } from "../../api";
|
|
|
+import { paperDimensionExport } from "../../api";
|
|
|
+import { downloadByApi } from "@/plugins/download";
|
|
|
|
|
|
export default {
|
|
|
name: "dimension-knowledge-list",
|
|
|
components: { ImportFile, ModifyKnowledgeDim },
|
|
|
- props: {
|
|
|
- course: {
|
|
|
- type: Object,
|
|
|
- default() {
|
|
|
- return {};
|
|
|
- }
|
|
|
- },
|
|
|
- datas: {
|
|
|
- type: Array,
|
|
|
- default() {
|
|
|
- return [];
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
data() {
|
|
|
return {
|
|
|
dataList: [],
|
|
|
- dataDict: [],
|
|
|
curRow: {},
|
|
|
loading: false,
|
|
|
// upload
|
|
@@ -114,40 +100,34 @@ export default {
|
|
|
downloading: false
|
|
|
};
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ ...mapState("baseConfigs", ["dimensionList", "baseInfo"])
|
|
|
+ },
|
|
|
mounted() {
|
|
|
this.initData();
|
|
|
},
|
|
|
methods: {
|
|
|
+ ...mapMutations("baseConfigs", ["setDimensionList"]),
|
|
|
+ ...mapActions("baseConfigs", ["fetchDimensionList"]),
|
|
|
initData() {
|
|
|
- this.dataList = this.datas.map(item => {
|
|
|
- return { ...item };
|
|
|
- });
|
|
|
+ this.dataList = this.dimensionList
|
|
|
+ .filter(item => item.dimensionType === "KNOWLEDGE")
|
|
|
+ .map(item => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ secondInd: item.codeSecond.substring(1) * 1,
|
|
|
+ isLastSec: false,
|
|
|
+ id: this.$randomCode()
|
|
|
+ };
|
|
|
+ });
|
|
|
this.sortDataList();
|
|
|
- this.getDict();
|
|
|
this.uploadData = {
|
|
|
- paperNumber: this.course.paperNumber,
|
|
|
- paperType: this.course.paperType,
|
|
|
- paperName: this.course.paperName,
|
|
|
+ paperNumber: this.baseInfo.paperNumber,
|
|
|
+ paperType: this.baseInfo.paperType,
|
|
|
+ paperName: this.baseInfo.paperName,
|
|
|
dimensionType: "KNOWLEDGE"
|
|
|
};
|
|
|
},
|
|
|
- getDict() {
|
|
|
- let dataDict = {};
|
|
|
- this.dataList.forEach(item => {
|
|
|
- if (!dataDict[item.codePrimary]) {
|
|
|
- dataDict[item.codePrimary] = {
|
|
|
- name: item.namePrimary,
|
|
|
- code: item.codePrimary,
|
|
|
- children: []
|
|
|
- };
|
|
|
- }
|
|
|
- dataDict[item.codePrimary].children.push({
|
|
|
- name: item.nameSecond,
|
|
|
- code: item.codeSecond
|
|
|
- });
|
|
|
- });
|
|
|
- this.dataDict = Object.values(dataDict);
|
|
|
- },
|
|
|
toImport() {
|
|
|
this.$refs.ImportFile.open();
|
|
|
},
|
|
@@ -157,8 +137,8 @@ export default {
|
|
|
|
|
|
const res = await downloadByApi(() => {
|
|
|
return paperDimensionExport({
|
|
|
- courseCode: this.course.courseCode,
|
|
|
- courseName: this.course.courseName,
|
|
|
+ courseCode: this.baseInfo.courseCode,
|
|
|
+ courseName: this.baseInfo.courseName,
|
|
|
dimensionType: "KNOWLEDGE"
|
|
|
});
|
|
|
}).catch(e => {
|
|
@@ -171,43 +151,39 @@ export default {
|
|
|
},
|
|
|
async fileUploaded() {
|
|
|
this.$message.success("导入成功!");
|
|
|
- const data = await paperDimensionList({
|
|
|
- paperNumber: this.course.paperNumber,
|
|
|
- paperType: this.course.paperType
|
|
|
- });
|
|
|
- this.dataList = data
|
|
|
- .filter(item => item.dimensionType === "KNOWLEDGE")
|
|
|
- .map(item => {
|
|
|
- return { ...item, id: this.$randomCode() };
|
|
|
- });
|
|
|
- this.sortDataList();
|
|
|
- this.emitChange();
|
|
|
+ await this.fetchDimensionList();
|
|
|
+ this.initData();
|
|
|
},
|
|
|
modified(data) {
|
|
|
if (data.id) {
|
|
|
const pos = this.dataList.findIndex(item => item.id === data.id);
|
|
|
this.dataList.splice(pos, 1, data);
|
|
|
} else {
|
|
|
- this.dataList.push(data);
|
|
|
- this.sortDataList();
|
|
|
+ this.dataList.push({
|
|
|
+ ...data,
|
|
|
+ id: this.$randomCode()
|
|
|
+ });
|
|
|
}
|
|
|
- this.emitChange();
|
|
|
+ this.sortDataList();
|
|
|
+ this.updateChange();
|
|
|
},
|
|
|
sortDataList() {
|
|
|
+ if (!this.dataList.length) return;
|
|
|
this.dataList.sort((a, b) => {
|
|
|
if (a.codePrimary < b.codePrimary) return -1;
|
|
|
if (a.codePrimary > b.codePrimary) return 1;
|
|
|
|
|
|
- const anoSecond = a.codeSecond.substring(1) * 1;
|
|
|
- const bnoSecond = b.codeSecond.substring(1) * 1;
|
|
|
-
|
|
|
- return anoSecond < bnoSecond ? -1 : 1;
|
|
|
+ return a.secondInd < b.secondInd ? -1 : 1;
|
|
|
+ });
|
|
|
+ this.dataList.forEach((item, index) => {
|
|
|
+ const nextItem = this.dataList[index + 1];
|
|
|
+ item.isLastSec = nextItem && nextItem.codePrimary !== item.codePrimary;
|
|
|
});
|
|
|
},
|
|
|
toAdd() {
|
|
|
this.curRow = {
|
|
|
- courseCode: this.course.courseCode,
|
|
|
- courseName: this.course.courseName
|
|
|
+ courseCode: this.baseInfo.courseCode,
|
|
|
+ courseName: this.baseInfo.courseName
|
|
|
};
|
|
|
this.$refs.ModifyKnowledgeDim.open();
|
|
|
},
|
|
@@ -217,7 +193,7 @@ export default {
|
|
|
},
|
|
|
toDelete({ $index }) {
|
|
|
this.dataList.splice($index, 1);
|
|
|
- this.emitChange();
|
|
|
+ this.updateChange();
|
|
|
},
|
|
|
toUp({ row, $index }) {
|
|
|
const pos = $index;
|
|
@@ -229,7 +205,7 @@ export default {
|
|
|
this.dataList[pos - 1].codeSecond = `${rowFirstCode}${rowSecondInd - 1}`;
|
|
|
this.dataList[pos].secondInd = rowSecondInd;
|
|
|
this.dataList[pos].codeSecond = `${rowFirstCode}${rowSecondInd}`;
|
|
|
- this.emitChange();
|
|
|
+ this.updateChange();
|
|
|
},
|
|
|
toDown({ row, $index }) {
|
|
|
const pos = $index;
|
|
@@ -241,10 +217,13 @@ export default {
|
|
|
this.dataList[pos + 1].codeSecond = `${rowFirstCode}${rowSecondInd + 1}`;
|
|
|
this.dataList[pos].secondInd = rowSecondInd;
|
|
|
this.dataList[pos].codeSecond = `${rowFirstCode}${rowSecondInd}`;
|
|
|
- this.emitChange();
|
|
|
+ this.updateChange();
|
|
|
},
|
|
|
- emitChange() {
|
|
|
- this.$emit("data-change", this.dataList);
|
|
|
+ updateChange() {
|
|
|
+ const knowledgeList = this.dimensionList.filter(
|
|
|
+ item => item.dimensionType === "KNOWLEDGE"
|
|
|
+ );
|
|
|
+ this.setDimensionList([...knowledgeList, ...this.dataList]);
|
|
|
}
|
|
|
}
|
|
|
};
|