index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const $api = require('../../utils/api.js').API;
  5. Page({
  6. data: {
  7. notices:[{}],
  8. tabs:['关注','热门股票','胜率榜','防守榜','冠军心得'],
  9. cur:0,
  10. date:'2021-11-09',
  11. followList:[],
  12. page:1,
  13. total:0
  14. },
  15. onLoad() {
  16. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  17. m = m > 9 ? m : '0' + m;
  18. d = d > 9 ? d : '0' + d;
  19. this.setData({
  20. date: y + '-' + m + '-' + d
  21. })
  22. this.getFollow()
  23. this.getData()
  24. this.getHot()
  25. $api.getNotoice().then(res=>{
  26. this.setData({
  27. notices:res.data.data
  28. })
  29. })
  30. },
  31. //关注分页
  32. next: function () {
  33. if (this.data.followList.length < this.data.total) {
  34. const page = this.data.page + 1
  35. this.setData({
  36. page: page
  37. })
  38. this.getFollow()
  39. }
  40. },
  41. getFollow(){
  42. var followList = this.data.followList
  43. $api.getMyFollow({
  44. page: this.data.page, page_size: 20
  45. }).then(res => {
  46. res.data.data.list.forEach(item=>{
  47. followList.push(item)
  48. })
  49. this.setData({
  50. followList: followList,
  51. total:res.data.data.total
  52. })
  53. })
  54. },
  55. getData(){
  56. //胜率
  57. $api.getRinrate().then(res=>{
  58. this.setData({
  59. winList:res.data.data.list
  60. })
  61. })
  62. //防守
  63. $api.getDefend().then(res => {
  64. this.setData({
  65. defendList: res.data.data.list
  66. })
  67. })
  68. //心得
  69. $api.getChampionlList().then(res => {
  70. this.setData({
  71. championList: res.data.data.list
  72. })
  73. })
  74. },
  75. getHot(){
  76. //热门
  77. let stock_date = this.data.date
  78. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  79. this.setData({
  80. hotbuyList: res.data.data.list
  81. })
  82. })
  83. $api.getHotsellList({ stock_date: stock_date }).then(res => {
  84. this.setData({
  85. hotsellList: res.data.data.list
  86. })
  87. })
  88. },
  89. tabChange(e){
  90. this.setData({
  91. cur:e.target.dataset.id
  92. })
  93. },
  94. //预览
  95. preview(e){
  96. console.log(e)
  97. wx.previewImage({
  98. urls: e.target.dataset.urls,
  99. current: e.target.dataset.src
  100. })
  101. },
  102. curChange(e){
  103. if (e.detail.source == "touch"){
  104. this.setData({
  105. cur: e.detail.current
  106. })
  107. }
  108. },
  109. //热门股票
  110. bindDateChange(e){
  111. this.setData({
  112. date:e.detail.value
  113. })
  114. this.getHot()
  115. }
  116. })