Browse Source

核查信息详情处理、上传图片处理

maxiaoxiao 1 week ago
parent
commit
983c19b681
2 changed files with 38 additions and 16 deletions
  1. 32 13
      pages/index/common/hcDetails.vue
  2. 6 3
      utils/choose.js

+ 32 - 13
pages/index/common/hcDetails.vue

@@ -69,14 +69,14 @@
 					</view>
 				</view>
 			</view>
-			<view class="hclist" v-if="active==2">
+			<view class="hclist" v-show="active==2">
 				<view class="example-body">
-					<uni-file-picker ref="upsgfjsRef" limit="9" title="最多选择9张图片" @select="e=>selectfile(e,'sgfjs')"
-						@delete="e=>fileDelete(e,'sgfjs')"></uni-file-picker>
+					<uni-file-picker ref="upsgfjsRef" limit="9" title="最多选择9张图片" v-model="fileList.sgfjs"
+						@select="e=>selectfile(e,'sgfjs')" @delete="e=>fileDelete(e,'sgfjs')"></uni-file-picker>
 				</view>
 
 			</view>
-			<view class="hclist" v-if="active==3">
+			<view class="hclist" v-show="active==3">
 				<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>
@@ -85,8 +85,8 @@
 						<uni-data-select v-model="checkform.decide" :localdata="hgxList"></uni-data-select>
 					</uni-forms-item>
 					<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-file-picker ref="upfjsRef" title="添加照片或文件" v-model="fileList.fjs"
+							@select="e=>selectfile(e,'fjs')" @delete="e=>fileDelete(e,'fjs')"></uni-file-picker>
 					</uni-forms-item>
 					<uni-forms-item label="其它说明" name="notes" required>
 						<uni-easyinput v-model="checkform.notes" type="textarea" placeholder="请输入其它说明" />
@@ -181,11 +181,25 @@
 					dkid: this.nowobj.dkjdxxId,
 					auditflowStep: 'WYDC',
 					auditflowId: this.nowobj.auditflowId,
-					fieldworkId: this.nowobj.id,
+					// fieldworkId: this.nowobj.id,
 
 				}).then((res) => {
-					if (res.data)
-						this.checkform = res.data
+					if (res.data) {
+						this.checkform = res.data[0]
+						this.checkform.fjs.map(f =>
+							_this.fileList.fjs.push({
+								name: 'fjsimg',
+								url: f.url
+							})
+						)
+						this.checkform.sgfjs.map(f =>
+							_this.fileList.sgfjs.push({
+								name: 'sgfjsimg',
+								url: f.url
+							})
+						)
+					}
+
 				});
 			},
 			getdict() {
@@ -238,7 +252,7 @@
 					fjs: [],
 					sdfjs: []
 				}
-				this.fileList= {
+				this.fileList = {
 					fjs: [],
 					sdfjs: []
 				}
@@ -273,16 +287,21 @@
 				this.$tab.navigateTo('/pages/index/common/tjDialog')
 			},
 			selectfile(e, fname) {
+				let _this = this
 				e.tempFilePaths.map(item => {
-					this.fileList[fname].push(item)
+					_this.fileList[fname].push({
+						name: fname + 'img',
+						url: item
+					})
 					uploadFile(item, (data) => {
-						this.checkform[fname].push(data);
+						if (data) _this.checkform[fname].push(data);
+						else _this.fileList[fname].pop()
 					})
 
 				})
 			},
 			fileDelete(e, fname) {
-				let index = this.fileList[fname].indexOf(e.tempFilePath)
+				let index = this.fileList[fname].findInex(f => f.url == e.tempFilePath)
 				this.fileList[fname].splice(index, 1)
 				this.checkform[fname].splice(index, 1);
 			}

+ 6 - 3
utils/choose.js

@@ -154,7 +154,7 @@ export function requestFile(filePath) {
 
 
 // 上传文件到服务器
-export function uploadFile(filePath) {
+export function uploadFile(filePath, fun) {
 	uni.uploadFile({
 		url: config.baseUrl + '/file/upload/v1', // 你的上传API地址
 		filePath,
@@ -164,14 +164,17 @@ export function uploadFile(filePath) {
 			Authorization: 'Bearer ' + getToken()
 		},
 		success: (e) => {
-			if (e.data.code == 200) {
-				console.log('上传成功', e.data.data.path, e.data.data.url)
+			let res = JSON.parse(e.data)
+			if (res.code == 200) {
+				console.log('上传成功', res.data.path, res.data.url)
+				fun(res.data);
 			} else {
 				uni.showToast({
 					title: '上传附件失败,请稍候再试!',
 					duration: 1000,
 					icon: 'none'
 				});
+				fun();
 			}
 		},
 		fail: (uploadFileErr) => {