123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- const WXAPI = require('apifm-wxapi')
- const AUTH = require('../../utils/auth')
- var sliderWidth = 96; // 需要设置slider的宽度,用于计算中间位置
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- tabs: ['可领', '已领', '失效', '口令'],
- activeIndex: 0,
- showPwdPop: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (e) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (this.data.activeIndex == 0) {
- this.sysCoupons()
- }
- AUTH.checkHasLogined().then(isLogined => {
- this.setData({
- isLogined
- })
- if (isLogined) {
- if (this.data.activeIndex == 1) {
- this.getMyCoupons()
- }
- if (this.data.activeIndex == 2) {
- this.invalidCoupons()
- }
- }
- })
- },
- onReachBottom: function () {
-
- },
- tabClick: function (e) {
- this.setData({
- activeIndex: e.detail.index
- });
- if (this.data.activeIndex == 0) {
- this.sysCoupons()
- }
- if (this.data.activeIndex == 1) {
- this.getMyCoupons()
- }
- if (this.data.activeIndex == 2) {
- this.invalidCoupons()
- }
- },
- sysCoupons() { // 读取可领取券列表
- var _this = this;
- wx.showLoading({
- title: '',
- })
- WXAPI.coupons().then(function (res) {
- wx.hideLoading({
- success: (res) => {},
- })
- if (res.code == 0) {
- _this.setData({
- coupons: res.data
- });
- } else {
- _this.setData({
- coupons: null
- });
- }
- })
- },
- getCounpon2(){
- if (!this.data.couponPwd) {
- wx.showToast({
- title: '请输入口令',
- icon: 'none'
- })
- return
- }
- const e = {
- kl: true,
- currentTarget: {
- dataset: {
- id: this.data.pwdCounponId
- }
- }
- }
- this.getCounpon(e)
- },
- getCounpon: function (e) {
- const that = this
- if (e.currentTarget.dataset.pwd) {
- this.setData({
- pwdCounponId: e.currentTarget.dataset.id,
- showPwdPop: true
- })
- return
- } else {
- if (!e.kl) {
- this.data.couponPwd = ''
- }
- }
- this.setData({
- showPwdPop: false
- })
- WXAPI.fetchCoupons({
- id: e.currentTarget.dataset.id,
- token: wx.getStorageSync('token'),
- pwd: this.data.couponPwd
- }).then(function (res) {
- if (res.code == 20001 || res.code == 20002) {
- wx.showModal({
- title: '错误',
- content: '来晚了',
- showCancel: false
- })
- return;
- }
- if (res.code == 20003) {
- wx.showModal({
- title: '错误',
- content: '你领过了,别贪心哦~',
- showCancel: false
- })
- return;
- }
- if (res.code == 30001) {
- wx.showModal({
- title: '错误',
- content: '您的积分不足',
- showCancel: false
- })
- return;
- }
- if (res.code == 20004) {
- wx.showModal({
- title: '错误',
- content: '已过期~',
- showCancel: false
- })
- return;
- }
- if (res.code == 0) {
- wx.showToast({
- title: '领取成功',
- icon: 'success'
- })
- } else {
- wx.showModal({
- title: '错误',
- content: res.msg,
- showCancel: false
- })
- }
- })
- },
- getMyCoupons: function () {
- var _this = this;
- wx.showLoading({
- title: '',
- })
- WXAPI.myCoupons({
- token: wx.getStorageSync('token'),
- status: 0
- }).then(function (res) {
- wx.hideLoading({
- success: (res) => {},
- })
- if (res.code == 0) {
- res.data.forEach(ele => {
- if (ele.dateEnd) {
- ele.dateEnd = ele.dateEnd.split(" ")[0]
- }
- })
- _this.setData({
- coupons: res.data
- })
- } else {
- _this.setData({
- coupons: null
- })
- }
- })
- },
- invalidCoupons: function () {
- var _this = this;
- wx.showLoading({
- title: '',
- })
- WXAPI.myCoupons({
- token: wx.getStorageSync('token'),
- status: '1,2,3'
- }).then(function (res) {
- wx.hideLoading({
- success: (res) => {},
- })
- if (res.code == 0) {
- _this.setData({
- coupons: res.data
- })
- } else {
- _this.setData({
- coupons: null
- })
- }
- })
- },
- toIndexPage: function () {
- wx.switchTab({
- url: "/pages/index/index"
- });
- },
- pwdCouponChange(e){
- this.setData({
- couponPwd: e.detail.value
- })
- },
- onPullDownRefresh() {
- if (this.data.activeIndex == 0) {
- this.sysCoupons()
- }
- if (this.data.activeIndex == 1) {
- this.getMyCoupons()
- }
- if (this.data.activeIndex == 2) {
- this.invalidCoupons()
- }
- wx.stopPullDownRefresh()
- },
- closePwd() {
- this.setData({
- showPwdPop: false
- })
- },
- processLogin(e) {
- if (!e.detail.userInfo) {
- wx.showToast({
- title: '已取消',
- icon: 'none',
- })
- return;
- }
- AUTH.register(this);
- },
- async exchangeCoupons() {
- if (!this.data.number) {
- wx.showToast({
- title: '请输入券号',
- icon: 'none'
- })
- return
- }
- if (!this.data.pwd) {
- wx.showToast({
- title: '请输入密码',
- icon: 'none'
- })
- return
- }
- this.setData({
- exchangeCouponsLoading: true
- })
- wx.showLoading({
- title: '',
- })
- const res = await WXAPI.exchangeCoupons(wx.getStorageSync('token'), this.data.number, this.data.pwd)
- wx.hideLoading({
- success: (res) => {},
- })
- this.setData({
- exchangeCouponsLoading: false
- })
- if (res.code != 0) {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '兑换成功'
- })
- }
- },
- })
|