<template>
|
<GlobalWindow :title="param.id ? '编辑运维记录' : '新建运维记录'" :confirmWorking="subLoading" :visible.sync="isShowModal"
|
width="600px" @close="close" @confirm="handleSub">
|
<el-form :model="param" ref="paramRef" :rules="rules">
|
<el-form-item label="选择设备" prop="deviceId">
|
<el-select v-model="param.deviceId" filterable clearable>
|
<el-option v-for="item in deviceList" :value="item.id" :label="item.name"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="运维人员" prop="userId">
|
<el-select v-model="param.userId" filterable clearable>
|
<el-option v-for="item in staffList" :value="item.id" :label="item.realname"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="设备状态" prop="">
|
<el-select v-model="param.status" filterable clearable>
|
<el-option :value="0" label="正常"></el-option>
|
<el-option :value="1" label="损坏"></el-option>
|
<el-option :value="2" label="报废"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="现场照片" prop="">
|
<div class="file_list">
|
<el-upload class="avatar-uploader" :data="uploadData" :auto-upload="true" :action="uploadImgUrl"
|
:show-file-list="false" :on-success="uploadAvatarSuccess" :on-error="uploadError"
|
:before-upload="beforeUpload">
|
<div class="upload_wrap">
|
<i class="el-icon-plus avatar-uploader-icon"></i>
|
<div>图片/视频</div>
|
</div>
|
</el-upload>
|
<div v-for="(item, i) in fileList" :key="i" class="item">
|
<i @click="handleDelImg(i)" class="el-icon-error close"></i>
|
<el-image :src="item.fileurlFull" :preview-src-list="[item.fileurlFull]" v-if="item.type == 0"
|
class="img"></el-image>
|
<video :src="item.fileurlFull" controls v-if="item.type == 1" class="img"></video>
|
</div>
|
</div>
|
</el-form-item>
|
<el-form-item label="运维备注" prop="content">
|
<el-input type="textarea" :rows="4" v-model="param.content" placeholder="请输入" />
|
</el-form-item>
|
<el-form-item label="运维时间" prop="dealDate">
|
<el-date-picker v-model="param.dealDate" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
|
type="datetime"></el-date-picker>
|
</el-form-item>
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
|
import { fetchList } from '@/api/Inspection/device'
|
import { getUserList } from '@/api/system/user'
|
import { create, updateById } from '@/api/Inspection/deviceRecord'
|
import { Message, Loading } from 'element-ui'
|
import dayjs from 'dayjs'
|
export default {
|
components: { GlobalWindow, UploadAvatarImage },
|
data() {
|
return {
|
isShowModal: false,
|
subLoading: false,
|
param: {},
|
deviceList: [],
|
staffList: [],
|
rules: {
|
dealDate: [{ required: true, message: '请选择' }],
|
deviceId: [{ required: true, message: '请选择' }],
|
content: [{ required: true, message: '请输入' }],
|
// code: [{ required: true, message: '请输入' }],
|
},
|
|
loadingInstance: null,
|
uploadImgUrl: process.env.VUE_APP_API_PREFIX + '/visitsAdmin/cloudService/public/uploadBatch',
|
fileList: [],
|
uploadData: {
|
folder: 'YW_DEVICE'
|
},
|
|
}
|
},
|
created() {
|
this.initData()
|
this.$set(this.param, 'dealDate', dayjs().format('YYYY-MM-DD HH:mm:ss'))
|
},
|
methods: {
|
handleSub() {
|
const { param, subLoading, fileList } = this
|
this.$refs['paramRef'].validate((valid) => {
|
if (valid) {
|
let fn = param.id ? updateById : create
|
if(fileList && fileList.length > 0){
|
param.multifileList = fileList
|
}
|
this.subLoading = true
|
fn(param).then(res => {
|
this.subLoading = false
|
this.$emit('success')
|
Message.success('保存成功')
|
this.close()
|
}).catch(() => {
|
this.subLoading = false
|
})
|
}
|
})
|
},
|
initData() {
|
fetchList({
|
model: {},
|
capacity: 1000,
|
page: 1,
|
}).then(res => {
|
this.deviceList = res.records
|
})
|
getUserList({}).then(res => {
|
this.staffList = res
|
})
|
},
|
changeSel(e) {
|
if (e && e.length == 1) {
|
this.$set(this.param, 'catePId', e[0])
|
this.$set(this.param, 'cateId', '')
|
} else if (e && e.length == 2) {
|
this.$set(this.param, 'catePId', e[0])
|
this.$set(this.param, 'cateId', e[1])
|
} else {
|
this.$set(this.param, 'catePId', '')
|
this.$set(this.param, 'cateId', '')
|
}
|
this.search()
|
},
|
beforeUpload(file) {
|
if (['video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb', 'image/jpeg', 'image/jpg', 'image/png', 'image/gif'].indexOf(file.type) == -1) {
|
this.$message.error('请上传正确的视频/图片格式')
|
return false
|
}
|
this.loadingInstance = Loading.service({
|
lock: true,
|
text: 'Loading',
|
spinner: 'el-icon-loading',
|
background: 'rgba(0, 0, 0, 0.7)'
|
})
|
},
|
uploadError() {
|
this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
|
if (this.loadingInstance) {
|
this.loadingInstance.close()
|
}
|
})
|
},
|
uploadAvatarSuccess(file) {
|
this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
|
if (this.loadingInstance) {
|
this.loadingInstance.close()
|
}
|
})
|
console.log('file', file)
|
const item = file.data[0]
|
if (['.mp4', '.avi', '.flv', '.wmv'].some(char => item.imgaddr.includes(char))) {
|
this.fileList.push({
|
type: 1,
|
objType: 6,
|
fileurl: item.imgaddr,
|
fileurlFull: item.url
|
})
|
} else {
|
this.fileList.push({
|
type: 0,
|
objType: 6,
|
fileurl: item.imgaddr,
|
fileurlFull: item.url
|
})
|
}
|
console.log('file', this.fileList)
|
// this.$set(this.param, 'faceImg', file.imgurl)
|
// this.$set(this.param, 'faceImgUrl', file.imgurlfull)
|
},
|
handleDelImg(i) {
|
this.fileList.splice(i, 1)
|
},
|
close() {
|
this.isShowModal = false
|
this.$emit('close')
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.file_list {
|
display: flex;
|
flex-wrap: wrap;
|
|
.avatar-uploader {
|
width: 92px;
|
height: 92px;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
border: 1px dashed #d9d9d9;
|
}
|
|
.item {
|
width: 92px;
|
max-height: 92px;
|
margin-left: 10px;
|
position: relative;
|
border: 1px dashed #d9d9d9;
|
border-radius: 4px;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
|
.close {
|
font-size: 20px;
|
position: absolute;
|
right: -10px;
|
top: -10px;
|
z-index: 111;
|
color: red;
|
cursor: pointer;
|
}
|
|
.img {
|
width: 92px;
|
max-height: 92px;
|
}
|
}
|
}
|
</style>
|