Browse Source

小程序:商家端-商品添加

panyong 2 years ago
parent
commit
f2314a5e36

+ 23 - 0
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -262,6 +262,29 @@ Page({
 
     this.unitHide()
   },
+  setFormValue(event) {
+    const { value } = event.detail
+    const { formkey } = event.target.dataset
+    let tempForm = {}
+
+    switch (formkey) {
+      case 'product_title':
+      case 'product_desc':
+      case 'product_spec':
+        tempForm[`form.${formkey}`] = value
+        break
+      case 'product_all_price':
+      case 'product_price':
+        tempForm[`form.${formkey}`] = value.replace(/^0[0-9]*/, '0').replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')
+        break
+      case 'product_count':
+        tempForm[`form.${formkey}`] = value.replace(/^0[0-9]*/, '0')
+        break
+      default:
+    }
+
+    this.setData(tempForm)
+  },
   onSubmit(e) {
     console.log(e.detail)
   }

+ 18 - 6
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.wxml

@@ -70,7 +70,9 @@
           <input
             value="{{form.product_title}}"
             placeholder="输入商品标题"
-            placeholder-class="placeholder"></input>
+            placeholder-class="placeholder"
+            data-formkey="product_title"
+            bind:input="setFormValue"></input>
         </view>
       </view>
       <view class="describe">
@@ -80,7 +82,9 @@
             placeholder="请输入商品简介"
             placeholder-class="placeholder"
             maxlength="{{200}}"
-            auto-height="{{true}}"></textarea>
+            auto-height="{{true}}"
+            data-formkey="product_desc"
+            bind:input="setFormValue"></textarea>
         </view>
         <view class="words-limit">{{form.product_desc.length}}/200</view>
       </view>
@@ -119,7 +123,9 @@
           <input
             value="{{form.product_spec}}"
             placeholder="输入商品规格"
-            placeholder-class="placeholder"></input>
+            placeholder-class="placeholder"
+            data-formkey="product_spec"
+            bind:input="setFormValue"></input>
         </view>
       </view>
       <view class="box" bind:tap="unitShow">
@@ -139,7 +145,9 @@
           <input
             value="{{form.product_all_price}}"
             placeholder="输入批发价"
-            placeholder-class="placeholder"></input>
+            placeholder-class="placeholder"
+            data-formkey="product_all_price"
+            bind:input="setFormValue"></input>
         </view>
       </view>
       <view class="box">
@@ -150,7 +158,9 @@
           <input
             value="{{form.product_price}}"
             placeholder="输入零售价"
-            placeholder-class="placeholder"></input>
+            placeholder-class="placeholder"
+            data-formkey="product_price"
+            bind:input="setFormValue"></input>
         </view>
       </view>
       <view class="box">
@@ -161,7 +171,9 @@
           <input
             value="{{form.product_count}}"
             placeholder="输入库存"
-            placeholder-class="placeholder"></input>
+            placeholder-class="placeholder"
+            data-formkey="product_count"
+            bind:input="setFormValue"></input>
         </view>
       </view>
       <view class="box border-bottom-2">