<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head :: head(link)"/>
<body>
<div id="app" class="ok-body" v-cloak>
    <!--模糊搜索区域-->
    <template>
        <div style="margin-bottom: 8px;margin-top: 8px;">
            <i-input placeholder="输入内容"  v-model="role.description"  style="width: 300px"></i-input>
            <i-button type="primary"  icon="ios-search" @click="load()">搜索</i-button>
            <i-button type="primary"  icon="ios-redo" @click="reload()" >重置</i-button>
            <i-button type="primary"  style="float:right;" icon="md-add" @click="add()">新增</i-button>
        </div>
    </template>
    <template>
        <i-table  size="small" :columns="tableTitle"  :data="tableData"></i-table>
        <br>
        <Page  style="float: right;" :current="role.pageNo" :total="tableSize" :page-size="role.pageSize"  @on-change="changePage" @on-page-size-change="changePageSize" show-elevator show-sizer show-total></Page>
    </template>
</div>
<div th:replace="common/foot :: foot(script)"></div>
<script th:inline="none">
layui.use(["okUtils", "okLayer"], function () {
    var okUtils = layui.okUtils;
    var okLayer = layui.okLayer;
    var vm = new Vue({
        el: '#app',
        data: function(){
        var _this = this;
		return {
            tableTitle : [{
                title: '序号',
                minWidth : 100,
                render: function(h, params) {
                    return h('span', params.index + (_this.role.pageNo- 1) * _this.role.pageSize + 1);
                }
            },{
                key : "roleSign",
                title : "角色标识",
                minWidth:100
            },{
                key : "roleName",
                title : "角色名称",
                minWidth:100
            },{
                key : "remark",
                title : "备注",
                minWidth:150
            },{
                key : "gmtCreate",
                title : "创建时间",
                minWidth:150
            },{
                title : '操作',
                key : 'action',
                minWidth : 350,
                align : 'center',
                render : function(h, params) {
                    var functionList = [];
                    var edit = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'md-create'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.edit(params.row);
                            }
                        }
                    }, '修改');
                    functionList.push(edit);
                    var remove = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'md-trash'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.remove(params.row);
                            }
                        }
                    }, '删除');
                    functionList.push(remove);
                    var menu = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'ios-build'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.menu(params.row);
                            }
                        }
                    }, '菜单权限');
                    functionList.push(menu);
                    var org = h('Button', {
                        props : {
                            type : 'primary',
                            size : 'small',
                            icon : 'ios-build'
                        },
                        style : {
                            marginRight : '8px'
                        },
                        on : {
                            click : function() {
                                vm.org(params.row);
                            }
                        }
                    }, '数据权限');
                    functionList.push(org);
                    return h('div', functionList);
                }
            } ],
            tableData : [],
            role : {
                pageSize : 10,
                pageNo : 1,
                startTime : '',
                endTime : '',
                description:''
            },
            tableSize : 50
          }
        },
        methods: {
            load : function() {
                var that = this;
                okUtils.ajaxCloud({
                    url:"/sys/role/list",
                    param : that.role,
                    success : function(result) {
                         that.tableData = result.msg.pageData;
                         that.tableSize = result.msg.totalCount;
                    }
                });
            },
            reload :  function(){
                vm.role.description = "";
                this.load();
            },
            changePage : function(pageNo) {
                vm.page.pageNo = pageNo;
                vm.load();
            },
            changePageSize : function(pageSize) {
                vm.page.pageSize = pageSize;
                vm.load();
            },
            add:function(){
                okUtils.dialogOpen({
                    title: '新增',
                    url: "sys/role/form.html",
                    scroll : true,
                    width: '30%',
                    height: '45%',
                    success : function(dialog) {

                    },
                    yes : function(dialog) {
                        dialog.vm.acceptClick(vm);
                    }
                });
            },
            edit : function(role) {
                okUtils.dialogOpen({
                    title: '修改',
                    url: "sys/role/form.html",
                    scroll : true,
                    width: '30%',
                    height: '45%',
                    success : function(dialog) {
                        dialog.vm.role = JSON.parse(JSON.stringify(role));
                    },
                    yes : function(dialog) {
                        dialog.vm.acceptClick(vm);
                    }
                });
            },
            remove : function (role) {
                 if(role.roleSign=="admin"){
                    okLayer.msg.redCross("Admin不允许删除");
                    return;
                 }
                 okLayer.confirm("确定要删除吗？", function () {
                    okUtils.ajaxCloud({
                        url:"/sys/role/delete",
                        param : {roleId: role.roleId},
                        success : function(result) {
                            okLayer.msg.greenTick(result.msg, function () {
                                 vm.load();
                            });
                        }
                    });
                 });
            },
            menu: function (role) {
                okUtils.dialogOpen({
                    title: '菜单',
                    url: "sys/role/menu.html",
                    scroll : true,
                    width: '300px',
                    height: '500px',
                    success : function(dialog) {
                        dialog.vm.roleId = role.roleId;
                        dialog.vm.load();
                    },
                    yes : function(dialog) {
                        dialog.vm.acceptClick(dialog);
                    }
                });
            },
            org: function (role) {
                okUtils.dialogOpen({
                    title: '机构',
                    url: "sys/role/org.html",
                    scroll : true,
                    width: '300px',
                    height: '500px',
                    success : function(dialog) {
                        dialog.vm.roleId = role.roleId;
                        dialog.vm.load();
                    },
                    yes : function(dialog) {
                        dialog.vm.acceptClick(dialog);
                    }
                });
            }
        },
        created: function() {
            this.load()
        }
    });
});
</script>
</body>
</html>