comm.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. String.prototype.Trim = function() {
  2. return this.replace(/(^\s*)|(\s*$)/g, "");
  3. };
  4. var provinceDATA=[];
  5. provinceDATA.push({'provinceid':'','selected':true,'provincename':'--请选择--'});
  6. provinceDATA.push({'provinceid':'1','provincename':'北京市'});
  7. provinceDATA.push({'provinceid':'2','provincename':'天津市'});
  8. provinceDATA.push({'provinceid':'3','provincename':'河北省'});
  9. provinceDATA.push({'provinceid':'4','provincename':'山西省'});
  10. provinceDATA.push({'provinceid':'5','provincename':'内蒙古'});
  11. provinceDATA.push({'provinceid':'6','provincename':'辽宁省'});
  12. provinceDATA.push({'provinceid':'7','provincename':'吉林省'});
  13. provinceDATA.push({'provinceid':'8','provincename':'黑龙江'});
  14. provinceDATA.push({'provinceid':'9','provincename':'上海市'});
  15. provinceDATA.push({'provinceid':'10','provincename':'江苏省'});
  16. provinceDATA.push({'provinceid':'11','provincename':'浙江省'});
  17. provinceDATA.push({'provinceid':'12','provincename':'安徽省'});
  18. provinceDATA.push({'provinceid':'13','provincename':'福建省'});
  19. provinceDATA.push({'provinceid':'14','provincename':'江西省'});
  20. provinceDATA.push({'provinceid':'15','provincename':'山东省'});
  21. provinceDATA.push({'provinceid':'16','provincename':'河南省'});
  22. provinceDATA.push({'provinceid':'17','provincename':'湖北省'});
  23. provinceDATA.push({'provinceid':'18','provincename':'湖南省'});
  24. provinceDATA.push({'provinceid':'19','provincename':'广东省'});
  25. provinceDATA.push({'provinceid':'20','provincename':'广西省'});
  26. provinceDATA.push({'provinceid':'21','provincename':'海南省'});
  27. provinceDATA.push({'provinceid':'22','provincename':'重庆市'});
  28. provinceDATA.push({'provinceid':'23','provincename':'四川省'});
  29. provinceDATA.push({'provinceid':'24','provincename':'贵州省'});
  30. provinceDATA.push({'provinceid':'25','provincename':'云南省'});
  31. provinceDATA.push({'provinceid':'26','provincename':'西藏'});
  32. provinceDATA.push({'provinceid':'27','provincename':'陕西省'});
  33. provinceDATA.push({'provinceid':'28','provincename':'甘肃省'});
  34. provinceDATA.push({'provinceid':'29','provincename':'青海省'});
  35. provinceDATA.push({'provinceid':'30','provincename':'宁夏'});
  36. provinceDATA.push({'provinceid':'31','provincename':'新疆'});
  37. provinceDATA.push({'provinceid':'32','provincename':'台湾省'});
  38. provinceDATA.push({'provinceid':'33','provincename':'香港'});
  39. provinceDATA.push({'provinceid':'34','provincename':'澳门'})
  40. String.format = function() {
  41. var i = 1 , args = arguments;
  42. var str = args[0];
  43. var re = /\{(\d+)\}/g;
  44. return str.replace(re,function(){return args[i++];});
  45. };
  46. jQuery.yihu = {
  47. url: '/HosYuYue/servlet/ActionServlet'+"?datetime="+new Date(),
  48. fjurl:"/HosYuYue/servlet/FjActionServlet?_id_="+new Date(),
  49. fileurl:"/HosYuYue/servlet/UploadFileServlet?_id_="+new Date(),
  50. createUploadIframe: function(id, uri)
  51. {
  52. //create frame
  53. var frameId = 'jUploadFrame' + id;
  54. var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';
  55. if(window.ActiveXObject)
  56. {
  57. if(typeof uri== 'boolean'){
  58. iframeHtml += ' src="' + 'javascript:false' + '"';
  59. }
  60. else if(typeof uri== 'string'){
  61. iframeHtml += ' src="' + uri + '"';
  62. }
  63. }
  64. iframeHtml += ' />';
  65. jQuery(iframeHtml).appendTo(document.body);
  66. return jQuery('#' + frameId).get(0);
  67. },
  68. createUploadForm: function(id, fileElementId, data)
  69. {
  70. //create form
  71. var formId = 'jUploadForm' + id;
  72. var fileId = 'jUploadFile' + id;
  73. var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
  74. if (data) {
  75. var _data = data.split('&');
  76. for(var i in _data){
  77. if (_data[i]) {
  78. var _d = _data[i].split('=');
  79. if(_d){
  80. jQuery('<input type="hidden" name="' + _d[0] + '" value="' + _d[1] + '" />').appendTo(form);
  81. }
  82. }
  83. }
  84. }
  85. for (var i = 0; i < fileElementId.length; i ++) {
  86. var oldElement = jQuery('#' + fileElementId[i]);
  87. var newElement = jQuery(oldElement).clone();
  88. jQuery(oldElement).attr('id', fileElementId[i]);
  89. jQuery(oldElement).attr('name', fileElementId[i].name);
  90. jQuery(oldElement).before(newElement);
  91. jQuery(oldElement).appendTo(form);
  92. }
  93. //set attributes
  94. jQuery(form).css('position', 'absolute');
  95. jQuery(form).css('top', '-1200px');
  96. jQuery(form).css('left', '-1200px');
  97. jQuery(form).appendTo('body');
  98. return form;
  99. } ,
  100. handleError : function( s, xhr, status, e ) {
  101. // If a local callback was specified, fire it
  102. if ( s.error ) {
  103. s.error.call( s.context || s, xhr, status, e );
  104. }
  105. // Fire the global callback
  106. if ( s.global ) {
  107. (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
  108. }
  109. } ,
  110. ajaxFileUpload: function(s) {
  111. // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
  112. s = jQuery.extend({}, jQuery.ajaxSettings, s);
  113. var id = new Date().getTime()
  114. var form = $.yihu.createUploadForm(id, s.fileElementId,s.data);
  115. var io = $.yihu.createUploadIframe(id, s.secureuri);
  116. var frameId = 'jUploadFrame' + id;
  117. var formId = 'jUploadForm' + id;
  118. // Watch for a new set of requests
  119. if ( s.global && ! jQuery.active++ )
  120. {
  121. jQuery.event.trigger( "ajaxStart" );
  122. }
  123. var requestDone = false;
  124. // Create the request object
  125. var xml = {}
  126. if ( s.global )
  127. jQuery.event.trigger("ajaxSend", [xml, s]);
  128. // Wait for a response to come back
  129. var uploadCallback = function(isTimeout)
  130. {
  131. var io = document.getElementById(frameId);
  132. try
  133. {
  134. if(io.contentWindow)
  135. {
  136. xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
  137. xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
  138. }else if(io.contentDocument)
  139. {
  140. xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
  141. xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
  142. }
  143. }catch(e)
  144. {
  145. $.yihu.handleError(s, xml, null, e);
  146. }
  147. if ( xml || isTimeout == "timeout")
  148. {
  149. requestDone = true;
  150. var status;
  151. try {
  152. status = isTimeout != "timeout" ? "success" : "error";
  153. // Make sure that the request was successful or notmodified
  154. if ( status != "error" )
  155. {
  156. // process the data (runs the xml through httpData regardless of callback)
  157. var data = $.yihu.uploadHttpData( xml, s.dataType );
  158. // If a local callback was specified, fire it and pass it the data
  159. if ( s.success )
  160. s.success( data, status );
  161. // Fire the global callback
  162. if( s.global )
  163. jQuery.event.trigger( "ajaxSuccess", [xml, s] );
  164. } else
  165. $.yihu.handleError(s, xml, status);
  166. } catch(e)
  167. {
  168. status = "error";
  169. $.yihu.handleError(s, xml, status, e);
  170. }
  171. // The request was completed
  172. if( s.global )
  173. jQuery.event.trigger( "ajaxComplete", [xml, s] );
  174. // Handle the global AJAX counter
  175. if ( s.global && ! --jQuery.active )
  176. jQuery.event.trigger( "ajaxStop" );
  177. // Process result
  178. if ( s.complete )
  179. s.complete(xml, status);
  180. jQuery(io).unbind()
  181. setTimeout(function()
  182. { try
  183. {
  184. jQuery(io).remove();
  185. jQuery(form).remove();
  186. } catch(e)
  187. {
  188. $.yihu.handleError(s, xml, null, e);
  189. }
  190. }, 100)
  191. xml = null
  192. }
  193. }
  194. // Timeout checker
  195. if ( s.timeout > 0 )
  196. {
  197. setTimeout(function(){
  198. // Check to see if the request is still happening
  199. if( !requestDone ) uploadCallback( "timeout" );
  200. }, s.timeout);
  201. }
  202. try
  203. {
  204. var form = jQuery('#' + formId);
  205. jQuery(form).attr('action', s.url);
  206. jQuery(form).attr('method', 'POST');
  207. jQuery(form).attr('target', frameId);
  208. if(form.encoding)
  209. {
  210. jQuery(form).attr('encoding', 'multipart/form-data');
  211. }
  212. else
  213. {
  214. jQuery(form).attr('enctype', 'multipart/form-data');
  215. }
  216. jQuery(form).submit();
  217. } catch(e)
  218. {
  219. $.yihu.handleError(s, xml, null, e);
  220. }
  221. $('#' + frameId).load(uploadCallback );
  222. return {abort: function () {}};
  223. },
  224. uploadHttpData: function( r, type ) {
  225. var data = !type;
  226. data = type == "xml" || data ? r.responseXML : r.responseText;
  227. // If the type is "script", eval it in global context
  228. if ( type == "script" )
  229. jQuery.globalEval( data );
  230. // Get the JavaScript object, if JSON is used.
  231. if ( type == "json" )
  232. eval( "data = " + data );
  233. // evaluate scripts within html
  234. if ( type == "html" )
  235. jQuery("<div>").html(data).evalScripts();
  236. return data;
  237. },
  238. post:function(bizAction,param,successFn)
  239. {
  240. param.bizAction=bizAction;
  241. $.ajax({
  242. url :this.url,
  243. data:param,
  244. type : "POST",
  245. dataType : 'json',
  246. success : successFn
  247. });
  248. },
  249. loadStore:function(businTypeID)
  250. {
  251. var res = new Object;
  252. $.ajax({
  253. url : this.url,
  254. data:{
  255. businTypeID: businTypeID, bizAction:'dictAction.getDict'
  256. },
  257. cache : false,
  258. async : false,
  259. type : "POST",
  260. dataType : 'json',
  261. success : function (data){
  262. var result = data.result;
  263. for ( var iterable_element in result) {
  264. res[result[iterable_element].businID] = result[iterable_element].businName;
  265. }
  266. }
  267. });
  268. return res;
  269. },
  270. loadDictSelect:function(id,businTypeID,defaultValue)
  271. {
  272. var param = {};
  273. param.bizAction = "dictAction.getDict";
  274. param.businTypeID = businTypeID;
  275. param.emptyText = '--请选择--';
  276. $.post(this.url,param
  277. ,function(result){
  278. $('#'+id).combobox('loadData',result.result);
  279. if(defaultValue != null && defaultValue != ''){
  280. $('#'+id).combobox('setValue',defaultValue);
  281. }
  282. },"json");
  283. },
  284. loadDictSelectInIDS:function(ids,businTypeID,defaultValue)
  285. {
  286. var param = {};
  287. param.bizAction = "dictAction.getDict";
  288. param.businTypeID = businTypeID;
  289. param.emptyText = '--请选择--';
  290. $.post(this.url,param
  291. ,function(result){
  292. for(var i=0;i<ids.length;i++){
  293. $('#'+ids[i]).combobox('loadData',result.result);
  294. }
  295. },"json");
  296. },
  297. getDictText:function(businTypeID,businID)
  298. {
  299. var businName="";
  300. $.ajax({
  301. url : this.url,
  302. data:{
  303. businTypeID: businTypeID, businID: businID ,bizAction:'dictAction.getDictText'
  304. },
  305. cache : false,
  306. async : false,
  307. type : "POST",
  308. dataType : 'json',
  309. success : function (data){
  310. businName=data.businName;
  311. }
  312. });
  313. return businName;
  314. },
  315. formatNull:function(value) {
  316. if (value == null || typeof(value) == "undefined") {
  317. return "";
  318. }
  319. return value;
  320. },
  321. open:function( strUrl,winWidth,winHeight,winLeft,winTop,id){
  322. var win_id='win_'+parseInt(Math.random()*10000);
  323. if(typeof(id)!="undefined")
  324. {
  325. win_id=id;
  326. }
  327. var newwin=window.open( strUrl,
  328. win_id,
  329. "width="+ winWidth + ","
  330. + "height="+winHeight + ","
  331. + "left="+winLeft+","
  332. + "top="+winTop+","
  333. + "status=yes,toolbar=no,menubar=no,location=yes,scrollbars=yes");
  334. newwin.focus();
  335. },
  336. QueryString:function(val) {
  337. var uri = window.location.search;
  338. var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
  339. return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
  340. },
  341. //取医院信息
  342. getHosInfo:function(ghthosid)
  343. {
  344. var res;
  345. $.ajax({
  346. url : this.url,
  347. data:{
  348. ghthospitalid: ghthosid,bizAction:'ght_JSQueryAction.getGhtHospitalInfo'
  349. },
  350. cache : false,
  351. async : false,
  352. type : "POST",
  353. dataType : 'json',
  354. success : function (data){
  355. res = data;
  356. }
  357. });
  358. return res;
  359. },
  360. //取社区信息
  361. getOrgInfo:function(orgid){
  362. var res;
  363. $.ajax({
  364. url : this.url,
  365. data:{
  366. orgid: orgid,bizAction:'ClinicInfoAction.getClinicInfoByOrgId'
  367. },
  368. cache : false,
  369. async : false,
  370. type : "POST",
  371. dataType : 'json',
  372. success : function (data){
  373. res = data;
  374. }
  375. });
  376. return res;
  377. },
  378. loadDict:function(businTypeID,emptyText)
  379. {
  380. var res;
  381. $.ajax({
  382. url : this.url,
  383. data:{
  384. businTypeID: businTypeID, emptyText: emptyText ,bizAction:'dictAction.getDict'
  385. },
  386. cache : false,
  387. async : false,
  388. type : "POST",
  389. dataType : 'json',
  390. success : function (data){
  391. res = data;
  392. }
  393. });
  394. return res;
  395. },
  396. loadDictNoLogin:function(businTypeID)
  397. {
  398. var res;
  399. $.ajax({
  400. url : this.url,
  401. data:{
  402. businTypeID: businTypeID, isLogin: '1' ,bizAction:'dictAction.getDict'
  403. },
  404. cache : false,
  405. async : false,
  406. type : "POST",
  407. dataType : 'json',
  408. success : function (data){
  409. res = data;
  410. }
  411. });
  412. return res;
  413. },
  414. loadSelect : function(id, param, defaultValue) {
  415. $.post(this.url, param, function(result) {
  416. $('#' + id).combobox('loadData', result.result);
  417. if (defaultValue != null && defaultValue != '') {
  418. $('#' + id).combobox('setValue', defaultValue);
  419. }
  420. }, "json");
  421. },
  422. getDictText:function(businTypeID,businID)
  423. {
  424. var businName="";
  425. $.ajax({
  426. url : this.url,
  427. data:{
  428. businTypeID: businTypeID, businID: businID ,bizAction:'dictAction.getDictText'
  429. },
  430. cache : false,
  431. async : false,
  432. type : "POST",
  433. dataType : 'json',
  434. success : function (data){
  435. businName=data.businName;
  436. }
  437. });
  438. return businName;
  439. },
  440. getSession:function()
  441. {
  442. var ret;
  443. $.ajax({
  444. url : this.url,
  445. data:{
  446. bizAction:'loginAction.writeSessionJSON'
  447. },
  448. cache : false,
  449. async : false,
  450. type : "POST",
  451. dataType : 'json',
  452. success : function (data){
  453. ret=data;
  454. }
  455. });
  456. return ret;
  457. },
  458. loadHosDeptTypeID:function()
  459. {
  460. var typeids = this.loadDict("B_HosDept.typeId").result;
  461. var typeid_combobox = '{"result":[';
  462. for(var i = 0;i<typeids.length;i++){
  463. var id = typeids[i].businID;
  464. var text = typeids[i].businName;
  465. if(text=='--请选择--'){
  466. typeid_combobox += '{"businName":"'+text+'","selected":true,"businID":""}';
  467. }else if(id != '4'){
  468. typeid_combobox += ',{"businName":"'+text+'","businID":"'+id+'"}';
  469. }
  470. }
  471. typeid_combobox += ']}';
  472. return eval("("+typeid_combobox+")");
  473. },
  474. alert:function(msg){
  475. $.messager.alert('提示','<font color=red>'+msg+'</font>','error');
  476. },
  477. showMsg : function(msg){
  478. $.messager.show({
  479. title:'提示',
  480. msg:'<font color=red>'+msg+'</font>',
  481. showType:'show'
  482. });
  483. },
  484. jsonObjectToString : function(o) {
  485. if (o == null)
  486. return "null";
  487. switch (o.constructor) {
  488. case String:
  489. var s = o; // .encodeURI();
  490. if (s.indexOf("}") < 0)
  491. s = '"' + s.replace(/(["\\])/g, '\\$1') + '"';
  492. s = s.replace(/\n/g, "\\n");
  493. s = s.replace(/\r/g, "\\r");
  494. return s;
  495. case Array:
  496. var v = [];
  497. for ( var i = 0; i < o.length; i++)
  498. v.push(jsonObjectToString(o[i]));
  499. if (v.length <= 0)
  500. return "\"\"";
  501. //return "" + v.join(",") + "";
  502. return "[" + v.join(",") + "]";
  503. case Number:
  504. return isFinite(o) ? o.toString() : this.jsonObjectToString(null);
  505. case Boolean:
  506. return o.toString();
  507. case Date:
  508. var d = new Object();
  509. d.__type = "System.DateTime";
  510. d.Year = o.getUTCFullYear();
  511. d.Month = o.getUTCMonth() + 1;
  512. d.Day = o.getUTCDate();
  513. d.Hour = o.getUTCHours();
  514. d.Minute = o.getUTCMinutes();
  515. d.Second = o.getUTCSeconds();
  516. d.Millisecond = o.getUTCMilliseconds();
  517. d.TimezoneOffset = o.getTimezoneOffset();
  518. return this.jsonObjectToString(d);
  519. default:
  520. if (o["toJSON"] != null && typeof o["toJSON"] == "function")
  521. return o.toJSON();
  522. if (typeof o == "object") {
  523. var v = [];
  524. for (attr in o) {
  525. if (typeof o[attr] != "function"){
  526. var attrValue = this.jsonObjectToString(o[attr]);
  527. if(attrValue.length>0 && attrValue!=null){
  528. v.push('"' + attr + '": ' + attrValue);
  529. }
  530. }
  531. }
  532. if (v.length > 0)
  533. return "{" + v.join(",") + "}";
  534. else
  535. return "{}";
  536. }
  537. alert(o.toString());
  538. return o.toString();
  539. }
  540. }
  541. };