index.js 4.0 KB

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