Blame view

src/components/date-picker/base/month-table.vue 2.23 KB
17e1fcf1   梁灏   init DatePicker
1
  <template>
c46f385a   梁灏   update DatePicker
2
3
4
      <div :class="classes" @click="handleClick">
          <span :class="getCellCls(cell)" v-for="cell in cells"><em :index="$index">{{ cell.text }}月</em></span>
      </div>
17e1fcf1   梁灏   init DatePicker
5
6
  </template>
  <script>
c46f385a   梁灏   update DatePicker
7
8
9
      import { deepCopy } from '../../../utils/assist';
      const prefixCls = 'ivu-date-picker-cells';
  
17e1fcf1   梁灏   init DatePicker
10
      export default {
c46f385a   梁灏   update DatePicker
11
12
13
14
15
          props: {
              date: {},
              month: {
                  type: Number
              },
13be4434   梁灏   update DatePicker
16
17
18
19
              disabledDate: {},
              selectionMode: {
                  default: 'month'
              }
17e1fcf1   梁灏   init DatePicker
20
          },
c46f385a   梁灏   update DatePicker
21
22
23
24
25
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      `${prefixCls}-month`
b0893113   jingsam   :art: add eslint
26
                  ];
c46f385a   梁灏   update DatePicker
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
              },
              cells () {
                  let cells = [];
                  const cell_tmpl = {
                      text: '',
                      selected: false,
                      disabled: false
                  };
  
                  for (let i = 0; i < 12; i++) {
                      const cell = deepCopy(cell_tmpl);
                      cell.text = i + 1;
  
                      const date = new Date(this.date);
                      date.setMonth(i);
13be4434   梁灏   update DatePicker
42
                      cell.disabled = typeof this.disabledDate === 'function' && this.disabledDate(date)  && this.selectionMode === 'month';
c46f385a   梁灏   update DatePicker
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  
                      cell.selected = Number(this.month) === i;
                      cells.push(cell);
                  }
  
                  return cells;
              }
          },
          methods: {
              getCellCls (cell) {
                  return [
                      `${prefixCls}-cell`,
                      {
                          [`${prefixCls}-cell-selected`]: cell.selected,
                          [`${prefixCls}-cell-disabled`]: cell.disabled
                      }
b0893113   jingsam   :art: add eslint
59
                  ];
c46f385a   梁灏   update DatePicker
60
61
62
63
64
65
66
67
68
69
              },
              handleClick (event) {
                  const target = event.target;
                  if (target.tagName === 'EM') {
                      const index = parseInt(event.target.getAttribute('index'));
                      const cell = this.cells[index];
                      if (cell.disabled) return;
  
                      this.$emit('on-pick', index);
                  }
68e9b100   梁灏   update DatePicker
70
                  this.$emit('on-pick-click');
c46f385a   梁灏   update DatePicker
71
72
              }
          }
b0893113   jingsam   :art: add eslint
73
74
      };
  </script>