index_20190327153623.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. const avatarStr = 'myData.user.user.avatar';
  201. this.setData({
  202. [str]: res.data.data.user.nickName,
  203. [avatarStr]: res.data.data.user.avatar
  204. })
  205. })
  206. return;
  207. }
  208. const userLocal = wx.getStorageSync('user')
  209. console.log(userLocal)
  210. const str = 'myData.user';
  211. this.setData({
  212. [str]: userLocal
  213. })
  214. httpRequestApi.getUserWorksInfo().success(res => {
  215. this.data.myData.user = res.data.data;
  216. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  217. if (this.data.myData.user.myRead) {
  218. this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  219. }
  220. this.setData({
  221. myData: this.data.myData,
  222. });
  223. }).fail(error => {
  224. console.log(error)
  225. })
  226. },
  227. // 触底加载
  228. onReachBottom: function() {
  229. console.log(this.data.myIndex)
  230. if (this.data.myIndex === 0) {
  231. this.setData({
  232. followPageNo: this.data.followPageNo + 1
  233. })
  234. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  235. this.getFollowWorks(this.data.followPageNo, 3);
  236. } else {
  237. console.log('没有更多')
  238. this.setData({
  239. ifHaveMore: false
  240. })
  241. }
  242. }
  243. // 当前在推荐页面 加载推荐
  244. if (this.data.myIndex === 1) {
  245. console.log(this.data.recommendPageNo)
  246. console.log(this.data.recommendTotalNo)
  247. this.setData({
  248. recommendPageNo: this.data.recommendPageNo + 1
  249. })
  250. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  251. this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  252. } else {
  253. console.log('没有更多')
  254. }
  255. }
  256. },
  257. onPullDownRefresh: function() {
  258. //当前在团购页下拉加载
  259. if (this.data.myIndex === 0) {
  260. // groupInit(this);
  261. }
  262. wx.showNavigationBarLoading() //在标题栏中显示加载
  263. //模拟加载
  264. setTimeout(function() {
  265. wx.hideNavigationBarLoading() //完成停止加载
  266. wx.stopPullDownRefresh() //停止下拉刷新
  267. }, 1500);
  268. },
  269. // 获取全部课本
  270. // getBookList: function () {
  271. // httpRequestApi.getAllBooks(1, 10).success((res) => {
  272. // this.data.bookList = res.data.data.list;
  273. // res.data.data.list.forEach(element => {
  274. // this.data.selectFlag.push(true);
  275. // });
  276. // this.setData({
  277. // bookList: this.data.bookList
  278. // })
  279. // }).fail((error) => {
  280. // console.log('错误', error)
  281. // })
  282. // },
  283. goToMessage: function() {
  284. wx.navigateTo({
  285. url: `../../pages/social/insideMessage/insideMessage`
  286. });
  287. const str = 'hotData.unReadMessageNum';
  288. this.setData({
  289. [str]: 0
  290. })
  291. },
  292. toMyCollage: function(e) {
  293. if (app.globalData.isIOS) {
  294. wx.navigateTo({
  295. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  296. });
  297. } else {
  298. wx.navigateTo({
  299. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  300. });
  301. }
  302. },
  303. toMyCourse: function() {
  304. wx.navigateTo({
  305. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  306. });
  307. },
  308. goToFlower: function() {
  309. wx.navigateTo({
  310. url: `../../pages/social/littleFlower/littleFlower`
  311. });
  312. },
  313. signInBtn: function(e) {
  314. this.setData({
  315. indexSignDialog: false
  316. })
  317. console.log(e.detail.formId)
  318. httpRequestApi.postFormId(e.detail.formId).success(res => {
  319. console.log(res)
  320. })
  321. this.goToFlower();
  322. },
  323. missionBtn: function() {
  324. this.setData({
  325. indexMissionDialog: false
  326. })
  327. this.goToFlower();
  328. }
  329. })