|
@@ -9,35 +9,142 @@ Page({
|
|
|
data: {
|
|
|
hasAddress: false,
|
|
|
address: '',
|
|
|
- calendarcolor: '#45A6B5',
|
|
|
timeActive: '0',
|
|
|
appointmentSuccess: false,
|
|
|
- newDate: '',
|
|
|
curYear: '-',
|
|
|
curMonth: '-',
|
|
|
- maxDate: '',
|
|
|
- defaultDate: '',
|
|
|
- formatter(day) {
|
|
|
- const time = day.date.getTime();
|
|
|
- const cDate = new Date()
|
|
|
- const cyear = cDate.getFullYear()
|
|
|
- const cmonth = cDate.getMonth() + 1;
|
|
|
- const cdate = cDate.getDate();
|
|
|
- const str = cyear + '-' + cmonth + '-' + cdate
|
|
|
- if (time == new Date(str).getTime() || time == new Date(str).getTime() - 86400000) {
|
|
|
- day.text = '约满'
|
|
|
- day.type = 'disabled'
|
|
|
- day.className = 'calendar-all-full'
|
|
|
- }
|
|
|
- return day;
|
|
|
- }
|
|
|
+ weekList: [],
|
|
|
+ backupWeekList: [],
|
|
|
+ currentTime: '',
|
|
|
+ currentWeek: '',
|
|
|
+ currentYear: ''
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
+ this.initCalendar()
|
|
|
+ },
|
|
|
|
|
|
+ // 初始化日历
|
|
|
+ async initCalendar () {
|
|
|
+ var that = this
|
|
|
+ var currentDate = new Date()
|
|
|
+ this.setData({
|
|
|
+ currentTime: currentDate.getTime(),
|
|
|
+ currentWeek: currentDate.getDay(),
|
|
|
+ currentYear: currentDate.getFullYear(),
|
|
|
+ currentDay: currentDate.getDate()
|
|
|
+ })
|
|
|
+ await that.createCalendarGrild(33)
|
|
|
+ var _weekList = that.data.weekList
|
|
|
+ _weekList.map((item, index) => {
|
|
|
+ if (index == that.data.currentWeek) {
|
|
|
+ item.date = that.data.currentDay
|
|
|
+ }
|
|
|
+ })
|
|
|
+ that.setData({
|
|
|
+ weekList: _weekList
|
|
|
+ })
|
|
|
+ // 周一开始
|
|
|
+ if (that.data.currentWeek >= 1) {
|
|
|
+ that.setData({
|
|
|
+ weekList: that.setCalendarItem()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 周日
|
|
|
+ if (that.data.currentWeek < 1) {
|
|
|
+ let _bankupWeekList = []
|
|
|
+ for (let index = 0; index < 7; index++) {
|
|
|
+ const bDate = new Date(that.data.currentTime - (index + 1) * 86400000).getDate()
|
|
|
+ const _month = baseDate.getMonth() + 1
|
|
|
+ _bankupWeekList.unshift({
|
|
|
+ date: index == 0 ? '约满' : bDate.getDate(),
|
|
|
+ dateStr: bDate.getFullYear() + '-' + _month,
|
|
|
+ disabled: true,
|
|
|
+ status: ''
|
|
|
+ })
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ backupWeekList: _bankupWeekList,
|
|
|
+ weekList: that.setCalendarItem()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setCalendarItem () {
|
|
|
+ var that = this
|
|
|
+ var _mapWeekList = that.data.weekList
|
|
|
+ _mapWeekList.map((item, index) => {
|
|
|
+ const baseDate = new Date((index - that.data.currentWeek) * 86400000 + that.data.currentTime)
|
|
|
+ const _month = baseDate.getMonth() + 1
|
|
|
+ const _year = baseDate.getFullYear()
|
|
|
+ if (index > that.data.currentWeek) {
|
|
|
+ if (index == that.data.currentWeek + 1) {
|
|
|
+ item.active = true
|
|
|
+ that.setData({
|
|
|
+ curYear: _year,
|
|
|
+ curMonth: _month
|
|
|
+ })
|
|
|
+ }
|
|
|
+ item.date = baseDate.getDate()
|
|
|
+ item.dateStr = baseDate.getFullYear() + '-' + _month
|
|
|
+ } else {
|
|
|
+ item.disabled = true
|
|
|
+ item.dateStr = baseDate.getFullYear() + '-' + _month
|
|
|
+ if (index == that.data.currentWeek || index == that.data.currentWeek - 1) {
|
|
|
+ item.date = '约满'
|
|
|
+ } else {
|
|
|
+ item.date = baseDate.getDate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return _mapWeekList
|
|
|
+ },
|
|
|
+ createCalendarGrild (count) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ var _list = []
|
|
|
+ for (let index = 0; index < count; index++) {
|
|
|
+ _list.push({
|
|
|
+ date: '-',
|
|
|
+ dateStr: '-',
|
|
|
+ disabled: false,
|
|
|
+ active: false,
|
|
|
+ status: '',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ weekList: _list
|
|
|
+ })
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 选择日期
|
|
|
+ handleSelectDate (e) {
|
|
|
+ const disabled = e.currentTarget.dataset.disabled
|
|
|
+ if (!disabled) {
|
|
|
+ const cDate = e.currentTarget.dataset.date
|
|
|
+ const index = e.currentTarget.dataset.index
|
|
|
+
|
|
|
+ console.log(index, 'cDate');
|
|
|
+ const _year = cDate.split('-')[0]
|
|
|
+ const _month = cDate.split('-')[1]
|
|
|
+ const _weeklist = this.data.weekList
|
|
|
+ _weeklist[index].active = true
|
|
|
+ _weeklist.map((item, i) => {
|
|
|
+ if (index == i ) {
|
|
|
+ item.active = true
|
|
|
+ } else {
|
|
|
+ item.active = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ curYear: _year,
|
|
|
+ curMonth: _month,
|
|
|
+ weekList: _weeklist
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
@@ -49,24 +156,9 @@ Page({
|
|
|
address: app.globalData.navigateBackParams.address
|
|
|
})
|
|
|
}
|
|
|
- this.handleDate()
|
|
|
},
|
|
|
- // 处理日期
|
|
|
- handleDate () {
|
|
|
- const date = new Date()
|
|
|
- const time = date.getTime()
|
|
|
- const year = date.getFullYear()
|
|
|
- const month = date.getMonth() + 1
|
|
|
- const day = date.getDate()
|
|
|
- const str = year + '-' + month + '-' + day
|
|
|
- const _maxDate= 2592000000 + time
|
|
|
- const _defaultDate = new Date(str).getTime() + 86400000
|
|
|
- this.setData({
|
|
|
- curYear: year,
|
|
|
- curMonth: month,
|
|
|
- maxDate: _maxDate,
|
|
|
- defaultDate: _defaultDate
|
|
|
- })
|
|
|
+ formatterFn (day) {
|
|
|
+ console.log(day);
|
|
|
},
|
|
|
/**
|
|
|
* 选择地址
|
|
@@ -83,14 +175,6 @@ Page({
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- handleSelect (val) {
|
|
|
- var selectMonth = new Date(val.detail).getMonth() + 1
|
|
|
- var selectYear = new Date(val.detail).getFullYear()
|
|
|
- this.setData({
|
|
|
- curYear: selectYear,
|
|
|
- curMonth: selectMonth
|
|
|
- })
|
|
|
- },
|
|
|
handleTime (e) {
|
|
|
console.log(e);
|
|
|
var timeActiveIndex = e.currentTarget.dataset.time
|