/**
 * set column width
 */
<template>
    <Modal v-model="show" title="设置列宽" @on-ok="ok" @on-cancel="cancel">
        <Row>
            <Col span="6">列宽:</Col>
            <Col span="18"><Input v-model="width"></Input></Col>
        </Row>
    </Modal>
</template>

<script>
    import Hub from '../../../Hub.js'
    import { setDirty } from '../../utils/Utils.js';
    import { mapState } from 'vuex';
    
    export default {
        name: 'SetColumnWidth',
        data() {
            return {
                show: false,
                width: 0
            };
        },
        computed: {
            ...mapState(['context', 'currColumnWidth'])
        },
        methods: {
            ok() {
                const hot = this.context.hot;
                
                const selected = hot.getSelected()[0];
                const startCol = selected[1];
                const colWidth = hot.getColWidth(startCol);
                const colWidths = hot.getSettings().colWidths;
                colWidths.splice(startCol, 1, this.width);
                hot.updateSettings({
                    colWidths: colWidths,
                    manualColumnResize: colWidths
                });

                this.show = false 
            },
            cancel() {
                this.show = false;
            }
        },
        created() {
            const that = this;
            Hub.$on('show_set_column_width_dialog', () => {
                that.show = true;
                that.width = that.currColumnWidth;
            });
        }
    };
</script>

<style>
</style>
