yuminge-app/yun-min-program-plugin-master/packageA/member/balance/detailed/detailed.js

175 lines
3.5 KiB
JavaScript

// pages/detailed/detailed.js
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
selected: 0,
all: [],
income: [],
//支出
expenditure: [],
balanceLang: '余额',
recordsList: [],
//more
isLoadMore: true,
page: 1,
total_page: 0,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.getNetData(0);
try {
var value = wx.getStorageSync('balance');
if (value) {
this.setData({
balanceLang: value
});
wx.setNavigationBarTitle({
title: value + "明细"
});
// Do something with return value
}
} catch (e) {
// Do something when catch error
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
this.getNetMoreData(this.data.selected);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
godetails(e) {
let item = e.currentTarget.dataset.item;
wx.navigateTo({
url: '/packageA/member/balance/details/details?item=' + JSON.stringify(item)
});
},
//发起http请求
getNetData(index) {
let that = this;
this.data.page = 1;
let urlStr = app.getNetAddresss("finance.balance.record");
urlStr += '&record_type=' + index;
app._getNetWork({
url: urlStr,
success: function(resdata) {
var res = resdata.data;
if (res.result == 1) {
var myData = res.data.data;
that.setData({
total_page: res.data.last_page,
recordsList: myData
});
// if (index == 0) {
// that.setData({
// all: myData
// })
// } else if (index == 1) {
// that.setData({
// income: myData
// })
// } else if (index == 2) {
// that.setData({
// expenditure: myData
// })
// }
}
},
fail: function(res) {
console.log(res);
}
});
},
getNetMoreData(index) {
let that = this;
that.setData({
isLoadMore: false
});
if (this.data.page >= this.data.total_page) {
return;
} else {
this.data.page = this.data.page + 1;
let urlStr = app.getNetAddresss("finance.balance.record");
urlStr = urlStr + '&record_type=' + index + '&page=' + this.data.page;
app._getNetWork({
url: urlStr,
success: function(resdata) {
var res = resdata.data;
if (res.result == 1) {
var myData = res.data.data;
that.setData({
recordsList: that.data.recordsList.concat(myData)
});
} else {
that.setData({
page: that.data.page - 1,
isLoadMore: false
});
}
},
fail: function(res) {
console.log(res);
}
});
}
},
swichTabTItem(e) {
let val = e.detail.index;
this.setData({
selected: val,
recordsList: []
});
this.getNetData(this.data.selected);
}
});