From 202adad6c3d5fe1d95e745d47434dc29cc60d957 Mon Sep 17 00:00:00 2001 From: Riku <risaku@163.com> Date: 星期六, 28 九月 2024 20:41:11 +0800 Subject: [PATCH] Merge branch 'hc-evalution' into riku-evaluation --- src/views/fysp/evaluation/EvalutationEdit.vue | 256 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 244 insertions(+), 12 deletions(-) diff --git a/src/views/fysp/evaluation/EvalutationEdit.vue b/src/views/fysp/evaluation/EvalutationEdit.vue index 24f1a0a..f45dabf 100644 --- a/src/views/fysp/evaluation/EvalutationEdit.vue +++ b/src/views/fysp/evaluation/EvalutationEdit.vue @@ -1,14 +1,44 @@ <template> <FYPageHeader title="璇勪及缁撴灉璇︽儏"></FYPageHeader> - <el-row v-for="item in evaluation" :key="item.id"> - - </el-row> + <el-row v-for="item in evaluation" :key="item.id"> </el-row> + <div class="btns"> + <el-button type="primary" @click="submit" :disabled="!isUpdated">鎻愪氦</el-button> + </div> + <el-table + class="table-style" + :data="tableData" + ref="tableRef" + :span-method="objectSpanMethod" + table-layout="fixed" + :cell-style="cellClassName" + border + stripe + > + <el-table-column v-slot="scope" prop="one_title" label="涓�绾ф寚鏍�" width="200"> + <!-- <el-checkbox v-model="scope.row.one_select" @change="checked => oneSelectChange(checked, scope.row)">{{ scope.row.one_title }}</el-checkbox> --> + </el-table-column> + <el-table-column prop="one_score" label="鍒嗗��" width="55" /> + <el-table-column prop="one_maxScore" label="鏈�澶у垎鍊�" width="90" /> + <el-table-column v-slot="scope" prop="two_title" label="浜岀骇鎸囨爣" width="200"> + <!-- <el-checkbox v-model="scope.row.two_select" @change="checked => twoSelectChange(checked, scope.row)">{{ scope.row.two_title }}</el-checkbox> --> + </el-table-column> + <el-table-column prop="two_score" label="鍒嗗��" width="55" /> + <el-table-column prop="two_maxScore" label="鏈�澶у垎鍊�" width="90" /> + <el-table-column v-slot="scope" prop="three_title" label="鍏蜂綋闂"> + <el-checkbox + v-model="scope.row.three_select" + @change="(checked) => threeSelectChange(checked, scope.row)" + >{{ scope.row.three_title }}</el-checkbox + > + </el-table-column> + <el-table-column prop="three_score" label="鍗曢」鎵e垎" width="90" /> + </el-table> </template> <script> import evaluateApi from '@/api/fysp/evaluateApi'; import { useFetchData } from '@/composables/fetchData'; - +import { ElMessage } from 'element-plus'; export default { setup() { const { loading, fetchData } = useFetchData(); @@ -16,7 +46,10 @@ }, data() { return { - evaluation: [] + tableData: [], + evaluation: [], + subTaskId: '', + isUpdated: false }; }, created() { @@ -30,18 +63,217 @@ // // 姝ゆ椂 data 宸茬粡琚� observed 浜� // { immediate: true } // ); - this.getScore(); + }, + computed: { + // 宸茶鍕鹃�夌殑item + checkedUpdatedList() { + var list = []; + for (let index = 0; index < this.tableData.length; index++) { + const element = this.tableData[index]; + if (element.three_select) { + list.push(element.three_id); + } + } + return list; + } + }, + mounted() { + this.getList(); }, methods: { - // 鑾峰彇璇勫垎 - getScore() { - this.fetchData(() => { - return evaluateApi.fetchItemEvaluation(this.$route.params.subTaskId).then((res) => { - this.evaluation = res; + // 姣忎竴涓崟鍏冩牸鐨刢lass + cellClassName({ row, column, rowIndex, columnIndex }) { + if (column.property === 'one_score') { + if (row.one_score < 0) { + return { color: 'red' }; + } + } else if (column.property === 'two_score') { + if (row.two_score < 0) { + return { color: 'red' }; + } + } else if (column.property === 'three_score') { + if (row.three_score < 0) { + return { color: 'red' }; + } + } + return { color: 'black' }; + }, + /** 鎻愪环 */ + submit() { + evaluateApi + .updateScore({ + subTaskId: this.subTaskId, + itemList: this.checkedUpdatedList + }) + .then((res) => { + if (res.success) { + ElMessage({ + message: res.message, + type: 'success' + }); + }else { + ElMessage({ + message: res.message, + type: 'error' + }); + } }); + setTimeout(() => { + this.getList(); + }, 1000); + }, + /** 閫氳繃绗笁绾х殑id鑾峰彇涓婄骇浠ュ強椤剁骇 */ + getSuperObjByThreeId(threeId, list, path = []) { + for (let index = 0; index < list.length; index++) { + const item = list[index]; + // 灏嗗綋鍓嶉」娣诲姞鍒拌矾寰勪腑 + const currentPath = path.concat(item); + if (item.id === threeId) { + // 濡傛灉鎵惧埌鍖归厤鐨� id锛岃繑鍥炶矾寰勬暟缁� + return currentPath; + } + const subList = item.subList; + if (subList) { + // 閫掑綊鏌ユ壘瀛愬垪琛� + const result = this.getSuperObjByThreeId(threeId, subList, currentPath); + if (result) { + return result; // 濡傛灉鎵惧埌鍖归厤鐨� id锛岃繑鍥炵粨鏋� + } + } + } + return null; // 濡傛灉娌℃湁鎵惧埌鍖归厤鐨� id锛岃繑鍥� null + }, + /** 闂閫夋嫨妗� */ + threeSelectChange(isSelect, row) { + this.isUpdated = true; + }, + /** 鍒楀悎骞� */ + objectSpanMethod({ row, column, rowIndex, columnIndex }) { + if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2) { + // 瀵� 涓�绾ф寚鏍� 鍒楄繘琛屽悎骞� + let rowSpan = 1; + for (let i = rowIndex + 1; i < this.tableData.length; i++) { + if (this.tableData[i].one_id === row.one_id) { + rowSpan++; + } else { + break; + } + } + if (rowIndex > 0) { + if (this.tableData[rowIndex - 1].one_id === row.one_id) { + return { rowspan: 0, colspan: 0 }; + } + } + return { rowspan: rowSpan, colspan: 1 }; + } else if (columnIndex === 3 || columnIndex === 4 || columnIndex === 5) { + // 瀵� 浜岀骇鎸囨爣 鍒楄繘琛屽悎骞讹紝纭繚 涓�绾ф寚鏍� 涓�鏍� + let rowSpan = 1; + for (let i = rowIndex + 1; i < this.tableData.length; i++) { + if (this.tableData[i].one_id === row.one_id && this.tableData[i].two_id === row.two_id) { + rowSpan++; + } else { + break; + } + } + if (rowIndex > 0) { + if ( + this.tableData[rowIndex - 1].one_id === row.one_id && + this.tableData[rowIndex - 1].two_id === row.two_id + ) { + return { rowspan: 0, colspan: 0 }; + } + } + return { rowspan: rowSpan, colspan: 1 }; + } + }, + /** 瀵硅薄灞炴�ф嫹璐� */ + deepCopyWithPrefix(obj, target, prefix) { + // 纭繚 target 鏄竴涓璞� + if (typeof target !== 'object' || target === null) { + target = {}; + } + + // 閬嶅巻瀵硅薄鐨勬墍鏈夊睘鎬� + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + // 涓哄睘鎬у悕鍔犱笂鍓嶇紑 + const newKey = prefix + key; + // 濡傛灉灞炴�у�兼槸瀵硅薄锛屽垯閫掑綊澶嶅埗 + if (typeof obj[key] === 'object' && obj[key] !== null) { + this.deepCopyWithPrefix(obj[key], (target[newKey] = {}), prefix); + } else { + // 鍚﹀垯鐩存帴澶嶅埗灞炴�� + target[newKey] = obj[key]; + } + } + } + + return target; + }, + /** @param data 鍒楄〃鏁版嵁 */ + genTableData(data) { + var result = []; + if (data) { + for (let i = 0; i < data.length; i++) { + const firstLevelItem = data[i]; + var secondLevel = firstLevelItem.subList; + if (secondLevel) { + for (let j = 0; j < secondLevel.length; j++) { + const secondLevelItem = secondLevel[j]; + var thirdLevel = secondLevelItem.subList; + if (thirdLevel) { + for (let q = 0; q < thirdLevel.length; q++) { + const thirdLevelItem = thirdLevel[q]; + var item = {}; + this.deepCopyWithPrefix(firstLevelItem, item, 'one_'); + this.deepCopyWithPrefix(secondLevelItem, item, 'two_'); + this.deepCopyWithPrefix(thirdLevelItem, item, 'three_'); + result.push(item); + } + } + } + } + } + } + return result; + }, + getList() { + this.subTaskId = this.$route.params.subTaskId; + evaluateApi.fetchItemEvaluation(this.subTaskId).then((res) => { + this.isUpdated = false; + this.tableData = this.genTableData(res.data.details); + }); + }, + onSearch(page, func) { + evaluateApi.fetchItemEvaluation(this.$route.params.subTaskId).then((res) => { + if (typeof func === 'function') { + // 澶勭悊鏁版嵁 + var data = this.genTableData(res.data); + + func({ data: data }); + } + this.tableData = this.genTableData(res.data); }); } } }; </script> -<style scoped></style> +<style scoped> +.table-style { + width: 100%; + padding-bottom: 30px; +} +.btns { + padding-bottom: 10px; + padding-right: 30px; + display: flex; + flex-direction: row-reverse; +} +/* 鏀瑰彉琛ㄦ牸鍐呭崟鍏冩牸杈规棰滆壊 */ +.el-table { + --el-table-border-color: #000000; +} +.red-cell { + background-color: red; +} +</style> -- Gitblit v1.9.3