rank.js 2.8 KB

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