Quellcode durchsuchen

fix(miniapp): 修复 product-edit 商品编辑页方法错位

onTypeChange 被误粘贴为 loadProduct 的内容且引用未定义变量 id,导致 onLoad 调用的 loadProduct 不存在、编辑页进页即崩。
拆分为: onTypeChange 仅同步 picker 选择; loadProduct(id) 承载商品详情加载回填逻辑。
liaoxg vor 19 Stunden
Ursprung
Commit
e001081430
1 geänderte Dateien mit 10 neuen und 4 gelöschten Zeilen
  1. 10 4
      cfc-frontend/pages/vendor/product-edit/product-edit.vue

+ 10 - 4
cfc-frontend/pages/vendor/product-edit/product-edit.vue

@@ -90,11 +90,16 @@ export default {
   },
   methods: {
     onTypeChange(e) {
+      var idx = Number(e.detail.value)
+      this.typeIndex = idx
+      this.form.productType = this.typeOptions[idx].value
+    },
+    loadProduct(id) {
       uni.showLoading({ title: '加载中...' })
-      productDetail({ id: Number(id) }).then(res => {
+      productDetail({ id: Number(id) }).then(function(res) {
         uni.hideLoading()
         if (res.code === 200 && res.data) {
-          const p = res.data
+          var p = res.data
           this.form.name = p.name || ''
           this.form.intro = p.intro || ''
           this.form.description = p.description || ''
@@ -103,12 +108,13 @@ export default {
           this.form.stock = p.stock || 0
           this.form.productType = p.productType || 'physical'
           // sync picker index
-          var idx = this.typeOptions.findIndex(function(t) { return t.value === this.form.productType }, this)
+          var self = this
+          var idx = this.typeOptions.findIndex(function(t) { return t.value === self.form.productType })
           if (idx >= 0) this.typeIndex = idx
         } else {
           uni.showToast({ title: res.message || '加载失败', icon: 'none' })
         }
-      }).catch(function() {
+      }.bind(this)).catch(function() {
         uni.hideLoading()
         uni.showToast({ title: '加载失败', icon: 'none' })
       })