123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- var app = getApp();
- Page({
- data: {
- couponList: [],
- couponNumber: '',
- tabList: ['未使用', '已使用', '已过期'],
- discStatus: '',
- tabIndex: 0,
- ticketDiscountList:[]
- },
- toggleTab(e) {
- this.setData({
- tabIndex: e.currentTarget.dataset.index,
- couponList: [],
- page: 1,
- });
- this.switchDiscStatus(e.currentTarget.dataset.index);
- },
- /**
- * 根据使用类型查询用户已领取的优惠券列表
- */
- switchDiscStatus(tabIndex) {
- let that = this;
- if (tabIndex == 0) {
- that.setData({
- discStatus: 0
- });
- } else if (tabIndex == 1) {
- that.setData({
- discStatus: 1
- });
- } else if (tabIndex == 2) {
- that.setData({
- discStatus: 2
- });
- }
- that.getCouponList();
- this.getTicketDiscountList();
- },
- /**
- * 暂时无用,兑换码触发
- */
- bindCouponNumberInput: function (e) {
- this.setData({
- couponNumber: e.detail.value
- });
- },
- onLoad: function (options) {
- // 页面初始化 options为页面跳转所带来的参数
- this.setData({
- discStatus: 0
- });
- this.getCouponList();
- this.getTicketDiscountList();
- },
- onReady: function () {
- },
- onShow: function () {
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- },
- /**
- * 查看用户已领取的优惠券
- */
- getCouponList() {
- wx.showLoading({
- title: '加载中...',
- });
- let that = this;
- util.request(api.CouponList, { coupon_number: that.data.couponNumber, discStatus: that.data.discStatus}).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- couponList: res.data
- });
- wx.hideLoading();
- }
- });
- },
- /**
- * 查看优惠券列表
- */
- getTicketDiscountList() {
- let that = this;
- util.request(api.TicketDiscountList, { storeId: wx.getStorageSync('storeId')}).then(function (res) {
- if (res.errno === 0) {
- // console.log(res.data);
- that.setData({
- ticketDiscountList: res.data
- });
- }
- });
- },
- /**
- * 兑换优惠券,暂时无用
- */
- exchangeCoupon() {
- var that = this;
- if (that.data.couponNumber.length == 0
- && that.data.couponNumber == '0') {
- wx.showModal({
- title: '错误信息',
- content: '优惠码不能为空',
- showCancel: false
- });
- return false;
- }
- util.request(api.CouponExchange, {
- coupon_number: that.data.couponNumber
- }, 'POST').then(function (res) {
- if (res.errno === 0) {
- wx.showToast({
- title: '兑换成功'
- });
- that.getCouponList();
- } else if (res.errno === 1) {
- util.showErrorToast(res.errmsg);
- }
- });
- },
- /**
- * 优惠券可使用商品
- */
- linkCoupon(event){
- // let url = event.currentTarget.dataset.couponUrl;
- let tickDiscId = event.currentTarget.dataset.tickId;
- let storeTopicId = event.currentTarget.dataset.storeTopicId;
- let storeId = wx.getStorageSync('storeId');
- wx.navigateTo({
- url: '../ticketDiscountGoods/ticketDiscountGoods?tickDiscId=' + tickDiscId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId
- })
- },
- /**
- * 领取优惠券
- */
- getUserCoupon(event) {
- var that = this;
- let tickDiscId = event.currentTarget.dataset.couponId;
- let storeTopicId = event.currentTarget.dataset.storeTopicId;
- let storeId = wx.getStorageSync('storeId');
- util.request(api.getUserCoupon, {
- tickDiscId: tickDiscId,
- storeTopicId: storeTopicId,
- storeId: storeId
- }, 'POST').then(function (res) {
- if (res.errno === 0) {
- wx.showToast({
- title: '领取成功'
- });
- that.setData({
- discStatus: 0,
- tabIndex: 0
- });
- that.getCouponList();
- that.getTicketDiscountList();
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- });
- },
- clearData: function () {
- let that = this;
- that.setData({
- couponNumber: ''
- });
- },
- /**
- * 去逛逛
- */
- toIndexPage: function () {
- wx.switchTab({
- url: "/pages/index/index"
- });
- },
- getCouponDetail(event) {
- // let url = event.currentTarget.dataset.couponUrl;
- let couponId = event.currentTarget.dataset.couponId;
- let storeTopicId = event.currentTarget.dataset.storeTopicId;
- let storeId = wx.getStorageSync('storeId');
- if (this.data.discStatus == 0) {
- wx.navigateTo({
- url: '../couponDetail/couponDetail?couponId=' + couponId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId + "&&isShare=2"
- })
- }else{
- if(this.data.discStatus == 1){
- wx.showToast({
- title: '该优惠券已使用',
- icon: 'none'
- })
- }else{
- wx.showToast({
- title: '该优惠券已过期',
- icon: 'none'
- })
- }
- }
- },
- getCouponDetail2(event) {
- // let url = event.currentTarget.dataset.couponUrl;
- let discId = event.currentTarget.dataset.discId;
- let storeTopicId = event.currentTarget.dataset.storeTopicId;
- let storeId = wx.getStorageSync('storeId');
- wx.navigateTo({
- url: '../couponDetail/couponDetail?discId=' + discId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId + "&&isShare=0"
- })
- },
-
- })
|