default.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. IsShowHelp: false,
  19. IsShowUserFamily: 0,
  20. },
  21. onPullDownRefresh: function () {
  22. wx.redirectTo({
  23. url: '../main/default',
  24. })
  25. wx.stopPullDownRefresh();
  26. },
  27. onLoad: function (options) {
  28. var that = this;
  29. that.setData({
  30. Containnerheight: main.getWindowHeight(),
  31. });
  32. if (app.globalData.IsIPad) {
  33. that.setData({
  34. IsIPad: "_iPad",
  35. });
  36. }
  37. wx.showShareMenu({
  38. withShareTicket: true,
  39. menus: ['shareAppMessage', 'shareTimeline']
  40. });
  41. that.getUserFamilyInfo(app.globalData.userInfo.UserID, function (data) {});
  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.navigateTo({
  51. url: '../other/newuser',
  52. });
  53. }
  54. } else {
  55. wx.getSetting({
  56. success(res) {
  57. if (app.globalData.userInfo.NickName == "陌生用户" && app.globalData.userInfo.IsMember == 1 && app.globalData.userInfo.IsShow == 1) {
  58. wx.navigateTo({
  59. url: '../index/accredit',
  60. });
  61. } else {
  62. if (!app.globalData.userInfo.IsMember && app.globalData.userInfo.IsShow == 1) {
  63. if (app.globalData.userInfo.Subscribe == 1) {
  64. wx.navigateTo({
  65. url: '../other/userbook',
  66. });
  67. app.globalData.GotoUrl = "";
  68. } else {
  69. wx.redirectTo({
  70. url: '../other/newuser',
  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. } 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. } else if (app.globalData.userInfo.ClassDayNumber < 0) {
  87. wx.redirectTo({
  88. url: '../other/userbook',
  89. });
  90. } else if (app.globalData.GotoUrl) {
  91. //console.log(app.globalData.GotoUrl);
  92. wx.navigateTo({
  93. url: app.globalData.GotoUrl,
  94. });
  95. app.globalData.GotoUrl = "";
  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. if (res.authSetting['scope.record'] === true) {
  108. app.globalData.IsRecorderAccredit = 1;
  109. } else if (res.authSetting['scope.record'] === false) {
  110. app.globalData.IsRecorderAccredit = -1;
  111. }
  112. }
  113. }
  114. });
  115. }
  116. app.globalData.TempStr2 = null;
  117. wx.setNavigationBarColor({
  118. frontColor: "#ffffff",
  119. backgroundColor: "#3157BA",
  120. });
  121. if (wx.getStorageSync("IsHelpAddInfomation") == 1) {
  122. that.setData({
  123. IsShowHelp: true,
  124. });
  125. main.ShowHelp(that, "#btnAdd", "up", "点击下方“添加题卡”按钮");
  126. } else {
  127. that.setData({
  128. IsShowHelp: false,
  129. });
  130. }
  131. },
  132. init: function () {
  133. //显示练习模式
  134. var cardType = wx.getStorageSync("CardType");
  135. if (!cardType)
  136. cardType = 0;
  137. this.setData({
  138. CardType: cardType,
  139. });
  140. //题卡主题色
  141. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  142. if (!arrColorIndex) {
  143. app.globalData.ColorIndex = common.random(1, 4);
  144. } else {
  145. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  146. }
  147. //显示答案操作方式
  148. var clickType = wx.getStorageSync("ClickType");
  149. if (!clickType)
  150. clickType = 0;
  151. app.globalData.ClickType = clickType;
  152. //选择建议
  153. var SecondConfigArray = wx.getStorageSync("SecondConfigArray");
  154. if (SecondConfigArray)
  155. app.globalData.SecondConfigArray = SecondConfigArray;
  156. //显示命名方式
  157. var MemoryLevel = wx.getStorageSync("MemoryLevel");
  158. if (!MemoryLevel)
  159. MemoryLevel = 0;
  160. app.globalData.MemoryLevel = MemoryLevel;
  161. },
  162. goto: function (e) {
  163. var url = e.currentTarget.dataset.url;
  164. wx.navigateTo({
  165. url: url,
  166. });
  167. if (url == "../../pages_agent/marketing/index") {
  168. this.setData({
  169. IsShowRemind: false,
  170. });
  171. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  172. }
  173. if (url == "../plan/studyplan" && this.data.DayNumber <= app.globalData.IsShowSettingRemind) {
  174. wx.setStorageSync('IsShowSettingRemind', this.data.DayNumber);
  175. }
  176. },
  177. //得到当天任务
  178. getTaskTodayList: function () {
  179. var that = this;
  180. main.UpdateMiaoguoCardTodayAll(true, function () {
  181. main.getTaskTodayList(function (data) {
  182. if (data.IsMaintain == 1) {
  183. that.setData({
  184. IsMaintain: 1,
  185. });
  186. } else {
  187. var TodayTaskNumber = data.ListNew.length + data.ListReview.length + data.ListHistory.length;
  188. that.setData({
  189. DayNumber: data.DayNumber,
  190. TodayTaskNumber: TodayTaskNumber,
  191. IsStart: data.IsStart,
  192. });
  193. //是否显示提示任务量设置
  194. if (that.data.DayNumber <= app.globalData.IsShowSettingRemind) {
  195. var IsShowSettingRemind = wx.getStorageSync("IsShowSettingRemind");
  196. if (!IsShowSettingRemind || IsShowSettingRemind < that.data.DayNumber) {
  197. that.setData({
  198. IsShowSettingRemind: 1,
  199. });
  200. } else {
  201. that.setData({
  202. IsShowSettingRemind: 0,
  203. });
  204. }
  205. }
  206. //判断是否出现推广广告
  207. common.getStorageValue(that, "IsShowMarketingTime", "2020-01-01 00:00:00", function () {
  208. if (that.data.IsShowMarketingTime < common.formatTime(new Date())) {
  209. main.getAwardData(function (data) {
  210. var award = data.Total - data.AwardDayNumber
  211. that.setData({
  212. IsShowRemind: true,
  213. AwardDayNumber: award,
  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. } else {
  250. that.setData({
  251. IsTempCardNoSaved: false,
  252. });
  253. wx.setNavigationBarColor({
  254. frontColor: "#ffffff",
  255. backgroundColor: "#3157BA",
  256. });
  257. }
  258. },
  259. gotoReLaunch: function (e) {
  260. var url = e.currentTarget.dataset.url;
  261. wx.reLaunch({
  262. url: url,
  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. } else if (usertype == "newuserid") {
  288. that.setData({
  289. ChangeNewUserID: id,
  290. });
  291. } else if (usertype == "introduceruserid") {
  292. that.setData({
  293. ChangeIntroducerUserID: id,
  294. });
  295. } else if (usertype == "versionid") {
  296. that.setData({
  297. VersoinID: id,
  298. });
  299. } else if (usertype == "groupuserid") {
  300. that.setData({
  301. ChangeGroupUserID: id,
  302. });
  303. } else if (usertype == "refunduserid") {
  304. that.setData({
  305. RefundUserID: id,
  306. });
  307. } else if (usertype == "refundremark") {
  308. that.setData({
  309. RefundRemark: id,
  310. });
  311. }
  312. },
  313. setSelectUser: function (e) {
  314. var that = this;
  315. if (app.globalData.userInfo.UserID == 1 ||
  316. app.globalData.userInfo.UserID == 2 ||
  317. app.globalData.userInfo.UserID == 3 ||
  318. app.globalData.userInfo.UserID == 4) {
  319. var userid = that.data.ChangeUserID;
  320. wx.setStorageSync("UserID", userid);
  321. app.globalData.userInfo.UserID = userid;
  322. var fieldStr = "";
  323. that.getUserInfo(userid, fieldStr, function (data) {
  324. wx.setNavigationBarTitle({
  325. title: data.NickName
  326. });
  327. main.getUserConfig();
  328. app.globalData.userInfo.ProductServiceTime = data.ProductServiceTime;
  329. if (app.globalData.userInfo.UserID != 2) {
  330. app.globalData.userInfo.NickName = data.NickName;
  331. app.globalData.userInfo.AvatarUrl = data.AvatarUrl;
  332. }
  333. if (data.IsPromoter > 0) {
  334. app.globalData.userInfo.IsPromoter = data.IsPromoter;
  335. app.globalData.userInfo.PromotionLimitDays = data.PromotionLimitDays;
  336. app.globalData.userInfo.PromotionLimitTime = data.PromotionLimitTime;
  337. app.globalData.userInfo.WXServiceCharge = data.WXServiceCharge;
  338. app.globalData.userInfo.IndividualIncomeTax = data.IndividualIncomeTax;
  339. app.globalData.userInfo.WXAccount = data.WXAccount;
  340. app.globalData.userInfo.RealName = data.RealName;
  341. app.globalData.userInfo.IntroducerNickName = data.IntroducerNickName;
  342. app.globalData.userInfo.IntroducerAvatarUrl = data.IntroducerAvatarUrl;
  343. }
  344. that.getUserFamilyInfo(app.globalData.userInfo.UserID, function (data) {});
  345. });
  346. that.setData({
  347. IsShowUserID: false,
  348. });
  349. that.onShow();
  350. }
  351. },
  352. getUserInfoFunction: function (e) {
  353. var that = this;
  354. var userid = e.currentTarget.dataset.id;
  355. var type1 = e.currentTarget.dataset.type;
  356. var fieldStr = "&FieldStr=NickName,AvatarUrl";
  357. if (userid) {
  358. that.getUserInfo(userid, fieldStr, function (data) {
  359. if (type1 == 3) {
  360. that.setData({
  361. RefundUserAvatar: data.AvatarUrl,
  362. RefundUserNickName: data.NickName,
  363. });
  364. var url = "GetUserPayList?UserID=" + userid;
  365. main.getData(url, function (data) {
  366. if (data) {
  367. that.setData({
  368. PayList: data,
  369. });
  370. }
  371. });
  372. }
  373. });
  374. }
  375. },
  376. getUserInfo: function (userID, fieldStr, callback) {
  377. var url = "GetMiaoguoWXUserInfo?UserID=" + userID + fieldStr;
  378. main.getData(url, function (data) {
  379. if (data) {
  380. callback(data);
  381. }
  382. });
  383. },
  384. //得到用户关联列表
  385. getUserFamilyInfo: function (userID, callback) {
  386. var that = this;
  387. var url = "GetUserFamily?UserID=" + userID + "&IsWeb=false";
  388. main.getData(url, function (data) {
  389. if (data) {
  390. if (data.length > 0) {
  391. that.setData({
  392. IsShowUserFamily: 1,
  393. UserFamilyNickName: common.getStringMaxLength(app.globalData.userInfo.NickName, 12),
  394. UserFamilyAvatar: app.globalData.userInfo.AvatarUrl,
  395. UserFamily: data,
  396. ChildUserID: app.globalData.userInfo.ChildUserID,
  397. });
  398. app.globalData.FamilyUsers = data;
  399. }
  400. }
  401. });
  402. },
  403. selectPayItem: function (e) {
  404. var that = this;
  405. var id = e.currentTarget.dataset.id;
  406. var list = that.data.PayList;
  407. for (var i = 0; i < list.length; i++) {
  408. if (list[i].TradeNo == id)
  409. list[i].IsSelected = "1";
  410. else
  411. list[i].IsSelected = "";
  412. }
  413. that.setData({
  414. PayList: list,
  415. });
  416. },
  417. setRefund: function () {
  418. var that = this;
  419. var str = "",
  420. TradeNo = "",
  421. Remark = "";
  422. var list = that.data.PayList;
  423. for (var i = 0; i < list.length; i++) {
  424. if (list[i].IsSelected == "1") {
  425. str = '确认给【' + that.data.RefundUserNickName + "】退款 ";
  426. str += list[i].Money + "元,";
  427. str += "交易编号:" + list[i].TradeNo;
  428. TradeNo = list[i].TradeNo;
  429. Remark = that.data.RefundRemark;
  430. break;
  431. }
  432. }
  433. if (!str) {
  434. wx.showToast({
  435. title: '请列表中选择',
  436. });
  437. } else if (!that.data.RefundRemark) {
  438. wx.showToast({
  439. title: '请输入退款备注',
  440. });
  441. } else {
  442. wx.showModal({
  443. title: '退款确认',
  444. showCancel: true,
  445. cancelText: "取消",
  446. content: str,
  447. confirmText: '确认',
  448. success(res) {
  449. if (res.confirm) {
  450. var url = "RefundUser?UserID=" + that.data.RefundUserID + "&TradeNo=" + TradeNo + "&Remark=" + Remark;
  451. main.getData(url, function (data) {
  452. wx.showToast({
  453. title: '退款完成',
  454. });
  455. });
  456. }
  457. }
  458. });
  459. }
  460. },
  461. closeRemind: function () {
  462. this.setData({
  463. IsShowRemind: false,
  464. });
  465. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  466. //判断每30天是否是高级模式
  467. wx.removeStorageSync('IsShowPatternMenu');
  468. },
  469. showUserFamily: function () {
  470. this.setData({
  471. IsShowUserFamily: 2,
  472. });
  473. },
  474. closeUserFamily: function () {
  475. this.setData({
  476. IsShowUserFamily: 1,
  477. });
  478. },
  479. setVersionStart: function (e) {
  480. var flag = e.currentTarget.dataset.flag;
  481. var versionid = e.currentTarget.dataset.versionid;
  482. var url = "UpdateVersionStatus?ProgramID=166&Version=" + versionid + "&Flag=" + flag;
  483. main.getData(url, function (data) {
  484. wx.showToast({
  485. title: '修改成功!',
  486. })
  487. });
  488. },
  489. onShareTimeline: function () {
  490. return this.onShareAppMessage();
  491. },
  492. closeHelp: function () {
  493. this.setData({
  494. IsShowHelp: false,
  495. });
  496. wx.setStorageSync('IsHelpAddInfomation', 0);
  497. },
  498. onShareAppMessage: function () {
  499. if (wx.getStorageSync("IsHelpAddInfomation") == 1) {
  500. return {
  501. title: "题卡制作【加资料】教程",
  502. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID + "&type=helpAddInfomation",
  503. imageUrl: app.globalData.uploadImageUrl + "web/program_screenshot_lesson_a0204.png",
  504. }
  505. } else {
  506. return {
  507. title: app.globalData.ShareTitle,
  508. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  509. imageUrl: app.globalData.ShareImage,
  510. }
  511. }
  512. },
  513. })