quan_pro.js
2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var t = require("../../../utils/util.js"), ut = t,
  e = require("../../../utils/common.js"),
  oo = getApp().globalData,
  os = getApp().globalData.setting;
  var utils = require('../../../utils/util.js'),ut=utils;
Page({
  data: {
    stoid: os.stoid,
    url: os.url,
    resourceUrl: os.resourceUrl,
    iurl: os.imghost,
    defaultAvatar: os.resourceUrl + "/static/images/user68.jpg",
    q_data: null,
    id:null,
    config2:null,
  },
  //------初始化加载----------
  onLoad: function(t) {
    var id=t.id;
    this.data.id=id;
    var goods_list = this.selectComponent("#goods_list"); //组件的id
    goods_list.init();
    setTimeout(function() {
      goods_list.get_list();
    }, 300)
  },
  //---展示,显示券的信息---
  onShow: function() {
    var th=this;
    var user_id=getApp().globalData.user_id;
    getApp().request.promiseGet("/api/weshop/prom/coupon/pageCouponList", {
      data:{store_id:os.stoid,type:1,id:th.data.id,user_id:user_id}
    }).then(res => {
         if(res.data.code==0){
            th.setData({q_data:res.data.data.pageData[0]});
         }
    });
  },
  onHide: function() {
    
  },
  //--滚动到顶部--
  doScrollTop: function() {
    wx.pageScrollTo({ scrollTop: 0 });
  },
  //---加载更多是靠这个函数----
  onReachBottom: function() {
    var goods_list = this.selectComponent("#goods_list"); //组件的id
    if (goods_list) goods_list.get_list();
  },
  //-----领取券-----
  get_quan: function() {
    var item=this.data.q_data;
    var cid = this.data.q_data.id;
    var th=this;
    //--先判断会员状态--
    var user_info = getApp().globalData.userInfo;
    if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
      wx.navigateTo({
        url: '/pages/getphone/getphone',
      })
      return false;
    }
    //如果券还在领取中,不能再点
    if (th.data.linging == 1) {
      getApp().my_warnning('领取中..', 0, this);
      return false;
    }
    th.data.linging = 1;
    //如果领取的次数到了
    if (item.everyone_num > 0 && item.lqnum >= item.everyone_num) {
      getApp().my_warnning('领取失败,您已领完该券', 0, this);
      return false;
    }
    var lq_num = item.lqnum;
    var pdata = {
      'uid': oo.user_id,
      'cid': cid,
      'store_id': os.stoid,
      'type': 5
    };
    var app = getApp(),
        th = this;
    app.request.post("/api/weshop/couponList/saveCouponList", {
      data: pdata,
      success: function(res) {
        th.data.linging = 0;
        if (res.data.code == 0) {
          item.lqnum++;
          var text = "dataList[" + index + "].is_get";
          var text2 = "dataList[" + index + "].linging";
          var text3="q_data";
          var obj = {};obj[text] = 1; obj[text2] = 0;obj[text3] = item;obj['show_success']=1;
          th.setData(obj);
        } else {
          app.confirmBox(res.data.msg);
        }
      }
    })
  },
});