index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const $api = require('../../utils/api.js').API;
  5. Page({
  6. data: {
  7. notices:[],
  8. tabs:['关注','热门股票','胜率榜','防守榜','冠军心得'],
  9. cur:0,
  10. date:'2021-11-09',
  11. followList:[],
  12. defendList:[],
  13. winList:[],
  14. page:1,
  15. total:0,
  16. page1: 1,
  17. total1: 0,
  18. page2: 1,
  19. total2: 0,
  20. error:0
  21. },
  22. onLoad() {
  23. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  24. m = m > 9 ? m : '0' + m;
  25. d = d > 9 ? d : '0' + d;
  26. this.setData({
  27. date: y + '-' + m + '-' + d
  28. })
  29. this.getFollow()
  30. this.getData()
  31. this.getWin()
  32. this.getDefen()
  33. $api.getNotoice().then(res=>{
  34. this.setData({
  35. notices:res.data.data
  36. })
  37. })
  38. },
  39. //关注分页
  40. next: function () {
  41. if (this.data.followList.length < this.data.total) {
  42. const page = this.data.page + 1
  43. this.setData({
  44. page: page
  45. })
  46. this.getFollow()
  47. }
  48. },
  49. getFollow(){
  50. var followList = this.data.followList
  51. $api.getMyFollow({
  52. page: this.data.page, page_size: 20
  53. }).then(res => {
  54. res.data.data.list.forEach(item=>{
  55. followList.push(item)
  56. })
  57. this.setData({
  58. followList: followList,
  59. total:res.data.data.total,
  60. error:0
  61. })
  62. })
  63. .catch(err=>{
  64. this.setData({
  65. error:1
  66. })
  67. // console.log(err)
  68. })
  69. },
  70. //胜率分页
  71. next1: function () {
  72. if (this.data.winList.length < this.data.total1) {
  73. const page = this.data.page1 + 1
  74. this.setData({
  75. page1: page
  76. })
  77. this.getWin()
  78. }
  79. },
  80. getWin() {
  81. var winList = this.data.winList
  82. $api.getRinrate({
  83. page: this.data.page1, page_size: 20
  84. }).then(res => {
  85. res.data.data.list.forEach(item => {
  86. winList.push(item)
  87. })
  88. this.setData({
  89. winList: winList,
  90. total1: res.data.data.total
  91. })
  92. })
  93. },
  94. //防守分页
  95. next2: function () {
  96. if (this.data.defendList.length < this.data.total2) {
  97. const page = this.data.page2 + 1
  98. this.setData({
  99. page2: page
  100. })
  101. this.getDefen()
  102. }
  103. },
  104. getDefen() {
  105. var defendList = this.data.defendList
  106. $api.getDefend({
  107. page: this.data.page1, page_size: 20
  108. }).then(res => {
  109. res.data.data.list.forEach(item => {
  110. defendList.push(item)
  111. })
  112. this.setData({
  113. defendList: defendList,
  114. total2: res.data.data.total
  115. })
  116. })
  117. },
  118. getData(){
  119. //心得
  120. $api.getChampionlList().then(res => {
  121. this.setData({
  122. championList: res.data.data.list
  123. })
  124. })
  125. $api.getDate().then(res=>{
  126. this.setData({
  127. date:res.data.data
  128. })
  129. this.getHot()
  130. })
  131. },
  132. getHot(){
  133. //热门
  134. let stock_date = this.data.date
  135. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  136. wx.hideNavigationBarLoading()
  137. this.setData({
  138. hotbuyList: res.data.data.list
  139. })
  140. })
  141. $api.getHotsellList({ stock_date: stock_date }).then(res => {
  142. this.setData({
  143. hotsellList: res.data.data.list
  144. })
  145. wx.hideNavigationBarLoading()
  146. })
  147. },
  148. tabChange(e){
  149. this.setData({
  150. cur:e.target.dataset.id
  151. })
  152. },
  153. //预览
  154. preview(e){
  155. console.log(e)
  156. wx.previewImage({
  157. urls: e.target.dataset.urls,
  158. current: e.target.dataset.src
  159. })
  160. },
  161. curChange(e){
  162. if (e.detail.source == "touch"){
  163. this.setData({
  164. cur: e.detail.current
  165. })
  166. }
  167. },
  168. //热门股票
  169. bindDateChange(e){
  170. this.setData({
  171. date:e.detail.value
  172. })
  173. wx.showNavigationBarLoading()
  174. this.getHot()
  175. },
  176. onShow: function () {
  177. if (this.data.error) {
  178. this.onLoad()
  179. }
  180. },
  181. })