default.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. ImagePath: app.globalData.uploadImageUrl,
  15. IsShowUserID: false,
  16. },
  17. onPullDownRefresh: function () {
  18. wx.redirectTo({
  19. url: '../main/default',
  20. })
  21. wx.stopPullDownRefresh();
  22. },
  23. onLoad: function (options) {
  24. var that = this;
  25. that.setData({
  26. Containnerheight: main.getWindowHeight(),
  27. });
  28. if (app.globalData.IsIPad) {
  29. that.setData({
  30. IsIPad: "_iPad",
  31. });
  32. if (app.globalData.systemInfo.windowHeight < app.globalData.systemInfo.windowWidth) {
  33. that.setData({
  34. IsExit: true,
  35. });
  36. }
  37. }
  38. },
  39. onHide: function () {
  40. wx.hideLoading();
  41. },
  42. onShow: function () {
  43. var that = this;
  44. if (app.globalData.userInfo.IsNewUser && app.globalData.userInfo.IsNewUser == 1 && app.globalData.userInfo.IsShow == 1) {
  45. if (app.globalData.userInfo.Subscribe == 0) {
  46. wx.redirectTo({
  47. url: '../other/newuser',
  48. });
  49. }
  50. }
  51. else {
  52. wx.getSetting({
  53. success(res) {
  54. if (res.authSetting['scope.userInfo'] || app.globalData.userInfo.IsShow == 0) {
  55. if (!app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  56. if (app.globalData.userInfo.Subscribe == 1) {
  57. wx.navigateTo({
  58. url: '../other/userbook',
  59. });
  60. app.globalData.GotoUrl = "";
  61. }
  62. else {
  63. wx.redirectTo({
  64. url: '../other/newuser',
  65. });
  66. }
  67. }
  68. else if (app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  69. if (app.globalData.GotoUrl.indexOf("../other/pay?PayType=6") >= 0) {
  70. wx.navigateTo({
  71. url: app.globalData.GotoUrl,
  72. });
  73. app.globalData.GotoUrl = "";
  74. }
  75. else {
  76. var productServiceTime = common.formatDateCHS(common.formatTime(new Date(app.globalData.userInfo.ProductServiceTime)));
  77. var today = common.formatDateCHS(common.formatTime(new Date()));
  78. if (productServiceTime < today) {
  79. wx.redirectTo({
  80. url: '../other/userbook',
  81. });
  82. }
  83. else if (app.globalData.userInfo.ClassDayNumber < 0) {
  84. wx.redirectTo({
  85. url: '../other/userbook',
  86. });
  87. }
  88. else if (app.globalData.GotoUrl) {
  89. //console.log(app.globalData.GotoUrl);
  90. wx.navigateTo({
  91. url: app.globalData.GotoUrl,
  92. });
  93. app.globalData.GotoUrl = "";
  94. }
  95. }
  96. }
  97. else if (app.globalData.userInfo.IsShow == 0) {
  98. main.buildInitData(function () { });
  99. }
  100. that.setData({
  101. IsAccredit: true,
  102. });
  103. //判断是否出现推广广告
  104. common.getStorageValue(that, "IsShowMarketing", app.globalData.userInfo.HasIntroducer, function () {
  105. if (app.globalData.userInfo.HasIntroducer == 0 && that.data.IsShowMarketing == 3) {
  106. var isShowMarketingTime = wx.getStorageSync("IsShowMarketingTime");
  107. if (common.formatTime(new Date()) >= isShowMarketingTime) {
  108. wx.removeStorageSync("IsShowMarketing");
  109. wx.removeStorageSync("IsShowMarketingTime");
  110. that.setData({
  111. IsShowMarketing: 0,
  112. });
  113. }
  114. }
  115. });
  116. that.init();
  117. that.getTaskTodayList();
  118. that.isNoSavedCard();
  119. }
  120. else {
  121. wx.navigateTo({
  122. url: '../index/accredit',
  123. });
  124. }
  125. if (res.authSetting['scope.record'] === true) {
  126. app.globalData.IsRecorderAccredit = 1;
  127. }
  128. else if (res.authSetting['scope.record'] === false) {
  129. app.globalData.IsRecorderAccredit = -1;
  130. }
  131. }
  132. });
  133. }
  134. wx.setNavigationBarColor({
  135. frontColor: "#ffffff",
  136. backgroundColor: "#3157BA",
  137. });
  138. },
  139. init: function () {
  140. //显示学习方案
  141. var cardType = wx.getStorageSync("CardType");
  142. if (!cardType)
  143. cardType = 0;
  144. this.setData({
  145. CardType: cardType,
  146. });
  147. //题卡主题色
  148. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  149. if (!arrColorIndex) {
  150. app.globalData.ColorIndex = common.random(1, 4);
  151. }
  152. else {
  153. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  154. }
  155. //显示答案操作方式
  156. var clickType = wx.getStorageSync("ClickType");
  157. if (!clickType)
  158. clickType = 0;
  159. app.globalData.ClickType = clickType;
  160. //选择建议
  161. var SecondConfigArray = wx.getStorageSync("SecondConfigArray");
  162. if (SecondConfigArray)
  163. app.globalData.SecondConfigArray = SecondConfigArray;
  164. //显示命名方式
  165. var MemoryLevel = wx.getStorageSync("MemoryLevel");
  166. if (!MemoryLevel)
  167. MemoryLevel = 0;
  168. app.globalData.MemoryLevel = MemoryLevel;
  169. },
  170. goto: function (e) {
  171. var url = e.currentTarget.dataset.url;
  172. wx.navigateTo({
  173. url: url,
  174. });
  175. if (url == "../marketing/index") {
  176. this.setData({
  177. IsShowMarketing: 2,
  178. });
  179. wx.setStorageSync("IsShowMarketing", 2);
  180. }
  181. },
  182. //得到当天任务
  183. getTaskTodayList: function () {
  184. var that = this;
  185. main.UpdateMiaoguoCardTodayAll(true, function () {
  186. main.getTaskTodayList(function (data) {
  187. if (data.IsMaintain == 1) {
  188. that.setData({
  189. IsMaintain: 1,
  190. });
  191. }
  192. else {
  193. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  194. that.setData({
  195. DayNumber: data.DayNumber,
  196. TodayTaskNumber: TodayTaskNumber,
  197. IsStart: data.IsStart,
  198. });
  199. if(app.globalData.MemoryLevel==0 && data.DayNumber>=8){
  200. var IsShowPatternMenu = wx.getStorageSync("IsShowPatternMenu");
  201. if (!IsShowPatternMenu){
  202. wx.navigateTo({
  203. url: '../other/menu?Type=1',
  204. });
  205. wx.setStorageSync('IsShowPatternMenu', 1);
  206. }
  207. }
  208. }
  209. });
  210. });
  211. },
  212. isNoSavedCard: function () {
  213. var that = this;
  214. //判断是否有未保存的卡
  215. if (app.globalData.userInfo.IsMaintain == 1) {
  216. that.setData({
  217. IsMaintain: app.globalData.userInfo.IsMaintain,
  218. });
  219. wx.setNavigationBarColor({
  220. frontColor: "#ffffff",
  221. backgroundColor: "#0B8457",
  222. })
  223. }
  224. //判断是否有未保存的卡
  225. else if (wx.getStorageSync("TempCardNoSaved")) {
  226. that.setData({
  227. IsTempCardNoSaved: true,
  228. });
  229. wx.setNavigationBarColor({
  230. frontColor: "#ffffff",
  231. backgroundColor: "#0B8457",
  232. })
  233. }
  234. else {
  235. that.setData({
  236. IsTempCardNoSaved: false,
  237. });
  238. wx.setNavigationBarColor({
  239. frontColor: "#ffffff",
  240. backgroundColor: "#3157BA",
  241. });
  242. }
  243. },
  244. onOpenTempCard: function () {
  245. var card = wx.getStorageSync("TempCardNoSaved");
  246. app.globalData.CardList = [card];
  247. wx.navigateTo({
  248. url: './add?type=add2&id=' + card.MiaoguoCardID,
  249. });
  250. },
  251. onGiveupTempCard: function () {
  252. var that = this;
  253. wx.removeStorageSync("TempCardNoSaved");
  254. that.isNoSavedCard();
  255. },
  256. gotoSearchCard: function () {
  257. wx.reLaunch({
  258. url: './searchCard',
  259. });
  260. },
  261. closeMarketing: function () {
  262. this.setData({
  263. IsShowMarketing: 3,
  264. });
  265. wx.setStorageSync("IsShowMarketing", 3);
  266. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 7, new Date())));
  267. },
  268. showUserID:function(){
  269. var that = this;
  270. if (app.globalData.userInfo.UserID == 1
  271. || app.globalData.userInfo.UserID == 3
  272. || app.globalData.userInfo.UserID == 4) {
  273. var userid=2;
  274. if (app.globalData.userInfo.UserID>=3)
  275. userid = app.globalData.userInfo.UserID;
  276. that.setData({
  277. IsShowUserID: true,
  278. ChangeuUserID:userid,
  279. });
  280. }
  281. },
  282. onKeyInput: function (e) {
  283. var id = e.detail.value;
  284. var that = this;
  285. that.setData({
  286. ChangeuUserID: id,
  287. });
  288. },
  289. setSelectUser: function (e) {
  290. var that = this;
  291. if (app.globalData.userInfo.UserID == 1
  292. || app.globalData.userInfo.UserID == 2
  293. || app.globalData.userInfo.UserID == 3
  294. || app.globalData.userInfo.UserID == 4) {
  295. var userid = that.data.ChangeuUserID;
  296. wx.setStorageSync("UserID", userid);
  297. app.globalData.userInfo.UserID = userid;
  298. var url = "GetMiaoguoWXUserInfo?UserID=" + app.globalData.userInfo.UserID + "&FieldStr=NickName,ProductServiceTime,AvatarUrl";
  299. main.getData(url, function (data) {
  300. if (data) {
  301. wx.setNavigationBarTitle({
  302. title: data.NickName
  303. });
  304. main.getUserConfig();
  305. app.globalData.userInfo.ProductServiceTime=data.ProductServiceTime;
  306. if (app.globalData.userInfo.UserID!=2){
  307. app.globalData.userInfo.NickName=data.NickName;
  308. app.globalData.userInfo.AvatarUrl=data.AvatarUrl;
  309. }
  310. }
  311. });
  312. that.setData({
  313. IsShowUserID: false,
  314. });
  315. that.onShow();
  316. }
  317. },
  318. onShareAppMessage: function () {
  319. return {
  320. title: app.globalData.ShareTitle,
  321. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  322. imageUrl: app.globalData.ShareImage,
  323. }
  324. },
  325. })