index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. hotFollowList:[],
  16. page:1,
  17. total:0,
  18. page1: 1,
  19. total1: 0,
  20. page2: 1,
  21. total2: 0,
  22. page3: 1,
  23. total3: 0,
  24. error:0
  25. },
  26. onLoad() {
  27. wx.showNavigationBarLoading()
  28. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  29. m = m > 9 ? m : '0' + m;
  30. d = d > 9 ? d : '0' + d;
  31. this.setData({
  32. date: y + '-' + m + '-' + d
  33. })
  34. this.getFollow()
  35. this.getData()
  36. this.getWin()
  37. this.getDefen()
  38. $api.getNotoice().then(res=>{
  39. this.setData({
  40. notices:res.data.data
  41. })
  42. })
  43. },
  44. fresh: function () {
  45. console.log(233)
  46. this.setData({
  47. page:1,
  48. total:0,
  49. loading:1
  50. })
  51. this.getFollow()
  52. },
  53. //关注分页
  54. next: function () {
  55. if (this.data.followList.length < this.data.total) {
  56. const page = this.data.page + 1
  57. this.setData({
  58. page: page
  59. })
  60. this.getFollow()
  61. }
  62. },
  63. getFollow(){
  64. var followList = this.data.followList
  65. if(this.data.loading){
  66. followList=[]
  67. }
  68. $api.getMyFollow({
  69. page: this.data.page, page_size: 20
  70. }).then(res => {
  71. wx.hideNavigationBarLoading()
  72. res.data.data.list.forEach(item=>{
  73. followList.push(item)
  74. })
  75. this.setData({
  76. followList: followList,
  77. total:res.data.data.total,
  78. error:0,
  79. loading: 0
  80. })
  81. })
  82. .catch(err=>{
  83. this.setData({
  84. error:1
  85. })
  86. // console.log(err)
  87. })
  88. },
  89. //胜率分页
  90. next1: function () {
  91. if (this.data.winList.length < this.data.total1) {
  92. const page = this.data.page1 + 1
  93. this.setData({
  94. page1: page
  95. })
  96. this.getWin()
  97. }
  98. },
  99. getWin() {
  100. var winList = this.data.winList
  101. $api.getRinrate({
  102. page: this.data.page1, page_size: 20
  103. }).then(res => {
  104. res.data.data.list.forEach(item => {
  105. winList.push(item)
  106. })
  107. this.setData({
  108. winList: winList,
  109. total1: res.data.data.total
  110. })
  111. })
  112. },
  113. //防守分页
  114. next2: function () {
  115. if (this.data.defendList.length < this.data.total2) {
  116. const page = this.data.page2 + 1
  117. this.setData({
  118. page2: page
  119. })
  120. this.getDefen()
  121. }
  122. },
  123. getDefen() {
  124. var defendList = this.data.defendList
  125. $api.getDefend({
  126. page: this.data.page1, page_size: 20
  127. }).then(res => {
  128. res.data.data.list.forEach(item => {
  129. defendList.push(item)
  130. })
  131. this.setData({
  132. defendList: defendList,
  133. total2: res.data.data.total
  134. })
  135. })
  136. },
  137. getData(){
  138. //心得
  139. $api.getChampionlList().then(res => {
  140. this.setData({
  141. championList: res.data.data.list
  142. })
  143. })
  144. $api.getDate().then(res=>{
  145. this.setData({
  146. date:res.data.data
  147. })
  148. this.getHot()
  149. this.getHotFollowList()
  150. })
  151. },
  152. //热门选手分页
  153. next3: function () {
  154. if (this.data.hotFollowList.length < this.data.total3) {
  155. const page = this.data.page3 + 1
  156. this.setData({
  157. page3: page
  158. })
  159. this.getHotFollowList()
  160. }
  161. },
  162. getHotFollowList() {
  163. var hotFollowList = this.data.hotFollowList
  164. let stock_date = this.data.date
  165. $api.getHotFollow({
  166. page: this.data.page3, page_size: 20, stock_date: stock_date
  167. }).then(res => {
  168. res.data.data.list.forEach(item => {
  169. hotFollowList.push(item)
  170. })
  171. this.setData({
  172. hotFollowList: hotFollowList,
  173. total3: res.data.data.total
  174. })
  175. })
  176. },
  177. getHot(){
  178. //热门
  179. let stock_date = this.data.date
  180. $api.getHotFollow({ stock_date: stock_date }).then(res => {
  181. this.setData({
  182. hotFollowList: res.data.data.list
  183. })
  184. })
  185. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  186. this.setData({
  187. hotbuyList: res.data.data.list
  188. })
  189. })
  190. $api.getHotsellList({ stock_date: stock_date }).then(res => {
  191. this.setData({
  192. hotsellList: res.data.data.list
  193. })
  194. })
  195. },
  196. tabChange(e){
  197. this.setData({
  198. cur:e.target.dataset.id
  199. })
  200. },
  201. //预览
  202. preview(e){
  203. console.log(e)
  204. wx.previewImage({
  205. urls: e.target.dataset.urls,
  206. current: e.target.dataset.src
  207. })
  208. },
  209. curChange(e){
  210. if (e.detail.source == "touch"){
  211. this.setData({
  212. cur: e.detail.current
  213. })
  214. }
  215. },
  216. //热门股票
  217. bindDateChange(e){
  218. this.setData({
  219. date:e.detail.value
  220. })
  221. wx.showNavigationBarLoading()
  222. this.getHot()
  223. },
  224. onShow: function () {
  225. if (this.data.error) {
  226. this.onLoad()
  227. }
  228. },
  229. })