indepCoupon.js 4.4 KB

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