var signInfo={1645545600: 1 1645632000: 1 1645718400: 1 1645804800: 1 1645891200: -1 1645977600: 1 1646064000: 1 1646150400: 1 1646236800: 1 1646323200: 1 1646409600: -1 1646496000: -1 1646582400: 1 1646668800: 1 1646755200: 0 1646841600: 0 1646928000: 0 1647014400: 0 1647100800: 0 1647187200: 0 1647273600: 0 1647360000: 0 1647446400: 0 1647532800: 0 1647619200: 0 1647705600: 0 1647792000: 0 1647878400: 0 1647964800: 0 1648051200: 0 1648137600: 0 1648224000: 0 1648310400: 0 1648396800: 0 1648483200: 0 1648569600: 0 1648656000: 0 1648742400: 0 1648828800: 0 1648915200: 0 1649001600: 0 1649088000: 0 1649174400: 0}
<calendar allSignDay='{{totalSignDays}}'
seriesSignDays="{{seriesSignDays}}"
updown="{{tabsReal.length}}"
dateCalendar="{{signInfo}}"
bind:datechange="requestdata"
bind:calendarStatus="calendarStatus"
bind:showposter="showPoster"></yt-calendar>
<wxs module="calendartool">
var getType = function (status, currentMonthFlag, dates) {
var str =8
// 上个月
if(currentMonthFlag===-1){
// 上月已签
if(status===1){
str = 1
}
// 上月缺签
if(status===-1){
str = 2
}
}
// 本月
if(currentMonthFlag===0){
// 本月已签
if(status===1){
// 日历年月日
var date = getDate(dates*1000)
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
// today 年月日
var yearnow = getDate().getFullYear();
var monthnow = getDate().getMonth() + 1;
var daynow = getDate().getDate();
if(year === yearnow&&month===monthnow&&day===daynow){
// 今日已签
str = 3
}else{
// 非今日已签
str = 4
}
}
// 本月缺签
if(status===-1) {
str = 5
}
// 本月未签
if(status===0){
// 日历年月日
var date = getDate(dates*1000)
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
// today 年月日
var yearnow = getDate().getFullYear();
var monthnow = getDate().getMonth() + 1;
var daynow = getDate().getDate();
if(year === yearnow&&month===monthnow&&day===daynow){
// 今日未签
str = 6
}else{
// 本月今日之后未签
str = 7
}
}
}
// 下个月
if(currentMonthFlag===1){
str = 8
}
return str;
};
var getStatus = function (item, index) {
var str =''
var status =item.punchFlag
if(status==-1){
str = '缺签'
}
if(status==0){
// 日历年月日
str = '+7'
if(item.seriesSignDays>-1){
str = '+'+item.seriesSignDays
}
}
if(status==1){
str = '已签'
}
return str;
};
var stamptimeTodate = function (dates) {
var str =''
// 日历年月日
var date = getDate(dates*1000)
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
// today 年月日
var yearnow = getDate().getFullYear();
var monthnow = getDate().getMonth() + 1;
var daynow = getDate().getDate();
if(year === yearnow&&month===monthnow&&day===daynow){
str = '今日'
}else{
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
str = month+'.' +day;
}
return str;
};
var getToday = function (dates) {
var str = dates
var year= dates.slice(0,4)
var month= dates.slice(5,7)
str = year +'年' +month;
return str;
};
module.exports = {
stamptimeTodate:stamptimeTodate,
getStatus: getStatus,
getToday:getToday,
getType: getType
};
</wxs>
<view class="calendar">
<view class="calendar-head">
<view class="sign-days">
<text class="hint">已累计签到</text>
<text class="hint-day">{{allSignDay}}</text>
<text class="hint">天</text>
</view>
<view class="date-hint" wx:if="{{!toggleFlag}}">
<image
bind:tap="getPreMonth"
class="arrow"
src="credit/leftarrow.png"></image>
<!-- <i-icon
name="sright"
size="12"
color="#a9a9a9"
class="arrow"></i-icon> -->
<!-- <view class="date">{{calendartool.getToday(today)}}</view> -->
<view class="date">{{calendartool.getToday(today)}}</view>
<image
bind:tap="getNextMonth"
class="arrow"
src="credit/rightarrow.png"></image>
<!-- <i-icon name="sright"
bind:tap="getNextMonth"
size="12"
color="#a9a9a9"
class="arrow"></i-icon> -->
</view>
</view>
<view class="week">
<view class="weekday"
data-item="{{item}}"
wx:for="{{weeks}}"
wx:key="{{index}}">
<text class="num">{{item}}</text>
</view>
</view>
<!-- wx:for="{{signInfo}}"
wx:for-index="key"
wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===1}}"
wx:for-item="value" -->
<view class="calendarbody">
<view class="calendar-day"
data-item="{{item}}"
wx:for="{{calendarData}}"
wx:key="{{item.dateCalendar}}">
<view class="day" data-item="{{item}}" bind:tap="showposter">
<!-- {{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}} -->
<!--type 1 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===1}}">
<view class="upday1">
<image
class="upicon"
src="credit/sign.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint1">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 2 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===2}}">
<view class="upday2">
<image
class="upicon"
src="credit/nosign.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint2">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 3 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===3}}">
<view class="upday3">
<image
class="upicon"
src="credit/sign.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint3">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 4 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===4}}">
<view class="upday4">
<image
class="upicon"
src="credit/sign.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint4">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 5 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===5}}">
<view class="upday5">
<image
class="upicon"
src="credit/nosign.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint5">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 6 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===6}}">
<view class="upday6">
<image
class="upicon"
src="/tinygolden.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint6">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 7 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===7}}">
<view class="upday7">
<image
class="upicon"
src="credit/tinygolden.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint7">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
<!--type 8 -->
<block wx:if="{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)===8}}">
<view class="upday8">
<image
class="upicon"
src="credit/tinygolden.png"></image>
<text class="sign">{{calendartool.getStatus(item,index)}}</text>
<!-- <text
class="sign">{{calendartool.getType(item.punchFlag,item.currentMonth,item.dateCalendar)}}</text> -->
</view>
<text class="downhint8">{{calendartool.stamptimeTodate(item.dateCalendar)}}</text>
</block>
</view>
</view>
</view>
<view class="shrik" bind:tap="changeCalendar"> <image wx:if="{{toggleFlag}}" class="icon-up" src="credit/downarrow.png"></image>
<image wx:else class="icon-up" src="credit/uparrow.png"></image>
</view>
</view>
.calendar{
padding:24rpx 16rpx 0rpx 16rpx;
background: #FFFFFF;
box-shadow: 0rpx 8rpx 10rpx 0rpx rgba(0,0,0,0.03);
border-radius: 16rpx;
width: 664rpx;
.calendar-head{
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
height: 44rpx;
.sign-days{
display: flex;
flex:1;
flex-direction: row;
align-items: center;
.hint-day{
font-size: 32rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #FF6B30 ;
}
.hint{
font-size: 32rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #333333;
}
}
.date-hint{
display: flex;
height: 34rpx;
flex-direction: row;
align-items: center;
justify-content: center;
.arrow{
width: 12rpx;
height: 16rpx;
padding-top: 10rpx;
padding-left: 10rpx;
padding-right: 10rpx;
padding-bottom: 10rpx;
position: relative;
}
.arrow::before{
content: ' ';
position: absolute;
top: -10px; right: -10px; bottom: -10px; left: -10px;
}
.date{
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #666666;
}
}
}
.week {
display: flex;
width: 100%;
flex-direction: row;
align-items: center;
margin-top:20rpx;
.weekday{
flex:1;
height: 34rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
margin-right: 34rpx;
&:last-child{
margin-right: 0rpx;
}
.num{
height: 34rpx;
width: 64rpx;
font-size: 24rpx;
text-align: center;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #333333;
}
}
}
.calendarbody{
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
width: 100%;
height: 794;
.calendar-day {
display: flex;
flex-direction: row;
flex:1;
width: 64rpx;
height: 130rpx;
margin-right: 34rpx;
margin-top: 20rpx;
&:nth-child(7n){
margin-right: 0rpx;
}
.day{
width: 64rpx;
height: 130rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upday1{
width: 64rpx;
height: 88rpx;
background: #FFA480;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height: 32rpx;
}
.sign{
padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
}
}
.downhint1{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #808080;
}
.upday2{
width: 64rpx;
height: 88rpx;
background: #F0F0F0;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #808080;
}
}
.downhint2{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #808080;
}
.upday3{
width: 64rpx;
height: 88rpx;
background: #FF6B30;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
}
}
.downhint3{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #FF6B30;
}
.upday4{
width: 64rpx;
height: 88rpx;
background: #FF6B30;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
}
}
.downhint4{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #666666;
}
.upday5{
width: 64rpx;
height: 88rpx;
background: #EEEEEE;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #666666;
}
}
.downhint5{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #666666;
}
.upday6{
width: 64rpx;
height: 88rpx;
background: #FFEDD9;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
// padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FF6B30;
}
}
.downhint6{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #FF6B30;
}
.upday7{
width: 64rpx;
height: 88rpx;
background: #FFEDD9 ;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
// padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FF6B30;
}
}
.downhint7{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 500;
color: #666666;
}
.upday8{
width: 64rpx;
height: 88rpx;
background: #F0F0F0;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.upicon{
width:32rpx;
height:32rpx;
}
.sign{
// padding-top: 6rpx;
font-size: 20rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #808080;
}
}
.downhint8{
margin-top: 8rpx;
font-size: 24rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #808080;
}
}
}
}
.shrik{
margin-top: 10rpx;
margin-bottom: 8rpx;
width: 100%;
height: 25rpx;
display: flex;
align-items: center;
justify-content: center;
.icon-up{
width: 38rpx;
height: 14rpx;
}
}
}
const app = getApp();
Component({ // 声明组件属性及默认值
properties: {
allSignDay: {
type: Number, // 必需 指定属性类型 [String, Number, Boolean, Object, Array, null(任意类型)]
value: 0
},
seriesSignDays:{
type: Number, // 必需 指定属性类型 [String, Number, Boolean, Object, Array, null(任意类型)]
value: 0
},
dateCalendar: {
type: Object,
value: {}
},
updown: {
type: Number,
value: 3
}
},
data: {
weeks: [
'日',
'一',
'二',
'三',
'四',
'五',
'六'
],
today: null,
"totalSignDays": 1,
"signInfo": null,
toggleFlag: true,
currentWeek: null,
calendarData: null,
userInfo: {
},
},
observers: {
updown: function (flag) {
},
dateCalendar: function (newSignInfo) { // 找到当月第一天 并算出第一天在一周的第n天 筛选出上月显示在本页面前面的n天
if(newSignInfo===''||newSignInfo===null||newSignInfo===undefined){
return
}
if(this.data.today===null){
let todayymd = this.getToday()
this.setData({
today: todayymd
})
}
let tempArr = [];
var dateMonthFirstDay = new Date(this.data.today);
dateMonthFirstDay.setDate(1);
dateMonthFirstDay.setHours(0);
dateMonthFirstDay.setSeconds(0);
dateMonthFirstDay.setMinutes(0);
var num = new Date(dateMonthFirstDay).getDay()
var dateMonthFirstDayStamp = dateMonthFirstDay.getTime() / 1000 - (num) * 24 * 60 * 60
for (const key in newSignInfo) {
if (Object.hasOwnProperty.call(newSignInfo, key)) {
if (key >= dateMonthFirstDayStamp) {
const value = newSignInfo[key];
let temjson = {
dateCalendar: key,
punchFlag: value,
currentMonth: 0,
seriesSignDays:-1
} // -1 上个月 0本月 1下个月 将数组分为3个部分
tempArr.push(temjson)
}
}
}
console.log('today',this.data.today)
// 由于本日历设计必然是7的倍数 取余 之后 把尾巴切除即可
var remainder = tempArr.length % 7
tempArr.splice(tempArr.length - remainder)
var currentMonthDay = this.getCurrentMonthDayNum()
var userCurrentTime = Number(new Date().getTime()/1000) ;
for (let index = 0; index < tempArr.length; index++) {
const element = tempArr[index];
if (index < num) {
element.currentMonth = -1
} else if (index > (currentMonthDay + num-1)) {
element.currentMonth = 1
}
}
// 对于 日期当月之前的一个月的情况 进行过去与现在的筛选(当月的前一月)
if((userCurrentTime>tempArr[currentMonthDay + num-1].dateCalendar)&&(userCurrentTime<tempArr[tempArr.length-1].dateCalendar)){
for (let index = 0; index < tempArr.length; index++) {
const element = tempArr[index];
if(index <=(currentMonthDay + num-1)){
element.currentMonth= -1
}else{
element.currentMonth= 0
}
}
}
// 比较 用户当前使用时间(不是日历显示的月份)cur 与 当前日历 第一个与最后一个 tempArr[0]<cur<tempArr[tempArr.length-1] 表示当月2 cur<tempArr[0] 上个月(过去) 3 cur>tempArr[tempArr.length-1] 下个月(未来)
// 真正将数据 判定为过去 现在 未来 3部分
// var userCurrentTime = Number(new Date().getTime()/1000) ;
if(userCurrentTime < Number(tempArr[0].dateCalendar)){
// 未来
for (let index = 0; index < tempArr.length; index++) {
const element = tempArr[index];
let calendarday = new Date(element.dateCalendar*1000)
let calendarmonth=calendarday.getMonth()+1;// 获取当前月 默认0-11
let today = new Date()
let currentmonth=today.getMonth()+1;// 获取当前月 默认0-11
if(currentmonth===calendarmonth){
element.currentMonth = 0
}else{
element.currentMonth= 1
}
}
}
if(userCurrentTime>Number((tempArr[tempArr.length-1].dateCalendar))){
// 过去
for (let index = 0; index < tempArr.length; index++) {
const element = tempArr[index];
element.currentMonth= -1
}
}
// 下 +2.。。+7
var flag = false
var countSeriesDay = this.data.seriesSignDays
for (let index = 0; index < tempArr.length; index++) {
const itemdate = tempArr[index];
// 获取今天 的index
let date = this.getYyMmDd(Number(itemdate.dateCalendar))
console.log('date11',date + this.data.today )
if(this.getToday() === date){
flag =true
}
if(flag&&countSeriesDay<7){
itemdate.seriesSignDays = countSeriesDay
++countSeriesDay
}
// 强制1个金币
itemdate.seriesSignDays = 1
}
this.setData({signInfo: tempArr})
if(Array.isArray(tempArr)&&this.data.signInfo.length===0){
return
}
if( this.data.today === this.getToday()){
this.currentweek()
}else{
this.setData({ calendarData:this.data.signInfo})
}
},
},
async atached(){
},
async ready(){
const { userInfo } = await app.get(['userInfo', 'openId'])
this.setData({
userInfo
})
app.watch('userInfo', userInfo => {
this.setData({
userInfo
})
})
},
methods: {
// 计算这个月有多少天
getCurrentMonthDayNum() {
let d = new Date(this.data.today)
// 将日期设置为下月一号
d.setMonth(d.getMonth()+1)
d.setDate('1')
// 获取本月最后一天
d.setDate(d.getDate()-1)
return d.getDate()
},
async showposter(e) {
const item = e.currentTarget.dataset ?. item || {}
app.track.CPA_point_calendar_click()
if(item.punchFlag===1){
try {
if(!this.data.userInfo.nickName){
const res = await app.authByProfile()
this.setData({
userInfo: res.userInfo
})
this.triggerEvent('showposter', {userInfo:res.userInfo})
}else{
this.triggerEvent('showposter', item)
}
} catch (error) {
// app.toast('获取昵称才能生成专属海报哦!')
}
}
},
currentweek() { // 当前天的周 日历年月日
var today = new Date()
var currentyear= today.getFullYear(); // 获取当前年
var currentmonth=today.getMonth();// 获取当前月 默认0-11
var currentday=today.getDate(); // 获取当前日
var week = today.getDay()
// 找到当天在数组中索引
var num = -1
for (let index = 0; index < this.data.signInfo.length; index++) {
const element = Number(this.data.signInfo[index].dateCalendar*1000);
let arrDates = new Date(element)
let arrDatesYear= arrDates.getFullYear(); // 获取年
let arrDatesMonth=arrDates.getMonth();// 获取月 默认0-11
let arrDatesDay=arrDates.getDate(); // 获取日
if (currentyear === arrDatesYear&¤tmonth===arrDatesMonth&&arrDatesDay===currentday) {
num = index
}
}
var startIndex = num - week
var currentWeek = this.data.signInfo.slice(startIndex, startIndex + 7)
this.setData({currentWeek: currentWeek})
if(this.data.toggleFlag){
this.setData({calendarData:currentWeek})
}else{
this.setData({
calendarData:this.data.signInfo
})
}
// 只有一个tab的时候默认展开
if(this.data.updown===1){
this.setData({
toggleFlag:false
})
if(this.data.toggleFlag===false){
this.setData({
calendarData:this.data.signInfo
})
}else{
this.setData({
calendarData:this.data.currentWeek
})
}
}
},
changeCalendar(){
this.setData({
toggleFlag:!this.data.toggleFlag
})
if(this.data.toggleFlag===false){
this.setData({
calendarData:this.data.signInfo
})
}else{
this.setData({
calendarData:this.data.currentWeek
})
app.track.CPA_point_calendar_open_click('关闭')
}
this.triggerEvent('calendarStatus',{toggleFlag:this.data.toggleFlag})
},
getToday(){
var today = new Date()
var currentyear= today.getFullYear(); // 获取当前年
var currentmonth=today.getMonth()+1;// 获取当前月 默认0-11
if(currentmonth<10){
currentmonth='0'+currentmonth
}
var currentday=today.getDate(); // 获取当前日
if(currentday<10){
currentday='0'+currentday
}
return currentyear+'-'+currentmonth+'-'+currentday
},
getYyMmDd(date){
var today = new Date(date*1000)
var currentyear= today.getFullYear(); // 获取当前年
var currentmonth=today.getMonth()+1;// 获取当前月 默认0-11
if(currentmonth<10){
currentmonth='0'+currentmonth
}
var currentday=today.getDate(); // 获取当前日
if(currentday<10){
currentday='0'+currentday
}
return currentyear+'-'+currentmonth+'-'+currentday
},
/**
* 获取上一个月
* @date 格式为yyyy-mm-dd的日期,如:2014-01-25
*/
getPreMonth(date) {
var arr = this.data.today.split('-');
var year = arr[0]; // 获取当前日期的年份
var month = arr[1]; // 获取当前日期的月份
var day = arr[2]; // 获取当前日期的日
var days = new Date(year, month, 0);
days = days.getDate(); // 获取当前日期中月的天数
var year2 = year;
var month2 = Number(month) - 1;
if (month2 == 0) {
year2 = Number(year2) - 1;
month2 = 12;
}
var day2 = day;
var days2 = new Date(year2, month2, 0);
days2 = days2.getDate();
if (day2 > days2) {
day2 = days2;
}
if (month2 < 10) {
month2 = '0' + month2;
}
var t2 = year2 + '-' + month2 + '-' + day2;
this.setData({
today: t2
})
app.track.CPA_point_calendar_open_click(t2)
this.triggerEvent('datechange',{dateparam:t2})
return t2;
},
/**
* 获取下一个月
* @date 格式为yyyy-mm-dd的日期,如:2014-01-25
*/
getNextMonth(date) {
var arr = this.data.today.split('-');
var year = arr[0]; // 获取当前日期的年份
var month = arr[1]; // 获取当前日期的月份
var day = arr[2]; // 获取当前日期的日
var days = new Date(year, month, 0);
days = days.getDate(); // 获取当前日期中的月的天数
var year2 = year;
var month2 = Number(month) + 1;
if (month2 == 13) {
year2 = Number(year2) + 1;
month2 = 1;
}
var day2 = day;
var days2 = new Date(year2, month2, 0);
days2 = days2.getDate();
if (day2 > days2) {
day2 = days2;
}
if (month2 < 10) {
month2 = '0' + month2;
}
var t2 = year2 + '-' + month2 + '-' + day2;
this.setData({
today: t2
})
app.track.CPA_point_calendar_open_click(t2)
this.triggerEvent('datechange',{dateparam:t2})
return t2;
}
}
})