index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const $api = require('../../utils/api.js').API;
  5. const $push = require('../../utils/api.js').PUSH;
  6. Page({
  7. data: {
  8. loading:0,
  9. notices:[],
  10. tabs:['今日留言','我的关注'],
  11. tabs1:['收益榜','盈利榜','亏损榜','跌幅榜'],
  12. cur:0,
  13. cur1:0,
  14. date:'2022-04-27',
  15. explist:[], //留言
  16. total1:0,
  17. page1:1,
  18. followList:[], //关注
  19. total2:-1,
  20. page2:1,
  21. banners:[],
  22. winLost:{},
  23. baikeList:[],
  24. articleList1:[],
  25. articleList2:[],
  26. articleList3:[],
  27. articleList4:[],
  28. groups:{},
  29. role:0,
  30. match_day:0,
  31. },
  32. onLoad() {
  33. wx.showNavigationBarLoading()
  34. wx.getStorage({
  35. key: 'user',
  36. complete: res => {
  37. this.setData({
  38. role: res.data.role,
  39. })
  40. }
  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. this.getIndexData()
  54. this.getExp()
  55. },
  56. fresh: function () {
  57. },
  58. // 获取首页数据
  59. getIndexData:function(){
  60. $api.getChampionlList({isbanner:1}).then(res=>{
  61. this.setData({
  62. banners:res.data.data.list
  63. })
  64. })
  65. $api.getWinList({new:1}).then(res=>{
  66. let day = res.data.data[0].valid_dates.indexOf(res.data.data[0].date)
  67. this.setData({
  68. winLost:res.data.data[0],
  69. match_day:day,
  70. })
  71. $api.getAvg({match_id:res.data.data[0].match_id}).then(res=>{
  72. var days=res.data.data.list,weeks=[]
  73. days=days.reverse()
  74. for(let i=0;i<52;i++){
  75. weeks.push({
  76. name:'第'+(i+1)+'周',
  77. data:[],
  78. total:0
  79. })
  80. }
  81. days.forEach(item=>{
  82. var w=this.getWeekNumber(item.stock_date)
  83. weeks[w-1].data.push(item)
  84. })
  85. weeks.forEach(item=>{
  86. if(item.data.length>0){
  87. var total=0
  88. var money = 10000.0
  89. item.data.forEach(i=>{
  90. var incom=Number(i.today_income.replace('%',''))
  91. money += money*incom/100.0
  92. i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate())
  93. })
  94. total = (money-10000)*100.0/10000.0
  95. item.total=total.toFixed(2)
  96. }
  97. })
  98. this.setData({
  99. days:weeks.reverse()
  100. })
  101. })
  102. $api.getWinLose({match_id:res.data.data[0].match_id}).then(res1=>{
  103. this.setData({
  104. groups:res1.data.data
  105. })
  106. })
  107. })
  108. $api.getBaikeRandom().then(res=>{
  109. this.setData({
  110. baikeList:res.data.data
  111. })
  112. })
  113. $api.getChampionlList({category:'每日点评',page:1}).then(res=>{
  114. this.setData({
  115. articleList1:res.data.data.list
  116. })
  117. })
  118. $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{
  119. this.setData({
  120. articleList2:res.data.data.list
  121. })
  122. })
  123. $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{
  124. this.setData({
  125. articleList3:res.data.data.list
  126. })
  127. })
  128. $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{
  129. this.setData({
  130. articleList4:res.data.data.list
  131. })
  132. })
  133. },
  134. //计算周数
  135. getWeekNumber:function(dateString) {
  136. const date = new Date(dateString);
  137. const year = date.getFullYear();
  138. // 将年份的第一个周一作为第一周的开始
  139. const firstWeekStart = new Date(year, 0, 1);
  140. firstWeekStart.setDate(firstWeekStart.getDate() - firstWeekStart.getDay() + 1);
  141. // 计算给定日期是一年中的第几周
  142. const currentDate = new Date(date);
  143. currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 1);
  144. let milliseconds = currentDate.getTime() - firstWeekStart.getTime();
  145. const weeks = Math.round(milliseconds / (7 * 24 * 60 * 60 * 1000));
  146. return weeks + 1; // 因为getWeek返回的是年初至今的周数,所以加1得到完整的周数
  147. },
  148. //获取今日留言
  149. getExp:function(){
  150. var list = this.data.explist
  151. $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{
  152. res.data.data.list.forEach(item => {
  153. list.push(item)
  154. })
  155. this.setData({
  156. explist: list,
  157. total1: res.data.data.total
  158. })
  159. })
  160. },
  161. //留言分页
  162. next1: function () {
  163. if (this.data.explist.length < this.data.total1) {
  164. const page = this.data.page1 + 1
  165. this.setData({
  166. page1: page
  167. })
  168. this.getExp()
  169. }
  170. },
  171. //我的关注
  172. getFollow(){
  173. var followList = this.data.followList
  174. if(this.data.loading){
  175. followList=[]
  176. }
  177. $api.getMyFollowV3({
  178. page: this.data.page2, page_size: 20
  179. }).then(res => {
  180. wx.hideNavigationBarLoading()
  181. res.data.data.list.forEach(item => {
  182. followList.push(item)
  183. })
  184. this.setData({
  185. followList: followList,
  186. total2:res.data.data.total,
  187. error:0,
  188. loading: 0
  189. })
  190. app.globalData.follow = 0
  191. })
  192. .catch(err=>{
  193. this.setData({
  194. error:1
  195. })
  196. })
  197. },
  198. //关注分页
  199. next2: function () {
  200. if (this.data.followList.length < this.data.total2) {
  201. const page = this.data.page2 + 1
  202. this.setData({
  203. page2: page
  204. })
  205. this.getFollow()
  206. }
  207. },
  208. tabChange(e){
  209. this.setData({
  210. cur:e.target.dataset.id
  211. })
  212. this.renew()
  213. },
  214. tabChange1(e){
  215. this.setData({
  216. cur1:e.target.dataset.id
  217. })
  218. },
  219. tapGroup(e){
  220. wx.navigateTo({
  221. url: '../avg/avg?index='+e.currentTarget.dataset.index + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  222. })
  223. },
  224. tapAvg(e){
  225. wx.navigateTo({
  226. url: '../avg/avg?index=0' + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  227. })
  228. },
  229. //预览
  230. preview(e){
  231. wx.previewImage({
  232. urls: e.target.dataset.urls,
  233. current: e.target.dataset.src
  234. })
  235. },
  236. curChange(e){
  237. if (e.detail.source == "touch"){
  238. this.setData({
  239. cur: e.detail.current
  240. })
  241. this.renew()
  242. }
  243. },
  244. curChange1(e){
  245. if (e.detail.source == "touch"){
  246. this.setData({
  247. cur1: e.detail.current
  248. })
  249. }
  250. },
  251. renew(){
  252. this.setData({
  253. followList:[],
  254. explist:[],
  255. page1: 1,
  256. total1: 0,
  257. page2: 1,
  258. total2: -1
  259. })
  260. switch(this.data.cur){
  261. case 0:
  262. this.data.page1 = 1
  263. this.getExp()
  264. break;
  265. case 1:
  266. this.data.page2 = 1
  267. this.getFollow()
  268. break;
  269. }
  270. },
  271. pushToday(e){
  272. $push.pushToday(e.currentTarget.dataset)
  273. },
  274. onShow: function (e) {
  275. $api.initUser()
  276. $api.getsignup().then(res => {
  277. this.setData({
  278. info: res.data.data
  279. })
  280. })
  281. if(this.data.cur == 0 && app.globalData.follow == 1){
  282. this.data.loading = 1
  283. this.data.page2 = 1
  284. this.data.total2 = -1,
  285. this.getFollow()
  286. }
  287. },
  288. })