index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. this.setData({
  62. banners:res.data.data.list
  63. })
  64. })
  65. $api.getWinList({new:1}).then(res=>{
  66. let day = res.data.data[0].valid_dates.indexOf(res.data.data[0].date)
  67. this.setData({
  68. winLost:res.data.data[0],
  69. match_day:day,
  70. })
  71. $api.getAvg({match_id:res.data.data[0].match_id}).then(res=>{
  72. var week=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五']
  73. var days=res.data.data.list,weeks=[[]]
  74. days=days.reverse()
  75. week.forEach((item,index)=>{
  76. weeks[index]={
  77. name:'第'+item+'周',
  78. data:[],
  79. total:0
  80. }
  81. })
  82. var i=0
  83. days.forEach(item=>{
  84. var w=new Date(item.stock_date).getDay()
  85. item.day=w
  86. if(w==1){
  87. i++
  88. }
  89. weeks[i].data.push(item)
  90. })
  91. weeks.forEach(item=>{
  92. if(item.data.length>0){
  93. var total=0
  94. item.data.forEach(i=>{
  95. var incom=Number(i.today_income.replace('%',''))
  96. total+=incom
  97. i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate())
  98. })
  99. item.total=total.toFixed(2)
  100. }
  101. })
  102. this.setData({
  103. days:weeks.reverse()
  104. })
  105. })
  106. $api.getWinLose({match_id:res.data.data[0].match_id}).then(res1=>{
  107. this.setData({
  108. groups:res1.data.data
  109. })
  110. })
  111. })
  112. $api.getBaikeRandom().then(res=>{
  113. this.setData({
  114. baikeList:res.data.data
  115. })
  116. })
  117. $api.getChampionlList({category:'游资专场',page:1}).then(res=>{
  118. this.setData({
  119. articleList1:res.data.data.list
  120. })
  121. })
  122. $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{
  123. this.setData({
  124. articleList2:res.data.data.list
  125. })
  126. })
  127. $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{
  128. this.setData({
  129. articleList3:res.data.data.list
  130. })
  131. })
  132. $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{
  133. this.setData({
  134. articleList4:res.data.data.list
  135. })
  136. })
  137. },
  138. //获取今日留言
  139. getExp:function(){
  140. var list = this.data.explist
  141. $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{
  142. res.data.data.list.forEach(item => {
  143. list.push(item)
  144. })
  145. this.setData({
  146. explist: list,
  147. total1: res.data.data.total
  148. })
  149. })
  150. },
  151. //留言分页
  152. next1: function () {
  153. if (this.data.explist.length < this.data.total1) {
  154. const page = this.data.page1 + 1
  155. this.setData({
  156. page1: page
  157. })
  158. this.getExp()
  159. }
  160. },
  161. //我的关注
  162. getFollow(){
  163. var followList = this.data.followList
  164. if(this.data.loading){
  165. followList=[]
  166. }
  167. $api.getMyFollowV3({
  168. page: this.data.page2, page_size: 20
  169. }).then(res => {
  170. wx.hideNavigationBarLoading()
  171. res.data.data.list.forEach(item => {
  172. followList.push(item)
  173. })
  174. this.setData({
  175. followList: followList,
  176. total2:res.data.data.total,
  177. error:0,
  178. loading: 0
  179. })
  180. app.globalData.follow = 0
  181. })
  182. .catch(err=>{
  183. this.setData({
  184. error:1
  185. })
  186. })
  187. },
  188. //关注分页
  189. next2: function () {
  190. if (this.data.followList.length < this.data.total2) {
  191. const page = this.data.page2 + 1
  192. this.setData({
  193. page2: page
  194. })
  195. this.getFollow()
  196. }
  197. },
  198. tabChange(e){
  199. this.setData({
  200. cur:e.target.dataset.id
  201. })
  202. this.renew()
  203. },
  204. tabChange1(e){
  205. this.setData({
  206. cur1:e.target.dataset.id
  207. })
  208. },
  209. tapGroup(e){
  210. wx.navigateTo({
  211. url: '../avg/avg?index='+e.currentTarget.dataset.index + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  212. })
  213. },
  214. tapAvg(e){
  215. wx.navigateTo({
  216. url: '../avg/avg?index=0' + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  217. })
  218. },
  219. //预览
  220. preview(e){
  221. wx.previewImage({
  222. urls: e.target.dataset.urls,
  223. current: e.target.dataset.src
  224. })
  225. },
  226. curChange(e){
  227. if (e.detail.source == "touch"){
  228. this.setData({
  229. cur: e.detail.current
  230. })
  231. this.renew()
  232. }
  233. },
  234. curChange1(e){
  235. if (e.detail.source == "touch"){
  236. this.setData({
  237. cur1: e.detail.current
  238. })
  239. }
  240. },
  241. renew(){
  242. this.setData({
  243. followList:[],
  244. explist:[],
  245. page1: 1,
  246. total1: 0,
  247. page2: 1,
  248. total2: -1
  249. })
  250. switch(this.data.cur){
  251. case 0:
  252. this.data.page1 = 1
  253. this.getExp()
  254. break;
  255. case 1:
  256. this.data.page2 = 1
  257. this.getFollow()
  258. break;
  259. }
  260. },
  261. pushToday(e){
  262. $push.pushToday(e.currentTarget.dataset)
  263. },
  264. onShow: function (e) {
  265. $api.initUser()
  266. $api.getsignup().then(res => {
  267. this.setData({
  268. info: res.data.data
  269. })
  270. })
  271. if(this.data.cur == 0 && app.globalData.follow == 1){
  272. this.data.loading = 1
  273. this.data.page2 = 1
  274. this.data.total2 = -1,
  275. this.getFollow()
  276. }
  277. },
  278. })