index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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<55;i++){
  75. weeks.push({
  76. name:'',
  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=weeks.filter(item=>item.data.length>0)
  86. var w_text=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五']
  87. weeks.forEach((item,index)=>{
  88. if(item.data.length>0){
  89. item.name='第'+w_text[index]+'周'
  90. var total=0
  91. var money = 10000.0
  92. item.data.forEach(i=>{
  93. var incom=Number(i.today_income.replace('%',''))
  94. money += money*incom/100.0
  95. i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate())
  96. })
  97. total = (money-10000)*100.0/10000.0
  98. item.total=total.toFixed(2)
  99. }
  100. })
  101. this.setData({
  102. days:weeks.reverse()
  103. })
  104. })
  105. $api.getWinLose({match_id:res.data.data[0].match_id}).then(res1=>{
  106. this.setData({
  107. groups:res1.data.data
  108. })
  109. })
  110. })
  111. $api.getBaikeRandom().then(res=>{
  112. this.setData({
  113. baikeList:res.data.data
  114. })
  115. })
  116. $api.getChampionlList({category:'每日点评',page:1}).then(res=>{
  117. this.setData({
  118. articleList1:res.data.data.list
  119. })
  120. })
  121. $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{
  122. this.setData({
  123. articleList2:res.data.data.list
  124. })
  125. })
  126. $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{
  127. this.setData({
  128. articleList3:res.data.data.list
  129. })
  130. })
  131. $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{
  132. this.setData({
  133. articleList4:res.data.data.list
  134. })
  135. })
  136. },
  137. //计算周数
  138. getWeekNumber:function(dateString) {
  139. const date = new Date(dateString);
  140. const year = date.getFullYear();
  141. // 将年份的第一个周一作为第一周的开始
  142. const firstWeekStart = new Date(year, 0, 1);
  143. firstWeekStart.setDate(firstWeekStart.getDate() - firstWeekStart.getDay() + 1);
  144. // 计算给定日期是一年中的第几周
  145. const currentDate = new Date(date);
  146. currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 1);
  147. let milliseconds = currentDate.getTime() - firstWeekStart.getTime();
  148. const weeks = Math.round(milliseconds / (7 * 24 * 60 * 60 * 1000));
  149. return weeks + 1; // 因为getWeek返回的是年初至今的周数,所以加1得到完整的周数
  150. },
  151. //获取今日留言
  152. getExp:function(){
  153. var list = this.data.explist
  154. $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{
  155. res.data.data.list.forEach(item => {
  156. list.push(item)
  157. })
  158. this.setData({
  159. explist: list,
  160. total1: res.data.data.total
  161. })
  162. })
  163. },
  164. //留言分页
  165. next1: function () {
  166. if (this.data.explist.length < this.data.total1) {
  167. const page = this.data.page1 + 1
  168. this.setData({
  169. page1: page
  170. })
  171. this.getExp()
  172. }
  173. },
  174. //我的关注
  175. getFollow(){
  176. var followList = this.data.followList
  177. if(this.data.loading){
  178. followList=[]
  179. }
  180. $api.getMyFollowV3({
  181. page: this.data.page2, page_size: 20
  182. }).then(res => {
  183. wx.hideNavigationBarLoading()
  184. res.data.data.list.forEach(item => {
  185. followList.push(item)
  186. })
  187. this.setData({
  188. followList: followList,
  189. total2:res.data.data.total,
  190. error:0,
  191. loading: 0
  192. })
  193. app.globalData.follow = 0
  194. })
  195. .catch(err=>{
  196. this.setData({
  197. error:1
  198. })
  199. })
  200. },
  201. //关注分页
  202. next2: function () {
  203. if (this.data.followList.length < this.data.total2) {
  204. const page = this.data.page2 + 1
  205. this.setData({
  206. page2: page
  207. })
  208. this.getFollow()
  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. cur1:e.target.dataset.id
  220. })
  221. },
  222. tapGroup(e){
  223. wx.navigateTo({
  224. url: '../avg/avg?index='+e.currentTarget.dataset.index + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  225. })
  226. },
  227. tapAvg(e){
  228. wx.navigateTo({
  229. url: '../avg/avg?index=0' + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  230. })
  231. },
  232. //预览
  233. preview(e){
  234. wx.previewImage({
  235. urls: e.target.dataset.urls,
  236. current: e.target.dataset.src
  237. })
  238. },
  239. curChange(e){
  240. if (e.detail.source == "touch"){
  241. this.setData({
  242. cur: e.detail.current
  243. })
  244. this.renew()
  245. }
  246. },
  247. curChange1(e){
  248. if (e.detail.source == "touch"){
  249. this.setData({
  250. cur1: e.detail.current
  251. })
  252. }
  253. },
  254. renew(){
  255. this.setData({
  256. followList:[],
  257. explist:[],
  258. page1: 1,
  259. total1: 0,
  260. page2: 1,
  261. total2: -1
  262. })
  263. switch(this.data.cur){
  264. case 0:
  265. this.data.page1 = 1
  266. this.getExp()
  267. break;
  268. case 1:
  269. this.data.page2 = 1
  270. this.getFollow()
  271. break;
  272. }
  273. },
  274. pushToday(e){
  275. $push.pushToday(e.currentTarget.dataset)
  276. },
  277. onShow: function (e) {
  278. $api.initUser()
  279. $api.getsignup().then(res => {
  280. this.setData({
  281. info: res.data.data
  282. })
  283. })
  284. if(this.data.cur == 0 && app.globalData.follow == 1){
  285. this.data.loading = 1
  286. this.data.page2 = 1
  287. this.data.total2 = -1,
  288. this.getFollow()
  289. }
  290. },
  291. })