浏览代码

小程序:首页接口对接

panyong 2 年之前
父节点
当前提交
a6e0607989

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

@@ -62,6 +62,10 @@ module.exports = {
               isRefresh: false,
               isFetchLock: false,
               pagenum: that.data.pagenum + 1
+            }, () => {
+              if (that.isLeft) {
+                that.isLeft(list)
+              }
             })
           }
         } else {

+ 15 - 0
htmldev/wxMini/pages/businessDetail/api/index.js

@@ -0,0 +1,15 @@
+const { request } = require('../../../api/request')
+
+/**
+ * 供应商详情
+ * @param id
+ * @returns {Promise<*>}
+ */
+export const getShopDetail = (businessId) => request({
+  url: '/api/user/home/shop/detail',
+  method: 'POST',
+  data: {
+    shop_id: businessId
+  },
+  showLoading: true
+})

+ 71 - 11
htmldev/wxMini/pages/businessDetail/businessDetail.js

@@ -1,9 +1,20 @@
+const pages = require('../../mixin/pages')
+const { getShopDetail } = require('./api/index')
+let leftHeight = 0
+let rightHeight = 0
+let query = null
+
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
+    ...pages.data(),
+    listUrl: '/api/user/home/shop/product/list',
+    searchForm: {
+      shop_id: ''
+    },
     background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
     nav: [
       {
@@ -16,16 +27,21 @@ Page({
       }
     ],
     active: '1',
-    list: [],
     leftList: [],
     rightList: []
   },
-
+  ...pages.methods,
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-
+    const { businessId } = options
+    this.setData({
+      'searchForm.shop_id': businessId
+    }, () => {
+      this.fetchShopDetail()
+      this.fetchOrderList()
+    })
   },
 
   /**
@@ -60,21 +76,65 @@ Page({
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh() {
-
+    if (this.data.freshing) {
+      return
+    }
+    this.setData({
+      freshing: true
+    })
+    this.fetchShopDetail()
+    this.bindCallBack()
   },
 
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom() {
-
+    this.fetchOrderList()
   },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
+  bindCallBack() {
+    this.fetchShopDetail()
+    this.refreshOrderList()
+  },
+  async fetchShopDetail() {
+    try {
+      const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id)
+      if (status) {
+
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+  },
+  async isLeft(list) {
+    const {
+      leftList,
+      rightList
+    } = this.data
+    query = wx.createSelectorQuery()
+    for (const item of list) {
+      leftHeight <= rightHeight ? leftList.push(item) : rightList.push(item)
+      await this.getBoxHeight(leftList, rightList)
+    }
+  },
+  getBoxHeight(leftList, rightList) {
+    return new Promise((resolve, reject) => {
+      this.setData({
+        leftList,
+        rightList
+      }, () => {
+        query.select('.waterfall-left').boundingClientRect()
+        query.select('.waterfall-right').boundingClientRect()
+        query.exec((res) => {
+          leftHeight = res[0].height
+          rightHeight = res[1].height
+          resolve()
+        })
+      })
+    })
   },
   handleNav(e) {
     const { value } = e.detail

+ 6 - 2
htmldev/wxMini/pages/businessDetail/businessDetail.json

@@ -1,6 +1,10 @@
 {
   "usingComponents": {
     "customer-tab": "../../components/customer-tab/index",
-    "goods-item-large": "../../components/goods-item-large"
-  }
+    "goods-item-large": "../../components/goods-item-large",
+    "van-loading": "@vant/weapp/loading/index"
+  },
+  "backgroundTextStyle": "dark",
+  "enablePullDownRefresh": true,
+  "onReachBottomDistance": 50
 }

+ 7 - 0
htmldev/wxMini/pages/businessDetail/businessDetail.wxml

@@ -38,3 +38,10 @@
     <goods-item-large/>
   </view>
 </view>
+<view class="pullup-wrapper" wx:if="{{!isRefresh && active === '2'}}">
+  <van-loading
+    wx:if="{{!finished}}"
+    size="24px"
+    type="spinner">加载中...
+  </van-loading>
+</view>

+ 2 - 3
htmldev/wxMini/pages/home/home.js

@@ -158,14 +158,13 @@ Page({
       this.refreshOrderList()
     })
   },
-  async isLeft() {
+  async isLeft(list) {
     const {
-      listData,
       leftList,
       rightList
     } = this.data
     query = wx.createSelectorQuery()
-    for (const item of listData) {
+    for (const item of list) {
       leftHeight <= rightHeight ? leftList.push(item) : rightList.push(item)
       await this.getBoxHeight(leftList, rightList)
     }

+ 3 - 1
htmldev/wxMini/pages/partner/partner.json

@@ -1,5 +1,7 @@
 {
-  "usingComponents": {},
+  "usingComponents": {
+    "van-loading": "@vant/weapp/loading/index"
+  },
   "backgroundTextStyle": "dark",
   "enablePullDownRefresh": true,
   "onReachBottomDistance": 50