2021-05-14 18:31:46 +08:00
|
|
|
<template>
|
|
|
|
<el-dialog v-dialogDrag :title="title" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" center class="uploadDialog">
|
|
|
|
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
|
2021-05-17 17:20:26 +08:00
|
|
|
<div class="fileError">{{ message }}</div>
|
2021-05-14 18:31:46 +08:00
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
|
<el-button type="primary" @click="doSave">{{ $t('global.confirm') }}</el-button>
|
|
|
|
<el-button @click="handleClose">{{ $t('global.cancel') }}</el-button>
|
|
|
|
</span>
|
|
|
|
</el-dialog>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { postUploadFile, putUploadFile } from '@/api/pdf';
|
2021-05-17 17:20:26 +08:00
|
|
|
// import { getPublishMapDetailById, getPublishMapVersionById } from '@/api/jmap/map';
|
|
|
|
// import { dbReadData, dbAddData, dbUpdateData } from '@/utils/indexedDb';
|
2021-05-14 18:31:46 +08:00
|
|
|
// uploadFile
|
|
|
|
import { meansUrl } from '@/api/upload';
|
2021-05-20 15:06:14 +08:00
|
|
|
import { DrawingType } from '@/scripts/ConstDic';
|
2021-05-14 18:31:46 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TrainingDetailEdit',
|
|
|
|
props: {
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dialogVisible: false,
|
|
|
|
formModel: {
|
|
|
|
upload: '',
|
|
|
|
filePath: '',
|
2021-05-20 15:06:14 +08:00
|
|
|
fileType: DrawingType.drawing,
|
2021-05-17 17:20:26 +08:00
|
|
|
fileName:''
|
2021-05-14 18:31:46 +08:00
|
|
|
},
|
|
|
|
fileList: [],
|
|
|
|
formData: '',
|
|
|
|
id: '',
|
2021-05-20 15:06:14 +08:00
|
|
|
message:'',
|
|
|
|
fileTypeList: [
|
|
|
|
{label: '设备图纸', value: DrawingType.drawing},
|
|
|
|
{label: '基础设备培训', value: DrawingType.baDeTr},
|
|
|
|
{label: '经典案例分析', value: DrawingType.clCaAn},
|
|
|
|
{label: '规范学习', value: DrawingType.normStudy}
|
|
|
|
]
|
2021-05-17 17:20:26 +08:00
|
|
|
// deviceTypeList: [
|
|
|
|
// { label: '区段', value: 'sectionList', code: 'SECTION' },
|
|
|
|
// { label: '道岔', value: 'switchList', code: 'SWITCH' },
|
|
|
|
// { label: '信号机', value: 'signalList', code: 'SIGNAL' },
|
|
|
|
// { label: '车站', value: 'stationList', code: 'STATION' },
|
|
|
|
// { label: '站台', value: 'stationStandList', code: 'STAND' },
|
|
|
|
// { label: '屏蔽门', value: 'psdList', code: 'PSD' },
|
|
|
|
// { label: '列车', value: 'trainList', code: 'TRAIN' }
|
|
|
|
// ],
|
2021-05-14 18:31:46 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
action() {
|
2021-12-30 09:34:50 +08:00
|
|
|
return `${this.$store.state.user.uploadUrl}${meansUrl}`;
|
2021-05-14 18:31:46 +08:00
|
|
|
},
|
|
|
|
form() {
|
|
|
|
const form = {
|
|
|
|
labelWidth: '120px',
|
|
|
|
items: [
|
2021-05-17 17:20:26 +08:00
|
|
|
// { prop: 'mapId', label: '选择线路:', type:'select', options: this.mapList, optionValue:'id', optionLabel:'name', change: true, onChange: this.handleMap },
|
|
|
|
// { prop: 'deviceTypes', label: '选择设备类型:', type:'select', options: this.deviceTypeList, optionValue:'value', optionLabel:'label', change: true, onChange: this.handleDevice },
|
|
|
|
// { prop: 'deviceIds', label: '选择设备:', type:'select', multiple: true, options: this.deviceCodesList, optionValue:'code', optionLabel:'name' },
|
|
|
|
{ prop: 'fileName', label: '文件名:', type:'text', show:true, rightWidth:true, required:true },
|
2021-05-20 15:06:14 +08:00
|
|
|
{ prop: 'fileType', label: '文件类型', type: 'select', options: this.fileTypeList, optionValue: 'value', optionLabel: 'label'},
|
2021-05-17 17:20:26 +08:00
|
|
|
{ prop: 'upload', label: '上传:', type:'uploadPicture', fileList: this.fileList, show: this.type == 'ADD', action: this.action, onChange: this.onChange, onSuccess: this.onSuccess }
|
2021-05-14 18:31:46 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
return form;
|
|
|
|
},
|
|
|
|
rules() {
|
|
|
|
const crules = {
|
2021-05-17 17:20:26 +08:00
|
|
|
fileName: [
|
|
|
|
{ required: true, message: '文件名不能为空', trigger: 'blur'}
|
2021-05-20 15:06:14 +08:00
|
|
|
],
|
|
|
|
fileType: [
|
|
|
|
{ required: true, message: '文件类型不能为空', trigger: 'blur' }
|
2021-05-14 18:31:46 +08:00
|
|
|
]
|
2021-05-17 17:20:26 +08:00
|
|
|
// upload: [
|
|
|
|
// { required: true, message: '请上传文件', trigger: 'onChange' }
|
|
|
|
// ]
|
2021-05-14 18:31:46 +08:00
|
|
|
};
|
|
|
|
return crules;
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
if (this.type === 'ADD') {
|
|
|
|
return '上传PDF';
|
|
|
|
} else {
|
2021-05-17 17:20:26 +08:00
|
|
|
return '更新PDF';
|
2021-05-14 18:31:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async show(data) {
|
|
|
|
this.dialogVisible = true;
|
|
|
|
if (this.type != 'ADD') {
|
|
|
|
this.id = data.id;
|
|
|
|
this.formModel = {
|
|
|
|
upload: '',
|
2021-05-17 17:20:26 +08:00
|
|
|
fileName:data.fileName,
|
2021-05-20 15:06:14 +08:00
|
|
|
fileType: data.fileType,
|
2021-05-14 18:31:46 +08:00
|
|
|
filePath: data.filePath
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.formModel = {
|
|
|
|
upload: '',
|
2021-05-17 17:20:26 +08:00
|
|
|
filePath: '',
|
2021-05-20 15:06:14 +08:00
|
|
|
fileType: DrawingType.drawing,
|
2021-05-17 17:20:26 +08:00
|
|
|
fileName:''
|
2021-05-14 18:31:46 +08:00
|
|
|
};
|
|
|
|
}
|
2021-05-20 15:06:14 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.dataform.clearFiles();
|
|
|
|
});
|
2021-05-14 18:31:46 +08:00
|
|
|
},
|
2021-05-17 17:20:26 +08:00
|
|
|
// async handleMap(mapId) {
|
|
|
|
// if (mapId) {
|
|
|
|
// if (mapId != this.rowData.mapId) {
|
|
|
|
// this.formModel.deviceIds = [];
|
|
|
|
// this.formModel.deviceTypes = '';
|
|
|
|
// }
|
|
|
|
// return new Promise(async (resolve, reject) => {
|
|
|
|
// const resp = await getPublishMapVersionById(mapId);
|
|
|
|
// const version = resp.data;
|
|
|
|
// dbReadData('mapData', mapId, version, async (mapData, version) =>{
|
|
|
|
// if (mapData && mapData.version == version) {
|
|
|
|
// this.graphDataNew = mapData.graphDataNew;
|
|
|
|
// resolve();
|
|
|
|
// } else if (mapData) {
|
|
|
|
// const res = await getPublishMapDetailById(mapId);
|
|
|
|
// this.graphDataNew = res.data.graphDataNew;
|
|
|
|
// dbUpdateData('mapData', res.data);
|
|
|
|
// resolve();
|
|
|
|
// } else {
|
|
|
|
// const res = await getPublishMapDetailById(mapId);
|
|
|
|
// this.graphDataNew = res.data.graphDataNew;
|
|
|
|
// dbAddData('mapData', res.data);
|
|
|
|
// resolve();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// } else {
|
|
|
|
// this.formModel.deviceIds = [];
|
|
|
|
// this.formModel.mapId = '';
|
|
|
|
// this.formModel.deviceTypes = '';
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// handleDevice(type) {
|
|
|
|
// if (type) {
|
|
|
|
// if (type != this.rowData.deviceTypes) {
|
|
|
|
// this.formModel.deviceIds = [];
|
|
|
|
// }
|
|
|
|
// this.deviceCodesList = this.graphDataNew[type].map(el => {
|
|
|
|
// return {
|
|
|
|
// code: el.code,
|
|
|
|
// name: `${el.name}(${el.code})`
|
|
|
|
// };
|
|
|
|
// });
|
|
|
|
// } else {
|
|
|
|
// this.formModel.deviceIds = [];
|
|
|
|
// }
|
|
|
|
// },
|
2021-05-14 18:31:46 +08:00
|
|
|
// uploadFile(file) {
|
|
|
|
// this.formData.append('file', file.file);
|
|
|
|
// },
|
|
|
|
onSuccess(res, file) {
|
|
|
|
this.formModel.filePath = res.data;
|
2021-05-17 17:20:26 +08:00
|
|
|
this.message = '';
|
2021-05-14 18:31:46 +08:00
|
|
|
},
|
|
|
|
doSave() {
|
|
|
|
const self = this;
|
|
|
|
this.$refs.dataform.validateForm(() => {
|
|
|
|
if (self.type == 'ADD') {
|
2021-05-17 17:20:26 +08:00
|
|
|
if (this.formModel.filePath) {
|
|
|
|
self.create();
|
|
|
|
} else {
|
|
|
|
this.message = '请上传文件';
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-14 18:31:46 +08:00
|
|
|
} else {
|
|
|
|
self.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
create() {
|
|
|
|
const self = this;
|
|
|
|
const data = {
|
2021-05-20 15:06:14 +08:00
|
|
|
fileType: this.formModel.fileType,
|
2021-05-17 17:20:26 +08:00
|
|
|
filePath: this.formModel.filePath,
|
|
|
|
fileName:this.formModel.fileName
|
2021-05-14 18:31:46 +08:00
|
|
|
};
|
|
|
|
postUploadFile(data).then((res) => {
|
|
|
|
self.$message.success('上传PDF成功!');
|
|
|
|
self.handleClose();
|
|
|
|
self.$emit('reloadTable');
|
|
|
|
}).catch(error => {
|
|
|
|
console.log(error);
|
2021-05-17 17:20:26 +08:00
|
|
|
self.$message.error(`上传PDF失败:${error.message}`);
|
2021-05-14 18:31:46 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
const self = this;
|
|
|
|
const data = {
|
|
|
|
id: this.id,
|
2021-05-20 15:06:14 +08:00
|
|
|
fileType: this.formModel.fileType,
|
2021-05-17 17:20:26 +08:00
|
|
|
fileName:this.formModel.fileName,
|
2021-05-14 18:31:46 +08:00
|
|
|
filePath: this.formModel.filePath
|
|
|
|
};
|
|
|
|
putUploadFile(data).then(() => {
|
2021-05-17 17:20:26 +08:00
|
|
|
self.$message.success('更新PDF成功!');
|
2021-05-14 18:31:46 +08:00
|
|
|
self.handleClose();
|
|
|
|
self.$emit('reloadTable');
|
|
|
|
}).catch(error => {
|
2021-05-17 17:20:26 +08:00
|
|
|
self.$message.error(`更新PDF失败:${error.message}`);
|
2021-05-14 18:31:46 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
handleClose() {
|
2021-05-17 17:20:26 +08:00
|
|
|
this.message = '';
|
2021-05-14 18:31:46 +08:00
|
|
|
this.formModel = {
|
2021-05-17 17:20:26 +08:00
|
|
|
upload: '',
|
|
|
|
filePath: '',
|
2021-05-20 15:06:14 +08:00
|
|
|
fileType: DrawingType.drawing,
|
2021-05-17 17:20:26 +08:00
|
|
|
fileName:''
|
2021-05-14 18:31:46 +08:00
|
|
|
};
|
|
|
|
this.$refs.dataform.resetForm();
|
|
|
|
this.dialogVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.uploadDialog{
|
|
|
|
/deep/ {
|
|
|
|
.el-select--medium{
|
|
|
|
width: 300px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 17:20:26 +08:00
|
|
|
.fileError{
|
|
|
|
color: red;
|
|
|
|
font-size: 13px;
|
|
|
|
margin-left: 122px;
|
|
|
|
vertical-align: top;
|
|
|
|
display: inline-block;
|
|
|
|
margin-top: -10px;
|
|
|
|
}
|
2021-05-14 18:31:46 +08:00
|
|
|
</style>
|