Browse Source

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

panyong 2 years ago
parent
commit
923e9ef5a4

+ 102 - 8
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -1,4 +1,5 @@
 const uploadJS = require('../../mixin/upload.js')
+const { getProductCategoryList, getProductBrandList } = require('./api/index')
 
 Page({
 
@@ -55,7 +56,13 @@ Page({
     product_img_url_max: 1,
     product_rotation_img_list_max: 5,
     product_detail_img_list_max: 5,
-    unitShow: false,
+    booCategory: false,
+    categoryInDefaultIndex: 0,
+    categoryList: [],
+    booBrand: false,
+    brandInDefaultIndex: 0,
+    brandList: [],
+    booUnit: false,
     unitInDefaultIndex: 0,
     unitInColumns: ['件', '个']
   },
@@ -63,8 +70,9 @@ Page({
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad(options) {
-
+  async onLoad(options) {
+    await this.fetchProductCategoryList()
+    await this.fetchProductBrandList()
   },
 
   /**
@@ -114,6 +122,44 @@ Page({
    */
   onShareAppMessage() {
 
+  },
+  async fetchProductCategoryList() {
+    try {
+      const { status, data, msg } = await getProductCategoryList()
+      if (status) {
+        this.setData({
+          categoryList: data.map(item => {
+            return {
+              ...item,
+              text: item.category_name
+            }
+          })
+        })
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+  },
+  async fetchProductBrandList() {
+    const { status, data, msg } = await getProductBrandList()
+    if (status) {
+      this.setData({
+        brandList: data.map(item => {
+          return {
+            ...item,
+            text: item.brand_name
+          }
+        })
+      })
+    } else {
+      wx.showToast({
+        title: msg,
+        icon: 'none'
+      })
+    }
   },
   ...uploadJS,
   uploadCallBack(res) {
@@ -140,22 +186,70 @@ Page({
       default:
     }
 
-    console.log(tempForm)
-
     if (Object.keys(tempForm).length > 0) {
       this.setData(tempForm)
     }
   },
+  categoryShow() {
+    this.setData({
+      booCategory: true
+    })
+  },
+  categoryHide() {
+    if (this.data.categoryList.length > 0) {
+      this.selectComponent('#picker-category').setIndexes([this.data.categoryInDefaultIndex])
+    }
+
+    this.setData({
+      booCategory: false
+    })
+  },
+  categoryConfirm(event) {
+    const { value, index } = event.detail
+
+    this.setData({
+      'form.product_category_id': value,
+      categoryInDefaultIndex: index
+    })
+
+    this.categoryHide()
+  },
+  brandShow() {
+    this.setData({
+      booBrand: true
+    })
+  },
+  brandHide() {
+    if (this.data.brandList.length > 0) {
+      this.selectComponent('#picker-brand').setIndexes([this.data.brandInDefaultIndex])
+    }
+
+    this.setData({
+      booBrand: false
+    })
+  },
+  brandConfirm(event) {
+    const { value, index } = event.detail
+
+    this.setData({
+      'form.product_brand_id': value,
+      brandInDefaultIndex: index
+    })
+
+    this.brandHide()
+  },
   unitShow() {
     this.setData({
-      unitShow: true
+      booUnit: true
     })
   },
   unitHide() {
-    this.selectComponent('#picker-unit').setIndexes([this.data.unitInDefaultIndex])
+    if (this.data.unitInColumns.length > 0) {
+      this.selectComponent('#picker-unit').setIndexes([this.data.unitInDefaultIndex])
+    }
 
     this.setData({
-      unitShow: false
+      booUnit: false
     })
   },
   unitConfirm(event) {

+ 40 - 3
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.wxml

@@ -84,7 +84,9 @@
         </view>
         <view class="words-limit">{{form.product_desc.length}}/200</view>
       </view>
-      <view class="box border-bottom-2">
+      <view
+        class="box border-bottom-2"
+        bind:tap="categoryShow">
         <label>
           <text>商品分类</text>
         </label>
@@ -96,7 +98,9 @@
           <image class="arrow" src="../../image/businessGoodsEdit/arrow.png"></image>
         </view>
       </view>
-      <view class="box">
+      <view
+        class="box"
+        bind:tap="brandShow">
         <label>
           <text>商品品牌</text>
         </label>
@@ -179,8 +183,41 @@
   </view>
 </view>
 
+  <!--弹窗:分类选择-->
+<van-popup
+  show="{{ booCategory }}"
+  close-on-click-overlay="{{false}}"
+  round
+  position="bottom"
+  bind:click-overlay="categoryHide">
+  <van-picker
+    id="picker-category"
+    columns="{{ categoryList }}"
+    show-toolbar
+    default-index="{{ categoryInDefaultIndex }}"
+    bind:cancel="categoryHide"
+    bind:confirm="categoryConfirm"/>
+</van-popup>
+
+  <!--弹窗:品牌选择-->
+<van-popup
+  show="{{ booBrand }}"
+  close-on-click-overlay="{{false}}"
+  round
+  position="bottom"
+  bind:click-overlay="brandHide">
+  <van-picker
+    id="picker-brand"
+    columns="{{ brandList }}"
+    show-toolbar
+    default-index="{{ brandInDefaultIndex }}"
+    bind:cancel="brandHide"
+    bind:confirm="brandConfirm"/>
+</van-popup>
+
+  <!--弹窗:单位选择-->
 <van-popup
-  show="{{ unitShow }}"
+  show="{{ booUnit }}"
   close-on-click-overlay="{{false}}"
   round
   position="bottom"