Blame view

src/components/date-picker/panel/date-range.vue 6.32 KB
17e1fcf1   梁灏   init DatePicker
1
  <template>
e0cd7f90   梁灏   fixed #134
2
      <div :class="classes">
3cf7cfd1   梁灏   update DatePicker
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
          <div :class="[prefixCls + '-sidebar']" v-if="shortcuts.length">
              <div
                  :class="[prefixCls + '-shortcut']"
                  v-for="shortcut in shortcuts"
                  @click="handleShortcutClick(shortcut)">{{ shortcut.text }}</div>
          </div>
          <div :class="[prefixCls + '-body']">
              <div :class="[prefixCls + '-content', prefixCls + '-content-left']">
                  <div :class="[datePrefixCls + '-header']" v-show="currentView !== 'time'">
                      <span
                          :class="iconBtnCls('prev', '-double')"
                          @click="prevYear"><Icon type="ios-arrow-left"></Icon></span>
                      <span
                          :class="iconBtnCls('prev')"
                          @click="prevMonth"
                          v-show="currentView === 'date'"><Icon type="ios-arrow-left"></Icon></span>
                      <span
                          :class="[datePrefixCls + '-header-label']"
                          @click="showYearPicker">{{ leftYear }} 年</span>
                      <span
                          :class="[datePrefixCls + '-header-label']"
                          @click="showMonthPicker"
                          v-show="currentView === 'date'">{{ leftMonth + 1 }} 月</span>
                  </div>
                  <date-table
                      v-show="currentView === 'date'"
                      :year="leftYear"
                      :month="leftMonth"
                      :date="date"
                      :min-date="minDate"
                      :max-date="maxDate"
                      :range-state="rangeState"
                      :selection-mode="selectionMode"
                      :disabled-date="disabledDate"
                      @on-pick="handleDatePick"></date-table>
              </div>
              <div :class="[prefixCls + '-content', prefixCls + '-content-right']">
                  <div :class="[datePrefixCls + '-header']" v-show="currentView !== 'time'">
                      <span
                          :class="[datePrefixCls + '-header-label']"
                          @click="showYearPicker">{{ rightYear }} 年</span>
                      <span
                          :class="[datePrefixCls + '-header-label']"
                          @click="showMonthPicker"
                          v-show="currentView === 'date'">{{ rightMonth + 1 }} 月</span>
                      <span
                          :class="iconBtnCls('next', '-double')"
                          @click="nextYear"><Icon type="ios-arrow-right"></Icon></span>
                      <span
                          :class="iconBtnCls('next')"
                          @click="nextMonth"
                          v-show="currentView === 'date'"><Icon type="ios-arrow-right"></Icon></span>
                  </div>
                  <date-table
                      v-show="currentView === 'date'"
                      :year="rightYear"
                      :month="rightMonth"
                      :date="rightDate"
                      :min-date="minDate"
                      :max-date="maxDate"
                      :range-state="rangeState"
                      :selection-mode="selectionMode"
                      :disabled-date="disabledDate"
                      @on-pick="handleDatePick"></date-table>
              </div>
          </div>
e0cd7f90   梁灏   fixed #134
69
      </div>
17e1fcf1   梁灏   init DatePicker
70
71
  </template>
  <script>
3cf7cfd1   梁灏   update DatePicker
72
73
74
75
76
77
      import Icon from '../../icon/icon.vue';
      import DateTable from '../base/date-table.vue';
      import { toDate } from '../util';
  
      import Mixin from './mixin';
  
e0cd7f90   梁灏   fixed #134
78
79
80
      const prefixCls = 'ivu-picker-panel';
      const datePrefixCls = 'ivu-date-picker';
  
17e1fcf1   梁灏   init DatePicker
81
      export default {
3cf7cfd1   梁灏   update DatePicker
82
83
          mixins: [Mixin],
          components: { Icon, DateTable },
17e1fcf1   梁灏   init DatePicker
84
          data () {
3cf7cfd1   梁灏   update DatePicker
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
              return {
                  prefixCls: prefixCls,
                  datePrefixCls: datePrefixCls,
                  shortcuts: [],
                  date: new Date(),
                  value: '',
                  minDate: '',
                  maxDate: '',
                  rangeState: {
                      endDate: null,
                      selecting: false
                  },
                  showTime: false,
                  disabledDate: '',
                  currentView: 'date',
                  selectionMode: 'range'
              }
17e1fcf1   梁灏   init DatePicker
102
          },
e0cd7f90   梁灏   fixed #134
103
104
105
106
          computed: {
              classes () {
                  return [
                      `${prefixCls}-body-wrapper`,
3cf7cfd1   梁灏   update DatePicker
107
                      `${datePrefixCls}-with-range`,
e0cd7f90   梁灏   fixed #134
108
109
110
111
                      {
                          [`${prefixCls}-with-sidebar`]: this.shortcuts.length
                      }
                  ]
3cf7cfd1   梁灏   update DatePicker
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
              },
              leftYear() {
                  return this.date.getFullYear();
              },
              leftMonth() {
                  return this.date.getMonth();
              },
              rightYear() {
                  return this.rightDate.getFullYear();
              },
              rightMonth() {
                  return this.rightDate.getMonth();
              },
              rightDate() {
                  const newDate = new Date(this.date);
                  const month = newDate.getMonth();
                  newDate.setDate(1);
  
                  if (month === 11) {
                      newDate.setFullYear(newDate.getFullYear() + 1);
                      newDate.setMonth(0);
                  } else {
                      newDate.setMonth(month + 1);
                  }
                  return newDate;
              }
          },
          watch: {
              value(newVal) {
                  if (!newVal) {
                      this.minDate = null;
                      this.maxDate = null;
                  } else if (Array.isArray(newVal)) {
                      this.minDate = newVal[0] ? toDate(newVal[0]) : null;
                      this.maxDate = newVal[1] ? toDate(newVal[1]) : null;
                      if (this.minDate) this.date = new Date(this.minDate);
  //                    this.handleConfirm(true);    // todo 稍后测试
                  }
e0cd7f90   梁灏   fixed #134
150
151
              }
          },
3cf7cfd1   梁灏   update DatePicker
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
          methods: {
              prevYear () {
  
              },
              nextYear () {
  
              },
              prevMonth () {
  
              },
              nextMonth () {
  
              },
              showYearPicker () {
  
              },
              showMonthPicker () {
  
              },
              handleDatePick () {
  
              },
              handleConfirm(visible) {
                  this.$emit('on-pick', [this.minDate, this.maxDate], visible);
              }
          }
17e1fcf1   梁灏   init DatePicker
178
179
      }
  </script>