index.js 4.8 KB

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