| | |
| | | <el-row :gutter="35"> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="RFID名称" prop="rfidName"> |
| | | <el-input class="input-length" v-model.trim="RFIDForm.rfidName" placeholder="请输入RFID名称" clearable></el-input> |
| | | <el-input class="input-add" v-model.trim="RFIDForm.rfidName" placeholder="请输入RFID名称" clearable></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="RFID编码" prop="rfid"> |
| | | <el-input class="input-length" v-model.trim="RFIDForm.rfid" placeholder="请输入RFID编码" clearable></el-input> |
| | | <el-input class="input-add" v-model.trim="RFIDForm.rfid" placeholder="请输入RFID编码" clearable></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="处理人所属车间"> |
| | | <el-cascader @change="getUser" :options="departmentData" filterable :props="{ emitPath: false, checkStrictly: true, value: 'depId', label: 'depName'}" placeholder="请输入RFID所属车间" clearable class="input-add" v-model="RFIDForm.exceptionHandlerDepId"> </el-cascader> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="异常处理人"> |
| | | <el-select v-model="RFIDForm.exceptionHandlerId" filterable class="input-add" placeholder="请输入异常处理人"> |
| | | <el-option v-for="item in userList" :key="item.uid" :label="item.realName" :value="item.uid"></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="RFID所属车间" prop="rfidDepartmentId"> |
| | | <el-cascader :options="departmentData" filterable :props="{ emitPath: false, checkStrictly: true, value: 'depId', label: 'depName' }" placeholder="请输入RFID所属车间" clearable class="input-add" v-model="RFIDForm. rfidDepartmentId"> </el-cascader> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="上传图片" prop="rfidImage"> |
| | | <el-upload accept="image/*" :on-preview="handlePictureCardPreview" :limits="1" v-model:file-list="fileList" :http-request="upload" :action="uploadUrl" list-type="picture-card" :on-remove="handleRemove" :before-remove="beforeRemove" :before-upload="getUploadUrl"> |
| | | <el-icon><Plus /></el-icon> |
| | | <template #tip> |
| | | <div class="el-upload__tip">上传 jpg/png 图片尺寸小于500KB</div> |
| | | </template> |
| | | </el-upload> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="isShowRFIDDialog = !isShowRFIDDialog" size="default">取 消</el-button> |
| | | <el-button type="primary" @click="submitRFID" v-throttle size="default">确 实</el-button> |
| | | <el-button type="primary" @click="submitRFID" v-throttle size="default">确 定</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | <el-dialog v-model="dialogVisible"> |
| | | <img w-full :src="dialogImageUrl" alt="Preview Image" /> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script lang="ts"> |
| | | import {userApi} from "/@/api/systemManage/user"; |
| | | |
| | | interface stateType { |
| | | isShowRFIDDialog: Boolean; |
| | | RFIDForm: { |
| | | rfid: string; |
| | | rfidName: string; |
| | | rfidImage: string | null; |
| | | rfidDepartmentId: number | null, |
| | | exceptionHandlerId: number | null, |
| | | exceptionHandlerDepId: number | null, |
| | | }; |
| | | title: string; |
| | | dialogVisible: Boolean; |
| | | dialogImageUrl: string | null; |
| | | RFIDFormRules: {}; |
| | | uploadUrl: string; |
| | | fileList: Array<file>; |
| | | departmentData: []; |
| | | userList: []; |
| | | } |
| | | interface levelListState {} |
| | | import { reactive, toRefs, ref } from 'vue'; |
| | | interface file { |
| | | url: string; |
| | | } |
| | | |
| | | import {reactive, toRefs, ref, onMounted} from 'vue'; |
| | | import { RFIDApi } from '/@/api/intellectInspectSystem/RFID'; |
| | | import { ElMessage } from 'element-plus'; |
| | | import { ElMessage, ElMessageBox } from 'element-plus'; |
| | | import type { UploadProps, UploadUserFile } from 'element-plus'; |
| | | import axios from 'axios'; |
| | | export default { |
| | | name: 'RFIDDialog', |
| | | setup(props: any, context: any) { |
| | |
| | | isShowRFIDDialog: false, |
| | | RFIDForm: { |
| | | rfid: '', |
| | | rfidName: '' |
| | | rfidName: '', |
| | | rfidDepartmentId: null, |
| | | exceptionHandlerId: null, |
| | | exceptionHandlerDepId: null, |
| | | rfidImage: null |
| | | }, |
| | | uploadUrl: '', |
| | | dialogVisible: false, |
| | | dialogImageUrl: null, |
| | | RFIDFormRules: { |
| | | rfid: [{ required: true, message: '请填写RFID编码', trigger: 'blur' }], |
| | | rfidName: [{ required: true, message: '请填写RFID名称', trigger: 'change' }], |
| | | riskLevel: [{ required: true, message: '请选择风险等级', trigger: 'change' }], |
| | | location: [{ required: true, message: '请填写区域位置', trigger: 'blur' }] |
| | | } |
| | | }); |
| | | rfidDepartmentId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | // exceptionHandlerDepId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | // exceptionHandlerId: [{ required: true, message: '请选择', trigger: 'change' }] |
| | | }, |
| | | |
| | | fileList: [], |
| | | departmentData: [], |
| | | userList: [] |
| | | }); |
| | | //打开模态框 |
| | | const openRFIDDialog = (type: string, value: object) => { |
| | | const openRFIDDialog = async (type: string, value: object, departmentList: []) => { |
| | | state.fileList = []; |
| | | state.isShowRFIDDialog = true; |
| | | state.departmentData = departmentList; |
| | | setTimeout(() => { |
| | | RFIDFormRef.value.clearValidate(); |
| | | }); |
| | | if (type === '新增') { |
| | | state.title = '新增巡检指标'; |
| | | state.title = '新增RFID'; |
| | | state.RFIDForm = { |
| | | rfid: '', |
| | | rfidName: '' |
| | | rfidName: '', |
| | | rfidDepartmentId: null, |
| | | exceptionHandlerId: null, |
| | | exceptionHandlerDepId: null, |
| | | rfidImage: '' |
| | | }; |
| | | } else { |
| | | state.title = '修改巡检指标'; |
| | | state.RFIDForm = JSON.parse(JSON.stringify(value)); |
| | | state.title = '修改RFID'; |
| | | let res = await RFIDApi().getRFIDById({id:parseInt(value.id)}) |
| | | state.RFIDForm = res.data.data |
| | | getUser() |
| | | if (state.RFIDForm.rfidImage === null) return; |
| | | state.fileList = [{ url: state.RFIDForm.rfidImage }]; |
| | | } |
| | | }; |
| | | |
| | | // // 图片上传 |
| | | // const fileList = ref<UploadUserFile[]>([]); |
| | | // |
| | | // const handleRemove = () => { |
| | | // ElMessageBox.confirm(`此操作将永久删除该图片,是否继续?`, '提示', { |
| | | // confirmButtonText: '确认', |
| | | // cancelButtonText: '取消', |
| | | // type: 'warning' |
| | | // }) |
| | | // .then(() => { |
| | | // state.RFIDForm.rfidImage = null; |
| | | // state.fileList = []; |
| | | // }) |
| | | // .catch(() => {}); |
| | | // }; |
| | | |
| | | const handlePreview: UploadProps['onPreview'] = (uploadFile) => { |
| | | console.log(uploadFile); |
| | | }; |
| | | |
| | | const getUploadUrl = async (rawFile: any) => { |
| | | const res = await RFIDApi().getUploadUrl(rawFile.name); |
| | | state.RFIDForm.rfidImage = res.data.rfidImage; |
| | | state.uploadUrl = res.data.uploadUrl; |
| | | }; |
| | | |
| | | const upload = async (params: any) => { |
| | | // const formData = new FormData(); |
| | | // formData.append('file', state.fileList[0].raw); |
| | | let reader = new FileReader(); |
| | | reader.readAsArrayBuffer(params.file); |
| | | reader.onload = async () => { |
| | | axios |
| | | .put(state.uploadUrl, reader.result, { |
| | | header: { 'Content-Type': 'multipart/form-data' } |
| | | }) |
| | | .then(() => { |
| | | if (state.fileList.length === 2) { |
| | | state.fileList.splice(0, 1); |
| | | } |
| | | }); |
| | | // let res = await RFIDApi().uploadFile(state.uploadUrl, reader.result); |
| | | // if (res.data.code === '200') { |
| | | // } else { |
| | | // ElMessage({ |
| | | // type: 'warning', |
| | | // message: res.data.msg |
| | | // }); |
| | | // } |
| | | }; |
| | | }; |
| | | |
| | | const beforeRemove = (file: {}, fileList: []) => { |
| | | const result = new Promise((resolve, reject) => { |
| | | ElMessageBox.confirm('此操作将删除该图片, 是否继续?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }) |
| | | .then(() => { |
| | | state.RFIDForm.rfidImage = null; |
| | | state.fileList = []; |
| | | // 请求删除接口 |
| | | }) |
| | | .catch(() => { |
| | | reject(false); |
| | | }); |
| | | }); |
| | | return result; |
| | | }; |
| | | |
| | | //新增修改提交 |
| | | const submitRFID = async () => { |
| | | RFIDFormRef.value.validate(async (valid: Boolean) => { |
| | | if (valid) { |
| | | if (state.title === '新增巡检指标') { |
| | | if (state.title === '新增RFID') { |
| | | let res = await RFIDApi().addRFID(state.RFIDForm); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '巡检指标新增成功', |
| | | message: 'RFID新增成功', |
| | | duration: 2000 |
| | | }); |
| | | state.isShowRFIDDialog = false; |
| | |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '巡检指标修改成功', |
| | | message: 'RFID修改成功', |
| | | duration: 2000 |
| | | }); |
| | | state.isShowRFIDDialog = false; |
| | |
| | | }); |
| | | }; |
| | | |
| | | //获取用户列表 |
| | | const getUser = async () => { |
| | | let res = await userApi().getUserLByDepartment(state.RFIDForm.exceptionHandlerDepId); |
| | | if (res.data.code === '200') { |
| | | state.userList = res.data.data; |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const handlePictureCardPreview = (uploadFile: { url: string }) => { |
| | | state.dialogImageUrl = uploadFile.url!; |
| | | state.dialogVisible = true; |
| | | }; |
| | | |
| | | return { |
| | | ...toRefs(state), |
| | | RFIDFormRef, |
| | | // fileList, |
| | | upload, |
| | | getUploadUrl, |
| | | getUser, |
| | | handlePreview, |
| | | beforeRemove, |
| | | submitRFID, |
| | | openRFIDDialog |
| | | openRFIDDialog, |
| | | handlePictureCardPreview |
| | | }; |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .input-length { |
| | | width: 85%; |
| | | } |
| | | </style> |
| | | <style scoped></style> |