index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. hot:0,
  12. date:'2022-04-27',
  13. followList:[],
  14. defendList:[],
  15. winList:[],
  16. hotFollowList:[],
  17. hotbuyList:[],
  18. championList:[],
  19. page:1,
  20. total:-1,
  21. page1: 1,
  22. total1: 0,
  23. page2: 1,
  24. total2: 0,
  25. page3: 1,
  26. total3: 0,
  27. error:0
  28. },
  29. onLoad() {
  30. wx.showNavigationBarLoading()
  31. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  32. m = m > 9 ? m : '0' + m;
  33. d = d > 9 ? d : '0' + d;
  34. this.setData({
  35. date: y + '-' + m + '-' + d
  36. })
  37. this.getFollow()
  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. $api.getChoice().then(res=>{
  196. this.setData({
  197. myList: res.data.data.list
  198. })
  199. })
  200. },
  201. tabChange(e){
  202. this.setData({
  203. cur:e.target.dataset.id
  204. })
  205. switch(e.target.dataset.id){
  206. case 0:
  207. if (this.data.followList.length>0){
  208. return
  209. }
  210. this.getFollow()
  211. case 1:
  212. if (this.data.hotbuyList.length>0) {
  213. return
  214. }
  215. this.getHot()
  216. case 2:
  217. if (this.data.hotFollowList.length > 0) {
  218. return
  219. }
  220. this.getHotFollowList()
  221. case 3:
  222. if (this.data.winList.length > 0) {
  223. return
  224. }
  225. this.getWin()
  226. case 4:
  227. if (this.data.championList.length>0) {
  228. return
  229. }
  230. this.getData()
  231. }
  232. },
  233. tabChange1(e){
  234. this.setData({
  235. hot:e.target.dataset.id
  236. })
  237. },
  238. //预览
  239. preview(e){
  240. console.log(e)
  241. wx.previewImage({
  242. urls: e.target.dataset.urls,
  243. current: e.target.dataset.src
  244. })
  245. },
  246. curChange(e){
  247. if (e.detail.source == "touch"){
  248. this.setData({
  249. cur: e.detail.current
  250. })
  251. switch (e.target.dataset.id) {
  252. case 0:
  253. if (this.data.followList.length > 0) {
  254. return
  255. }
  256. this.getFollow()
  257. case 1:
  258. if (this.data.hotbuyList) {
  259. return
  260. }
  261. this.getHot()
  262. case 2:
  263. if (this.data.hotFollowList.length > 0) {
  264. return
  265. }
  266. this.getHotFollowList()
  267. case 3:
  268. if (this.data.winList.length > 0) {
  269. return
  270. }
  271. this.getWin()
  272. case 4:
  273. if (this.data.championList) {
  274. return
  275. }
  276. this.getData()
  277. }
  278. }
  279. },
  280. //热门股票
  281. bindDateChange(e){
  282. this.setData({
  283. date:e.detail.value
  284. })
  285. wx.showNavigationBarLoading()
  286. this.getHot()
  287. },
  288. onShow: function (e) {
  289. this.setData({
  290. followList:[],
  291. defendList:[],
  292. winList:[],
  293. hotFollowList:[],
  294. hotbuyList:[],
  295. championList:[],
  296. page:1,
  297. total:-1,
  298. page1: 1,
  299. total1: 0,
  300. page2: 1,
  301. total2: 0,
  302. page3: 1,
  303. total3: 0
  304. })
  305. switch(this.data.cur){
  306. case 0:
  307. this.getFollow()
  308. case 1:
  309. this.getHot()
  310. case 2:
  311. this.getHotFollowList()
  312. case 3:
  313. this.getWin()
  314. case 4:
  315. this.getData()
  316. }
  317. // if (app.globalData.follow){
  318. // this.setData({
  319. // page: 1,
  320. // total: -1,
  321. // followList: [],
  322. // })
  323. // app.globalData.follow=0
  324. // this.getFollow()
  325. // }
  326. // if (this.data.error) {
  327. // this.onLoad()
  328. // }
  329. },
  330. })