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

    /* *************************** 模块初始化 ***************************** */
    var systemParam = {
        grid: null,
        dialog: null,
        init: function () {
            var me = this;
            $('.m-retrieve-area').show();
            $("#txtName").ligerSearch({
                onClick:function(value){
                    me.reloadGrid();
                }});
            me.grid = $("#div_grid").ligerGrid({
                url: '${contextRoot}/param/getParamList',
                parms: {
                    name: $('#txtName').val()
                },
                columns: [
                    {display: '参数名', id: 'paramKey', name: 'paramKey', width: '30%'},
                    // {display: '所属机构', name: 'name', width: '10%', align: "center"},
                    {display: '参数值', name: 'paramValue', width: '30%'},
                    {display: '备注', name: 'remark', width: '30%'},
                    {
                        display: '操作', name: 'operator', width: '10%', render: function (row) {

                        var html = '<div class="m-inline-buttons" style="width:80px;">';
                        html += "<a class=\"m-btn-edit\" onclick=\"systemParam.editorDialog('"+row.id+"')\"></a>";
                        html += "<a class=\"m-btn-delete\" onclick=\"systemParam.delete('"+row.id+"')\"></a>";
                        html += '</div>';
                        return html;
                    }
                    }
                ],
                onDblClickRow: function (row) {
                    me.editorDialog(row.id);
                }
            });
            me.bindEvents();

        },
        bindEvents: function () {
            var me = this;

            $('#div_new_record').click(function () {
                me.editorDialog();
            });
        },
        delete:function(id){
            var message = "确定要删除该系统参数吗？";

            jQuery.ligerDialog.confirm(message, function (confirm) {
                if (confirm)
                {
                    $.ajax({ //ajax处理
                        type: "POST",
                        url : "${contextRoot}/param/deleteParam",
                        dataType : "json",
                        data:{id:id},
                        cache:false,
                        success :function(data){
                            if(data.successFlg) {
                                $.ligerDialog.success(data.message);
                                systemParam.grid.reload();
                            }
                            else{
                                $.ligerDialog.error(data.message);
                            }
                        },
                        error :function(data){
                            $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                        }
                    });
                }
            });
        },
        //刷新列表数据
        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 = {"id": id};
            }

            me.dialog = $.ligerDialog.open({
                height: 260,
                width: 500,
                title: title,
                url: '${contextRoot}/param/editorParam',
                //load: true,
                urlParms: params
            });
        },
        anthorize: function (id) {

        },
        //弹窗返回
        dialogSuccess: function (message) {
            $.ligerDialog.success(message);
            this.reloadGrid();
            this.dialog.close();
        }
    };

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