giftcard.js 5.3 KB

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