index.js 9.2 KB

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