tableConfig.vue 2.83 KB
<template>
    <el-dialog
        :title="$t('配置显示列')"
        :visible.sync="configBool"
        width="50%"
        :close-on-click-modal="false"
        class="manage-dialog"
        :before-close="closeDialog"
        >
        <!-- 自定义字段 S -->
        <el-checkbox-group v-model="keys" style="padding-bottom:20px;" >
            <el-checkbox style="margin-top:6px;margin-bottom:6px;min-width:120px;" v-for="item in tabColumn" :checked="item.checked" :disabled="item.disable" :label="item.label" :key="item.prop"></el-checkbox>
        </el-checkbox-group>
        <!-- 自定义字段 e -->
        <div slot="footer" class="dialog-footer">
            <el-button class="dialog-btn" @click="closeDialog">{{$t('dialog.cancel')}}</el-button>
            <el-button
            type="primary"
            @click="confirmSubmit"
            class="dialog-btn dialog-confirm-btn"
            >{{$t('dialog.confirm')}}</el-button>
        </div>
    </el-dialog>                                                          
</template>
<script>
import _ from 'underscore';
export default {
    name: 'tableConfig',
    data() {
        return {
           tabKey:'', 
           tabColumn:[],
           keys:[],
           configBool:false
        }
    },
    methods:{
        initDialog({tabKey,tabColumn}){
            this.tabKey = tabKey+'_itable';
            let localCols = localStorage.getItem(this.tabKey);
            let hasConfig = false;
            if(localCols){
               hasConfig = true;
               localCols = localCols.split(',');
            }else{
               localCols=[];
            }
            let keys = [];
            let propObj = {};
            this.tabColumn = _.map(tabColumn,col=>{
               if((!hasConfig&&col.show)||(hasConfig&&localCols.includes(col.prop))){
                   col.checked = true;
                   propObj[col.prop] = true;
               }else{
                   col.checked = false  
               }
               col.label = this.$t(col.label);
               col.disable = col.disable||false;
               return col;
           });
           //if(this.keys.length)this.keys = keys;
           return propObj;
        },
        showDialog(){
           this.configBool = true;
        },
        closeDialog(){
           this.configBool = false;
        },
        confirmSubmit(){
            let propsObj = {};
            let propsList =  _.map(this.keys,label=>{
                let col = _.findWhere(this.tabColumn,{label});
                if(col&&col.prop){
                    propsObj[col.prop]=true;
                    return col.prop
                }
                return null;
            });
            localStorage.setItem(this.tabKey,propsList);
            this.$emit('confirm',propsObj);
            this.closeDialog();
        },
    }
}
</script>

<style>

</style>