index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. explist:[],
  20. page:1,
  21. total:-1,
  22. page1: 1,
  23. total1: 0,
  24. page2: 1,
  25. total2: 0,
  26. page3: 1,
  27. total3: 0,
  28. page4: 1,
  29. total4: 0,
  30. page5:1, // 今日留言加载更多
  31. total5:0,
  32. error:0
  33. },
  34. onLoad() {
  35. wx.showNavigationBarLoading()
  36. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  37. m = m > 9 ? m : '0' + m;
  38. d = d > 9 ? d : '0' + d;
  39. // this.setData({
  40. // date: y + '-' + m + '-' + d
  41. // })
  42. $api.getDate().then(res=>{
  43. this.setData({
  44. date:res.data.data
  45. })
  46. $api.getNotoice().then(res=>{
  47. this.setData({
  48. notices:res.data.data
  49. })
  50. })
  51. })
  52. this.getFollow()
  53. },
  54. fresh: function () {
  55. this.setData({
  56. page:1,
  57. total:-1,
  58. loading:1
  59. })
  60. this.getFollow()
  61. },
  62. //关注分页
  63. next: function () {
  64. if (this.data.followList.length < this.data.total) {
  65. const page = this.data.page + 1
  66. this.setData({
  67. page: page
  68. })
  69. this.getFollow()
  70. }
  71. },
  72. getFollow(){
  73. var followList = this.data.followList
  74. if(this.data.loading){
  75. followList=[]
  76. }
  77. $api.getMyFollow({
  78. page: this.data.page, page_size: 20
  79. }).then(res => {
  80. wx.hideNavigationBarLoading()
  81. res.data.data.list.forEach(item=>{
  82. item.today_income=parseInt(item.today_income)+"%"
  83. item.total_income=parseInt(item.total_income)+"%"
  84. followList.push(item)
  85. })
  86. this.setData({
  87. followList: followList,
  88. total:res.data.data.total,
  89. error:0,
  90. loading: 0
  91. })
  92. })
  93. .catch(err=>{
  94. this.setData({
  95. error:1
  96. })
  97. })
  98. },
  99. //胜率分页
  100. next1: function () {
  101. if (this.data.winList.length < this.data.total1) {
  102. const page = this.data.page1 + 1
  103. this.setData({
  104. page1: page
  105. })
  106. this.getWin()
  107. }
  108. },
  109. getWin() {
  110. var winList = this.data.winList
  111. $api.getRinrate({
  112. page: this.data.page1, page_size: 20
  113. }).then(res => {
  114. res.data.data.list.forEach(item => {
  115. winList.push(item)
  116. })
  117. this.setData({
  118. winList: winList,
  119. total1: res.data.data.total
  120. })
  121. })
  122. },
  123. //防守分页 防守榜去掉
  124. // next2: function () {
  125. // if (this.data.defendList.length < this.data.total2) {
  126. // const page = this.data.page2 + 1
  127. // this.setData({
  128. // page2: page
  129. // })
  130. // this.getDefen()
  131. // }
  132. // },
  133. // getDefen() {
  134. // var defendList = this.data.defendList
  135. // $api.getDefend({
  136. // page: this.data.page2, page_size: 20
  137. // }).then(res => {
  138. // res.data.data.list.forEach(item => {
  139. // defendList.push(item)
  140. // })
  141. // this.setData({
  142. // defendList: defendList,
  143. // total2: res.data.data.total
  144. // })
  145. // })
  146. // },
  147. getData(){
  148. //心得
  149. $api.getChampionlList().then(res => {
  150. this.setData({
  151. championList: res.data.data.list
  152. })
  153. })
  154. },
  155. //热门选手分页
  156. next3: function () {
  157. if (this.data.hotFollowList.length < this.data.total3) {
  158. const page = this.data.page3 + 1
  159. this.setData({
  160. page3: page
  161. })
  162. this.getHotFollowList()
  163. }
  164. },
  165. getHotFollowList() {
  166. var hotFollowList = this.data.hotFollowList
  167. let stock_date = this.data.date
  168. $api.getHotFollow({
  169. page: this.data.page3, page_size: 20, stock_date: stock_date
  170. }).then(res => {
  171. res.data.data.list.forEach(item => {
  172. hotFollowList.push(item)
  173. })
  174. this.setData({
  175. hotFollowList: hotFollowList,
  176. total3: res.data.data.total
  177. })
  178. })
  179. },
  180. getHot(){
  181. //热门
  182. let stock_date = this.data.date
  183. $api.getHotbuyList({ stock_date: stock_date }).then(res => {
  184. this.setData({
  185. hotbuyList: res.data.data.list
  186. })
  187. wx.hideNavigationBarLoading()
  188. })
  189. // $api.getHotsellList({ stock_date: stock_date }).then(res => {
  190. // this.setData({
  191. // hotsellList: res.data.data.list
  192. // })
  193. // })
  194. },
  195. tabChange(e){
  196. this.setData({
  197. cur:e.target.dataset.id
  198. })
  199. this.renew()
  200. },
  201. tabChange1(e){
  202. this.setData({
  203. hot:e.target.dataset.id
  204. })
  205. },
  206. //预览
  207. preview(e){
  208. console.log(e)
  209. wx.previewImage({
  210. urls: e.target.dataset.urls,
  211. current: e.target.dataset.src
  212. })
  213. },
  214. curChange(e){
  215. if (e.detail.source == "touch"){
  216. this.setData({
  217. cur: e.detail.current
  218. })
  219. this.renew()
  220. }
  221. },
  222. //热门股票
  223. bindDateChange(e){
  224. this.setData({
  225. date:e.detail.value
  226. })
  227. wx.showNavigationBarLoading()
  228. this.getHot()
  229. },
  230. //今日留言
  231. next5: function () {
  232. if (this.data.explist.length < this.data.total5) {
  233. const page = this.data.page5 + 1
  234. this.setData({
  235. page5: page
  236. })
  237. this.getExp()
  238. }
  239. },
  240. getExp(){
  241. $api.getExperience({page:this.data.page5,page_size:20}).then(res=>{
  242. var data=res.data.data.list;
  243. data.forEach(item=>{
  244. item.today_income=parseInt(item.today_income)+"%"
  245. item.total_income=parseInt(item.total_income)+"%"
  246. })
  247. this.setData({
  248. explist: data,
  249. total5: res.data.data.list.total
  250. })
  251. })
  252. },
  253. renew(){
  254. this.setData({
  255. followList:[],
  256. defendList:[],
  257. winList:[],
  258. hotFollowList:[],
  259. hotbuyList:[],
  260. championList:[],
  261. explist:[],
  262. page:1,
  263. total:-1,
  264. page1: 1,
  265. total1: 0,
  266. page2: 1,
  267. total2: 0,
  268. page3: 1,
  269. total3: 0,
  270. page5: 1,
  271. total5: 0
  272. })
  273. switch(this.data.cur){
  274. case 0:
  275. this.getFollow()
  276. break;
  277. case 1:
  278. this.getHot()
  279. break;
  280. case 2:
  281. this.getHotFollowList()
  282. break;
  283. case 3:
  284. this.getExp()
  285. break;
  286. case 4:
  287. this.getData()
  288. break;
  289. }
  290. },
  291. onShow: function (e) {
  292. //判断是否报名
  293. $api.getAuthinfo().then(res=>{
  294. if(res.data.data.role==0){
  295. wx.navigateTo({
  296. url: '../login/user?type=3&player_type='+res.data.data.player_type,
  297. })
  298. }
  299. })
  300. // if(this.data.followList.length<=0){
  301. // this.getFollow()
  302. // }
  303. },
  304. })