Browse Source

实际地类、核查初判字典查询接口联调

maxiaoxiao 4 months ago
parent
commit
46d142982a
2 changed files with 292 additions and 53 deletions
  1. 109 53
      pages/index/common/hcDetails.vue
  2. 183 0
      utils/choose.js

+ 109 - 53
pages/index/common/hcDetails.vue

@@ -71,24 +71,25 @@
 			</view>
 			<view class="hclist" v-if="active==2">
 				<view class="example-body">
-					<uni-file-picker v-model="fileList" limit="9" title="最多选择9张图片"></uni-file-picker>
+					<uni-file-picker ref="upsgfjsRef" limit="9" title="最多选择9张图片" @select="e=>selectfile(e,'sgfjs')"
+						@delete="e=>fileDelete(e,'sgfjs')"></uni-file-picker>
 				</view>
 
 			</view>
 			<view class="hclist" v-if="active==3">
-				<uni-forms ref="form" :model="checkform" labelWidth="80px">
-					<uni-forms-item label="实际地类" name="nickName">
-						<uni-data-select v-model="checkform.phonenumber" :localdata="range"></uni-data-select>
+				<uni-forms ref="checkRef" :model="checkform" labelWidth="80px">
+					<uni-forms-item label="实际地类" name="dlbm">
+						<uni-data-select v-model="checkform.dlbm" :localdata="decList"></uni-data-select>
 					</uni-forms-item>
-					<uni-forms-item label="核查初判" name="phonenumber">
-						<uni-data-select v-model="checkform.phonenumber" :localdata="range"></uni-data-select>
+					<uni-forms-item label="核查初判" name="decide">
+						<uni-data-select v-model="checkform.decide" :localdata="hgxList"></uni-data-select>
 					</uni-forms-item>
-					<uni-forms-item label="其它材料" name="email">
-						<uni-file-picker v-model="checkform.fileList" title="添加照片或文件"></uni-file-picker>
-
+					<uni-forms-item label="其它材料" name="fjs">
+						<uni-file-picker ref="upfjsRef" title="添加照片或文件" @select="e=>selectfile(e,'fjs')"
+							@delete="e=>fileDelete(e,'fjs')"></uni-file-picker>
 					</uni-forms-item>
-					<uni-forms-item label="其它说明" name="sex" required>
-						<uni-easyinput v-model="checkform.phonenumber" type="textarea" placeholder="请输入其它说明" />
+					<uni-forms-item label="其它说明" name="notes" required>
+						<uni-easyinput v-model="checkform.notes" type="textarea" placeholder="请输入其它说明" />
 					</uni-forms-item>
 				</uni-forms>
 			</view>
@@ -108,19 +109,24 @@
 
 </template>
 <script>
+	import {
+		uploadFile
+	} from '@/utils/choose.js'
 	import {
 		getDkjbxx,
 		getDkjbywy,
 		getStep,
 		hcWork,
 		getHcInfo,
-		tjWork,
-		getTjInfo
+		getdecTree,
 	} from "@/api/dkjbxx.js";
+	import {
+		getdict
+	} from "@/api/apis.js";
+
 	import {
 		jbxxs,
 		tdxzTable,
-
 	} from "../config";
 	export default {
 		name: "list",
@@ -142,28 +148,25 @@
 				ywyptab: "1",
 				sheets: [],
 				//上传拍照
-				fileList: [],
+				fileList: {},
 				checkform: {},
-				range: [{
-						value: 0,
-						text: "篮球"
-					},
-					{
-						value: 1,
-						text: "足球"
-					},
-					{
-						value: 2,
-						text: "游泳"
-					},
-				],
+				decList: [],
+				hgxList: []
 
 			};
 		},
-		mounted() {},
+		mounted() {
+			// this.getsteps()
+		},
 		methods: {
 			handleClick(val) {
 				this.nowobj = val
+				this.getsteps();
+				this.reset();
+				this.getInfos(val);
+				this.getdict()
+			},
+			getInfos(val) {
 				let id = val.dkjdxxId
 				getDkjbxx(id).then((res) => {
 					this.infoObj = res.data;
@@ -173,41 +176,72 @@
 						this.sheets = JSON.parse(res.data.sheetJson);
 						this.ywyptab = this.sheets[0].sheet;
 					}
-					console.log(this.sheets);
-				});
-				this.steps = [];
-				getStep({
-					dkjdxxId: id
-				}).then((res) => {
-					this.steps = res.data;
-					this.qrdis = this.steps.find((x) => x.auditflowStep.includes('WYQR'))
-					this.tjdis = this.steps.find((x) => x.auditflowStep.includes('TJ'))
-
 				});
 				getHcInfo({
-					dkid: id,
+					dkid: this.nowobj.dkjdxxId,
 					auditflowStep: 'WYDC',
-					auditflowId: '',
-					fieldworkId: ''
+					auditflowId: this.nowobj.auditflowId,
+					fieldworkId: this.nowobj.id,
 
 				}).then((res) => {
-					this.checkform = res.data || {};
+					if (res.data)
+						this.checkform = res.data
 				});
-				getTjInfo({
-					dkid: id,
-					auditflowStep: 'WYTJ',
-					auditflowId: '',
-					fieldworkId: ''
+			},
+			getdict() {
+				this.decList = [];
+				this.hgxList = [];
+				getdecTree({
+					dictType: '3DDLBM'
+				}).then((res) => {
+					res.data.map(di => {
+						this.decList.push({
+							value: di.dictCode,
+							text: di.dictLabel
+						})
+					})
 
+				});
+				getdict({
+					dictType: 'hgx_decide'
 				}).then((res) => {
-					// this.tjinfo = res.data;
+					res.rows.map(di => {
+						this.hgxList.push({
+							value: di.dictCode,
+							text: di.dictLabel
+						})
+					})
 				});
 			},
 			returnList() {
 				this.$emit('returnList')
 			},
-			reset() {
+			getsteps() {
+				this.steps = [];
+				getStep({
+					dkjdxxId: this.nowobj.dkjdxxId
+				}).then((res) => {
+					this.steps = res.data;
+					this.qrdis = this.steps.find((x) => x.auditflowStep.includes('WYQR'))
+					this.tjdis = this.steps.find((x) => x.auditflowStep.includes('TJ'))
 
+				});
+			},
+			reset() {
+				this.checkform = {
+					fieldworkId: this.nowobj.id,
+					dlbm: "",
+					dlmc: "",
+					decide: "",
+					notes: "",
+					auditflowStep: "WYDC",
+					fjs: [],
+					sdfjs: []
+				}
+				this.fileList= {
+					fjs: [],
+					sdfjs: []
+				}
 			},
 			afterRead(files, detail) {
 				// files.forEach(element => {
@@ -221,15 +255,37 @@
 			},
 			affirm(confirmState) {
 				uni.$globalData = this.nowobj
-				this.$tab.navigateTo('/pages/index/common/edit?confirmState=' + confirmState)
+				this.$tab.navigateTo('/pages/index/common/affirm?confirmState=' + confirmState)
+			},
+			save() {
+				let a = this.decList.find(d => d.value == this.checkform.dlbm)
+				if (a) this.checkform.dlmc = a.text;
+
+				this.$refs.checkRef.validate().then(res => {
+					hcWork(this.checkform).then(response => {
+						this.$modal.msgSuccess("保存成功")
+						this.getsteps()
+					})
+				})
 			},
 			tj() {
 				uni.$globalData = this.nowobj
 				this.$tab.navigateTo('/pages/index/common/tjDialog')
 			},
+			selectfile(e, fname) {
+				e.tempFilePaths.map(item => {
+					this.fileList[fname].push(item)
+					uploadFile(item, (data) => {
+						this.checkform[fname].push(data);
+					})
 
-
-
+				})
+			},
+			fileDelete(e, fname) {
+				let index = this.fileList[fname].indexOf(e.tempFilePath)
+				this.fileList[fname].splice(index, 1)
+				this.checkform[fname].splice(index, 1);
+			}
 		},
 	};
 </script>

+ 183 - 0
utils/choose.js

@@ -0,0 +1,183 @@
+import config from '@/config'
+import {
+	uplaodfile
+} from "@/api/apis.js";
+import {
+	getToken
+} from '@/utils/auth'
+// 选择图片
+export function chooseImage() {
+	uni.chooseImage({
+		sourceType: ['album', 'camera'], // 使用相机拍照
+		camera: 'back', // 默认使用后置摄像头,可选值有front、back
+		success: (res) => {
+			console.log('拍照成功:', res);
+			// 处理图片,例如预览图片或上传到服务器
+			// upload(res)
+			let file = res.tempFiles[0];
+			var formData = new FormData();
+			formData.append('file', file)
+			uplaodfile(formData).then(a => {
+				console.log(aaa)
+			})
+		},
+		fail: (err) => {
+			console.error('拍照失败:', err);
+		}
+	});
+}
+export function upload(res) {
+	let file = res.tempFiles[0];
+	var formData = new FormData();
+	formData.append('file', file)
+	var requestOptions = {
+		method: 'post',
+		headers: {
+			Authorization: 'Bearer ' + getToken()
+		},
+		body: formData,
+	};
+	fetch(
+			config.uploadUrl + '/file/upload/v1',
+			requestOptions
+		)
+		.then((response) => {
+			return response.json();
+		}).then(res => {
+			console.log(res);
+			if (res.code == '1000') {
+				uni.showToast({
+					title: res.message,
+				})
+			} else {
+				uni.showToast({
+					title: res.message,
+					icon: 'error'
+				})
+			}
+		})
+
+
+}
+// 选择视频
+export function chooseVideo() {
+	uni.chooseVideo({
+		sourceType: ['album', 'camera'], // 使用相机录像
+		camera: 'back', // 默认使用后置摄像头,可选值有front、back
+		maxDuration: 60, // 最大录制时长(秒)
+		success: (res) => {
+			console.log('视频录制成功:', res);
+			// 处理视频,例如将视频路径显示在页面上
+		},
+		fail: (err) => {
+			console.error('视频录制失败:', err);
+		}
+	});
+}
+
+
+// 选择照片或视频
+export function chooseMedia() {
+	uni.chooseMedia({
+		count: 9, // 默认为9, 设置为1时只能选择一个文件
+		mediaType: ['image', 'video'], // 选择媒体类型,可以是'image'或'video'
+		sourceType: ['album', 'camera'], // 可选择来源是相册还是相机
+		success: (res) => {
+			res.tempFiles.forEach(element => {
+				const tempFilePaths = element.tempFilePath;
+				// 上传文件到服务器
+				uploadFile(tempFilePaths);
+			});
+
+		},
+		fail: (err) => {
+			console.log('选择媒体失败:', err);
+		}
+	});
+}
+
+
+export function getFile(filePath) {
+	const fileManager = uni.getFileSystemManager();
+	fileManager.readFile({
+		filePath: filePath, // 需要读文件的路径
+		encoding: 'base64', // 编码格式,此处以base64为例,也可以使用'binary'等其他格式
+		success: (res) => {
+			console.error('读取文件成功:', res.data);
+			uploadFile(res.data); // 调用上传方法,传入文件内容
+		},
+		fail: (error) => {
+			console.error('读取文件失败:', error);
+		}
+	});
+}
+export function requestFile(filePath) {
+	// const blob = new Blob([res.data]);
+	// files: [formData],
+	// create: true
+	plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, (fs) => {
+		fs.root.getFile(filePath, {}, (fileEntry) => {
+			fileEntry.file((file) => {
+
+				console.log("文件大小:", file);
+				//创建读取文件对象
+				let fileReader = new plus.io.FileReader();
+				//以文本格式读取文件数据内容
+				// fileReader.readAsText(file, 'utf-8');
+				//文件读取操作完成时的回调函数
+				fileReader.readAsArrayBuffer(file);
+				console.log("aaaa:", fileReader);
+				fileReader.onloadend = (evt) => {
+					console.log("文件:", evt);
+					var fileData = new FormData();
+					fileData.append('file', new Blob([evt], {
+						type: file.type
+					}));
+					// console.log(JSON.parse(evt.target.result),
+					// 	'JSON.parse(evt.target.result)')
+					// resolve(JSON.parse(evt.target.result))
+					// sURL = JSON.parse(evt.target.result).URL;
+
+				}
+			});
+
+			// fileEntry.createWriter((writer) => {
+			// 	writer.write(new Blob(['Hello, UniApp!'], {
+			// 		type: 'text/plain'
+			// 	}));
+			// });
+		});
+	});
+}
+
+
+
+
+// 上传文件到服务器
+export function uploadFile(filePath) {
+	uni.uploadFile({
+		url: config.baseUrl + '/file/upload/v1', // 你的上传API地址
+		filePath,
+		name: 'file', // 必须填写,后台用来接收文件
+		header: {
+			"Content-Type": "multipart/form-data;",
+			Authorization: 'Bearer ' + getToken()
+		},
+		success: (e) => {
+			if (e.data.code == 200) {
+				console.log('上传成功', e.data.data.path, e.data.data.url)
+			} else {
+				uni.showToast({
+					title: '上传附件失败,请稍候再试!',
+					duration: 1000,
+					icon: 'none'
+				});
+			}
+		},
+		fail: (uploadFileErr) => {
+			console.log('上传失败:', uploadFileErr);
+			return;
+		},
+
+	});
+}