default.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. app.globalData.TempStr2=null;
  128. wx.setNavigationBarColor({
  129. frontColor: "#ffffff",
  130. backgroundColor: "#3157BA",
  131. });
  132. },
  133. init: function () {
  134. //显示练习模式
  135. var cardType = wx.getStorageSync("CardType");
  136. if (!cardType)
  137. cardType = 0;
  138. this.setData({
  139. CardType: cardType,
  140. });
  141. //题卡主题色
  142. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  143. if (!arrColorIndex) {
  144. app.globalData.ColorIndex = common.random(1, 4);
  145. }
  146. else {
  147. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  148. }
  149. //显示答案操作方式
  150. var clickType = wx.getStorageSync("ClickType");
  151. if (!clickType)
  152. clickType = 0;
  153. app.globalData.ClickType = clickType;
  154. //选择建议
  155. var SecondConfigArray = wx.getStorageSync("SecondConfigArray");
  156. if (SecondConfigArray)
  157. app.globalData.SecondConfigArray = SecondConfigArray;
  158. //显示命名方式
  159. var MemoryLevel = wx.getStorageSync("MemoryLevel");
  160. if (!MemoryLevel)
  161. MemoryLevel = 0;
  162. app.globalData.MemoryLevel = MemoryLevel;
  163. },
  164. goto: function (e) {
  165. var url = e.currentTarget.dataset.url;
  166. wx.navigateTo({
  167. url: url,
  168. });
  169. if (url == "../marketing/index") {
  170. this.setData({
  171. IsShowRemind: false,
  172. });
  173. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  174. }
  175. if (url == "../plan/studyplan" && this.data.DayNumber<=app.globalData.IsShowSettingRemind){
  176. wx.setStorageSync('IsShowSettingRemind', this.data.DayNumber);
  177. }
  178. },
  179. //得到当天任务
  180. getTaskTodayList: function () {
  181. var that = this;
  182. main.UpdateMiaoguoCardTodayAll(true, function () {
  183. main.getTaskTodayList(function (data) {
  184. if (data.IsMaintain == 1) {
  185. that.setData({
  186. IsMaintain: 1,
  187. });
  188. }
  189. else {
  190. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  191. that.setData({
  192. DayNumber: data.DayNumber,
  193. TodayTaskNumber: TodayTaskNumber,
  194. IsStart: data.IsStart,
  195. });
  196. if(app.globalData.MemoryLevel==0 && data.DayNumber>=8){
  197. var IsShowPatternMenu = wx.getStorageSync("IsShowPatternMenu");
  198. if (!IsShowPatternMenu){
  199. wx.navigateTo({
  200. url: '../other/menu?Type=1',
  201. });
  202. wx.setStorageSync('IsShowPatternMenu', 1);
  203. }
  204. }
  205. //是否显示提示任务量设置
  206. if (that.data.DayNumber<=app.globalData.IsShowSettingRemind){
  207. var IsShowSettingRemind = wx.getStorageSync("IsShowSettingRemind");
  208. if (!IsShowSettingRemind || IsShowSettingRemind<that.data.DayNumber){
  209. that.setData({
  210. IsShowSettingRemind: 1,
  211. });
  212. }
  213. else{
  214. that.setData({
  215. IsShowSettingRemind: 0,
  216. });
  217. }
  218. }
  219. //判断是否出现推广广告
  220. common.getStorageValue(that, "IsShowMarketingTime", "2020-01-01 00:00:00", function () {
  221. if (that.data.IsShowMarketingTime<common.formatTime(new Date())) {
  222. main.getAwardData(function(data){
  223. var award=data.Total-data.AwardDayNumber
  224. that.setData({
  225. IsShowRemind: true,
  226. AwardDayNumber:award,
  227. });
  228. });
  229. }
  230. });
  231. }
  232. });
  233. });
  234. },
  235. isNoSavedCard: function () {
  236. var that = this;
  237. //判断是否有未保存的卡
  238. if (app.globalData.userInfo.IsMaintain == 1) {
  239. that.setData({
  240. IsMaintain: app.globalData.userInfo.IsMaintain,
  241. });
  242. wx.setNavigationBarColor({
  243. frontColor: "#ffffff",
  244. backgroundColor: "#0B8457",
  245. })
  246. }
  247. //判断是否有未保存的卡
  248. else if (wx.getStorageSync("TempCardNoSaved")) {
  249. that.setData({
  250. IsTempCardNoSaved: true,
  251. });
  252. wx.setNavigationBarColor({
  253. frontColor: "#ffffff",
  254. backgroundColor: "#0B8457",
  255. })
  256. }
  257. else {
  258. that.setData({
  259. IsTempCardNoSaved: false,
  260. });
  261. wx.setNavigationBarColor({
  262. frontColor: "#ffffff",
  263. backgroundColor: "#3157BA",
  264. });
  265. }
  266. },
  267. onOpenTempCard: function () {
  268. var card = wx.getStorageSync("TempCardNoSaved");
  269. app.globalData.CardList = [card];
  270. wx.navigateTo({
  271. url: './add?type=add2&id=' + card.MiaoguoCardID,
  272. });
  273. },
  274. onGiveupTempCard: function () {
  275. var that = this;
  276. wx.removeStorageSync("TempCardNoSaved");
  277. that.isNoSavedCard();
  278. },
  279. gotoCardmain: function () {
  280. wx.reLaunch({
  281. url: './cardmain',
  282. });
  283. },
  284. showUserID:function(){
  285. var that = this;
  286. if (app.globalData.userInfo.UserID == 1
  287. || app.globalData.userInfo.UserID == 3
  288. || app.globalData.userInfo.UserID == 4) {
  289. var userid=2;
  290. if (app.globalData.userInfo.UserID>=3)
  291. userid = app.globalData.userInfo.UserID;
  292. that.setData({
  293. IsShowUserID: true,
  294. ChangeUserID:userid,
  295. });
  296. }
  297. },
  298. onKeyInput: function (e) {
  299. var id = e.detail.value;
  300. var usertype = e.currentTarget.dataset.type;
  301. var that = this;
  302. if (usertype=="userid"){
  303. that.setData({
  304. ChangeUserID: id,
  305. });
  306. }
  307. else if (usertype=="newuserid"){
  308. that.setData({
  309. ChangeNewUserID: id,
  310. });
  311. }
  312. else if (usertype=="introduceruserid"){
  313. that.setData({
  314. ChangeIntroducerUserID: id,
  315. });
  316. }
  317. else if (usertype=="versionid"){
  318. that.setData({
  319. VersoinID: id,
  320. });
  321. }
  322. },
  323. setSelectUser: function (e) {
  324. var that = this;
  325. if (app.globalData.userInfo.UserID == 1
  326. || app.globalData.userInfo.UserID == 2
  327. || app.globalData.userInfo.UserID == 3
  328. || app.globalData.userInfo.UserID == 4) {
  329. var userid = that.data.ChangeUserID;
  330. wx.setStorageSync("UserID", userid);
  331. app.globalData.userInfo.UserID = userid;
  332. var fieldStr="&FieldStr=NickName,ProductServiceTime,AvatarUrl";
  333. that.getUserInfo(userid,fieldStr,function(data){
  334. wx.setNavigationBarTitle({
  335. title: data.NickName
  336. });
  337. main.getUserConfig();
  338. app.globalData.userInfo.ProductServiceTime=data.ProductServiceTime;
  339. if (app.globalData.userInfo.UserID!=2){
  340. app.globalData.userInfo.NickName=data.NickName;
  341. app.globalData.userInfo.AvatarUrl=data.AvatarUrl;
  342. }
  343. });
  344. that.setData({
  345. IsShowUserID: false,
  346. });
  347. that.onShow();
  348. }
  349. },
  350. getUserInfoFunction:function(e){
  351. var that = this;
  352. var userid=e.currentTarget.dataset.id;
  353. var type1=e.currentTarget.dataset.type;
  354. var fieldStr="&FieldStr=NickName,AvatarUrl";
  355. if (userid){
  356. that.getUserInfo(userid,fieldStr,function(data){
  357. if (type1==1){
  358. that.setData({
  359. IntroducerAvatar: data.AvatarUrl,
  360. IntroducerNickName: data.NickName,
  361. });
  362. }
  363. else{
  364. that.setData({
  365. NewUserAvatar: data.AvatarUrl,
  366. NewUserNickName: data.NickName,
  367. });
  368. }
  369. });
  370. }
  371. },
  372. getUserInfo:function(userID,fieldStr,callback){
  373. var url = "GetMiaoguoWXUserInfo?UserID=" + userID + fieldStr;
  374. main.getData(url, function (data) {
  375. if (data) {
  376. callback(data);
  377. }
  378. });
  379. },
  380. setUserIntroducer: function (e) {
  381. var that = this;
  382. if (that.data.ChangeNewUserID && that.data.ChangeIntroducerUserID){
  383. if (app.globalData.userInfo.UserID == 1
  384. || app.globalData.userInfo.UserID == 2
  385. || app.globalData.userInfo.UserID == 3
  386. || app.globalData.userInfo.UserID == 4) {
  387. var url = "UpdateIntroducer?UserID=" + that.data.ChangeNewUserID + "&Introducer="+that.data.ChangeIntroducerUserID;
  388. main.getData(url, function (data) {
  389. that.setData({
  390. ChangeNewUserID: null,
  391. ChangeIntroducerUserID: null,
  392. });
  393. wx.showToast({
  394. title: '介绍人更改成功',
  395. })
  396. });
  397. }
  398. }
  399. },
  400. closeRemind:function(){
  401. this.setData({
  402. IsShowRemind: false,
  403. });
  404. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  405. },
  406. setVersionStart:function(e){
  407. var flag=e.currentTarget.dataset.flag;
  408. var versionid=e.currentTarget.dataset.versionid;
  409. var url = "UpdateVersionStatus?ProgramID=166&Version="+versionid+"&Flag=" + flag;
  410. main.getData(url, function (data) {
  411. wx.showToast({
  412. title: '修改成功!',
  413. })
  414. });
  415. },
  416. onShareAppMessage: function () {
  417. return {
  418. title: app.globalData.ShareTitle,
  419. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  420. imageUrl: app.globalData.ShareImage,
  421. }
  422. },
  423. onShareTimeline: function () {
  424. return this.onShareAppMessage();
  425. },
  426. })