血透系统PC前端

tools.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. export function getFileExtension(filename) {
  2. var tempArr = filename.split('.')
  3. var ext
  4. if (tempArr.length === 1 || (tempArr[0] === '' && tempArr.length === 2)) {
  5. ext = ''
  6. } else {
  7. ext = tempArr.pop().toLowerCase() // get the extension and make it lower-case
  8. }
  9. return ext
  10. }
  11. export function isCardNo(card) {
  12. // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  13. var reg_18 = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
  14. var reg_15 = /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$/
  15. return reg_18.test(card) || reg_15.test(card)
  16. }
  17. export function jsGetAge(strBirthday, splitstr) {
  18. // debugger
  19. var returnAge
  20. var strBirthdayArr = strBirthday.split(splitstr)
  21. var birthYear = strBirthdayArr[0]
  22. var birthMonth = strBirthdayArr[1]
  23. var birthDay = strBirthdayArr[2]
  24. var d = new Date()
  25. var nowYear = d.getFullYear()
  26. var nowMonth = d.getMonth() + 1
  27. var nowDay = d.getDate()
  28. if (nowYear == birthYear) {
  29. returnAge = 0 // 同年 则为0岁
  30. } else {
  31. var ageDiff = nowYear - birthYear // 年之差
  32. if (ageDiff > 0) {
  33. if (nowMonth == birthMonth) {
  34. var dayDiff = nowDay - birthDay // 日之差
  35. if (dayDiff < 0) {
  36. returnAge = ageDiff - 1
  37. } else {
  38. returnAge = ageDiff
  39. }
  40. } else {
  41. var monthDiff = nowMonth - birthMonth // 月之差
  42. if (monthDiff < 0) {
  43. returnAge = ageDiff - 1
  44. } else {
  45. returnAge = ageDiff
  46. }
  47. }
  48. } else {
  49. returnAge = -1 // 返回-1 表示出生日期输入错误 晚于今天
  50. }
  51. }
  52. return returnAge // 返回周岁年龄
  53. }
  54. export function isPositiveInteger(s) {
  55. // 是否为正整数
  56. var re = /^[0-9]+$/
  57. return re.test(s)
  58. }
  59. export function isPositiveNumber(s) {
  60. var re = /^\d+(\.\d+)?$/
  61. return re.test(s)
  62. }
  63. export function dialysisAge(firstDialysisDate) {
  64. var dialysisAge
  65. var startDate = firstDialysisDate.split('-')
  66. var startYear = startDate[0]
  67. var startMonth = startDate[1]
  68. var startDay = startDate[2]
  69. var d = new Date()
  70. var nowYear = d.getFullYear()
  71. var nowMonth = d.getMonth() + 1
  72. var nowDay = d.getDate()
  73. var diffYear = nowYear - startYear
  74. var diffMonth = nowMonth - startMonth
  75. var diffDay = nowDay - startDay
  76. if (diffYear < 0) {
  77. dialysisAge = ''
  78. } else if (diffYear == 0) {
  79. if (diffMonth < 0) {
  80. dialysisAge = ''
  81. } else if (diffMonth == 0 && diffDay < 0) {
  82. dialysisAge = ''
  83. } else {
  84. if (diffDay < 0) {
  85. diffMonth -= 1
  86. }
  87. dialysisAge = diffMonth + '个月'
  88. }
  89. } else {
  90. if (diffDay < 0) {
  91. diffMonth -= 1
  92. }
  93. if (diffMonth < 0) {
  94. diffYear -= 1
  95. diffMonth += 12
  96. }
  97. if (diffYear > 0 && diffMonth > 0) {
  98. dialysisAge = diffYear + '年零' + diffMonth + '个月'
  99. } else if (diffYear > 0) {
  100. dialysisAge = diffYear + '年'
  101. } else {
  102. dialysisAge = diffMonth + '个月'
  103. }
  104. }
  105. return dialysisAge // 返回周岁年龄
  106. }
  107. export function uParseTime(time, cFormat) {
  108. if (time === 0) {
  109. return ''
  110. }
  111. if (arguments.length === 0) {
  112. return null
  113. }
  114. const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  115. let date
  116. if (typeof time === 'object') {
  117. date = time
  118. } else {
  119. if (('' + time).length !== 13) time = parseInt(time) * 1000
  120. date = new Date(time)
  121. }
  122. const formatObj = {
  123. y: date.getFullYear(),
  124. m: date.getMonth() + 1,
  125. d: date.getDate(),
  126. h: date.getHours(),
  127. i: date.getMinutes(),
  128. s: date.getSeconds(),
  129. a: date.getDay()
  130. }
  131. const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
  132. let value = formatObj[key]
  133. if (key === 'a') {
  134. return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
  135. }
  136. if (result.length > 0 && value < 10) {
  137. value = '0' + value
  138. }
  139. return value || 0
  140. })
  141. return time_str
  142. }
  143. export function calculateAnticoagulantZL(type, shouji, shichang, weichi) {
  144. console.log(type)
  145. console.log(shouji)
  146. console.log(shichang)
  147. console.log(weichi)
  148. var t = 0.5
  149. if (type == 1) {
  150. t = 0.5
  151. } else if (type == 2) {
  152. t = 1
  153. } else {
  154. return 0
  155. }
  156. shouji = parseFloat(shouji)
  157. shichang = parseFloat(shichang)
  158. weichi = parseFloat(weichi)
  159. if (isNaN(shouji) || isNaN(shichang) || isNaN(weichi)) {
  160. return 0
  161. }
  162. console.log((shouji + (shichang - t) * weichi).toFixed(1))
  163. return (shouji + (shichang - t) * weichi).toFixed(1)
  164. }