Browse Source

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

panyong 2 years ago
parent
commit
d38e656509

+ 21 - 7
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -55,8 +55,9 @@ Page({
     product_img_url_max: 1,
     product_rotation_img_list_max: 5,
     product_detail_img_list_max: 5,
-    show: false,
-    columns: ['杭州', '宁波', '温州', '嘉兴', '湖州']
+    unitShow: false,
+    unitInDefaultIndex: 0,
+    unitInColumns: ['件', '个']
   },
 
   /**
@@ -145,14 +146,27 @@ Page({
       this.setData(tempForm)
     }
   },
-  onClose() {
+  unitShow() {
     this.setData({
-      show: false
+      unitShow: true
     })
   },
-  onChange(event) {
-    const { picker, value, index } = event.detail
-    console.log(`当前值:${value}, 当前索引:${index}`)
+  unitHide() {
+    this.selectComponent('#picker-unit').setIndexes([this.data.unitInDefaultIndex])
+
+    this.setData({
+      unitShow: false
+    })
+  },
+  unitConfirm(event) {
+    const { value, index } = event.detail
+
+    this.setData({
+      'form.product_unit': value,
+      unitInDefaultIndex: index
+    })
+
+    this.unitHide()
   },
   onSubmit(e) {
     console.log(e.detail)

+ 8 - 7
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.wxml

@@ -118,7 +118,7 @@
             placeholder-class="placeholder"></input>
         </view>
       </view>
-      <view class="box">
+      <view class="box" bind:tap="unitShow">
         <label>
           <text>单 位</text>
         </label>
@@ -180,15 +180,16 @@
 </view>
 
 <van-popup
-  show="{{ show }}"
+  show="{{ unitShow }}"
   close-on-click-overlay="{{false}}"
   round
   position="bottom"
-  bind:click-overlay="onClose"
-  bind:close="onClose">
+  bind:click-overlay="unitHide">
   <van-picker
-    columns="{{ columns }}"
+    id="picker-unit"
+    columns="{{ unitInColumns }}"
     show-toolbar
-    default-index="{{ 2 }}"
-    bind:change="onChange"/>
+    default-index="{{ unitInDefaultIndex }}"
+    bind:cancel="unitHide"
+    bind:confirm="unitConfirm"/>
 </van-popup>