default.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. //判断每30天是否是高级模式
  230. wx.removeStorageSync('IsShowPatternMenu');
  231. }
  232. });
  233. }
  234. });
  235. });
  236. },
  237. isNoSavedCard: function () {
  238. var that = this;
  239. //判断是否有系统故障
  240. if (app.globalData.userInfo.IsMaintain == 1) {
  241. that.setData({
  242. IsMaintain: app.globalData.userInfo.IsMaintain,
  243. });
  244. wx.setNavigationBarColor({
  245. frontColor: "#ffffff",
  246. backgroundColor: "#0B8457",
  247. })
  248. }
  249. //判断是否有未保存的卡
  250. else if (wx.getStorageSync("TempCardNoSaved")) {
  251. wx.navigateTo({
  252. url: '../other/recover',
  253. });
  254. }
  255. else {
  256. that.setData({
  257. IsTempCardNoSaved: false,
  258. });
  259. wx.setNavigationBarColor({
  260. frontColor: "#ffffff",
  261. backgroundColor: "#3157BA",
  262. });
  263. }
  264. },
  265. gotoCardmain: function () {
  266. wx.reLaunch({
  267. url: './cardmain',
  268. });
  269. },
  270. showUserID:function(){
  271. var that = this;
  272. if (app.globalData.userInfo.UserID == 1
  273. || app.globalData.userInfo.UserID == 3
  274. || app.globalData.userInfo.UserID == 4) {
  275. var userid=2;
  276. if (app.globalData.userInfo.UserID>=3)
  277. userid = app.globalData.userInfo.UserID;
  278. that.setData({
  279. IsShowUserID: true,
  280. ChangeUserID:userid,
  281. });
  282. }
  283. },
  284. onKeyInput: function (e) {
  285. var id = e.detail.value;
  286. var usertype = e.currentTarget.dataset.type;
  287. var that = this;
  288. if (usertype=="userid"){
  289. that.setData({
  290. ChangeUserID: id,
  291. });
  292. }
  293. else if (usertype=="newuserid"){
  294. that.setData({
  295. ChangeNewUserID: id,
  296. });
  297. }
  298. else if (usertype=="introduceruserid"){
  299. that.setData({
  300. ChangeIntroducerUserID: id,
  301. });
  302. }
  303. else if (usertype=="versionid"){
  304. that.setData({
  305. VersoinID: id,
  306. });
  307. }
  308. },
  309. setSelectUser: function (e) {
  310. var that = this;
  311. if (app.globalData.userInfo.UserID == 1
  312. || app.globalData.userInfo.UserID == 2
  313. || app.globalData.userInfo.UserID == 3
  314. || app.globalData.userInfo.UserID == 4) {
  315. var userid = that.data.ChangeUserID;
  316. wx.setStorageSync("UserID", userid);
  317. app.globalData.userInfo.UserID = userid;
  318. var fieldStr="&FieldStr=NickName,ProductServiceTime,AvatarUrl";
  319. that.getUserInfo(userid,fieldStr,function(data){
  320. wx.setNavigationBarTitle({
  321. title: data.NickName
  322. });
  323. main.getUserConfig();
  324. app.globalData.userInfo.ProductServiceTime=data.ProductServiceTime;
  325. if (app.globalData.userInfo.UserID!=2){
  326. app.globalData.userInfo.NickName=data.NickName;
  327. app.globalData.userInfo.AvatarUrl=data.AvatarUrl;
  328. }
  329. });
  330. that.setData({
  331. IsShowUserID: false,
  332. });
  333. that.onShow();
  334. }
  335. },
  336. getUserInfoFunction:function(e){
  337. var that = this;
  338. var userid=e.currentTarget.dataset.id;
  339. var type1=e.currentTarget.dataset.type;
  340. var fieldStr="&FieldStr=NickName,AvatarUrl";
  341. if (userid){
  342. that.getUserInfo(userid,fieldStr,function(data){
  343. if (type1==1){
  344. that.setData({
  345. IntroducerAvatar: data.AvatarUrl,
  346. IntroducerNickName: data.NickName,
  347. });
  348. }
  349. else{
  350. that.setData({
  351. NewUserAvatar: data.AvatarUrl,
  352. NewUserNickName: data.NickName,
  353. });
  354. }
  355. });
  356. }
  357. },
  358. getUserInfo:function(userID,fieldStr,callback){
  359. var url = "GetMiaoguoWXUserInfo?UserID=" + userID + fieldStr;
  360. main.getData(url, function (data) {
  361. if (data) {
  362. callback(data);
  363. }
  364. });
  365. },
  366. setUserIntroducer: function (e) {
  367. var that = this;
  368. if (that.data.ChangeNewUserID && that.data.ChangeIntroducerUserID){
  369. if (app.globalData.userInfo.UserID == 1
  370. || app.globalData.userInfo.UserID == 2
  371. || app.globalData.userInfo.UserID == 3
  372. || app.globalData.userInfo.UserID == 4) {
  373. var url = "UpdateIntroducer?UserID=" + that.data.ChangeNewUserID + "&Introducer="+that.data.ChangeIntroducerUserID;
  374. main.getData(url, function (data) {
  375. that.setData({
  376. ChangeNewUserID: null,
  377. ChangeIntroducerUserID: null,
  378. });
  379. wx.showToast({
  380. title: '介绍人更改成功',
  381. })
  382. });
  383. }
  384. }
  385. },
  386. closeRemind:function(){
  387. this.setData({
  388. IsShowRemind: false,
  389. });
  390. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  391. },
  392. setVersionStart:function(e){
  393. var flag=e.currentTarget.dataset.flag;
  394. var versionid=e.currentTarget.dataset.versionid;
  395. var url = "UpdateVersionStatus?ProgramID=166&Version="+versionid+"&Flag=" + flag;
  396. main.getData(url, function (data) {
  397. wx.showToast({
  398. title: '修改成功!',
  399. })
  400. });
  401. },
  402. onShareAppMessage: function () {
  403. return {
  404. title: app.globalData.ShareTitle,
  405. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  406. imageUrl: app.globalData.ShareImage,
  407. }
  408. },
  409. onShareTimeline: function () {
  410. return this.onShareAppMessage();
  411. },
  412. })