Jamcuk
2017-12-27 3996156e8e022dce953986acd91c3045272a4adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// pages/mingxi/mingxi.js
 
const app = getApp();
const com = require("../../utils/common.js");
const dowx = require("../../utils/DOWX.js");
 
 
Page({
 
    data: {
        // 问题组
        openid: null,
        userlist: [],
        sizemax: 0, //列表总页数
 
 
        // 页面信息
        scrolltop: 0 //滑动框距离顶部的距离
    },
 
    onShow: function () { var th = this; th.refresh(); },
 
    // 刷新按钮
    refresh: function () 
    {
        dowx.Startrefresh(this);
        var th = this;
        // 获取我的openid
        app.Get_info(function (dd) 
        {
            th.setData({ openid: dd.info2.openid });
            th.yema = 1;
            th.Get_userlist(th.yema);//请求通知列表
        });
        // 回到顶部
        th.setData({ scrolltop: 0 });
    },
 
    // 滑动框触底事件
    tf_llviewower: false, //是否正在进行触底事件
    yema: 1, //请求的页码
    ScrollviewEnd: function () 
    {
        var th = this;
        if (th.tf_llviewower == false) 
        {
            th.tf_llviewower = true; //正在触发
            setTimeout(function () { th.tf_llviewower = false }, 500); //500ms防刷
 
            th.yema++;//页码+1
            if (th.yema <= th.data.sizemax) {
                // 页码未超标
                th.Get_userlist(th.yema); //获取精选列表第n页
            }
            else {
                // 页面超标
                th.yema = th.data.sizemax;//让页码=最大值
                wx.showToast({ title: '没有更多了' });
            }
        }
    },
 
 
 
 
 
    // 请求数据相关
    // 请求通知列表,参数:  页码
    Get_userlist: function (yemaC) 
    {
        var th = this;
        // 数据准备
        var mydata = {
            openid: th.data.openid,
            page: yemaC,
            pagesize: 16
        };
        var myurl = com.getWholeUrl("bainian/api/client/user/getmoneyhistory", mydata);
        // 发送请求
        dowx.AjaxPost(myurl, {}, function (res) 
        {
            dowx.Stoprefresh(th);
            dowx.AjaxStop();
 
            if (res.code == 0) 
            {
                th.setData({ sizemax: res.data.count });//保存总页数
                var zu_mo = [];  // 重新设置一个数组来保存信息
                var datamo = res.data.data;//请求所返回的data组
                for (var i = 0; i < datamo.length; i++) 
                {
                    var data_mo = {
                        money: datamo[i].money, //变动金额
                        tf_add: datamo[i].add, //是否为收入(否即为支出)
                        time: dowx.FormatDate(datamo[i].createtime), //收支时间
                        content: datamo[i].desc //具体收支说明
                    };
                    zu_mo.push(data_mo);
                }
 
                // 如果请求的是第一页,那么覆盖原列表
                if (yemaC == 1) { th.setData({ userlist: zu_mo }); }
                // 如果请求大于第一页,那么在原列表后面串接
                else if (yemaC > 1) {
                    var mo = th.data.userlist.concat(zu_mo);
                    th.setData({ userlist: mo });
                }
            }
            else { dowx.Showred(th, '获取收支明细列表返回错误:' + res.msg); }
        });
    }
 
})