Commit a45cb9de by liang ce

合并代码

parents 39b3bc13 c7ffaecb
...@@ -13,14 +13,14 @@ Page({ ...@@ -13,14 +13,14 @@ Page({
}, },
onReady() { onReady() {
let data = { let data = {
"startTime":"2020-01-01 00:00:00", "startTime": "2020-01-01 00:00:00",
"endTime":"2025-12-30 23:59:59" "endTime": "2025-12-30 23:59:59"
} }
let that = this let that = this
getHomeUserSchedule(data).then(res => { getHomeUserSchedule(data).then(res => {
that.setData({ that.setData({
AllScheduleList: res.data.data AllScheduleList: res.data.data
},() => { }, () => {
let now = new Date() let now = new Date()
let year = now.getFullYear(); let year = now.getFullYear();
let scheduleList = this.returnScheduleList(year); let scheduleList = this.returnScheduleList(year);
...@@ -33,63 +33,62 @@ Page({ ...@@ -33,63 +33,62 @@ Page({
onShow() { onShow() {
// 页面显示 // 页面显示
}, },
returnScheduleList (year) { returnScheduleList(year) {
let that = this let that = this
let weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'] let weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
let DateMap = new Map(); let DateMap = new Map();
let isLeapYear = year % 4 == 0 && year % 100 != 0 || year % 400 ==0 let isLeapYear = year % 4 == 0 && year % 100 != 0 || year % 400 == 0
if (isLeapYear) { if (isLeapYear) {
let isFirstWeek = false; let isFirstWeek = false;
for(let i = 1; i <= 366; i++) { for (let i = 1; i <= 366; i++) {
if (i<7 && new Date(year, 0, i).getDay() === 0) { if (i < 7 && new Date(year, 0, i).getDay() === 0) {
isFirstWeek = true isFirstWeek = true
} }
if (isFirstWeek) { if (isFirstWeek) {
DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, { DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, {
scheduleList:[] scheduleList: []
}) })
} }
} }
let num = 6 - new Date(year, 0, 366).getDay() let num = 6 - new Date(year, 0, 366).getDay()
for (let i = 0; i<=num;i++) { for (let i = 0; i <= num; i++) {
DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, { DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, {
scheduleList:[] scheduleList: []
}) })
} }
} else { } else {
let isFirstWeek = false; let isFirstWeek = false;
for(let i = 1; i <= 365; i++) { for (let i = 1; i <= 365; i++) {
if (i<7 && new Date(year, 0, i).getDay() === 0) { if (i < 7 && new Date(year, 0, i).getDay() === 0) {
isFirstWeek = true isFirstWeek = true
} }
if (isFirstWeek) { if (isFirstWeek) {
DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, { DateMap.set(`${new Date(year, 0, i).toLocaleDateString()}`, {
scheduleList:[] scheduleList: []
}) })
} }
} }
let num = 6 - new Date(year, 0, 366).getDate() let num = 6 - new Date(year, 0, 366).getDate()
for (let i = 0; i<=num;i++) { for (let i = 0; i <= num; i++) {
DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, { DateMap.set(`${new Date(year, 0, 366 + i).toLocaleDateString()}`, {
scheduleList:[] scheduleList: []
}) })
} }
} }
for(let y=0;y<this.data.AllScheduleList.length;y++) { for (let y = 0; y < this.data.AllScheduleList.length; y++) {
let date1 = this.data.AllScheduleList[y].startTime.slice(0,10).replace(/-/g, '/') let date1 = this.data.AllScheduleList[y].startTime.slice(0, 10).replace(/-/g, '/')
let date2 = this.data.AllScheduleList[y].endTime.slice(0,10).replace(/-/g, '/') let date2 = this.data.AllScheduleList[y].endTime.slice(0, 10).replace(/-/g, '/')
let count = this.count(date1, date2) let count = this.count(date1, date2)
if(count == 0) { if (count == 0) {
DateMap.get(`${new Date(this.data.AllScheduleList[y].startTime.replace(/-/g, '/')).toLocaleDateString()}`).scheduleList.push(this.data.AllScheduleList[y]) DateMap.get(`${new Date(this.data.AllScheduleList[y].startTime.replace(/-/g, '/')).toLocaleDateString()}`).scheduleList.push(this.data.AllScheduleList[y])
} else { } else {
for(let j = 0;j<=count;j++) { for (let j = 0; j <= count; j++) {
let time = new Date(); let time = new Date();
time.setDate(time.getDate()+j) time.setDate(time.getDate() + j)
// let finalDate = day.setDate(day.getDate()+j)
console.log(`${time.getFullYear()}/${time.getMonth()+1}/${time.getDate()}`) DateMap.get(new Date(time.getFullYear(), time.getMonth() + 1, time.getDate()).toLocaleDateString()).scheduleList.push({
DateMap.get(`${time.getFullYear()}/${time.getMonth()+1}/${time.getDate()}`).scheduleList.push({
...this.data.AllScheduleList[y], ...this.data.AllScheduleList[y],
number: j+1 number: j + 1
}) })
} }
} }
...@@ -103,13 +102,13 @@ Page({ ...@@ -103,13 +102,13 @@ Page({
value: year value: year
}) })
DateMap.forEach(function (value, key, map) { DateMap.forEach(function (value, key, map) {
if (new Date(key).getDay() === 0 && that.count(new Date(key),new Date(year, 0, isLeapYear ? 366 : 365) >= 7)) { if (new Date(key).getDay() === 0 && that.count(new Date(key), new Date(year, 0, isLeapYear ? 366 : 365) >= 7)) {
listWeek = listWeek + 1 listWeek = listWeek + 1
if (new Date(key).getMonth() !== listMonth) { if (new Date(key).getMonth() !== listMonth) {
listMonth = new Date(key).getMonth() listMonth = new Date(key).getMonth()
DateList.push({ DateList.push({
type: 'month', type: 'month',
value: new Date(key).getMonth()+1 value: new Date(key).getMonth() + 1
}) })
let rangeYear1 = new Date(key).getFullYear() let rangeYear1 = new Date(key).getFullYear()
let rangeMonth1 = new Date(key).getMonth() let rangeMonth1 = new Date(key).getMonth()
...@@ -119,7 +118,7 @@ Page({ ...@@ -119,7 +118,7 @@ Page({
let rangeDay2 = new Date(rangeDate).getDate() let rangeDay2 = new Date(rangeDate).getDate()
DateList.push({ DateList.push({
type: 'week', type: 'week',
value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1+ '月'}${rangeDay2}日`, value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1 + '月'}${rangeDay2}日`,
}) })
} else { } else {
let rangeYear1 = new Date(key).getFullYear() let rangeYear1 = new Date(key).getFullYear()
...@@ -130,10 +129,10 @@ Page({ ...@@ -130,10 +129,10 @@ Page({
let rangeDay2 = new Date(rangeDate).getDate() let rangeDay2 = new Date(rangeDate).getDate()
DateList.push({ DateList.push({
type: 'week', type: 'week',
value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1+ '月'}${rangeDay2}日`, value: `第${listWeek}周,${rangeMonth1 + 1}${rangeDay1}日 - ${rangeMonth2 == rangeMonth1 ? '' : rangeMonth2 + 1 + '月'}${rangeDay2}日`,
}) })
} }
} else if (new Date(key).getDay() === 0 && that.count(new Date(key),new Date(year, 0, isLeapYear ? 366 : 365) < 7)){ } else if (new Date(key).getDay() === 0 && that.count(new Date(key), new Date(year, 0, isLeapYear ? 366 : 365) < 7)) {
listWeek = 1 listWeek = 1
DateList.push({ DateList.push({
type: 'week', type: 'week',
...@@ -145,7 +144,7 @@ Page({ ...@@ -145,7 +144,7 @@ Page({
type: 'day', type: 'day',
value: { value: {
value: value.scheduleList, value: value.scheduleList,
day: new Date(key).getDate() < 10 ? '0'+ new Date(key).getDate() : new Date(key).getDate(), day: new Date(key).getDate() < 10 ? '0' + new Date(key).getDate() : new Date(key).getDate(),
week: weekList[new Date(key).getDay()] week: weekList[new Date(key).getDay()]
}, },
}) })
...@@ -154,10 +153,10 @@ Page({ ...@@ -154,10 +153,10 @@ Page({
console.log(DateList) console.log(DateList)
return DateList return DateList
}, },
count(date1, date2){ count(date1, date2) {
var date1=new Date(date1); var date1 = new Date(date1);
var date2=new Date(date2); var date2 = new Date(date2);
var date=(date2.getTime()-date1.getTime())/(1000*60*60*24);/*不用考虑闰年否*/ var date = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24);/*不用考虑闰年否*/
return date return date
}, },
onHide() { onHide() {
...@@ -186,7 +185,7 @@ Page({ ...@@ -186,7 +185,7 @@ Page({
nextPage() { nextPage() {
dd.navigateTo({ url: './../createOrEditSchedule/createOrEditSchedule' }) dd.navigateTo({ url: './../createOrEditSchedule/createOrEditSchedule' })
}, },
nextDetail (e) { nextDetail(e) {
let id = e.target.dataset.id let id = e.target.dataset.id
dd.navigateTo({ url: `./../scheduleDetail/scheduleDetail?id=${id}` }) dd.navigateTo({ url: `./../scheduleDetail/scheduleDetail?id=${id}` })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment