123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- // index.js
- // 获取应用实例
- const app = getApp()
- const $api = require('../../utils/api.js').API;
- const $push = require('../../utils/api.js').PUSH;
- Page({
- data: {
- loading:0,
- notices:[],
- tabs:['今日留言','我的关注'],
- tabs1:['收益榜','盈利榜','亏损榜','跌幅榜'],
- cur:0,
- cur1:0,
- date:'2022-04-27',
- explist:[], //留言
- total1:0,
- page1:1,
- followList:[], //关注
- total2:-1,
- page2:1,
- banners:[],
- winLost:{},
- baikeList:[],
- articleList1:[],
- articleList2:[],
- articleList3:[],
- articleList4:[],
- groups:{},
- role:0,
- match_day:0,
- socore:[10,9,8,7,6,5,4,3,2,1],
- isScore:0,
- isWeek:0,
- scoredays:[]
- },
- onLoad() {
- var w=new Date().getDay()
- if(w == 0 || w == 6){
- this.setData({
- isWeek:1
- })
- }
- wx.showNavigationBarLoading()
- wx.getStorage({
- key: 'user',
- complete: res => {
- this.setData({
- role: res.data.role,
- })
- }
- })
- $api.getDate().then(res=>{
- this.setData({
- date:res.data.data
- })
- $api.getNotoice().then(res=>{
- this.setData({
- notices:res.data.data
- })
- })
- // 是否打分
- var y=new Date().getFullYear()
- var m=Number(new Date().getMonth() + 1)
- var d = new Date().getDate()
- m=m>9?m:'0'+m;
- d=d>9?d:'0'+d
- var date = y+'-'+m+'-'+d
- if(!this.data.isWeek){
- $api.checkMark({stock_date:date}).then(res=>{
- if(res.data.data){
- this.setData({
- isScore:1
- })
- }
- })
- }
-
- })
- this.getFollow()
- this.getIndexData()
- this.getExp()
- this.getWeekAvg()
-
- },
- getWeekAvg:function(){
- $api.getMark().then(res=>{
- var days=res.data.data,weeks={}
- days.forEach(item=>{
- item.week=getYearWeek(item.stock_date)
- item.date=(new Date(item.stock_date).getMonth()+1)+'/'+(new Date(item.stock_date).getDate())
- weeks[item.week]=[]
- })
- days.forEach(item=>{
- weeks[item.week].push(item)
- })
- var scoredays=[]
- for (let key in weeks) {
- scoredays.push({
- name:key,
- data:weeks[key].reverse()
- })
- }
- this.setData({
- scoredays:scoredays.reverse()
- })
- })
-
- function getYearWeek(endDate) {
- //本年的第一天
- endDate=new Date(endDate)
- var beginDate = new Date(endDate.getFullYear(), 0, 1);
- //星期从0-6,0代表星期天,6代表星期六
- var endWeek = endDate.getDay();
- if (endWeek == 0) endWeek = 7;
- var beginWeek = beginDate.getDay();
- if (beginWeek == 0) beginWeek = 7;
- //计算两个日期的天数差
- var millisDiff = endDate.getTime() - beginDate.getTime();
- var dayDiff = Math.floor(( millisDiff + (beginWeek - endWeek) * (24 * 60 * 60 * 1000)) / 86400000);
- return Math.ceil(dayDiff / 7) + 1;
- }
- },
- radioChange:function(e){
- var y=new Date().getFullYear()
- var m=Number(new Date().getMonth() + 1)
- var d = new Date().getDate()
- m=m>9?m:'0'+m;
- d=d>9?d:'0'+d
- var date = y+'-'+m+'-'+d
- this.setData({
- s:e.detail.value
- })
- $api.markScore({stock_date:date,score:e.detail.value}).then(res=>{
- console.log(res)
- if(res.data.code == 0){
- wx.showToast({
- title: '打分成功',
- })
- this.setData({
- isScore:1
- })
- this.getWeekAvg()
- }
- })
- },
- fresh: function () {
- },
- // 获取首页数据
- getIndexData:function(){
-
- $api.getChampionlList({isbanner:1}).then(res=>{
- this.setData({
- banners:res.data.data.list
- })
- })
- $api.getWinList({new:1}).then(res=>{
- let day = res.data.data[0].valid_dates.indexOf(res.data.data[0].date)
- this.setData({
- winLost:res.data.data[0],
- match_day:day,
- })
- $api.getAvg({match_id:res.data.data[0].match_id}).then(res=>{
- var days=res.data.data.list,weeks=[]
- days=days.reverse()
- for(let i=0;i<55;i++){
- weeks.push({
- name:'',
- data:[],
- total:0
- })
- }
- days.forEach(item=>{
- var w=this.getWeekNumber(item.stock_date)
- weeks[w-1].data.push(item)
- })
- weeks=weeks.filter(item=>item.data.length>0)
- var w_text=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五']
- weeks.forEach((item,index)=>{
- if(item.data.length>0){
- item.name='第'+w_text[index]+'周'
- var total=0
- var money = 10000.0
- item.data.forEach(i=>{
- var incom=Number(i.today_income.replace('%',''))
- money += money*incom/100.0
- i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate())
- })
- total = (money-10000)*100.0/10000.0
- item.total=total.toFixed(2)
- }
- })
- this.setData({
- days:weeks.reverse()
- })
- })
- $api.getWinLose({match_id:res.data.data[0].match_id}).then(res1=>{
- this.setData({
- groups:res1.data.data
- })
- })
- })
- $api.getBaikeRandom().then(res=>{
- this.setData({
- baikeList:res.data.data
- })
- })
- $api.getChampionlList({category:'每日点评',page:1}).then(res=>{
- this.setData({
- articleList1:res.data.data.list
- })
- })
- $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{
- this.setData({
- articleList2:res.data.data.list
- })
- })
- $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{
- this.setData({
- articleList3:res.data.data.list
- })
- })
- $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{
- this.setData({
- articleList4:res.data.data.list
- })
- })
- },
- //计算周数
- getWeekNumber:function(dateString) {
- const date = new Date(dateString);
- const year = date.getFullYear();
- // 将年份的第一个周一作为第一周的开始
- const firstWeekStart = new Date(year, 0, 1);
- firstWeekStart.setDate(firstWeekStart.getDate() - firstWeekStart.getDay() + 1);
- // 计算给定日期是一年中的第几周
- const currentDate = new Date(date);
- currentDate.setDate(currentDate.getDate() - currentDate.getDay() + 1);
- let milliseconds = currentDate.getTime() - firstWeekStart.getTime();
- const weeks = Math.round(milliseconds / (7 * 24 * 60 * 60 * 1000));
- return weeks + 1; // 因为getWeek返回的是年初至今的周数,所以加1得到完整的周数
- },
- //获取今日留言
- getExp:function(){
- var list = this.data.explist
- $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{
- res.data.data.list.forEach(item => {
- list.push(item)
- })
- this.setData({
- explist: list,
- total1: res.data.data.total
- })
- })
- },
- //留言分页
- next1: function () {
- if (this.data.explist.length < this.data.total1) {
- const page = this.data.page1 + 1
- this.setData({
- page1: page
- })
- this.getExp()
- }
- },
- //我的关注
- getFollow(){
- var followList = this.data.followList
- if(this.data.loading){
- followList=[]
- }
- $api.getMyFollowV3({
- page: this.data.page2, page_size: 20
- }).then(res => {
- wx.hideNavigationBarLoading()
- res.data.data.list.forEach(item => {
- followList.push(item)
- })
- this.setData({
- followList: followList,
- total2:res.data.data.total,
- error:0,
- loading: 0
- })
- app.globalData.follow = 0
- })
- .catch(err=>{
- this.setData({
- error:1
- })
- })
- },
- //关注分页
- next2: function () {
- if (this.data.followList.length < this.data.total2) {
- const page = this.data.page2 + 1
- this.setData({
- page2: page
- })
- this.getFollow()
- }
- },
- tabChange(e){
- this.setData({
- cur:e.target.dataset.id
- })
- this.renew()
- },
- tabChange1(e){
- this.setData({
- cur1:e.target.dataset.id
- })
- },
- tapGroup(e){
- wx.navigateTo({
- url: '../avg/avg?index='+e.currentTarget.dataset.index + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
- })
- },
- tapAvg(e){
- wx.navigateTo({
- url: '../avg/avg?index=0' + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)),
- })
- },
- //预览
- preview(e){
- wx.previewImage({
- urls: e.target.dataset.urls,
- current: e.target.dataset.src
- })
- },
- curChange(e){
- if (e.detail.source == "touch"){
- this.setData({
- cur: e.detail.current
- })
- this.renew()
- }
- },
- curChange1(e){
- if (e.detail.source == "touch"){
- this.setData({
- cur1: e.detail.current
- })
- }
- },
- renew(){
- this.setData({
- followList:[],
- explist:[],
- page1: 1,
- total1: 0,
- page2: 1,
- total2: -1
- })
- switch(this.data.cur){
- case 0:
- this.data.page1 = 1
- this.getExp()
- break;
- case 1:
- this.data.page2 = 1
- this.getFollow()
- break;
- }
- },
- pushToday(e){
- $push.pushToday(e.currentTarget.dataset)
- },
- onShow: function (e) {
- $api.initUser()
-
- $api.getsignup().then(res => {
- this.setData({
- info: res.data.data
- })
- })
-
- if(this.data.cur == 0 && app.globalData.follow == 1){
- this.data.loading = 1
- this.data.page2 = 1
- this.data.total2 = -1,
- this.getFollow()
- }
- },
- })
|