<template>
    <div :class="[model.sysCss, 'app-login-input']" :style="containerStyle">
        <i-input
            size='large'
            :prefix='defaultIcon'
            v-model="curValue"
            :disabled="disabled"
            :readonly="readonly"
            :placeholder="model.caption">
        </i-input>
    </div>
</template>

<script lang="ts">
import { PanelFieldModel } from '@/model/panel-detail';
import { Vue, Component, Prop } from 'vue-property-decorator';

@Component({
})
export default class AppLoginInput extends Vue {

    /**
     * 模型
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public model!: PanelFieldModel;
    
    /**
     * 值
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public value!: string;

    /**
     * 名称
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public name!: string;

    /**
     * 默认图标
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public defaultIcon?: string;

    /**
     * 容器样式
     *
     * @type {any}
     * @memberof AppLoginInput
     */
    public containerStyle: any = null;

    /**
     * 禁用模式
     *
     * @type {any}
     * @memberof AppLoginInput
     */
    public disabled: boolean = false;

    /**
     * 只读模式
     *
     * @type {any}
     * @memberof AppLoginInput
     */
    public readonly: boolean = false;

    /**
     * 当前值
     *
     * @type {any}
     * @memberof AppLoginInput
     */
    get curValue() {
        return this.value;
    }

    /**
     * 值变化
     *
     * @memberof AppPresetTextInput
     */
    set curValue(val: any) {
        this.$emit('valueChange', { name: this.name, value: val });
    }

    public mounted() {
        if (this.model) {
            this.containerStyle = this.model.getElementStyle();
            this.disabled = Object.is(this.model.fieldState, '1');
            this.readonly = Object.is(this.model.fieldState, '2'); 
        }
    }
    
}
</script>
<style lang="less">
@import "./app-login-input.less";
</style>