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

142 lines
4.4 KiB
Vue

<template>
<el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :before-close="doClose" center>
<el-form ref="form" :model="formModel" label-width="80px" :rules="rules">
<el-form-item label="公共数据" prop="common">
<el-switch v-model="formModel.common" />
</el-form-item>
<el-form-item v-if="!formModel.common" label="关联车站" prop="stationCode">
<el-select v-model="formModel.stationCode" placeholder="请选择">
<el-option
v-for="item in stationList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-form>
<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: [],
ibpId: '',
formModel: {
stationCode: '',
common: false
}
};
},
computed: {
rules() {
const crules = {
stationCode: [
{ required: true, message: '请选择', trigger: 'change' }
]
};
return crules;
}
},
watch: {
'$route.params.mapId': function() {
this.getStationLIst();
}
},
async created () {
this.getStationLIst();
},
methods: {
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);
}
},
doShow(data) {
if (data) {
this.formModel.stationCode = data.stationCode;
this.formModel.common = !data.stationCode;
this.ibpId = data.id;
this.isPut = true;
} else {
this.formModel.stationCode = '';
}
this.dialogVisible = true;
},
doCreate() {
this.$refs.form.validate(() => {
const param = {
mapId: this.$route.params.mapId,
stationCode: this.formModel.common ? null : this.formModel.stationCode
};
createIbp(param).then(resp => {
this.$message.success('创建成功');
this.$emit('reloadTable');
}).catch(error => {
this.$messageBox(`创建失败: ${error.message}`);
});
this.doClose();
});
},
putInfo() {
this.$refs.form.validate(() => {
const param = {
mapId: this.$route.params.mapId,
stationCode: this.formModel.common ? null : this.formModel.stationCode
};
putIbpBasicInfo(this.ibpId, param).then(resp => {
this.$message.success('更新成功');
this.$emit('reloadTable');
this.isPut = false;
}).catch(error => {
this.$messageBox(`更新失败: ${error.message}`);
});
this.doClose();
});
},
doClose() {
this.$refs.form.resetFields();
this.dialogVisible = false;
}
}
};
</script>
<style lang="scss" scoped>
/deep/ .el-dialog--center .el-dialog__body{
padding: 25px 65px 30px 10px;
}
</style>