Ver código fonte

feat(订单详情): 实现文件ID同步更新功能

添加文件ID更新处理逻辑,确保在图片上传、删除、排序和隐藏操作后同步更新fileIds
将"一键复制"按钮文案改为"一键保存"
Yannay 1 mês atrás
pai
commit
d0ab09257f

+ 12 - 0
pages/orderDetailRefactored/components/OrderDetailView.vue

@@ -23,6 +23,7 @@
23
         :current-receipt="currentReceipt"
23
         :current-receipt="currentReceipt"
24
         :follow-up-list="followUpList"
24
         :follow-up-list="followUpList"
25
         @next="handleNext"
25
         @next="handleNext"
26
+        @update-file-ids="handleUpdateFileIds"
26
       />
27
       />
27
     </view>
28
     </view>
28
     
29
     
@@ -37,6 +38,7 @@
37
         @next="handleNext"
38
         @next="handleNext"
38
         @save="handleNeedSave"
39
         @save="handleNeedSave"
39
         @confirm-pay="handleConfirmPay"
40
         @confirm-pay="handleConfirmPay"
41
+        @update-file-ids="handleUpdateFileIds"
40
         ref="pageThreeRef"
42
         ref="pageThreeRef"
41
       />
43
       />
42
     </view>
44
     </view>
@@ -245,6 +247,16 @@ export default {
245
       if (index === 2 && this.$refs.pageThreeRef) {
247
       if (index === 2 && this.$refs.pageThreeRef) {
246
         this.$refs.pageThreeRef.refreshImageList()
248
         this.$refs.pageThreeRef.refreshImageList()
247
       }
249
       }
250
+    },
251
+
252
+    /**
253
+     * 更新 fileIds
254
+     */
255
+    handleUpdateFileIds(fileIds) {
256
+      if (this.currentReceipt) {
257
+        this.$set(this.currentReceipt, 'fileIds', fileIds)
258
+        this.fileIds = fileIds
259
+      }
248
     }
260
     }
249
   }
261
   }
250
 }
262
 }

+ 40 - 5
pages/orderDetailRefactored/components/PageThree.vue

@@ -266,6 +266,25 @@ export default {
266
           this.orderDetail.itemBrand,
266
           this.orderDetail.itemBrand,
267
           this.currentReceipt.clueId
267
           this.currentReceipt.clueId
268
         )
268
         )
269
+        
270
+        // 按照 fileIds 排序
271
+        if (this.currentReceipt.fileIds && list && list.length > 0) {
272
+          const sortedIds = this.currentReceipt.fileIds.split(',')
273
+          list.sort((a, b) => {
274
+            const indexA = sortedIds.indexOf(a.id)
275
+            const indexB = sortedIds.indexOf(b.id)
276
+            
277
+            // 如果都不在列表中,保持原顺序
278
+            if (indexA === -1 && indexB === -1) return 0
279
+            // 如果 a 不在列表中,放到后面
280
+            if (indexA === -1) return 1
281
+            // 如果 b 不在列表中,放到后面
282
+            if (indexB === -1) return -1
283
+            // 都在列表中,按 index 排序
284
+            return indexA - indexB
285
+          })
286
+        }
287
+        
269
         this.detailImages = list || []
288
         this.detailImages = list || []
270
       } catch (error) {
289
       } catch (error) {
271
         console.error('加载细节图失败:', error)
290
         console.error('加载细节图失败:', error)
@@ -382,10 +401,12 @@ export default {
382
       this.resetDragState()
401
       this.resetDragState()
383
 
402
 
384
       //每次拖拽结束后把新的顺序传送给接口
403
       //每次拖拽结束后把新的顺序传送给接口
404
+      const fileIds = this.detailImages.map(item => item.id).join(',')
385
       await uni.$u.api.updateReceiptForm({
405
       await uni.$u.api.updateReceiptForm({
386
         id: this.currentReceipt.id,
406
         id: this.currentReceipt.id,
387
-        fileIds: this.detailImages.map(item => item.id).join(',')
407
+        fileIds: fileIds
388
       })
408
       })
409
+      this.$emit('update-file-ids', fileIds)
389
     },
410
     },
390
 
411
 
391
     /**
412
     /**
@@ -433,13 +454,15 @@ export default {
433
           '3',
454
           '3',
434
           uploadResults
455
           uploadResults
435
         )
456
         )
436
-        this.loadDetailImages()
457
+        await this.loadDetailImages()
437
 
458
 
438
         //上传新图片完成之后也要把新数据给接口
459
         //上传新图片完成之后也要把新数据给接口
460
+        const fileIds = this.detailImages.map(item => item.id).join(',')
439
         await uni.$u.api.updateReceiptForm({
461
         await uni.$u.api.updateReceiptForm({
440
           id: this.currentReceipt.id,
462
           id: this.currentReceipt.id,
441
-          fileIds: this.detailImages.map(item => item.id).join(',')
463
+          fileIds: fileIds
442
         })
464
         })
465
+        this.$emit('update-file-ids', fileIds)
443
 
466
 
444
       } catch (error) {
467
       } catch (error) {
445
         console.error('上传失败:', error)
468
         console.error('上传失败:', error)
@@ -449,11 +472,23 @@ export default {
449
     /**
472
     /**
450
      * 隐藏图片
473
      * 隐藏图片
451
      */
474
      */
452
-    handleHideImage(item, index) {
475
+    async handleHideImage(item, index) {
453
       const itemIndex = this.detailImages.findIndex(img => img.id === item.id || img.fileUrl === item.fileUrl)
476
       const itemIndex = this.detailImages.findIndex(img => img.id === item.id || img.fileUrl === item.fileUrl)
454
       if (itemIndex !== -1) {
477
       if (itemIndex !== -1) {
455
         this.detailImages.splice(itemIndex, 1)
478
         this.detailImages.splice(itemIndex, 1)
456
-        uni.$u.toast('图片已隐藏')
479
+        
480
+        // 更新 fileIds
481
+        const fileIds = this.detailImages.map(item => item.id).join(',')
482
+        try {
483
+          await uni.$u.api.updateReceiptForm({
484
+            id: this.currentReceipt.id,
485
+            fileIds: fileIds
486
+          })
487
+          this.$emit('update-file-ids', fileIds)
488
+          uni.$u.toast('图片已隐藏')
489
+        } catch (error) {
490
+          console.error('更新失败:', error)
491
+        }
457
       }
492
       }
458
     },
493
     },
459
 
494
 

+ 40 - 3
pages/orderDetailRefactored/components/PageTwo.vue

@@ -139,7 +139,7 @@
139
         <view class="detail-image-header">
139
         <view class="detail-image-header">
140
           <text class="detail-image-title">上传高清细节图(支持多选)</text>
140
           <text class="detail-image-title">上传高清细节图(支持多选)</text>
141
           <view class="copy-btn" @click="copyAllDetailImages">
141
           <view class="copy-btn" @click="copyAllDetailImages">
142
-            <text>一键复制</text>
142
+            <text>一键保存</text>
143
           </view>
143
           </view>
144
         </view>
144
         </view>
145
         <view class="detail-image-upload-container">
145
         <view class="detail-image-upload-container">
@@ -254,6 +254,25 @@ export default {
254
           this.orderDetail.itemBrand,
254
           this.orderDetail.itemBrand,
255
           this.currentReceipt.clueId
255
           this.currentReceipt.clueId
256
         )
256
         )
257
+        
258
+        // 按照 fileIds 排序
259
+        if (this.currentReceipt.fileIds && list && list.length > 0) {
260
+          const sortedIds = this.currentReceipt.fileIds.split(',')
261
+          list.sort((a, b) => {
262
+            const indexA = sortedIds.indexOf(a.id)
263
+            const indexB = sortedIds.indexOf(b.id)
264
+            
265
+            // 如果都不在列表中,保持原顺序
266
+            if (indexA === -1 && indexB === -1) return 0
267
+            // 如果 a 不在列表中,放到后面
268
+            if (indexA === -1) return 1
269
+            // 如果 b 不在列表中,放到后面
270
+            if (indexB === -1) return -1
271
+            // 都在列表中,按 index 排序
272
+            return indexA - indexB
273
+          })
274
+        }
275
+        
257
         this.detailImages = list || []
276
         this.detailImages = list || []
258
       } catch (error) {
277
       } catch (error) {
259
         console.error('加载细节图失败:', error)
278
         console.error('加载细节图失败:', error)
@@ -341,7 +360,16 @@ export default {
341
           '3',
360
           '3',
342
           uploadResults
361
           uploadResults
343
         )
362
         )
344
-        this.loadDetailImages()
363
+        await this.loadDetailImages()
364
+
365
+        // 更新 fileIds
366
+        const fileIds = this.detailImages.map(item => item.id).join(',')
367
+        await uni.$u.api.updateReceiptForm({
368
+          id: this.currentReceipt.id,
369
+          fileIds: fileIds
370
+        })
371
+        this.$emit('update-file-ids', fileIds)
372
+
345
       } catch (error) {
373
       } catch (error) {
346
         console.error('上传失败:', error)
374
         console.error('上传失败:', error)
347
       }
375
       }
@@ -358,7 +386,16 @@ export default {
358
           if (res.confirm) {
386
           if (res.confirm) {
359
             try {
387
             try {
360
               await imageUpload.deleteFile(item.id)
388
               await imageUpload.deleteFile(item.id)
361
-              this.loadDetailImages()
389
+              await this.loadDetailImages()
390
+
391
+              // 更新 fileIds
392
+              const fileIds = this.detailImages.map(item => item.id).join(',')
393
+              await uni.$u.api.updateReceiptForm({
394
+                id: this.currentReceipt.id,
395
+                fileIds: fileIds
396
+              })
397
+              this.$emit('update-file-ids', fileIds)
398
+
362
             } catch (error) {
399
             } catch (error) {
363
               console.error('删除失败:', error)
400
               console.error('删除失败:', error)
364
             }
401
             }