<template>
    <div class="op-page snmp-page">
        <cs-dynamic-table ref="child" :prop="csTable" :parent="this">
            <template slot="form" scope="props">
                <snmp-form :model="props.obj" :action="props.action" :tableVm="props.tableVm" @close-modal="props.closeModal" :tableInfo="props.tableInfo" ref="form"></snmp-form>
            </template>
        </cs-dynamic-table>
    </div>
</template>
<script lang="ts">
    import { Component, Prop, Vue, Emit,Watch } from "vue-property-decorator";
    import SnmpForm from "./snmp-form.vue";

    @Component({
        components: {
            SnmpForm
        }
    })
    export default class SNMP extends Vue {
        private csTable:any = {
            formWidth: 35,
            parentVm: this,
            dataSrc: this.$msPrefix.base+"/api/v1/data/all/snmpCollector",
            delSrc: this.$msPrefix.base+"/api/v1/data/delete/snmpCollector/",
            batchDelUri: this.$msPrefix.base+"/api/v1/data/batch/snmpCollector",
            dataProp: "data.content",
            postMethod: false,
            pageableProp: {
                pageSize: "data.size",
                total: "data.totalElements",
                currentPage: "data.number"
            },
            showIndex: true,
            emptyModel:  {
                code: "",
                version: 0,
                port:null,
                username: "",
                password: "",
                privateKey: "",
                rcommunity: "",
                rwCommunity: "",
                expireTime: "",
                reconnectCount: "",
                description:""
            },
            columns: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center',
                },
                {
                    type: 'index',
                    align: 'center',
                    title:"序号"
                }, {
                    key: 'code',
                    title: '标识',
                    align: 'center',
                },
                {
                    key: 'version',
                    title: '版本',
                    align: 'center',
                    render: (h, params) => {
                        let value=['SNMPv1','SNMPv2','SNMPv3','其他认证方式'][params.row.version];
                        return h('span',value)
                    }
                },
                
                {
                    key: 'ip',
                    title: '地址',
                    align: 'center',
                },
                {
                    key: 'port',
                    title: '端口',
                    align: 'center',
                },
                {

                    title: '操作',
                    key: 'action',
                    minWidth:200,
                    align: 'center',
                    render: (h, params) => {
                        let menus = [{
                            icon: 'ios-eye',
                            action: 'detail',
                            label: '详情',
                            type:'info'
                        }, {
                            icon: 'ios-create-outline',
                            action: 'update',
                            label: '编辑',
                            type:'primary'
                        }, {
                            icon: 'md-trash',
                            action: 'delete',
                            label: '删除',
                            type:'error'

                        }];
                        let clickEvent = this.clickEvent;
                        return h('div', [
                            h('CsButton', {
                                props: {
                                    actions: menus,
                                    click: clickEvent,
                                    data: params.row,
                                    size:"small",
                                    styleCss:"marginRight:5px",
                                    disabled:params.row._disabled
                                },
                            })
                        ]);
                    }
                }]
        }

        clickEvent(name:string, obj:any) {
            if(name == 'delete') {
                (this.$refs.child as any).handleDelete(obj.id)
            }else {
                (this.$refs.child as any).formInfo.title = name == 'update' ? "编辑" : "详情";
                (this.$refs.child as any).formInfo.action = name == 'update' ? 'update' : 'detail';
                (this.$refs.child as any).formInfo.model = _.cloneDeep(obj);
                (this.$refs.child as any).dialogVisible = true;
            }

        }

        mounted(){
           
        }

    }
</script>

