| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- // pages/coupon-list/index.js
- import { getCouponReceive } from '../../api/user.js'
- import { getCoupons } from '../../api/api.js'
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- parameter: {
- navbar: '1',
- return: '1',
- title: '领取优惠券',
- color: false
- },
- couponsList: [],
- loading: false,
- loadend: false,
- page: 1,
- limit: 20
- },
- /**
- * 授权回调
- */
- onLoadFun: function () {
- this.getUseCoupons()
- },
- /** 领取优惠券 */
- getCoupon: function (e) {
- var that = this
- var id = e.currentTarget.dataset.id
- var index = e.currentTarget.dataset.index
- var list = that.data.couponsList
- getCouponReceive({
- couponId: id
- }).then(
- function (res) {
- list[index].is_use = true
- that.setData({
- couponsList: list
- })
- app.Tips({
- title: '领取成功'
- })
- },
- function (res) {
- return app.Tips({
- title: res.msg
- })
- }
- )
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {},
- /**
- * 获取领取优惠券列表
- */
- getUseCoupons: function () {
- var that = this
- if (this.data.loadend) return false
- if (this.data.loading) return false
- that.setData({
- loading: true,
- loadTitle: '正在搜索'
- })
- getCoupons({
- page: this.data.page,
- limit: this.data.limit
- })
- .then(res => {
- var list = res.data,
- loadend = list.length < that.data.limit
- var couponsList = app.SplitArray(list, that.data.couponsList)
- that.setData({
- loading: false,
- couponsList: couponsList,
- page: that.data.page + 1,
- loadend: loadend,
- loadTitle: loadend ? '已全部加载' : '加载更多'
- })
- })
- .catch(err => {
- that.setData({
- loading: false,
- loadTitle: '加载更多'
- })
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.getUseCoupons()
- }
- })
|