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 ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
|
|
|
|
<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>
|
2019-11-01 15:19:15 +08:00
|
|
|
import { getQuestById} from '@/api/quest';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ScriptDraft',
|
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
default() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dialogVisible: false,
|
|
|
|
mapList: [],
|
|
|
|
taskStatusList: [],
|
|
|
|
formModel: {
|
|
|
|
name: '',
|
|
|
|
mapId: '',
|
|
|
|
description:''
|
2019-09-26 10:54:07 +08:00
|
|
|
}
|
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' }
|
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: [
|
2019-11-18 12:28:08 +08:00
|
|
|
{ validator: this.validateScriptName, trigger: 'blur' },
|
|
|
|
{ validator: this.validateScriptName, trigger: 'change' }
|
2019-11-19 15:34:45 +08:00
|
|
|
],
|
|
|
|
description: [
|
|
|
|
{ validator: this.validateDescription, trigger: 'blur' },
|
|
|
|
{ validator: this.validateDescription, trigger: 'change' }
|
2019-11-01 15:19:15 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
return crules;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2019-11-18 12:28:08 +08:00
|
|
|
validateScriptName(rule, value, callback) {
|
|
|
|
if (value.trim().length === 0) {
|
|
|
|
this.formModel.name = this.formModel.name.replace(/\s/g, '');
|
|
|
|
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) {
|
|
|
|
this.formModel.description = this.formModel.name.replace(/\s/g, '');
|
|
|
|
return callback(new Error(this.$t('scriptRecord.inputScriptDescription')));
|
|
|
|
} else {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
},
|
2019-11-01 15:19:15 +08:00
|
|
|
doShow(questid) {
|
|
|
|
if (questid) {
|
|
|
|
getQuestById(questid).then(resp=>{
|
|
|
|
const data = {'name':resp.data.name, 'description':resp.data.description, 'mapId':resp.data.mapId};
|
|
|
|
this.formModel = data;
|
|
|
|
this.formModel.id = questid;
|
|
|
|
this.dialogVisible = true;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
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(() => {
|
|
|
|
self.$emit('create', Object.assign({}, this.formModel));
|
|
|
|
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>
|