default.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. IsMaintain: 0,
  12. IsIPhoneX: app.globalData.IsIPhoneX,
  13. ImagePath: app.globalData.uploadImageUrl,
  14. IsShowUserID: false,
  15. VersionID:app.globalData.Version,
  16. AwardDayNumber:0,
  17. IsShowRemind:false,
  18. },
  19. onPullDownRefresh: function () {
  20. wx.redirectTo({
  21. url: '../main/default',
  22. })
  23. wx.stopPullDownRefresh();
  24. },
  25. onLoad: function (options) {
  26. var that = this;
  27. that.setData({
  28. Containnerheight: main.getWindowHeight(),
  29. });
  30. if (app.globalData.IsIPad) {
  31. that.setData({
  32. IsIPad: "_iPad",
  33. });
  34. if (app.globalData.systemInfo.windowHeight < app.globalData.systemInfo.windowWidth) {
  35. that.setData({
  36. IsExit: true,
  37. });
  38. }
  39. }
  40. wx.showShareMenu({
  41. withShareTicket: true,
  42. menus: ['shareAppMessage', 'shareTimeline']
  43. })
  44. },
  45. onHide: function () {
  46. wx.hideLoading();
  47. },
  48. onShow: function () {
  49. var that = this;
  50. if (app.globalData.userInfo.IsNewUser && app.globalData.userInfo.IsNewUser == 1 && app.globalData.userInfo.IsShow == 1) {
  51. if (app.globalData.userInfo.Subscribe == 0) {
  52. wx.redirectTo({
  53. url: '../other/newuser',
  54. });
  55. }
  56. }
  57. else {
  58. wx.getSetting({
  59. success(res) {
  60. if (res.authSetting['scope.userInfo'] || app.globalData.userInfo.IsShow == 0) {
  61. if (!app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  62. if (app.globalData.userInfo.Subscribe == 1) {
  63. wx.navigateTo({
  64. url: '../other/userbook',
  65. });
  66. app.globalData.GotoUrl = "";
  67. }
  68. else {
  69. wx.redirectTo({
  70. url: '../other/newuser',
  71. });
  72. }
  73. }
  74. else if (app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  75. if (app.globalData.GotoUrl.indexOf("../other/pay?PayType=6") >= 0) {
  76. wx.navigateTo({
  77. url: app.globalData.GotoUrl,
  78. });
  79. app.globalData.GotoUrl = "";
  80. }
  81. else {
  82. var productServiceTime = common.formatDateCHS(common.formatTime(new Date(app.globalData.userInfo.ProductServiceTime)));
  83. var today = common.formatDateCHS(common.formatTime(new Date()));
  84. if (productServiceTime < today) {
  85. wx.redirectTo({
  86. url: '../other/userbook',
  87. });
  88. }
  89. else if (app.globalData.userInfo.ClassDayNumber < 0) {
  90. wx.redirectTo({
  91. url: '../other/userbook',
  92. });
  93. }
  94. else if (app.globalData.GotoUrl) {
  95. //console.log(app.globalData.GotoUrl);
  96. wx.navigateTo({
  97. url: app.globalData.GotoUrl,
  98. });
  99. app.globalData.GotoUrl = "";
  100. }
  101. }
  102. }
  103. else if (app.globalData.userInfo.IsShow == 0) {
  104. main.buildInitData(function () { });
  105. }
  106. that.setData({
  107. IsAccredit: true,
  108. });
  109. that.init();
  110. that.getTaskTodayList();
  111. that.isNoSavedCard();
  112. }
  113. else {
  114. wx.navigateTo({
  115. url: '../index/accredit',
  116. });
  117. }
  118. if (res.authSetting['scope.record'] === true) {
  119. app.globalData.IsRecorderAccredit = 1;
  120. }
  121. else if (res.authSetting['scope.record'] === false) {
  122. app.globalData.IsRecorderAccredit = -1;
  123. }
  124. }
  125. });
  126. }
  127. wx.setNavigationBarColor({
  128. frontColor: "#ffffff",
  129. backgroundColor: "#3157BA",
  130. });
  131. },
  132. init: function () {
  133. //显示练习模式
  134. var cardType = wx.getStorageSync("CardType");
  135. if (!cardType)
  136. cardType = 0;
  137. this.setData({
  138. CardType: cardType,
  139. });
  140. //题卡主题色
  141. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  142. if (!arrColorIndex) {
  143. app.globalData.ColorIndex = common.random(1, 4);
  144. }
  145. else {
  146. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  147. }
  148. //显示答案操作方式
  149. var clickType = wx.getStorageSync("ClickType");
  150. if (!clickType)
  151. clickType = 0;
  152. app.globalData.ClickType = clickType;
  153. //选择建议
  154. var SecondConfigArray = wx.getStorageSync("SecondConfigArray");
  155. if (SecondConfigArray)
  156. app.globalData.SecondConfigArray = SecondConfigArray;
  157. //显示命名方式
  158. var MemoryLevel = wx.getStorageSync("MemoryLevel");
  159. if (!MemoryLevel)
  160. MemoryLevel = 0;
  161. app.globalData.MemoryLevel = MemoryLevel;
  162. },
  163. goto: function (e) {
  164. var url = e.currentTarget.dataset.url;
  165. wx.navigateTo({
  166. url: url,
  167. });
  168. if (url == "../marketing/index") {
  169. this.setData({
  170. IsShowRemind: false,
  171. });
  172. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  173. }
  174. if (url == "../plan/studyplan" && this.data.DayNumber<=app.globalData.IsShowSettingRemind){
  175. wx.setStorageSync('IsShowSettingRemind', this.data.DayNumber);
  176. }
  177. },
  178. //得到当天任务
  179. getTaskTodayList: function () {
  180. var that = this;
  181. main.UpdateMiaoguoCardTodayAll(true, function () {
  182. main.getTaskTodayList(function (data) {
  183. if (data.IsMaintain == 1) {
  184. that.setData({
  185. IsMaintain: 1,
  186. });
  187. }
  188. else {
  189. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  190. that.setData({
  191. DayNumber: data.DayNumber,
  192. TodayTaskNumber: TodayTaskNumber,
  193. IsStart: data.IsStart,
  194. });
  195. if(app.globalData.MemoryLevel==0 && data.DayNumber>=8){
  196. var IsShowPatternMenu = wx.getStorageSync("IsShowPatternMenu");
  197. if (!IsShowPatternMenu){
  198. wx.navigateTo({
  199. url: '../other/menu?Type=1',
  200. });
  201. wx.setStorageSync('IsShowPatternMenu', 1);
  202. }
  203. }
  204. //是否显示提示任务量设置
  205. if (that.data.DayNumber<=app.globalData.IsShowSettingRemind){
  206. var IsShowSettingRemind = wx.getStorageSync("IsShowSettingRemind");
  207. if (!IsShowSettingRemind || IsShowSettingRemind<that.data.DayNumber){
  208. that.setData({
  209. IsShowSettingRemind: 1,
  210. });
  211. }
  212. else{
  213. that.setData({
  214. IsShowSettingRemind: 0,
  215. });
  216. }
  217. }
  218. //判断是否出现推广广告
  219. common.getStorageValue(that, "IsShowMarketingTime", "2020-01-01 00:00:00", function () {
  220. if (that.data.IsShowMarketingTime<common.formatTime(new Date())) {
  221. main.getAwardData(function(data){
  222. var award=data.Total-data.AwardDayNumber
  223. that.setData({
  224. IsShowRemind: true,
  225. AwardDayNumber:award,
  226. });
  227. });
  228. }
  229. });
  230. }
  231. });
  232. });
  233. },
  234. isNoSavedCard: function () {
  235. var that = this;
  236. //判断是否有未保存的卡
  237. if (app.globalData.userInfo.IsMaintain == 1) {
  238. that.setData({
  239. IsMaintain: app.globalData.userInfo.IsMaintain,
  240. });
  241. wx.setNavigationBarColor({
  242. frontColor: "#ffffff",
  243. backgroundColor: "#0B8457",
  244. })
  245. }
  246. //判断是否有未保存的卡
  247. else if (wx.getStorageSync("TempCardNoSaved")) {
  248. that.setData({
  249. IsTempCardNoSaved: true,
  250. });
  251. wx.setNavigationBarColor({
  252. frontColor: "#ffffff",
  253. backgroundColor: "#0B8457",
  254. })
  255. }
  256. else {
  257. that.setData({
  258. IsTempCardNoSaved: false,
  259. });
  260. wx.setNavigationBarColor({
  261. frontColor: "#ffffff",
  262. backgroundColor: "#3157BA",
  263. });
  264. }
  265. },
  266. onOpenTempCard: function () {
  267. var card = wx.getStorageSync("TempCardNoSaved");
  268. app.globalData.CardList = [card];
  269. wx.navigateTo({
  270. url: './add?type=add2&id=' + card.MiaoguoCardID,
  271. });
  272. },
  273. onGiveupTempCard: function () {
  274. var that = this;
  275. wx.removeStorageSync("TempCardNoSaved");
  276. that.isNoSavedCard();
  277. },
  278. gotoSearchCard: function () {
  279. wx.reLaunch({
  280. url: './searchCard',
  281. });
  282. },
  283. showUserID:function(){
  284. var that = this;
  285. if (app.globalData.userInfo.UserID == 1
  286. || app.globalData.userInfo.UserID == 3
  287. || app.globalData.userInfo.UserID == 4) {
  288. var userid=2;
  289. if (app.globalData.userInfo.UserID>=3)
  290. userid = app.globalData.userInfo.UserID;
  291. that.setData({
  292. IsShowUserID: true,
  293. ChangeUserID:userid,
  294. });
  295. }
  296. },
  297. onKeyInput: function (e) {
  298. var id = e.detail.value;
  299. var usertype = e.currentTarget.dataset.type;
  300. var that = this;
  301. if (usertype=="userid"){
  302. that.setData({
  303. ChangeUserID: id,
  304. });
  305. }
  306. else if (usertype=="newuserid"){
  307. that.setData({
  308. ChangeNewUserID: id,
  309. });
  310. }
  311. else if (usertype=="introduceruserid"){
  312. that.setData({
  313. ChangeIntroducerUserID: id,
  314. });
  315. }
  316. else if (usertype=="versionid"){
  317. that.setData({
  318. VersoinID: id,
  319. });
  320. }
  321. },
  322. setSelectUser: function (e) {
  323. var that = this;
  324. if (app.globalData.userInfo.UserID == 1
  325. || app.globalData.userInfo.UserID == 2
  326. || app.globalData.userInfo.UserID == 3
  327. || app.globalData.userInfo.UserID == 4) {
  328. var userid = that.data.ChangeUserID;
  329. wx.setStorageSync("UserID", userid);
  330. app.globalData.userInfo.UserID = userid;
  331. var fieldStr="&FieldStr=NickName,ProductServiceTime,AvatarUrl";
  332. that.getUserInfo(userid,fieldStr,function(data){
  333. wx.setNavigationBarTitle({
  334. title: data.NickName
  335. });
  336. main.getUserConfig();
  337. app.globalData.userInfo.ProductServiceTime=data.ProductServiceTime;
  338. if (app.globalData.userInfo.UserID!=2){
  339. app.globalData.userInfo.NickName=data.NickName;
  340. app.globalData.userInfo.AvatarUrl=data.AvatarUrl;
  341. }
  342. });
  343. that.setData({
  344. IsShowUserID: false,
  345. });
  346. that.onShow();
  347. }
  348. },
  349. getUserInfoFunction:function(e){
  350. var that = this;
  351. var userid=e.currentTarget.dataset.id;
  352. var type1=e.currentTarget.dataset.type;
  353. var fieldStr="&FieldStr=NickName,AvatarUrl";
  354. if (userid){
  355. that.getUserInfo(userid,fieldStr,function(data){
  356. if (type1==1){
  357. that.setData({
  358. IntroducerAvatar: data.AvatarUrl,
  359. IntroducerNickName: data.NickName,
  360. });
  361. }
  362. else{
  363. that.setData({
  364. NewUserAvatar: data.AvatarUrl,
  365. NewUserNickName: data.NickName,
  366. });
  367. }
  368. });
  369. }
  370. },
  371. getUserInfo:function(userID,fieldStr,callback){
  372. var url = "GetMiaoguoWXUserInfo?UserID=" + userID + fieldStr;
  373. main.getData(url, function (data) {
  374. if (data) {
  375. callback(data);
  376. }
  377. });
  378. },
  379. setUserIntroducer: function (e) {
  380. var that = this;
  381. if (that.data.ChangeNewUserID && that.data.ChangeIntroducerUserID){
  382. if (app.globalData.userInfo.UserID == 1
  383. || app.globalData.userInfo.UserID == 2
  384. || app.globalData.userInfo.UserID == 3
  385. || app.globalData.userInfo.UserID == 4) {
  386. var url = "UpdateIntroducer?UserID=" + that.data.ChangeNewUserID + "&Introducer="+that.data.ChangeIntroducerUserID;
  387. main.getData(url, function (data) {
  388. that.setData({
  389. ChangeNewUserID: null,
  390. ChangeIntroducerUserID: null,
  391. });
  392. wx.showToast({
  393. title: '介绍人更改成功',
  394. })
  395. });
  396. }
  397. }
  398. },
  399. closeRemind:function(){
  400. this.setData({
  401. IsShowRemind: false,
  402. });
  403. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  404. },
  405. setVersionStart:function(e){
  406. var flag=e.currentTarget.dataset.flag;
  407. var versionid=e.currentTarget.dataset.versionid;
  408. var url = "UpdateVersionStatus?ProgramID=166&Version="+versionid+"&Flag=" + flag;
  409. main.getData(url, function (data) {
  410. wx.showToast({
  411. title: '修改成功!',
  412. })
  413. });
  414. },
  415. onShareAppMessage: function () {
  416. return {
  417. title: app.globalData.ShareTitle,
  418. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  419. imageUrl: app.globalData.ShareImage,
  420. }
  421. },
  422. onShareTimeline: function () {
  423. return this.onShareAppMessage();
  424. },
  425. })