index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var timeout2, timeout3;
  5. Page({
  6. data: {
  7. version: app.globalData.Version,
  8. },
  9. onLoad: function (options) {
  10. if (options) {
  11. if (options.UserID) {
  12. console.log("UserID:" + options.UserID);
  13. app.globalData.introducer = options.UserID;
  14. }
  15. if (options.SourceID) {
  16. console.log("SourceID:" + options.SourceID);
  17. app.globalData.SourceID = options.SourceID;
  18. }
  19. // 扫码介绍人
  20. if (options.scene) {
  21. var scene = decodeURIComponent(options.scene);
  22. console.log("scene:" + scene);
  23. var introducer = 0;
  24. if (scene.indexOf("UserID") >= 0)
  25. introducer = scene.substr(scene.indexOf("UserID") + 7);
  26. console.log("introducer:" + introducer);
  27. app.globalData.introducer = scene;
  28. }
  29. if (options.ProductID) {
  30. this.setData({
  31. ProductID: options.ProductID,
  32. ProductUserID: options.ProductUserID,
  33. });
  34. }
  35. if (options.GiftID) {
  36. this.setData({
  37. GiftID: options.GiftID,
  38. });
  39. }
  40. }
  41. this.setData({
  42. Containnerheight: server.getWindowHeight(),
  43. });
  44. this.getUserInfo();
  45. this.updateProgram();
  46. },
  47. //得到用户信息
  48. getUserInfo: function (cb) {
  49. var that = this
  50. //调用登录接口
  51. wx.login({
  52. success: function (res0) {
  53. app.globalData.userInfo = {};
  54. app.globalData.userInfo.Code = res0.code;
  55. //console.log("Code:" + res0.code);app.globalData.userInfo.nickName = "陌生用户";
  56. that.login(app.globalData.userInfo);
  57. },
  58. fail: function () {
  59. setTimeout(function () {
  60. that.getUserInfo();
  61. console.log("reboot:" + new Date().getTime());
  62. }, 2000);
  63. }
  64. });
  65. },
  66. login: function (param) {
  67. var that = this;
  68. server.getLocalHost(function () {
  69. server.postData('MathLogin', {
  70. Code: param.Code,
  71. Introducer: app.globalData.introducer,
  72. UserSource: app.globalData.userSource,
  73. SourceID: app.globalData.SourceID,
  74. LastUserSource: app.globalData.userSource,
  75. Brand: app.globalData.systemInfo.brand,
  76. Model: app.globalData.systemInfo.model,
  77. PixelRatio: app.globalData.systemInfo.pixelRatio,
  78. ScreenWidth: app.globalData.systemInfo.screenWidth,
  79. ScreenHeight: app.globalData.systemInfo.screenHeight,
  80. WindowWidth: app.globalData.systemInfo.windowWidth,
  81. WindowHeight: app.globalData.systemInfo.windowHeight,
  82. WXLanguage: app.globalData.systemInfo.language,
  83. WXVersion: app.globalData.systemInfo.version,
  84. System: app.globalData.systemInfo.system,
  85. Platform: app.globalData.systemInfo.platform,
  86. SDKVersion: app.globalData.systemInfo.SDKVersion,
  87. ProgramVersion: app.globalData.Version,
  88. }, function (data) {
  89. //console.log("UserInfo:" + data);
  90. if (!data) {
  91. timeout3 = setTimeout(function () {
  92. that.getUserInfo();
  93. console.log("reboot:" + new Date().getTime());
  94. }, 2000);
  95. } else {
  96. app.globalData.userInfo = data;
  97. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  98. // var isShow = data.IsShow;
  99. // if (isShow == -1) {
  100. // isShow = 0;
  101. // }
  102. // else {
  103. // var systemInfo = wx.getSystemInfoSync();
  104. // if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  105. // isShow = 1;
  106. // }
  107. // }
  108. // app.globalData.userInfo.IsShow = isShow;
  109. app.globalData.userInfo.IsShow = data.IsShow;
  110. //app.globalData.IsLocked = data.IsLocked;
  111. app.globalData.IsLocked = 0;
  112. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  113. that.getQuestionType(function () {
  114. if (that.data.GiftID) {
  115. var url = "../../package4/main/giftcard?GiftID=" + that.data.GiftID + "&UserID=" + app.globalData.introducer
  116. wx.redirectTo({
  117. url: url
  118. });
  119. }
  120. else if (that.data.ProductID) {
  121. var url = "../../package4/main/activateOK?ProductID=" + that.data.ProductID
  122. + "&ProductUserID=" + that.data.ProductUserID
  123. + "&CurrentUserID=" + app.globalData.userInfo.UserID
  124. + "&CurrentProductID=" + app.globalData.ProgramID;
  125. wx.redirectTo({
  126. url: url
  127. });
  128. }
  129. else {
  130. setTimeout(function () {
  131. common.getStorageValue(that, "IsStart", false, function () {
  132. if (that.data.IsStart) {
  133. wx.redirectTo({
  134. url: '../main/default'
  135. })
  136. }
  137. else {
  138. wx.redirectTo({
  139. url: '../main/help'
  140. })
  141. }
  142. });
  143. }, 2000);
  144. }
  145. that.getPriceList();
  146. wx.setStorageSync("IsShare", 0);
  147. });
  148. }
  149. });
  150. });
  151. },
  152. getQuestionType: function (callback) {
  153. var that = this;
  154. server.getData('GetQuestionTypes?Mode=2', function (data) {
  155. if (data) {
  156. //var arr = common.Decrypt(data);
  157. var arr = data;
  158. wx.setStorageSync("QuestionTypeList", arr);
  159. callback();
  160. }
  161. });
  162. //调用登录接口
  163. wx.login({
  164. success: function (res0) {
  165. server.getData('GetBaiduToken20220922?ProgramID='+app.globalData.ProgramID+'&Code='+res0.code, function (data) {
  166. if (data) {
  167. app.globalData.BaiduToken = data;
  168. }
  169. });
  170. }});
  171. },
  172. getPriceList: function () {
  173. var that = this;
  174. server.getData('ProductPayPriceList500', function (data) {
  175. if (data) {
  176. var arrProduct = JSON.parse(common.Decrypt(data));
  177. var programList = server.getProgramList();
  178. for (var j = 0; j < arrProduct.length; j++) {
  179. arrProduct[j].ProductList = [];
  180. var arr = arrProduct[j].ProductNum.split(",");
  181. for (var k = 0; k < arr.length; k++) {
  182. for (var i = 0; i < programList.length; i++) {
  183. if (programList[i].ID == arr[k]) {
  184. arrProduct[j].ProductList.push(programList[i]);
  185. }
  186. }
  187. }
  188. }
  189. wx.setStorageSync("ProductPrice", arrProduct);
  190. }
  191. });
  192. },
  193. updateProgram: function () {
  194. const updateManager = wx.getUpdateManager();
  195. updateManager.onCheckForUpdate(function (res) {
  196. // 请求完新版本信息的回调
  197. console.log(res.hasUpdate)
  198. });
  199. updateManager.onUpdateReady(function () {
  200. updateManager.applyUpdate();
  201. });
  202. },
  203. onShareAppMessage: function () {
  204. return {
  205. title: app.globalData.ShareTitle,
  206. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  207. imageUrl: app.globalData.ShareImage,
  208. }
  209. },
  210. })