rt-sim-training-client/src/views/trainingManage/gradeRules.vue

193 lines
7.3 KiB
Vue
Raw Normal View History

2022-08-30 15:43:21 +08:00
<template>
<el-dialog :title="title" :visible.sync="dialogVisible" width="800px" :modal="false" :before-close="doClose" center>
<!-- -->
<!-- <span>角色</span> -->
<el-form ref="form" :model="addModel" label-width="70px" :rules="rules">
<el-form-item label="角色:" prop="memberId" style="display:inline-block">
<el-select v-model="addModel.memberId" placeholder="" style="width:145px" size="mini" @change="changeMember">
<el-option
v-for="item in memberList"
2022-08-30 16:53:37 +08:00
:key="item.id"
:label="item.normalName"
:value="item.id"
2022-08-30 15:43:21 +08:00
/>
</el-select>
</el-form-item>
<el-form-item label="总分:" prop="fullMarks" style="display:inline-block">
<el-input-number v-model="addModel.fullMarks" style="width:145px" :min="0" size="mini" :step="1" />
</el-form-item>
</el-form>
<!-- <span style="margin-left:10px">总分</span> -->
<!-- </el-form-item> -->
<el-table
id="gradeRules"
ref="gradeRules"
:data="allstepList"
border
:height="350"
style="border:1px #ccc solid;"
>
<el-table-column
type="index"
label="序号"
width="80"
/>
<el-table-column
prop="description"
label="步骤描述"
width="468"
/>
<el-table-column
prop="score"
label="扣分分值"
width="200"
>
<template v-if="addModel.memberId==scope.row.memberId" slot-scope="scope">
<el-input-number v-model="currentStepMap[scope.row.id]" style="width:145px" :min="0" :step="1" size="mini" />
</template>
</el-table-column>
</el-table>
<el-row justify="center" style="margin-top:20px">
<el-col :span="6" :offset="7">
<el-button @click="cancel">取消</el-button>
</el-col>
<el-col :span="8" :offset="0">
<el-button type="primary" :loading="loading" @click="commit">确定 </el-button>
</el-col>
</el-row>
</el-dialog>
</template>
<script>
2022-08-30 16:53:37 +08:00
import {covertMemberData} from '@/views/newMap/displayNew/utils';
2022-08-30 15:43:21 +08:00
import { getTrainingStepList, getTrainingMmembers, updateTrainingGradeRules, getTrainingGradeRules } from '@/api/trainingManage';
export default {
name: 'GradeRules',
props: {},
data() {
return {
dialogVisible: false,
trainingId:'',
loading:false,
title:'评分',
allstepList:[],
2022-08-30 16:53:37 +08:00
memberList:[],
2022-08-30 15:43:21 +08:00
currentStepMap:{},
gradeRulesMap:{},
addModel:{
memberId:'',
fullMarks:'',
details:[
]
},
rules:{
memberId: [
{ required: true, message: '请选择角色', trigger: 'blur' },
{ required: true, message: '请选择角色', trigger: 'change' }
],
fullMarks: [
{ required: true, message: '请输入总分', trigger: 'blur' },
{ required: true, message: '请输入总分', trigger: 'change' }
]
}
};
},
methods:{
doShow(row) {
this.dialogVisible = true;
this.trainingId = row.id;
// 获取步骤
getTrainingStepList(row.id).then(resp => {
if (resp.data) {
this.allstepList = resp.data;
// 获取规则
getTrainingGradeRules(row.id).then(response=>{
this.gradeRulesMap = {};
response.data.forEach(gradeRule=>{
this.gradeRulesMap[gradeRule.memberId] = gradeRule;
});
// 获取角色信息
getTrainingMmembers(row.id).then(res=>{
2022-08-30 16:53:37 +08:00
let activeTrainList = [];
if (this.$store.state.training.started) {
activeTrainList = this.$store.state.map.activeTrainList;
}
// 获取仿真成员列表
const result = covertMemberData(activeTrainList, res.data);
let list = [];
result.deviceListData.forEach(item => {
list = list.concat(item);
});
this.memberList = list;
2022-08-30 15:43:21 +08:00
if (this.memberList.length > 0) {
2022-08-30 16:53:37 +08:00
this.changeMember(this.memberList[0].id);
2022-08-30 15:43:21 +08:00
}
//
}).catch((e) => {
console.error(e);
});
});
}
}).catch((e) => {
console.error(e);
this.$message.error('获取实训步骤信息失败!');
});
},
changeMember(memberId) {
this.currentStepMap = {};
if (this.gradeRulesMap[memberId]) {
this.addModel.fullMarks = this.gradeRulesMap[memberId].fullMarks;
this.gradeRulesMap[memberId].details.forEach(each=>{
this.currentStepMap[each.elementId] = each.score;
});
} else {
this.allstepList.forEach(each=>{
if (each.memberId == memberId) {
this.currentStepMap[each.id] = 0;
}
});
this.addModel.fullMarks = '';
}
2022-08-30 16:53:37 +08:00
debugger;
2022-08-30 15:43:21 +08:00
this.addModel.memberId = memberId;
},
doClose() {
this.dialogVisible = false;
},
cancel() {
this.doClose();
},
commit() {
this.$refs.form.validate((valid) => {
if (valid) {
this.loading = true;
const keyList = Object.keys(this.currentStepMap);
const details = [];
keyList.forEach(key=>{
details.push({elementId:key, score:this.currentStepMap[key]});
});
this.addModel.details = details;
2022-08-30 16:53:37 +08:00
const gradeRulesList = Object.values(this.gradeRulesMap);
gradeRulesList.forEach(gradeRule=>{
if (gradeRule.memberId == this.addModel.memberId) {
gradeRule = this.addModel;
}
});
if (!this.gradeRulesMap[this.addModel.memberId] && this.addModel.details.length > 0) {
gradeRulesList.push(this.addModel);
}
updateTrainingGradeRules(this.trainingId, gradeRulesList).then(resp => {
this.loading = false;
this.$message.success('更新实训评分规则成功!');
this.gradeRulesMap[this.addModel.memberId] = this.addModel;
2022-08-30 15:43:21 +08:00
}).catch((e) => {
2022-08-30 16:53:37 +08:00
this.loading = false;
2022-08-30 15:43:21 +08:00
console.error(e);
this.$message.error('更新实训评分规则失败!');
});
}
});
}
}
};
</script>