From fe90a52e90e41e6916988c50caa3c63540d588d3 Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期四, 16 十月 2025 15:35:09 +0800
Subject: [PATCH] 修改模板

---
 seller/src/views/order/order/editTemplateModal.vue |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 100 insertions(+), 16 deletions(-)

diff --git a/seller/src/views/order/order/editTemplateModal.vue b/seller/src/views/order/order/editTemplateModal.vue
index 18e0d4a..6ed906c 100644
--- a/seller/src/views/order/order/editTemplateModal.vue
+++ b/seller/src/views/order/order/editTemplateModal.vue
@@ -86,12 +86,12 @@
       </div>
 
       <!-- 璋冭瘯淇℃伅 -->
-<!--      <details style="margin-top: 20px; border: 1px solid #eee; padding: 10px;">-->
-<!--        <summary>璋冭瘯淇℃伅</summary>-->
-<!--        <pre>{{ JSON.stringify(templateData, null, 2) }}</pre>-->
-<!--        <p>閫変腑鐨勫浘鐗嘔D: {{ selectedImageId }}</p>-->
-<!--        <p>琛ㄥ崟鍊�: {{ JSON.stringify(formValues, null, 2) }}</p>-->
-<!--      </details>-->
+<!--      <details style="margin-top: 20px; border: 1px solid #eee; padding: 10px;">
+        <summary>璋冭瘯淇℃伅</summary>
+        <pre>{{ JSON.stringify(templateData, null, 2) }}</pre>
+        <p>閫変腑鐨勫浘鐗嘔D: {{ selectedImageId }}</p>
+        <p>琛ㄥ崟鍊�: {{ JSON.stringify(formValues, null, 2) }}</p>
+      </details>-->
     </Form>
 
     <div v-else>
@@ -124,6 +124,11 @@
     orderSn: {
       type: String,
       default: ""
+    },
+    // 娣诲姞userCheckTemplates灞炴��
+    userCheckTemplates: {
+      type: Array,
+      default: () => []
     }
   },
   data() {
@@ -195,8 +200,12 @@
           // 澶勭悊妯℃澘鑷畾涔夋爣棰樺瓧娈电殑鍥炴樉
           if (res.data.templateConstomizeTitles) {
             res.data.templateConstomizeTitles.forEach(item => {
-              // 鍥炴樉宸叉湁鐨勫��
-              if (item.value !== undefined && item.value !== null) {
+              // 鍥炴樉宸叉湁鐨勫�� - 浠巙serCheckTemplates涓幏鍙栧搴攕ubId鐨勫��
+              const userTemplate = this.getUserTemplateBySubId(item.id);
+              if (userTemplate && userTemplate.content !== undefined && userTemplate.content !== null) {
+                this.$set(this.formValues, item.id, userTemplate.content);
+              } else if (item.value !== undefined && item.value !== null) {
+                // 濡傛灉娌℃湁鎵惧埌userCheckTemplates涓殑鍊硷紝鍒欎娇鐢ㄦā鏉块粯璁ゅ��
                 this.$set(this.formValues, item.id, item.value);
               } else {
                 // 鍒濆鍖栬〃鍗曞�硷紙濡傛灉娌℃湁榛樿鍊硷級
@@ -213,11 +222,29 @@
               // 鏌ユ壘閫変腑鍥剧墖鐨刄RL骞朵繚瀛�
               const selectedImage = res.data.templateImgs.find(img => img.id === res.data.chooseImageId);
               if (selectedImage) {
-                this.selectedImageUrl = selectedImage.imgUrl || '';
+                // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+                this.selectedImageUrl = this.processImageUrl(selectedImage.imgUrl || '');
               }
             } else {
-              this.selectedImageId = res.data.templateImgs[0].id;
-              this.selectedImageUrl = res.data.templateImgs[0].imgUrl || '';
+              // 灏濊瘯浠巙serCheckTemplates涓幏鍙栭�変腑鐨勫浘鐗�
+              const userTemplate = this.getUserTemplateByType('IMAGE');
+              if (userTemplate && userTemplate.chooseImg) {
+                // 鏌ユ壘瀵瑰簲鐨勫浘鐗嘔D
+                const matchedImage = res.data.templateImgs.find(img => img.imgUrl === userTemplate.chooseImg);
+                if (matchedImage) {
+                  this.selectedImageId = matchedImage.id;
+                  // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+                  this.selectedImageUrl = this.processImageUrl(matchedImage.imgUrl || '');
+                } else {
+                  this.selectedImageId = res.data.templateImgs[0].id;
+                  // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+                  this.selectedImageUrl = this.processImageUrl(res.data.templateImgs[0].imgUrl || '');
+                }
+              } else {
+                this.selectedImageId = res.data.templateImgs[0].id;
+                // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+                this.selectedImageUrl = this.processImageUrl(res.data.templateImgs[0].imgUrl || '');
+              }
             }
           } else {
             // 濡傛灉娌℃湁妯℃澘鍥剧墖锛屾竻绌洪�変腑鐘舵��
@@ -239,6 +266,25 @@
       } finally {
         this.loading = false;
       }
+    },
+
+    // 鏍规嵁subId鑾峰彇userCheckTemplates涓殑瀵瑰簲椤�
+    getUserTemplateBySubId(subId) {
+      // 浠巔rops涓幏鍙杣serCheckTemplates鏁版嵁
+      if (this.userCheckTemplates && this.userCheckTemplates.length > 0) {
+        // 鏌ユ壘subId鍖归厤鐨勯」
+        return this.userCheckTemplates.find(template => template.subId === subId);
+      }
+      return null;
+    },
+
+    // 鏍规嵁绫诲瀷鑾峰彇userCheckTemplates涓殑瀵瑰簲椤�
+    getUserTemplateByType(contentType) {
+      if (this.userCheckTemplates && this.userCheckTemplates.length > 0) {
+        // 鏌ユ壘contentType鍖归厤鐨勯」
+        return this.userCheckTemplates.find(template => template.contentType === contentType);
+      }
+      return null;
     },
 
     // 鑾峰彇鍥剧墖URL
@@ -282,7 +328,8 @@
       if (this.templateData && this.templateData.templateImgs) {
         const selectedImage = this.templateData.templateImgs.find(img => img.id === imageId);
         if (selectedImage) {
-          this.selectedImageUrl = selectedImage.imgUrl || '';
+          // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+          this.selectedImageUrl = this.processImageUrl(selectedImage.imgUrl || '');
         } else {
           this.selectedImageUrl = '';
         }
@@ -326,7 +373,7 @@
         console.log('涓婁紶鏂囦欢杩斿洖缁撴灉:', res); // 娣诲姞璋冭瘯鏃ュ織
         if (res.code === 200) {
           // 涓婁紶鎴愬姛锛岃缃〃鍗曞��
-          // 纭繚res.data鏄瓧绗︿覆绫诲瀷
+          // 淇敼杩欓噷锛氬彧淇濆瓨鏂囦欢鍚嶆垨鐩稿璺緞锛岃�屼笉鏄畬鏁磋矾寰�
           let fileKey = '';
           if (typeof res.data === 'string') {
             fileKey = res.data;
@@ -342,7 +389,21 @@
             fileKey = String(fileKey);
           }
 
+          // 淇敼杩欓噷锛氬鐞嗘枃浠惰矾寰勶紝鍙繚鐣欐枃浠跺悕閮ㄥ垎
+          // 濡傛灉鏄畬鏁碪RL锛屽垯鍙彇璺緞閮ㄥ垎锛涘惁鍒欎繚鎸佸師鏍�
+          if (fileKey.startsWith('http://') || fileKey.startsWith('https://')) {
+            // 鎻愬彇URL涓殑璺緞閮ㄥ垎
+            try {
+              const urlObj = new URL(fileKey);
+              fileKey = urlObj.pathname.substring(1); // 鍘绘帀寮�澶寸殑鏂滄潬
+            } catch (e) {
+              // 濡傛灉URL瑙f瀽澶辫触锛屼繚鎸佸師鏍�
+              console.warn('Failed to parse URL:', fileKey);
+            }
+          }
+
           this.$set(this.formValues, fieldId, fileKey);
+          
           this.$Message.success("鍥剧墖涓婁紶鎴愬姛");
           
           // 寮哄埗鏇存柊瑙嗗浘浠ョ‘淇濆浘鐗囬瑙堟纭樉绀�
@@ -373,7 +434,8 @@
         sn: this.orderSn,
         templateName: this.form.templateName,
         chooseImageId: this.selectedImageId,
-        chooseImage: this.selectedImageUrl, // 娣诲姞閫変腑鍥剧墖URL
+        // 淇敼杩欓噷锛氬鐞哻hooseImage锛屽彧淇濆瓨鐩稿璺緞
+        chooseImage: this.processImageUrl(this.selectedImageUrl),
         templateForm: []
       };
 
@@ -384,13 +446,35 @@
             id: item.id,
             templateTitle: item.templateTitle,
             contentType: item.contentType,
-            value: this.formValues[item.id] || ""
+            // 淇敼杩欓噷锛氬鐞唙alue锛屽彧淇濆瓨鐩稿璺緞
+            value: this.processImageUrl(this.formValues[item.id]) || ""
           });
         });
       }
 
       console.log("鎻愪氦鍙傛暟:", params);
       return params;
+    },
+
+    // 澶勭悊鍥剧墖URL锛屽彧淇濈暀鐩稿璺緞
+    processImageUrl(url) {
+      if (!url || typeof url !== 'string') {
+        return url;
+      }
+
+      // 濡傛灉鏄畬鏁碪RL锛屽垯鍙彇璺緞閮ㄥ垎锛涘惁鍒欎繚鎸佸師鏍�
+      if (url.startsWith('http://') || url.startsWith('https://')) {
+        try {
+          const urlObj = new URL(url);
+          return urlObj.pathname.substring(1); // 鍘绘帀寮�澶寸殑鏂滄潬
+        } catch (e) {
+          // 濡傛灉URL瑙f瀽澶辫触锛屼繚鎸佸師鏍�
+          console.warn('Failed to parse URL:', url);
+          return url;
+        }
+      }
+
+      return url;
     },
 
     // 纭畾鎸夐挳
@@ -523,4 +607,4 @@
   border-color: #57a3f3;
   color: #57a3f3;
 }
-</style>
+</style>
\ No newline at end of file

--
Gitblit v1.8.0