default.js 12 KB

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