index.js 4.6 KB

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