default.js 16 KB

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