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
| import { Popover } from "element-ui"; export default { inheritAttrs: false, model: { prop: "value", event: "change" }, data() { return { popover: false, year: new Date().getFullYear(), quarterValue: "", quarterList: [ { label: "第一季度", value: 1 }, { label: "第二季度", value: 2 }, { label: "第三季度", value: 3 }, { label: "第四季度", value: 4 } ], inputValue: "", inputHovering: false }; }, computed: { totalValue() { if (this.year && this.quarterValue) { return this.year + "-" + this.quarterValue; } else { return ""; } }, showClose() { return this.inputHovering && this.inputValue; }, prevYearDisabled() { if (this.year <= 2000) { return { color: "#ddd", cursor: "not-allowed" }; } else { return {}; } }, nextYearDisabled() { if (new Date().getFullYear() <= this.year) { return { color: "#ddd", cursor: "not-allowed" }; } else { return {}; } } }, components: { ElPopover: Popover }, methods: { prev() { if (this.year > 2000) { this.year--; } }, next() { if (this.year < new Date().getFullYear()) { this.year++; } }, handleSetQuarterValue(value) { if (!this.quarterDisabled(value)) { this.quarterValue = value; } }, quarterDisabled(value) { const currMonth = new Date().getMonth() + 1; const quarter = Math.floor( currMonth % 3 == 0 ? currMonth / 3 : currMonth / 3 + 1 ); if ( this.year < new Date().getFullYear() || (this.year >= new Date().getFullYear() && quarter >= value) ) { return false; } else { return true; } }, handleClearClick() { this.inputValue = ""; this.quarterValue = ""; this.$emit("change", ""); this.$refs.quarterInput.blur(); } }, watch: { totalValue() { this.inputValue = this.totalValue; this.$emit("change", this.inputValue); this.popover = false; }, value() { this.year = this.value.split("-")[0]; this.quarterValue = this.value.split("-")[1]; } } };
|