default.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var canPress=true;//按钮按下有反应
  5. Page({
  6. data: {
  7. IsTempCardNoSaved: false,
  8. IsExit: false,
  9. DayNumber: 0,
  10. TodayTaskNumber: 0,
  11. IsStart: 0,
  12. IsMaintain: 0,
  13. IsIPhoneX: app.globalData.IsIPhoneX,
  14. ImagePath: app.globalData.uploadImageUrl,
  15. IsShowUserID: false,
  16. VersionID: app.globalData.Version,
  17. AwardDayNumber: 0,
  18. IsShowRemind: false,
  19. IsShowHelp: false,
  20. IsShowUserFamily: 0,
  21. ChildUserID:false,
  22. },
  23. onPullDownRefresh: function () {
  24. wx.redirectTo({
  25. url: '../main/default',
  26. })
  27. wx.stopPullDownRefresh();
  28. },
  29. onLoad: function (options) {
  30. var that = this;
  31. that.setData({
  32. ChildUserID:false,
  33. Containnerheight: main.getWindowHeight(),
  34. });
  35. if (app.globalData.IsIPad) {
  36. that.setData({
  37. IsIPad: "_iPad",
  38. });
  39. }
  40. wx.showShareMenu({
  41. withShareTicket: true,
  42. menus: ['shareAppMessage', 'shareTimeline']
  43. });
  44. canPress=true;
  45. that.getUserFamilyInfo(app.globalData.userInfo.UserID, function (data) {});
  46. },
  47. onHide: function () {
  48. wx.hideLoading();
  49. canPress=true;
  50. },
  51. onShow: function () {
  52. var that = this;
  53. if (app.globalData.userInfo.IsNewUser && app.globalData.userInfo.IsNewUser == 1 && app.globalData.userInfo.IsShow == 1) {
  54. if (app.globalData.userInfo.Subscribe == 0) {
  55. wx.navigateTo({
  56. url: '../other/newuser',
  57. });
  58. }
  59. } else {
  60. wx.getSetting({
  61. success(res) {
  62. if (app.globalData.userInfo.NickName == "陌生用户" && app.globalData.userInfo.IsMember == 1 && app.globalData.userInfo.IsShow == 1) {
  63. wx.navigateTo({
  64. url: '../index/accredit',
  65. });
  66. } else {
  67. if (!app.globalData.userInfo.IsTryOut && app.globalData.userInfo.IsShow == 1) {
  68. if (app.globalData.userInfo.Subscribe == 1) {
  69. wx.navigateTo({
  70. url: '../other/userbook',
  71. });
  72. app.globalData.GotoUrl = "";
  73. } else {
  74. wx.redirectTo({
  75. url: '../other/newuser',
  76. });
  77. }
  78. } else if (app.globalData.userInfo.IsTryOut && app.globalData.userInfo.IsShow == 1) {
  79. if (app.globalData.GotoUrl.indexOf("../other/pay?PayType=6") >= 0) {
  80. wx.navigateTo({
  81. url: app.globalData.GotoUrl,
  82. });
  83. app.globalData.GotoUrl = "";
  84. } else {
  85. var productServiceTime = common.formatDateCHS(common.formatTime(new Date(app.globalData.userInfo.ProductServiceTime)));
  86. var today = common.formatDateCHS(common.formatTime(new Date()));
  87. if (productServiceTime < today) {
  88. wx.redirectTo({
  89. url: '../other/userbook',
  90. });
  91. } else if (app.globalData.GotoUrl) {
  92. //console.log(app.globalData.GotoUrl);
  93. wx.navigateTo({
  94. url: app.globalData.GotoUrl,
  95. });
  96. app.globalData.GotoUrl = "";
  97. }
  98. }
  99. } else if (app.globalData.userInfo.IsShow == 0) {
  100. var url = 'SetGrade?UserID=' + app.globalData.userInfo.UserID+'&Grade=1';
  101. main.getData(url, function (data) {});
  102. }
  103. that.setData({
  104. IsAccredit: true,
  105. });
  106. that.init();
  107. that.getTaskTodayList();
  108. that.isNoSavedCard();
  109. if (res.authSetting['scope.record'] === true) {
  110. app.globalData.IsRecorderAccredit = 1;
  111. } else if (res.authSetting['scope.record'] === false) {
  112. app.globalData.IsRecorderAccredit = -1;
  113. }
  114. }
  115. }
  116. });
  117. }
  118. app.globalData.TempStr2 = null;
  119. wx.setNavigationBarColor({
  120. frontColor: "#ffffff",
  121. backgroundColor: "#3157BA",
  122. });
  123. if (wx.getStorageSync("IsHelpAddInfomation") == 1) {
  124. that.setData({
  125. IsShowHelp: true,
  126. });
  127. main.ShowHelp(that, "#btnAdd", "up", "点击下方“添加题卡”按钮");
  128. } else {
  129. that.setData({
  130. IsShowHelp: false,
  131. });
  132. }
  133. },
  134. init: function () {
  135. //显示练习模式
  136. var cardType = wx.getStorageSync("CardType");
  137. if (!cardType)
  138. cardType = 0;
  139. this.setData({
  140. CardType: cardType,
  141. });
  142. //题卡主题色
  143. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  144. if (!arrColorIndex) {
  145. app.globalData.ColorIndex = common.random(1, 4);
  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. //console.log("canPress:"+canPress);
  166. if (canPress){
  167. var url = e.currentTarget.dataset.url;
  168. wx.navigateTo({
  169. url: url,
  170. });
  171. if (url == "../../pages_agent/marketing/index") {
  172. this.setData({
  173. IsShowRemind: false,
  174. });
  175. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  176. }
  177. if (url == "../plan/studyplan" && this.data.DayNumber <= app.globalData.IsShowSettingRemind) {
  178. wx.setStorageSync('IsShowSettingRemind', this.data.DayNumber);
  179. }
  180. canPress=false;
  181. //console.log("canPress:"+canPress);
  182. setTimeout(function(){
  183. canPress=true;
  184. //console.log("canPress:"+canPress);
  185. },2000);
  186. }
  187. },
  188. //得到当天任务
  189. getTaskTodayList: function () {
  190. var that = this;
  191. main.UpdateMiaoguoCardTodayAll(true, function () {
  192. main.getTaskTodayList(function (data) {
  193. if (data.IsMaintain == 1) {
  194. that.setData({
  195. IsMaintain: 1,
  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. //是否显示提示任务量设置
  205. if (that.data.DayNumber <= app.globalData.IsShowSettingRemind) {
  206. var IsShowSettingRemind = wx.getStorageSync("IsShowSettingRemind");
  207. if (!IsShowSettingRemind || IsShowSettingRemind < that.data.DayNumber) {
  208. that.setData({
  209. IsShowSettingRemind: 1,
  210. });
  211. } else {
  212. that.setData({
  213. IsShowSettingRemind: 0,
  214. });
  215. }
  216. }
  217. //判断是否出现推广广告
  218. common.getStorageValue(that, "IsShowMarketingTime", "2020-01-01 00:00:00", function () {
  219. if (that.data.IsShowMarketingTime < common.formatTime(new Date())) {
  220. main.getAwardData(function (data) {
  221. var award = data.Total - data.AwardDayNumber
  222. that.setData({
  223. IsShowRemind: true,
  224. AwardDayNumber: award,
  225. });
  226. });
  227. } else {
  228. if (app.globalData.MemoryLevel == 0 && data.DayNumber >= 8) {
  229. var IsShowPatternMenu = wx.getStorageSync("IsShowPatternMenu");
  230. if (!IsShowPatternMenu) {
  231. wx.navigateTo({
  232. url: '../other/menu?Type=1',
  233. });
  234. wx.setStorageSync('IsShowPatternMenu', 1);
  235. }
  236. }
  237. }
  238. });
  239. }
  240. });
  241. });
  242. },
  243. isNoSavedCard: function () {
  244. var that = this;
  245. //判断是否有系统故障
  246. if (app.globalData.userInfo.IsMaintain == 1) {
  247. that.setData({
  248. IsMaintain: app.globalData.userInfo.IsMaintain,
  249. });
  250. wx.setNavigationBarColor({
  251. frontColor: "#ffffff",
  252. backgroundColor: "#0B8457",
  253. })
  254. }
  255. //判断是否有未保存的卡
  256. else if (wx.getStorageSync("TempCardNoSaved")) {
  257. wx.navigateTo({
  258. url: '../other/recover',
  259. });
  260. } else {
  261. that.setData({
  262. IsTempCardNoSaved: false,
  263. });
  264. wx.setNavigationBarColor({
  265. frontColor: "#ffffff",
  266. backgroundColor: "#3157BA",
  267. });
  268. }
  269. },
  270. gotoReLaunch: function (e) {
  271. var url = e.currentTarget.dataset.url;
  272. wx.reLaunch({
  273. url: url,
  274. });
  275. },
  276. showUserID: function () {
  277. var that = this;
  278. if (app.globalData.userInfo.UserID == 1 ||
  279. app.globalData.userInfo.UserID == 3 ||
  280. app.globalData.userInfo.UserID == 4) {
  281. var userid = 2;
  282. if (app.globalData.userInfo.UserID >= 3)
  283. userid = app.globalData.userInfo.UserID;
  284. that.setData({
  285. IsShowUserID: true,
  286. ChangeUserID: userid,
  287. });
  288. }
  289. },
  290. onKeyInput: function (e) {
  291. var id = e.detail.value;
  292. var usertype = e.currentTarget.dataset.type;
  293. var that = this;
  294. if (usertype == "userid") {
  295. that.setData({
  296. ChangeUserID: id,
  297. });
  298. } else if (usertype == "newuserid") {
  299. that.setData({
  300. ChangeNewUserID: id,
  301. });
  302. } else if (usertype == "introduceruserid") {
  303. that.setData({
  304. ChangeIntroducerUserID: id,
  305. });
  306. } else if (usertype == "versionid") {
  307. that.setData({
  308. VersoinID: id,
  309. });
  310. } else if (usertype == "groupuserid") {
  311. that.setData({
  312. ChangeGroupUserID: id,
  313. });
  314. } else if (usertype == "refunduserid") {
  315. that.setData({
  316. RefundUserID: id,
  317. });
  318. } else if (usertype == "refundremark") {
  319. that.setData({
  320. RefundRemark: id,
  321. });
  322. }
  323. },
  324. setSelectUser: function (e) {
  325. var that = this;
  326. if (app.globalData.userInfo.UserID == 1 ||
  327. app.globalData.userInfo.UserID == 2 ||
  328. app.globalData.userInfo.UserID == 3 ||
  329. app.globalData.userInfo.UserID == 4) {
  330. var userid = that.data.ChangeUserID;
  331. wx.setStorageSync("UserID", userid);
  332. app.globalData.userInfo.UserID = userid;
  333. var fieldStr = "";
  334. that.getUserInfo(userid, fieldStr, function (data) {
  335. wx.setNavigationBarTitle({
  336. title: data.NickName
  337. });
  338. main.getUserConfig();
  339. app.globalData.userInfo.ProductServiceTime = data.ProductServiceTime;
  340. if (app.globalData.userInfo.UserID != 2) {
  341. app.globalData.userInfo.NickName = data.NickName;
  342. app.globalData.userInfo.AvatarUrl = data.AvatarUrl;
  343. }
  344. if (data.IsPromoter > 0) {
  345. app.globalData.userInfo.IsPromoter = data.IsPromoter;
  346. app.globalData.userInfo.PromotionLimitDays = data.PromotionLimitDays;
  347. app.globalData.userInfo.PromotionLimitTime = data.PromotionLimitTime;
  348. app.globalData.userInfo.WXServiceCharge = data.WXServiceCharge;
  349. app.globalData.userInfo.IndividualIncomeTax = data.IndividualIncomeTax;
  350. app.globalData.userInfo.WXAccount = data.WXAccount;
  351. app.globalData.userInfo.RealName = data.RealName;
  352. app.globalData.userInfo.IntroducerNickName = data.IntroducerNickName;
  353. app.globalData.userInfo.IntroducerAvatarUrl = data.IntroducerAvatarUrl;
  354. }
  355. that.getUserFamilyInfo(app.globalData.userInfo.UserID, function (data) {});
  356. });
  357. that.setData({
  358. IsShowUserID: false,
  359. });
  360. that.onShow();
  361. }
  362. },
  363. getUserInfoFunction: function (e) {
  364. var that = this;
  365. var userid = e.currentTarget.dataset.id;
  366. var type1 = e.currentTarget.dataset.type;
  367. var fieldStr = "&FieldStr=NickName,AvatarUrl";
  368. if (userid) {
  369. that.getUserInfo(userid, fieldStr, function (data) {
  370. if (type1 == 3) {
  371. that.setData({
  372. RefundUserAvatar: data.AvatarUrl,
  373. RefundUserNickName: data.NickName,
  374. });
  375. var url = "GetUserPayList?UserID=" + userid;
  376. main.getData(url, function (data) {
  377. if (data) {
  378. that.setData({
  379. PayList: data,
  380. });
  381. }
  382. });
  383. }
  384. });
  385. }
  386. },
  387. getUserInfo: function (userID, fieldStr, callback) {
  388. var url = "GetMiaoguoWXUserInfo?UserID=" + userID + fieldStr;
  389. main.getData(url, function (data) {
  390. if (data) {
  391. callback(data);
  392. }
  393. });
  394. },
  395. //得到用户关联列表
  396. getUserFamilyInfo: function (userID, callback) {
  397. var that = this;
  398. var url = "GetUserFamily?UserID=" + userID + "&IsWeb=false";
  399. main.getData(url, function (data) {
  400. if (data) {
  401. if (data.length > 0) {
  402. that.setData({
  403. IsShowUserFamily: 1,
  404. UserFamilyNickName: common.getStringMaxLength(app.globalData.userInfo.NickName, 12),
  405. UserFamilyAvatar: app.globalData.userInfo.AvatarUrl,
  406. UserFamily: data,
  407. });
  408. if (app.globalData.userInfo.ChildUserID){
  409. that.setData({
  410. ChildUserID: app.globalData.userInfo.ChildUserID,
  411. });
  412. }
  413. app.globalData.FamilyUsers = data;
  414. }
  415. }
  416. });
  417. },
  418. selectPayItem: function (e) {
  419. var that = this;
  420. var id = e.currentTarget.dataset.id;
  421. var list = that.data.PayList;
  422. for (var i = 0; i < list.length; i++) {
  423. if (list[i].TradeNo == id)
  424. list[i].IsSelected = "1";
  425. else
  426. list[i].IsSelected = "";
  427. }
  428. that.setData({
  429. PayList: list,
  430. });
  431. },
  432. setRefund: function () {
  433. var that = this;
  434. var str = "",
  435. TradeNo = "",
  436. Remark = "";
  437. var list = that.data.PayList;
  438. for (var i = 0; i < list.length; i++) {
  439. if (list[i].IsSelected == "1") {
  440. str = '确认给【' + that.data.RefundUserNickName + "】退款 ";
  441. str += list[i].Money + "元,";
  442. str += "交易编号:" + list[i].TradeNo;
  443. TradeNo = list[i].TradeNo;
  444. Remark = that.data.RefundRemark;
  445. break;
  446. }
  447. }
  448. if (!str) {
  449. wx.showToast({
  450. title: '请列表中选择',
  451. });
  452. } else if (!that.data.RefundRemark) {
  453. wx.showToast({
  454. title: '请输入退款备注',
  455. });
  456. } else {
  457. wx.showModal({
  458. title: '退款确认',
  459. showCancel: true,
  460. cancelText: "取消",
  461. content: str,
  462. confirmText: '确认',
  463. success(res) {
  464. if (res.confirm) {
  465. var url = "RefundUser?UserID=" + that.data.RefundUserID + "&TradeNo=" + TradeNo + "&Remark=" + Remark;
  466. main.getData(url, function (data) {
  467. wx.showToast({
  468. title: '退款完成',
  469. });
  470. });
  471. }
  472. }
  473. });
  474. }
  475. },
  476. closeRemind: function () {
  477. this.setData({
  478. IsShowRemind: false,
  479. });
  480. wx.setStorageSync("IsShowMarketingTime", common.formatTime(common.addDate("d", 30, new Date())));
  481. //判断每30天是否是高级模式
  482. wx.removeStorageSync('IsShowPatternMenu');
  483. },
  484. showUserFamily: function () {
  485. this.setData({
  486. IsShowUserFamily: 2,
  487. });
  488. },
  489. closeUserFamily: function () {
  490. this.setData({
  491. IsShowUserFamily: 1,
  492. });
  493. },
  494. setVersionStart: function (e) {
  495. var flag = e.currentTarget.dataset.flag;
  496. var versionid = e.currentTarget.dataset.versionid;
  497. var url = "UpdateVersionStatus?ProgramID=166&Version=" + versionid + "&Flag=" + flag;
  498. main.getData(url, function (data) {
  499. wx.showToast({
  500. title: '修改成功!',
  501. })
  502. });
  503. },
  504. onShareTimeline: function () {
  505. return this.onShareAppMessage();
  506. },
  507. closeHelp: function () {
  508. this.setData({
  509. IsShowHelp: false,
  510. });
  511. wx.setStorageSync('IsHelpAddInfomation', 0);
  512. },
  513. onShareAppMessage: function () {
  514. if (wx.getStorageSync("IsHelpAddInfomation") == 1) {
  515. return {
  516. title: "题卡制作【加资料】教程",
  517. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID + "&type=helpAddInfomation",
  518. imageUrl: app.globalData.uploadImageUrl + "web/program_screenshot_lesson_a0204.png",
  519. }
  520. } else {
  521. return {
  522. title: app.globalData.ShareTitle,
  523. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  524. imageUrl: app.globalData.ShareImage,
  525. }
  526. }
  527. },
  528. })