index.js 6.3 KB

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