Pārlūkot izejas kodu

始宁农业小程序:新增全部产品

panyong 1 gadu atpakaļ
vecāks
revīzija
4d9496e785

+ 3 - 2
htmldev/shiningWxMini/app.json

@@ -20,7 +20,8 @@
     "pages/businessGoodsManage/businessGoodsManage",
     "pages/businessGoodsEdit/businessGoodsEdit",
     "pages/businessApply/businessApply",
-    "pages/h5/h5"
+    "pages/h5/h5",
+    "pages/goods/goods"
   ],
   "permission": {
     "scope.userLocation": {
@@ -72,4 +73,4 @@
       }
     ]
   }
-}
+}

+ 9 - 9
htmldev/shiningWxMini/custom-tab-bar/index.js

@@ -12,17 +12,17 @@ Component({
     active: 'pages/home/home',
     list: app.globalData.tabBarList
   },
-  attached() {
-    this.setData({
-      list: app.globalData.tabBarList
-    })
-
-    app.addTabBarList = res => {
+  lifetimes: {
+    attached() {
       this.setData({
-        list: res
-      }, () => {
-        this.triggerEvent('getTabBarList', res)
+        list: app.globalData.tabBarList
       })
+
+      app.addTabBarList = res => {
+        this.setData({
+          list: res
+        })
+      }
     }
   },
   /**

+ 158 - 0
htmldev/shiningWxMini/pages/goods/goods.js

@@ -0,0 +1,158 @@
+const pages = require('../../mixin/pages')
+const { getProductCategoryList } = require('../../api/common')
+let leftHeight = 0
+let rightHeight = 0
+let query = wx.createSelectorQuery()
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    ...pages.data(),
+    listUrl: '/api/user/caigou/product/list',
+    searchForm: {
+      key_words: '',
+      category_id: ''
+    },
+    categoryList: [],
+    navScrollLeft: -1,
+    leftList: [],
+    rightList: []
+  },
+  ...pages.methods,
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  async onLoad(options) {
+    await this.fetchProductCategoryList()
+    this.fetchOrderList()
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+    if (this.data.freshing) {
+      return
+    }
+    this.setData({
+      freshing: true
+    })
+    this.bindCallBack()
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+    this.fetchOrderList()
+  },
+  bindCallBack() {
+    this.refreshOrderList()
+  },
+  async fetchProductCategoryList() {
+    try {
+      const { status, data, msg } = await getProductCategoryList()
+      if (status && Array.isArray(data) && data.length > 0) {
+        const temp = data.map(item => {
+          return {
+            ...item,
+            text: item.category_name
+          }
+        })
+
+        temp.unshift({
+          category_img_url: '',
+          category_name: '全部',
+          id: 0
+        })
+
+        this.setData({
+          categoryList: temp,
+          'searchForm.category_id': temp[0].id
+        })
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+  },
+  handleNav(e) {
+    const { item } = e.currentTarget.dataset
+
+    if (this.data.searchForm.category_id !== item.id) {
+      this.setData({
+        'searchForm.category_id': item.id,
+        navScrollLeft: 0
+      }, () => {
+        this.refreshOrderList()
+      })
+    }
+  },
+  async isLeft(list) {
+    const {
+      leftList,
+      rightList
+    } = this.data
+
+    for (const item of list) {
+      if (leftHeight < rightHeight) {
+        leftList.push(item)
+      } else if (leftHeight === rightHeight) {
+        leftList.length <= rightList ? leftList.push(item) : rightList.push(item)
+      } else {
+        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()
+        })
+      })
+    })
+  }
+})

+ 11 - 0
htmldev/shiningWxMini/pages/goods/goods.json

@@ -0,0 +1,11 @@
+{
+  "usingComponents": {
+    "van-loading": "@vant/weapp/loading/index",
+    "goods-item-large": "../../components/goods-item-large"
+  },
+  "navigationBarTitleText": "商品展示",
+  "backgroundColor": "#F6F6F6",
+  "backgroundTextStyle": "dark",
+  "enablePullDownRefresh": true,
+  "onReachBottomDistance": 50
+}

+ 32 - 0
htmldev/shiningWxMini/pages/goods/goods.scss

@@ -0,0 +1,32 @@
+.page-header-search {
+  padding: 20rpx 0 28rpx;
+}
+
+.shopping-car {
+  position: relative;
+  left: 0;
+  top: 0;
+}
+
+.shopping-car image {
+  display: block;
+  width: 40rpx;
+  height: 50rpx;
+}
+
+.waterfall {
+  width: 690rpx;
+  padding: 30rpx 0;
+  margin: 0 auto;
+  font-size: 0;
+}
+
+.waterfall-left,
+.waterfall-right {
+  display: inline-block;
+  width: 330rpx;
+}
+
+.waterfall-right {
+  margin-left: 30rpx;
+}

+ 59 - 0
htmldev/shiningWxMini/pages/goods/goods.wxml

@@ -0,0 +1,59 @@
+<view class="wrapper">
+  <view class="app_page-header-search page-header-search">
+    <view class="app_page-header-search-warp app_width-690">
+      <label for="header-search">
+        <image src="../../image/common/search@2x.png"></image>
+      </label>
+      <input
+        placeholder-class="app_header-search-placeholder"
+        value="{{searchForm.key_words}}"
+        placeholder="搜索"
+        data-formkey="key_words"
+        bind:input="handleKeyWords"></input>
+    </view>
+  </view>
+  <scroll-view
+    class="app_nav-wrap"
+    scroll-x="{{true}}"
+    scroll-with-animation="{{true}}"
+    scroll-into-view="item-{{searchForm.category_id * 1 < 4 ? navScrollLeft : searchForm.category_id * 1 - 3}}">
+    <view
+      class="nav {{searchForm.category_id === item.id ? 'active' : ''}}"
+      wx:for="{{categoryList}}"
+      wx:key="id"
+      data-item="{{item}}"
+      bind:tap="handleNav">
+      <view
+        class="photo"
+        id="item-{{index}}">
+        <image src="{{item.category_img_url}}"></image>
+      </view>
+      <view class="name">{{item.category_name}}</view>
+    </view>
+  </scroll-view>
+  <!--瀑布流-->
+  <view class="waterfall">
+    <view class="waterfall-left">
+      <block wx:for="{{leftList}}" wx:key="id">
+        <goods-item-large item="{{item}}"/>
+      </block>
+    </view>
+    <view class="waterfall-right">
+      <block wx:for="{{rightList}}" wx:key="id">
+        <goods-item-large item="{{item}}"/>
+      </block>
+    </view>
+  </view>
+  <!-- 无数据 -->
+  <view class="list-bitmap" wx:if="{{finished && listData.length < 1}}">
+    <image src="../../image/common/bitmap.png"></image>
+    <text>暂无数据</text>
+  </view>
+  <view class="pullup-wrapper" wx:if="{{!isRefresh}}">
+    <van-loading
+      wx:if="{{!finished}}"
+      size="24px"
+      type="spinner">加载中...
+    </van-loading>
+  </view>
+</view>

+ 2 - 118
htmldev/shiningWxMini/pages/guide/guide.js

@@ -1,34 +1,15 @@
-const pages = require('../../mixin/pages')
-const { getProductCategoryList } = require('../../api/common')
-let leftHeight = 0
-let rightHeight = 0
-let query = wx.createSelectorQuery()
-
 Page({
 
   /**
    * 页面的初始数据
    */
-  data: {
-    ...pages.data(),
-    listUrl: '/api/user/caigou/product/list',
-    searchForm: {
-      key_words: '',
-      category_id: ''
-    },
-    categoryList: [],
-    navScrollLeft: -1,
-    leftList: [],
-    rightList: []
-  },
-  ...pages.methods,
+  data: {},
 
   /**
    * 生命周期函数--监听页面加载
    */
   async onLoad(options) {
-    await this.fetchProductCategoryList()
-    this.fetchOrderList()
+
   },
 
   /**
@@ -57,102 +38,5 @@ Page({
    */
   onUnload() {
 
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-    if (this.data.freshing) {
-      return
-    }
-    this.setData({
-      freshing: true
-    })
-    this.bindCallBack()
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-    this.fetchOrderList()
-  },
-  bindCallBack() {
-    this.refreshOrderList()
-  },
-  async fetchProductCategoryList() {
-    try {
-      const { status, data, msg } = await getProductCategoryList()
-      if (status && Array.isArray(data) && data.length > 0) {
-        const temp = data.map(item => {
-          return {
-            ...item,
-            text: item.category_name
-          }
-        })
-
-        temp.unshift({
-          category_img_url: '',
-          category_name: '全部',
-          id: 0
-        })
-
-        this.setData({
-          categoryList: temp,
-          'searchForm.category_id': temp[0].id
-        })
-      } else {
-        wx.showToast({
-          title: msg,
-          icon: 'none'
-        })
-      }
-    } catch (err) {}
-  },
-  handleNav(e) {
-    const { item } = e.currentTarget.dataset
-
-    if (this.data.searchForm.category_id !== item.id) {
-      this.setData({
-        'searchForm.category_id': item.id,
-        navScrollLeft: 0
-      }, () => {
-        this.refreshOrderList()
-      })
-    }
-  },
-  async isLeft(list) {
-    const {
-      leftList,
-      rightList
-    } = this.data
-
-    for (const item of list) {
-      if (leftHeight < rightHeight) {
-        leftList.push(item)
-      } else if (leftHeight === rightHeight) {
-        leftList.length <= rightList ? leftList.push(item) : rightList.push(item)
-      } else {
-        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()
-        })
-      })
-    })
   }
 })

+ 2 - 8
htmldev/shiningWxMini/pages/guide/guide.json

@@ -1,11 +1,5 @@
 {
-  "usingComponents": {
-    "van-loading": "@vant/weapp/loading/index",
-    "goods-item-large": "../../components/goods-item-large"
-  },
+  "usingComponents": {},
   "navigationBarTitleText": "选购指南",
-  "backgroundColor": "#F6F6F6",
-  "backgroundTextStyle": "dark",
-  "enablePullDownRefresh": true,
-  "onReachBottomDistance": 50
+  "backgroundColor": "#F6F6F6"
 }

+ 1 - 57
htmldev/shiningWxMini/pages/guide/guide.wxml

@@ -1,59 +1,3 @@
 <view class="wrapper">
-  <view class="app_page-header-search page-header-search">
-    <view class="app_page-header-search-warp app_width-690">
-      <label for="header-search">
-        <image src="../../image/common/search@2x.png"></image>
-      </label>
-      <input
-        placeholder-class="app_header-search-placeholder"
-        value="{{searchForm.key_words}}"
-        placeholder="搜索"
-        data-formkey="key_words"
-        bind:input="handleKeyWords"></input>
-    </view>
-  </view>
-  <scroll-view
-    class="app_nav-wrap"
-    scroll-x="{{true}}"
-    scroll-with-animation="{{true}}"
-    scroll-into-view="item-{{searchForm.category_id * 1 < 4 ? navScrollLeft : searchForm.category_id * 1 - 3}}">
-    <view
-      class="nav {{searchForm.category_id === item.id ? 'active' : ''}}"
-      wx:for="{{categoryList}}"
-      wx:key="id"
-      data-item="{{item}}"
-      bind:tap="handleNav">
-      <view
-        class="photo"
-        id="item-{{index}}">
-        <image src="{{item.category_img_url}}"></image>
-      </view>
-      <view class="name">{{item.category_name}}</view>
-    </view>
-  </scroll-view>
-  <!--瀑布流-->
-  <view class="waterfall">
-    <view class="waterfall-left">
-      <block wx:for="{{leftList}}" wx:key="id">
-        <goods-item-large item="{{item}}"/>
-      </block>
-    </view>
-    <view class="waterfall-right">
-      <block wx:for="{{rightList}}" wx:key="id">
-        <goods-item-large item="{{item}}"/>
-      </block>
-    </view>
-  </view>
-  <!-- 无数据 -->
-  <view class="list-bitmap" wx:if="{{finished && listData.length < 1}}">
-    <image src="../../image/common/bitmap.png"></image>
-    <text>暂无数据</text>
-  </view>
-  <view class="pullup-wrapper" wx:if="{{!isRefresh}}">
-    <van-loading
-      wx:if="{{!finished}}"
-      size="24px"
-      type="spinner">加载中...
-    </van-loading>
-  </view>
+  选购指南,待完善...
 </view>

+ 3 - 31
htmldev/shiningWxMini/pages/guide/guide.wxss

@@ -1,32 +1,4 @@
-.page-header-search {
-  padding: 20rpx 0 28rpx;
-}
-
-.shopping-car {
-  position: relative;
-  left: 0;
-  top: 0;
-}
-
-.shopping-car image {
-  display: block;
-  width: 40rpx;
-  height: 50rpx;
-}
-
-.waterfall {
-  width: 690rpx;
-  padding: 30rpx 0;
-  margin: 0 auto;
-  font-size: 0;
-}
-
-.waterfall-left,
-.waterfall-right {
-  display: inline-block;
-  width: 330rpx;
-}
-
-.waterfall-right {
-  margin-left: 30rpx;
+.wrapper {
+  padding-top: 100rpx;
+  text-align: center;
 }

+ 40 - 37
htmldev/shiningWxMini/pages/home/home.js

@@ -29,21 +29,20 @@ Page({
       },
       {
         icon: 'guide@2x.png',
-        name: '选购指南',
-        path: 'guide'
+        name: '全部产品',
+        path: 'goods'
       },
       {
         icon: 'collection@2x.png',
         name: '收藏',
         path: 'collection'
+      },
+      {
+        icon: 'news.png',
+        name: '选购指南',
+        path: 'guide'
       }
     ],
-    objNews: {
-      icon: 'news.png',
-      name: '农事天地',
-      path: 'news'
-    },
-    hasNewsTab: false,
     categoryList: [],
     leftList: [],
     rightList: []
@@ -64,19 +63,13 @@ Page({
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady() {
-    this.setData({
-      hasNewsTab: this.getTabBar().data.list.findIndex(item => item.pagePath === 'pages/news/news') > -1
-    })
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    const that = this
-    this.getTabBar().init((value) => {
-      console.log(value)
-    })
+    this.getTabBar().init()
   },
 
   /**
@@ -241,7 +234,9 @@ Page({
   handleNav(item) {
     if (Object.prototype.toString.call(item) === '[object Object]' && item.path) {
       const path = item.path
-
+      if (!path) {
+        return
+      }
       if (path === 'news' || path === 'partner') {
         wx.switchTab({
           url: `/pages/${path}/${path}`
@@ -274,38 +269,46 @@ Page({
             const moIdState = subscriptionsSetting.itemSettings[tmplIds]
             if (moIdState === 'accept') {
               // 接受了消息推送
+              that.handleNav(item)
             } else if (moIdState === 'reject') {
               // 拒绝消息推送
+              that.handleNav(item)
             } else if (moIdState === 'ban') {
               // 已被后台封禁
+              that.handleNav(item)
+            } else {
+              that.handleSubscribeMessageBridge(tmplIds, item)
             }
-
-            that.handleNav(item)
           } else {
-            // 当用户没有点击 ’总是保持以上选择,不再询问‘  按钮。那每次执到这都会拉起授权弹窗
-            wx.showModal({
-              title: '提示',
-              content: '请授权开通服务通知',
-              showCancel: true,
-              success: function (res) {
-                if (res.confirm) {
-                  wx.requestSubscribeMessage({
-                    tmplIds: [tmplIds],
-                    success(res) {
-                      that.handleNav(item)
-                    },
-                    fail(err) {
-                      that.handleNav(item)
-                    }
-                  })
-                }
-              }
-            })
+            that.handleSubscribeMessageBridge(tmplIds, item)
           }
         } else {
           // 订阅消息未开启
+          that.handleSubscribeMessageBridge(tmplIds, item)
         }
       }
     } catch (err) {}
+  },
+  handleSubscribeMessageBridge(tmplIds, item) {
+    const that = this
+    // 当用户没有点击 ’总是保持以上选择,不再询问‘  按钮。那每次执到这都会拉起授权弹窗
+    wx.showModal({
+      title: '提示',
+      content: '请授权开通服务通知',
+      showCancel: true,
+      success: function (res) {
+        if (res.confirm) {
+          wx.requestSubscribeMessage({
+            tmplIds: [tmplIds],
+            success(res) {
+              that.handleNav(item)
+            },
+            fail(err) {
+              that.handleNav(item)
+            }
+          })
+        }
+      }
+    })
   }
 })

+ 0 - 8
htmldev/shiningWxMini/pages/home/home.wxml

@@ -67,14 +67,6 @@
       <image src="../../image/home/{{item.icon}}"></image>
       <text>{{item.name}}</text>
     </view>
-    <view
-      class="nav"
-      data-item="{{objNews}}"
-      bind:tap="handleSubscribeMessage"
-      wx:if="{{hasNewsTab}}">
-      <image src="../../image/home/{{objNews.icon}}"></image>
-      <text>{{objNews.name}}</text>
-    </view>
   </view>
   <!-- 核心入口:最新上架、VR看菜园、频道:村长说农货 -->
   <view class="marketing-wrap">

+ 1 - 1
htmldev/shiningWxMini/pages/home/home.wxss

@@ -97,6 +97,7 @@
 
 .header-nav {
   display: flex;
+  justify-content: space-between;
   align-items: center;
   width: 690rpx;
   margin: 25rpx auto 0;
@@ -106,7 +107,6 @@
   display: flex;
   flex-direction: column;
   align-items: center;
-  width: 25%;
 }
 
 .header-nav .nav image {