小程式上拉載入
阿新 • • 發佈:2018-12-22
wxml程式碼
<scroll-view style="height:{{scrollHeight}}px;" scroll-y="true" bindscrolltolower="bindDownLoad" lower-threshold="100"> <view wx:if="{{notimg}}" class='notdata'> <image class='notimf' src='/images/notdata.png'></image> <view class='nottext'>沒有任何商品資訊</view> </view> <view wx:for="{{productInfo}}" class='productcontent' data-pid='{{item.product_id}}' bindtap='navhref'> <image class='productimg' src='{{item.product_pic}}'></image> <view class='productname'>{{item.product_name}}</view> <view class='productprice'> <view class='productmoney'>¥<text style='font-size:17px'>{{item.shop_price}}</text></view> <view class='addprice'>賺¥<text style='font-size:17px'>36.5</text></view> </view> <!-- <view class='closetime'>12月21日 18:00:00 結束</view> --> <!-- 進度條 --> <view class='con_bai'> <progress class='strip' percent="80" color="pink" /> <text>已搶83%</text> </view> </view> <view wx:if="{{loadgif}}" class="body-view"> <loading hidden="{{hidden}}" > 載入中... </loading> </view> </scroll-view>
wxss程式碼
.productcontent{ height: 260rpx; width: 97%; padding-left: 3%; padding-top: 20rpx; border-bottom: 2px solid pink; } .productimg{ width: 35%; height: 70%; float: left; } .productname{ width: 62%; height: 35%; padding-left: 3%; display: inline-block; font-size: 15px; color: #333; } .productprice{ width: 62%; height: 35%; padding-left: 3%; display: inline-block; } .productprice{ height: 30%; line-height: 86rpx; padding-top: 8rpx; font-size: 11px; font-weight: 600; } .addprice{ width: 47.5%; height: 100%; display: inline-block; color: orange; } .productmoney{ width: 30%; height: 100%; display: inline-block; } .closetime{ width: 62%; height: 15%; display: inline-block; font-size: 11px; color: #999999; padding-left: 3%; } .con_bai{ /* border: 1px solid red; */ width: 100%; /* height: 30px; */ float: left; padding:16rpx; margin-top: 10rpx; } progress{ width:40%; float: left; margin-left: 24%; } .con_bai text{ color:#A1A1A1; font-size:10px; float: left; margin-top:-14rpx; margin-left:10rpx; } .notdata{ width: 100%; height: 100%; text-align: center; } .notimf{ margin-top: 35%; width: 90px; height: 90px; } .nottext{ color: #999999; }
js程式碼
var app = getApp(); // pages/characteristic/characteristic.js Page({ data: { scrollHeight: 0,//商品容器高度 productInfo:[], currentPage:1, notimg:false, isdata:true, }, onLoad: function (options) { var that = this; // 獲取螢幕高度 wx.getSystemInfo({ success: function (res) { that.setData({ scrollHeight: res.windowHeight }); } }); //初始化呼叫一次商品資訊 wx.request({ url: app.globalData.requestUrl + 'getIndexProductListByGroup', data: { 'web': app.globalData.webUrl, 'page': that.data.currentPage, }, success(d) { if(d.data.status==1){ that.setData({ productInfo: d.data.info, }) }else{ that.setData({ notimg:true, }) } } }) }, onShow: function () { }, // 商品詳情 navhref: function (e) { // console.log(e.currentTarget.dataset.pid) wx.navigateTo({ url: '/pages/product_info/product_info?productid='+e.currentTarget.dataset.pid, //你自己的介面 }) }, //滑動到底部觸發事件 bindDownLoad: function () { var that = this; //呼叫商品資訊方法 if (that.data.isdata){ getIndexProductListByGroup(that) } }, }) //獲取商品列表資訊 function getIndexProductListByGroup(that) { wx.showLoading({ title: '載入中' }); wx.request({ url: app.globalData.requestUrl + 'getIndexProductListByGroup', data:{ 'web': app.globalData.webUrl, 'page': ++that.data.currentPage, }, success(d){ wx.hideLoading() if(d.data.status==1){ that.setData({ productInfo: that.data.productInfo.concat(d.data.info), }) }else{ that.setData({ isdata:false }) wx.showToast({ title: '沒有更多商品啦', icon:'none' }) } } }) }