index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. IsMemberForeverRemind: 0,
  70. IsMiaoguoAD: false,
  71. IsMiaoguoAD2:0,
  72. IsShowGift:0,
  73. },
  74. onLoad: function (options) {
  75. //app.globalData.userInfo.UserID=5;
  76. this.setData({
  77. Height: common.getSystemHeight(),
  78. ListProgram: server.getProgramListOld(),
  79. IsShowGift:app.globalData.userInfo.IsShowGift,
  80. });
  81. var that = this;
  82. isMiaoguoADShow = false;
  83. },
  84. onShow: function () {
  85. this.setData({
  86. IsLocked: app.globalData.IsLocked,
  87. IsShow: app.globalData.userInfo.IsShow,
  88. IsMember: app.globalData.userInfo.IsMember,
  89. NickName: app.globalData.userInfo.NickName,
  90. AvatarUrl: app.globalData.userInfo.AvatarUrl,
  91. });
  92. if (wx.getStorageSync("HasActivate") == 1) {
  93. wx.navigateTo({
  94. url: '../../package4/main/activate',
  95. });
  96. }
  97. else {
  98. this.getData();
  99. if (app.globalData.goto) {
  100. var url = "../main/list?id=1";
  101. if (app.globalData.goto == "test")
  102. url = '../main/test';
  103. wx.navigateTo({
  104. url: url,
  105. });
  106. app.globalData.goto = "";
  107. }
  108. }
  109. var miaoguoADTime = wx.getStorageSync("miaoguoADTime");
  110. if (miaoguoADTime) {
  111. if (this.data.IsShow == 1 && this.data.IsMember == 1 && isMiaoguoADShow && common.formatTime(new Date()) >= miaoguoADTime) {
  112. this.setData({
  113. IsMiaoguoAD2: 1,
  114. });
  115. }
  116. }
  117. else {
  118. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 1, new Date())));
  119. }
  120. isMiaoguoADShow=true;
  121. if (app.globalData.IsShowMiaoguo){
  122. this.setData({
  123. IsShowMiaoguo:1,
  124. });
  125. app.globalData.IsShowMiaoguo=false;
  126. }
  127. },
  128. getData: function () {
  129. var that = this;
  130. server.getData('GetHanziRecordData?UserID=' + app.globalData.userInfo.UserID + "&Version=" + app.globalData.Version, function (data) {
  131. if (data) {
  132. if (!data.DayNumber)
  133. data.DayNumber = 0;
  134. var finishedCount = 0;
  135. if (data.FinishedList)
  136. finishedCount = data.FinishedList.length;
  137. var reviewCount = 0;
  138. if (data.ReviewList)
  139. reviewCount = data.ReviewList.length;
  140. hanziNumber = 0;
  141. var arr = JSON.parse(wx.getStorageSync("HanziAll"));
  142. for (var k = 0; k < data.FinishedList.length; k++) {
  143. for (var i = 0; i < arr.length; i++) {
  144. var b1 = false;
  145. for (var j = 0; j < arr[i].Units.length; j++) {
  146. var item = arr[i].Units[j];
  147. if (item.ID == data.FinishedList[k].UnitID) {
  148. hanziNumber += item.Words.length;
  149. for (var n = 0; n < item.Words.length; n++) {
  150. for (var l = 0; l < data.ReviewList.length; l++) {
  151. if (data.ReviewList[l].WordID == item.Words[n].ID) {
  152. hanziNumber--;
  153. }
  154. }
  155. }
  156. b1 = true;
  157. break;
  158. }
  159. }
  160. if (b1)
  161. break;
  162. }
  163. }
  164. if (!hanziNumber) {
  165. hanziNumber = 0;
  166. }
  167. that.setData({
  168. IsAccredit:true,
  169. DayNumber: data.DayNumber,
  170. HanziNumber: hanziNumber,
  171. FinishedCount: finishedCount,
  172. ReviewCount: reviewCount,
  173. });
  174. wx.setStorageSync("FinishedList", data.FinishedList);
  175. wx.setStorageSync("ReviewList", data.ReviewList);
  176. }
  177. });
  178. var UnitCustom = wx.getStorageSync("UnitCustom");
  179. if (!UnitCustom) {
  180. var that = this;
  181. server.getData('GetHanziCustomList?UserID=' + app.globalData.userInfo.UserID, function (data) {
  182. if (data && data.length > 0) {
  183. for (var n = 0; n < data.length; n++) {
  184. if (data[n].List)
  185. data[n].List = JSON.parse(data[n].List);
  186. }
  187. wx.setStorageSync("UnitCustom", data);
  188. }
  189. });
  190. }
  191. },
  192. goto: function (e) {
  193. var url = e.currentTarget.dataset.url;
  194. wx.navigateTo({
  195. url: url
  196. });
  197. if (e.currentTarget.dataset.id == "topAD") {
  198. this.setData({
  199. IsMiaoguoAD2: 0,
  200. });
  201. wx.setStorageSync('IsMiaoguoAD', false);
  202. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 15, new Date())));
  203. }
  204. app.globalData.userInfo.IsShowGift=0;
  205. },
  206. gotoSearch: function (e) {
  207. wx.navigateTo({
  208. url: "../main/search",
  209. });
  210. },
  211. gotoReview: function () {
  212. if (this.data.IsShow == 1 && this.data.IsMember == 0) {
  213. wx.navigateTo({
  214. url: '../../package4/main/buyad',
  215. })
  216. }
  217. else {
  218. wx.navigateTo({
  219. url: '../main/review',
  220. });
  221. }
  222. },
  223. gotoTest: function (e) {
  224. wx.navigateTo({
  225. url: '../main/test',
  226. });
  227. },
  228. switchProgram: function (e) {
  229. wx.navigateToMiniProgram({
  230. appId: e.currentTarget.dataset.appid,
  231. path: "pages/index/index?SourceID="+app.globalData.ProgramID,
  232. extraData: {
  233. },
  234. success(res) {
  235. // 打开成功
  236. }
  237. });
  238. },
  239. gotoMemberCenter: function () {
  240. if (app.globalData.userInfo.NickName=="陌生用户" && app.globalData.userInfo.IsShow>0) {
  241. //请去授权
  242. wx.navigateTo({
  243. url: './accredit?type=accredit',
  244. });
  245. }
  246. else if (app.globalData.userInfo.IsShow>0) {
  247. wx.navigateTo({
  248. url: './userinfo',
  249. });
  250. }
  251. },
  252. updateMember: function () {
  253. if (app.globalData.userInfo.UserID == 1) {
  254. if (app.globalData.userInfo.IsMember == 1) {
  255. app.globalData.userInfo.IsMember = 0;
  256. this.setData({
  257. IsMember: false,
  258. });
  259. }
  260. else {
  261. app.globalData.userInfo.IsMember = 1;
  262. this.setData({
  263. IsMember: true,
  264. });
  265. }
  266. }
  267. },
  268. close: function (e) {
  269. this.setData({
  270. IsMiaoguoAD2: 0,
  271. IsShowGift:0,
  272. });
  273. var num=e.currentTarget.dataset.num;
  274. if (num>0){
  275. var time = common.addDate("d", Number(num), new Date());
  276. time = common.formatTime(time);
  277. wx.setStorageSync("miaoguoADTime", time);
  278. }
  279. app.globalData.userInfo.IsShowGift=0;
  280. },
  281. showMiaoguo:function(){
  282. this.setData({
  283. IsShowMiaoguo: 1,
  284. IsMiaoguoAD2: 0,
  285. });
  286. app.globalData.userInfo.IsShowGift=0;
  287. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 15, new Date())));
  288. },
  289. closeMiaoguo:function(){
  290. this.setData({
  291. IsShowMiaoguo: 0,
  292. });
  293. },
  294. onShareAppMessage: function () {
  295. return {
  296. title: app.globalData.ShareTitle,
  297. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  298. imageUrl: app.globalData.ShareImage,
  299. }
  300. },
  301. })