| | |
| | | <template> |
| | | <el-dialog |
| | | title="新增检测数据" |
| | | :title="isEdit ? '编辑检测数据' : '新增检测数据'" |
| | | :visible.sync="dialogVisible" |
| | | width="60%" |
| | | :close-on-click-modal="false" |
| | |
| | | > |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检测样编号" prop="sampleCode"> |
| | | <el-form-item label="数据编号" prop="dataCode"> |
| | | <el-input |
| | | v-model="form.sampleCode" |
| | | placeholder="请输入检测样编号" |
| | | v-model="form.dataCode" |
| | | placeholder="请输入数据编号" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检测数据" prop="testData"> |
| | | <el-form-item label="检测数据" prop="dataTitle"> |
| | | <el-input |
| | | v-model="form.testData" |
| | | v-model="form.dataTitle" |
| | | placeholder="请输入检测数据" |
| | | /> |
| | | </el-form-item> |
| | |
| | | |
| | | <el-row :gutter="20"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="检测类型" prop="testTypes"> |
| | | <el-checkbox-group v-model="form.testTypes"> |
| | | <el-checkbox label="photo">拍照</el-checkbox> |
| | | <el-checkbox label="spectrum">图谱</el-checkbox> |
| | | <el-form-item label="检测类型" prop="dataType"> |
| | | <el-checkbox-group v-model="form.dataType"> |
| | | <el-checkbox label="1">拍照</el-checkbox> |
| | | <el-checkbox label="2">图谱</el-checkbox> |
| | | </el-checkbox-group> |
| | | </el-form-item> |
| | | </el-col> |
| | |
| | | :on-change="handlePhotoChange" |
| | | > |
| | | <i class="el-icon-plus"></i> |
| | | <!-- <div class="el-upload__tip" slot="tip">支持 jpg、png 格式文件</div> --> |
| | | </el-upload> |
| | | </el-form-item> |
| | | </el-col> |
| | |
| | | visible: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | isEdit: { |
| | | type: Boolean, |
| | | default: false |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | isIPad: /iPad/i.test(navigator.userAgent), |
| | | form: { |
| | | sampleCode: "", |
| | | testData: "", |
| | | testTypes: ["photo"], // 默认选中拍照 |
| | | dataCode: "", |
| | | dataTitle: "", |
| | | dataType: ["1"], |
| | | dataFiles: "", |
| | | dataPictures: "", |
| | | photos: [], |
| | | spectrums: [] |
| | | }, |
| | | rules: { |
| | | sampleCode: [ |
| | | { required: true, message: "请输入检测样编号", trigger: "blur" } |
| | | dataCode: [ |
| | | { required: true, message: "请输入数据编号", trigger: "blur" } |
| | | ], |
| | | testData: [ |
| | | dataTitle: [ |
| | | { required: true, message: "请输入检测数据", trigger: "blur" } |
| | | ], |
| | | testTypes: [ |
| | | dataType: [ |
| | | { |
| | | type: 'array', |
| | | required: true, |
| | |
| | | message: "请上传检测照片", |
| | | trigger: "change", |
| | | validator: (rule, value, callback) => { |
| | | if (this.form.testTypes.includes('photo') && (!this.photoList || !this.photoList.length)) { |
| | | if (this.form.dataType.includes('1') && (!this.photoList || !this.photoList.length)) { |
| | | callback(new Error('请上传检测照片')); |
| | | } else { |
| | | callback(); |
| | |
| | | message: "请上传检测图谱", |
| | | trigger: "change", |
| | | validator: (rule, value, callback) => { |
| | | if (this.form.testTypes.includes('spectrum') && (!this.spectrumList || !this.spectrumList.length)) { |
| | | if (this.form.dataType.includes('2') && (!this.spectrumList || !this.spectrumList.length)) { |
| | | callback(new Error('请上传检测图谱')); |
| | | } else { |
| | | callback(); |
| | |
| | | } |
| | | }, |
| | | showPhotoUpload() { |
| | | return this.form.testTypes.includes('photo'); |
| | | return this.form.dataType.includes('1'); |
| | | }, |
| | | showSpectrumUpload() { |
| | | return this.form.testTypes.includes('spectrum'); |
| | | return this.form.dataType.includes('2'); |
| | | } |
| | | }, |
| | | methods: { |
| | | setFormData(data) { |
| | | console.log('data',data) |
| | | |
| | | // 设置基础表单数据 |
| | | this.form.sampleCode = data.sampleCode; |
| | | this.form.testData = data.testData; |
| | | this.form.testTypes = data.testTypes; |
| | | this.form.dataCode = data.dataCode; |
| | | this.form.dataTitle = data.dataTitle; |
| | | // 处理 dataType,确保它是数组格式 |
| | | this.form.dataType = Array.isArray(data.dataType) ? data.dataType : (data.dataType ? data.dataType.split(',') : []); |
| | | |
| | | // 设置照片列表 |
| | | if (data.photos && data.photos.length) { |
| | | this.photoList = data.photos.map(photo => ({ |
| | | name: photo.name, |
| | | url: photo.url, |
| | | status: 'success' |
| | | })); |
| | | if (data.dataPictures) { |
| | | try { |
| | | const pictures = typeof data.dataPictures === 'string' ? JSON.parse(data.dataPictures) : data.dataPictures; |
| | | this.photoList = pictures.map(photo => ({ |
| | | name: photo.name, |
| | | url: photo.url, |
| | | status: 'success' |
| | | })); |
| | | } catch (e) { |
| | | console.error('解析照片数据失败:', e); |
| | | this.photoList = []; |
| | | } |
| | | } else { |
| | | this.photoList = []; |
| | | } |
| | | |
| | | // 设置图谱列表 |
| | | if (data.spectrums && data.spectrums.length) { |
| | | this.spectrumList = data.spectrums.map(spectrum => ({ |
| | | name: spectrum.name, |
| | | url: spectrum.url, |
| | | status: 'success' |
| | | })); |
| | | if (data.dataFiles) { |
| | | try { |
| | | const files = typeof data.dataFiles === 'string' ? JSON.parse(data.dataFiles) : data.dataFiles; |
| | | this.spectrumList = files.map(file => ({ |
| | | name: file.name, |
| | | url: file.url, |
| | | status: 'success' |
| | | })); |
| | | } catch (e) { |
| | | console.error('解析图谱数据失败:', e); |
| | | this.spectrumList = []; |
| | | } |
| | | } else { |
| | | this.spectrumList = []; |
| | | } |
| | |
| | | this.photoList = []; |
| | | this.spectrumList = []; |
| | | this.form = { |
| | | sampleCode: "", |
| | | testData: "", |
| | | testTypes: ["photo"], |
| | | dataCode: "", |
| | | dataTitle: "", |
| | | dataType: ["1"], |
| | | dataFiles: "", |
| | | dataPictures: "", |
| | | photos: [], |
| | | spectrums: [] |
| | | }; |
| | |
| | | if (valid) { |
| | | const submitData = { |
| | | ...this.form, |
| | | photos: this.photoList, |
| | | spectrums: this.spectrumList |
| | | // 确保 dataType 在提交时转换为字符串 |
| | | dataType: Array.isArray(this.form.dataType) ? this.form.dataType.join(',') : this.form.dataType, |
| | | dataFiles: JSON.stringify(this.spectrumList), |
| | | dataPictures: JSON.stringify(this.photoList) |
| | | }; |
| | | this.$emit("success", submitData); |
| | | } |
| | | }); |
| | | }, |
| | | handlePhotoChange(file, fileList) { |
| | | this.photoList = fileList; |
| | | // 模拟上传成功 |
| | | const mockFile = { |
| | | name: file.name || '测试图片.jpg', |
| | | url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', |
| | | status: 'success' |
| | | }; |
| | | this.photoList = [...this.photoList, mockFile]; |
| | | this.$refs.form.validateField('photos'); |
| | | }, |
| | | handleSpectrumChange(file, fileList) { |
| | | this.spectrumList = fileList; |
| | | // 模拟上传成功 |
| | | const mockFile = { |
| | | name: file.name || '测试图谱.pdf', |
| | | url: 'https://example.com/test.pdf', |
| | | status: 'success' |
| | | }; |
| | | this.spectrumList = [...this.spectrumList, mockFile]; |
| | | this.$refs.form.validateField('spectrums'); |
| | | }, |
| | | handleSpectrumRemove(file) { |
| | |
| | | }, |
| | | // iPad 相关方法 |
| | | handleIPadPhoto() { |
| | | // TODO: 调用 iPad 拍照功能 |
| | | console.log('调用 iPad 拍照功能'); |
| | | // 模拟 iPad 拍照功能 |
| | | const mockFile = { |
| | | name: 'iPad拍照.jpg', |
| | | url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', |
| | | status: 'success' |
| | | }; |
| | | this.photoList = [...this.photoList, mockFile]; |
| | | this.$refs.form.validateField('photos'); |
| | | }, |
| | | handleIPadUpload() { |
| | | // TODO: 调用 iPad 上传功能 |
| | | console.log('调用 iPad 上传功能'); |
| | | // 模拟 iPad 上传功能 |
| | | const mockFile = { |
| | | name: 'iPad上传图片.jpg', |
| | | url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', |
| | | status: 'success' |
| | | }; |
| | | this.photoList = [...this.photoList, mockFile]; |
| | | this.$refs.form.validateField('photos'); |
| | | }, |
| | | handleIPadSpectrum() { |
| | | // TODO: 调用 iPad 选择图谱功能 |
| | | console.log('调用 iPad 选择图谱功能'); |
| | | // 模拟 iPad 选择图谱功能 |
| | | const mockFile = { |
| | | name: 'iPad图谱.pdf', |
| | | url: 'https://example.com/test.pdf', |
| | | status: 'success' |
| | | }; |
| | | this.spectrumList = [...this.spectrumList, mockFile]; |
| | | this.$refs.form.validateField('spectrums'); |
| | | } |
| | | } |
| | | }; |