index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const $api = require('../../utils/api.js').API;
  5. const $push = require('../../utils/api.js').PUSH;
  6. Page({
  7. data: {
  8. loading:0,
  9. notices:[],
  10. tabs:['今日留言','我的关注'],
  11. cur:0,
  12. date:'2022-04-27',
  13. explist:[], //留言
  14. total1:0,
  15. page1:1,
  16. followList:[], //关注
  17. total2:-1,
  18. page2:1,
  19. banners:[],
  20. winLost:{},
  21. baikeList:[],
  22. articleList1:[],
  23. articleList2:[],
  24. articleList3:[],
  25. articleList4:[],
  26. role:0,
  27. },
  28. onLoad() {
  29. wx.showNavigationBarLoading()
  30. wx.getStorage({
  31. key: 'user',
  32. complete: res => {
  33. this.setData({
  34. role: res.data.role,
  35. })
  36. }
  37. })
  38. $api.getDate().then(res=>{
  39. this.setData({
  40. date:res.data.data
  41. })
  42. $api.getNotoice().then(res=>{
  43. this.setData({
  44. notices:res.data.data
  45. })
  46. })
  47. })
  48. this.getFollow()
  49. this.getIndexData()
  50. this.getExp()
  51. },
  52. fresh: function () {
  53. },
  54. // 获取首页数据
  55. getIndexData:function(){
  56. $api.getChampionlList({isbanner:1}).then(res=>{
  57. console.log(res)
  58. this.setData({
  59. banners:res.data.data.list
  60. })
  61. })
  62. $api.getWinList({new:1}).then(res=>{
  63. this.setData({
  64. winLost:res.data.data[0]
  65. })
  66. })
  67. $api.getBaikeRandom().then(res=>{
  68. this.setData({
  69. baikeList:res.data.data
  70. })
  71. })
  72. $api.getChampionlList({category:'游资专场',page:1}).then(res=>{
  73. this.setData({
  74. articleList1:res.data.data.list
  75. })
  76. })
  77. $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{
  78. this.setData({
  79. articleList2:res.data.data.list
  80. })
  81. })
  82. $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{
  83. this.setData({
  84. articleList3:res.data.data.list
  85. })
  86. })
  87. $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{
  88. this.setData({
  89. articleList4:res.data.data.list
  90. })
  91. })
  92. },
  93. //获取今日留言
  94. getExp:function(){
  95. var list = this.data.explist
  96. $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{
  97. res.data.data.list.forEach(item => {
  98. list.push(item)
  99. })
  100. this.setData({
  101. explist: list,
  102. total1: res.data.data.total
  103. })
  104. })
  105. },
  106. //留言分页
  107. next1: function () {
  108. if (this.data.explist.length < this.data.total1) {
  109. const page = this.data.page1 + 1
  110. this.setData({
  111. page1: page
  112. })
  113. this.getExp()
  114. }
  115. },
  116. //我的关注
  117. getFollow(){
  118. var followList = this.data.followList
  119. if(this.data.loading){
  120. followList=[]
  121. }
  122. $api.getMyFollowV3({
  123. page: this.data.page2, page_size: 20
  124. }).then(res => {
  125. wx.hideNavigationBarLoading()
  126. res.data.data.list.forEach(item => {
  127. followList.push(item)
  128. })
  129. this.setData({
  130. followList: followList,
  131. total2:res.data.data.total,
  132. error:0,
  133. loading: 0
  134. })
  135. app.globalData.follow = 0
  136. })
  137. .catch(err=>{
  138. this.setData({
  139. error:1
  140. })
  141. })
  142. },
  143. //关注分页
  144. next2: function () {
  145. if (this.data.followList.length < this.data.total2) {
  146. const page = this.data.page2 + 1
  147. this.setData({
  148. page2: page
  149. })
  150. this.getFollow()
  151. }
  152. },
  153. tabChange(e){
  154. this.setData({
  155. cur:e.target.dataset.id
  156. })
  157. this.renew()
  158. },
  159. //预览
  160. preview(e){
  161. wx.previewImage({
  162. urls: e.target.dataset.urls,
  163. current: e.target.dataset.src
  164. })
  165. },
  166. curChange(e){
  167. if (e.detail.source == "touch"){
  168. this.setData({
  169. cur: e.detail.current
  170. })
  171. this.renew()
  172. }
  173. },
  174. renew(){
  175. this.setData({
  176. followList:[],
  177. explist:[],
  178. page1: 1,
  179. total1: 0,
  180. page2: 1,
  181. total2: -1
  182. })
  183. switch(this.data.cur){
  184. case 0:
  185. this.data.page1 = 1
  186. this.getExp()
  187. break;
  188. case 1:
  189. this.data.page2 = 1
  190. this.getFollow()
  191. break;
  192. }
  193. },
  194. pushToday(e){
  195. $push.pushToday(e.currentTarget.dataset)
  196. },
  197. onShow: function (e) {
  198. $api.initUser()
  199. $api.getsignup().then(res => {
  200. this.setData({
  201. info: res.data.data
  202. })
  203. })
  204. if(this.data.cur == 0 && app.globalData.follow == 1){
  205. this.data.loading = 1
  206. this.data.page2 = 1
  207. this.data.total2 = -1,
  208. this.getFollow()
  209. }
  210. },
  211. })