Riku
2024-09-28 dad10a883e2995704b17132f50474107f5a45a9a
src/components/search-option/FYOptionTime.vue
@@ -1,8 +1,9 @@
<template>
  <el-form-item label="时间">
  <el-form-item label="时间" :prop="prop">
    <el-date-picker
      v-model="selectedOptions"
      type="month"
      v-model="date"
      @change="handleChange"
      :type="type"
      placeholder="选择时间"
      style="width: 150px"
    />
@@ -10,9 +11,10 @@
</template>
<script>
import dayjs from 'dayjs'
import dayjs from 'dayjs';
const MONTH = 'month'
const MONTH = 'month';
const DATE = 'date';
export default {
  props: {
@@ -26,45 +28,27 @@
    initValue: {
      type: Boolean,
      default: true
    }
    },
    prop: String
  },
  emits: ['update:value'],
  data() {
    return {
      selectedOptions: ''
    }
      date: this.value
    };
  },
  watch: {
    selectedOptions: {
      handler(nVal, oVal) {
        if (nVal != oVal) {
          this.$emit('update:value', nVal)
        }
      }
    },
    value: {
      handler(nVal, oVal) {
        if (nVal != oVal) {
          this.selectedOptions = nVal
        }
      },
      immediate: true
    }
  computed:{
  },
  methods: {
    timeFormat() {
      switch (this.type) {
        case MONTH:
          return 'YYYY-MM'
        default:
          return 'YYYY-MM'
      }
    }
    handleChange(value) {
      this.$emit('update:value', value);
    },
  },
  mounted() {
    if (this.initValue) {
      this.selectedOptions = new Date()
      this.date = new Date()
      this.handleChange(this.date);
    }
  }
}
};
</script>