|
|
|
@ -1,11 +1,16 @@ |
|
|
|
<template> |
|
|
|
<view class="calendar-box"> |
|
|
|
<view class="month lf-p-l-10 lf-p-r-10"> |
|
|
|
<view @click="lastMonth" v-if="havePre">上月</view> |
|
|
|
<view>{{year}}年{{month}}月</view> |
|
|
|
<view @click="nextMonth" v-if="haveNext">下月</view> |
|
|
|
</view> |
|
|
|
<view class="week"> |
|
|
|
<view :style="'color:'+(weeks==weeked?bgweek:'')+';'" v-for="weeks in weekArr">{{weeks}}</view> |
|
|
|
<view v-for="weeks in weekArr">{{weeks}}</view> |
|
|
|
</view> |
|
|
|
<view class="day"> |
|
|
|
<view :class="[{'checkday':days.date==''},{'choose':days.date==localDate}]" |
|
|
|
:style="'background:'+(days.date==localDate?bgday:'')+';'" v-for="(days,index) in dayArr" :key="index"> |
|
|
|
<view :class="[{'checkday':days.date==''},{'choose':days.flag==true}]" |
|
|
|
:style="'background:'+(days.flag==true?bgday:'')+';'" v-for="(days,index) in dayArr" :key="index"> |
|
|
|
{{days.day}} |
|
|
|
<view :class="[{'circle':days.flag},{'repair':days.day<day},{'sign':days.day==day}]"></view> |
|
|
|
</view> |
|
|
|
@ -35,6 +40,14 @@ |
|
|
|
bgday: { |
|
|
|
type: String, |
|
|
|
default: '#1998FE' |
|
|
|
}, |
|
|
|
startTime: { |
|
|
|
type: String, |
|
|
|
default: '' |
|
|
|
}, |
|
|
|
endTime: { |
|
|
|
type: String, |
|
|
|
default: '' |
|
|
|
} |
|
|
|
}, |
|
|
|
data() { |
|
|
|
@ -46,10 +59,17 @@ |
|
|
|
year: new Date().getFullYear(), // 当前年 |
|
|
|
month: new Date().getMonth() + 1, // 当前月 |
|
|
|
weekArr: ['日', '一', '二', '三', '四', '五', '六'], // 每周 |
|
|
|
selfDays: 0, |
|
|
|
havePre: false, |
|
|
|
haveNext: false |
|
|
|
} |
|
|
|
}, |
|
|
|
onShow() { |
|
|
|
|
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
let that = this; |
|
|
|
that.dateDiff(that.startTime,that.endTime); |
|
|
|
// 初始日期 |
|
|
|
that.initDate(); |
|
|
|
// 今天日期 |
|
|
|
@ -61,7 +81,31 @@ |
|
|
|
// 签到功能 |
|
|
|
if (that.type != 'calendar') { |
|
|
|
for (let i in that.dayArr) { |
|
|
|
that.$set(that.dayArr[i], 'flag', false); |
|
|
|
let chooseList = [] |
|
|
|
if(that.selfDays) { |
|
|
|
var dataStart = that.startTime.split('-'); |
|
|
|
var endStart = that.endTime.split('-'); |
|
|
|
let numberStart = Number(dataStart[2]) |
|
|
|
let nowMonth = new Date().getMonth() + 1; |
|
|
|
let splitStartMonth = dataStart[1]; |
|
|
|
let splitEndMonth = endStart[1]; |
|
|
|
console.log('当前月',nowMonth) |
|
|
|
console.log('传来的月份',that.month) |
|
|
|
if(that.month < nowMonth) { |
|
|
|
console.log('小于当前月') |
|
|
|
this.havePre = true |
|
|
|
}else if(splitEndMonth > nowMonth){ |
|
|
|
console.log('大于当前月') |
|
|
|
this.haveNext = true |
|
|
|
} |
|
|
|
var totalDays = Number(that.selfDays) + Number(dataStart[2]); |
|
|
|
for(let j = numberStart;j < totalDays;j++) { |
|
|
|
if(that.dayArr[i].day == j && that.dayArr[i].date) { |
|
|
|
that.$set(that.dayArr[i], 'flag', true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// that.$set(that.dayArr[i], 'flag', false); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -98,6 +142,39 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
dateDiff(sDate1,sDate2) { |
|
|
|
var aDate, oDate1, oDate2, iDays; |
|
|
|
aDate = sDate1.split('-'); |
|
|
|
console.log('addate',aDate[1]) |
|
|
|
if(aDate[1] == '01') { |
|
|
|
this.month = 1 |
|
|
|
}else if (aDate[1] == '02') { |
|
|
|
this.month = 2 |
|
|
|
}else if (aDate[1] == '03') { |
|
|
|
this.month = 3 |
|
|
|
}else if (aDate[1] == '04') { |
|
|
|
this.month = 4 |
|
|
|
}else if (aDate[1] == '05') { |
|
|
|
this.month = 5 |
|
|
|
}else if (aDate[1] == '06') { |
|
|
|
this.month = 6 |
|
|
|
}else if (aDate[1] == '07') { |
|
|
|
this.month = 7 |
|
|
|
}else if (aDate[1] == '08') { |
|
|
|
this.month = 8 |
|
|
|
}else if (aDate[1] == '09') { |
|
|
|
this.month = 9 |
|
|
|
}else{ |
|
|
|
this.month = Number(aDate[1]) |
|
|
|
} |
|
|
|
if(aDate[1]) |
|
|
|
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); |
|
|
|
aDate = sDate2.split('-'); |
|
|
|
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); |
|
|
|
iDays = parseInt(Math.abs(oDate1 - oDate2) /1000/60/60/24); |
|
|
|
this.selfDays = iDays+1; |
|
|
|
return iDays + 1; |
|
|
|
}, |
|
|
|
// 初始化日期 |
|
|
|
initDate() { |
|
|
|
let that = this; |
|
|
|
@ -115,8 +192,6 @@ |
|
|
|
obj.date = that.year + '-' + that.formatNum(that.month) + '-' + that.formatNum(i); |
|
|
|
obj.day = i; |
|
|
|
that.dayArr.push(obj); |
|
|
|
// 补充后面空白日期 |
|
|
|
console.log('当前越日期',that.dayArr) |
|
|
|
if (i == totalDay && value != 6) that.addAfter(value); |
|
|
|
} |
|
|
|
}, |
|
|
|
|