rank.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // pages/rank/rank.js
  2. const $api = require('../../utils/api.js').API;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. datas:{},
  9. date:'',
  10. match:[],
  11. index:0,
  12. match_id:''
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. // var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  19. // m = m > 9 ? m : '0' + m;
  20. // d = d > 9 ? d : '0' + d;
  21. // this.setData({
  22. // date: y + '-' + m + '-' + d
  23. // })
  24. $api.getMatchList().then(res=>{
  25. let l = res.data.data.length - 1;
  26. this.setData({
  27. match:res.data.data,
  28. index: l,
  29. match_id: res.data.data[l].id
  30. })
  31. this.getDate()
  32. })
  33. },
  34. getDate(){
  35. $api.getDate({ match_id: this.data.match_id }).then(res => {
  36. this.setData({
  37. date: res.data.data
  38. })
  39. this.getData()
  40. })
  41. },
  42. getData() {
  43. wx.showNavigationBarLoading()
  44. if (!this.data.match_id){
  45. return
  46. }
  47. $api.getRank({ stock_date: this.data.date, match_id: this.data.match_id}).then(res => {
  48. wx.hideNavigationBarLoading()
  49. this.setData({
  50. datas:res.data.data,
  51. })
  52. })
  53. .catch(err=>{
  54. wx.hideNavigationBarLoading()
  55. })
  56. },
  57. bindChange(e) {
  58. let match=this.data.match;
  59. this.setData({
  60. index: e.detail.value,
  61. match_id: match[e.detail.value].id
  62. })
  63. this.getDate()
  64. },
  65. bindDateChange(e) {
  66. this.setData({
  67. date: e.detail.value
  68. })
  69. this.getData()
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  80. $api.getMyStyle().then(res => {
  81. if (!res.data.data.init_fund) {
  82. wx.navigateTo({
  83. url: '../style/style',
  84. })
  85. }
  86. })
  87. wx.hideNavigationBarLoading()
  88. if (!this.data.datas.groups){
  89. $api.getDate().then(res => {
  90. this.setData({
  91. date: res.data.data
  92. })
  93. this.getData()
  94. })
  95. }
  96. },
  97. /**
  98. * 生命周期函数--监听页面隐藏
  99. */
  100. onHide: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面卸载
  104. */
  105. onUnload: function () {
  106. },
  107. /**
  108. * 页面相关事件处理函数--监听用户下拉动作
  109. */
  110. onPullDownRefresh: function () {
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function () {
  116. },
  117. /**
  118. * 用户点击右上角分享
  119. */
  120. onShareAppMessage: function () {
  121. }
  122. })