<template>
    <div :class="nxInputClass">
        <DatePicker
            :editable="false"
            :placeholder="placeholder"
            @on-blur="blur"
            @on-change="currVal=$event"
            format="yyyy-MM-dd"
            transfer
            v-model="currVal"
        ></DatePicker>
        <span class="error">{{fieldError}}</span>
    </div>
</template>
<script>
import Item from '../mixins/item'
import dayjs from 'dayjs'

export default {
    name: 'XDate',
    data() {
        return {
            currVal: undefined
        }
    },
    mixins: [Item],
    props: {},
    computed: {
        style() {
            return {}
        },

        nxInputClass() {
            return {
                'ivu-form-item-error': this.fieldError
            }
        }
    },
    mounted() {},
    methods: {
        /*表单数据改变*/
        formValueChange(value) {
            if (value) {
                this.currVal = value[this.prop]
            }
        },

        /*获取数据*/
        getValue() {
            if (this.currVal) {
                return dayjs(this.currVal).format('YYYY-MM-DD')
            } else {
                return this.currVal
            }
        },

        /*失去焦点时去掉必填显示*/
        blur() {
            if (this.currVal) {
                this.form.formError[this.prop] = null
            }
        }
    }
}
</script>