common.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. var issOnlineUrl = "http://127.0.0.1:24010/ZKIDROnline";
  2. var browserFlag = getBrowserType();
  3. /*
  4. $().ready(function(){
  5. $(document).off("DOMNodeInserted","#cert_message_type");
  6. $("#cert_message_type").on("DOMNodeInserted",function(e){
  7. openMessage($("#cert_message_type").text(), $("#cert_message").text());
  8. });
  9. });
  10. */
  11. //身份证
  12. //includeScript("baseISSObject.js", function(){
  13. //includeScript("baseISSOnline.js", function(){
  14. var setting = {
  15. Cert: {
  16. callBack: function (result) {
  17. setCertificateData(result);
  18. },
  19. select: "#button_readID"
  20. },
  21. Methods: {
  22. showMessage: function (type, message) {
  23. $("#cert_message").text(message);
  24. $("#cert_message_type").text(msgType[type]);
  25. },
  26. downloadDrive: function () {
  27. $.jBox.closeTip();
  28. messageBox({
  29. messageType: "confirm", text: "请安装相关硬件驱动!点击确定下载驱动。",
  30. callback: function (result) {
  31. if (result) {
  32. window.location.href = "middleware/ZKIDROnline.exe";
  33. }
  34. closeMessage();
  35. }
  36. });
  37. }
  38. }
  39. }
  40. createISSonlineDevice(setting);
  41. //});
  42. //});
  43. function setCertificateData(result) {
  44. //$("#birthDay").val(result.Certificate.Birthday.replace(/\./g,"-").substr(0,10));
  45. var birthday = result.Certificate.Birthday;
  46. $("#birthDay").val(birthday.substring(0, 4) + "-" + birthday.substring(4, 6) + "-" + birthday.substring(6));
  47. var returnAge = jsGetAge($("#birthDay").val());
  48. $("#age").val(returnAge);
  49. $("#idCard").val(result.Certificate.IDNumber);
  50. queryUserInfoBySocialNo();
  51. //$("#issuedValidDate").val(result.Certificate.IssuedData+"-"+result.Certificate.ValidDate);
  52. // imgData =result.Certificate.Base64Photo;
  53. // $("#id_img_pers").attr("src","data:image/jpg;base64,"+imgData);
  54. // $("#personIdPhoto").val(imgData);
  55. // $("#personPhoto").val("");
  56. $("#userName").val(result.Certificate.Name);
  57. if (result.Certificate.Sex == "男") {
  58. $("#gender").val(1);
  59. $('#gender').selectpicker('refresh');
  60. } else if (result.Certificate.Sex == "女") {
  61. $("#gender").val(2);
  62. $('#gender').selectpicker('refresh');
  63. }
  64. //$("#nation").val(result.Certificate.Nation);
  65. $("#address").val(result.Certificate.Address);
  66. //$("#idAddress").val(result.Certificate.Address);
  67. $("#copyAddress").attr("data-clipboard-text",result.Certificate.Address);
  68. $("#copyAddress").show();
  69. try {
  70. $("#imageIdCard").val(result.Certificate.Base64Photo);
  71. setNation(result.Certificate.Nation);
  72. $("#nationToUpload").val(result.Certificate.Nation);
  73. $("#idIssued").val(result.Certificate.IDIssued);
  74. $("#issuedData").val(result.Certificate.IssuedData);
  75. $("#validDate").val(result.Certificate.ValidDate);
  76. } catch (e) {
  77. }
  78. }
  79. /**
  80. * 设置民族
  81. */
  82. function setNation(nation) {
  83. var nationKey = null;
  84. if (nation == "阿昌") {
  85. nationKey = "AC";
  86. } else if (nation == "白") {
  87. nationKey = "BA";
  88. } else if (nation == "崩龙") {
  89. nationKey = "BE";
  90. } else if (nation == "布朗") {
  91. nationKey = "BL";
  92. } else if (nation == "保安") {
  93. nationKey = "BN";
  94. } else if (nation == "布依") {
  95. nationKey = "BY";
  96. } else if (nation == "穿青人") {
  97. nationKey = "CQ";
  98. } else if (nation == "朝鲜") {
  99. nationKey = "CX";
  100. } else if (nation == "傣") {
  101. nationKey = "DA";
  102. } else if (nation == "侗") {
  103. nationKey = "DO";
  104. } else if (nation == "独龙") {
  105. nationKey = "DR";
  106. } else if (nation == "达斡尔") {
  107. nationKey = "DU";
  108. } else if (nation == "东乡") {
  109. nationKey = "DX";
  110. } else if (nation == "鄂温克") {
  111. nationKey = "EW";
  112. } else if (nation == "京") {
  113. nationKey = "GI";
  114. } else if (nation == "仡佬") {
  115. nationKey = "GL";
  116. } else if (nation == "高山") {
  117. nationKey = "GS";
  118. } else if (nation == "汉") {
  119. nationKey = "HA";
  120. } else if (nation == "哈尼") {
  121. nationKey = "HN";
  122. } else if (nation == "回") {
  123. nationKey = "HU";
  124. } else if (nation == "赫哲") {
  125. nationKey = "HZ";
  126. } else if (nation == "基诺") {
  127. nationKey = "JN";
  128. } else if (nation == "景颇") {
  129. nationKey = "JP";
  130. } else if (nation == "柯尔克孜") {
  131. nationKey = "KG";
  132. } else if (nation == "哈萨克") {
  133. nationKey = "KZ";
  134. } else if (nation == "珞巴") {
  135. nationKey = "LB";
  136. } else if (nation == "拉祜") {
  137. nationKey = "LH";
  138. } else if (nation == "黎") {
  139. nationKey = "LI";
  140. } else if (nation == "傈僳") {
  141. nationKey = "LS";
  142. } else if (nation == "满") {
  143. nationKey = "MA";
  144. } else if (nation == "门巴") {
  145. nationKey = "MB";
  146. } else if (nation == "蒙古") {
  147. nationKey = "MG";
  148. } else if (nation == "苗") {
  149. nationKey = "MI";
  150. } else if (nation == "仫佬") {
  151. nationKey = "ML";
  152. } else if (nation == "毛难") {
  153. nationKey = "MN";
  154. } else if (nation == "怒族") {
  155. nationKey = "NU";
  156. } else if (nation == "纳西") {
  157. nationKey = "NX";
  158. } else if (nation == "鄂伦春") {
  159. nationKey = "OR";
  160. } else if (nation == "普米族") {
  161. nationKey = "PM";
  162. } else if (nation == "羌") {
  163. nationKey = "QI";
  164. } else if (nation == "其他") {
  165. nationKey = "QT";
  166. } else if (nation == "俄罗斯") {
  167. nationKey = "RS";
  168. } else if (nation == "畲") {
  169. nationKey = "SH";
  170. } else if (nation == "撒拉") {
  171. nationKey = "SL";
  172. } else if (nation == "水") {
  173. nationKey = "SU";
  174. } else if (nation == "塔吉克") {
  175. nationKey = "TA";
  176. } else if (nation == "土家") {
  177. nationKey = "TJ";
  178. } else if (nation == "塔塔尔") {
  179. nationKey = "TT";
  180. } else if (nation == "土") {
  181. nationKey = "TU";
  182. } else if (nation == "维吾尔") {
  183. nationKey = "UG";
  184. } else if (nation == "乌孜别克") {
  185. nationKey = "UZ";
  186. } else if (nation == "佤") {
  187. nationKey = "VA";
  188. } else if (nation == "外国血统") {
  189. nationKey = "WG";
  190. } else if (nation == "锡伯") {
  191. nationKey = "XB";
  192. } else if (nation == "瑶") {
  193. nationKey = "YA";
  194. } else if (nation == "裕固") {
  195. nationKey = "YG";
  196. } else if (nation == "彝") {
  197. nationKey = "YI";
  198. } else if (nation == "藏") {
  199. nationKey = "ZA";
  200. } else if (nation == "壮") {
  201. nationKey = "ZH";
  202. }
  203. $('#nation').selectpicker('val', nationKey);
  204. $('#nation').selectpicker('refresh');
  205. }
  206. function getRandomNum() {
  207. var random = parseInt(Math.random() * 10000);
  208. return random;
  209. }
  210. //消息控件的使用类型的类
  211. var msgType =
  212. {
  213. info: "info",
  214. success: "success",
  215. warning: "warning",
  216. error: "error",
  217. loading: "loading"
  218. };
  219. function getBrowserType() {
  220. var browserFlag = "";
  221. //是否支持html5的cors跨域
  222. if (typeof(Worker) !== "undefined") {
  223. browserFlag = "html5";
  224. }
  225. //此处判断ie8、ie9
  226. else if (navigator.userAgent.indexOf("MSIE 7.0") > 0 || navigator.userAgent.indexOf("MSIE 8.0") > 0 || navigator.userAgent.indexOf("MSIE 9.0") > 0) {
  227. browserFlag = "simple";
  228. }
  229. else {
  230. browserFlag = "upgradeBrowser";//当前浏览器不支持该功能,请升级浏览器
  231. }
  232. return browserFlag;
  233. }
  234. function openMessage(type, text, ptimeout) {
  235. text = (text == "" ? null : text);
  236. var timeout = 1000;
  237. if (type == msgType.warning || type == msgType.info)//警告
  238. {
  239. timeout = 3000;
  240. }
  241. else if (type == msgType.success)//成功
  242. {
  243. text = (text && text != null ? text : "操作成功");//${common_op_succeed}:操作成功
  244. var num = strlen(text) / 30;
  245. num = num > 8 ? 8 : num;
  246. timeout = Math.ceil(num) * timeout;//动态判断显示字符数的长度来延长显示时间
  247. }
  248. else if (type == msgType.error)//失败
  249. {
  250. text = (text && text != null) ? text : "操作失败";//${common_op_failed}:操作失败,程序出现异常
  251. timeout = 3000;
  252. }
  253. else if (type == msgType.loading)//处理中
  254. {
  255. timeout = 0;//当为'loading'时,timeout值会被设置为0,表示不会自动关闭。
  256. text = text && text != null ? text : "处理中";//${common_op_processing}:处理中
  257. }
  258. var width = strlen(text) * 6.1 + 45;//按字符计算宽度
  259. timeout = ptimeout ? ptimeout : timeout;
  260. $.jBox.tip(text, type, {timeout: timeout, width: (width > 400 ? 400 : "auto")});//设定最大宽度为400
  261. }
  262. function closeMessage(timeout) {
  263. timeout = timeout ? timeout : 1000;
  264. window.setTimeout("$.jBox.closeTip();", timeout);//设定最小等待时间
  265. }
  266. function strlen(str) {
  267. var len = 0;
  268. if (str != null) {
  269. for (var i = 0; i < str.length; i++) {
  270. var c = str.charCodeAt(i);
  271. if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
  272. len++;
  273. }
  274. else {
  275. len += 2;
  276. }
  277. }
  278. }
  279. return len;
  280. }
  281. function messageBox(paramsJson) {
  282. this.messageType = paramsJson.messageType ? $.trim(paramsJson.messageType) : "confirm";
  283. this.types = "";
  284. if (paramsJson.type) {
  285. this.typeArray = paramsJson.type.split(" ");
  286. for (var i = 0; i < this.typeArray.length; i++) {
  287. this.types += this.typeArray[i] + " ";
  288. }
  289. }
  290. switch (this.messageType) {
  291. case "confirm":
  292. $.jBox.confirm(paramsJson.text, "提示", function (v, h, f) {
  293. if (v == "ok") {
  294. paramsJson.callback(true);
  295. }
  296. });
  297. break;
  298. }
  299. }
  300. /**
  301. * 根据出生日期算出年龄
  302. * @param strBirthday
  303. * @returns {number}
  304. */
  305. function jsGetAge(strBirthday) {
  306. var returnAge;
  307. var strBirthdayArr = strBirthday.split("-");
  308. var birthYear = strBirthdayArr[0];
  309. var birthMonth = strBirthdayArr[1];
  310. var birthDay = strBirthdayArr[2];
  311. d = new Date();
  312. var nowYear = d.getFullYear();
  313. var nowMonth = d.getMonth() + 1;
  314. var nowDay = d.getDate();
  315. if (nowYear == birthYear) {
  316. returnAge = 0;//同年 则为0岁
  317. }
  318. else {
  319. var ageDiff = nowYear - birthYear; //年之差
  320. if (ageDiff > 0) {
  321. if (nowMonth == birthMonth) {
  322. var dayDiff = nowDay - birthDay;//日之差
  323. if (dayDiff < 0) {
  324. returnAge = ageDiff - 1;
  325. }
  326. else {
  327. returnAge = ageDiff;
  328. }
  329. }
  330. else {
  331. var monthDiff = nowMonth - birthMonth;//月之差
  332. if (monthDiff < 0) {
  333. returnAge = ageDiff - 1;
  334. }
  335. else {
  336. returnAge = ageDiff;
  337. }
  338. }
  339. }
  340. else {
  341. returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
  342. }
  343. }
  344. return returnAge;//返回周岁年龄
  345. }
  346. /**
  347. * 身份证号有变化后查询病人信息
  348. */
  349. function queryUserInfoBySocialNo() {
  350. var idCard = $("#idCard").val();
  351. if (idCard.length == 18) {
  352. $.ajax({
  353. type: "GET",
  354. url: '/thmz/getBySocialNo?socialNo=' + idCard,
  355. contentType: "application/json;charset=UTF-8",
  356. dataType: "json",
  357. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  358. success: function (res) {
  359. if (res == '401' || res == 401) {
  360. window.location.href = '/thmz/login/view'
  361. return;
  362. }
  363. if (res.code == 0) {
  364. if (res.data != null && res.data.length > 0) {
  365. //如果只有一条数据的时候,直接加载当前病人信息
  366. if(res.data.length==1){
  367. fillPatinet(res.data[0].patientId);
  368. }else {
  369. fitPatient(res);
  370. }
  371. } else {
  372. var birthday = idCard.substring(6, 14);
  373. birthday = birthday.substring(0, 4) + "-" + birthday.substring(4, 6) + "-" + birthday.substring(6);
  374. $("#birthDay").val(birthday);
  375. var returnAge = jsGetAge(birthday);
  376. $("#age").val(returnAge);
  377. var gender = idCard.substring(16, 17);
  378. if (gender % 2 == 0) {
  379. $("#gender").val(2);
  380. } else {
  381. $("#gender").val(1);
  382. }
  383. $('#gender').selectpicker('refresh');
  384. }
  385. } else {
  386. errorMesage(res);
  387. }
  388. }
  389. });
  390. }
  391. }
  392. /**
  393. * 查询患者信息
  394. */
  395. function fitPatient(res) {
  396. if (res.data.length > 0) {
  397. $("#patientModal").modal();
  398. $("#patientTable").html(null);
  399. for (var i = 0; i < res.data.length; i++) {
  400. var gender = '未知';
  401. if (res.data[i].sex == 1) {
  402. gender = '男';
  403. } else if (res.data[i].sex == 2) {
  404. gender = '女';
  405. }
  406. var icCardNo = res.data[i].icCardNo;
  407. if (icCardNo == null || icCardNo == "null") {
  408. icCardNo = "";
  409. }
  410. var phoneNo = res.data[i].phoneNo;
  411. if (phoneNo == null || phoneNo == "null") {
  412. phoneNo = "";
  413. }
  414. var birthDay = format(res.data[i].birthDay, "yyyy-MM-dd");
  415. if (birthDay == null || birthDay == "null") {
  416. birthDay = "";
  417. }
  418. var socialNo = res.data[i].socialNo;
  419. if (socialNo == null || socialNo == "null") {
  420. socialNo = "";
  421. }
  422. $("<tr data-target='" + res.data[i].patientId + "'><td>" + res.data[i].patientId + "</td><td>" + res.data[i].name + "</td><td>" + gender + "</td><td>" + icCardNo + "</td><td>" + phoneNo + "</td><td>" + birthDay + "</td><td>" + socialNo + "</td></tr>").appendTo("#patientTable").bind('click', function () {
  423. $("#patientModal").modal("hide");
  424. fillPatinet($(this).attr("data-target"));
  425. });
  426. }
  427. }
  428. }