<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
<script>

        /* *************************** 模块初始化 ***************************** */
        var organization = {
            grid:null,
            dialog:null,
            init: function () {
                var me = this;

                me.grid = $("#div_grid").ligerGrid({
                    url: '${contextRoot}/org/getOrgList',
                    columns: [
                        {display:'机构代码',name:'code', width: '10%'},
                        {display:'机构名称',name:'fullName', width: '20%'},
                        {display:'机构地址',name:'address', width: '20%'},
                        {display:'机构类型',name:'orgType',width: '15%',dict: true,dictName:"ORG_TYPE"},
                        {display:'入驻方式',name:'settledWay',width: '15%',dict: true,dictName:"SETTLED_WAY"},
                        {display:'操作', name: 'operator', width: '20%', render: function (row) {
                            var html = '<div class="m-inline-buttons" style="width:80px;">';

                            html += '<a class="m-btn-edit" onclick="javascript:organization.editorDialog(\''+row.id+'\')"></a>';
                            html += '<a class="m-btn-delete" onclick="javascript:organization.deleteOrg(\''+row.id+'\')"></a>';
                            html += '</div>';
                            return html;
                        }}
                    ],
                    onDblClickRow : function (row){
                        me.editorDialog(row.id);
                    }
                });

                $("#txtName").ligerSearch({onClick:function(value){
                    me.reloadGrid();
                }});

                $('#btnAdd').click(function () {
                    me.editorDialog();
                });
            },
            //刷新列表数据
            reloadGrid:function(){
                this.grid.set({
                    parms: {name:$('#txtName').val()}
                });
                this.grid.reload();
            },
            //编辑弹窗
            editorDialog:function(id){
                var me = this;
                var title = "新增组织信息";
                var params = null;
                if(id!=undefined&&id!=null)
                {
                    title = "编辑组织信息";
                    params = {orgId:id};
                }

                me.dialog = $.ligerDialog.open({
                    height: 600,
                    width: 600,
                    title: title,
                    url: '${contextRoot}/org/editorOrganization',
                    //load: true,
                    urlParms: params
                });
            },
            //删除机构
            deleteOrg:function(id){
                var me = this;
                jQuery.ligerDialog.confirm("确定要删除该机构吗？", function (confirm) {
                    if (confirm)
                    {
                        $.ajax({ //ajax处理
                            type: "POST",
                            url : '${contextRoot}/org/deleteOrg',
                            dataType : "json",
                            data:{orgId:id},
                            cache:false,
                            success :function(data){
                                if (data.successFlg) {
                                    me.grid.reload();
                                    $.ligerDialog.success(data.message);
                                }
                                else{
                                    $.ligerDialog.error(data.message);
                                }
                            },
                            error :function(data){
                                $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                            }
                        });
                    }
                });
            },
            //设置有效无效
            activity: function (id,activityFlag) {
                var me = this;
                $.ajax({ //ajax处理
                    type: "POST",
                    url : '${contextRoot}/org/activityOrg',
                    dataType : "json",
                    data:{orgId:id,activityFlag:activityFlag},
                    cache:false,
                    success :function(data){
                        if (data.successFlg) {
                            me.grid.reload();
                        }
                        else{
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error :function(data){
                        $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                    }
                });
            },
            //弹窗返回
            dialogSuccess:function(message){
                this.dialog.close();
                this.reloadGrid();
                $.ligerDialog.success(message);
            }
        };

        $(function () {
            organization.init();
        });
</script>