yuminge-app/yun-min-program-plugin-master/packageI/warehouseFarm/warehouseFarmGift/warehouseFarmGift.js

140 lines
2.6 KiB
JavaScript

// packageI/warehouseFarm/warehouseFarmGift/warehouseFarmGift.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
keyword: "",
total_page: 0,
page: 1,
list: [],
loading: false,
finished: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
getData() {
if (this.data.loading||this.data.finished) {
return;
}
this.data.loading = true;
let urlStr = app.getNetAddresss("plugin.warehouse.frontend.controllers.gift.list");
app._postNetWork({
url: urlStr,
data: {
keyword: this.data.keyword,
page: this.data.page
},
success: (resdata) => {
let res = resdata.data;
this.data.loading = false;
if (res.result == 1) {
this.setData({
list: this.data.list.concat(res.data.data)
});
this.data.page = this.data.page + 1;
if (res.data.current_page == res.data.last_page) {
this.data.finished = true;
}
} else {
wx.showToast({
icon: "none",
title: res.msg,
duration: 1000,
});
}
},
fail: (res) => {
console.log(res);
},
});
},
initData() {
this.data.loading = false;
this.data.finished = false;
this.data.page = 1;
this.data.list = [];
},
onChange(e) {
this.setData({
keyword: e.detail
});
},
onSearch() {
this.initData();
this.getData();
},
toUrl(e) {
let _data = e.currentTarget.dataset || {};
this.wxRouterLink(_data);
},
wxRouterLink(_data) {
let _Param = '';
const {
url,
...otherParam
} = _data;
Object.keys(otherParam).forEach(function (key) {
if (otherParam[key] !== '') _Param += key + '=' + otherParam[key] + '&';
});
if (url === '') return;
wx.navigateTo({
url: url + '?' + _Param.slice(0, -1)
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getData();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getData();
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
});