|
- // pages/givePage/givePage.js
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- buyNumber: 1,
- ticketNum: 1,
- ticketUser: [],//优惠券信息
- getBackData:"",//赠送回传字段
- surplusNum:0,//剩余张数
- yesMask:false,//提示赠送弹框
- shareId:"",//获取用户标识
- sellId:"",//优惠券券码
- showMask:false,//弹框
- yesShare:false,//防止重复点击赠送按钮
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options.id)
- this.data.id = options.id
- this.data.sellId = options.id;
- if (app.globalData.openId) {
- this.getTicketUser()
- } else {
- app.globalData.openidSuccessFuc = this.getTicketUser;
- }
- },
- getTicketUser: function () {//获取优惠券信息
- app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: this.data.sellId, from: 2 }, e => {
- console.log(e)
- if (e.code == 200) {
- this.setData({
- ticketUser: e.data,
- surplusNum:e.data.num,
- })
- }
- }, this)
- },
-
- getShareId:function(){
- wx.showLoading({
- title: '加载中',
- })
- app.wxRequest(app.globalData.httpUrl + 'couponsell/presentid', { coupon_sell_id: this.data.sellId}, e => {
- console.log(e)
- if (e.code == 200) {
- wx.hideLoading();
- this.setData({
- shareId: e.present_id,
- showMask:true,
- })
- }
- }, this)
- },
- shareBtn:function(){
- if (!this.data.yesShare) {
- this.data.yesShare = true;
- this.getShareId();
- }
- },
- hideMask:function(){
- this.data.yesShare = false;
- this.setData({
- showMask: false,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (options) {
- this.setData({
- showMask: false,
- yesShare:false,
- })
- var shareUrl = "";//分享指定路径
- if (options.from === "button"){
- shareUrl = '/pages/receiveTicket/receiveTicket?shareId=' + this.data.shareId + "&number=" + this.data.buyNumber
- }
- return{
- title:"赠送给好友",
- imageUrl: this.data.ticketUser.coupon_img_small,
- path: shareUrl,
- success: res=> {
- console.log(res, "转发成功")
- },
- }
- },
- addFn: function () {
- if (this.data.ticketNum < this.data.ticketUser.num) {
- this.data.ticketNum++;
- this.setData({
- buyNumber: this.data.ticketNum
- })
- }
- },
- subtractFn: function () {
- if (this.data.ticketNum > 1) {
- this.data.ticketNum--;
- this.setData({
- buyNumber: this.data.ticketNum
- })
- }
- },
- getInputVal: function (e) {
- if (e.detail.value <= this.data.surplusNum){
- console.log(this.data.buyNumber)
- // if (e.detail.value < 1) {
- // wx.showToast({
- // title: "赠送量最小为1",
- // duration: 1000
- // })
- // this.setData({
- // buyNumber: 1,
- // ticketNum: 1
- // })
- // }else{
- // this.setData({
- // buyNumber: e.detail.value,
- // ticketNum: e.detail.value
- // })
- // }
- this.setData({
- buyNumber: e.detail.value,
- ticketNum: e.detail.value
- })
- } else{
- wx.showToast({
- title: "您赠送数量太大",
- duration:1000
- })
- setTimeout(() => {
- this.setData({
- buyNumber: 1,
- ticketNum: 1
- })
- },1000)
- }
- },
- })
|