|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- // pages/coupon/coupon.js
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- couponType:1,//1代金券 2菜品券
- coupon_img_large:'',//优惠券图片
- coupon_name_detail:'',//券名称
- coupon_memo:'',//券描述
- totalNums: 0, //总数量
- nums: 0, //核销数量
- writeOffing:false,
- original_price:100,//抵消金额
- },
- user_id:null,
- coupon_sell_id:null,
- /**
- * 核销数修改
- */
- changeNums(e) {
- var value=e.detail.value;
- var str=parseInt(value);
- if(str>this.data.totalNums){
- str=this.data.totalNums
- }
- this.setData({
- nums: str?str:0
- })
- },
- /**
- * 核销
- */
- writeOff: function() {
- if(!this.data.writeOffing){
- this.setData({
- writeOffing:true
- })
- var data={
- user_id:this.user_id,
- coupon_sell_id:this.coupon_sell_id,
- check_num:this.data.nums
- }
- app.requestPost('admin/buy/check',data,res=>{
- if(res.code==200){
- wx.showToast({
- title: '核销成功',
- icon: 'success',
- duration: 2000
- })
- this.getCouponDetails();
- // this.setData({
- // writeOffing:false,
- // totalNums:this.data.totalNums-this.data.nums,
- // nums:0
- // })
- }else{
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 2000
- })
- this.setData({
- writeOffing:false
- })
- }
- })
- }
- },
- /**
- * 添加优惠券
- */
- 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();
- this.user_id=options.user_id;
- this.coupon_sell_id=options.coupon_sell_id;
- this.getCouponDetails();
- },
- getCouponDetails(){
- app.requestGet('admin/buy/detail',{user_id:this.user_id,coupon_sell_id:this.coupon_sell_id},res=>{
- if(res.code==200){
- var {coupon_img_large,coupon_name_detail,coupon_memo,num,item_type:couponType,original_price}=res.data;
- this.setData({
- couponType,
- coupon_img_large,
- coupon_name_detail,
- coupon_memo,
- totalNums:num,
- writeOffing:false,
- original_price:parseInt(original_price)
- })
- app.globalData.couponToken = res.token;
- }
- })
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {},
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
-
- }
- })
|