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

124 lines
3.7 KiB
Vue
Raw Normal View History

<template>
<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 v-if="!isPut" type="primary" @click="doCreate">{{ $t('global.confirm') }}</el-button>
<el-button v-if="isPut" type="primary" @click="putInfo">更新</el-button>
<el-button @click="doClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { getStationList } from '@/api/runplan';
import { createIbp, putIbpBasicInfo } from '@/api/ibp';
export default {
name: 'ScriptDraft',
props: {
title: {
type: String,
default() {
return '';
}
}
},
data() {
return {
dialogVisible: false,
isPut: false,
stationList: [],
formModel: {
stationCode: ''
}
};
},
computed: {
form() {
const form = {
labelWidth: '150px',
items: [
{ prop: 'stationCode', label: '关联站台:', type: 'select', options: this.stationList }
]
};
return form;
},
rules() {
const crules = {
stationCode: [
{ required: true, message: '请选择', trigger: 'change' }
]
};
return crules;
}
},
async created () {
try {
const res = await getStationList(this.$route.params.mapId);
this.stationList = [];
if (res.code == 200) {
console.log(res.data);
res.data.forEach(station => {
const param = {
label: station.name,
value: station.code
};
this.stationList.push(param);
});
}
} catch (error) {
console.log(error);
}
},
methods: {
doShow(code) {
if (code) {
this.formModel.stationCode = code;
} else {
this.formModel.stationCode = '';
}
this.dialogVisible = true;
},
doCreate() {
this.$refs.dataform.validateForm(() => {
const param = {
mapId: this.$route.params.mapId,
stationCode: this.formModel.stationCode
};
createIbp(param).then(resp => {
this.$message.success('创建成功');
this.$emit('reloadTable');
}).catch(error => {
this.$messageBox(`创建失败: ${error.message}`);
});
this.doClose();
});
},
putInfo() {
this.$refs.dataform.validateForm(() => {
const param = {
mapId: this.$route.params.mapId,
stationCode: this.formModel.stationCode
};
putIbpBasicInfo(param).then(resp => {
this.$message.success('更新成功');
this.$emit('reloadTable');
}).catch(error => {
this.$messageBox(`更新失败: ${error.message}`);
});
this.doClose();
});
},
doClose() {
this.$refs.dataform.resetForm();
this.dialogVisible = false;
}
}
};
</script>
<style lang="scss" scoped>
/deep/ .el-dialog--center .el-dialog__body{
padding: 25px 65px 30px 10px;
}
</style>