index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // nova-tourism/components/calendar/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. show:{
  8. type:Boolean,
  9. default: false
  10. },
  11. title: {
  12. type: String,
  13. value: '日期选择',
  14. },
  15. color: String,
  16. formatter: null,
  17. // defaultDate: {
  18. // type: null,
  19. // observer: function (val) {
  20. // this.setData({ currentDate: val });
  21. // this.scrollIntoView();
  22. // },
  23. // },
  24. },
  25. created: function () {
  26. this.setData({
  27. currentDate: this.getInitialDate(this.defaultDate),
  28. });
  29. },
  30. /**
  31. * 组件的初始数据
  32. */
  33. data: {
  34. subtitle: '',
  35. currentDate: null,
  36. scrollIntoView: '',
  37. startTime:'',
  38. endTime: ''
  39. },
  40. /**
  41. * 组件的方法列表
  42. */
  43. methods: {
  44. getInitialDate: function(defaultDate){
  45. let now = new Date()
  46. let currentYear = now.getFullYear();
  47. let currentMonth = now.getMonth()+1;
  48. let currentDay = now.getDay();
  49. // let months =
  50. if(!defaultDate){
  51. }
  52. },
  53. getInitialDate: function (defaultDate) {
  54. var _this = this;
  55. if (defaultDate === void 0) {// defaultDate 为undefined
  56. defaultDate = null;
  57. }
  58. let {type,minDate,maxDate} = this.data;
  59. var now = utils_1.getToday().getTime();
  60. if (type === 'range') {
  61. if (!Array.isArray(defaultDate)) {
  62. defaultDate = [];
  63. }
  64. var _b = defaultDate || [],
  65. startDay = _b[0],
  66. endDay = _b[1];
  67. var start = this.limitDateRange(
  68. startDay || now,
  69. minDate,
  70. utils_1.getPrevDay(new Date(maxDate)).getTime()
  71. );
  72. var end = this.limitDateRange(
  73. endDay || now,
  74. utils_1.getNextDay(new Date(minDate)).getTime()
  75. );
  76. return [start, end];
  77. }
  78. if (type === 'multiple') {
  79. if (Array.isArray(defaultDate)) {
  80. return defaultDate.map(function (date) {
  81. return _this.limitDateRange(date);
  82. });
  83. }
  84. return [this.limitDateRange(now)];
  85. }
  86. if (!defaultDate || Array.isArray(defaultDate)) {
  87. defaultDate = now;
  88. }
  89. return this.limitDateRange(defaultDate);
  90. },
  91. emit: function (date) {
  92. var getTime = function (date) {
  93. return date instanceof Date ? date.getTime() : date;
  94. };
  95. this.setData({
  96. currentDate: Array.isArray(date) ? date.map(getTime) : getTime(date),
  97. });
  98. this.$emit('select', utils_1.copyDates(date));
  99. },
  100. }
  101. })