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

<script type="text/javascript">

    /* *************************** 模块初始化 ***************************** */
    var editorOrganization = {
        actionUrl:"${contextRoot}/org/addOrg",
        init: function () {

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


            $("#qlcAdapterVersion").ligerComboBox({
                valueField: 'id',
                textField: 'text',
                tree: {
                    url:'/adapterCenter/getVersionTree',
                    textFieldName:"text",
                    idFieldName:"id",
                    parentIDFieldName:"pid",
                    checkbox:false
                }
            });
            $("#selOrgType").ligerComboBox({dict:true,dictName:"ORG_TYPE"});
            $("#selSettledWay").ligerComboBox({dict:true,dictName:"SETTLED_WAY"});


            var modelString = "${model.id}";
            var data;
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                debugger
                data = {
                    id: "${model.id}",
                    code: "${model.code}",
                    fullName: "${model.fullName}",
                    pid:"${model.pid}",
                    shortName: "${model.shortName}",
                    pyCode: "${model.pyCode}",
                    area: "${model.area}",
                    address: "${model.address}",
                    orgType: "${model.orgType}",
                    settledWay: "${model.settledWay}",
                    tel: "${model.tel}",
                    tags: "${model.tags}",
                    activityFlag: "${model.activityFlag}",
                    qlcOrgCode:"${model.qlcOrgCode}",
                    qlcAdapterVersion:"${model.qlcAdapterVersion}"
                };

                me.actionUrl = "${contextRoot}/org/updateOrg";
            }

            $("#div_info_form").ligerAutoForm({
                data:data,
                validate:{
                    code:"required",
                    fullName: {
                        required:true
                    }
                },
                message:{
                    code:"机构代码不能为空！",
                    fullName:"机构名称不能为空！"
                }
            });
        },
        bindEvents: function () {
            var me = this;
            $("#btnSave").click(function () {
                if(!$("#div_info_form").ligerAutoForm("validate"))
                {
                    return;
                }
                var data = $("#div_info_form").ligerAutoForm("getData");
                debugger
                $.ajax({ //ajax处理
                    type: "POST",
                    url : me.actionUrl,
                    dataType : "json",
                    data:data,
                    cache:false,
                    success :function(data){
                        if(data.successFlg) {
                            parent.organization.dialogSuccess(data.message);
                        }
                        else{
                            $.ligerDialog.error(data.message);
                        }
                    },
                    error :function(data){
                        $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                    }
                });
            });

            $("#btnCancel").click(function(){
                parent.organization.dialog.close();
            });

        }
    };



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