// pages/coupon/coupon.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { type: 2, //1券码核销 2手机号核销 user_phone: '', //手机号 state: 0, //0核销未完成 1核销中 2核销已完成 totalNums: 50, //总数量 nums: 1, //核销数量 coupon_name: '', //优惠券名称 couponTime: '', //优惠券购买时间 code_num: '', //核销短信验证码 }, /** * 验证码修改 */ changeCode(event) { this.setData({ code_num: event.detail.value }) }, /** * 核销 */ writeOff: function() { if (this.data.state == 1) { return } if (this.data.code_num.length != 6) { wx.showToast({ title: '验证码错误', icon: 'none', duration: 2000 }) } else { this.setData({ state: 1 }) var data = { check_type: 2, user_phone: this.data.user_phone, code_num: this.data.code_num, coupon_sell_id: app.globalData.couponData.coupon_sell_id, coupon_code: '', check_num: this.data.nums } app.requestPost('couponbuy/check', data, res => { var state; if (res.code == 200) { state = 2; wx.switchTab({ url: '../record/record' }) } else { state = 0; wx.showToast({ title: res.message, icon: 'none', duration: 2000 }) } this.setData({ state: state }) }) } }, /** * 添加优惠券 */ addCoupon() { if (this.data.nums + 1 <= this.data.totalNums) { this.setData({ nums: this.data.nums + 1 }) } }, /** * 减少优惠券 */ reduceCoupon() { if (this.data.nums - 1 > 0) { this.setData({ nums: this.data.nums - 1 }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { wx.hideShareMenu(); var code = options.code; var pohone = options.phone; if (code) { //券码查询 this.setData({ type: 1 }) } if (pohone) { //手机号查询 console.log(app.globalData.couponData) var couponData = app.globalData.couponData; this.setData({ type: 2, user_phone: pohone, totalNums: couponData.num, coupon_name: couponData.coupon_name, couponTime: couponData.cdate }) /** * 发送验证码 */ app.requestGet('couponbuy/check/smscode', { user_phone: pohone},res=>{ if(res.code==200){ }else{ wx.showToast({ title: res.message, icon: 'none', duration: 2000 }) } }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })