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

    @Component({
        components: {
            SettingForm
        }
    })
    export default class Setting extends Vue {
        private csTable:any = {
            formWidth: 35,
            parentVm: this,
            dataSrc: this.$msPrefix.psem+"/api/v1/data/all/PSEMProfile",
            delSrc: this.$msPrefix.psem+"/api/v1/data/delete/PSEMProfile/",
            batchDelUri: this.$msPrefix.psem+"/api/v1/data/batch/PSEMProfile",
            dataProp: "data.content",
            postMethod: false,
            pageableProp: {
                pageSize: "data.size",
                total: "data.totalElements",
                currentPage: "data.number"
            },
            showIndex: true,
            emptyModel:  {
                name: "",
                type: 0,
                code: "",
                params: "",
                responseKey: "",
                excuteType: "",
                excuteContent: "",
                handleScript: "",
                extInfo: "",
            },
            columns: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center',
                }, {
                    key: 'name',
                    title: '动环配置名称',
                    align: 'center',
                },
                {
                    key: 'type',
                    title: '数据源类型',
                    align: 'center',
                    render: (h, params) => {
                        let value={0:"jdbc",1:"snmp",9:"二次开发"}[params.row.type]
                        return h('span',value)
                    }
                },
                
                {
                    key: 'code',
                    title: '数据源标识',
                    align: 'center',
                },
                // {
                //     key: 'excuteType',
                //     title: '执行参数类型',
                //     align: 'center',
                // },
                // {
                //     key: 'excuteContent',
                //     title: '执行参数内容',
                //     align: 'center',
                // },
                // {
                //     key: 'handleScript',
                //     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.form as any).getPlatData(obj.type);
                (this.$refs.child as any).dialogVisible = true;
            }

        }
        mounted(){
           
        }

    }
</script>

