util.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. toastr.options = {
  2. "closeButton": true,
  3. "positionClass": "toast-top-center"
  4. }
  5. Date.prototype.format = function(formatStr)
  6. {
  7. var str = formatStr;
  8. var Week = ['日','一','二','三','四','五','六'];
  9. str=str.replace(/yyyy|YYYY/,this.getFullYear());
  10. str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
  11. str=str.replace(/MM/,this.getMonth()>8?(this.getMonth()+1).toString():'0' + (this.getMonth()+1));
  12. str=str.replace(/M/g,this.getMonth()+1);
  13. str=str.replace(/w|W/g,Week[this.getDay()]);
  14. str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
  15. str=str.replace(/d|D/g,this.getDate());
  16. str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
  17. str=str.replace(/h|H/g,this.getHours());
  18. str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
  19. str=str.replace(/m/g,this.getMinutes());
  20. str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
  21. str=str.replace(/s|S/g,this.getSeconds());
  22. return str;
  23. }
  24. //获取链接上的参数
  25. function getRequest() {
  26. var url = location.search; //获取url中"?"符后的字串
  27. var theRequest = new Object();
  28. if (url.indexOf("?") != -1) {
  29. var str = url.substr(1);
  30. strs = str.split("&");
  31. for(var i = 0; i < strs.length; i ++) {
  32. theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
  33. }
  34. }
  35. return theRequest;
  36. }
  37. //根据选择的tab获得开始和结束时间
  38. function getStartEndDate(index){
  39. var now = new Date(),
  40. sDate = new Date();
  41. var endDate = now.format('yyyy-MM-dd'),
  42. startDate = '';
  43. switch (index){
  44. case '0':
  45. startDate = '';
  46. endDate = '';
  47. break;
  48. case '1': //近一周
  49. sDate.setDate(now.getDate() - 7);
  50. startDate = sDate.format('yyyy-MM-dd');
  51. break;
  52. case '2': //近一个月
  53. sDate.setMonth(now.getMonth() -1);
  54. startDate = sDate.format('yyyy-MM-dd');
  55. break;
  56. case '3': //近半年
  57. sDate.setMonth(now.getMonth() - 6);
  58. startDate = sDate.format('yyyy-MM-dd');
  59. break;
  60. case '4': //近一年
  61. sDate.setFullYear(now.getFullYear() - 1);
  62. startDate = sDate.format('yyyy-MM-dd');
  63. break;
  64. }
  65. return {endDate: endDate, startDate: startDate};
  66. }
  67. //获得状态值
  68. //续方各状态返回值
  69. //(-3 支付过期 -2 患者自己取消 )续方取消,
  70. //-1 审核不通过 ,
  71. //(0 待审核, 2调整中,3调整成功, 4调整失败 ,10 医生审核(CA)通过)审核中,
  72. //20药师审核中,
  73. //21.药师审核失败,
  74. //30 开方中/药师审核成功,
  75. //31.开方失败,
  76. //(40开方完成/待支付 ,41 支付失败 )待支付,
  77. // 50 支付成功/待配药,
  78. //(60配药成功/待配送)等待领药,
  79. //(61配送失败62分配健管师 65配送中,69配送到服务站)配送中,
  80. //(100配送到患者手中/已完成)已完成
  81. //根据状态获得相关信息
  82. function getStatusName(status){
  83. var name = "";
  84. status = status + '';
  85. switch (status){
  86. case '-3':
  87. name = '支付过期';
  88. break;
  89. case '-2':
  90. name = '续方取消(居民主动取消)';
  91. break;
  92. case '-1':
  93. name = '审核未通过';
  94. break;
  95. case '0':
  96. case '2':
  97. case '3':
  98. case '4':
  99. case '10':
  100. name = '审核中';
  101. break;
  102. case '20':
  103. name = '药师审核中';
  104. break;
  105. case '21':
  106. name = '药师审核失败';
  107. break;
  108. case '30':
  109. name = '开方中';
  110. break;
  111. case '31':
  112. name = '开方失败';
  113. break;
  114. case '40':
  115. name = '待支付';
  116. break;
  117. case '41':
  118. name = '支付失败';
  119. break;
  120. case '50':
  121. name = '配药中';
  122. break;
  123. case '60':
  124. name = '等待领药';
  125. break;
  126. case '61':
  127. case '62':
  128. case '65':
  129. name = '配送中';
  130. break;
  131. case '69':
  132. name = '药品到达服务站';
  133. break;
  134. case '100':
  135. name = '已完成';
  136. break;
  137. default:
  138. break;
  139. }
  140. return name;
  141. }
  142. function getExpressName(type){
  143. switch(type){
  144. case 1:
  145. return '自取';
  146. break;
  147. case 2:
  148. return '快递配送';
  149. break;
  150. case 3:
  151. return '健管师配送';
  152. break;
  153. }
  154. }
  155. function getDrugs(prescriptionInfo) {
  156. return _.map(prescriptionInfo,function(v) {
  157. return v.drugName + '&emsp;' + (v.num || '') + (v.drugNumUnitName || '')+'&emsp;'
  158. })
  159. }
  160. function getDaysRemaining(item) {
  161. // 最小用药天数minDrugDay -(当前时间-建立时间presCreateTime)天数
  162. var minDrugDay = item.minDrugDay,
  163. presCreateTime = item.presCreateTime,
  164. curTime = new Date().getTime();
  165. if(item.status == 0 || item.status == 2 || item.status == 3 || item.status == 4 || item.status == 10 || item.status == 31) {
  166. if(minDrugDay && presCreateTime) {
  167. var preTime = new Date(presCreateTime.replace(/-/g,'/')).getTime();
  168. var remain = Math.round(minDrugDay - parseInt(Math.abs(curTime - preTime)/(24 * 3600 * 1000)));
  169. if(remain <= 0){
  170. return '<span style="color: #ff3b30;">已用完</span>';
  171. } else {
  172. return remain;
  173. }
  174. } else {
  175. return '<span style="color: #ff3b30;">-</span>';
  176. }
  177. } else {
  178. return '<span style="color: #ff3b30;">-</span>';
  179. }
  180. }
  181. function getReviewResultName(status) {
  182. if(status == -2) {
  183. return "删除"
  184. } else if(status == -1) {
  185. return "审核未成功"
  186. } else if(status == 0) {
  187. return "待审核"
  188. } else if(status == 1) {
  189. return "审核成功"
  190. } else {
  191. return ""
  192. }
  193. }
  194. function showErrorMsg(msg) {
  195. if(top.toastr) {
  196. top.toastr.error(msg)
  197. }
  198. }
  199. function showSuccessMsg(msg) {
  200. if(top.toastr) {
  201. top.toastr.success(msg)
  202. }
  203. }
  204. function showWarningMsg(msg) {
  205. if(top.toastr) {
  206. top.toastr.warning(msg)
  207. }
  208. }
  209. function calcWorldWithTextarea() {
  210. var preVule = ''
  211. $('textarea[calcWorld]').on('input focus',function() {
  212. var num = $(this).attr('calcWorld');
  213. var len = $(this).val().length;
  214. var value = $(this).val();
  215. var $tip = $(this).parent().find('.wordCount');
  216. if(num >= len) {
  217. $tip.text(len+' / '+ num)
  218. preVule = value
  219. } else {
  220. $(this).val(preVule)
  221. }
  222. })
  223. }
  224. function isTeamLeader() {
  225. var docInfo = JSON.parse(window.localStorage.getItem('docInfo'))
  226. return docInfo.isLeader == '1'? true: false;
  227. }
  228. //设置title
  229. function setTitle(title){
  230. var a = top.document.getElementById("pageTitle");
  231. $(a).text(title);
  232. }