calendar.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import TCalendar from '../common/shared/calendar/index';
  11. const { prefix } = config;
  12. const name = `${prefix}-calendar`;
  13. let Calendar = class Calendar extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [`${prefix}-class`];
  17. this.options = {
  18. multipleSlots: true,
  19. styleIsolation: 'apply-shared',
  20. };
  21. this.properties = props;
  22. this.data = {
  23. prefix,
  24. name,
  25. months: [],
  26. };
  27. this.lifetimes = {
  28. ready() {
  29. let { confirmBtn } = this.data;
  30. if (!confirmBtn) {
  31. confirmBtn = { content: '确认' };
  32. }
  33. this.base = new TCalendar(this.properties);
  34. this.setData({
  35. days: this.base.getDays(),
  36. confirmBtn,
  37. });
  38. this.calcMonths();
  39. },
  40. };
  41. this.methods = {
  42. calcMonths() {
  43. const months = this.base.getMonths();
  44. this.setData({
  45. months,
  46. });
  47. },
  48. handleClose() {
  49. this.setData({ visible: false });
  50. },
  51. handleSelect(e) {
  52. const { date, year, month } = e.currentTarget.dataset;
  53. if (date.type === 'disabled')
  54. return;
  55. const value = this.base.select({ cellType: date.type, year, month, date: date.day });
  56. this.base.value = value;
  57. this.calcMonths();
  58. },
  59. onTplButtonTap() {
  60. const value = this.base.getTrimValue();
  61. this.triggerEvent('confirm', { value });
  62. },
  63. };
  64. }
  65. };
  66. Calendar = __decorate([
  67. wxComponent()
  68. ], Calendar);
  69. export default Calendar;