<template>
    <view class="easy-table">
        <slot></slot>
    </view>
</template>

<script>
    export default {
        name: 'easyTable',
        props: {
            checked: {
                type: Boolean,
                default: false
            },
            singleSelect: {
                type: Boolean,
                default: true
            }
        },
        data() {
            return {}
        },
        created() {
            this.trChildren = [];
            this.thChildren = [];
        },
        methods: {
            /**
             * 选中
             */
            check(index) {
                for (let i = 0; i < this.trChildren.length; i++) {
                    if (i === index) {
                        this.trChildren[i].check();
                        break;
                    }
                }
            },

            /**
             * 不选择
             */
            uncheck(index) {
                for (let i = 0; i < this.trChildren.length; i++) {
                    if (i === index) {
                        this.trChildren[i].uncheck();
                        break;
                    }
                }
            },

            /**
             * 清除所有已选行
             */
            clearSelection() {
                for (let i = 0; i < this.trChildren.length; i++) {
                    if (this.trChildren[i].checked) {
                        this.trChildren[i].uncheck();
                    }
                }
            },

            /**
             * 获取已选中行
             */
            getSelections() {
                let res = [];
                for (let i = 0; i < this.trChildren.length; i++) {
                    if (this.trChildren[i].checked) {
                        res.push(i);
                    }
                }
                return res;
            }
        }
    }
</script>

<style lang="scss">
</style>