美文网首页
微信小程序分页

微信小程序分页

作者: 刘叶青 | 来源:发表于2019-03-26 10:17 被阅读0次

wxml:
<block wx:if="{{list.length != 0}}">

    <view  bindtouchstart="touchstart" bindtouchend="touchend" style="height:{{win_h}}px;">

        <view class='report_item' wx:for="{{list}}">

            <view class="clearfix">

                <view class='title_left pull-left'>科室</view>

                <view class='report_info pull-right'>{{item.jzksmc}}</view>

            </view>

            <view class="clearfix">

                <view class='title_left pull-left'>医院</view>

                <view class='report_info pull-right'>{{item.hosname}}</view>

            </view>

            <view class="clearfix">

                <view class='title_left pull-left'>疾病名称</view>

                <view class='report_info pull-right'>{{item.zdmc}}</view>

            </view>

            <view class="clearfix">

                <view class='title_left pull-left'>就诊日期</view>

                <view class='report_info pull-right'>{{item.jzrq}}</view>

            </view>

            <view class="clearfix">

                <view class='title_left pull-left'>医生姓名</view>

                <view class='report_info pull-right'>{{item.ysxm}}</view>

            </view>

        </view>

        <block wx:if="{{!more_data}}">

            <view class="text-center gray">没有更多数据了</view>

        </block>

    </view>

</block>

<block wx:else>

    <view class="text-center gray">

        <view class="no_list_data">

            <image src="{{img_url}}no_content.png" class="no_content"></image>

        </view>

        <view>暂无数据</view>

    </view>

</block>

wxss:

page{

    background: #f5f5f5;

    line-height: 80rpx;

}

.report_item{

    background: #fff;

    margin-bottom:20rpx;

}

.report_item>view{

    padding: 0 20rpx;

}

js:

const app = getApp();

Page({

    data : {

        idcard : '',

        img_url : app.global_data.img_url,

        list : [],

        curpage : '1',

        pagesize : '10',

        clientY1 : 0,

        clientY2 : 0,

        more_data : true, //判断分页有没有更多数据

    },

    onLoad(query) {

      let that = this;

      wx.showLoading({

          title: '加载中...',

      });

      let win_h = wx.getSystemInfoSync().windowHeight;

      let idcard = query.idcard;

      console.log('idcard', idcard);

      that.setData({

          idcard, win_h

      });

      get_list(that);

    },

    touchstart(e){

        let that = this;

        let clientY1 = e.changedTouches[0].clientY;

        that.setData({

            clientY1

        });

    },

    touchend(e){

        let that = this;

        let clientY2 = e.changedTouches[0].clientY;

        that.setData({

            clientY2

        });

        let clientY1 = that.data.clientY1;

        console.log(clientY1, clientY2);

        if(clientY2 < clientY1){

            let curpage = parseInt(that.data.curpage);

            ++curpage;

            curpage = curpage.toString();

            console.log(curpage);

            that.setData({

                curpage

            });

            let more_data = that.data.more_data;

            if(more_data){

                wx.showLoading({

                    title: '加载中...',

                });

                get_list(that);

            }

        }

    },

    set_time (e) {

        this.setData({

          times_index: e.detail.value

        });

    },

    get_detail(e){

        let that = this;

        let pexamid = e.currentTarget.dataset.pexamid;

        let jgdm = e.currentTarget.dataset.jgdm;

        let examname = e.currentTarget.dataset.examname;

        let examdate = e.currentTarget.dataset.examdate;

        let bdate = e.currentTarget.dataset.bdate;

        let hosname = e.currentTarget.dataset.hosname;

        let tjzj = e.currentTarget.dataset.tjzj;

        let jkjy = e.currentTarget.dataset.jkjy;

        wx.navigateTo({

            url: '../body_exam_detail/body_exam_detail?pexamid=' + pexamid + '&jgdm=' + jgdm + '&examname=' + examname + '&examdate=' + examdate + '&bdate=' + bdate + '&hosname=' + hosname + '&tjzj=' + tjzj + '&jkjy=' + jkjy

        });

    }

});

function get_list(that) {

    // 上线前,把下面的idcard改成that.data.idcard

    let idcard = that.data.idcard;

    let pagesize = that.data.pagesize;

    let curpage = that.data.curpage;

    wx.request({

        url: app.global_data.ajax_url + 'platform/HYServer?requesttype=1020&sfzh=' + idcard + '&pagesize=' + pagesize + '&curpage=' + curpage,

        success(res) {

            let new_list = JSON.parse(res.data.data);

            let pagesize = that.data.pagesize;

            if(new_list.length < parseInt(pagesize)){

                let more_data = false;

                that.setData({

                    more_data

                });

            }

            if(new_list.length > 0){

                let list = that.data.list.concat(new_list);

                that.setData({

                    list

                });

            }

        },

        fail(res){

            console.log(res);

        },

        complete(){

            wx.hideLoading();

        }

    });

}

相关文章

网友评论

      本文标题:微信小程序分页

      本文链接:https://www.haomeiwen.com/subject/lugwvqtx.html