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

116 lines
2.9 KiB
Vue
Raw Normal View History

2019-07-26 13:32:43 +08:00
<template>
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="25%" :before-close="handleClose" center>
2019-08-08 15:57:36 +08:00
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<span slot="footer" class="dialog-footer">
2019-08-29 17:16:33 +08:00
<el-button v-loading="loading" type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
<el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
2019-08-08 15:57:36 +08:00
</span>
</el-dialog>
2019-07-26 13:32:43 +08:00
</template>
<script>
2019-08-08 15:57:36 +08:00
import { addTrainingRulesList } from '@/api/management/operation';
import { OperationList } from '@/scripts/OperationConfig';
2019-08-29 17:16:33 +08:00
import { getSkinCodeList } from '@/api/management/mapskin';
2019-07-26 13:32:43 +08:00
2019-08-08 15:57:36 +08:00
export default {
name: 'AddBatch',
data() {
return {
loading: false,
dialogVisible: false,
formModel: {
2019-10-10 09:33:56 +08:00
skinCode: this.$route.query.skinCode
2019-08-08 15:57:36 +08:00
},
2019-08-29 17:16:33 +08:00
skinCodeList: [],
2019-08-08 15:57:36 +08:00
isShow: false
};
},
computed: {
form() {
this.type === 'ADD';
const form = {
labelWidth: '120px',
items: [
2019-10-10 09:33:56 +08:00
{ prop: 'skinCode', label: this.$t('lesson.skinType'), type: 'select', required: true, options: this.skinCodeList, disabled: true }
2019-08-08 15:57:36 +08:00
]
};
return form;
},
rules() {
const crules = {
2019-08-29 17:16:33 +08:00
skinCode: [
{ required: true, message: this.$t('rules.inputSkinType'), trigger: 'change' }
2019-08-08 15:57:36 +08:00
]
};
return crules;
},
title() {
2019-08-29 17:16:33 +08:00
return this.$t('lesson.generationOperation');
2019-08-08 15:57:36 +08:00
}
},
mounted() {
this.init();
},
methods: {
init() {
// 获取皮肤列表
2019-08-29 17:16:33 +08:00
this.skinCodeList = [];
getSkinCodeList().then(response => {
this.skinCodeList = response.data.map(item => {
2019-08-08 15:57:36 +08:00
const params = {};
params.label = item.name;
params.value = item.code;
return params;
});
});
},
show(total) {
if (total) {
this.isShow = true;
}
2019-07-26 13:32:43 +08:00
2019-08-08 15:57:36 +08:00
this.loading = false;
this.dialogVisible = true;
},
doSave() {
const self = this;
this.$refs.dataform.validateForm(() => {
if (this.isShow) {
this.$confirm(this.$t('lesson.wellClearOperate'), this.$t('global.tips'), {
2019-08-29 17:16:33 +08:00
confirmButtonText: this.$t('global.confirm'),
cancelButtonText: this.$t('global.cancel'),
2019-08-08 15:57:36 +08:00
type: 'warning'
}).then(() => {
self.create();
}).catch(() => { });
} else {
self.create();
}
});
},
create() {
const self = this;
this.loading = true;
2019-08-29 17:16:33 +08:00
addTrainingRulesList(this.formModel.skinCode, OperationList[this.formModel.skinCode].list).then(response => {
2019-08-08 15:57:36 +08:00
self.loading = false;
2019-08-29 17:16:33 +08:00
self.$message.success(this.$t('lesson.batchCreateSuccess'));
2019-08-08 15:57:36 +08:00
self.handleClose();
self.$emit('reloadTable'); // 刷新列表
}).catch(error => {
self.loading = false;
2019-08-29 17:16:33 +08:00
self.$message.error(`${this.$('error.batchCreateFailed')}:${error.message}`);
2019-08-08 15:57:36 +08:00
});
},
handleClose() {
this.formModel = {
2019-10-10 09:33:56 +08:00
skinCode: this.$route.query.skinCode
2019-08-08 15:57:36 +08:00
};
this.$refs.dataform.resetForm();
this.isShow = false;
this.dialogVisible = false;
}
}
};
</script>