rank.js 3.0 KB

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