<template>
    <div class="oo-page">
        <div class="oo-server">
            <cs-dynamic-table ref="child" :prop="csTable" :parent="this">
                <template slot="form" scope="props">
                      <favor-command-form :model="props.obj" :action="props.action" :tableVm="props.tableVm" @closeModal="props.closeModal" :tableInfo="props.tableInfo" ref="form"></favor-command-form>
                </template>
            </cs-dynamic-table>
            <!--            <Modal v-model="modelFlag" title="详情" width="50" :mask-closable="false" @closeModal="closeModal">-->
            <!--                <role-detail-form @closeModal="closeModal" ref="manage" :detail="activeModel"></role-detail-form>-->
            <!--                <div slot="footer"></div>-->
            <!--            </Modal>-->
        </div>
    </div>
</template>

<script lang="ts">
    import { Component, Vue } from "vue-property-decorator";
    import FavorCommandForm from "./favor-form.vue";
    import { State, Mutation, Getter } from "vuex-class";

    @Component({
        components: {
            FavorCommandForm
        }
    })
    export default class Favor extends Vue {
        modelFlag : boolean = false;
        private username = localStorage.getItem("username");
        private activeModel : any = {
            code:"",
            name:"",
            description:"",
            roleMenus:[]
        };
        private csTable : any = {
            formWidth: 35,
            parentVm: this,
            dataSrc: this.$msPrefix.automation+"/api/v1/data/list/commandFavor",
            delSrc: this.$msPrefix.automation+"/api/v1/data/delete/commandFavor/",
            batchDelUri: this.$msPrefix.automation+"/api/v1/data/batch/commandFavor",
            dataProp: "data.content",
            postMethod: true,
            postData:{
                 "#currentUserName": ["userName"]
            },
            pageableProp: {
                pageSize: "data.size",
                total: "data.totalElements",
                currentPage: "data.number"
            },
             search: {
                show: true,
                prop: "commandLike",
                value: "",
                placeholder: "输入命令内容,回车搜索"
            },
            showIndex: true,
            emptyModel:  {
                name:""
            },
            columns: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center',
                }, {
                    key: 'command',
                    title: '命令',
                    align: 'center',
                    ellipsis: true,
                    tooltip: true,
                    sortable:true,
                }, {
                    key: 'description',
                    title: '描述',
                    align: 'center',
                    ellipsis: true,
                    tooltip: true,
                    sortable:true,
                },
                {
                    title: '操作',
                    key: 'action',
                    minWidth:200,
                    align: 'center',
                    render: (h, params) => {
                        let menus = [{
                            icon: 'ios-eye',
                            action: 'detail',
                            label: '详情',
                            type:'primary'
                        },{
                            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;
            }

        }

        closeModal(){
            this.modelFlag=!1;
        }
    }
</script>
