|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // pages/receiveTicket/receiveTicket.js
- const app = getApp();
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- yesGet: true,//是否被领取
- ticketUser:[],//优惠券信息
- titleWord:"",
- presentId:"",//接受的id
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.globalData.present_id = options.shareId;
- this.data.presentId = options.shareId;
- app.globalData.number = options.number;
- this.getTicketUser(options.shareId, options.number);
- // wx.showToast({
- // title: options.number,
- // duration:2000
- // })
- },
-
- getTicketUser: function (id,number) {//获取优惠券信息
- app.wxRequest(app.globalData.httpUrl + 'couponbuy/presentstate', { present_id: id, present_num: number }, e => {
- console.log(e)
- if (e.code == 201) {
- this.setData({
- ticketUser: e.data,
- yesGet: true
- })
- } else if (e.code == 202){
- this.setData({
- yesGet: false,
- titleWord:"此券已被领取"
- })
- } else if (e.code == 203){
- this.setData({
- yesGet: false,
- titleWord: "此券已失效"
- })
- } else if (e.code == -201) {
- this.setData({
- yesGet: false,
- titleWord: "没有相关赠送记录"
- })
- } else if (e.code == 204) {
- this.setData({
- yesGet: false,
- titleWord: "赠送优惠券不足,无法领取"
- })
- } else if (e.code == 205) {
- this.setData({
- yesGet: false,
- titleWord: "优惠券超限,无法领取"
- })
- }
- }, this)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- },
- // "p1583395285z86"
- getTicketFn:function(){//点击领取优惠券
- var id = this.data.presentId;
- app.wxRequest(app.globalData.httpUrl + 'couponbuy/receive', { present_id: id }, e => {
- console.log(e)
- if (e.code == 200) {
- wx.showToast({
- title: '领取成功',
- duration:500
- })
- setTimeout(()=>{
- wx.switchTab({
- url: '/pages/index/index'
- })
- },500)
- } else if (e.code == -201) {//用户未注册
- console.log(e.message)
- } else if (e.code == -202) {//没有相应赠品记录
- console.log(e.message)
- }else if (e.code == -203){//无法领取自己的优惠券
- console.log(e.message)
- wx.showToast({
- title: '领取失败',
- duration: 500
- })
- } else if (e.code == -204) {//赠送优惠券已领取
- console.log(e.message)
- } else if (e.code == -205) {//优惠券已失效
- console.log(e.message)
- wx.showToast({
- title: '优惠券已失效',
- duration: 500
- })
- }
- }, this,"POST")
- },
- backIndex:function(){//优惠券已被领取,点击确定返回首页
-
- },
- })
|