index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. //index.js
  2. //获取应用实例
  3. import {
  4. getOpenidSessionKey
  5. } from '../../utils/httpUtil';
  6. import {
  7. formatDate
  8. } from '../../utils/util';
  9. const app = getApp()
  10. import {
  11. hotInit
  12. } from '../../component/hot/hot';
  13. import {
  14. groupInit
  15. } from '../../component/group/group';
  16. import {
  17. myInit
  18. } from '../../component/my/my';
  19. // import {
  20. // followInit
  21. // } from '../../component/follow/follow';
  22. // import '../../utils/hls';
  23. import httpRequestApi from '../../utils/APIClient';
  24. import httputil from '../../utils/httpUtil';
  25. import {
  26. GetQueryString
  27. } from '../../utils/util';
  28. Page({
  29. data: {
  30. tab: [{
  31. name: '我的',
  32. templates: 'my',
  33. },
  34. {
  35. name: '发现',
  36. templates: 'hot',
  37. },
  38. {
  39. name: '热团',
  40. templates: 'group',
  41. },
  42. // {
  43. // name: '动态',
  44. // templates: 'follow',
  45. // },
  46. ],
  47. winH: 568,
  48. myIndex: 1,
  49. followData: [],
  50. recommendPageNo: 0,
  51. recommendTotalNo: 1,
  52. followPageNo: 1,
  53. followPageTotalNo: 1,
  54. myData: {},
  55. templates: 'hot',
  56. title: 'index中的title',
  57. jurisdictionFlag: true,
  58. hotInput: '12345',
  59. mineSettingInfo: '528',
  60. hide: true,
  61. isIOS: app.globalData.isIOS,
  62. ifHaveMore: true,
  63. indexSignDialog: false,
  64. indexMissionDialog: false,
  65. unfinishedCount: 0
  66. },
  67. jurisdiction: function() {
  68. //隐藏弹框
  69. this.setData({
  70. hide: !this.data.hide
  71. })
  72. //登录页信息
  73. this.onShow();
  74. },
  75. //tab点击
  76. switcher: function({
  77. currentTarget
  78. }) {
  79. if (currentTarget.dataset.index === this.data.myIndex) return;
  80. this.updateData(currentTarget.dataset.index);
  81. },
  82. // 根据index 更新template
  83. updateData: function(index) {
  84. let myIndex = index;
  85. let templates = this.data.tab[myIndex].templates;
  86. this.setData({
  87. myIndex,
  88. templates
  89. });
  90. if (myIndex == 0) {
  91. // groupInit(this);
  92. this.setData({
  93. followPageNo: 1,
  94. })
  95. myInit(this);
  96. }
  97. if (myIndex == 1) {
  98. // this.setData({
  99. // recommendPageNo: 0
  100. // })
  101. hotInit(this);
  102. }
  103. if (myIndex == 2) {
  104. groupInit(this);
  105. }
  106. },
  107. onLoad: function(options) {
  108. this.uid = wx.getStorageSync('uid');
  109. wx.getSystemInfo({
  110. success: (res) => {
  111. this.setData({
  112. winH: res.windowHeight
  113. });
  114. }
  115. });
  116. if (options.index) {
  117. this.updateData(options.index)
  118. }
  119. setTimeout(() => {
  120. if (wx.getStorageSync('uid')) {
  121. httpRequestApi.userLoginRecord().success(res => {
  122. if (res.data.data && res.data.data.length !== 0) {
  123. // 有数据弹签到
  124. if (this.data.unfinishedCount > 0) {
  125. this.setData({
  126. indexSignDialog: true
  127. })
  128. }
  129. } else {
  130. // 没数据弹任务
  131. let oldDay = wx.getStorageSync('oldDay');
  132. let newDate = new Date();
  133. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  134. let timeStep = (newDate.getMonth() + 1).toString() + day
  135. if (oldDay) {
  136. let temp = parseInt(timeStep) - parseInt(oldDay)
  137. if (temp > 0) {
  138. wx.setStorageSync('oldDay', timeStep);
  139. this.setData({
  140. indexMissionDialog: true
  141. })
  142. }
  143. } else {
  144. wx.setStorageSync('oldDay', timeStep);
  145. this.setData({
  146. indexMissionDialog: true
  147. })
  148. }
  149. }
  150. })
  151. }
  152. }, 2800)
  153. // hotInit(this)
  154. // this.init();
  155. },
  156. onShow: function() {
  157. wx.setNavigationBarTitle({
  158. title: '小学课文朗读配音'
  159. })
  160. // this.init();
  161. getOpenidSessionKey((res) => {
  162. hotInit(this)
  163. }, (error) => {
  164. // console.log(error)
  165. wx.setStorageSync('userSourseType', 'normal')
  166. this.setData({
  167. hide: !this.data.hide
  168. })
  169. return;
  170. });
  171. if (this.data.myIndex === 0) {
  172. // 从修改信息页面退回
  173. this.getUserWorksInfo(true);
  174. }
  175. },
  176. onHide: function() {
  177. const str = 'hotData.inputFocus'
  178. this.setData({
  179. [str]: false
  180. });
  181. },
  182. //初始化数据
  183. // init: function () {
  184. // httputil.getOpenidSessionKey((res) => {
  185. // console.log('微信的用户信息', res)
  186. // }, (error) => {
  187. // console.log(1111111111111111)
  188. // // this.jurisdiction()
  189. // wx.navigateTo({
  190. // url: '../../loginPage/loginPage'
  191. // })
  192. // });
  193. // },
  194. // 获取用户信息
  195. getUserWorksInfo: function(flag) {
  196. console.log(flag)
  197. if (flag) {
  198. httpRequestApi.getUserWorksInfo().success(res => {
  199. const str = 'myData.user.user.nickName';
  200. this.setData({
  201. [str]: res.data.data.user.nickName
  202. })
  203. })
  204. return;
  205. }
  206. const userLocal = wx.getStorageSync('user')
  207. console.log(userLocal)
  208. const str = 'myData.user';
  209. this.setData({
  210. [str]: userLocal
  211. })
  212. httpRequestApi.getUserWorksInfo().success(res => {
  213. this.data.myData.user = res.data.data;
  214. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  215. if (this.data.myData.user.myRead) {
  216. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  217. }
  218. this.setData({
  219. myData: this.data.myData,
  220. });
  221. }).fail(error => {
  222. console.log(error)
  223. })
  224. },
  225. // 触底加载
  226. onReachBottom: function() {
  227. console.log(this.data.myIndex)
  228. if (this.data.myIndex === 0) {
  229. this.setData({
  230. followPageNo: this.data.followPageNo + 1
  231. })
  232. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  233. this.getFollowWorks(this.data.followPageNo, 3);
  234. } else {
  235. console.log('没有更多')
  236. this.setData({
  237. ifHaveMore: false
  238. })
  239. }
  240. }
  241. // 当前在推荐页面 加载推荐
  242. if (this.data.myIndex === 1) {
  243. console.log(this.data.recommendPageNo)
  244. console.log(this.data.recommendTotalNo)
  245. this.setData({
  246. recommendPageNo: this.data.recommendPageNo + 1
  247. })
  248. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  249. this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  250. } else {
  251. console.log('没有更多')
  252. }
  253. }
  254. },
  255. onPullDownRefresh: function() {
  256. //当前在团购页下拉加载
  257. if (this.data.myIndex === 0) {
  258. // groupInit(this);
  259. }
  260. wx.showNavigationBarLoading() //在标题栏中显示加载
  261. //模拟加载
  262. setTimeout(function() {
  263. wx.hideNavigationBarLoading() //完成停止加载
  264. wx.stopPullDownRefresh() //停止下拉刷新
  265. }, 1500);
  266. },
  267. // 获取全部课本
  268. // getBookList: function () {
  269. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  270. // this.data.bookList = res.data.data.list;
  271. // res.data.data.list.forEach(element => {
  272. // this.data.selectFlag.push(true);
  273. // });
  274. // this.setData({
  275. // bookList: this.data.bookList
  276. // })
  277. // }).fail((error) => {
  278. // console.log('错误', error)
  279. // })
  280. // },
  281. goToMessage: function() {
  282. wx.navigateTo({
  283. url: `../../pages/social/insideMessage/insideMessage`
  284. });
  285. const str = 'hotData.unReadMessageNum';
  286. this.setData({
  287. [str]: 0
  288. })
  289. },
  290. toMyCollage: function(e) {
  291. if (app.globalData.isIOS) {
  292. wx.navigateTo({
  293. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  294. });
  295. } else {
  296. wx.navigateTo({
  297. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  298. });
  299. }
  300. },
  301. toMyCourse: function() {
  302. wx.navigateTo({
  303. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  304. });
  305. },
  306. goToFlower: function() {
  307. wx.navigateTo({
  308. url: `../../pages/social/littleFlower/littleFlower`
  309. });
  310. },
  311. signInBtn: function(e) {
  312. this.setData({
  313. indexSignDialog: false
  314. })
  315. console.log(e.detail.formId)
  316. httpRequestApi.postFormId(e.detail.formId).success(res => {
  317. console.log(res)
  318. })
  319. this.goToFlower();
  320. },
  321. missionBtn: function() {
  322. this.setData({
  323. indexMissionDialog: false
  324. })
  325. this.goToFlower();
  326. }
  327. })