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

            /* ************************** 变量定义 ******************************** */

            // 通用工具类库
            var Util = $.Util;

            // 画面用户信息表对象
            var patientInfoGrid = null;

            // 页面表格条件部模块
            var patientRetrieve = null;

            // 页面主模块，对应于用户信息表区域
            var patientMaster = null;
            /* ************************** 变量定义结束 ******************************** */

            /* *************************** 函数定义 ******************************* */
            function pageInit() {
                patientRetrieve.init();
                patientMaster.init();
            }

            /* *************************** 函数定义结束******************************* */

            patientRetrieve = {
                $element: $(".m-retrieve-area"),
                $searchPatient: $("#inp_search"),
                $newPatient: $("#div_new_patient"),
                init: function () {
                    this.$element.show();
                    this.$searchPatient.ligerTextBox({
                        width: 240, isSearch: true, search: function () {
                            var searchNm = patientRetrieve.$searchPatient.val();
                            patientMaster.searchPatient(searchNm);
                        }
                    })
                }
            };

            patientMaster = {
                init: function () {
                    patientInfoGrid = $("#div_patient_info_grid").ligerGrid({
                        url: '${contextRoot}/patient/searchPatient',
                        // 传给服务器的ajax 参数
                        parms: {
                            searchNm: '',
                            searchType: ''
                        },
                        columns: [
                            {display: '姓名', name: 'name', width: '10%'},
                            {display: '身份证号', name: 'idCardNo', width: '30%', align: 'left'},
                            {display: '性别', name: 'genderValue', width: '20%'},
                            {display: '病人手机', name: 'tel', width: '20%', resizable: true},
                            {display: '家庭地址', name: 'homeAddress', width: '10%', minColumnWidth: 20},
                            {
                                display: '操作', name: 'operator', width: '10%', render: function (row) {
                                var html = '<a href="javascript:void(0)" onclick="javascript:' + Util.format("$.publish('{0}',['{1}'])", "patient:patientInfoModifyDialog:open", row.idCardNo) + '">修改</a>';
                                return html;
                            }
                            }
                        ],
                        onDblClickRow: function (row) {
                            $.ligerDialog.open({
                                title:'<div class="f-ib" style="border-style: solid; border: 1px 1px 0 0; border-radius: 5px; width: 120px;" id="div_patientBasicMsgDialog">病人基本信息</div><div class="f-ib"  id="div_cardManagerDialog"  style="width: 90px">卡管理</div><div class="f-ib"  id="div_recordManagerDialog" style="width: 90px" >档案管理</div>',
                                height: 700,
                                width: 600,
                                url: '${contextRoot}/patient/patientDialogType',
                                load: true,
                                urlParms: {
                                    idCardNo: row.idCardNo,
                                    patientDialogType: 'patientInfoMessage'
                                },
                                isHidden: false
                            });
                        }
                    });
                    patientInfoGrid.adjustToWidth();
                    this.bindEvents();
                },
                searchPatient: function (searchNm) {
                    patientInfoGrid.setOptions({parms: {searchNm: searchNm}});
                    patientInfoGrid.loadData(true);
                },
                bindEvents: function () {
                    var self = this;
                    //新增人口信息
                    patientRetrieve.$newPatient.click(function(){
                        $.ligerDialog.open({
                            isHidden:true,
                            title:'新增人口信息',
                            width:600,
                            height:550,
                            url:'${contextRoot}/patient/patientDialogType',
                            urlParms:{
                                patientDialogType:'addPanient'
                            }
                        })
                    });
                    //修改人口信息
                  $.subscribe('patient:patientInfoModifyDialog:open',function(event,idCardNo){
                        $.ligerDialog.open({
                            isHidden:true,
                            title:'修改人口信息',
                            width:600,
                            height:550,
                            url:'${contextRoot}/patient/patientDialogType',
                            urlParms:{
                                idCardNo:idCardNo,
                                patientDialogType:'updatePanient'
                            }
                        })
                    });
                    //删除人口信息
                    $.subscribe('patient:patientInfoModifyDialog:delete', function (event, idCardNo) {
                        $.ligerDialog.confirm('确认删除该行信息？<br>如果是请点击确认按钮，否则请点击取消。', function (yes) {
                            if (yes) {
                                var dataModel = $.DataModel.init();
                                dataModel.updateRemote('${contextRoot}/patient/deletePatient', {
                                    data: {idCardNo: idCardNo},
                                    success: function (data) {
                                        if (data.successFlg) {
                                            //$.Notice.open({type: 'success', msg: '删除成功！'});
                                            patientMaster.searchPatient();
                                        } else {
                                            $.Notice.open({type: 'error', msg: data.errorMsg});
                                        }
                                    }
                                });
                            }
                        });
                    })
                }
            };

            /* ************************* Dialog页面回调接口 ************************** */
            win.patientDialogRefresh = function () {
                patientMaster.searchPatient();
            };
            /* ************************* Dialog页面回调接口结束 ************************** */
            /* *************************** 页面初始化 **************************** */
            pageInit();
            /* *************************** 页面初始化结束 **************************** */

        });
    })(jQuery, window);
</script>