|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- // pages/coupon/coupon.js
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- type: 2, //1券码核销 2手机号核销
- user_phone: '', //手机号
- state: 0, //0核销未完成 1核销中 2核销已完成
- totalNums: 1, //总数量
- nums: 1, //核销数量
- coupon_name: '', //优惠券名称
- couponTime: '', //优惠券购买时间
- code_num: '', //核销短信验证码
- couponCode: '', //券号
- couponType: '', //券类型
- duration: '', //券期间
- },
- /**
- * 核销数修改
- */
- changeNums(event) {
- var nums
- if (event.detail.value > this.data.totalNums) {
- nums = this.data.totalNums
- }
- if (event.detail.value < 1) {
- nums = 1
- }
- this.setData({
- nums: nums
- })
- },
- /**
- * 验证码修改
- */
- changeCode(event) {
- this.setData({
- code_num: event.detail.value
- })
- },
- /**
- * 核销
- */
- writeOff: function() {
- if (this.data.state == 1) {
- 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) { //手机号核销
- wx.switchTab({
- url: '../record/record'
- })
- }
- } else {
- state = 0;
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 2000
- })
- }
- that.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
- })
- }
- },
- /**
- * 返回核销大厅
- */
- 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,
- couponTime: couponData.buy_date,
- couponType: couponData.coupon_type,
- duration: couponData.duration
- })
- }
- if (pohone) { //手机号查询
- this.setData({
- type: 2,
- user_phone: pohone,
- totalNums: couponData.num,
- coupon_name: couponData.coupon_name,
- couponTime: couponData.buy_date
- })
- /**
- * 发送验证码
- */
- 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() {
-
- }
- })
|