index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. error:0
  15. },
  16. onLoad() {
  17. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  18. m = m > 9 ? m : '0' + m;
  19. d = d > 9 ? d : '0' + d;
  20. this.setData({
  21. date: y + '-' + m + '-' + d
  22. })
  23. this.getFollow()
  24. this.getData()
  25. this.getHot()
  26. $api.getNotoice().then(res=>{
  27. this.setData({
  28. notices:res.data.data
  29. })
  30. })
  31. },
  32. //关注分页
  33. next: function () {
  34. if (this.data.followList.length < this.data.total) {
  35. const page = this.data.page + 1
  36. this.setData({
  37. page: page
  38. })
  39. this.getFollow()
  40. }
  41. },
  42. getFollow(){
  43. var followList = this.data.followList
  44. $api.getMyFollow({
  45. page: this.data.page, page_size: 20
  46. }).then(res => {
  47. res.data.data.list.forEach(item=>{
  48. followList.push(item)
  49. })
  50. this.setData({
  51. followList: followList,
  52. total:res.data.data.total,
  53. error:0
  54. })
  55. })
  56. .catch(err=>{
  57. this.setData({
  58. error:1
  59. })
  60. // console.log(err)
  61. })
  62. },
  63. getData(){
  64. //胜率
  65. $api.getRinrate().then(res=>{
  66. this.setData({
  67. winList:res.data.data.list
  68. })
  69. })
  70. //防守
  71. $api.getDefend().then(res => {
  72. this.setData({
  73. defendList: res.data.data.list
  74. })
  75. })
  76. //心得
  77. $api.getChampionlList().then(res => {
  78. this.setData({
  79. championList: res.data.data.list
  80. })
  81. })
  82. },
  83. getHot(){
  84. //热门
  85. let stock_date = this.data.date
  86. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  87. this.setData({
  88. hotbuyList: res.data.data.list
  89. })
  90. })
  91. $api.getHotsellList({ stock_date: stock_date }).then(res => {
  92. this.setData({
  93. hotsellList: res.data.data.list
  94. })
  95. })
  96. },
  97. tabChange(e){
  98. this.setData({
  99. cur:e.target.dataset.id
  100. })
  101. },
  102. //预览
  103. preview(e){
  104. console.log(e)
  105. wx.previewImage({
  106. urls: e.target.dataset.urls,
  107. current: e.target.dataset.src
  108. })
  109. },
  110. curChange(e){
  111. if (e.detail.source == "touch"){
  112. this.setData({
  113. cur: e.detail.current
  114. })
  115. }
  116. },
  117. //热门股票
  118. bindDateChange(e){
  119. this.setData({
  120. date:e.detail.value
  121. })
  122. this.getHot()
  123. },
  124. onShow: function () {
  125. if (this.data.error) {
  126. this.onLoad()
  127. }
  128. },
  129. })