index.js 7.0 KB

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