小程序?qū)崿F(xiàn)下拉加載

  • 首頁下拉加載數(shù)據(jù)

    • index.wxml

        //引用封裝好的小數(shù)點(diǎn)保留2位的方法
      <wxs module="filters" src="../../../filter/filter.wxs"></wxs>
      <view class="order-list">
          <view class="navagator">
             <!-- 標(biāo)簽欄 -->
            <view style="color:#797d82;">
              <van-tabs>
                <van-tab title="全部"></van-tab>
                <van-tab title="待分享"></van-tab>
                <van-tab title="待付款"></van-tab>
                <van-tab title="待發(fā)貨"></van-tab>
                <van-tab title="待收貨"></van-tab>
              </van-tabs>
            </view>
          </view>
        <!-- 商品詳情 -->
          <view class="goodsDetail">
            <view class="goodsBox" style="margin-top:30rpx;" wx:for="{{orderListArr}}" wx:key="{{index}}" bindtap="toDetail" data-orderId="{{item.orderId}}">
              <van-card class="padd-15" wx:for="{{item.carts}}" wx:key="{{cartsItem.cartId}}" wx:for-item="cartsItem" num="{{cartsItem.buyNum}}" price="{{filters.toFix(cartsItem.price)}}" title="{{cartsItem.masterName}}" thumb="{{cartsItem.imgUrl}}" style="font-size: 30rpx;background-color: #fff;" />
              <view slot="footer" style="height:80rpx" class="border-line">
                <view style="height:26rpx;font-size:26rpx;padding-right:20rpx">
                  共{{item.cartnumber}}件商品
                  <text style="padding-left:20rpx"></text>
                  實(shí)付¥
                  <text style="color:#C03131;font-size:30rpx">{{filters.toFix(item.totalPrice)}}</text>
                </view>
              </view>
              <view slot="footer" class="margin-top">
                <text class="flr">{{item.payStatus == "0"?"已取消":"交易成功"}}</text>
                <view class="buttosize">{{item.payStatus == "0"?"重新購買":"評(píng)價(jià)"}}</view>
              </view>
            </view>
        </view>
      </view>
      
    • index.wxss

      .van-card__price {
         color: #C03131 !important;
      }
      .padd-15 {
        padding: 30rpx 30rpx 0 30rpx;
      }
      .border-line {
         background-color: #fff;
         display: flex;
         justify-content: flex-end;
         line-height: 80rpx;
         height: 80rpx;
         border-bottom: 2rpx solid #ece9e9;
         border-top: 2rpx solid #ece9e9;
         z-index: 3
      }
      .van-card[data-v-55a01f0e] {
        border-bottom: 2rpx solid #ECE9E9;
      }
      .van-card:not(:first-child) {
        margin-top: 0
      }
      van-nav-bar .van-icon {
        color: #2e2f30;
        font-size: 44rpx
      }
      .order-list {
        height: 100%;
        background: #fff
      }
      .order-list .van-card {
        background: #fff
      }
      .order-list .navagator {
        position: fixed;
        width: 100%;
        top: 0;
        z-index: 9
      }
      .van-card__header {
          background: #fff
      }
      .order-list .goodsDetail {
        margin-top: 45px;
        background: #fff
      }
      img {
        width: 140rpx;
        height: 140rpx
      }
      .van-card__thumb {
        width: 140rpx;
        height: 140rpx
      }
      .van-image__error,
      .van-image__img,
      .van-image__loading {
        width: 140rpx;
        height: 140rpx
      }
      .van-card__content {
        height: 140rpx
      }
      .van-card__header {
        min-height: 140rpx
      }
      .van-card__bottom {
        line-height: 40rpx;
        margin-top: 64rpx
      }
      .van-card {
        background: white
      }
      .flr {
        float: left;
        line-height: 90rpx;
        color: #bdc0c5
      }
      .buttosize {
        font-size: 26rpx;
        width: 172rpx;
        height: 66rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2rpx solid #2e2f30;
        box-sizing: border-box
      }
      .margin-top {
        height: 90rpx;
        align-items: center;
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        margin-right: 10rpx;
        padding: 0 20rpx
      }
      
    • index.json

      {
        "usingComponents": {
          "w-swiper": "/components/w-swiper/w-swiper",
          "van-sticky": "../../../dist/sticky/index"
        },
        "navigationBarTitleText": "首頁"
      }
      
    • index.js

      //獲取應(yīng)用實(shí)例
      // const filterFn  = require("../../filter/filter.js");
      const app = getApp()
      //Page Object
      Page({
        data: {
          // 首頁頭部圖片
          headSwiper: [],
          // 商品分類數(shù)組
          categoryList: [],
          // 商品列表
          productList: [],
          pageNum: 1,
          pullDownArr: [],
          // flag:true
          resing: [],
          dataBack: true
        },
        sendId(event) {
          // console.log(event.currentTarget.dataset.link)
          var productId = event.currentTarget.dataset.link
          wx.navigateTo({
            url: productId
          });
        },
        // 頁面展示相當(dāng)于 created()
        onShow: function () {
          // 獲取輪播圖數(shù)據(jù)
          this.getDataList()
          // 獲取商品分類數(shù)據(jù)
          this.categoryData()
          // 商品列表
          this.productListData(this.data.pageNum)
      
          // this.goodList(1)
        },
        // 獲取輪播圖數(shù)據(jù)
        getDataList() {
          let url = '/product/getBanners'
          app.$get(url).then(res => {
            // console.log(res,'sss')
            this.setData({
              headSwiper: res.banners
            })
          }).catch(err => {
            console.log(err)
          })
        },
        // 獲取商品分類數(shù)據(jù)
        categoryData() {
          let url = '/category/all'
          app.$get(url).then(res => {
            // console.log(res,'商品分類')
              this.setData({
              categoryList: res.list
            })
          }).catch(err => {
            console.log(err)
          })
        },
        // 獲取商品列表數(shù)據(jù)
        productListData(pageNum) {
          // console.log(2 + 1)
          let url = "/product/list?pageNum=" + pageNum
          app.$get(url).then(res => {
           wx.showLoading({
              title: '拼命加載中',
            })
      
            setTimeout(function () {
              wx.hideLoading()
            }, 2000)
            // 節(jié)流  判斷這個(gè)接口數(shù)組的長度  當(dāng)這個(gè)接口數(shù)組不為空的時(shí)候發(fā)送請(qǐng)求數(shù)據(jù) 问词,否則不發(fā)送
            if (res.list.length) {
              console.log(res.list, '商品列表')
              //遍歷這個(gè)接口數(shù)組
              let tempArr = res.list.map(item => {
                return {
                  ...item,
                  //把商品價(jià)格保留2位小數(shù)
                  minPrice: (item.minPrice / 100).toFixed(2)
                }
              })
              // 拼接productList
              let tempt = this.data.productList.concat(tempArr)
              // 保存數(shù)據(jù)
              this.setData({
                // 然后把這個(gè)數(shù)組賦值給productList
                productList: tempt,
                resing: res.list,
                dataBack: true
              })
            }
          }).catch(err => {
            console.log(err)
          })
        },
      
        // 事件處理函數(shù)的聲明(上拉刷新)
        // onPullDownRefresh: function () {
        //   // 重新加載數(shù)據(jù)
        //   this.setData({ pageNum: 0 })
        //   this.getData()
        // },
        // 監(jiān)聽用戶上拉觸底事件(下拉加載)
        onReachBottom() {
          if (this.data.dataBack) {
            // 判斷數(shù)據(jù)長度是否為0
            let pages = this.data.pageNum + 1
            console.log(pages)
            this.productListData(pages)
            this.setData({
              pageNum: pages,
              // 當(dāng)監(jiān)聽數(shù)據(jù)為假的時(shí)候不在發(fā)送請(qǐng)求
              dataBack: false
            })
          }
        }
      });
      
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
禁止轉(zhuǎn)載夺克,如需轉(zhuǎn)載請(qǐng)通過簡信或評(píng)論聯(lián)系作者拳亿。
  • 序言:七十年代末漓库,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子趟咆,更是在濱河造成了極大的恐慌添瓷,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,386評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件值纱,死亡現(xiàn)場(chǎng)離奇詭異仰坦,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)计雌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來玫霎,“玉大人凿滤,你說我怎么就攤上這事∈” “怎么了翁脆?”我有些...
    開封第一講書人閱讀 164,704評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長鼻种。 經(jīng)常有香客問我反番,道長,這世上最難降的妖魔是什么叉钥? 我笑而不...
    開封第一講書人閱讀 58,702評(píng)論 1 294
  • 正文 為了忘掉前任罢缸,我火速辦了婚禮,結(jié)果婚禮上投队,老公的妹妹穿的比我還像新娘枫疆。我一直安慰自己,他們只是感情好敷鸦,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,716評(píng)論 6 392
  • 文/花漫 我一把揭開白布息楔。 她就那樣靜靜地躺著寝贡,像睡著了一般。 火紅的嫁衣襯著肌膚如雪值依。 梳的紋絲不亂的頭發(fā)上圃泡,一...
    開封第一講書人閱讀 51,573評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音愿险,去河邊找鬼颇蜡。 笑死,一個(gè)胖子當(dāng)著我的面吹牛拯啦,可吹牛的內(nèi)容都是我干的澡匪。 我是一名探鬼主播,決...
    沈念sama閱讀 40,314評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼褒链,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼唁情!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起甫匹,我...
    開封第一講書人閱讀 39,230評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤甸鸟,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后兵迅,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體抢韭,經(jīng)...
    沈念sama閱讀 45,680評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,873評(píng)論 3 336
  • 正文 我和宋清朗相戀三年恍箭,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了刻恭。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,991評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡扯夭,死狀恐怖鳍贾,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情交洗,我是刑警寧澤骑科,帶...
    沈念sama閱讀 35,706評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站构拳,受9級(jí)特大地震影響咆爽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜置森,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,329評(píng)論 3 330
  • 文/蒙蒙 一斗埂、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧凫海,春花似錦蜜笤、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽沪伙。三九已至,卻和暖如春县好,著一層夾襖步出監(jiān)牢的瞬間围橡,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評(píng)論 1 270
  • 我被黑心中介騙來泰國打工缕贡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留翁授,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,158評(píng)論 3 370
  • 正文 我出身青樓晾咪,卻偏偏與公主長得像收擦,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子谍倦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,941評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容