index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var interval = 0;
  5. var isPaying = false;
  6. var hanziNumber = 0;
  7. var isMiaoguoADShow=false;
  8. Page({
  9. data: {
  10. Version: app.globalData.Version,
  11. List: [
  12. {
  13. ImageUrl: "home_plate_11.png",
  14. Url: "../main/list?id=1",
  15. },
  16. {
  17. ImageUrl: "home_plate_12.png",
  18. Url: "../main/list?id=2",
  19. },
  20. {
  21. ImageUrl: "home_plate_21.png",
  22. Url: "../main/list?id=3",
  23. },
  24. {
  25. ImageUrl: "home_plate_22.png",
  26. Url: "../main/list?id=4",
  27. },
  28. {
  29. ImageUrl: "home_plate_31.png",
  30. Url: "../main/list?id=5",
  31. },
  32. {
  33. ImageUrl: "home_plate_32.png",
  34. Url: "../main/list?id=6",
  35. },
  36. {
  37. ImageUrl: "home_plate_41.png",
  38. Url: "../main/list?id=7",
  39. },
  40. {
  41. ImageUrl: "home_plate_42.png",
  42. Url: "../main/list?id=8",
  43. },
  44. {
  45. ImageUrl: "home_plate_51.png",
  46. Url: "../main/list?id=9",
  47. },
  48. {
  49. ImageUrl: "home_plate_52.png",
  50. Url: "../main/list?id=10",
  51. },
  52. {
  53. ImageUrl: "home_plate_61.png",
  54. Url: "../main/list?id=11",
  55. },
  56. {
  57. ImageUrl: "home_plate_62.png",
  58. Url: "../main/list?id=12",
  59. },
  60. ],
  61. NickName: "陌生用户",
  62. IsMember: 1,
  63. NewUserNumber: 2,
  64. AvatarUrl: "",
  65. DayNumber: "0",
  66. ReviewCount: "0",
  67. FinishedCount: "0",
  68. IsAccredit: false,
  69. IsRemind: false,
  70. IsMemberForeverRemind: 0,
  71. IsMiaoguoAD: false,
  72. IsMiaoguoAD2:0,
  73. IsShowGift:0,
  74. },
  75. onLoad: function (options) {
  76. //app.globalData.userInfo.UserID=5;
  77. this.setData({
  78. Height: common.getSystemHeight(),
  79. ListProgram: server.getProgramListOld(),
  80. IsShowGift:app.globalData.userInfo.IsShowGift,
  81. });
  82. var that = this;
  83. isMiaoguoADShow = false;
  84. },
  85. onShow: function () {
  86. this.setData({
  87. IsLocked: app.globalData.IsLocked,
  88. IsShow: app.globalData.userInfo.IsShow,
  89. IsMember: app.globalData.userInfo.IsMember,
  90. NickName: app.globalData.userInfo.NickName,
  91. AvatarUrl: app.globalData.userInfo.AvatarUrl,
  92. });
  93. if (app.globalData.userInfo.NickName=="陌生用户" && app.globalData.userInfo.IsShow>0) {
  94. this.setData({
  95. IsRemind:true,
  96. });
  97. }
  98. else{
  99. this.setData({
  100. IsRemind:false,
  101. });
  102. }
  103. if (wx.getStorageSync("HasActivate") == 1) {
  104. wx.navigateTo({
  105. url: '../../package4/main/activate',
  106. });
  107. }
  108. else {
  109. this.getData();
  110. if (app.globalData.goto) {
  111. var url = "../main/list?id=1";
  112. if (app.globalData.goto == "test")
  113. url = '../main/test';
  114. wx.navigateTo({
  115. url: url,
  116. });
  117. app.globalData.goto = "";
  118. }
  119. }
  120. var miaoguoADTime = wx.getStorageSync("miaoguoADTime");
  121. if (miaoguoADTime) {
  122. if (this.data.IsShow == 1 && this.data.IsMember == 1 && isMiaoguoADShow && common.formatTime(new Date()) >= miaoguoADTime) {
  123. this.setData({
  124. IsMiaoguoAD2: 1,
  125. });
  126. }
  127. }
  128. else {
  129. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 1, new Date())));
  130. }
  131. isMiaoguoADShow=true;
  132. if (app.globalData.IsShowMiaoguo){
  133. this.setData({
  134. IsShowMiaoguo:1,
  135. });
  136. app.globalData.IsShowMiaoguo=false;
  137. }
  138. },
  139. getData: function () {
  140. var that = this;
  141. server.getData('GetHanziRecordData?UserID=' + app.globalData.userInfo.UserID + "&Version=" + app.globalData.Version, function (data) {
  142. if (data) {
  143. if (!data.DayNumber)
  144. data.DayNumber = 0;
  145. var finishedCount = 0;
  146. if (data.FinishedList)
  147. finishedCount = data.FinishedList.length;
  148. var reviewCount = 0;
  149. if (data.ReviewList)
  150. reviewCount = data.ReviewList.length;
  151. hanziNumber = 0;
  152. var arr = JSON.parse(wx.getStorageSync("HanziAll"));
  153. for (var k = 0; k < data.FinishedList.length; k++) {
  154. for (var i = 0; i < arr.length; i++) {
  155. var b1 = false;
  156. for (var j = 0; j < arr[i].Units.length; j++) {
  157. var item = arr[i].Units[j];
  158. if (item.ID == data.FinishedList[k].UnitID) {
  159. hanziNumber += item.Words.length;
  160. for (var n = 0; n < item.Words.length; n++) {
  161. for (var l = 0; l < data.ReviewList.length; l++) {
  162. if (data.ReviewList[l].WordID == item.Words[n].ID) {
  163. hanziNumber--;
  164. }
  165. }
  166. }
  167. b1 = true;
  168. break;
  169. }
  170. }
  171. if (b1)
  172. break;
  173. }
  174. }
  175. if (!hanziNumber) {
  176. hanziNumber = 0;
  177. }
  178. that.setData({
  179. IsAccredit:true,
  180. DayNumber: data.DayNumber,
  181. HanziNumber: hanziNumber,
  182. FinishedCount: finishedCount,
  183. ReviewCount: reviewCount,
  184. });
  185. wx.setStorageSync("FinishedList", data.FinishedList);
  186. wx.setStorageSync("ReviewList", data.ReviewList);
  187. }
  188. });
  189. var UnitCustom = wx.getStorageSync("UnitCustom");
  190. if (!UnitCustom) {
  191. var that = this;
  192. server.getData('GetHanziCustomList?UserID=' + app.globalData.userInfo.UserID, function (data) {
  193. if (data && data.length > 0) {
  194. for (var n = 0; n < data.length; n++) {
  195. if (data[n].List)
  196. data[n].List = JSON.parse(data[n].List);
  197. }
  198. wx.setStorageSync("UnitCustom", data);
  199. }
  200. });
  201. }
  202. },
  203. goto: function (e) {
  204. var url = e.currentTarget.dataset.url;
  205. wx.navigateTo({
  206. url: url
  207. });
  208. if (e.currentTarget.dataset.id == "topAD") {
  209. this.setData({
  210. IsMiaoguoAD2: 0,
  211. });
  212. wx.setStorageSync('IsMiaoguoAD', false);
  213. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 15, new Date())));
  214. }
  215. app.globalData.userInfo.IsShowGift=0;
  216. },
  217. gotoSearch: function (e) {
  218. wx.navigateTo({
  219. url: "../main/search",
  220. });
  221. },
  222. gotoReview: function () {
  223. if (this.data.IsShow == 1 && this.data.IsMember == 0) {
  224. wx.navigateTo({
  225. url: '../../package4/main/buyad',
  226. })
  227. }
  228. else {
  229. wx.navigateTo({
  230. url: '../main/review',
  231. });
  232. }
  233. },
  234. gotoTest: function (e) {
  235. wx.navigateTo({
  236. url: '../main/test',
  237. });
  238. },
  239. switchProgram: function (e) {
  240. wx.navigateToMiniProgram({
  241. appId: e.currentTarget.dataset.appid,
  242. path: "pages/index/index?SourceID="+app.globalData.ProgramID,
  243. extraData: {
  244. },
  245. success(res) {
  246. // 打开成功
  247. }
  248. });
  249. },
  250. gotoMemberCenter: function () {
  251. if (app.globalData.userInfo.NickName=="陌生用户" && app.globalData.userInfo.IsShow>0) {
  252. //请去授权
  253. wx.navigateTo({
  254. url: './accredit?type=accredit',
  255. });
  256. }
  257. else if (app.globalData.userInfo.IsShow>0) {
  258. wx.navigateTo({
  259. url: './userinfo',
  260. });
  261. }
  262. },
  263. updateMember: function () {
  264. if (app.globalData.userInfo.UserID == 1) {
  265. if (app.globalData.userInfo.IsMember == 1) {
  266. app.globalData.userInfo.IsMember = 0;
  267. this.setData({
  268. IsMember: false,
  269. });
  270. }
  271. else {
  272. app.globalData.userInfo.IsMember = 1;
  273. this.setData({
  274. IsMember: true,
  275. });
  276. }
  277. }
  278. },
  279. close: function (e) {
  280. this.setData({
  281. IsMiaoguoAD2: 0,
  282. IsShowGift:0,
  283. });
  284. var num=e.currentTarget.dataset.num;
  285. if (num>0){
  286. var time = common.addDate("d", Number(num), new Date());
  287. time = common.formatTime(time);
  288. wx.setStorageSync("miaoguoADTime", time);
  289. }
  290. app.globalData.userInfo.IsShowGift=0;
  291. },
  292. showMiaoguo:function(){
  293. this.setData({
  294. IsShowMiaoguo: 1,
  295. IsMiaoguoAD2: 0,
  296. });
  297. app.globalData.userInfo.IsShowGift=0;
  298. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 15, new Date())));
  299. },
  300. closeMiaoguo:function(){
  301. this.setData({
  302. IsShowMiaoguo: 0,
  303. });
  304. },
  305. onShareAppMessage: function () {
  306. return {
  307. title: app.globalData.ShareTitle,
  308. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  309. imageUrl: app.globalData.ShareImage,
  310. }
  311. },
  312. })