default.js 12 KB

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