common.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. //@ sourceURL=common.js
  2. var issOnlineUrl = "http://127.0.0.1:24010/ZKIDROnline";
  3. var browserFlag = getBrowserType();
  4. /*
  5. $().ready(function(){
  6. $(document).off("DOMNodeInserted","#cert_message_type");
  7. $("#cert_message_type").on("DOMNodeInserted",function(e){
  8. openMessage($("#cert_message_type").text(), $("#cert_message").text());
  9. });
  10. });
  11. */
  12. //身份证
  13. //includeScript("baseISSObject.js", function(){
  14. //includeScript("baseISSOnline.js", function(){
  15. // var setting = {
  16. // Cert: {
  17. // callBack: function (result) {
  18. // setCertificateData(result);
  19. // },
  20. // select: "#button_readID"
  21. // },
  22. // Methods: {
  23. // showMessage: function (type, message) {
  24. // $("#cert_message").text(message);
  25. // $("#cert_message_type").text(msgType[type]);
  26. // },
  27. // downloadDrive: function () {
  28. // $.jBox.closeTip();
  29. // messageBox({
  30. // messageType: "confirm", text: "请安装相关硬件驱动!点击确定下载驱动。",
  31. // callback: function (result) {
  32. // if (result) {
  33. // window.location.href = "middleware/ZKIDROnline.exe";
  34. // }
  35. // closeMessage();
  36. // }
  37. // });
  38. // }
  39. // }
  40. // }
  41. // try {
  42. // createISSonlineDevice(setting);
  43. // } catch (e) {
  44. // console.info("不要用读取身份证");
  45. // }
  46. /**
  47. * 身份证读卡
  48. * @param params
  49. */
  50. function siReadIdCard(params) {
  51. $.ajax({
  52. type: "GET",
  53. url: 'http://localhost:8321/readcard/entry?param='+params,
  54. contentType: "application/json;charset=UTF-8",
  55. dataType: "json",
  56. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  57. success: function (res) {
  58. if (res == '401' || res == 401) {
  59. window.location.href = '/thmz/login/view'
  60. return;
  61. }
  62. if (res.code == 200) {
  63. var str = res.data.split("^")
  64. var str1= str.filter(item=>item !='')
  65. var Certificate = {
  66. Birthday:str1[4],
  67. IDNumber:str1[0],
  68. Name:str1[1],
  69. Address:str1[5],
  70. Base64Photo:str1[8],
  71. Nation:str1[3],
  72. IDIssued:str1[6],
  73. IssuedData:str1[7].substring(0,8),
  74. ValidDate:str1[7].substring(8),
  75. Sex:str1[2]
  76. }
  77. var resultData = {Certificate:Certificate}
  78. console.log('resultData',resultData);
  79. setCertificateData(resultData)
  80. } else {
  81. errorMesage(res);
  82. }
  83. }
  84. });
  85. // window.open('ReadCard://'+prm, '_self')
  86. }
  87. function setCertificateData(result) {
  88. //$("#birthDay").val(result.Certificate.Birthday.replace(/\./g,"-").substr(0,10));
  89. var birthday = result.Certificate.Birthday;
  90. $("#birthDay").val(birthday.substring(0, 4) + "-" + birthday.substring(4, 6) + "-" + birthday.substring(6));
  91. var returnAge = jsGetAge($("#birthDay").val());
  92. $("#age").val(returnAge);
  93. $("#idCard").val(result.Certificate.IDNumber);
  94. queryUserInfoBySocialNo();
  95. //$("#issuedValidDate").val(result.Certificate.IssuedData+"-"+result.Certificate.ValidDate);
  96. // imgData =result.Certificate.Base64Photo;
  97. // $("#id_img_pers").attr("src","data:image/jpg;base64,"+imgData);
  98. // $("#personIdPhoto").val(imgData);
  99. // $("#personPhoto").val("");
  100. $("#userName").val(result.Certificate.Name);
  101. if (result.Certificate.Sex == "男") {
  102. $("#gender").val(1);
  103. $('#gender').selectpicker('refresh');
  104. } else if (result.Certificate.Sex == "女") {
  105. $("#gender").val(2);
  106. $('#gender').selectpicker('refresh');
  107. }
  108. //$("#nation").val(result.Certificate.Nation);
  109. //$("#address").val(result.Certificate.Address);
  110. //$("#idAddress").val(result.Certificate.Address);
  111. $("#copyAddress").attr("data-clipboard-text", result.Certificate.Address);
  112. $("#copyAddress").show();
  113. try {
  114. $("#imageIdCard").val(result.Certificate.Base64Photo);
  115. setNation(result.Certificate.Nation);
  116. $("#nationToUpload").val(result.Certificate.Nation);
  117. //机关单位
  118. $("#idIssued").val(result.Certificate.IDIssued);
  119. //有效期 开始时间
  120. $("#issuedData").val(result.Certificate.IssuedData);
  121. //有效期结束时间
  122. $("#validDate").val(result.Certificate.ValidDate);
  123. } catch (e) {
  124. }
  125. $.ajax({
  126. type: "GET",
  127. url: '/thmz/getFullRegionFromIdCard?address=' + result.Certificate.Address,
  128. contentType: "application/json;charset=UTF-8",
  129. dataType: "json",
  130. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  131. success: function (res) {
  132. if (res == '401' || res == 401) {
  133. window.location.href = '/thmz/login/view'
  134. return;
  135. }
  136. if (res.code == 0) {
  137. $('#provinceCode').selectpicker('val', res.provinceCode);
  138. $('#provinceCode').selectpicker('refresh');
  139. initCity(1, res.cityCode);
  140. initDistrict(1, res.cityCode, res.districtCode);
  141. $("#detail").val(res.detail);
  142. } else {
  143. errorMesage(res);
  144. }
  145. }
  146. });
  147. }
  148. /**
  149. * 设置民族
  150. */
  151. function setNation(nation) {
  152. var nationKey = null;
  153. if (nation == "阿昌") {
  154. nationKey = "AC";
  155. } else if (nation == "白") {
  156. nationKey = "BA";
  157. } else if (nation == "崩龙") {
  158. nationKey = "BE";
  159. } else if (nation == "布朗") {
  160. nationKey = "BL";
  161. } else if (nation == "保安") {
  162. nationKey = "BN";
  163. } else if (nation == "布依") {
  164. nationKey = "BY";
  165. } else if (nation == "穿青人") {
  166. nationKey = "CQ";
  167. } else if (nation == "朝鲜") {
  168. nationKey = "CX";
  169. } else if (nation == "傣") {
  170. nationKey = "DA";
  171. } else if (nation == "侗") {
  172. nationKey = "DO";
  173. } else if (nation == "独龙") {
  174. nationKey = "DR";
  175. } else if (nation == "达斡尔") {
  176. nationKey = "DU";
  177. } else if (nation == "东乡") {
  178. nationKey = "DX";
  179. } else if (nation == "鄂温克") {
  180. nationKey = "EW";
  181. } else if (nation == "京") {
  182. nationKey = "GI";
  183. } else if (nation == "仡佬") {
  184. nationKey = "GL";
  185. } else if (nation == "高山") {
  186. nationKey = "GS";
  187. } else if (nation == "汉") {
  188. nationKey = "HA";
  189. } else if (nation == "哈尼") {
  190. nationKey = "HN";
  191. } else if (nation == "回") {
  192. nationKey = "HU";
  193. } else if (nation == "赫哲") {
  194. nationKey = "HZ";
  195. } else if (nation == "基诺") {
  196. nationKey = "JN";
  197. } else if (nation == "景颇") {
  198. nationKey = "JP";
  199. } else if (nation == "柯尔克孜") {
  200. nationKey = "KG";
  201. } else if (nation == "哈萨克") {
  202. nationKey = "KZ";
  203. } else if (nation == "珞巴") {
  204. nationKey = "LB";
  205. } else if (nation == "拉祜") {
  206. nationKey = "LH";
  207. } else if (nation == "黎") {
  208. nationKey = "LI";
  209. } else if (nation == "傈僳") {
  210. nationKey = "LS";
  211. } else if (nation == "满") {
  212. nationKey = "MA";
  213. } else if (nation == "门巴") {
  214. nationKey = "MB";
  215. } else if (nation == "蒙古") {
  216. nationKey = "MG";
  217. } else if (nation == "苗") {
  218. nationKey = "MI";
  219. } else if (nation == "仫佬") {
  220. nationKey = "ML";
  221. } else if (nation == "毛难") {
  222. nationKey = "MN";
  223. } else if (nation == "怒族") {
  224. nationKey = "NU";
  225. } else if (nation == "纳西") {
  226. nationKey = "NX";
  227. } else if (nation == "鄂伦春") {
  228. nationKey = "OR";
  229. } else if (nation == "普米族") {
  230. nationKey = "PM";
  231. } else if (nation == "羌") {
  232. nationKey = "QI";
  233. } else if (nation == "其他") {
  234. nationKey = "QT";
  235. } else if (nation == "俄罗斯") {
  236. nationKey = "RS";
  237. } else if (nation == "畲") {
  238. nationKey = "SH";
  239. } else if (nation == "撒拉") {
  240. nationKey = "SL";
  241. } else if (nation == "水") {
  242. nationKey = "SU";
  243. } else if (nation == "塔吉克") {
  244. nationKey = "TA";
  245. } else if (nation == "土家") {
  246. nationKey = "TJ";
  247. } else if (nation == "塔塔尔") {
  248. nationKey = "TT";
  249. } else if (nation == "土") {
  250. nationKey = "TU";
  251. } else if (nation == "维吾尔") {
  252. nationKey = "UG";
  253. } else if (nation == "乌孜别克") {
  254. nationKey = "UZ";
  255. } else if (nation == "佤") {
  256. nationKey = "VA";
  257. } else if (nation == "外国血统") {
  258. nationKey = "WG";
  259. } else if (nation == "锡伯") {
  260. nationKey = "XB";
  261. } else if (nation == "瑶") {
  262. nationKey = "YA";
  263. } else if (nation == "裕固") {
  264. nationKey = "YG";
  265. } else if (nation == "彝") {
  266. nationKey = "YI";
  267. } else if (nation == "藏") {
  268. nationKey = "ZA";
  269. } else if (nation == "壮") {
  270. nationKey = "ZH";
  271. }
  272. $('#nation').selectpicker('val', nationKey);
  273. $('#nation').selectpicker('refresh');
  274. }
  275. function getRandomNum() {
  276. var random = parseInt(Math.random() * 10000);
  277. return random;
  278. }
  279. //消息控件的使用类型的类
  280. var msgType =
  281. {
  282. info: "info",
  283. success: "success",
  284. warning: "warning",
  285. error: "error",
  286. loading: "loading"
  287. };
  288. function getBrowserType() {
  289. var browserFlag = "";
  290. //是否支持html5的cors跨域
  291. if (typeof(Worker) !== "undefined") {
  292. browserFlag = "html5";
  293. }
  294. //此处判断ie8、ie9
  295. else if (navigator.userAgent.indexOf("MSIE 7.0") > 0 || navigator.userAgent.indexOf("MSIE 8.0") > 0 || navigator.userAgent.indexOf("MSIE 9.0") > 0) {
  296. browserFlag = "simple";
  297. }
  298. else {
  299. browserFlag = "upgradeBrowser";//当前浏览器不支持该功能,请升级浏览器
  300. }
  301. return browserFlag;
  302. }
  303. function openMessage(type, text, ptimeout) {
  304. text = (text == "" ? null : text);
  305. var timeout = 1000;
  306. if (type == msgType.warning || type == msgType.info)//警告
  307. {
  308. timeout = 3000;
  309. }
  310. else if (type == msgType.success)//成功
  311. {
  312. text = (text && text != null ? text : "操作成功");//${common_op_succeed}:操作成功
  313. var num = strlen(text) / 30;
  314. num = num > 8 ? 8 : num;
  315. timeout = Math.ceil(num) * timeout;//动态判断显示字符数的长度来延长显示时间
  316. }
  317. else if (type == msgType.error)//失败
  318. {
  319. text = (text && text != null) ? text : "操作失败";//${common_op_failed}:操作失败,程序出现异常
  320. timeout = 3000;
  321. }
  322. else if (type == msgType.loading)//处理中
  323. {
  324. timeout = 0;//当为'loading'时,timeout值会被设置为0,表示不会自动关闭。
  325. text = text && text != null ? text : "处理中";//${common_op_processing}:处理中
  326. }
  327. var width = strlen(text) * 6.1 + 45;//按字符计算宽度
  328. timeout = ptimeout ? ptimeout : timeout;
  329. $.jBox.tip(text, type, {timeout: timeout, width: (width > 400 ? 400 : "auto")});//设定最大宽度为400
  330. }
  331. function closeMessage(timeout) {
  332. timeout = timeout ? timeout : 1000;
  333. window.setTimeout("$.jBox.closeTip();", timeout);//设定最小等待时间
  334. }
  335. function strlen(str) {
  336. var len = 0;
  337. if (str != null) {
  338. for (var i = 0; i < str.length; i++) {
  339. var c = str.charCodeAt(i);
  340. if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
  341. len++;
  342. }
  343. else {
  344. len += 2;
  345. }
  346. }
  347. }
  348. return len;
  349. }
  350. function messageBox(paramsJson) {
  351. this.messageType = paramsJson.messageType ? $.trim(paramsJson.messageType) : "confirm";
  352. this.types = "";
  353. if (paramsJson.type) {
  354. this.typeArray = paramsJson.type.split(" ");
  355. for (var i = 0; i < this.typeArray.length; i++) {
  356. this.types += this.typeArray[i] + " ";
  357. }
  358. }
  359. switch (this.messageType) {
  360. case "confirm":
  361. $.jBox.confirm(paramsJson.text, "提示", function (v, h, f) {
  362. if (v == "ok") {
  363. paramsJson.callback(true);
  364. }
  365. });
  366. break;
  367. }
  368. }
  369. /**
  370. * 根据出生日期算出年龄
  371. * @param strBirthday
  372. * @returns {number}
  373. */
  374. function jsGetAge(strBirthday) {
  375. var returnAge;
  376. var strBirthdayArr = strBirthday.split("-");
  377. var birthYear = strBirthdayArr[0];
  378. var birthMonth = strBirthdayArr[1];
  379. var birthDay = strBirthdayArr[2];
  380. d = new Date();
  381. var nowYear = d.getFullYear();
  382. var nowMonth = d.getMonth() + 1;
  383. var nowDay = d.getDate();
  384. if (nowYear == birthYear) {
  385. returnAge = 0;//同年 则为0岁
  386. }
  387. else {
  388. var ageDiff = nowYear - birthYear; //年之差
  389. if (ageDiff > 0) {
  390. if (nowMonth == birthMonth) {
  391. var dayDiff = nowDay - birthDay;//日之差
  392. if (dayDiff < 0) {
  393. returnAge = ageDiff - 1;
  394. }
  395. else {
  396. returnAge = ageDiff;
  397. }
  398. }
  399. else {
  400. var monthDiff = nowMonth - birthMonth;//月之差
  401. if (monthDiff < 0) {
  402. returnAge = ageDiff - 1;
  403. }
  404. else {
  405. returnAge = ageDiff;
  406. }
  407. }
  408. }
  409. else {
  410. returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
  411. }
  412. }
  413. return returnAge;//返回周岁年龄
  414. }
  415. /**
  416. * 身份证号有变化后查询病人信息
  417. */
  418. function queryUserInfoBySocialNo() {
  419. var idCard = $("#idCard").val();
  420. if (idCard.length == 18) {
  421. $.ajax({
  422. type: "GET",
  423. url: '/thmz/getBySocialNo?socialNo=' + idCard,
  424. contentType: "application/json;charset=UTF-8",
  425. dataType: "json",
  426. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  427. success: function (res) {
  428. if (res == '401' || res == 401) {
  429. window.location.href = '/thmz/login/view'
  430. return;
  431. }
  432. if (res.code == 0) {
  433. if (res.data != null && res.data.length > 0) {
  434. //如果只有一条数据的时候,直接加载当前病人信息
  435. if (res.data.length == 1) {
  436. fillPatinet(res.data[0].patientId);
  437. } else {
  438. fitPatient(res);
  439. }
  440. } else {
  441. var birthday = idCard.substring(6, 14);
  442. birthday = birthday.substring(0, 4) + "-" + birthday.substring(4, 6) + "-" + birthday.substring(6);
  443. $("#birthDay").val(birthday);
  444. var returnAge = jsGetAge(birthday);
  445. $("#age").val(returnAge);
  446. var gender = idCard.substring(16, 17);
  447. if (gender % 2 == 0) {
  448. $("#gender").val(2);
  449. } else {
  450. $("#gender").val(1);
  451. }
  452. $('#gender').selectpicker('refresh');
  453. }
  454. } else {
  455. errorMesage(res);
  456. }
  457. }
  458. });
  459. }
  460. }
  461. /**
  462. * 查询患者信息
  463. */
  464. function fitPatient(res) {
  465. if (res.data.length > 0) {
  466. $("#patientModal").modal();
  467. $("#patientTable").html(null);
  468. for (var i = 0; i < res.data.length; i++) {
  469. var gender = '未知';
  470. if (res.data[i].sex == 1) {
  471. gender = '男';
  472. } else if (res.data[i].sex == 2) {
  473. gender = '女';
  474. }
  475. var icCardNo = res.data[i].icCardNo;
  476. if (icCardNo == null || icCardNo == "null") {
  477. icCardNo = "";
  478. }
  479. var phoneNo = res.data[i].phoneNo;
  480. if (phoneNo == null || phoneNo == "null") {
  481. phoneNo = "";
  482. }
  483. var birthDay = format(res.data[i].birthDay, "yyyy-MM-dd");
  484. if (birthDay == null || birthDay == "null") {
  485. birthDay = "";
  486. }
  487. var socialNo = res.data[i].socialNo;
  488. if (socialNo == null || socialNo == "null") {
  489. socialNo = "";
  490. }
  491. $("<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 () {
  492. $("#patientModal").modal("hide");
  493. fillPatinet($(this).attr("data-target"));
  494. });
  495. }
  496. }
  497. }
  498. /**
  499. * 初始化省份
  500. * @param type 1 挂号 2 挂号列表 3 医生工作台 4 入院登记 5 传染病上报
  501. */
  502. function initProvince(type) {
  503. $.ajax({
  504. type: "GET",
  505. url: '/thmz/getProvince',
  506. dataType: "json",
  507. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  508. success: function (res) {
  509. if (res == '401' || res == 401) {
  510. window.location.href = '/thmz/login/view'
  511. return;
  512. }
  513. var html ='<option value="-1">—— 省 ——</option>';
  514. $.each(res.data, function (commentIndex, comment) {
  515. html += '<option value="' + comment.code + '">' + comment.name + '</option>';
  516. });
  517. if (type == 1) {
  518. $('#provinceCode').empty(); //清空resText里面的所有内容
  519. $('#provinceCode').html(html);
  520. $('#provinceCode').selectpicker('refresh');
  521. $('#provinceCode').selectpicker({
  522. dropuAuto: false,
  523. size: 5
  524. });
  525. $('#editUserProvinceCode').empty(); //清空resText里面的所有内容
  526. $('#editUserProvinceCode').html(html);
  527. $('#editUserProvinceCode').selectpicker('refresh');
  528. $('#editUserProvinceCode').selectpicker({
  529. dropuAuto: false,
  530. size: 5
  531. });
  532. initCity(1, null);
  533. initCity(2, null);
  534. } else if (type == 2) {
  535. $('#editUserProvinceCode').empty(); //清空resText里面的所有内容
  536. $('#editUserProvinceCode').html(html);
  537. $('#editUserProvinceCode').selectpicker('refresh');
  538. $('#editUserProvinceCode').selectpicker({
  539. dropuAuto: false,
  540. size: 5
  541. });
  542. initCity(2, null);
  543. } else if (type == 3) {
  544. $('#editUserProvinceCode').empty(); //清空resText里面的所有内容
  545. $('#editUserProvinceCode').html(html);
  546. $('#editUserProvinceCode').selectpicker('refresh');
  547. $('#editUserProvinceCode').selectpicker({
  548. dropuAuto: false,
  549. size: 5
  550. });
  551. initCity(2, null);
  552. $('#rapidAcceptsProvinceCode').empty(); //清空resText里面的所有内容
  553. $('#rapidAcceptsProvinceCode').html(html);
  554. $('#rapidAcceptsProvinceCode').selectpicker('refresh');
  555. $('#rapidAcceptsProvinceCode').selectpicker({
  556. dropuAuto: false,
  557. size: 5
  558. });
  559. initCity(3, null);
  560. } else if (type == 4) {
  561. $('#provinceCode').empty(); //清空resText里面的所有内容
  562. $('#provinceCode').html(html);
  563. $('#provinceCode').selectpicker('refresh');
  564. $('#provinceCode').selectpicker({
  565. dropuAuto: false,
  566. size: 5
  567. });
  568. initCity(1, null);
  569. $('#provinceCodeBorn').empty(); //清空resText里面的所有内容
  570. $('#provinceCodeBorn').html(html);
  571. $('#provinceCodeBorn').selectpicker('refresh');
  572. $('#provinceCodeBorn').selectpicker({
  573. dropuAuto: false,
  574. size: 5
  575. });
  576. initCity(4, null);
  577. } else if (type == 5) {
  578. $('#crbMainCardProvinceCode').empty(); //清空resText里面的所有内容
  579. $('#crbMainCardProvinceCode').html(html);
  580. $('#crbMainCardProvinceCode').selectpicker('refresh');
  581. $('#crbMainCardProvinceCode').selectpicker({
  582. dropuAuto: false,
  583. size: 5
  584. });
  585. initCity(5, null);
  586. }
  587. }
  588. });
  589. }
  590. /**
  591. * 初始化市
  592. * @param type 1 新增模块 2 修改模块 3 快速接诊 4 入院登记 5 传染病上报
  593. * @param defaultCode 默认选中
  594. */
  595. function initCity(type, defaultCode) {
  596. var parentCode = $("#provinceCode").val();
  597. if (type == 2) {
  598. parentCode = $("#editUserProvinceCode").val();
  599. } else if (type == 3) {
  600. parentCode = $("#rapidAcceptsProvinceCode").val();
  601. }else if (type == 4){
  602. parentCode = $("#provinceCodeBorn").val();
  603. }else if (type == 5){
  604. parentCode = $("#crbMainCardProvinceCode").val();
  605. }
  606. $.ajax({
  607. type: "GET",
  608. url: '/thmz/getRegionByParentCode?parentCode=' + parentCode,
  609. dataType: "json",
  610. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  611. success: function (res) {
  612. if (res == '401' || res == 401) {
  613. window.location.href = '/thmz/login/view'
  614. return;
  615. }
  616. var html ='<option value="-1">—— 市 ——</option>';
  617. $.each(res.data, function (commentIndex, comment) {
  618. html += '<option value="' + comment.code + '">' + comment.name + '</option>';
  619. });
  620. var id = 'cityCode';
  621. if (type == 2) {
  622. id = 'editCityCode';
  623. } else if (type == 3) {
  624. id = 'rapidAcceptsCityCode';
  625. }else if (type == 4){
  626. id = 'cityCodeBorn';
  627. }else if (type == 5){
  628. id = 'crbMainCardCityCode';
  629. }
  630. $('#' + id).empty(); //清空resText里面的所有内容
  631. $('#' + id).html(html);
  632. $('#' + id).selectpicker('refresh');
  633. $('#' + id).selectpicker({
  634. dropuAuto: false,
  635. size: 5
  636. });
  637. if (defaultCode != null && defaultCode != "") {
  638. $('#' + id).selectpicker('val', defaultCode);
  639. $('#' + id).selectpicker('refresh');
  640. } else {
  641. initDistrict(type, defaultCode, null);
  642. }
  643. }
  644. });
  645. }
  646. /**
  647. * 初始化区县
  648. * @param type 1 新增模块 2 修改模块 3 快速接诊 4 入院登记 5 传染病上报
  649. * @param defaultCityCode 因为需要联动加载,市区域的值
  650. * @param defaultCode 默认选中
  651. */
  652. function initDistrict(type, defaultCityCode, defaultCode) {
  653. if (defaultCityCode == null || defaultCityCode == "") {
  654. defaultCityCode = $("#cityCode").val();
  655. if (type == 2) {
  656. defaultCityCode = $("#editCityCode").val();
  657. } else if (type == 3) {
  658. defaultCityCode = $("#rapidAcceptsCityCode").val();
  659. } else if (type == 4) {
  660. defaultCityCode = $("#cityCodeBorn").val();
  661. }else if (type == 5) {
  662. defaultCityCode = $("#crbMainCardCityCode").val();
  663. }
  664. }
  665. $.ajax({
  666. type: "GET",
  667. url: '/thmz/getRegionByParentCode?parentCode=' + defaultCityCode,
  668. dataType: "json",
  669. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  670. success: function (res) {
  671. if (res == '401' || res == 401) {
  672. window.location.href = '/thmz/login/view'
  673. return;
  674. }
  675. var html ='<option value="-1">—— 区 ——</option>';
  676. $.each(res.data, function (commentIndex, comment) {
  677. html += '<option value="' + comment.code + '">' + comment.name + '</option>';
  678. });
  679. var id = 'districtCode';
  680. if (type == 2) {
  681. id = 'editUserDistrictCode';
  682. } else if (type == 3) {
  683. id = 'rapidAcceptsDistrictCode';
  684. } else if (type == 4) {
  685. id = 'districtCodeBorn';
  686. }else if (type == 5) {
  687. id = 'crbMainCardDistrictCode';
  688. }
  689. $('#' + id).empty(); //清空resText里面的所有内容
  690. $('#' + id).html(html);
  691. $('#' + id).selectpicker('refresh');
  692. $('#' + id).selectpicker({
  693. dropuAuto: false,
  694. size: 5
  695. });
  696. if (defaultCode != null && defaultCode != "") {
  697. $('#' + id).selectpicker('val', defaultCode);
  698. $('#' + id).selectpicker('refresh');
  699. }
  700. }
  701. });
  702. }