Browse Source

巡检图片上传

seimin 3 months ago
parent
commit
f32b9fef4c

+ 32 - 18
components/DsFilePicker.vue

@@ -3,16 +3,19 @@
3 3
 </template>
4 4
 
5 5
 <script setup>
6
-  import { defineEmits, ref, reactive, defineProps } from 'vue'
6
+  import { defineEmits, ref, reactive, defineProps, defineExpose } from 'vue'
7 7
   import { onLoad } from '@dcloudio/uni-app'
8 8
   import { useLoginUserStore } from '@/stores/loginUser'
9 9
   import { useUploadFile } from '@/share/useUploadFile.js'
10 10
 
11 11
   const emit = defineEmits(['cancelEmit', 'knowEmit']);
12
-  const { inspectionExecuteId } = defineProps({
12
+  const { inspectionExecuteId, extra } = defineProps({
13 13
     inspectionExecuteId: {
14 14
       type: Number,
15
-    }
15
+    },
16
+    extra: {
17
+      type: Number,
18
+    },
16 19
   });
17 20
   const loginUserStore = useLoginUserStore();
18 21
   const { uploadFile }  = useUploadFile();
@@ -24,11 +27,22 @@
24 27
   
25 28
   // 处理图片
26 29
   const handlerImgRef = ref(null)
27
-  // handlerImgRef.value.upload();
30
+  
31
+  // 上传图片
32
+  const uploadFn = () => {
33
+    handlerImgRef.value.upload();
34
+  }
35
+  
36
+  defineExpose({
37
+    uploadFn,
38
+    baseFormData,
39
+    extra,
40
+    inspectionExecuteId,
41
+  })
28 42
   
29 43
   // 处理图片
30 44
   function handlerOrderImg(imgObj){
31
-    return uploadFile(imgObj, 'incident', inspectionExecuteId.value)
45
+    return uploadFile(imgObj, 'inspection', inspectionExecuteId, extra)
32 46
   }
33 47
   
34 48
   // 上传报修图片成功
@@ -46,18 +60,18 @@
46 60
     })
47 61
     
48 62
     Promise.all(requestList).then(resList => {
49
-      uni.hideLoading();
50
-      console.log(resList);
51
-      uni.showToast({
52
-      	icon: 'none',
53
-        title: '建单成功',
54
-        mask: true,
55
-      });
56
-      setTimeout(() => {
57
-        uni.reLaunch({
58
-          url: '/pages/incidentList/incidentList',
59
-        })
60
-      }, 1500)
63
+      // uni.hideLoading();
64
+      // console.log(resList);
65
+      // uni.showToast({
66
+      // 	icon: 'none',
67
+      //   title: '建单成功',
68
+      //   mask: true,
69
+      // });
70
+      // setTimeout(() => {
71
+      //   uni.reLaunch({
72
+      //     url: '/pages/incidentList/incidentList',
73
+      //   })
74
+      // }, 1500)
61 75
     })
62 76
   }
63 77
   
@@ -79,7 +93,7 @@
79 93
   }
80 94
   
81 95
   onLoad((option) => {
82
-    console.log(inspectionExecuteId)
96
+    console.log(extra)
83 97
   })
84 98
 </script>
85 99
 

+ 6 - 2
http/api.js

@@ -161,8 +161,12 @@ export function api_workHourManagement(data){
161 161
 /**
162 162
  * 上传附件
163 163
  */
164
-export function api_uploadAttachment(type, id){
165
-  return `${path}/common/common/uploadAttachment/${type}/${id}/${id}`
164
+export function api_uploadAttachment(type, id, extra){
165
+  if(extra){
166
+    return `${path}/common/common/uploadAttachment/${type}/${id}/${extra}`
167
+  }else{
168
+    return `${path}/common/common/uploadAttachment/${type}/${id}/${id}`
169
+  }
166 170
 }
167 171
 
168 172
 /**

+ 92 - 58
pages/inspection/inspectionValue/inspectionValue.vue

@@ -7,7 +7,7 @@
7 7
           <uni-forms-item v-if="item.type === '1'" class="formItem" :required="item.required" :name="item.key">
8 8
             <template v-slot:label>
9 9
               <view class="customLabelWrap">
10
-                <text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
10
+                <text :class="{'is-required': item.required}">*</text><text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
11 11
               </view>
12 12
             </template>
13 13
             <uni-data-picker :placeholder="'请选择' + item.name" :popup-title="'请选择' + item.name" :localdata="item.list" v-model="formValues[item.key]" @change="changeForm()">
@@ -17,7 +17,7 @@
17 17
           <uni-forms-item v-if="item.type === '2'" class="formItem" :required="item.required" :name="item.key">
18 18
             <template v-slot:label>
19 19
               <view class="customLabelWrap">
20
-                <text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
20
+                <text :class="{'is-required': item.required}">*</text><text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
21 21
               </view>
22 22
             </template>
23 23
             <uni-data-checkbox v-model="formValues[item.key]" @change="changeForm()" :localdata="item.list" />
@@ -26,7 +26,7 @@
26 26
           <uni-forms-item v-if="item.type === '3'" class="formItem" :required="item.required" :name="item.key">
27 27
             <template v-slot:label>
28 28
               <view class="customLabelWrap">
29
-                <text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
29
+                <text :class="{'is-required': item.required}">*</text><text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
30 30
               </view>
31 31
             </template>
32 32
             <uni-data-checkbox v-model="formValues[item.key]" @change="changeForm()" multiple :localdata="item.list" />
@@ -35,7 +35,7 @@
35 35
           <uni-forms-item v-if="item.type === '4'" class="formItem" :required="item.required" :name="item.key">
36 36
             <template v-slot:label>
37 37
               <view class="customLabelWrap">
38
-                <text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
38
+                <text :class="{'is-required': item.required}">*</text><text class="customLabel">{{item.name}}</text><text v-if="item.isException" class="customLabel red">&nbsp;异</text>
39 39
               </view>
40 40
             </template>
41 41
             <uni-number-box v-model="formValues[item.key]" @change="changeForm()" :min="-9999" :max="9999" :placeholder="'请输入' + item.name"></uni-number-box>
@@ -50,7 +50,7 @@
50 50
           </uni-forms-item>
51 51
           <!-- 图片上传 -->
52 52
           <uni-forms-item v-if="item.type === '7' && item.isException" class="formItem" :label="item.name" :required="item.required" :name="item.key">
53
-            <DsFilePicker v-model="formValues[item.key]"></DsFilePicker>
53
+            <DsFilePicker :extra="item.id" :inspectionExecuteId="inspectionExecuteId" :ref="(el) => itemRefs[item.id] = el"></DsFilePicker>
54 54
           </uni-forms-item>
55 55
           <!-- 分割线 -->
56 56
           <view class="detail_head" v-if="item.type === '8'">
@@ -70,7 +70,7 @@
70 70
   import fromPairs from 'lodash-es/fromPairs'
71 71
   import keyBy from 'lodash-es/keyBy'
72 72
   import DsFilePicker from '@/components/DsFilePicker.vue';
73
-  import { ref, reactive } from 'vue'
73
+  import { ref, reactive, nextTick } from 'vue'
74 74
   import { onLoad } from '@dcloudio/uni-app'
75 75
   import { api_addModel } from "@/http/api.js"
76 76
   import { defaultColor } from '@/static/js/theme.js'
@@ -79,7 +79,7 @@
79 79
   import { useGoBack } from '@/share/useGoBack.js'
80 80
   import { useLoginUserStore } from '@/stores/loginUser'
81 81
   import { useInspectionValueStore } from '@/stores/inspectionValue'
82
-import { forIn } from 'lodash-es';
82
+  import { forIn } from 'lodash-es';
83 83
 
84 84
   useSetTitle();
85 85
   const loginUserStore = useLoginUserStore();
@@ -94,6 +94,9 @@ import { forIn } from 'lodash-es';
94 94
 
95 95
   // 表单
96 96
   const baseForm = ref()
97
+  
98
+  // 图片上传ref数组
99
+  const itemRefs = ref({});
97 100
 
98 101
   const inspectionExecuteId = ref()
99 102
 
@@ -132,57 +135,81 @@ import { forIn } from 'lodash-es';
132 135
 
133 136
   // 保存
134 137
   function submit(){
135
-    baseForm.value.validate().then(res => {
136
-      console.log('success', res);
137
-      uni.showLoading({
138
-        title: "加载中",
139
-        mask: true,
140
-      });
141
-      console.log(formValues);
142
-      let postData = {
143
-        account: loginUserStore.loginUser.user.account,
144
-        valuesList: [],
145
-      };
146
-      // baseFormData
147
-      for(let key in formValues){
148
-        let obj = baseFormData.find(v => v.key === key);
149
-        if(!((obj.type === '5' && !obj.isException) || (obj.type === '6' && !obj.isException) || (obj.type === '7' && !obj.isException))){
150
-          let name = obj.name;
151
-          let itemId = obj.id;
152
-          let _formPageList = dataInfo.inspectionFormDTO?.formPageList || [];
153
-          _formPageList = _formPageList.map(v => v.formItemList).flat();
154
-          let formItem = _formPageList.find(v => v.id === itemId);
155
-          postData.valuesList.push({
156
-            taskId: inspectionExecuteId.value,
157
-            nodeId: dataInfo.id,
158
-            formId: dataInfo.inspectionFormDTO.id,
159
-            itemId: formItem.id,
160
-            pageId: formItem.pageId,
161
-            orders: formItem.orders,
162
-            name,
163
-            valuex: (formItem.type.value === '1' || formItem.type.value === '2' || formItem.type.value === '3') ? '' : formValues[key].toString(),
164
-            configIds: (formItem.type.value === '1' || formItem.type.value === '2' || formItem.type.value === '3') ? formValues[key].toString() : undefined,
165
-            hosId: dataInfo.inspectionFormDTO.hosId,
166
-          })
167
-        }
138
+    console.log(itemRefs.value);
139
+    console.log(formValues);
140
+    console.log(baseFormData);
141
+    // 处理图片上传检验问题
142
+    Object.values(itemRefs.value).forEach(v => {
143
+      console.log(v.inspectionExecuteId);
144
+      console.log(v.extra);
145
+      if(v && v.baseFormData.handlerImgList.length){
146
+        baseFormData.forEach(vv => {
147
+          if(vv.id == v.extra){
148
+            formValues[vv.key] = v.inspectionExecuteId;
149
+            vv.value = v.inspectionExecuteId;
150
+          }
151
+        })
168 152
       }
169
-      console.log(postData);
170
-      api_addModel(postData).then((res) => {
171
-        uni.hideLoading();
172
-        if (res.status == 200) {
173
-          inspectionValueStore.clearInspectionValueData();
174
-          uni.reLaunch({
175
-            url: `/pages/inspection/inspectionExecute/inspectionExecute`
176
-          })
177
-        } else {
178
-          uni.showToast({
179
-            icon: 'none',
180
-            title: res.msg || '请求数据失败!'
181
-          });
153
+    })
154
+    
155
+    nextTick(() => {
156
+      baseForm.value.validate().then(res => {
157
+        console.log('success', res);
158
+        uni.showLoading({
159
+          title: "加载中",
160
+          mask: true,
161
+        });
162
+        console.log(formValues);
163
+        let postData = {
164
+          account: loginUserStore.loginUser.user.account,
165
+          valuesList: [],
166
+        };
167
+        // baseFormData
168
+        for(let key in formValues){
169
+          let obj = baseFormData.find(v => v.key === key);
170
+          if(!((obj.type === '5' && !obj.isException) || (obj.type === '6' && !obj.isException) || (obj.type === '7' && !obj.isException))){
171
+            let name = obj.name;
172
+            let itemId = obj.id;
173
+            let _formPageList = dataInfo.inspectionFormDTO?.formPageList || [];
174
+            _formPageList = _formPageList.map(v => v.formItemList).flat();
175
+            let formItem = _formPageList.find(v => v.id === itemId);
176
+            postData.valuesList.push({
177
+              taskId: inspectionExecuteId.value,
178
+              nodeId: dataInfo.id,
179
+              formId: dataInfo.inspectionFormDTO.id,
180
+              itemId: formItem.id,
181
+              pageId: formItem.pageId,
182
+              orders: formItem.orders,
183
+              name,
184
+              valuex: (formItem.type.value === '1' || formItem.type.value === '2' || formItem.type.value === '3') ? '' : formValues[key].toString(),
185
+              configIds: (formItem.type.value === '1' || formItem.type.value === '2' || formItem.type.value === '3') ? formValues[key].toString() : undefined,
186
+              hosId: dataInfo.inspectionFormDTO.hosId,
187
+            })
188
+          }
182 189
         }
183
-      });
184
-    }).catch(err => {
185
-      console.log('err', err);
190
+        console.log(postData);
191
+        console.log(itemRefs.value);
192
+        // return;
193
+        api_addModel(postData).then((res) => {
194
+          uni.hideLoading();
195
+          if (res.status == 200) {
196
+            Object.values(itemRefs.value).forEach(v => {
197
+              v && v.uploadFn();
198
+            })
199
+            inspectionValueStore.clearInspectionValueData();
200
+            uni.reLaunch({
201
+              url: `/pages/inspection/inspectionExecute/inspectionExecute`
202
+            })
203
+          } else {
204
+            uni.showToast({
205
+              icon: 'none',
206
+              title: res.msg || '请求数据失败!'
207
+            });
208
+          }
209
+        });
210
+      }).catch(err => {
211
+        console.log('err', err);
212
+      })
186 213
     })
187 214
   }
188 215
 
@@ -232,11 +259,11 @@ import { forIn } from 'lodash-es';
232 259
       }
233 260
     });
234 261
 
235
-    let firstPageBottom = firstPage.filter(v => v.type === '5' || v.type === '6');
262
+    let firstPageBottom = firstPage.filter(v => v.type === '5' || v.type === '6' || v.type === '7');
236 263
     firstPage = firstPage.filter(v => v.type !== '5' && v.type !== '6' && v.type !== '7');
237 264
 
238 265
     // 其他项
239
-    if(isException){
266
+    if(!isException){
240 267
       firstPage.forEach(v => {
241 268
         // 下拉,单选
242 269
         if(v.type === '1' || v.type === '2'){
@@ -320,6 +347,13 @@ import { forIn } from 'lodash-es';
320 347
 </script>
321 348
 
322 349
 <style lang="scss" scoped>
350
+.customLabelWrap{
351
+  .is-required{
352
+    color: #dd524d;
353
+    font-weight: bold;
354
+    margin-top: 8rpx;
355
+  }
356
+}
323 357
 .inspectionValue{
324 358
   height: 100%;
325 359
   display: flex;

+ 3 - 3
share/useUploadFile.js

@@ -42,13 +42,13 @@ export function useUploadFile() {
42 42
   /**
43 43
    * 上传图片
44 44
    */
45
-  const uploadFile = async (imgObj, type, incidentId) => {
45
+  const uploadFile = async (imgObj, type, incidentId, extra) => {
46 46
 		console.log('44444', type)
47 47
 		if(imgObj.extname=='mp4' || imgObj.extname=='avi' || imgObj.extname=='mpeg' || 
48 48
 			imgObj.extname=='wmv' || imgObj.extname=='mov' || imgObj.extname=='3gp' ||
49 49
 			imgObj.extname=='flv' || imgObj.extname=='mkv'){
50 50
 			return uni.uploadFile({
51
-			  url: api_uploadAttachment(type, incidentId),
51
+			  url: api_uploadAttachment(type, incidentId, extra),
52 52
 			  filePath: imgObj.path,
53 53
 			  name: 'file',
54 54
 			  formData: {
@@ -74,7 +74,7 @@ export function useUploadFile() {
74 74
 			let tp = window.URL.createObjectURL(fileSrc)
75 75
 			console.log('压缩后', tp);
76 76
 			return uni.uploadFile({
77
-			  url: api_uploadAttachment(type, incidentId),
77
+			  url: api_uploadAttachment(type, incidentId, extra),
78 78
 			  filePath: tp,
79 79
 			  name: 'file',
80 80
 			  formData: {