indepCoupon3.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/indepCoupon/indepCoupon.js
  2. var app = getApp();
  3. var WxParse = require('../../wxParse/wxParse.js');
  4. Page({
  5. data: {
  6. hiddenmodal: true, //提示弹窗
  7. getFlag : 0,//是否领取过的标志,0为未领取过
  8. couponFlag : 0,//剩余优惠劵张数
  9. shareFlag : 1
  10. },
  11. onLoad:function(options){
  12. var that = this;
  13. var shareFlag = options.shareFlag;
  14. if (shareFlag != '' && shareFlag != null && shareFlag != undefined) {
  15. that.setData({
  16. shareFlag: shareFlag
  17. })
  18. }
  19. },
  20. //获取优惠劵
  21. getCoupon:function(e){
  22. var that = this;
  23. var host = getApp().globalData.servsers;
  24. var un_id = getApp().globalData.un_id;
  25. //优惠劵共有30张
  26. wx.login({
  27. success: function (res) {
  28. var code = res.code;
  29. wx.getUserInfo({
  30. withCredentials: true,
  31. success: function (res) {
  32. wx.request({
  33. url: host + "userapi/insertadd",
  34. data: {
  35. user_id: code,
  36. name: res.userInfo.nickName,
  37. icon: res.userInfo.avatarUrl,
  38. iv: res.iv,
  39. encryptedData: res.encryptedData,
  40. },
  41. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  42. header: {
  43. 'Accept': 'application/json'
  44. },
  45. success: function (res) {
  46. that.setData({
  47. un_id: res.data.unionId
  48. })
  49. var un_id = res.data.unionId;
  50. console.log(un_id);
  51. if (un_id != undefined && un_id != '' && un_id != null) {
  52. //判断是否还有剩余优惠劵
  53. wx.request({
  54. url: host + "mycouponapi/insertaddno3",//有总张数限制,且每人限领一张
  55. data: {
  56. user_id: un_id,
  57. coupon_id: '7',
  58. batch_no: '3'
  59. },
  60. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  61. header: {
  62. 'Accept': 'application/json'
  63. },
  64. success: function (res) {
  65. if (res.data.result == 0) {//优惠劵有剩余 0:领取成功 1:领取过了 2:优惠卷已抢空!
  66. //领取成功
  67. that.setData({
  68. hiddenmodal: false,
  69. modalCont: '领取成功'
  70. })
  71. setTimeout(function () {
  72. that.setData({
  73. hiddenmodal: true
  74. })
  75. }, 1000)
  76. } else if (res.data.result == 1) {
  77. //已领取过优惠劵
  78. that.setData({
  79. hiddenmodal: false,
  80. modalCont: '您已领取过此优惠劵'
  81. })
  82. setTimeout(function () {
  83. that.setData({
  84. hiddenmodal: true
  85. })
  86. }, 1000)
  87. } else {
  88. //优惠劵张数已用尽 提示
  89. that.setData({
  90. hiddenmodal: false,
  91. modalCont: '优惠劵已被抢空'
  92. })
  93. setTimeout(function () {
  94. that.setData({
  95. hiddenmodal: true
  96. })
  97. wx.redirectTo({
  98. url: '/pages/girlsDay/girlsDay'
  99. })
  100. }, 1000)
  101. }
  102. }
  103. })
  104. }
  105. //判断结束
  106. if (res == null || res.data == null) {
  107. console.error('网络请求失败');
  108. return;
  109. }
  110. }
  111. })
  112. }
  113. })
  114. }
  115. })
  116. },
  117. onShareAppMessage: function (res) {//页面分享
  118. var that = this;
  119. var host = getApp().globalData.servsers;
  120. if (res.from === 'button') {
  121. // 来自页面内转发按钮
  122. console.log(res.target)
  123. }
  124. return {
  125. title: '大良造-送您一张无门槛优惠劵!',
  126. path: '/pages/indepCoupon3/indepCoupon3?shareFlag=1',
  127. success: function (res) {
  128. that.setData({
  129. hiddenmodal: false,
  130. modalCont: '分享成功'
  131. })
  132. setTimeout(function () {
  133. that.setData({
  134. hiddenmodal: true
  135. })
  136. wx.redirectTo({
  137. url: '/pages/girlsDay/girlsDay'
  138. })
  139. }, 1000)
  140. },
  141. fail: function (res) {
  142. // 转发失败
  143. }
  144. }
  145. },
  146. //返回首页
  147. backIndex: function (e) {
  148. wx.switchTab({
  149. url: '/pages/index/index',
  150. })
  151. }
  152. })
  153. var that;
  154. var imageUtil = require('../../utils/util.js');