index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  122. // var isShow = data.IsShow;
  123. // if (isShow == -1) {
  124. // isShow = 0;
  125. // }
  126. // else {
  127. // var systemInfo = wx.getSystemInfoSync();
  128. // if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  129. // isShow = 1;
  130. // }
  131. // }
  132. // app.globalData.userInfo.IsShow = isShow;
  133. app.globalData.userInfo.IsShow = data.IsShow;
  134. app.globalData.IsLocked = data.IsLocked;
  135. if (that.data.GiftID) {
  136. var url = "../../package4/main/giftcard?GiftID=" + that.data.GiftID + "&UserID=" + app.globalData.introducer
  137. wx.redirectTo({
  138. url: url
  139. });
  140. }
  141. else if (that.data.ProductID) {
  142. var url = "../../package4/main/activateOK?ProductID=" + that.data.ProductID
  143. + "&ProductUserID=" + that.data.ProductUserID
  144. + "&CurrentUserID=" + app.globalData.userInfo.UserID
  145. + "&CurrentProductID=" + app.globalData.ProgramID;
  146. wx.redirectTo({
  147. url: url
  148. });
  149. }
  150. else {
  151. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  152. that.getHanzi(function(){
  153. setTimeout(function () {
  154. wx.redirectTo({
  155. url: '../main/index'
  156. })
  157. }, 2000);
  158. });
  159. that.getPriceList();
  160. wx.setStorageSync("IsShare", 0);
  161. }
  162. }
  163. });
  164. });
  165. },
  166. getHanzi: function (callback) {
  167. var that = this;
  168. var time = wx.getStorageSync("HanziUpdateTime");
  169. server.getData('GetHanziAll0124?UpdateTime=' + time, function (data) {
  170. if (data) {
  171. if (data.List) {
  172. var arr = common.Decrypt(data.List);
  173. wx.setStorageSync("HanziAll", arr);
  174. wx.setStorageSync("HanziUpdateTime", data.UpdateTime);
  175. }
  176. app.globalData.BaiduToken = data.String;
  177. callback();
  178. }
  179. });
  180. },
  181. getPriceList: function () {
  182. var that = this;
  183. server.getData('ProductPayPriceList500', function (data) {
  184. if (data) {
  185. var arrProduct = JSON.parse(common.Decrypt(data));
  186. var programList = server.getProgramList();
  187. for (var j = 0; j < arrProduct.length; j++) {
  188. arrProduct[j].ProductList = [];
  189. var arr = arrProduct[j].ProductNum.split(",");
  190. for (var k = 0; k < arr.length; k++) {
  191. for (var i = 0; i < programList.length; i++) {
  192. if (programList[i].ID == arr[k]) {
  193. arrProduct[j].ProductList.push(programList[i]);
  194. }
  195. }
  196. }
  197. }
  198. wx.setStorageSync("ProductPrice", arrProduct);
  199. }
  200. });
  201. },
  202. updateProgram: function () {
  203. const updateManager = wx.getUpdateManager();
  204. updateManager.onCheckForUpdate(function (res) {
  205. // 请求完新版本信息的回调
  206. console.log(res.hasUpdate)
  207. });
  208. updateManager.onUpdateReady(function () {
  209. updateManager.applyUpdate();
  210. });
  211. },
  212. onShareAppMessage: function () {
  213. return {
  214. title: app.globalData.ShareTitle,
  215. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  216. imageUrl: app.globalData.ShareImage,
  217. }
  218. },
  219. })