index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. $api.getDate().then(res=>{
  38. this.setData({
  39. date:res.data.data
  40. })
  41. })
  42. // this.getFollow()
  43. $api.getNotoice().then(res=>{
  44. this.setData({
  45. notices:res.data.data
  46. })
  47. })
  48. },
  49. fresh: function () {
  50. this.setData({
  51. page:1,
  52. total:-1,
  53. loading:1
  54. })
  55. this.getFollow()
  56. },
  57. //关注分页
  58. next: function () {
  59. if (this.data.followList.length < this.data.total) {
  60. const page = this.data.page + 1
  61. this.setData({
  62. page: page
  63. })
  64. this.getFollow()
  65. }
  66. },
  67. getFollow(){
  68. var followList = this.data.followList
  69. if(this.data.loading){
  70. followList=[]
  71. }
  72. $api.getMyFollow({
  73. page: this.data.page, page_size: 20
  74. }).then(res => {
  75. wx.hideNavigationBarLoading()
  76. res.data.data.list.forEach(item=>{
  77. item.today_income=parseInt(item.today_income)+"%"
  78. item.total_income=parseInt(item.total_income)+"%"
  79. followList.push(item)
  80. })
  81. this.setData({
  82. followList: followList,
  83. total:res.data.data.total,
  84. error:0,
  85. loading: 0
  86. })
  87. })
  88. .catch(err=>{
  89. this.setData({
  90. error:1
  91. })
  92. })
  93. },
  94. //胜率分页
  95. next1: function () {
  96. if (this.data.winList.length < this.data.total1) {
  97. const page = this.data.page1 + 1
  98. this.setData({
  99. page1: page
  100. })
  101. this.getWin()
  102. }
  103. },
  104. getWin() {
  105. var winList = this.data.winList
  106. $api.getRinrate({
  107. page: this.data.page1, page_size: 20
  108. }).then(res => {
  109. res.data.data.list.forEach(item => {
  110. winList.push(item)
  111. })
  112. this.setData({
  113. winList: winList,
  114. total1: res.data.data.total
  115. })
  116. })
  117. },
  118. //防守分页 防守榜去掉
  119. // next2: function () {
  120. // if (this.data.defendList.length < this.data.total2) {
  121. // const page = this.data.page2 + 1
  122. // this.setData({
  123. // page2: page
  124. // })
  125. // this.getDefen()
  126. // }
  127. // },
  128. // getDefen() {
  129. // var defendList = this.data.defendList
  130. // $api.getDefend({
  131. // page: this.data.page2, page_size: 20
  132. // }).then(res => {
  133. // res.data.data.list.forEach(item => {
  134. // defendList.push(item)
  135. // })
  136. // this.setData({
  137. // defendList: defendList,
  138. // total2: res.data.data.total
  139. // })
  140. // })
  141. // },
  142. getData(){
  143. //心得
  144. $api.getChampionlList().then(res => {
  145. this.setData({
  146. championList: res.data.data.list
  147. })
  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.getHotbuyList({ stock_date: stock_date }).then(res => {
  179. this.setData({
  180. hotbuyList: res.data.data.list
  181. })
  182. wx.hideNavigationBarLoading()
  183. })
  184. // $api.getHotsellList({ stock_date: stock_date }).then(res => {
  185. // this.setData({
  186. // hotsellList: res.data.data.list
  187. // })
  188. // })
  189. $api.getChoice().then(res=>{
  190. this.setData({
  191. myList: res.data.data.list
  192. })
  193. })
  194. },
  195. tabChange(e){
  196. this.setData({
  197. cur:e.target.dataset.id
  198. })
  199. switch(e.target.dataset.id){
  200. case 0:
  201. if (this.data.followList.length>0){
  202. return
  203. }
  204. this.getFollow()
  205. break;
  206. case 1:
  207. if (this.data.hotbuyList.length>0) {
  208. return
  209. }
  210. this.getHot()
  211. break;
  212. case 2:
  213. if (this.data.hotFollowList.length > 0) {
  214. return
  215. }
  216. this.getHotFollowList()
  217. break;
  218. case 3:
  219. if (this.data.winList.length > 0) {
  220. return
  221. }
  222. this.getWin()
  223. break;
  224. case 4:
  225. if (this.data.championList.length>0) {
  226. return
  227. }
  228. this.getData()
  229. break;
  230. }
  231. },
  232. tabChange1(e){
  233. this.setData({
  234. hot:e.target.dataset.id
  235. })
  236. },
  237. //预览
  238. preview(e){
  239. console.log(e)
  240. wx.previewImage({
  241. urls: e.target.dataset.urls,
  242. current: e.target.dataset.src
  243. })
  244. },
  245. curChange(e){
  246. if (e.detail.source == "touch"){
  247. this.setData({
  248. cur: e.detail.current
  249. })
  250. switch (e.target.dataset.id) {
  251. case 0:
  252. if (this.data.followList.length > 0) {
  253. return
  254. }
  255. this.getFollow()
  256. break;
  257. case 1:
  258. if (this.data.hotbuyList) {
  259. return
  260. }
  261. this.getHot()
  262. break;
  263. case 2:
  264. if (this.data.hotFollowList.length > 0) {
  265. return
  266. }
  267. this.getHotFollowList()
  268. case 3:
  269. if (this.data.winList.length > 0) {
  270. return
  271. }
  272. this.getWin()
  273. break;
  274. case 4:
  275. if (this.data.championList) {
  276. return
  277. }
  278. this.getData()
  279. break;
  280. }
  281. }
  282. },
  283. //热门股票
  284. bindDateChange(e){
  285. this.setData({
  286. date:e.detail.value
  287. })
  288. wx.showNavigationBarLoading()
  289. this.getHot()
  290. },
  291. onShow: function (e) {
  292. //判断是否报名
  293. $api.getAuthinfo().then(res=>{
  294. // if(res.data.data.phone == null || res.data.data.phone==''){
  295. // wx.navigateTo({
  296. // url: '../login/user',
  297. // })
  298. // }
  299. if(res.data.data.role==0){
  300. wx.navigateTo({
  301. url: '../login/user?type=3',
  302. })
  303. }
  304. })
  305. this.setData({
  306. followList:[],
  307. defendList:[],
  308. winList:[],
  309. hotFollowList:[],
  310. hotbuyList:[],
  311. championList:[],
  312. page:1,
  313. total:-1,
  314. page1: 1,
  315. total1: 0,
  316. page2: 1,
  317. total2: 0,
  318. page3: 1,
  319. total3: 0
  320. })
  321. switch(this.data.cur){
  322. case 0:
  323. this.getFollow()
  324. break;
  325. case 1:
  326. this.getHot()
  327. break;
  328. case 2:
  329. this.getHotFollowList()
  330. break;
  331. case 3:
  332. this.getWin()
  333. break;
  334. case 4:
  335. this.getData()
  336. break;
  337. }
  338. // if (app.globalData.follow){
  339. // this.setData({
  340. // page: 1,
  341. // total: -1,
  342. // followList: [],
  343. // })
  344. // app.globalData.follow=0
  345. // this.getFollow()
  346. // }
  347. // if (this.data.error) {
  348. // this.onLoad()
  349. // }
  350. },
  351. })