comm.js 16 KB

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