rt-sim-training-client/src/views/lesson/trainingRule/saveAs.vue

138 lines
4.1 KiB
Vue
Raw Normal View History

<template>
2019-10-29 13:15:57 +08:00
<el-dialog
v-dialogDrag
:title="title"
:visible.sync="dialogVisible"
width="25%"
:before-close="handleClose"
center
>
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<span slot="footer" class="dialog-footer">
<el-button v-loading="loading" type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
<el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { postOperateSaveAs } from '@/api/management/operation';
2019-10-30 18:07:09 +08:00
import { listPublishMap } from '@/api/jmap/map';
export default {
2019-10-29 13:15:57 +08:00
name: 'AddBatch',
data() {
return {
loading: false,
dialogVisible: false,
formModel: {
2019-10-31 17:45:15 +08:00
mapIdFrom: '',
mapIdTo: ''
2019-10-29 13:15:57 +08:00
},
2019-10-30 18:07:09 +08:00
mapIdList: []
2019-10-29 13:15:57 +08:00
};
},
computed: {
form() {
this.type === 'ADD';
const form = {
labelWidth: '120px',
items: [
{
2019-10-31 17:45:15 +08:00
prop: 'mapIdFrom',
2019-10-29 13:15:57 +08:00
label: this.$t('lesson.skinTypeFrom'),
type: 'select',
required: true,
2019-10-30 18:07:09 +08:00
options: this.mapIdList
2019-10-29 13:15:57 +08:00
},
{
2019-10-31 17:45:15 +08:00
prop: 'mapIdTo',
2019-10-29 13:15:57 +08:00
label: this.$t('lesson.skinTypeTo'),
type: 'select',
required: true,
2019-10-30 18:07:09 +08:00
options: this.mapIdList
2019-10-29 13:15:57 +08:00
}
]
};
return form;
},
rules() {
const crules = {
2019-10-31 17:45:15 +08:00
mapIdFrom: [
2019-10-29 13:15:57 +08:00
{
required: true,
message: this.$t('rules.inputSkinType'),
trigger: 'change'
}
],
2019-10-31 17:45:15 +08:00
mapIdTo: [
2019-10-29 13:15:57 +08:00
{
required: true,
message: this.$t('rules.inputSkinType'),
trigger: 'change'
}
]
};
return crules;
},
title() {
return this.$t('lesson.copyLesson');
}
},
mounted() {
this.init();
},
methods: {
init() {
2019-10-30 18:07:09 +08:00
// 获取已发布地图列表
this.mapIdList = [];
listPublishMap().then(response => {
this.mapIdList = response.data.map(item => {
2019-10-29 13:15:57 +08:00
const params = {};
params.label = item.name;
2019-10-30 18:07:09 +08:00
params.value = item.id;
2019-10-29 13:15:57 +08:00
return params;
});
});
},
show() {
this.dialogVisible = true;
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
2019-10-31 17:45:15 +08:00
if (this.formModel.mapIdFrom != this.formModel.mapIdTo) {
2019-10-29 13:15:57 +08:00
self.create();
} else {
this.$alert(this.$t('lesson.countSkinCode'), this.$t('global.tips'), {
confirmButtonText: this.$t('global.confirm'),
callback: () => {}
});
}
});
},
create() {
const self = this;
this.loading = true;
2019-10-31 17:45:15 +08:00
postOperateSaveAs(this.formModel.mapIdFrom, this.formModel.mapIdTo)
2019-10-29 13:15:57 +08:00
.then(response => {
self.loading = false;
self.$message.success(this.$t('lesson.batchCreateSuccess'));
self.handleClose();
self.$emit('reloadTable'); // 刷新列表
})
.catch(error => {
self.loading = false;
self.$message.error(
`${this.$('error.batchCreateFailed')}:${error.message}`
);
});
},
handleClose() {
this.$refs.dataform.resetForm();
this.dialogVisible = false;
}
}
};
</script>