123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // pages/myCoupons/myCoupons.js
- const { default: activity } = require("../../api/activity");
- const util = require('../../utils/util.js');
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- couponList:[], //我的卡券列表
- nextPage:1,
- pageSize:12,
- mobile:'', //我的手机号
- totalPage:1, //总页码
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- //获取我的卡券列表 api/supers/coupon/sn-list-member
- let _self = this;
- if(options.mobile) {
- _self.setData({
- mobile:options.mobile
- })
- }
- _self.getSnListMember();
- },
- //获取我的券列表
- async getSnListMember(step='init') {
- let _self = this;
- let nextPage = _self.data.nextPage;
- let pageSize = _self.data.pageSize;
- let mobile = _self.data.mobile;
- let res =await activity.getSnListMember(nextPage,pageSize,mobile);
- let totalPage =Math.ceil(res.count/pageSize);
- _self.setData({
- totalPage:totalPage
- })
- let list =_self.handleList(res.list);
- if(step=='init') {
- _self.setData({
- couponList:list
- })
- } else if(step=='pull') {
- _self.setData({
- couponList:_self.data.couponList.concat(list),
- })
- }
- },
- /**
- * 处理数据
- */
- handleList(list) {
- list.map((item,key)=>{
- item.beignTime = util.format(item.beginTimestamp*1000);
- item.endTime = util.format(item.endTimestamp*1000);
- item.coupon.discount = item.coupon.type.value=='D'?item.coupon.discount/10:item.coupon.discount;
- item.isFree = item.coupon.type.value=='D'&& item.coupon.discount==0?true:false;
- })
- return list;
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- let _self = this;
- let nextPage = _self.data.nextPage;
- let totalPage = _self.data.totalPage;
- if(nextPage>=totalPage) {
- app.showToast ('亲,到底了!');
- return;
- }
- _self.setData({
- nextPage:nextPage+1
- })
- _self.getSnListMember('pull')
- },
- /**
- * 使用券跳转小程序
- */
- goUseCoupon() {
- wx.navigateToMiniProgram({
- appId: 'wxd92a2d29f8022f40',
- path: 'pages/index/index',
- extraData: {
- foo: 'bar'
- },
- envVersion: 'develop',
- success(res) {
- // 打开成功
- }
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|