index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. socore:[10,9,8,7,6,5,4,3,2,1],
  32. isScore:0,
  33. isWeek:0,
  34. scoredays:[]
  35. },
  36. onLoad() {
  37. var w=new Date().getDay()
  38. if(w == 0 || w == 6){
  39. this.setData({
  40. isWeek:1
  41. })
  42. }
  43. wx.showNavigationBarLoading()
  44. wx.getStorage({
  45. key: 'user',
  46. complete: res => {
  47. this.setData({
  48. role: res.data.role,
  49. })
  50. }
  51. })
  52. $api.getDate().then(res=>{
  53. this.setData({
  54. date:res.data.data
  55. })
  56. $api.getNotoice().then(res=>{
  57. this.setData({
  58. notices:res.data.data
  59. })
  60. })
  61. // 是否打分
  62. var y=new Date().getFullYear()
  63. var m=Number(new Date().getMonth() + 1)
  64. var d = new Date().getDate()
  65. m=m>9?m:'0'+m;
  66. d=d>9?d:'0'+d
  67. var date = y+'-'+m+'-'+d
  68. if(!this.data.isWeek){
  69. $api.checkMark({stock_date:date}).then(res=>{
  70. if(res.data.data){
  71. this.setData({
  72. isScore:1
  73. })
  74. }
  75. })
  76. }
  77. })
  78. this.getFollow()
  79. this.getIndexData()
  80. this.getExp()
  81. this.getWeekAvg()
  82. },
  83. getWeekAvg:function(){
  84. $api.getMark().then(res=>{
  85. var days=res.data.data,weeks={}
  86. days.forEach(item=>{
  87. item.week=getYearWeek(item.stock_date)
  88. item.date=(new Date(item.stock_date).getMonth()+1)+'/'+(new Date(item.stock_date).getDate())
  89. weeks[item.week]=[]
  90. })
  91. days.forEach(item=>{
  92. weeks[item.week].push(item)
  93. })
  94. var scoredays=[]
  95. for (let key in weeks) {
  96. scoredays.push({
  97. name:key,
  98. data:weeks[key].reverse()
  99. })
  100. }
  101. this.setData({
  102. scoredays:scoredays.reverse()
  103. })
  104. })
  105. function getYearWeek(endDate) {
  106. //本年的第一天
  107. endDate=new Date(endDate)
  108. var beginDate = new Date(endDate.getFullYear(), 0, 1);
  109. //星期从0-6,0代表星期天,6代表星期六
  110. var endWeek = endDate.getDay();
  111. if (endWeek == 0) endWeek = 7;
  112. var beginWeek = beginDate.getDay();
  113. if (beginWeek == 0) beginWeek = 7;
  114. //计算两个日期的天数差
  115. var millisDiff = endDate.getTime() - beginDate.getTime();
  116. var dayDiff = Math.floor(( millisDiff + (beginWeek - endWeek) * (24 * 60 * 60 * 1000)) / 86400000);
  117. return Math.ceil(dayDiff / 7) + 1;
  118. }
  119. },
  120. radioChange:function(e){
  121. var y=new Date().getFullYear()
  122. var m=Number(new Date().getMonth() + 1)
  123. var d = new Date().getDate()
  124. m=m>9?m:'0'+m;
  125. d=d>9?d:'0'+d
  126. var date = y+'-'+m+'-'+d
  127. this.setData({
  128. s:e.detail.value
  129. })
  130. $api.markScore({stock_date:date,score:e.detail.value}).then(res=>{
  131. console.log(res)
  132. if(res.data.code == 0){
  133. wx.showToast({
  134. title: '打分成功',
  135. })
  136. this.setData({
  137. isScore:1
  138. })
  139. this.getWeekAvg()
  140. }
  141. })
  142. },
  143. fresh: function () {
  144. },
  145. // 获取首页数据
  146. getIndexData:function(){
  147. $api.getChampionlList({isbanner:1}).then(res=>{
  148. this.setData({
  149. banners:res.data.data.list
  150. })
  151. })
  152. $api.getWinList({new:1}).then(res=>{
  153. let day = res.data.data[0].valid_dates.indexOf(res.data.data[0].date)
  154. this.setData({
  155. winLost:res.data.data[0],
  156. match_day:day,
  157. })
  158. $api.getAvg({match_id:res.data.data[0].match_id}).then(res=>{
  159. var days=res.data.data.list,weeks=[]
  160. days=days.reverse()
  161. for(let i=0;i<55;i++){
  162. weeks.push({
  163. name:'',
  164. data:[],
  165. total:0
  166. })
  167. }
  168. days.forEach(item=>{
  169. var w=this.getWeekNumber(item.stock_date)
  170. weeks[w-1].data.push(item)
  171. })
  172. weeks=weeks.filter(item=>item.data.length>0)
  173. var w_text=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五']
  174. weeks.forEach((item,index)=>{
  175. if(item.data.length>0){
  176. item.name='第'+w_text[index]+'周'
  177. var total=0
  178. var money = 10000.0
  179. item.data.forEach(i=>{
  180. var incom=Number(i.today_income.replace('%',''))
  181. money += money*incom/100.0
  182. i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate())
  183. })
  184. total = (money-10000)*100.0/10000.0
  185. item.total=total.toFixed(2)
  186. }
  187. })
  188. this.setData({
  189. days:weeks.reverse()
  190. })
  191. })
  192. $api.getWinLose({match_id:res.data.data[0].match_id}).then(res1=>{
  193. this.setData({
  194. groups:res1.data.data
  195. })
  196. })
  197. })
  198. $api.getBaikeRandom().then(res=>{
  199. this.setData({
  200. baikeList:res.data.data
  201. })
  202. })
  203. $api.getChampionlList({category:'每日点评',page:1}).then(res=>{
  204. this.setData({
  205. articleList1:res.data.data.list
  206. })
  207. })
  208. $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{
  209. this.setData({
  210. articleList2:res.data.data.list
  211. })
  212. })
  213. $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{
  214. this.setData({
  215. articleList3:res.data.data.list
  216. })
  217. })
  218. $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{
  219. this.setData({
  220. articleList4:res.data.data.list
  221. })
  222. })
  223. },
  224. //计算周数
  225. getWeekNumber:function(dateString) {
  226. const date = new Date(dateString);
  227. const year = date.getFullYear();
  228. // 将年份的第一个周一作为第一周的开始
  229. const firstWeekStart = new Date(year, 0, 1);
  230. firstWeekStart.setDate(firstWeekStart.getDate() - firstWeekStart.getDay() + 1);
  231. // 计算给定日期是一年中的第几周
  232. const currentDate = new Date(date);
  233. currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 1);
  234. let milliseconds = currentDate.getTime() - firstWeekStart.getTime();
  235. const weeks = Math.round(milliseconds / (7 * 24 * 60 * 60 * 1000));
  236. return weeks + 1; // 因为getWeek返回的是年初至今的周数,所以加1得到完整的周数
  237. },
  238. //获取今日留言
  239. getExp:function(){
  240. var list = this.data.explist
  241. $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{
  242. res.data.data.list.forEach(item => {
  243. list.push(item)
  244. })
  245. this.setData({
  246. explist: list,
  247. total1: res.data.data.total
  248. })
  249. })
  250. },
  251. //留言分页
  252. next1: function () {
  253. if (this.data.explist.length < this.data.total1) {
  254. const page = this.data.page1 + 1
  255. this.setData({
  256. page1: page
  257. })
  258. this.getExp()
  259. }
  260. },
  261. //我的关注
  262. getFollow(){
  263. var followList = this.data.followList
  264. if(this.data.loading){
  265. followList=[]
  266. }
  267. $api.getMyFollowV3({
  268. page: this.data.page2, page_size: 20
  269. }).then(res => {
  270. wx.hideNavigationBarLoading()
  271. res.data.data.list.forEach(item => {
  272. followList.push(item)
  273. })
  274. this.setData({
  275. followList: followList,
  276. total2:res.data.data.total,
  277. error:0,
  278. loading: 0
  279. })
  280. app.globalData.follow = 0
  281. })
  282. .catch(err=>{
  283. this.setData({
  284. error:1
  285. })
  286. })
  287. },
  288. //关注分页
  289. next2: function () {
  290. if (this.data.followList.length < this.data.total2) {
  291. const page = this.data.page2 + 1
  292. this.setData({
  293. page2: page
  294. })
  295. this.getFollow()
  296. }
  297. },
  298. tabChange(e){
  299. this.setData({
  300. cur:e.target.dataset.id
  301. })
  302. this.renew()
  303. },
  304. tabChange1(e){
  305. this.setData({
  306. cur1:e.target.dataset.id
  307. })
  308. },
  309. tapGroup(e){
  310. wx.navigateTo({
  311. url: '../avg/avg?index='+e.currentTarget.dataset.index + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  312. })
  313. },
  314. tapAvg(e){
  315. wx.navigateTo({
  316. url: '../avg/avg?index=0' + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
  317. })
  318. },
  319. //预览
  320. preview(e){
  321. wx.previewImage({
  322. urls: e.target.dataset.urls,
  323. current: e.target.dataset.src
  324. })
  325. },
  326. curChange(e){
  327. if (e.detail.source == "touch"){
  328. this.setData({
  329. cur: e.detail.current
  330. })
  331. this.renew()
  332. }
  333. },
  334. curChange1(e){
  335. if (e.detail.source == "touch"){
  336. this.setData({
  337. cur1: e.detail.current
  338. })
  339. }
  340. },
  341. renew(){
  342. this.setData({
  343. followList:[],
  344. explist:[],
  345. page1: 1,
  346. total1: 0,
  347. page2: 1,
  348. total2: -1
  349. })
  350. switch(this.data.cur){
  351. case 0:
  352. this.data.page1 = 1
  353. this.getExp()
  354. break;
  355. case 1:
  356. this.data.page2 = 1
  357. this.getFollow()
  358. break;
  359. }
  360. },
  361. pushToday(e){
  362. $push.pushToday(e.currentTarget.dataset)
  363. },
  364. onShow: function (e) {
  365. $api.initUser()
  366. $api.getsignup().then(res => {
  367. this.setData({
  368. info: res.data.data
  369. })
  370. })
  371. if(this.data.cur == 0 && app.globalData.follow == 1){
  372. this.data.loading = 1
  373. this.data.page2 = 1
  374. this.data.total2 = -1,
  375. this.getFollow()
  376. }
  377. },
  378. })