index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. }
  36. this.setData({
  37. Containnerheight: server.getWindowHeight(),
  38. });
  39. this.getUserInfo();
  40. this.updateProgram();
  41. },
  42. //得到用户信息
  43. getUserInfo: function (cb) {
  44. var that = this
  45. //调用登录接口
  46. wx.login({
  47. success: function (res0) {
  48. app.globalData.userInfo = {};
  49. app.globalData.userInfo.Code = res0.code;
  50. //console.log("Code:" + res0.code);
  51. wx.getSetting({
  52. scope: "scope.userInfo",
  53. success(res) {
  54. if (!res.authSetting['scope.userInfo']) {
  55. app.globalData.userInfo.nickName = "陌生用户";
  56. app.globalData.userInfo.language = "";
  57. app.globalData.userInfo.gender = "0";
  58. app.globalData.userInfo.city = "";
  59. app.globalData.userInfo.province = "";
  60. app.globalData.userInfo.country = "";
  61. app.globalData.userInfo.avatarUrl = "";
  62. that.login(app.globalData.userInfo);
  63. } else {
  64. wx.getUserInfo({
  65. withCredentials: false,
  66. success: function (res) {
  67. app.globalData.userInfo = res.userInfo;
  68. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  69. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  70. app.globalData.userInfo.Code = res0.code;
  71. that.login(app.globalData.userInfo);
  72. },
  73. fail: function (res) {
  74. that.login(app.globalData.userInfo);
  75. }
  76. });
  77. }
  78. }
  79. });
  80. },
  81. fail: function () {
  82. timeout2 = setTimeout(function () {
  83. that.getUserInfo();
  84. console.log("reboot:" + new Date().getTime());
  85. }, 2000);
  86. }
  87. });
  88. },
  89. login: function (param) {
  90. var that = this;
  91. server.getLocalHost(function () {
  92. server.postData('MathLogin', {
  93. Code: param.Code,
  94. NickName: param.nickName,
  95. Language: param.language,
  96. Gender: param.gender,
  97. City: param.city,
  98. Province: param.province,
  99. Country: param.country,
  100. AvatarUrl: param.avatarUrl,
  101. Introducer: app.globalData.introducer,
  102. UserSource: app.globalData.userSource,
  103. SourceID: app.globalData.SourceID,
  104. LastUserSource: app.globalData.userSource,
  105. Brand: app.globalData.systemInfo.brand,
  106. Model: app.globalData.systemInfo.model,
  107. PixelRatio: app.globalData.systemInfo.pixelRatio,
  108. ScreenWidth: app.globalData.systemInfo.screenWidth,
  109. ScreenHeight: app.globalData.systemInfo.screenHeight,
  110. WindowWidth: app.globalData.systemInfo.windowWidth,
  111. WindowHeight: app.globalData.systemInfo.windowHeight,
  112. WXLanguage: app.globalData.systemInfo.language,
  113. WXVersion: app.globalData.systemInfo.version,
  114. System: app.globalData.systemInfo.system,
  115. Platform: app.globalData.systemInfo.platform,
  116. SDKVersion: app.globalData.systemInfo.SDKVersion,
  117. ProgramVersion: app.globalData.version,
  118. }, function (data) {
  119. //console.log("UserInfo:" + data);
  120. if (!data) {
  121. timeout3 = setTimeout(function () {
  122. that.getUserInfo();
  123. console.log("reboot:" + new Date().getTime());
  124. }, 2000);
  125. } else {
  126. app.globalData.userInfo = data;
  127. var isShow = data.IsShow;
  128. if (isShow == -1) {
  129. isShow = 0;
  130. }
  131. else {
  132. var systemInfo = wx.getSystemInfoSync();
  133. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  134. isShow = 1;
  135. }
  136. }
  137. if (data.DayNumber>=5){
  138. app.globalData.IsLocked =true;
  139. }
  140. console.log(data.DayNumber);
  141. app.globalData.IsShow = isShow;
  142. //app.globalData.userInfo.AvatarUrl = param.avatarUrl;
  143. that.getQuestionType(function () {
  144. setTimeout(function () {
  145. common.getStorageValue(that, "IsStart", false, function () {
  146. if (that.data.IsStart) {
  147. wx.redirectTo({
  148. url: '../main/default'
  149. })
  150. }
  151. else {
  152. wx.redirectTo({
  153. url: '../main/help'
  154. })
  155. }
  156. });
  157. }, 2000);
  158. that.getPriceList();
  159. });
  160. }
  161. });
  162. });
  163. },
  164. getQuestionType: function (callback) {
  165. var that = this;
  166. server.getData('GetQuestionTypes?Mode=2', function (data) {
  167. if (data) {
  168. //var arr = common.Decrypt(data);
  169. var arr = data;
  170. wx.setStorageSync("QuestionTypeList", arr);
  171. callback();
  172. }
  173. });
  174. server.getData('GetBaiduToken', function (data) {
  175. if (data) {
  176. app.globalData.BaiduToken = data;
  177. }
  178. });
  179. },
  180. getPriceList: function () {
  181. var that = this;
  182. if (!wx.getStorageSync("ProductPrice")) {
  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. },
  203. updateProgram: function () {
  204. const updateManager = wx.getUpdateManager();
  205. updateManager.onCheckForUpdate(function (res) {
  206. // 请求完新版本信息的回调
  207. console.log(res.hasUpdate)
  208. });
  209. updateManager.onUpdateReady(function () {
  210. wx.showModal({
  211. title: '更新提示',
  212. content: '新版本已经准备好,是否重启应用?',
  213. success: function (res) {
  214. if (res.confirm) {
  215. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  216. updateManager.applyUpdate()
  217. }
  218. }
  219. });
  220. });
  221. },
  222. onShareAppMessage: function () {
  223. return {
  224. title: app.globalData.ShareTitle,
  225. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  226. imageUrl: app.globalData.ShareImageUrl,
  227. }
  228. },
  229. })