rt-sim-training-client/src/views/scriptManage/create.vue

187 lines
6.7 KiB
Vue
Raw Normal View History

2019-09-26 10:54:07 +08:00
<template>
2019-11-01 15:19:15 +08:00
<el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :before-close="doClose" center>
<data-form v-if="isCreate" ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<data-form v-else ref="dataform" :form="updateForm" :form-model="updateFormModel" :rules="updateRules" />
2019-11-01 15:19:15 +08:00
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="doCreate">{{ $t('global.confirm') }}</el-button>
<el-button @click="doClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
2019-09-26 10:54:07 +08:00
</template>
<script>
2020-04-21 10:07:26 +08:00
import { getScriptByIdBasic} from '@/api/script';
2019-11-01 15:19:15 +08:00
export default {
name: 'ScriptDraft',
props: {
title: {
type: String,
default() {
return '';
}
}
},
data() {
return {
dialogVisible: false,
isCreate:true,
2019-11-01 15:19:15 +08:00
formModel: {
name: '',
mapId: '',
description:''
},
updateFormModel:{
name: '',
mapId: '',
description:'',
fullMarksDuration:0,
passingGradeDuration:0,
zeroDuration:0
2019-09-26 10:54:07 +08:00
}
// updateForm
//
2019-11-01 15:19:15 +08:00
};
},
computed: {
form() {
const form = {
labelWidth: '150px',
items: [
2019-11-18 12:28:08 +08:00
{ prop: 'name', label: this.$t('scriptRecord.scriptName'), type: 'text' },
{ prop: 'description', label: this.$t('scriptRecord.scriptDescription'), type: 'textarea' }
]
};
return form;
},
updateForm() {
const form = {
labelWidth: '150px',
items: [
{ prop: 'name', label: this.$t('scriptRecord.scriptName'), type: 'text' },
{ prop: 'description', label: this.$t('scriptRecord.scriptDescription'), type: 'textarea' },
{ prop: 'fullMarksDuration', label: '满分时长', type: 'number', min:0, step:1, message:'秒' },
{ prop: 'passingGradeDuration', label: '及格时长', type: 'number', min:0, step:1, message:'秒' },
{ prop: 'zeroDuration', label: '零分时长', type: 'number', min:0, step:1, message:'秒' }
2019-11-01 15:19:15 +08:00
]
};
return form;
2019-09-26 10:54:07 +08:00
},
2019-11-01 15:19:15 +08:00
rules() {
const crules = {
name: [
{ required: true, validator: this.validateScriptName, trigger: 'blur' }
2019-11-19 15:34:45 +08:00
],
description: [
{ required: true, validator: this.validateDescription, trigger: 'blur' }
2019-11-01 15:19:15 +08:00
]
};
return crules;
},
updateRules() {
const crules = {
name: [
{ required: true, validator: this.validateScriptName, trigger: 'blur' }
],
description: [
{ required: true, validator: this.validateDescription, trigger: 'blur' }
],
fullMarksDuration: [
{ required: true, validator: this.validateDuration, trigger: 'blur' }
],
passingGradeDuration: [
{ required: true, validator: this.validateDuration, trigger: 'blur' }
],
zeroDuration: [
{ required: true, validator: this.validateDuration, trigger: 'blur' }
]
};
return crules;
2019-11-01 15:19:15 +08:00
}
},
methods: {
2019-11-18 12:28:08 +08:00
validateScriptName(rule, value, callback) {
if (value.trim().length == 0) {
2019-11-18 12:28:08 +08:00
this.formModel.name = this.formModel.name.replace(/\s/g, '');
this.updateFormModel.name = this.formModel.name.replace(/\s/g, '');
2019-11-18 12:28:08 +08:00
return callback(new Error(this.$t('scriptRecord.inputScriptName')));
} else {
return callback();
}
},
2019-11-19 15:34:45 +08:00
validateDescription(rule, value, callback) {
if (value.trim().length == 0) {
2019-11-28 11:27:37 +08:00
this.formModel.description = this.formModel.description.replace(/\s/g, '');
this.updateFormModel.description = this.formModel.name.replace(/\s/g, '');
2019-11-19 15:34:45 +08:00
return callback(new Error(this.$t('scriptRecord.inputScriptDescription')));
} else {
return callback();
}
},
validateDuration(rule, value, callback) {
if (!value) {
return callback(new Error('时长不能为空'));
}
switch (rule.field) {
case 'fullMarksDuration': {
this.updateFormModel.fullMarksDuration = parseInt(value);
break;
}
case 'passingGradeDuration': {
this.updateFormModel.passingGradeDuration = parseInt(value);
break;
}
case 'zeroDuration': {
this.updateFormModel.zeroDuration = parseInt(value);
break;
}
}
return callback();
},
2019-11-01 15:19:15 +08:00
doShow(questid) {
if (questid) {
2020-04-21 10:07:26 +08:00
getScriptByIdBasic(questid).then(resp=>{
this.isCreate = false;
const data = {
'name':resp.data.name,
'description':resp.data.description,
'mapId':resp.data.mapId,
'fullMarksDuration':resp.data.fullMarksDuration || 0,
'passingGradeDuration':resp.data.passingGradeDuration || 0,
'zeroDuration':resp.data.zeroDuration || 0
};
this.updateFormModel = data;
this.updateFormModel.id = questid;
2019-11-01 15:19:15 +08:00
this.dialogVisible = true;
});
} else {
this.isCreate = true;
2019-11-01 15:19:15 +08:00
this.formModel.mapId = this.$route.params.mapId;
this.dialogVisible = true;
}
2019-09-26 10:54:07 +08:00
},
2019-11-01 15:19:15 +08:00
doCreate() {
const self = this;
this.$refs.dataform.validateForm(() => {
if (this.isCreate) {
self.$emit('create', Object.assign({}, this.formModel));
} else {
self.$emit('create', Object.assign({}, this.updateFormModel));
}
2019-11-01 15:19:15 +08:00
self.doClose();
});
2019-09-26 10:54:07 +08:00
},
2019-11-01 15:19:15 +08:00
doClose() {
this.$refs.dataform.resetForm();
this.dialogVisible = false;
2019-09-26 10:54:07 +08:00
}
}
2019-11-01 15:19:15 +08:00
};
2019-09-26 13:21:15 +08:00
</script>
<style lang="scss" scoped>
/deep/ .el-dialog--center .el-dialog__body{
padding: 25px 65px 30px 10px;
}
2019-11-01 15:19:15 +08:00
</style>