1 2 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| export default { props: { minDate: { type: Date, default() { return new Date(2019, 0, 1); } }, maxDate: { type: Date, default() { return new Date(2030, 0, 1); } }, defaultDate: { type: Date, default() { return new Date(); } }, showPicker: { type: Boolean, default: false } }, data() { return { activeRange: "", startDate: "", endDate: "", showPopup: false }; }, watch: { showPicker(val) { this.showPopup = val; } }, created() { this.currentDate = this.defaultDate; }, methods: { formatter(type, val) { console.log(type, val); if (type === "year") { return `${val}年`; } else if (type === "month") { return `${val}月`; } else if (type === "day") { return `${val}日`; } return val; }, pickerChange() { this.activeRange = this.activeRange || "start"; if (this.activeRange == "start") { this.startDate = this.currentDate; } else if (this.activeRange == "end") { this.endDate = this.currentDate; } }, rangeChange(type) { this.activeRange = type; if (this.activeRange == "start") { if (this.startDate) { this.currentDate = this.startDate; } else { this.startDate = this.currentDate; } } else if (this.activeRange == "end") { if (this.endDate) { this.currentDate = this.endDate; } else { this.endDate = this.currentDate; } } }, confirm() { const startDate = this.startDate ? this.$tools.timeF(this.startDate, "YYYY-MM-DD") : ""; const endDate = this.endDate ? this.$tools.timeF(this.endDate, "YYYY-MM-DD") : ""; console.log(endDate); if (startDate && endDate && startDate > endDate) { this.$toast("开始时间不能大于结束时间"); return false; } this.$emit("confirm", startDate, endDate); }, closed() { this.$emit("closed"); }, reset() { this.currentDate = new Date(); this.endDate = this.startDate = ""; this.activeRange = "start"; }, getMonthLastDay(time) { var date = new Date(time || new Date()); var currentMonth = date.getMonth(); var nextMonth = ++currentMonth; var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1); var oneDay = 1000 * 60 * 60 * 24; return this.$tools.timeF( new Date(nextMonthFirstDay - oneDay), "YYYY-MM-DD" ); } } };
|