34
34
v-for =" (child,k2) in day"
35
35
:data-date =" formatDate(year, month, child)"
36
36
:data-current =" currentValue"
37
- :class =" buildClass(k2, child, formatDate(year, month, child) === currentValue && !child.isLastMonth && !child.isNextMonth )"
37
+ :class =" buildClass(k2, child)"
38
38
@click =" select(k1,k2,child)" >
39
39
<slot
40
40
:year =" year"
@@ -68,19 +68,28 @@ export default {
68
68
props: props (),
69
69
data () {
70
70
return {
71
+ multi: false ,
71
72
year: 0 ,
72
73
month: 0 ,
73
74
days: [],
74
75
today: format (new Date (), ' YYYY-MM-DD' ),
75
- months: [' 01 ' , ' 02 ' , ' 03 ' , ' 04 ' , ' 05 ' , ' 06 ' , ' 07 ' , ' 08 ' , ' 09 ' , ' 10' , ' 11' , ' 12' ],
76
+ months: [' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' 10' , ' 11' , ' 12' ],
76
77
currentValue: ' '
77
78
}
78
79
},
79
80
created () {
80
81
this .currentValue = this .value
82
+ this .multi = Object .prototype .toString .call (this .currentValue ) === ' [object Array]'
81
83
},
82
84
mounted () {
83
- this .currentValue = this .convertDate (this .currentValue )
85
+ if (this .multi ) {
86
+ for (let i = 0 ; i < this .currentValue .length ; i++ ) {
87
+ this .$set (this .currentValue , i, this .convertDate (this .currentValue [i]))
88
+ }
89
+ } else {
90
+ this .currentValue = this .convertDate (this .currentValue )
91
+ }
92
+
84
93
this .render (this .renderMonth [0 ], this .renderMonth [1 ] - 1 )
85
94
},
86
95
computed: {
@@ -101,17 +110,17 @@ export default {
101
110
},
102
111
watch: {
103
112
value (val ) {
104
- this .currentValue = val
113
+ this .currentValue = this . multi ? val : this . convertDate (val)
105
114
},
106
115
currentValue (val ) {
107
- this .currentValue = this .convertDate (val)
116
+ const value = this .multi ? this . currentValue [ this . currentValue . length - 1 ] : this .currentValue
108
117
if (this .renderOnValueChange ) {
109
- this .render (null , null , val )
118
+ this .render (null , null , value )
110
119
} else {
111
- this .render (this .year , this .month , this . currentValue )
120
+ this .render (this .year , this .month , value )
112
121
}
113
- this .$emit (' input' , val )
114
- this .$emit (' on-change' , val )
122
+ this .$emit (' input' , this . currentValue )
123
+ this .$emit (' on-change' , this . currentValue )
115
124
},
116
125
renderFunction () {
117
126
this .render (this .year , this .month , this .currentValue )
@@ -149,7 +158,15 @@ export default {
149
158
convertDate (date ) {
150
159
return date === ' TODAY' ? this .today : date
151
160
},
152
- buildClass (index , child , isCurrent ) {
161
+ buildClass (index , child ) {
162
+ let isCurrent = false
163
+ if (! child .isLastMonth && ! child .isNextMonth ) {
164
+ if (this .multi && this .currentValue .length > 0 ) {
165
+ isCurrent = this .currentValue .indexOf (this .formatDate (this .year , this .month , child)) > - 1
166
+ } else {
167
+ isCurrent = this .currentValue === this .formatDate (this .year , this .month , child)
168
+ }
169
+ }
153
170
const className = {
154
171
current: child .current || isCurrent,
155
172
' is-disabled' : child .disabled ,
@@ -159,10 +176,12 @@ export default {
159
176
return className
160
177
},
161
178
render (year , month ) {
162
- let data = getDays ({
179
+ let data = null
180
+ const value = this .multi ? this .currentValue [this .currentValue .length - 1 ] : this .currentValue
181
+ data = getDays ({
163
182
year: year,
164
183
month: month,
165
- value: this . currentValue ,
184
+ value,
166
185
rangeBegin: this .convertDate (this .startDate ),
167
186
rangeEnd: this .convertDate (this .endDate ),
168
187
returnSixRows: this .returnSixRows ,
@@ -207,12 +226,42 @@ export default {
207
226
if (! data .isBetween ) {
208
227
return
209
228
}
229
+ let _currentValue = null
210
230
if (! data .isLastMonth && ! data .isNextMonth ) {
211
231
this .days [k1][k2].current = true
212
- this .currentValue = [this .year , zero (this .month + 1 ), zero (this .days [k1][k2].day )].join (' -' )
232
+ _currentValue = [this .year , zero (this .month + 1 ), zero (this .days [k1][k2].day )].join (' -' )
233
+ } else {
234
+ _currentValue = [data .year , zero (data .month + 1 ), zero (data .day )].join (' -' )
235
+ }
236
+ if (this .multi ) {
237
+ let index = this .currentValue .indexOf (_currentValue)
238
+ if (index > - 1 ) {
239
+ this .currentValue .splice (index, 1 )
240
+ } else {
241
+ this .currentValue .push (_currentValue)
242
+ }
243
+ } else {
244
+ this .currentValue = this .currentValue === _currentValue ? ' ' : _currentValue
245
+ }
246
+
247
+ this .currentValueChange ()
248
+ },
249
+ currentValueChange () {
250
+ if (this .multi ) {
251
+ for (let i = 0 ; i < this .currentValue .length ; i++ ) {
252
+ this .$set (this .currentValue , i, this .convertDate (this .currentValue [i]))
253
+ }
213
254
} else {
214
- this .currentValue = [ data . year , zero ( data . month + 1 ), zero ( data . day )]. join ( ' - ' )
255
+ this .currentValue = this . convertDate ( this . currentValue )
215
256
}
257
+ const value = this .multi ? this .currentValue [this .currentValue .length - 1 ] : this .currentValue
258
+ if (this .renderOnValueChange ) {
259
+ this .render (null , null , value)
260
+ } else {
261
+ this .render (this .year , this .month , value)
262
+ }
263
+ this .$emit (' input' , this .currentValue )
264
+ this .$emit (' on-change' , this .currentValue )
216
265
},
217
266
showChild (year , month , child ) {
218
267
if (this .replaceText (child .day , this .formatDate (year, month, child))) {
@@ -224,7 +273,7 @@ export default {
224
273
}
225
274
}
226
275
</script >
227
-
276
+
228
277
<style lang="less">
229
278
@import ' ../../styles/variable.less' ;
230
279
0 commit comments