rank.js 3.3 KB

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