index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  28. m = m > 9 ? m : '0' + m;
  29. d = d > 9 ? d : '0' + d;
  30. this.setData({
  31. date: y + '-' + m + '-' + d
  32. })
  33. this.getFollow()
  34. this.getData()
  35. this.getWin()
  36. this.getDefen()
  37. $api.getNotoice().then(res=>{
  38. this.setData({
  39. notices:res.data.data
  40. })
  41. })
  42. },
  43. fresh: function () {
  44. console.log(233)
  45. this.setData({
  46. page:1,
  47. total:0,
  48. loading:1
  49. })
  50. this.getFollow()
  51. },
  52. //关注分页
  53. next: function () {
  54. if (this.data.followList.length < this.data.total) {
  55. const page = this.data.page + 1
  56. this.setData({
  57. page: page
  58. })
  59. this.getFollow()
  60. }
  61. },
  62. getFollow(){
  63. var followList = this.data.followList
  64. if(this.data.loading){
  65. followList=[]
  66. }
  67. $api.getMyFollow({
  68. page: this.data.page, page_size: 20
  69. }).then(res => {
  70. res.data.data.list.forEach(item=>{
  71. followList.push(item)
  72. })
  73. this.setData({
  74. followList: followList,
  75. total:res.data.data.total,
  76. error:0,
  77. loading: 0
  78. })
  79. })
  80. .catch(err=>{
  81. this.setData({
  82. error:1
  83. })
  84. // console.log(err)
  85. })
  86. },
  87. //胜率分页
  88. next1: function () {
  89. if (this.data.winList.length < this.data.total1) {
  90. const page = this.data.page1 + 1
  91. this.setData({
  92. page1: page
  93. })
  94. this.getWin()
  95. }
  96. },
  97. getWin() {
  98. var winList = this.data.winList
  99. $api.getRinrate({
  100. page: this.data.page1, page_size: 20
  101. }).then(res => {
  102. res.data.data.list.forEach(item => {
  103. winList.push(item)
  104. })
  105. this.setData({
  106. winList: winList,
  107. total1: res.data.data.total
  108. })
  109. })
  110. },
  111. //防守分页
  112. next2: function () {
  113. if (this.data.defendList.length < this.data.total2) {
  114. const page = this.data.page2 + 1
  115. this.setData({
  116. page2: page
  117. })
  118. this.getDefen()
  119. }
  120. },
  121. getDefen() {
  122. var defendList = this.data.defendList
  123. $api.getDefend({
  124. page: this.data.page1, page_size: 20
  125. }).then(res => {
  126. res.data.data.list.forEach(item => {
  127. defendList.push(item)
  128. })
  129. this.setData({
  130. defendList: defendList,
  131. total2: res.data.data.total
  132. })
  133. })
  134. },
  135. getData(){
  136. //心得
  137. $api.getChampionlList().then(res => {
  138. this.setData({
  139. championList: res.data.data.list
  140. })
  141. })
  142. $api.getDate().then(res=>{
  143. this.setData({
  144. date:res.data.data
  145. })
  146. this.getHot()
  147. this.getHotFollowList()
  148. })
  149. },
  150. //热门选手分页
  151. next3: function () {
  152. if (this.data.hotFollowList.length < this.data.total3) {
  153. const page = this.data.page3 + 1
  154. this.setData({
  155. page3: page
  156. })
  157. this.getHotFollowList()
  158. }
  159. },
  160. getHotFollowList() {
  161. var hotFollowList = this.data.hotFollowList
  162. let stock_date = this.data.date
  163. $api.getHotFollow({
  164. page: this.data.page3, page_size: 20, stock_date: stock_date
  165. }).then(res => {
  166. res.data.data.list.forEach(item => {
  167. hotFollowList.push(item)
  168. })
  169. this.setData({
  170. hotFollowList: hotFollowList,
  171. total3: res.data.data.total
  172. })
  173. })
  174. },
  175. getHot(){
  176. //热门
  177. let stock_date = this.data.date
  178. $api.getHotFollow({ stock_date: stock_date }).then(res => {
  179. this.setData({
  180. hotFollowList: res.data.data.list
  181. })
  182. })
  183. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  184. wx.hideNavigationBarLoading()
  185. this.setData({
  186. hotbuyList: res.data.data.list
  187. })
  188. })
  189. $api.getHotsellList({ stock_date: stock_date }).then(res => {
  190. this.setData({
  191. hotsellList: res.data.data.list
  192. })
  193. wx.hideNavigationBarLoading()
  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. })