default.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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.navigateTo({
  48. url: '../other/newuser',
  49. });
  50. }
  51. }
  52. else {
  53. wx.getSetting({
  54. success(res) {
  55. if (app.globalData.userInfo.NickName=="陌生用户" && app.globalData.userInfo.IsMember==1 && app.globalData.userInfo.IsShow == 1){
  56. wx.navigateTo({
  57. url: '../index/accredit',
  58. });
  59. }
  60. else{
  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. if (res.authSetting['scope.record'] === true) {
  113. app.globalData.IsRecorderAccredit = 1;
  114. }
  115. else if (res.authSetting['scope.record'] === false) {
  116. app.globalData.IsRecorderAccredit = -1;
  117. }
  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. //是否显示提示任务量设置
  192. if (that.data.DayNumber<=app.globalData.IsShowSettingRemind){
  193. var IsShowSettingRemind = wx.getStorageSync("IsShowSettingRemind");
  194. if (!IsShowSettingRemind || IsShowSettingRemind<that.data.DayNumber){
  195. that.setData({
  196. IsShowSettingRemind: 1,
  197. });
  198. }
  199. else{
  200. that.setData({
  201. IsShowSettingRemind: 0,
  202. });
  203. }
  204. }
  205. //判断是否出现推广广告
  206. common.getStorageValue(that, "IsShowMarketingTime", "2020-01-01 00:00:00", function () {
  207. if (that.data.IsShowMarketingTime<common.formatTime(new Date())) {
  208. main.getAwardData(function(data){
  209. var award=data.Total-data.AwardDayNumber
  210. that.setData({
  211. IsShowRemind: true,
  212. AwardDayNumber:award,
  213. });
  214. });
  215. }
  216. else{
  217. if(app.globalData.MemoryLevel==0 && data.DayNumber>=8){
  218. var IsShowPatternMenu = wx.getStorageSync("IsShowPatternMenu");
  219. if (!IsShowPatternMenu){
  220. wx.navigateTo({
  221. url: '../other/menu?Type=1',
  222. });
  223. wx.setStorageSync('IsShowPatternMenu', 1);
  224. }
  225. }
  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. gotoReLaunch: function (e) {
  261. var url=e.currentTarget.dataset.url;
  262. wx.reLaunch({
  263. url: url,
  264. });
  265. },
  266. showUserID:function(){
  267. var that = this;
  268. if (app.globalData.userInfo.UserID == 1
  269. || app.globalData.userInfo.UserID == 3
  270. || app.globalData.userInfo.UserID == 4) {
  271. var userid=2;
  272. if (app.globalData.userInfo.UserID>=3)
  273. userid = app.globalData.userInfo.UserID;
  274. that.setData({
  275. IsShowUserID: true,
  276. ChangeUserID:userid,
  277. });
  278. }
  279. },
  280. onKeyInput: function (e) {
  281. var id = e.detail.value;
  282. var usertype = e.currentTarget.dataset.type;
  283. var that = this;
  284. if (usertype=="userid"){
  285. that.setData({
  286. ChangeUserID: id,
  287. });
  288. }
  289. else if (usertype=="newuserid"){
  290. that.setData({
  291. ChangeNewUserID: id,
  292. });
  293. }
  294. else if (usertype=="introduceruserid"){
  295. that.setData({
  296. ChangeIntroducerUserID: id,
  297. });
  298. }
  299. else if (usertype=="versionid"){
  300. that.setData({
  301. VersoinID: id,
  302. });
  303. }
  304. else if (usertype=="groupuserid"){
  305. that.setData({
  306. ChangeGroupUserID: id,
  307. });
  308. }
  309. },
  310. setSelectUser: function (e) {
  311. var that = this;
  312. if (app.globalData.userInfo.UserID == 1
  313. || app.globalData.userInfo.UserID == 2
  314. || app.globalData.userInfo.UserID == 3
  315. || app.globalData.userInfo.UserID == 4) {
  316. var userid = that.data.ChangeUserID;
  317. wx.setStorageSync("UserID", userid);
  318. app.globalData.userInfo.UserID = userid;
  319. var fieldStr="&FieldStr=NickName,ProductServiceTime,AvatarUrl";
  320. that.getUserInfo(userid,fieldStr,function(data){
  321. wx.setNavigationBarTitle({
  322. title: data.NickName
  323. });
  324. main.getUserConfig();
  325. app.globalData.userInfo.ProductServiceTime=data.ProductServiceTime;
  326. if (app.globalData.userInfo.UserID!=2){
  327. app.globalData.userInfo.NickName=data.NickName;
  328. app.globalData.userInfo.AvatarUrl=data.AvatarUrl;
  329. }
  330. });
  331. that.setData({
  332. IsShowUserID: false,
  333. });
  334. that.onShow();
  335. }
  336. },
  337. getUserInfoFunction:function(e){
  338. var that = this;
  339. var userid=e.currentTarget.dataset.id;
  340. var type1=e.currentTarget.dataset.type;
  341. var fieldStr="&FieldStr=NickName,AvatarUrl";
  342. if (userid){
  343. that.getUserInfo(userid,fieldStr,function(data){
  344. if (type1==0){
  345. that.setData({
  346. NewUserAvatar: data.AvatarUrl,
  347. NewUserNickName: data.NickName,
  348. });
  349. }
  350. else if (type1==1){
  351. that.setData({
  352. IntroducerAvatar: data.AvatarUrl,
  353. IntroducerNickName: data.NickName,
  354. });
  355. }
  356. else if (type1==2){
  357. that.setData({
  358. GroupUserAvatar: data.AvatarUrl,
  359. GroupUserNickName: data.NickName,
  360. });
  361. }
  362. });
  363. }
  364. },
  365. getUserInfo:function(userID,fieldStr,callback){
  366. var url = "GetMiaoguoWXUserInfo?UserID=" + userID + fieldStr;
  367. main.getData(url, function (data) {
  368. if (data) {
  369. callback(data);
  370. }
  371. });
  372. },
  373. setUserGroup: function (e) {
  374. var that = this;
  375. if (that.data.ChangeGroupUserID){
  376. if (app.globalData.userInfo.UserID == 1
  377. || app.globalData.userInfo.UserID == 2
  378. || app.globalData.userInfo.UserID == 3
  379. || app.globalData.userInfo.UserID == 4) {
  380. var id=e.currentTarget.dataset.id;
  381. var url = "UpdateUserMemberInfo?UserID=" + that.data.ChangeGroupUserID + "&GroupID="+id;
  382. main.getData(url, function (data) {
  383. that.setData({
  384. ChangeGroupUserID: null,
  385. GroupUserAvatar:null,
  386. });
  387. wx.showToast({
  388. title: '群更改成功',
  389. })
  390. });
  391. }
  392. }
  393. },
  394. setUserIntroducer: function (e) {
  395. var that = this;
  396. if (that.data.ChangeNewUserID && that.data.ChangeIntroducerUserID){
  397. if (app.globalData.userInfo.UserID == 1
  398. || app.globalData.userInfo.UserID == 2
  399. || app.globalData.userInfo.UserID == 3
  400. || app.globalData.userInfo.UserID == 4) {
  401. var url = "UpdateIntroducer?UserID=" + that.data.ChangeNewUserID + "&Introducer="+that.data.ChangeIntroducerUserID;
  402. main.getData(url, function (data) {
  403. that.setData({
  404. ChangeNewUserID: null,
  405. ChangeIntroducerUserID: null,
  406. NewUserAvatar:null,
  407. IntroducerAvatar:null,
  408. });
  409. wx.showToast({
  410. title: '介绍人更改成功',
  411. })
  412. });
  413. }
  414. }
  415. },
  416. closeRemind:function(){
  417. this.setData({
  418. IsShowRemind: false,
  419. });
  420. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  421. //判断每30天是否是高级模式
  422. wx.removeStorageSync('IsShowPatternMenu');
  423. },
  424. setVersionStart:function(e){
  425. var flag=e.currentTarget.dataset.flag;
  426. var versionid=e.currentTarget.dataset.versionid;
  427. var url = "UpdateVersionStatus?ProgramID=166&Version="+versionid+"&Flag=" + flag;
  428. main.getData(url, function (data) {
  429. wx.showToast({
  430. title: '修改成功!',
  431. })
  432. });
  433. },
  434. onShareAppMessage: function () {
  435. return {
  436. title: app.globalData.ShareTitle,
  437. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  438. imageUrl: app.globalData.ShareImage,
  439. }
  440. },
  441. onShareTimeline: function () {
  442. return this.onShareAppMessage();
  443. },
  444. })