index.js 6.2 KB

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