<template>
  <div class="d-form-field d-calendar">
    <div class="d-field-label" :style="{ width: labelWidth }">{{ label }}</div>
    <van-field readonly :value="displayValue" :name="name" :class="{ 'field-border': border }" :placeholder="placeholder" right-icon="arrow" :required="required" :disabled="disabled" @click="showPicker = !disabled && true" />
    <van-popup round position="bottom" v-model="showPicker">
      <van-calendar show-toolbar :title="'选择' + label" @confirm="onConfirm" @cancel="showPicker = false" />
    </van-popup>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop, Watch } from "vue-property-decorator";
/**
 * @Description 日期选择器
 * @Author ZPFly
 * @Date 2021/11/3 10:19
 */
@Component({
  name: "DCalendar",
})
export default class DSelect extends Vue {
  @Prop({ default: "" }) value: string | undefined; // 当前选择器的值
  @Prop({ default: "" }) label: string | undefined; // 输入框左侧文本
  @Prop({ default: "80px" }) labelWidth: string | undefined; // 输入框标签长度
  @Prop({ default: "" }) placeholder: string | undefined; // 输入框占位提示文字
  @Prop({ default: "" }) name: string | undefined; // 名称，提交表单的标识符
  @Prop({ default: false }) disabled: boolean | undefined; //是否禁用输入框
  @Prop({ default: false }) required: boolean | undefined; //是否显示表单必填星号
  @Prop({ default: true }) isLink: boolean | undefined; //是否展示右侧箭头并开启点击反馈
  @Prop({ default: "down" }) arrowDirection: string | undefined; //箭头方向，可选值为 right left up
  @Prop({ default: false }) border: false | undefined; // 显示边框

  _value: any = ""; // 选择器的值
  _valueKey: any = ""; // 选项对象中，选项文字对应的键名
  showPicker = false; // 显示选择器
  displayValue = ""; // 选中对象的文字
  /**
   * @Description 确认时间日期
   * @Author ZPFly
   * @Date 2021/11/5 10:14
   */
  onConfirm(val: any) {
    console.log(val);
  }
}
</script>
<style scoped></style>
