index.js 5.3 KB

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