You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
8.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. // import sysConfig from "./mm";
  2. // import { getapi, postapi, putapi, deletapi } from "@/api/api";
  3. const sysConfig = require('./mm');
  4. const {getapi, postapi, putapi, deletapi} = require('../api/api');
  5. //多级联动选择数据处理 add by pengjun
  6. function tcdate(date) {
  7. for (var i = 0; i < date.length; i++) {
  8. if (date[i].treeChildren.length == 0) {
  9. date[i].treeChildren = undefined;
  10. } else {
  11. tcdate(date[i].treeChildren);
  12. }
  13. }
  14. };
  15. exports.tcdate = tcdate;
  16. //json 对像赋值 只从 provide/提供 对象 赋值到 receive/接收 中有的 key 项 add by pengjun receive provide
  17. function objCopy(provide, receive) {
  18. if (provide && receive) {
  19. let keys = Object.keys(receive);
  20. for (let key in keys) {
  21. if (provide[keys[key]] !== undefined) {
  22. receive[keys[key]] = provide[keys[key]];
  23. }
  24. }
  25. }
  26. };
  27. exports.objCopy = objCopy;
  28. //对象深拷贝
  29. function deepCopy(obj) {
  30. if (obj == null || typeof obj != 'object') {
  31. return obj;
  32. }
  33. let copy;
  34. if (Array.isArray(obj)) {
  35. copy = [];
  36. for (let i = 0; i < obj.length; i++) {
  37. copy[i] = deepCopy(obj[i]);
  38. }
  39. } else {
  40. copy = {};
  41. for (let key in obj) {
  42. copy[key] = deepCopy(obj[key]);
  43. }
  44. }
  45. return copy;
  46. };
  47. exports.deepCopy = deepCopy;
  48. //类似PB中的dddw的功能 add by pengjun
  49. function dddw(arrayData, key, value, display) {
  50. //console.log(arrayData,key,value,display)
  51. let ret = value;
  52. if (arrayData) {
  53. for (let i = 0; i < arrayData.length; i++) {
  54. if (arrayData[i][key] == value) {
  55. ret = arrayData[i][display];
  56. break;
  57. }
  58. }
  59. }
  60. return ret;
  61. };
  62. exports.dddw = dddw;
  63. //一般uuid字段为空时,需设置为null值
  64. function setNull(obj, arrayKeys) {
  65. if (arrayKeys) {
  66. for (let i = 0; i < arrayKeys.length; i++) {
  67. if (!obj[arrayKeys[i]] || obj[arrayKeys[i]].length < 1) {
  68. obj[arrayKeys[i]] = null;
  69. }
  70. }
  71. }
  72. };
  73. exports.setNull = setNull;
  74. //将字符串转换成二进制形式,中间用空格隔开
  75. function strToBinary(str) {
  76. let result = [];
  77. let list = str.split("");
  78. for (var i = 0; i < list.length; i++) {
  79. if (i != 0) {
  80. result.push(" ");
  81. }
  82. let item = list[i];
  83. let binaryStr = item.charCodeAt().toString(2);
  84. result.push(binaryStr);
  85. }
  86. return result.join("");
  87. };
  88. exports.strToBinary = strToBinary;
  89. //将二进制字符串转换成Unicode字符串
  90. function binaryToStr(str) {
  91. var result = [];
  92. var list = str.split(" ");
  93. for (var i = 0; i < list.length; i++) {
  94. var item = list[i];
  95. var asciiCode = parseInt(item, 2);
  96. var charValue = String.fromCharCode(asciiCode);
  97. result.push(charValue);
  98. }
  99. return result.join("");
  100. };
  101. exports.binaryToStr = binaryToStr;
  102. //数组过滤出符合条件的
  103. function arrayFilter(arr, key, value) {
  104. let result = [];
  105. for (let i = 0; i < arr.length; i++) {
  106. if (arr[i][key] == value) {
  107. result.push(arr[i]);
  108. }
  109. }
  110. return result;
  111. };
  112. exports.arrayFilter = arrayFilter;
  113. //数组相减 arrFront = arrFront - reduceArr ;
  114. function arrayReduce(arrFront, reduceArr, key) {
  115. let keys = key.split("=");
  116. let keyF = keys[0];
  117. let keyR = keys.length > 1 ? keys[1] : keys[0];
  118. //console.log(arrFront, reduceArr)
  119. if (!arrFront || arrFront.length < 1 || !reduceArr || reduceArr.length < 1) {
  120. return arrFront;
  121. }
  122. //console.log(arrFront.length, reduceArr.length)
  123. for (let i = 0; i < reduceArr.length; i++) {
  124. //console.log('i', i)
  125. for (let j = 0; j < arrFront.length; j++) {
  126. //console.log('j', j)
  127. if (reduceArr[i][keyR] == arrFront[j][keyF]) {
  128. arrFront.splice(j, 1);
  129. }
  130. }
  131. }
  132. return arrFront;
  133. };
  134. exports.arrayReduce = arrayReduce;
  135. //判断数组中 是否存在 某个值的对象记录 如不存在返回 - 1,存在返回相应的 序列
  136. function arrayExistObj(arr, key, value) {
  137. let ret = - 1
  138. for (let i = 0; i < arr.length; i++) {
  139. if (arr[i][key] == value) {
  140. ret = i
  141. break
  142. }
  143. }
  144. return ret
  145. };
  146. exports.arrayExistObj = arrayExistObj;
  147. //判断身份证是否合法
  148. function checkIDCode(IDCode) {
  149. // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  150. let ret = false;
  151. let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  152. if(reg.test(IDCode)) {
  153. ret = true;
  154. }
  155. if(!ret) return ret
  156. if(IDCode.length == 15){
  157. if (IDCode.substring(8, 10).parseInt > 12 || IDCode.substring(8, 10).parseInt == 0) return false
  158. if (IDCode.substring(10, 12).parseInt > 31 || IDCode.substring(10, 12).parseInt == 0) return false
  159. }else{
  160. if (IDCode.substring(10, 12).parseInt > 12 || IDCode.substring(10, 12).parseInt == 0) return false
  161. if (IDCode.substring(12, 14).parseInt > 31 || IDCode.substring(12, 14).parseInt == 0) return false
  162. }
  163. return ret
  164. };
  165. exports.checkIDCode = checkIDCode;
  166. //根据身份证号判断出生日期(yyyy-MM-DD),当前年龄与性别 粗犷式,不精确判断闰年平年
  167. function parseID(id) {
  168. let ret = {
  169. birthday: null,
  170. age: null,
  171. sex: 'U',
  172. }
  173. if(!checkIDCode(id)) return ret
  174. let yearInMs = 1000 * 60 * 60 * 24 * 365.2425;
  175. //出生日期
  176. ret.birthday = id.substring(6, 10) + '-' + id.substring(10, 12) + '-' + id.substring(12, 14)
  177. //年龄
  178. ret.age = Math.floor((new Date().getTime() - new Date(ret.birthday).getTime()) / yearInMs)
  179. //奇数 男, 偶数 女
  180. if (id.substring(16, 17) % 2 == 0) {
  181. ret.sex = 'F'
  182. } else {
  183. ret.sex = 'M'
  184. }
  185. return ret
  186. };
  187. exports.parseID = parseID;
  188. //根据出生日期,计算当前年龄 粗犷式,不精确判断闰年平年
  189. function birthdayToAge(birthday) {
  190. let yearInMs = 1000 * 60 * 60 * 24 * 365.2425;
  191. //年龄
  192. return Math.floor((new Date().getTime() - new Date(birthday).getTime()) / yearInMs)
  193. };
  194. exports.birthdayToAge = birthdayToAge;
  195. function ageToBirthday(age) {
  196. let yearInMs = 1000 * 60 * 60 * 24 * 365.2425 * Number(age);
  197. //年龄
  198. return new Date(new Date().getTime() - yearInMs)
  199. };
  200. exports.ageToBirthday = ageToBirthday;
  201. //分析身份证数据
  202. function parsIcCardtoLocal(idNos, dictSex, dictNation) {
  203. let local = deepCopy(idNos);
  204. // {
  205. // "Code": "Success",
  206. // "Name": "刘滔",
  207. // "Sex": "男",
  208. // "Nation": "汉",
  209. // "Birthday": "1986-01-22",
  210. // "Address": "湖南省长沙县春华镇九木村新元组367号",
  211. // "DepartmentIC": "长沙县公安局",
  212. // "StartDateIC": "2019-11-25",
  213. // "EndDateIC": "2039-11-25",
  214. // "IDCode": "430121198601223693",
  215. // "Photo": ""
  216. // }
  217. //console.log(local, dictSex, dictNation)
  218. let lfind = -1;
  219. lfind = arrayExistObj(dictSex, 'displayName', local.Sex)
  220. // console.log(lfind,local.Sex)
  221. if (lfind > -1) local.sexId = dictSex[lfind].id;
  222. lfind = arrayExistObj(dictNation, 'displayName', local.Nation + '族')
  223. // console.log(lfind,local.Nation)
  224. if (lfind > -1) local.nationId = dictNation[lfind].nationId;
  225. local.birthDate = new Date(local.Birthday)
  226. local.age = birthdayToAge(local.Birthday)
  227. return local
  228. };
  229. exports.parsIcCardtoLocal = parsIcCardtoLocal;
  230. function photoParse(photo) {
  231. //console.log(sysConfig,photo)
  232. let lphoto = '' //data:image、UpLoad/、/pic/Photo.jpg
  233. if(!photo) return '/pic/Photo.jpg'
  234. if (photo.indexOf("UpLoad/") > - 1) {
  235. lphoto = sysConfig.apiurl + '/' + photo + '?' + new Date().getTime()
  236. } else {
  237. lphoto = photo
  238. }
  239. //console.log(lphoto)
  240. return lphoto
  241. };
  242. exports.photoParse = photoParse;
  243. async function savePeoplePhoto(peopleId, photoBase64) {
  244. let lres = { code: -1, msg: '' }
  245. if (!peopleId) return { code: -1, msg: '人员ID不能为空' }
  246. if (!photoBase64 || photoBase64.indexOf('data:image') < 0) return { code: -1, msg: '图像数据不是合法的base64编码数据' }
  247. let uploadPhoto = {
  248. patientRegisterId: peopleId,
  249. photo: photoBase64.split(",")[1],
  250. };
  251. try {
  252. lres = await postapi(`/api/app/patient-register/up-load-img`, uploadPhoto)
  253. let body = {
  254. patientRegisterId: peopleId,
  255. photo: lres.data,
  256. }
  257. await postapi(`/api/app/patient-register/update-photo`, body)
  258. } catch (error) {
  259. lres = { code: -1, msg: error }
  260. }
  261. return lres
  262. };
  263. exports.savePeoplePhoto = savePeoplePhoto;