var help = require('/util/help.js');
|
var api = require('/util/api.js');
|
var $this;
|
Page({
|
data: {
|
/* 列表数据开始 */
|
list: [],
|
showLoading: false,
|
page: 1,
|
total: 0,
|
showEmptyDefault: false,
|
isRequesting: false,//是否正在请求中
|
showFooter: false,
|
/* 列表数据结束 */
|
|
|
//中奖弹框
|
showDrawnModal: false,
|
//过期未领弹框
|
showOutDateModal: false,
|
showNotice: false,
|
noticeMode: 'closable',//closable
|
},
|
|
onLoad() {
|
help.setPageNavBar("天天领现金");
|
$this = this;
|
$this.requestNotice();
|
$this.requestActivity(1, true);
|
//延时请求
|
setTimeout(() => {
|
$this.requestRecieveAwardNotify();
|
}, 1000);
|
|
},
|
|
//请求活动
|
requestActivity(page, first) {
|
$this.setData({
|
page: page,
|
isRequesting: true,
|
showEmptyDefault: false
|
});
|
if (first) {
|
my.showNavigationBarLoading();
|
}
|
api.getRecommendActivity({
|
data: {
|
page: page
|
},
|
showErrorToast: true,
|
showLoading: first,
|
success: function (res) {
|
console.log(res)
|
if (res.code == 0) {
|
var list = res.data.data;
|
//设置列表数据
|
if (list != null && list.length > 0) {
|
var totalList = $this.data.list.concat(list);
|
if (page == 1) {
|
totalList = list;
|
}
|
$this.setData({
|
total: res.data.count,
|
list: totalList,
|
showFooter: totalList.length >= res.data.count
|
})
|
}
|
//设置空列表默认显示
|
if (page == 1 && (list == null || list.length == 0)) {
|
$this.setData({
|
showEmptyDefault: true
|
})
|
}
|
}
|
},
|
fail: function () {
|
//请求失败需要将页码减1
|
if ($this.data.page > 1) {
|
$this.setData({
|
page: $this.data.page - 1
|
});
|
}
|
},
|
complete: function () {
|
my.hideNavigationBarLoading();
|
my.stopPullDownRefresh();
|
setTimeout(() => {
|
$this.setData({
|
isRequesting: false,
|
showLoading: false
|
});
|
}, 1000);
|
|
}
|
});
|
|
},
|
requestNotice() {
|
api.getNotice({
|
position: 'home',
|
success(res) {
|
if (res.code == 0) {
|
$this.setData({
|
notice: res.data,
|
showNotice: true,
|
noticeMode: res.data.link ? 'link' : 'closable'
|
})
|
}
|
}
|
});
|
|
},
|
//获取奖项通知
|
requestRecieveAwardNotify() {
|
api.getRecieveAwardNotify({
|
success: function (res) {
|
if (res.code == 0) {
|
if (res.data.type == 1)//领奖
|
{
|
$this.setData({
|
award: res.data,
|
showDrawnModal: true
|
});
|
} else if (res.data.type == 2)//过期
|
{
|
$this.setData({
|
award: res.data,
|
showOutDateModal: true
|
});
|
}
|
|
}
|
}
|
});
|
},
|
//领奖
|
onRecieveAward() {
|
api.recieveAward({
|
showLoading: true,
|
showErrorToast: true,
|
activityId: $this.data.award.activityId,
|
success: function (res) {
|
if (res.code == 0) {
|
my.showToast({
|
content: res.msg
|
});
|
} else {
|
my.showToast({
|
content: res.msg
|
});
|
}
|
}
|
|
});
|
},
|
onOutDateDetailClick() {
|
api.setDrawnNotifyRead({
|
id: $this.data.award.id,
|
success: function (res) {
|
|
}
|
});
|
},
|
|
//下拉刷新
|
onPullDownRefresh() {
|
this.requestActivity(1, false);
|
},
|
//到达底部
|
async scrollMytrip() {
|
if (this.data.isRequesting)
|
return;
|
try {
|
console.log('scrollMytrip:');
|
const { page, list, } = this.data;
|
// 判断是否还有数据需要加载
|
if (list.length < this.data.total) {
|
//开启加载
|
this.setData({ showLoading: true });
|
const newPage = page + 1;
|
$this.requestActivity(newPage);
|
}
|
} catch (e) {
|
this.setData({ showLoading: false });
|
console.log('scrollMytrip执行异常:', e);
|
}
|
},
|
clickItem(event) {
|
var item = help.getEventParam(event, 'item');
|
console.log(item.activity.id);
|
my.navigateTo({
|
url: '/pages/activity-detail/activity-detail?id=' + item.activity.id
|
});
|
},
|
showDialog() {
|
|
|
},
|
onCloseDialog1() {
|
|
this.setData({
|
showDrawnModal: false
|
|
});
|
|
|
},
|
onCloseDialog2(event) {
|
this.setData({
|
showOutDateModal: false
|
});
|
},
|
|
|
|
|
onNoticeClick() {
|
|
if (this.data.noticeMode == 'closable') {
|
this.setData({
|
showNotice: false
|
});
|
} else {
|
my.showToast({
|
content: "进入详情"
|
});
|
if ($this.data.notice.link) {
|
my.navigateTo({
|
url: '/pages/web/web?url=' + $this.data.notice.link
|
})
|
}
|
}
|
}
|
|
|
});
|