<template>
    <div class="my-inputBox">
        <div class="line"></div>
        <div class="my-title">
            <slot class="title">
                <span>{{title}}</span>
            </slot>
            <slot name="icon"></slot>
        </div>
        <div
            :class="['my-input',arrowsRight?'isLink':'']">
            <slot name="content">
                <!-- <textarea
                    auto-height
                    v-if="type == 'textarea'"
                    class="text-line text-textarea"
                    :disabled="disabled"
                    ref="input"
                    :type="type"
                    v-model="currentValue"
                    @blur="onBlur"
                    @input="onChange"
                    :isFocus="true"
                    :placeholder="placeholder">
                </textarea> -->
                <appTextarea
                    auto-height
                    v-if="type == 'textarea'"
                    class="text-line text-textarea"
                    :disabled="disabled"
                    ref="input"
                    :type="type"
                    v-model="currentValue"
                    @blur="onBlur"
                    @input="onChange"
                    :focus="isFocus"
                    :placeholder="placeholder"
                ></appTextarea>
                <input
                v-else
                class="text-line"
                :disabled="disabled"
                ref="input"
                :type="type"
                v-model="currentValue"
                @blur="onBlur"
                @input="onChange"
                :focus="isFocus"
                :placeholder="placeholder">
            </slot>
            <!-- <i class="icon-butongguo" v-show="isClear&&currentValue !== ''" @click="clear"></i> -->
        </div>
        <div class="my-left">
             <slot name="inputRight"></slot>
        </div>
    </div>
</template>

<script>
import appTextarea from './app-textarea'
export default {
	name: 'app_input_all',
	components: {
		appTextarea
	},
	data() {
		return {
			currentValue: ''
		}
	},
	props: {
		value: {
			type: [String, Number]
		},
		title: {
			type: String
		},
		type: {
			type: String,
			default: 'text'
		},
		placeholder: {
			type: String
		},
		isClear: {
			type: Boolean,
			default: true
		},
		isFocus: {
			type: Boolean,
			default: false
		},
		disabled: {
			type: Boolean,
			default: false
		},
		arrowsRight: {
			type: Boolean,
			default: false
		}
	},
	created() {
		this.currentValue = (this.value === undefined || this.value === null) ? '' : this.value
	},
	mounted() {
		if (this.isFocus) {
			this.focus()
		}
	},
	methods: {
		clear() {
			this.currentValue = ''
			this.focus()
		},
		focus() {
			this.$refs.input.focus()
		},
		blur() {
			this.$refs.input.blur()
		},
		onBlur($event) {
			this.$emit('on-blur', this.currentValue, $event)
		},
		onChange(event) {
			let val = null
			if (this.type == 'text') {
				val = event.target.value
			} else {
				val = event
			}
			this.$emit('on-change', val)
		}
	},
	watch: {
		value(val) {
			this.currentValue = val
		},
		currentValue(val) {
			this.$emit('input', val)
		}
	}
}
</script>

<style scoped lang="scss">
    .my-inputBox{
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: content-box;
        padding-bottom: 15px;
        & .line{
            position: absolute;
            width: 100%;
            height: 1px;
            left: 0;
            bottom: 0;
            border-bottom: 1px solid #ebedf0;
        }
        .my-input{
            position: relative;
            flex: 1;
            box-sizing: content-box;
            & .text-textarea {
                min-height: 150px;
                display: inline-block;
                width: 100%;
                padding: 20px 20px 20px 10px;
                box-sizing: border-box;
            }
           &  input{
                min-height: 88px;
                padding-left: 10px;
                padding-right: 50px;
           }
           &.isLink::after{
                content: "";
                display: inline-block;
                width: 15px;
                height: 15px;
                border-width:2px 2px 0 0;
                border-color:#C8C8CD;
                border-style:solid;
                position: absolute;
                top: 50%;
                right: 30px;
                transform: translate(0,-50%) matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
            }
        }
    }
    input,textarea{
        -webkit-appearance:none;
        outline:0;
        background-color:transparent;
        border:0;
        font-size: 28px;
        font-weight: normal;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #4d4d4d;
        display: block;
    }
    .icon-butongguo{
        color: #cccccc;
        font-size: 28px;
        position: absolute;
        padding: 20px 10px 20px 20px;
        right: 0;
        top: 50%;
        transform: translate(0,-50%);
    }
    .my-title {
        color: #666;
        font-size: 28px;
        width: 180px;

    }
</style>
