<template>
  <el-date-picker
		:id="id"
		:class="{'highlight': highlight}"
		:style="{'border-bottom': isShowRed ? `1px solid ${isShowRed}` : ''}"
		v-model="model"
		type="datetime"
		v-bind:disabled="isDisable"
		v-on="$listeners"
    :value-format="valueFormat" :format="format"
		@change="handleChange"
	></el-date-picker>
</template>

<script>
import commonDepend from '~/mixin/commonDepend.js'
import markSetShowRed from '~/components/business/componentMixins/markSetShowRed.js'
export default {
	inject: {
		root: {
			default: () => null
		}
	},
	mixins: [commonDepend, markSetShowRed],
	props: {
		value: {
			default: ''
		},
		disabled: {
			type: Boolean,
			default: false
		},
		format: {
			type: String,
			default: 'yyyy-MM-dd HH:mm:ss'
		},
    valueFormat: {
			type: String,
			default: 'yyyy-MM-dd HH:mm:ss'
		},
		id: {
			type: String,
			default: undefined
    },
    // 此对象为markset或者modifySet所在的对象,如果传了此对象可以标记当前对象下的字段为红色下划线
    markSetData: {
      type: Object,
      default: () => null
    },
		customModifykey: {
			type: String,
      default: null
		}
	},
	computed: {
		model: {
			get() {
				return this.value
			},
			set(newVal) {
				this.$emit('input', newVal)
			}
		},
		mode() {
			return this.$store.state.Status.mode
		},
		isDisable: {
			get() {
				return this.mode === 'display' || this.disabled
			}
		},
		highlight() {
			return this.$store.state.Status.highlights.indexOf(this.id) !== -1
		},
		attrs() {
			if (this.mode === 'display' || this.disabled) {
				let { placeholder, ...rest } = this.$attrs
				return rest
			}
			return this.$attrs
		},
  },
  watch: {
    disabled(newVal) {
      if (newVal) {
        this.resetValidate()
      }
    }
  },
	methods: {
		handleChange () {
			if (!this.customModifykey) {
				// 添加isModify属性
				this.changeModify()
			}
		}
	}
}
</script>

<style>
  .el-input.highlight .el-input__inner {
    border-color: red;
	}
	.el-input__prefix{
	height: 16px!important;
}
</style>