index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //index.js
  2. //获取应用实例
  3. import {
  4. getOpenidSessionKey
  5. } from '../../utils/httpUtil';
  6. const app = getApp()
  7. import {
  8. hotInit
  9. } from '../../component/hot/hot';
  10. import {
  11. groupInit
  12. } from '../../component/group/group';
  13. import {
  14. myInit
  15. } from '../../component/my/my';
  16. import {
  17. followInit
  18. } from '../../component/follow/follow';
  19. // import '../../utils/hls';
  20. import httpRequestApi from '../../utils/APIClient';
  21. import httputil from '../../utils/httpUtil';
  22. Page({
  23. data: {
  24. tab: [{
  25. name: '热团',
  26. templates: 'group',
  27. },
  28. {
  29. name: '推荐',
  30. templates: 'hot',
  31. },
  32. {
  33. name: '关注',
  34. templates: 'follow',
  35. },
  36. {
  37. name: '我的',
  38. templates: 'my',
  39. }
  40. ],
  41. winH: 568,
  42. myIndex: 1,
  43. followData: [],
  44. recommendPageNo: 1,
  45. recommendTotalNo: 0,
  46. followPageNo: 1,
  47. followPageTotalNo: 0,
  48. myData: {},
  49. templates: 'hot',
  50. title: 'index中的title',
  51. jurisdictionFlag: true,
  52. hotInput: '12345',
  53. mineSettingInfo: '528',
  54. hide: true
  55. },
  56. jurisdiction: function () {
  57. //隐藏弹框
  58. this.setData({
  59. hide: !this.data.hide
  60. })
  61. //登录页信息
  62. this.onShow();
  63. },
  64. //tab点击
  65. switcher: function ({
  66. currentTarget
  67. }) {
  68. this.updateData(currentTarget.dataset.index);
  69. },
  70. // 根据index 更新template
  71. updateData: function (index) {
  72. let myIndex = index;
  73. let templates = this.data.tab[myIndex].templates;
  74. this.setData({
  75. myIndex,
  76. templates
  77. });
  78. if (myIndex == 0) {
  79. groupInit(this);
  80. }
  81. if (myIndex == 1) {
  82. this.setData({
  83. recommendPageNo: 1
  84. })
  85. hotInit(this);
  86. }
  87. if (myIndex == 2) {
  88. this.setData({
  89. followPageNo: 1
  90. })
  91. followInit(this);
  92. }
  93. if (myIndex == 3) {
  94. myInit(this);
  95. // getOpenidSessionKey( res => {
  96. // console.log(res);
  97. // }, (error) => {
  98. // this.setData({
  99. // hide: !this.data.hide
  100. // });
  101. // });
  102. }
  103. },
  104. onLoad: function (options) {
  105. console.log(options)
  106. this.uid = wx.getStorageSync('uid');
  107. wx.getSystemInfo({
  108. success: (res) => {
  109. this.setData({
  110. winH: res.windowHeight
  111. });
  112. }
  113. });
  114. if (options.index) {
  115. this.updateData(options.index)
  116. }
  117. hotInit(this)
  118. // this.init();
  119. },
  120. onShow: function () {
  121. // this.init();
  122. getOpenidSessionKey((res) => {}, (error) => {
  123. // console.log(error)
  124. this.setData({
  125. hide: !this.data.hide
  126. })
  127. });
  128. if (this.data.myIndex === 3) {
  129. this.getUserWorksInfo();
  130. }
  131. },
  132. //初始化数据
  133. init: function () {
  134. httputil.getOpenidSessionKey((res) => {
  135. console.log('微信的用户信息', res)
  136. }, (error) => {
  137. console.log(error);
  138. this.jurisdiction()
  139. // this.setData({
  140. // jurisdictionFlag: false
  141. // })
  142. });
  143. },
  144. // 获取用户信息
  145. getUserWorksInfo: function () {
  146. httpRequestApi.getUserWorksInfo().success(res => {
  147. console.log(res)
  148. this.data.myData.user = res.data.data; //直接赋值 给 myData的user对象。
  149. this.setData({
  150. myData: this.data.myData,
  151. });
  152. }).fail(error => {
  153. console.log(error)
  154. })
  155. },
  156. // 触底加载
  157. onReachBottom: function () {
  158. // 当前在推荐页面 加载推荐
  159. if (this.data.myIndex === 1) {
  160. console.log(this.data.recommendPageNo)
  161. this.setData({
  162. recommendPageNo: this.data.recommendPageNo + 1
  163. })
  164. if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  165. this.getHotRecommend(this.uid, this.data.recommendPageNo, 3);
  166. } else {
  167. console.log('没有更多')
  168. }
  169. }
  170. if (this.data.myIndex === 2) {
  171. console.log(this.data.followPageTotalNo)
  172. this.setData({
  173. followPageNo: this.data.followPageNo + 1
  174. })
  175. if (this.data.followPageNo <= this.data.followPageTotalNo) {
  176. this.getWorks(this.uid, this.data.followPageNo, 5);
  177. } else {
  178. console.log('没有更多')
  179. }
  180. }
  181. },
  182. onPullDownRefresh: function () {
  183. //当前在团购页下拉加载
  184. if (this.data.myIndex === 0) {
  185. groupInit(this);
  186. }
  187. wx.startPullDownRefresh();
  188. setTimeout(() => {
  189. wx.stopPullDownRefresh()
  190. },10)
  191. }
  192. })