You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.0 KiB
Vue

4 years ago
<template>
<el-date-picker
4 years ago
v-if="options !== null && options.attrs !== null"
4 years ago
ref="dateRef"
v-model="options.value"
:type="options.attrs.type"
:range-separator="$t(options.attrs.rangeSeparator)"
:start-placeholder="$t(options.attrs.startPlaceholder)"
:end-placeholder="$t(options.attrs.endPlaceholder)"
:placeholder="$t(options.attrs.placeholder)"
:append-to-body="inScreen"
4 years ago
style="min-height: 36px"
4 years ago
@change="dateChange"
/>
</template>
<script>
4 years ago
import { timeSection } from "@/utils";
4 years ago
export default {
props: {
element: {
type: Object,
4 years ago
default: null,
4 years ago
},
inDraw: {
type: Boolean,
4 years ago
default: true,
4 years ago
},
inScreen: {
type: Boolean,
required: false,
4 years ago
default: true,
},
4 years ago
},
data() {
return {
options: null,
4 years ago
operator: "between",
values: null,
};
4 years ago
},
created() {
4 years ago
this.options = this.element.options;
if (this.options.attrs.type === "date") {
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
this.options.value = start;
console.log("date", this.options, start);
} else if (this.options.attrs.type === "daterange") {
const end = new Date();
end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 8);
this.options.value = [start, end];
console.log("daterange", this.options);
} else {
this.options.value = null;
}
if (
(this.options.attrs.type === "date" || this.options.attrs.type === "daterange") &&
Array.isArray(this.options.value) &&
this.options.value.length === 0
) {
this.options.value = null;
4 years ago
}
4 years ago
if (
!!this.options &&
!!this.options.value &&
Object.keys(this.options.value).length === 0
) {
// this.options.value = null;
4 years ago
}
},
methods: {
search() {
4 years ago
this.setCondition();
4 years ago
},
setCondition() {
const param = {
component: this.element,
4 years ago
value: Array.isArray(this.options.value)
? this.options.value
: [this.options.value],
operator: this.operator,
};
param.value = this.formatValues(param.value);
this.inDraw && this.$store.commit("addViewFilter", param);
4 years ago
},
dateChange(value) {
4 years ago
this.setCondition();
this.styleChange();
4 years ago
},
formatValues(values) {
if (!values || values.length === 0) {
4 years ago
return [];
4 years ago
}
4 years ago
if (this.options.attrs.type === "daterange") {
4 years ago
if (values.length !== 2) {
4 years ago
return null;
4 years ago
}
4 years ago
let start = values[0];
let end = values[1];
start = timeSection(start, "date")[0];
end = timeSection(end, "date")[1];
const results = [start, end];
return results;
4 years ago
} else {
4 years ago
const value = values[0];
return timeSection(value, this.options.attrs.type);
4 years ago
}
},
styleChange() {
4 years ago
this.$store.commit("recordStyleChange");
},
},
};
4 years ago
</script>
4 years ago
<style lang="scss" scoped></style>