giftcard.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var giftID=0;
  5. Page({
  6. data: {
  7. },
  8. onLoad: function (options) {
  9. giftID = options.GiftID;
  10. var userID = options.UserID;
  11. this.setData({
  12. Containnerheight: common.getSystemHeight(),
  13. ProgramList: server.getProgramList(),
  14. });
  15. this.init(giftID,userID);
  16. },
  17. init: function (id,userID) {
  18. var that = this;
  19. server.getData('GetGiftInfoByUserID500?ID=' + id + "&ProductID=" + app.globalData.ProgramID+"&UserID="+userID, function (data) {
  20. if (data) {
  21. var price = data.PriceTotal;
  22. var numberWidth = 240;
  23. var fontsize = 100;
  24. if (price.toString().length == 2) {
  25. numberWidth = 180;
  26. }
  27. else if (price.toString().length == 3) {
  28. numberWidth = 220;
  29. }
  30. else if (price.toString().length == 4) {
  31. numberWidth = 220;
  32. }
  33. else if (price.toString().length == 5) {
  34. numberWidth = 240;
  35. fontsize = 85;
  36. }
  37. that.setData({
  38. NumberWidth: numberWidth,
  39. GiftInfo: data,
  40. FontSize:fontsize,
  41. });
  42. }
  43. });
  44. },
  45. gotoFeedback: function () {
  46. server.gotoFeedback();
  47. },
  48. goto: function (e) {
  49. var that = this;
  50. wx.getSetting({
  51. success(res) {
  52. if (!res.authSetting['scope.userInfo']) {
  53. wx.authorize({
  54. scope: 'scope.userInfo',
  55. success() {
  56. that.getUserInfo();
  57. },
  58. fail() {
  59. wx.openSetting({
  60. success(res) {
  61. that.getUserInfo();
  62. },
  63. });
  64. }
  65. })
  66. } else {
  67. that.getUserInfo();
  68. }
  69. }
  70. });
  71. },
  72. //得到用户信息
  73. getUserInfo: function () {
  74. var that = this
  75. //调用登录接口
  76. wx.login({
  77. success: function (res0) {
  78. wx.getUserInfo({
  79. withCredentials: true,
  80. success: function (res) {
  81. app.globalData.userInfo = res.userInfo;
  82. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  83. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  84. that.setData({
  85. IsAccredit: true,
  86. NickName: app.globalData.userInfo.NickName,
  87. AvatarUrl: app.globalData.userInfo.AvatarUrl
  88. });
  89. app.globalData.userInfo.Code = res0.code;
  90. app.globalData.userInfo.iv = res.iv;
  91. app.globalData.userInfo.encryptedData = res.encryptedData;
  92. that.login(app.globalData.userInfo);
  93. },
  94. fail: function (res) {
  95. wx.reLaunch({
  96. url: '../index/index'
  97. });
  98. }
  99. });
  100. },
  101. fail: function () {
  102. wx.reLaunch({
  103. url: '../index/index'
  104. });
  105. }
  106. });
  107. },
  108. login: function (param) {
  109. var that = this;
  110. var url="Login";
  111. switch(app.globalData.ProgramID){
  112. case 164:
  113. url = "MathStar" + url;
  114. break;
  115. case 105:
  116. url = "Math" + url;
  117. break;
  118. case 106:
  119. url = "Hanzi" + url;
  120. break;
  121. case 98:
  122. url = "Pinyin" + url;
  123. break;
  124. case 99:
  125. url = "Phonics" + url;
  126. break;
  127. }
  128. server.postData(url, {
  129. Code: param.Code,
  130. NickName: param.nickName,
  131. Language: param.language,
  132. Gender: param.gender,
  133. City: param.city,
  134. Province: param.province,
  135. Country: param.country,
  136. AvatarUrl: param.avatarUrl,
  137. ProgramVersion: app.globalData.Version,
  138. Introducer: app.globalData.introducer,
  139. UserSource: app.globalData.userSource,
  140. SourceID: app.globalData.SourceID,
  141. LastUserSource: app.globalData.userSource,
  142. iv: param.iv,
  143. encryptedData: param.encryptedData,
  144. }, function (data) {
  145. app.globalData.userInfo.UserID = data.UserID;
  146. wx.showLoading({
  147. title: '兑换中...',
  148. });
  149. server.getData('SetUserGiftExchange500?UserID=' + app.globalData.userInfo.UserID + "&ProductPayInfoID=" + giftID, function (data2) {
  150. wx.hideLoading();
  151. if (data2) {
  152. app.globalData.userInfo.IsMember = 1;
  153. app.globalData.IsMemberForeverRemind = 1;
  154. if (that.data.GiftInfo.GiftNumber>1)
  155. wx.setStorageSync("HasActivate", 1);
  156. wx.reLaunch({
  157. url: '../../pages/index/index'
  158. });
  159. }
  160. else {
  161. var title = "无效";
  162. var content = "兑换卡已被领取,请联系赠送者了解原因!";
  163. wx.showModal({
  164. showCancel: false,
  165. title: title,
  166. content: content,
  167. confirmText: "返回首页",
  168. success: function () {
  169. wx.reLaunch({
  170. url: '../../pages/index/index'
  171. });
  172. }
  173. });
  174. }
  175. });
  176. });
  177. },
  178. gotoDefault:function(){
  179. wx.reLaunch({
  180. url: '../../pages/index/index'
  181. });
  182. },
  183. onShareAppMessage: function () {
  184. return {
  185. title: app.globalData.ShareTitle,
  186. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  187. imageUrl: app.globalData.ShareImage,
  188. }
  189. },
  190. })