rank.js 2.6 KB

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