<template>
  <a-date-picker
    v-if="lx === 's'"
    v-model="model"
    type="date"
    :default-value="model"
    :disabled-date="disabledStartDate"
  />
  <a-date-picker
    v-else
    v-model="model"
    type="date"
    :default-value="model"
    :disabled-date="disabledEndDate"
  />
</template>

<script>
import moment from 'moment'
import components from './_import-components/audit-project-input-import'

export default {
  name: 'AuditProjectInput',
  metaInfo: {
    title: 'AuditProjectInput',
  },
  components,
  props: {
    value: {
      type: Number,
      default: null,
    },
    field: {
      type: Object,
      default: () => {},
    },
    index: {
      type: Number,
      default: -1,
    },
    lx: {
      type: String,
      default: '',
    },
    data: {
      type: String,
      default: 'udata',
    },
  },
  data() {
    return {
      model: '',
      time: 0,
    }
  },
  watch: {
    model() {
      this.$emit('change', new Date(this.model).getTime(), this.field, this.index, this.lx)
    },
  },
  created() {
    if (this.value !== null) {
      this.model = moment(this.value)
    }
  },
  methods: {
    disabledStartDate(startDate) {
      const finishDate = this.time
      if (!startDate || !finishDate) {
        return false
      }
      return startDate.valueOf() > finishDate.valueOf()
    },
    disabledEndDate(finishDate) {
      const startDate = this.time
      if (!finishDate || !startDate) {
        return false
      }
      return startDate.valueOf() >= finishDate.valueOf()
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
