index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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:-1,
  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. this.setData({
  46. page:1,
  47. total:-1,
  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. wx.hideNavigationBarLoading()
  71. res.data.data.list.forEach(item=>{
  72. followList.push(item)
  73. })
  74. this.setData({
  75. followList: followList,
  76. total:res.data.data.total,
  77. error:0,
  78. loading: 0
  79. })
  80. })
  81. .catch(err=>{
  82. this.setData({
  83. error:1
  84. })
  85. // console.log(err)
  86. })
  87. },
  88. //胜率分页
  89. next1: function () {
  90. if (this.data.winList.length < this.data.total1) {
  91. const page = this.data.page1 + 1
  92. this.setData({
  93. page1: page
  94. })
  95. this.getWin()
  96. }
  97. },
  98. getWin() {
  99. var winList = this.data.winList
  100. $api.getRinrate({
  101. page: this.data.page1, page_size: 20
  102. }).then(res => {
  103. res.data.data.list.forEach(item => {
  104. winList.push(item)
  105. })
  106. this.setData({
  107. winList: winList,
  108. total1: res.data.data.total
  109. })
  110. })
  111. },
  112. //防守分页
  113. next2: function () {
  114. if (this.data.defendList.length < this.data.total2) {
  115. const page = this.data.page2 + 1
  116. this.setData({
  117. page2: page
  118. })
  119. this.getDefen()
  120. }
  121. },
  122. getDefen() {
  123. var defendList = this.data.defendList
  124. $api.getDefend({
  125. page: this.data.page2, page_size: 20
  126. }).then(res => {
  127. res.data.data.list.forEach(item => {
  128. defendList.push(item)
  129. })
  130. this.setData({
  131. defendList: defendList,
  132. total2: res.data.data.total
  133. })
  134. })
  135. },
  136. getData(){
  137. //心得
  138. $api.getChampionlList().then(res => {
  139. this.setData({
  140. championList: res.data.data.list
  141. })
  142. })
  143. $api.getDate().then(res=>{
  144. this.setData({
  145. date:res.data.data
  146. })
  147. this.getHot()
  148. this.getHotFollowList()
  149. })
  150. },
  151. //热门选手分页
  152. next3: function () {
  153. if (this.data.hotFollowList.length < this.data.total3) {
  154. const page = this.data.page3 + 1
  155. this.setData({
  156. page3: page
  157. })
  158. this.getHotFollowList()
  159. }
  160. },
  161. getHotFollowList() {
  162. var hotFollowList = this.data.hotFollowList
  163. let stock_date = this.data.date
  164. $api.getHotFollow({
  165. page: this.data.page3, page_size: 20, stock_date: stock_date
  166. }).then(res => {
  167. res.data.data.list.forEach(item => {
  168. hotFollowList.push(item)
  169. })
  170. this.setData({
  171. hotFollowList: hotFollowList,
  172. total3: res.data.data.total
  173. })
  174. })
  175. },
  176. getHot(){
  177. //热门
  178. let stock_date = this.data.date
  179. $api.getHotFollow({ stock_date: stock_date }).then(res => {
  180. this.setData({
  181. hotFollowList: res.data.data.list
  182. })
  183. })
  184. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  185. this.setData({
  186. hotbuyList: res.data.data.list
  187. })
  188. wx.hideNavigationBarLoading()
  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 (e) {
  225. $api.getMyStyle().then(res => {
  226. if (!res.data.data.init_fund) {
  227. wx.navigateTo({
  228. url: '../style/style',
  229. })
  230. }
  231. })
  232. if (app.globalData.follow){
  233. this.setData({
  234. page: 1,
  235. page3: 1,
  236. total: -1,
  237. total3:0,
  238. followList: [],
  239. hotFollowList:[]
  240. })
  241. app.globalData.follow=0
  242. this.getFollow()
  243. this.getHotFollowList()
  244. }
  245. if (this.data.error) {
  246. this.onLoad()
  247. }
  248. },
  249. })