餐饮油烟智能监测与监管一体化平台
feiyu02
6 天以前 ccc970e575ef3f3e5c67af8da210263f4ac549f9
src/components/search-option/FYOptionTime.vue
@@ -14,66 +14,76 @@
</template>
<script>
import dayjs from 'dayjs';
import dayjs from 'dayjs'
const MONTH = 'month';
const DATE = 'date';
const RANGE = 'datetimerange';
const RANGE2 = 'daterange';
const MONTH = 'month'
const DATE = 'date'
const RANGE = 'datetimerange'
const RANGE2 = 'daterange'
export default {
  props: {
    type: {
      type: String,
      default: MONTH
      default: MONTH,
    },
    // 返回结果
    value: Date || Array,
    // 是否默认返回初始选项
    initValue: {
      type: Boolean,
      default: true
      default: true,
    },
    label: {
      type: String,
      default: '时间'
      default: '时间',
    },
    prop: {
      type: String,
      default: 'time'
    }
      default: 'time',
    },
  },
  emits: ['update:value', 'change'],
  data() {
    return {
      date: this.value
    };
      date: this.value,
    }
  },
  watch: {
    value: {
      handler(newVal, oldVal) {
        if (newVal != oldVal) {
          this.date = newVal
        }
      },
      immediate: true,
    },
  },
  computed: {},
  methods: {
    handleChange(value) {
      this.$emit('update:value', value);
      this.$emit('change', value);
    }
      this.$emit('update:value', value)
      this.$emit('change', value)
    },
  },
  mounted() {
    if (this.initValue) {
      switch (this.type) {
        case RANGE:
        case RANGE2:
          this.date = [dayjs().startOf('month').toDate(), dayjs().toDate()];
          break;
          this.date = [dayjs().startOf('month').toDate(), dayjs().toDate()]
          break
        case MONTH:
          this.date = dayjs().startOf('month').toDate();
          break;
          this.date = dayjs().startOf('month').toDate()
          break
        case DATE:
          this.date = dayjs().toDate();
          break;
          this.date = dayjs().toDate()
          break
        default:
          break;
          break
      }
      this.handleChange(this.date);
      this.handleChange(this.date)
    }
  }
};
  },
}
</script>