index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function (options) {
  8. wx.hideShareMenu();
  9. if (options) {
  10. if (options.UserID) {
  11. console.log("UserID:" + options.UserID);
  12. app.globalData.introducer = options.UserID;
  13. if (options.QuestionTypeID)
  14. questionTypeID = options.QuestionTypeID;
  15. }
  16. if (options.goto) {
  17. console.log("goto:" + options.goto);
  18. app.globalData.goto = options.goto;
  19. }
  20. if (options.SourceID) {
  21. console.log("SourceID:" + options.SourceID);
  22. app.globalData.SourceID = options.SourceID;
  23. }
  24. // 扫码介绍人
  25. if (options.scene) {
  26. var scene = decodeURIComponent(options.scene);
  27. console.log("scene:" + scene);
  28. var introducer = 0;
  29. if (scene.indexOf("UserID") >= 0)
  30. introducer = scene.substr(scene.indexOf("UserID") + 7);
  31. console.log("introducer:" + introducer);
  32. app.globalData.introducer = scene;
  33. }
  34. if (options.ProductID) {
  35. this.setData({
  36. ProductID: options.ProductID,
  37. ProductUserID: options.ProductUserID,
  38. });
  39. }
  40. if (options.GiftID) {
  41. this.setData({
  42. GiftID: options.GiftID,
  43. });
  44. }
  45. if (options.Share==1) {
  46. this.setData({
  47. MiaoguoCardID: options.MiaoguoCardID,
  48. });
  49. }
  50. }
  51. this.setData({
  52. Containnerheight: main.getWindowHeight(),
  53. });
  54. this.updateProgram();
  55. this.getUserInfo();
  56. },
  57. //得到用户信息
  58. getUserInfo: function (cb) {
  59. var that = this
  60. //调用登录接口
  61. wx.login({
  62. success: function (res0) {
  63. app.globalData.userInfo = {};
  64. app.globalData.userInfo.Code = res0.code;
  65. //console.log("Code:" + res0.code);
  66. wx.getSetting({
  67. scope: "scope.userInfo",
  68. success(res) {
  69. if (!res.authSetting['scope.userInfo']) {
  70. app.globalData.userInfo.nickName = "陌生用户";
  71. app.globalData.userInfo.language = "";
  72. app.globalData.userInfo.gender = "0";
  73. app.globalData.userInfo.city = "";
  74. app.globalData.userInfo.province = "";
  75. app.globalData.userInfo.country = "";
  76. app.globalData.userInfo.avatarUrl = "../images/universalpic_face_default_blue_120x120.png";
  77. that.login(app.globalData.userInfo);
  78. }
  79. else {
  80. wx.getUserInfo({
  81. withCredentials: false,
  82. success: function (res) {
  83. app.globalData.userInfo = res.userInfo;
  84. app.globalData.userInfo.NickName = app.globalData.userInfo.nickName;
  85. app.globalData.userInfo.AvatarUrl = app.globalData.userInfo.avatarUrl;
  86. app.globalData.userInfo.Code = res0.code;
  87. that.login(app.globalData.userInfo);
  88. },
  89. fail: function (res) {
  90. that.login(app.globalData.userInfo);
  91. }
  92. });
  93. }
  94. }
  95. });
  96. },
  97. fail: function () {
  98. }
  99. });
  100. },
  101. login: function (param) {
  102. var that = this;
  103. main.getLocalHost(function () {
  104. main.postData('MiaoguoLogin', {
  105. Code: param.Code,
  106. NickName: param.nickName,
  107. Language: param.language,
  108. Gender: param.gender,
  109. City: param.city,
  110. Province: param.province,
  111. Country: param.country,
  112. AvatarUrl: param.avatarUrl,
  113. Introducer: app.globalData.introducer,
  114. UserSource: app.globalData.userSource,
  115. SourceID: app.globalData.SourceID,
  116. LastUserSource: app.globalData.userSource,
  117. Brand: app.globalData.systemInfo.brand,
  118. Model: app.globalData.systemInfo.model,
  119. PixelRatio: app.globalData.systemInfo.pixelRatio,
  120. ScreenWidth: app.globalData.systemInfo.screenWidth,
  121. ScreenHeight: app.globalData.systemInfo.screenHeight,
  122. WindowWidth: app.globalData.systemInfo.windowWidth,
  123. WindowHeight: app.globalData.systemInfo.windowHeight,
  124. WXLanguage: app.globalData.systemInfo.language,
  125. WXVersion: app.globalData.systemInfo.version,
  126. System: app.globalData.systemInfo.system,
  127. Platform: app.globalData.systemInfo.platform,
  128. SDKVersion: app.globalData.systemInfo.SDKVersion,
  129. ProgramVersion: app.globalData.Version,
  130. }, function (data) {
  131. if (!data) {
  132. timeout3 = setTimeout(function () {
  133. that.getUserInfo();
  134. console.log("reboot:" + new Date().getTime());
  135. }, 2000);
  136. }
  137. else {
  138. app.globalData.userInfo = data;
  139. var isShow = data.IsShow;
  140. if (isShow == -1) {
  141. isShow = 0;
  142. }
  143. else {
  144. var systemInfo = wx.getSystemInfoSync();
  145. if (isShow == 0 && systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  146. isShow = 1;
  147. }
  148. }
  149. app.globalData.IsShow = isShow;
  150. if (app.globalData.userInfo.IsMember == 1)
  151. app.globalData.IsLocked = 0;
  152. wx.removeStorageSync("UserID");
  153. wx.removeStorageSync("UserName");
  154. //测试
  155. //var url = '../../package4/main/giftcard?GiftID=89542&UserID=1';
  156. //var url = '../main/share';
  157. // var url = '../../package4/main/share';
  158. // wx.redirectTo({
  159. // url: url,
  160. // });
  161. var url = '../main/default?IsStart=1';
  162. if (that.data.MiaoguoCardID){
  163. url += "&Share=1&MiaoguoCardID=" + that.data.MiaoguoCardID;
  164. }
  165. setTimeout(function () {
  166. wx.redirectTo({
  167. url: url,
  168. });
  169. }, 2000);
  170. that.getBaiduToken();
  171. that.getTaskTodayList();
  172. }
  173. });
  174. });
  175. },
  176. getBaiduToken: function () {
  177. main.getData('GetBaiduToken', function (data) {
  178. if (data) {
  179. app.globalData.BaiduToken = data;
  180. //console.log(app.globalData.BaiduToken);
  181. }
  182. });
  183. },
  184. //得到当天任务
  185. getTaskTodayList: function () {
  186. var that = this;
  187. common.getStorageValue(that, "CardMaxNumberNew", 10, function () {
  188. common.getStorageValue(that, "CardMaxNumberHistory", 30, function () {
  189. common.getStorageValue(that, "SortTypeIndex", 0, function () {
  190. var url = 'GetMiaoguoCardToday?UserID=' + app.globalData.userInfo.UserID;
  191. url += "&New=" + that.data.CardMaxNumberNew;
  192. url += "&History=" + that.data.CardMaxNumberHistory;
  193. url += "&SortTypeIndex=" + that.data.SortTypeIndex;
  194. main.getData(url, function (data) {
  195. if (data) {
  196. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  197. that.setData({
  198. List: data,
  199. DayNumber: data.DayNumber,
  200. TodayTaskNumber: TodayTaskNumber,
  201. IsStart: data.IsStart,
  202. });
  203. wx.setStorageSync("TaskToday", data);
  204. }
  205. });
  206. });
  207. });
  208. });
  209. },
  210. updateProgram: function () {
  211. const updateManager = wx.getUpdateManager();
  212. updateManager.onCheckForUpdate(function (res) {
  213. // 请求完新版本信息的回调
  214. //console.log(res.hasUpdate)
  215. });
  216. updateManager.onUpdateReady(function () {
  217. wx.showModal({
  218. title: '更新提示',
  219. content: '新版本已经准备好,是否重启应用?',
  220. success: function (res) {
  221. if (res.confirm) {
  222. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  223. updateManager.applyUpdate()
  224. }
  225. }
  226. });
  227. });
  228. },
  229. onShareAppMessage: function () {
  230. return {
  231. title: app.globalData.ShareTitle,
  232. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  233. imageUrl: app.globalData.ShareImage,
  234. }
  235. },
  236. })