index.js 4.4 KB

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