index.js 7.0 KB

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