index.js 6.4 KB

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