2020-03-13 18:19:04 +08:00
|
|
|
<template>
|
|
|
|
<el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :before-close="doClose" center>
|
2020-12-17 13:19:12 +08:00
|
|
|
<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>
|
2020-03-13 18:19:04 +08:00
|
|
|
<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: '',
|
2020-03-13 18:19:04 +08:00
|
|
|
formModel: {
|
2020-12-17 13:19:12 +08:00
|
|
|
stationCode: '',
|
|
|
|
common: false
|
2020-03-13 18:19:04 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
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-13 18:19:04 +08:00
|
|
|
}
|
|
|
|
},
|
2020-03-16 16:06:50 +08:00
|
|
|
async created () {
|
|
|
|
this.getStationLIst();
|
|
|
|
},
|
2020-03-13 18:19:04 +08:00
|
|
|
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;
|
2020-12-17 13:19:12 +08:00
|
|
|
this.formModel.common = !data.stationCode;
|
2020-03-13 19:01:59 +08:00
|
|
|
this.ibpId = data.id;
|
|
|
|
this.isPut = true;
|
2020-03-13 18:19:04 +08:00
|
|
|
} else {
|
|
|
|
this.formModel.stationCode = '';
|
|
|
|
}
|
|
|
|
this.dialogVisible = true;
|
|
|
|
},
|
|
|
|
doCreate() {
|
2020-12-17 13:19:12 +08:00
|
|
|
this.$refs.form.validate(() => {
|
2020-03-13 18:19:04 +08:00
|
|
|
const param = {
|
|
|
|
mapId: this.$route.params.mapId,
|
2020-12-17 13:19:12 +08:00
|
|
|
stationCode: this.formModel.common ? null : this.formModel.stationCode
|
2020-03-13 18:19:04 +08:00
|
|
|
};
|
|
|
|
createIbp(param).then(resp => {
|
|
|
|
this.$message.success('创建成功');
|
|
|
|
this.$emit('reloadTable');
|
|
|
|
}).catch(error => {
|
|
|
|
this.$messageBox(`创建失败: ${error.message}`);
|
|
|
|
});
|
|
|
|
this.doClose();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
putInfo() {
|
2020-12-17 13:19:12 +08:00
|
|
|
this.$refs.form.validate(() => {
|
2020-03-13 18:19:04 +08:00
|
|
|
const param = {
|
|
|
|
mapId: this.$route.params.mapId,
|
2020-12-17 13:19:12 +08:00
|
|
|
stationCode: this.formModel.common ? null : this.formModel.stationCode
|
2020-03-13 18:19:04 +08:00
|
|
|
};
|
2020-03-13 19:01:59 +08:00
|
|
|
putIbpBasicInfo(this.ibpId, param).then(resp => {
|
2020-03-13 18:19:04 +08:00
|
|
|
this.$message.success('更新成功');
|
|
|
|
this.$emit('reloadTable');
|
2020-03-13 19:01:59 +08:00
|
|
|
this.isPut = false;
|
2020-03-13 18:19:04 +08:00
|
|
|
}).catch(error => {
|
|
|
|
this.$messageBox(`更新失败: ${error.message}`);
|
|
|
|
});
|
|
|
|
this.doClose();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
doClose() {
|
2020-12-17 13:19:12 +08:00
|
|
|
this.$refs.form.resetFields();
|
2020-03-13 18:19:04 +08:00
|
|
|
this.dialogVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
/deep/ .el-dialog--center .el-dialog__body{
|
|
|
|
padding: 25px 65px 30px 10px;
|
|
|
|
}
|
|
|
|
</style>
|