123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // nova-tourism/components/calendar/index.js
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- show:{
- type:Boolean,
- default: false
- },
- title: {
- type: String,
- value: '日期选择',
- },
- color: String,
- formatter: null,
- // defaultDate: {
- // type: null,
- // observer: function (val) {
- // this.setData({ currentDate: val });
- // this.scrollIntoView();
- // },
- // },
- },
- created: function () {
- this.setData({
- currentDate: this.getInitialDate(this.defaultDate),
- });
- },
- /**
- * 组件的初始数据
- */
- data: {
- subtitle: '',
- currentDate: null,
- scrollIntoView: '',
- startTime:'',
- endTime: ''
- },
- /**
- * 组件的方法列表
- */
- methods: {
- getInitialDate: function(defaultDate){
- let now = new Date()
- let currentYear = now.getFullYear();
- let currentMonth = now.getMonth()+1;
- let currentDay = now.getDay();
- // let months =
- if(!defaultDate){
-
- }
- },
- getInitialDate: function (defaultDate) {
- var _this = this;
- if (defaultDate === void 0) {// defaultDate 为undefined
- defaultDate = null;
- }
- let {type,minDate,maxDate} = this.data;
- var now = utils_1.getToday().getTime();
- if (type === 'range') {
- if (!Array.isArray(defaultDate)) {
- defaultDate = [];
- }
- var _b = defaultDate || [],
- startDay = _b[0],
- endDay = _b[1];
- var start = this.limitDateRange(
- startDay || now,
- minDate,
- utils_1.getPrevDay(new Date(maxDate)).getTime()
- );
- var end = this.limitDateRange(
- endDay || now,
- utils_1.getNextDay(new Date(minDate)).getTime()
- );
- return [start, end];
- }
- if (type === 'multiple') {
- if (Array.isArray(defaultDate)) {
- return defaultDate.map(function (date) {
- return _this.limitDateRange(date);
- });
- }
- return [this.limitDateRange(now)];
- }
- if (!defaultDate || Array.isArray(defaultDate)) {
- defaultDate = now;
- }
- return this.limitDateRange(defaultDate);
- },
- emit: function (date) {
- var getTime = function (date) {
- return date instanceof Date ? date.getTime() : date;
- };
- this.setData({
- currentDate: Array.isArray(date) ? date.map(getTime) : getTime(date),
- });
- this.$emit('select', utils_1.copyDates(date));
- },
- }
- })
|