123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import {
- get,
- post
- } from "../../utils/http";
- // pages/couponCentre/couponCentre.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- store_id: '', //店铺id
- page: 1, //页数
- limit: 10, //页面大小
- CouponList: [], //优惠券列表
- couponType: ['抵扣券', '满减券', '全额减免券', '卡券'], //优惠券类型
- total: '', //优惠券总数
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 获取商品id
- this.setData({
- store_id: wx.getStorageSync('store_id')
- })
- // 获取优惠券列表
- this.getCouponList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- if (this.data.CouponList.length < this.data.total) {
- this.getCouponList(++this.data.page)
- } else {
- return
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- // 获取优惠券列表
- getCouponList(_page) {
- let {
- CouponList
- } = this.data
- get('/v2/api/activity/coupon', {
- store_id: this.data.store || wx.getStorageSync('store_id'),
- page: _page || this.data.page,
- limit: this.data.limit
- }, (res) => {
- // 点击领取后刷新页面
- if (_page == 'no') {
- this.setData({
- CouponList: res.data.list,
- total: res.data.total
- })
- }
- // 获取页面时判断是否刷新页面
- if (res.code == 200 && _page != 'no') {
- CouponList.push(...res.data.list)
- this.setData({
- CouponList,
- total: res.data.total
- })
- }
- })
- },
- // 领取优惠券发起请求
- getCoupon(e) {
- let activeId = e.currentTarget.dataset.activeid
- post('/v2/api/activity/receive', {
- id: activeId,
- store_id: wx.getStorageSync('store_id')
- }, (res) => {
- let coupon_id = res.data
- this.getCouponList("no") //刷新数据不添加
- // 发起订阅请求 下发权限
- wx.requestSubscribeMessage({
- tmplIds: ['1c7uBFGMQYBAFRiJIk2IoyKFhC7En3ElONwm8Nwl5HQ'],
- success(res) {
- console.log(res);
- let status = ''
- // 判断是否发起订阅请求 1是确认发送 2不发
- if (res['1c7uBFGMQYBAFRiJIk2IoyKFhC7En3ElONwm8Nwl5HQ'] == 'reject') {
- status = 2
- } else {
- status = 1
- }
- get('/v2/api/activity/push', {
- type: 1,
- status,
- coupon_id,
- }, res => {})
- },
- })
- })
- },
- // 领取过的优惠券跳转到项目列表
- goProject(){
- wx.switchTab({
- url: '/pages/orderBy/orderBy',
- })
- }
- })
|