vant calendar 使用

<template>
  <div>
    <van-field
      :required="required"
      :label="label"
      v-model="date"
      @click="show = true"
      readonly
      right-icon="notes-o"
      input-align="right"
      :placeholder="'请选择'+label"
      :disabled="disabled"
    />
    <van-calendar
      v-model="show"
      type="range"
      :readonly="disabled"
      @confirm="onConfirm"
      confirm-text="完成"
      color="#00c87f"
      :poppable="true"
      get-container="#app"
      :min-date="min"
      :max-date="max"
      :default-date="defaultRange"
    />
    <!--    -->
  </div>
</template>

<script>
import Vue from "vue";
import { Calendar } from "vant";
import filters  from "@/filters/index";
Vue.use(Calendar);
export default {
  props: {
    // 是否必录
    disabled: {
      type: Boolean,
      default: false,
    },
    required: {
      type: Boolean,
      default: false,
    },
    label: {
      type: String,
      default: "",
    },
    value: {
      type: String,
      default: "",
    },
    minDate: {
      type: String,
      default:filters.stampDate(new Date().setFullYear(new Date().getFullYear()-2)),
    },
    maxDate: {
      type: String,
      default: filters.stampDate(new Date().setFullYear(new Date().getFullYear()+2)),
    },
  },
 
  data() {
    return {
      date:this.value,
      show: false,
      min: new Date(this.minDate),
      max: new Date(this.maxDate),
    };
  },
  computed:{
    defaultRange(){
      const [start, end] = this.date.split('至');
      return [new Date(start),new Date(end)]
    },
  },
  watch: {
    value(val) {
      this.date = val;
    },
    date() {
      this.$emit("input", this.date);
    },
  },
  methods: {
    onConfirm(date) {
      const [start, end] = date;
      this.show = false;
      this.date = `${filters.stampDate(start)} 至 ${filters.stampDate(end)}`;
      this.$emit("input", this.date);
      this.$emit('dateConfirm',date)
    },
    checkVlue() {
      const [start, end] = this.date.split('至');
      var labelstring=this.label===" "?this.placeholder.substr(3):this.label;
      console.log(labelstring, this.required , (!this.fieldValue || this.fieldValue.trim() === ""));
      if ( this.required && (!start || start.trim() === ""||!end || end.trim() === "") ) {
        this.$toast("请选择" + labelstring);
        return false;
      }
      this.$emit('blurFun',this.fieldValue);
      return true;
    },
  },
};
</script>

<style>
</style>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值