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

135 lines
4.1 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: [],
2020-03-13 19:01:59 +08:00
ibpId: '',
formModel: {
stationCode: ''
}
};
},
computed: {
form() {
const form = {
labelWidth: '150px',
items: [
2020-12-16 13:59:31 +08:00
{ prop: 'stationCode', label: '关联车站:', type: 'select', options: this.stationList }
]
};
return form;
},
rules() {
const crules = {
stationCode: [
{ required: true, message: '请选择', trigger: 'change' }
]
};
return crules;
}
},
2020-03-16 16:06:50 +08:00
watch: {
'$route.params.mapId': function() {
this.getStationLIst();
}
},
2020-03-16 16:06:50 +08:00
async created () {
this.getStationLIst();
},
methods: {
2020-03-16 16:06:50 +08:00
async getStationLIst() {
try {
const res = await getStationList(this.$route.params.mapId);
this.stationList = [];
if (res.code == 200) {
res.data.forEach(station => {
const param = {
label: station.name,
value: station.code
};
this.stationList.push(param);
});
}
} catch (error) {
console.log(error);
}
},
2020-03-13 19:01:59 +08:00
doShow(data) {
if (data) {
this.formModel.stationCode = data.stationCode;
this.ibpId = data.id;
this.isPut = true;
} 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
};
2020-03-13 19:01:59 +08:00
putIbpBasicInfo(this.ibpId, param).then(resp => {
this.$message.success('更新成功');
this.$emit('reloadTable');
2020-03-13 19:01:59 +08:00
this.isPut = false;
}).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>