// pages/coupon/coupon.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { type: 2, //1券码核销 2手机号核销 user_phone: '', //手机号 state: 0, //0核销未完成 1核销中 2核销已完成 headImgUrl:'',//头图 totalNums: 1, //总数量 nums: 1, //核销数量 coupon_name: '', //优惠券名称 couponTime: '', //优惠券购买时间 code_num: '', //核销短信验证码 couponCode: '', //券号 duration: '', //券期间 type_name:'',//券类型 }, /** * 核销数修改 */ changeNums(event) { this.setData({ nums: parseInt(event.detail.value) }) }, /** * 验证码修改 */ changeCode(event) { this.setData({ code_num: event.detail.value }) }, /** * 核销 */ writeOff: function() { if (this.data.state == 1) { return } if (this.data.nums>this.data.totalNums){ wx.showToast({ title: '券剩余数量不足', icon: 'none', duration: 2000 }) return } var data; if (this.data.type == 1) { //券核销 data = { check_type: 1, coupon_code: this.data.couponCode, check_num: 1 } } else { //手机号核销 if (this.data.code_num.length != 6) { wx.showToast({ title: '验证码错误', icon: 'none', duration: 2000 }) return } data = { check_type: 2, user_phone: this.data.user_phone, code_num: this.data.code_num, coupon_code: '', check_num: this.data.nums } } data.coupon_sell_id = app.globalData.couponData.coupon_sell_id; console.log(data); this.setData({ state: 1 }) var that = this; app.requestPost('couponbuy/check', data, res => { var state; if (res.code == 200) { state = 2; if (that.data.type == 2) { //手机号核销 this.setData({ totalNums: this.data.totalNums-this.data.nums }) } } else { state = 0; wx.showToast({ title: res.message, icon: 'none', duration: 2000 }) } that.setData({ state: state }) }) }, /** * 添加优惠券 */ addCoupon() { if (isNaN(this.data.nums)) { this.setData({ nums: 1 }) }else if (this.data.nums + 1 <= this.data.totalNums) { this.setData({ nums: this.data.nums + 1 }) } }, /** * 减少优惠券 */ reduceCoupon() { if (isNaN(this.data.nums)){ this.setData({ nums: 1 }) }else if (this.data.nums - 1 > 0) { this.setData({ nums: this.data.nums - 1 }) } }, blueNums(){ if (isNaN(this.data.nums)) { this.setData({ nums: 1 }) } }, /** * 返回核销大厅 */ goHome() { wx.switchTab({ url: '../home/home' }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { wx.hideShareMenu(); var code = options.code; var pohone = options.phone; var couponData = app.globalData.couponData; if (code) { //券码查询 this.setData({ type: 1, couponCode: code, coupon_name: couponData.coupon_name, type_name: couponData.type_name, couponTime: couponData.buy_date, duration: couponData.duration, headImgUrl: couponData.coupon_img_large }) } if (pohone) { //手机号查询 this.setData({ type: 2, user_phone: pohone, totalNums: couponData.num, coupon_name: couponData.coupon_name, type_name: couponData.type_name, couponTime: couponData.buy_date, duration: couponData.duration, headImgUrl: couponData.coupon_img_large }) /** * 发送验证码 */ 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() { } })