Parcourir la source

修改商品规格展示内容

ext.liuqiwen3 il y a 3 semaines
Parent
commit
4a6c6b8ec4
1 fichiers modifiés avec 35 ajouts et 7 suppressions
  1. 35 7
      pages/merchantCenters/releaseProduct.vue

+ 35 - 7
pages/merchantCenters/releaseProduct.vue

@@ -198,7 +198,7 @@
 									</view>
 								</up-upload>
 								<view class="cate-name">
-									{{formatterAttrValue(item.attrValue)}}
+									{{formatterAttrValue(item)}}
 								</view>
 							</view>
 							<view class="cate-ipt-line">
@@ -1351,12 +1351,40 @@
 				break
 		}
 	}
-  const formatterAttrValue = (attrstrValue) => {
-    const data = JSON.parse(attrstrValue);
-
-    const result = `圈号:${data.圈号},重量:${data.重量}g`;
-    return result;
-  }
+  const formatterAttrValue = (attr) => {
+    // 如果属性名是"默认",直接返回"默认"
+    if (attr.attrName === "默认") {
+      return "默认";
+    }
+
+    try {
+      // 尝试解析JSON
+      const data = JSON.parse(attr.attrValue);
+      const result = [];
+
+      // 遍历所有属性
+      for (const [key, value] of Object.entries(data)) {
+        if (key === "单规格") {
+          // 如果是单规格,直接返回值
+          return value;
+        } else if (key === "重量" || key === "重量(克)" || key.endsWith("重量")) {
+          // 如果属性名包含"重量",添加单位g
+          result.push(`${key}:${value}g`);
+        } else {
+          // 圈号直接显示
+          result.push(`${key}:${value}`);
+        }
+      }
+
+      // 用逗号连接所有属性
+      return result.join(",");
+
+    } catch (error) {
+      // 如果不是有效的JSON,返回原始值
+      console.error("解析JSON失败:", error);
+      return attr.attrValue;
+    }
+  };
 </script>
 
 <style scoped lang="scss">