default.js 12 KB

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