<template>
    <div style="width:100%;">
        <div>
            <div class="item-style">
                <i-switch v-model="value"></i-switch>
            </div>
        </div>
        <div v-show="value">
            <div >
                <label class="item-style">文本框类型</label>
                <inputSelect></inputSelect>
            </div>
            <div v-show="isTextarea">
                <label class="item-style">行数</label>
                <Input style="margin: 0px 10px 7px;width: 92%;" placeholder="只能输入数字，最大行数为10" clearable type="number" v-model="LineNums"/>
            </div>

            <div class="title-style">校验</div>
            <validateArr></validateArr>
            <div class="title-style">是否展示</div>
            <showFlag></showFlag>
            <div class="title-style">联动</div>
            <linkageChangeValue></linkageChangeValue>
        </div>
    </div>
</template>

<script>
    import * as components from './style';
    import {PropertyMixin} from '../../service/main-tool-editor-type-mixin';
    import showFlag from '../main-tool-editor-type-showFlag';
    import validateArr from '../main-tool-editor-type-box-validateArr';
    import linkageChangeValue from '../main-tool-editor-type-box-linkageChangeValue';
    import inputSelect from '../main-tool-editor-type-box-inputSelect';
    import eventbus from '../../service/eventbus';
    export default {
        components: {
            ...components,
            showFlag,
            validateArr,
            linkageChangeValue,
            inputSelect
        },
        mixins: [PropertyMixin],
        position: 'mainToolEditorTypeInputHeightLevel',
        name: 'main-tool-editor-type-inputHeightLevel',
        data() {
            return {
                LineNums:1,
                value: this.editor.value || false,
                isTextarea:false
            };
        },
        mounted() {
            this.initCurrtField();
            this.initLineRow();
            this.setInstanceProps(this.value);
            eventbus.$off("computIsShow");
            eventbus.$on("computIsShow", (data) => {
                debugger;
               if(data.com!=""){
                   this.isTextarea=false;
               }else{
                   this.isTextarea=true;
               }
            });
        },
        computed: {
            getLineNums() {
                debugger;
                let currentInstance = this.$store.state.viewport.instances.get(this.$store.state.viewport.currentEditInstanceKey);
                //note 为事件新增一项
                if (!currentInstance.data.extend.rows) {
                    currentInstance.data.extend.rows = 1;
                }
                return currentInstance.data.extend.rows ;
            },
            applicationState() {

                return this.$store.state.application;
            },
            viewportState() {
                return this.$store.state.viewport;
            }
        },
        methods: {
            initLineRow(){
                debugger;
                let currentInstance = this.$store.state.viewport.instances.get(this.$store.state.viewport.currentEditInstanceKey);
                //note 为事件新增一项
                if(currentInstance.data.extend.rows){
                    this.LineNums=currentInstance.data.extend.rows;
                }
            },
            setLineRow(line){
                debugger;
                let currentInstance = this.$store.state.viewport.instances.get(this.$store.state.viewport.currentEditInstanceKey);
                if(parseInt(line)>10){
                    this.$Notice.warning({
                        title: '友情提示' +
                        '',
                        desc:  '最大只能輸入行数为10'
                    });
                    this.LineNums=10;
                    //note 为事件新增一项
                    currentInstance.data.extend.rows=10;
                    return;
                }
                //note 为事件新增一项
                 currentInstance.data.extend.rows=line;
            },
            handleChange() {

            }
        },
        watch: {
            LineNums(n, o) {
                if (n === o) {
                    return;
                }
                this.setLineRow(n);
            },
            value(n, o) {
                if (n === o) {
                    return;
                }
                this.setInstanceProps(n);
            }
        }
    };
</script>

<style scoped>

</style>
