Explorar el Código

fix(sku-editor): showDialog处理object规格+update移除productId避免400

Xiaogang Liao hace 2 meses
padre
commit
1ca3db440d
Se han modificado 1 ficheros con 8 adiciones y 1 borrados
  1. 8 1
      cfc-web/src/views/admin/components/ProductSkuEditor.vue

+ 8 - 1
cfc-web/src/views/admin/components/ProductSkuEditor.vue

@@ -161,8 +161,14 @@ export default {
     showDialog(sku) {
       if (sku) {
         this.editingId = sku.id
+        let specsVal = sku.specs || ''
+        if (typeof specsVal === 'object') {
+          specsVal = JSON.stringify(specsVal)
+        } else if (typeof specsVal === 'string' && specsVal.trim().startsWith('[')) {
+          try { specsVal = JSON.stringify(JSON.parse(specsVal)) } catch (e) {}
+        }
         this.skuForm = {
-          specs: sku.specs || '',
+          specs: specsVal,
           price: sku.price ? parseFloat(sku.price) : 0,
           originalPrice: sku.originalPrice ? parseFloat(sku.originalPrice) : 0,
           stock: sku.stock || 0,
@@ -248,6 +254,7 @@ export default {
           let res
           if (this.editingId) {
             payload.id = this.editingId
+            delete payload.productId
             res = await updateProductSku(payload)
           } else {
             res = await createProductSku(payload)