default.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. IsTempCardNoSaved:false,
  7. IsExit:false,
  8. DayNumber: 0,
  9. TodayTaskNumber: 0,
  10. IsStart: 0,
  11. IsShowMarketing: 1,
  12. IsMaintain:0,
  13. IsIPhoneX: app.globalData.IsIPhoneX,
  14. },
  15. onPullDownRefresh: function () {
  16. wx.redirectTo({
  17. url: '../main/default',
  18. })
  19. wx.stopPullDownRefresh();
  20. },
  21. onLoad: function (options) {
  22. var that = this;
  23. that.setData({
  24. Containnerheight: main.getWindowHeight(),
  25. });
  26. if (app.globalData.IsIPad){
  27. that.setData({
  28. IsIPad: "_iPad",
  29. });
  30. if (app.globalData.systemInfo.windowHeight < app.globalData.systemInfo.windowWidth){
  31. that.setData({
  32. IsExit:true,
  33. });
  34. }
  35. }
  36. this.checkMemory();
  37. },
  38. onHide:function(){
  39. wx.hideLoading();
  40. },
  41. onShow: function () {
  42. var that = this;
  43. if (app.globalData.userInfo.IsNewUser==1 && app.globalData.userInfo.IsShow == 1) {
  44. if (app.globalData.userInfo.Subscribe == 0) {
  45. wx.redirectTo({
  46. url: '../other/newuser',
  47. });
  48. }
  49. }
  50. else {
  51. wx.getSetting({
  52. success(res) {
  53. if (res.authSetting['scope.userInfo'] || app.globalData.userInfo.IsShow == 0) {
  54. if (!app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  55. if (app.globalData.userInfo.Subscribe == 1) {
  56. wx.navigateTo({
  57. url: '../other/userbook',
  58. });
  59. app.globalData.GotoUrl = "";
  60. }
  61. else{
  62. wx.redirectTo({
  63. url: '../other/newuser',
  64. });
  65. }
  66. }
  67. else if (app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  68. var productServiceTime = common.formatDateCHS(common.formatTime(new Date(app.globalData.userInfo.ProductServiceTime)));
  69. var today = common.formatDateCHS(common.formatTime(new Date()));
  70. if (productServiceTime < today) {
  71. wx.redirectTo({
  72. url: '../other/userbook',
  73. });
  74. }
  75. else if (app.globalData.userInfo.ClassDayNumber < 0) {
  76. wx.redirectTo({
  77. url: '../other/userbook',
  78. });
  79. }
  80. else if (app.globalData.GotoUrl) {
  81. //console.log(app.globalData.GotoUrl);
  82. wx.navigateTo({
  83. url: app.globalData.GotoUrl,
  84. });
  85. app.globalData.GotoUrl = "";
  86. }
  87. }
  88. else if (app.globalData.userInfo.IsShow == 0) {
  89. main.buildInitData(function () { });
  90. }
  91. that.setData({
  92. IsAccredit: true,
  93. });
  94. common.getStorageValue(that, "UserName", "秒过", function () {
  95. wx.setNavigationBarTitle({
  96. title: that.data.UserName
  97. });
  98. });
  99. //判断是否出现推广广告
  100. common.getStorageValue(that, "IsShowMarketing", app.globalData.userInfo.HasIntroducer, function () {
  101. if (app.globalData.userInfo.HasIntroducer == 0 && that.data.IsShowMarketing == 3) {
  102. var isShowMarketingTime = wx.getStorageSync("IsShowMarketingTime");
  103. if (common.formatTime(new Date()) >= isShowMarketingTime) {
  104. wx.removeStorageSync("IsShowMarketing");
  105. wx.removeStorageSync("IsShowMarketingTime");
  106. that.setData({
  107. IsShowMarketing: 0,
  108. });
  109. }
  110. }
  111. });
  112. that.init();
  113. that.getTaskTodayList();
  114. that.isNoSavedCard();
  115. }
  116. else {
  117. wx.navigateTo({
  118. url: '../index/accredit',
  119. });
  120. }
  121. if (res.authSetting['scope.record'] === true) {
  122. app.globalData.IsRecorderAccredit = 1;
  123. }
  124. else if (res.authSetting['scope.record'] === false) {
  125. app.globalData.IsRecorderAccredit = -1;
  126. }
  127. }
  128. });
  129. }
  130. wx.setNavigationBarColor({
  131. frontColor: "#ffffff",
  132. backgroundColor: "#3157BA",
  133. });
  134. },
  135. init:function(){
  136. //题卡主题色
  137. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  138. if (!arrColorIndex) {
  139. app.globalData.ColorIndex = common.random(1,4);
  140. }
  141. else {
  142. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  143. }
  144. //显示答案操作方式
  145. var clickType = wx.getStorageSync("ClickType");
  146. if (!clickType)
  147. clickType = 0;
  148. app.globalData.ClickType=clickType;
  149. //显示命名方式
  150. var MemoryLevel = wx.getStorageSync("MemoryLevel");
  151. if (!MemoryLevel)
  152. MemoryLevel = 0;
  153. app.globalData.MemoryLevel = MemoryLevel;
  154. //选择建议
  155. var SecondConfigArray = wx.getStorageSync("SecondConfigArray");
  156. if (SecondConfigArray)
  157. app.globalData.SecondConfigArray = SecondConfigArray;
  158. },
  159. goto: function (e) {
  160. var url = e.currentTarget.dataset.url;
  161. wx.navigateTo({
  162. url: url,
  163. });
  164. if (url =="../marketing/index"){
  165. this.setData({
  166. IsShowMarketing: 2,
  167. });
  168. wx.setStorageSync("IsShowMarketing", 2);
  169. }
  170. },
  171. //得到当天任务
  172. getTaskTodayList: function () {
  173. var that=this;
  174. main.UpdateMiaoguoCardTodayAll(true, function () {
  175. main.getTaskTodayList(function (data) {
  176. if (data.IsMaintain==1){
  177. that.setData({
  178. IsMaintain:1,
  179. });
  180. }
  181. else{
  182. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  183. that.setData({
  184. DayNumber: data.DayNumber,
  185. TodayTaskNumber: TodayTaskNumber,
  186. IsStart: data.IsStart,
  187. });
  188. }
  189. });
  190. });
  191. },
  192. isNoSavedCard:function(){
  193. var that=this;
  194. //判断是否有未保存的卡
  195. if (app.globalData.userInfo.IsMaintain==1) {
  196. that.setData({
  197. IsMaintain: app.globalData.userInfo.IsMaintain,
  198. });
  199. wx.setNavigationBarColor({
  200. frontColor: "#ffffff",
  201. backgroundColor: "#0B8457",
  202. })
  203. }
  204. //判断是否有未保存的卡
  205. else if (wx.getStorageSync("TempCardNoSaved")) {
  206. that.setData({
  207. IsTempCardNoSaved: true,
  208. });
  209. wx.setNavigationBarColor({
  210. frontColor: "#ffffff",
  211. backgroundColor: "#0B8457",
  212. })
  213. }
  214. else{
  215. that.setData({
  216. IsTempCardNoSaved: false,
  217. });
  218. wx.setNavigationBarColor({
  219. frontColor: "#ffffff",
  220. backgroundColor: "#3157BA",
  221. });
  222. }
  223. },
  224. onOpenTempCard:function(){
  225. var card = wx.getStorageSync("TempCardNoSaved");
  226. app.globalData.CardList=[card];
  227. wx.navigateTo({
  228. url: './add?type=add2&id='+card.MiaoguoCardID,
  229. });
  230. },
  231. onGiveupTempCard:function(){
  232. var that=this;
  233. wx.removeStorageSync("TempCardNoSaved");
  234. that.isNoSavedCard();
  235. },
  236. gotoSearchCard:function(){
  237. wx.reLaunch({
  238. url: './searchCard',
  239. });
  240. },
  241. closeMarketing:function(){
  242. this.setData({
  243. IsShowMarketing:3,
  244. });
  245. wx.setStorageSync("IsShowMarketing", 3);
  246. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d",7,new Date())));
  247. },
  248. checkMemory: function () {
  249. wx.onMemoryWarning(function () {
  250. wx.showModal({
  251. title: '手机内存不足',
  252. content: '请先清理内存再用秒过。内存不足会导致小程序异常或被迫退出。',
  253. showCancel: false,
  254. confirmText: '知道了',
  255. success: function (res) {
  256. }
  257. });
  258. });
  259. },
  260. onShareAppMessage: function () {
  261. return {
  262. title: app.globalData.ShareTitle,
  263. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  264. imageUrl: app.globalData.ShareImage,
  265. }
  266. },
  267. })