Browse Source

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

panyong 2 years ago
parent
commit
dacff31dad

+ 20 - 0
htmldev/wxMini/api/common.js

@@ -82,3 +82,23 @@ export const userLoginOut = () => request({
   method: 'POST',
   showLoading: false
 })
+
+/**
+ * 商品分类
+ * @returns {Promise<*>}
+ */
+export const getProductCategoryList = () => request({
+  url: '/api/shop/product/category/list',
+  method: 'POST',
+  showLoading: true
+})
+
+/**
+ * 商品品牌
+ * @returns {Promise<*>}
+ */
+export const getProductBrandList = () => request({
+  url: '/api/shop/product/brand/list',
+  method: 'POST',
+  showLoading: true
+})

+ 87 - 0
htmldev/wxMini/mixin/pages.js

@@ -0,0 +1,87 @@
+const { request } = require('../api/request')
+
+module.exports = {
+  data: {
+    searchForm: {
+      key_words: ''
+    },
+    pagenum: 0,
+    pagesize: 20,
+    finished: false, // 所有数据是否加载完
+    isRefresh: false, // 是否下拉刷新
+    isFetchLock: false, // 接口调用加锁
+    list: [],
+    freshing: false
+  },
+  methods: {
+    handleKeyWords(event) {
+      this.setData({
+        'searchForm.key_words': event.detail
+      })
+    },
+    async fetOrderList() {
+      const that = this
+      const isRefresh = that.data.isRefresh
+
+      if (that.data.finished) {
+        return
+      }
+
+      if (that.data.isFetchLock) {
+        return
+      }
+
+      that.setData({
+        isFetchLock: true,
+        pagenum: that.data.pagenum + 1
+      })
+      try {
+        const { status, data, msg } = await request({
+          url: that.data.api,
+          method: 'POST',
+          data: {
+            'page': that.data.pageNum,
+            'page_size': that.data.pageSize,
+            key_words: that.data.searchForm.key_words
+          },
+          showLoading: true
+        })
+        if (status) {
+          const { list } = data
+          if (Array.isArray(list)) {
+            const _list = isRefresh ? [].concat(list) : that.data.list.concat(list)
+
+            that.setData({
+              list: _list,
+              finished: list.length < 10,
+              isRefresh: false,
+              isFetchLock: false
+            })
+          }
+        } else {
+          wx.showToast({
+            title: msg,
+            icon: 'none'
+          })
+        }
+      } catch (e) {}
+      if (that.data.freshing) {
+        that.data.freshing = false
+      }
+      if (isRefresh && wx.stopPullDownRefresh) {
+        wx.stopPullDownRefresh()
+      }
+    },
+    refresh() {
+      this.setData({
+        pagenum: 0,
+        pagesize: 20,
+        finished: false,
+        isRefresh: true,
+        isFetchLock: false
+      }, () => {
+        this.fetOrderList()
+      })
+    }
+  }
+}

+ 0 - 19
htmldev/wxMini/pages/businessGoodsEdit/api/index.js

@@ -1,23 +1,4 @@
 const { request } = require('../../../api/request')
-/**
- * 商品分类
- * @returns {Promise<*>}
- */
-export const getProductCategoryList = () => request({
-  url: '/api/shop/product/category/list',
-  method: 'POST',
-  showLoading: true
-})
-
-/**
- * 商品品牌
- * @returns {Promise<*>}
- */
-export const getProductBrandList = () => request({
-  url: '/api/shop/product/brand/list',
-  method: 'POST',
-  showLoading: true
-})
 
 /**
  * 商品添加

+ 2 - 1
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -1,5 +1,6 @@
 const uploadJS = require('../../mixin/upload.js')
-const { getProductCategoryList, getProductBrandList, postAddProduct, postModifyProduct } = require('./api/index')
+const { postAddProduct, postModifyProduct } = require('./api/index')
+const { getProductCategoryList, getProductBrandList } = require('../../api/common')
 const { formatTs, yuan2Fen } = require('../../utils/util')
 const minDate = new Date().getTime()
 const objMinDate = formatTs(minDate)

+ 11 - 0
htmldev/wxMini/pages/home/api/index.js

@@ -0,0 +1,11 @@
+const { request } = require('../../../api/request')
+
+/**
+ * 商户信息
+ * @returns {Promise<*>}
+ */
+export const getShopInfo = () => request({
+  url: '/api/shop/info',
+  method: 'POST',
+  showLoading: true
+})

+ 4 - 1
htmldev/wxMini/pages/home/home.wxml

@@ -4,7 +4,10 @@
       <label for="header-search">
         <image src="../../image/common/search@2x.png"></image>
       </label>
-      <input placeholder-class="app_header-search-placeholder" value="" placeholder="搜索"></input>
+      <input
+        placeholder-class="app_header-search-placeholder"
+        value="{{searchForm.key_words}}"
+        placeholder="搜索"></input>
     </view>
     <view class="leaving-a-message" bind:tap="jumpLeavingAMessage">
       <image src="../../image/common/message@2x.png"></image>

+ 1 - 13
htmldev/wxMini/project.private.config.json

@@ -3,19 +3,7 @@
     "urlCheck": false,
     "compileHotReLoad": true
   },
-  "condition": {
-    "miniprogram": {
-      "list": [
-        {
-          "name": "1111",
-          "pathName": "pages/businessGoodsEdit/businessGoodsEdit",
-          "query": "",
-          "launchMode": "default",
-          "scene": null
-        }
-      ]
-    }
-  },
+  "condition": {},
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
   "libVersion": "2.13.2",
   "projectname": "%E5%A7%8B%E5%AE%81%E5%86%9C%E4%B8%9A"