/*!hnapp.js
* ================
*
* @author
* @support
* @email
* @version
* @license
*/
'use strict';
//判断是否引用jquery
if (typeof jquery === "undefined") {
throw new error("adminlte requires jquery");
}
$.hn = {};
$(function () {
_inithn();
//窗口大小改变时重新计算jqgrid的宽度
$.hn.layout();
$(':input,select', '.form-table').each(function () {
if ($(this).attr('type') != "button" && $(this).attr('type') != "submit"
&& $(this).attr('type') != "reset" && $(this).attr('type') != "image" &&
$(this).attr("disabled") != 'disabled') {
if ($(this).val() == "") {
$(this).css('background-color', '#dbeadd');
} else {
$(this).attr('data-oldvalue', $(this).val())
}
$(this).bind('blur', function () {
if ($(this).val() != "" && $(this).val() != $(this).data("oldvalue")) {
$(this).css('background-color', '#dbeadd');
}
else if ($(this).val() != "" && $(this).val() == $(this).data("oldvalue")) {
$(this).css('background-color', '#fff');
}
})
}
});
})
function _inithn() {
/*
* hn
* @type object
* @description $.hn 为自定义js的主要命名空间
*/
$.hn = {
/* 测试方法
* @method test
* @type function
* @description 测试方法
* @param
* @example $.hn.test()
*/
test: function () {
alert("hello!");
},
/* 测试对象
* @type object
* @description 测试方法
*/
testobject: {
/* 测试对象内方法
* @method hello
* @type function
* @description 测试对象内方法
* @param {string} msg 消息内容
* @example $.hn.testobject.hello('hello!')
*/
hello: function (msg) {
alert(msg);
}
},
/* 页面布局及重绘对象
* @method resize_jqgrid
* @type function
* @description 页面布局及重绘对象
* @example $.hn.layout()
*/
layout: function () {
//if ($('.jqgrid', '.content').length > 0) {
// $('.jqgrid').jqgrid('setgridwidth', $('.content').width() - 2)
//}
$(window, '.content').resize(function () {
if ($('.jqgrid', '.content').length > 0) {
$('.jqgrid').jqgrid('setgridwidth', $('.content').width() - 2)
}
});
if (typeof $.fn.slimscroll != 'undefined') {
$(".modal-body").slimscroll({
alwaysvisible: false,
height: "260px",
size: "3px"
});
}
},
/* 页面布局及重绘对象
* @type object
* @description 页面布局及重绘对象
*/
message: {
/* 弹窗消息
* @method alert
* @type function
* @description 在页面内弹出消息
* @param {string} message 消息内容
* @param {string} title 弹窗题头
* @param {string} classify 弹窗类型,类型有info(i),warn(w),error(e),success(s)
* @example $.hn.message.alert()
*/
alert: function (message, title, classify, callback) {
$.alert(message, classify, callback);
/*
var modalcontent = $("
")
var modalheader = $("")
.append($(''));
if (classify == "info" || classify == "i") {
title = (title == "" || title == nan) ? "系统消息" : title;
$(' ' + title + '
').appendto(modalheader);
}
else if (classify == "warn" || classify == "w") {
title = (title == "" || title == nan) ? "警告信息" : title;
$(' ' + title + '
').appendto(modalheader);
}
else if (classify == "error" || classify == "e") {
title = (title == "" || title == nan) ? "错误信息" : title;
$(' ' + title + '
').appendto(modalheader);
}
else if (classify == "success" || classify == "s") {
title = (title == "" || title == nan) ? "系统信息" : title;
$(' ' + title + '
').appendto(modalheader);
}
else {
title = (title == "" || title == nan) ? "系统消息" : title;
$(' ' + title + '
').appendto(modalheader);
}
modalheader.appendto(modalcontent);
$('').appendto(modalcontent);
var modal = top.$("").append($("").append(modalcontent));
modal.modal({ keyboard: true }).on('hidden.bs.modal', function (e) {
$(this).detach();
if (callback instanceof function) {
callback();
}
});
*/
},
/* confirm弹窗
* @method confirm
* @type function
* @description 在页面内弹出确认信息
* @param {string} message 消息内容
* @param {string} title 弹窗题头
* @param {string} oktext 确认按钮文本,默认为“确认”
* @example $.hn.message.confirm("确认吗?","","").on(function(e){ 取消:e为false,确认:e为true})
*/
confirm: function (message, title, oktext) {
var modalcontent = $("")
var modalheader = $("")
.append($(''));
title = (title == "" || title == nan) ? "提示信息" : title;
oktext = (oktext == "" || oktext == nan) ? "确定" : oktext;
$(' ' + title + '
').appendto(modalheader);
modalheader.appendto(modalcontent);
$('').appendto(modalcontent);
var modelfooter = $("")
.append($(''))
.append($(''));
modelfooter.appendto(modalcontent);
if(typeof(top.$('.modal.fade.confirm').html()) != "undefined"){
return {
on: function () {}
};
}
var modal = top.$("").append($("").append(modalcontent));
modal.modal({ keyboard: true }).on('hidden.bs.modal', function (e) {
$(this).detach();
});
return {
on: function (callback) {
if (callback && callback instanceof function) {
modal.find('.btn-ok').one("click",function () {
callback(true);
});
modal.find('.btn-cancel').click(function () { callback(false) });
}
}
};
},
withoutconfirm: function (message, title, oktext) {
var modalcontent = $("")
var modalheader = $("")
.append($(''));
title = (title == "" || title == nan) ? "提示信息" : title;
oktext = (oktext == "" || oktext == nan) ? "确定" : oktext;
$(' ' + title + '
').appendto(modalheader);
modalheader.appendto(modalcontent);
$('').appendto(modalcontent);
var modelfooter = $("")
.append($(''))
.append($(''));
modelfooter.appendto(modalcontent);
var modal = top.$("").append($("").append(modalcontent));
modal.modal({ keyboard: true }).on('hidden.bs.modal', function (e) {
$(this).detach();
});
return {
on: function (callback) {
if (callback && callback instanceof function) {
modal.find('.btn-ok').click(function () {
if(modal.find('#tags').is(":checked")){
$('#mytags').val(modal.find('#tags').val());
}
callback(true) });
modal.find('.btn-cancel').click(function () { callback(false) });
}
}
};
}
},
/* confirm弹窗
* @method confirm
* @type function
* @description 在页面内弹出确认信息
*/
dialog:{
/*
* @method open
* @type function
* @description 弹出页面
* @param {json} opt 页面参数
* //$.hn.dialog.open({url:"",title:"",style:""});
*/
open:function(opt){
/*
*opt.url:弹出页请求的url
*opt.title:弹出页标题
*opt.width:弹出页宽度
*opt.height:弹出页高度
*opt.top:弹出页上边距
*opt.left:弹出页左边距
*/
// window.open(opt.url,opt.title,'height='+opt.style.height+',width='+opt.style.width+',top='+opt.style.top+',left='+opt.style.left+',toolbar=0,menubar=0,scrollbars=0, resizable=0,location=0, status=0');
//window.open ('../../jsp/price/pricechangeexedetailgrid.jsp','newwindow','height=300,width=620,top=200,left=500,toolbar=0,menubar=0,scrollbars=0, resizable=0,location=0, status=0');
top.dialog({
id: opt.id,
title: opt.title,
url: opt.url,
data: opt.data,
width: opt.width,
height: opt.height,
padding: "2px",
onclose: function () {
if (opt.closefunc != "" && typeof (opt.closefunc) == "function") {
opt.closefunc(this.returnvalue);
}
}
}).showmodal();
},
/*
* @method opendialog
* @type function
* @description 弹出页面
* @param {string} opt 页面参数
* //$.dialog.opendialog('test-dialog','测试','example/list1.html','800px','400px',"");
*/
opendialog: function (id,title, url, width, height,closefunc) {
// 固定物流信息弹框宽度以便展示, 后期重构时重写每个物流信息的弹框调用
width = '800px';
top.dialog({
id: id,
title: title,
url: url,
width: width,
height: height,
onclose:function () {
if(closefunc!=""&&typeof(closefunc)=="function"){
closefunc(this.returnvalue);
}
/*var strs = new array();
strs = this.returnvalue.split("|$");
if (this.returnvalue.length>0) {
//$('#'+id).val('');
$('#'+id).val(strs[0]);
}
if (this.returnvalue.length>0) {
//$('#'+name).html('');
$('#'+name).html(strs[1]);
}
console.log('onclose');*/
},
padding: "2px"
}).showmodal();
}
},
// 弹窗口
window : {
open : function(opts) {
if (opts) {
var id = opts.id || "";
var title = opts.title || "";
var url = opts.url || "";
var callback = opts.callback || null;
var $window = $("");
var $header = $("");
var $close = $("");
var $iframe = $("");
$header.append($close);
$window.append($header).append($iframe);
var modal = top.$("").append($window);
modal.data("callback", callback);
modal.modal({ keyboard: true }).on('hidden.bs.modal', function (e) {
$(this).detach();
});
$close.click(function() {
if (callback instanceof function) {
callback();
}
});
}
},
close : function(id, args) {
top.window.$("div.modal-backdrop.fade.in").remove();
var $modal = top.$("#" + id);
var callback = $modal.data("callback");
$modal.detach();
if (callback instanceof function) {
callback(args);
}
}
}
}
}
(function ($) {
$.fn.hnselect = function (v) {
/*
*v.parent_selector:父级select
*v.url:请求的url
*v.data:请求url时传的data,父级select未指定时必须传data
*v.dataid:传参时参数名称,参数值为父级select选定的值
*v.func():执行ajax请求获取select数据成功后执行的函数
*v.defaultselect:默认选中选
*v.defaulttext:默认加载项
*/
/* 保存当前对象 */
var self = this;
v.isfirstselect = v.isfirstselect||0;
var backup = $(self).clone();
/* 判断父级select是否为空*/
if (v.parent_selector == "" || v.parent_selector == undefined) {
return this.each(function () {
$.ajax({
url: v.url,//action地址
data: v.data,//传值
type: "post",//执行方式get or post 默认以post方式执行
datatype: "json",
success: function (json, textstatus) {
/* 清空当前select */
$("option", self).remove();
if (v.defaulttext != undefined)
$(self).append(v.defaulttext);
//alert(json);
$.map(json, function (item) {
//alert(item.value + item.text);
$(self).append("");
});
if (1 === $("option", this).size() && $(this).val() === "") {
$(self).attr("disabled", "disabled");
} else {
$(self).removeattr("disabled");
}
if (v.defaultselect != undefined)
//alert(json.stringify(v.defaultselect));
$(self).val(v.defaultselect);
if (v.func != undefined)
v.func();
}
});
});
}
else {
return this.each(function () {
$(v.parent_selector).each(function () {
$(this).bind("change", function () {
if (v.isfirstselect > 1) {
v.defaultselect = "";
}
var data = {};
if ($(":selected", v.parent_selector).val() != "") {
var id = $(v.parent_selector).attr("id");
if (v.dataid != undefined)
id = v.dataid;
var value = $(":selected", v.parent_selector).val();
data[id] = value;
$.ajax({
url: v.url,//action地址
data: data,//传值
type: "post",//执行方式get or post 默认以post方式执行
datatype: "json",
success: function (json, textstatus) {
var selected_key = $(':selected', self).val();
$("option", self).remove();
if (v.defaulttext != undefined)
$(self).append(v.defaulttext);
$.map(json, function (item) {
$(self).append("");
});
if (1 === $("option", self).size() && $(self).val() === "") {
$(self).attr("disabled", "disabled");
} else {
$(self).removeattr("disabled");
}
$(self).trigger("change");
if (v.defaultselect != undefined)
$(self).val(v.defaultselect);
if (v.func != undefined)
v.func();
}
});
}
else {
$("option", self).remove();
if (v.defaulttext != undefined)
$(self).append(v.defaulttext);
}
});
$(this).trigger("change");
});
});
}
};
/*
$.fn.hnselect = function (v) {
v.p = 0;
var select = $.fn.hnselects(v);
};
*/
$.extend({
alert : function(msg, type, callback) {
top.$.topalert(msg, type, callback);
},
topalert : function(msg, type, callback) {
var $div = top.$("div.msg-div");
if ($div == null || $div.length == 0) {
$div = $("");
top.$("body").append($div);
}
var $text = $("");
if (type == "success") {
$text.append("");
$text.css("background-color", "#00c0ef");
} else if (type == "error") {
$text.append("");
$text.css("background-color", "#dd4b39");
} else if (type == "warn") {
$text.append("");
$text.css("background-color", "#f39c12");
}
$text.append(msg || "");
$div.append($text);
$div.show();
$text.animate({"margin-left":"0px"});
$text.delay(1000).animate({"margin-left":"250px"}, function() {
$text.remove();
if ($div.children().length == 0) {
$div.hide();
if (typeof callback == "function") {
callback();
}
}
});
}
});
$.fn.extend({
// 模糊搜索企业
fuzzysearchcomp : function(callback) {
var selflist = this;
return this.each(function(i, obj) {
var $panel = $('');
var left = $(this).offset().left;
var top = $(this).offset().top + 23;
$panel.css("left", left + "px");
$panel.css("top", top + "px");
$("body").append($panel);
var fuzzytimer = null;
$(this).bind("keydown", function() {
cleartimeout(fuzzytimer);
});
$(this).bind("keyup focus click", function(event) {
cleartimeout(fuzzytimer);
(function(self, $panel) {
fuzzytimer = settimeout(function() {
var oldname = self.data("oldname") || "";
var compname = $.trim(self.val()).touppercase();
if (compname == null || compname == "") {
$panel.hide();
return;
}
if (oldname == compname && $panel.is(":visible")) {
return;
}
self.data("oldname", compname);
if (event.which == 37 || event.which == 38
|| event.which == 39 || event.which == 40
|| event.which == 13) {
return;
}
$.post(getrootpath() + "/stdcompinfo/searchcompbyname.html", {
"compname" : compname
}, function(result) {
if (result.success) {
var list = result.rows || [];
$panel.children().remove();
if (list.length > 0) {
for (var i=0; i= 0) {
var before = py.substring(0, pi);
var after = py.substr(pi + compname.length);
py = before + "" + compname + "" + after;
} else if (ni >= 0) {
var before = name.substring(0, ni);
var after = name.substr(ni + compname.length);
name = before + "" + compname + "" + after;
}
var left = '' + py + '';
var right = '' + name + '';
var $li = $('' + left + right + '');
$li.data("comp", comp);
$panel.append($li);
}
$panel.children("li:first").addclass("fuzzy-search-focus");
$panel.children("li:last").css("border-bottom", "0px none");
$panel.children("li").hover(function() {
$panel.children("li").removeclass("fuzzy-search-focus");
$(this).addclass("fuzzy-search-focus");
});
$panel.children("li").click(function() {
var comp = $(this).data("comp");
var compcode = comp.code;
var compname = comp.name;
self.val(compname);
$panel.hide();
if (callback instanceof function) {
callback(compcode);
}
});
} else {
$panel.append('没有符合条件的记录!');
}
if ($panel.is(":not(:visible)")) {
$panel.show();
}
}
}, "json");
}, 500);
})($(this), $panel);
event.stoppropagation();
});
$(this).keyup(function(event) {
if (event.which == 37 || event.which == 38
|| event.which == 39 || event.which == 40
|| event.which == 13) {
var $lis = $panel.children("li");
if ($panel.is(":visible") && $lis.length > 0) {
var $curli = $lis.filter(".fuzzy-search-focus");
var $nextli = null;
switch (event.which) {
case 38:
$nextli = $curli.prev();
if ($nextli.length <= 0) {
$nextli = $lis.filter(":last");
}
break;
case 40:
$nextli = $curli.next();
if ($nextli.length <= 0) {
$nextli = $lis.filter(":first");
}
break;
case 13:
var comp = $curli.data("comp");
var compcode = comp.code;
var compname = comp.name;
$(this).val(compname);
$panel.hide();
if (callback instanceof function) {
callback(compcode);
}
return;
}
if ($nextli.length > 0) {
$curli.removeclass("fuzzy-search-focus");
$nextli.addclass("fuzzy-search-focus");
}
}
}
});
$(this).blur(function() {
var $curli = $panel.children("li.fuzzy-search-focus");
var comp = $curli.data("comp") || {};
var compcode = comp.code || "";
var compname = comp.name || "";
$(this).val(compname);
$panel.hide();
if (callback instanceof function) {
callback(compcode);
}
});
});
}
});
$(window).bind("click", function(){
$("ul.fuzzy-search-ul").hide();
});
})(jquery);
//json util
var json = {
//------json深拷贝------
"clone" : function(param) {
var jsonobject = null;
if (param instanceof array) {
jsonobject = [];
for (var i=0; i请选择");
data = uniquearray(data);
console.log("格式化后:"+data.length);
for(var i in data){
var name = typeof(data[i].name)=="undefined"?data[i].projname:data[i].name;
self.append("");
}
self.trigger("change");
}
function uniquearray(data){
for ( var i = 1; i < data.length; i++ ) {
if ( data[i].projid === data[ i - 1 ].projid ) {
data.splice( i--, 1 );
}
}
return data;
}
//js获取项目根路径,如: http://localhost:8083/uimcardprj
function getrootpath() {
//获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
var curwwwpath=window.document.location.href;
//获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
var pathname=window.document.location.pathname;
var pos=curwwwpath.indexof(pathname);
//获取主机地址,如: http://localhost:8083
var localhostpaht=curwwwpath.substring(0,pos);
//获取带"/"的项目名,如:/uimcardprj
var projectname=pathname.substring(0,pathname.substr(1).indexof('/')+1);
return(localhostpaht+projectname);
}
// 根据企业code展示企业信息
function showcompinfo(compcode, compname) {
$.hn.dialog.opendialog(
compcode,
"企业详情",
getrootpath() + '/stdcompinfo/tocompinfobycode.html?compcode=' + compcode,
'800px',
'510px'
);
}
//根据企业code展示企业信息
function showdruginfo(drugcode, drugname) {
$.hn.dialog.opendialog(
drugcode,
"药品详情",
getrootpath() + '/stdproddruginfo/todruginfobycode.html?drugcode=' + drugcode,
'800px',
'550px'
);
}
//根据医疗机构code展示医疗机构信息
function showhospinfo(hospcode) {
$.hn.dialog.opendialog(
hospcode,
"医疗机构详情",
getrootpath() + '/stdhospinfo/tohospinfobycode.html?hospcode=' + hospcode,
'800px',
'510px'
);
}
// 药品弹窗信息链接
function druginfolink(drugcode, drugname, type) {
var str = "";
if (type == 1 && drugcode && drugname) { // 药品名称上加链接[type == 1]
str = "" + drugname + "";
} else if (drugcode) { // 默认药品编码上加链接[type == 0]
str = "" + drugcode + "";
}
return str
}
// 企业弹窗信息链接
function compinfolink(compcode, compname, type) {
var str = "";
if (type == 1 && compcode && compname) { // 企业名称上加链接[type == 1]
str = "" + compname + "";
} else if (compcode) { // 默认企业编码上加链接[type == 0]
str = "" + compcode + "";
}
return str;
}
//医院弹窗信息链接
function hospinfolink(hospcode, hospname, type) {
var str = "";
if (type == 1 && hospcode && hospname) { // 医院名称上加链接[type == 1]
str = "" + hospname + "";
} else if (hospcode) { // 默认医院编码上加链接[type == 0]
str = "" + hospcode + "";
}
return str;
}
function create(){//jqgrid高度自适应
var heightall = $(window).height();//获取整个页面window的高度
var heightsearch = $('.box').height();//获取查询条件的高度
var heightbutt = $('.bottongroup').height();//获取jqgrid下方操作按钮的高度
var heightheard = $('.jqgrid', '.content').offset();//获取页面题头的高度
var heighttable = 255;//默认jqgrid的高度
if (heightheard != undefined){//判断题头
heighttable = heightall - heightheard.top - heightsearch - 10 -20;
if(heightbutt != null){
heighttable = heightall - heightheard.top - heightsearch - 10 -20 - heightbutt;
}
}
if (heighttable > 600){//jqgrid的高度不能大于600,大于的固定600
heighttable = 600;
}
return heighttable;
}
function changeselectchecked(gridlist,num,value,event){
var ids = $(gridlist).jqgrid('getdataids');
if(!$('#jqg_gridlist_'+num).is(':checked')){
if(event.which==13 || (event.which==8)){
return;
}
$(gridlist).setselection(ids[--num],true);
} if(value.length==0 && $('#jqg_gridlist_'+num).is(':checked')){
$(gridlist).setselection(ids[--num],true);
}
}
$.extend({
standardpost:function(url,args){
var form = document.createelement("form");
form.method = "post";
form.action = url;
form.style.display = "none";
var input;
$.each(args,function(key,value){
input = document.createelement("textarea");
input.name = key;
input.value = value;
form.appendchild(input);
});
document.body.appendchild(form);
form.submit();
return form;
/* var form = $(""),
input;
form.attr({"action":url});
$.each(args,function(key,value){
input = $("");
input.attr({"name":key});
input.val(value);
form.append(input);
});
form[0].submit();*/
}
});