spirit_anesthetic_print.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. //@ sourceURL=spirit_anesthetic_print.js
  2. var LODOP; //声明为全局变量
  3. $(function () {
  4. initDeptSelect(0,"unitCodeSearch");
  5. init_daterangepickertime();
  6. setTimeout(function () {
  7. getLodop();
  8. }, 800);
  9. $("#jmtj_table").hide();
  10. $(".selectpicker").selectpicker({
  11. dropuAuto: false
  12. });
  13. //初始化页面上面的按钮事件
  14. $("#btn_search").click(function (t) {
  15. $('.sjh').remove();
  16. if($('#drugFlagSearch').val() == 0){
  17. getSendDrugRecordData();
  18. }else{
  19. getSpiritAnestheticPrintData();
  20. }
  21. });
  22. $('#btn_clean').click(function () {
  23. cleanParams();
  24. });
  25. $("#btn_daily").click(function (t) {
  26. print();
  27. });
  28. $("#btn_excel").click(function (t) {
  29. let id = "qbtj_table";
  30. let name = "药品发药明细统计表";
  31. if($("#qbtj_table").is(':hidden')){
  32. id = "jmtj_table";
  33. let drugFlag = $("#drugFlagSearch").val();
  34. if(drugFlag == 1){
  35. name = "麻、精一及麻黄碱类药品使用登记";
  36. }else if(drugFlag == 2){
  37. name = "终止妊娠药统计";
  38. }else if(drugFlag == 3){
  39. name = "精二类统计";
  40. }
  41. }
  42. $("#"+id).table2excel({
  43. exclude:".exclHide",
  44. filename:name+"("+getRePortRangeArr()[0].substring(0,getRePortRangeArr()[0].indexOf(" ")+1)+").xls"
  45. })
  46. });
  47. $("#drugFlagSearch").change(function (t,d,e) {
  48. let drugFlag = $("#drugFlagSearch").val();
  49. let title = "";
  50. if(drugFlag == 1){
  51. title = "麻、精一及麻黄碱类药品使用登记";
  52. $("#jmtj_table").show();
  53. $("#qbtj_table").hide();
  54. }else if(drugFlag == 2){
  55. title = "终止妊娠药统计";
  56. $("#jmtj_table").show();
  57. $("#qbtj_table").hide();
  58. }else if(drugFlag == 3){
  59. title = "精二类统计";
  60. $("#jmtj_table").show();
  61. $("#qbtj_table").hide();
  62. }else if(drugFlag == 0){
  63. title = "药品发药明细统计表";
  64. $("#qbtj_table").show();
  65. $("#jmtj_table").hide();
  66. }
  67. $(".title").html(title);
  68. $(".dateRange").html($('#reportrange span').html());
  69. $(".printDate").html(format(new Date(),"yyyy-MM-dd HH:mm"));
  70. });
  71. //初始化药品查询弹出框
  72. initSearchList('<div id="medicinePopoverContent"><table id="tb_table_medicine"></table></div>',
  73. 'searchTextDrug', 700, 250);
  74. $('#searchTextDrug').on('input focus',function(e){
  75. showDrugPopover();
  76. if($('#searchTextDrug').val() == ''){
  77. $('#codeSearch').val("");
  78. $('#serialSearch').val("");
  79. }
  80. });
  81. });
  82. /**
  83. * 获取精麻药统计报表
  84. */
  85. function getSpiritAnestheticPrintData() {
  86. $(".dateRange").html($('#reportrange span').html());
  87. $(".printDate").html(format(new Date(),"yyyy-MM-dd HH:mm"));
  88. $.ajax({
  89. type: "GET",
  90. url: '/thmz/getSpiritAnestheticPrint',
  91. contentType: "application/json;charset=UTF-8",
  92. dataType: "json",
  93. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  94. data: queryParams(),
  95. success: function (res) {
  96. if (res == '401' || res == 401) {
  97. window.location.href = '/thmz/login/view'
  98. return;
  99. }
  100. if (res.code == 0) {
  101. let html = '';
  102. let code = '';
  103. let number = 0;
  104. let sex;
  105. let drugFlag = $("#drugFlagSearch").val();
  106. for (var i = 0; i < res.data.length; i++) {
  107. let data = res.data[i];
  108. if(code == ''){
  109. code = data.chargeItemCode;
  110. number += parseFloat(data.quantity);
  111. }else if(code == data.chargeItemCode){
  112. number += parseFloat(data.quantity);
  113. }else{
  114. html += '<tr class="sjh">';
  115. html += '<td colspan="15" style="text-align: center;font-weight: 700;">共计:' + number + '</td>';
  116. html += '</tr>';
  117. code = data.chargeItemCode;
  118. number = parseFloat(data.quantity);
  119. }
  120. if(data.sex == 1){
  121. sex = "男"
  122. }else if(data.sex == 2){
  123. sex = "女"
  124. }else{
  125. sex = "未知"
  126. }
  127. html += '<tr class="sjh">';
  128. html += '<td class="xtd" style="text-align: center;mso-number-format: \'\\@\';">' + data.chargeDate.substring(5,11) + '</td>';
  129. html += '<td class="xtd" style="text-align: center;">' + data.patientId + '</td>';
  130. html += '<td class="xtd" style="text-align: center;">' + data.name + '</td>';
  131. html += '<td class="xtd" style="text-align: center;">' + sex + '</td>';
  132. html += '<td class="xtd" style="text-align: center;">' + data.age + '</td>';
  133. html += '<td style="mso-number-format: \'\\@\';">' + data.socialNo + '</td>';
  134. html += '<td>' + data.icdText + '</td>';
  135. html += '<td class="xtd" style="text-align: center;">' + data.chargeItemCode + '</td>';
  136. html += '<td>' + data.drugname + '</td>';
  137. html += '<td>' + data.specification + '</td>';
  138. html += '<td class="xtd" style="text-align: center;">' + data.quantity + '</td>';
  139. html += '<td class="xtd" style="text-align: center;">' + data.employeeName.trim() + '</td>';
  140. html += '<td class="xtd" style="text-align: center;">' + data.warnDeptName + '</td>';
  141. html += '<td class="xtd" ></td>';
  142. html += '<td class="xtd" ></td>';
  143. html += '</tr>';
  144. }
  145. html += '<tr class="sjh">';
  146. html += '<td colspan="15" style="text-align: center;font-weight: 700;">共计:' + number + '</td>';
  147. html += '</tr>';
  148. $("#jmtj_table").append(html);
  149. } else if (res.code == -1) {
  150. new PNotify({
  151. title: '错误提示',
  152. text: res.message,
  153. type: 'error',
  154. hide: true,
  155. styling: 'bootstrap3'
  156. });
  157. }
  158. }
  159. });
  160. }
  161. /**
  162. * 获取所有药品类型统计报表
  163. */
  164. function getSendDrugRecordData() {
  165. $('#YWaitDialog').css('top',$('.xtd').offset().top);
  166. $('#YWaitDialog').show();
  167. $(".dateRange").html($('#reportrange span').html());
  168. $(".printDate").html(format(new Date(),"yyyy-MM-dd HH:mm"));
  169. $.ajax({
  170. type: "POST",
  171. url: '/thmz/getSendDrugRecord',
  172. contentType: "application/json;charset=UTF-8",
  173. dataType: "json",
  174. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  175. data: JSON.stringify({
  176. 'beginDate': getRePortRangeArr()[0],
  177. 'endDate': getRePortRangeArr()[1],
  178. 'chargeCode': $('#codeSearch').val()==''?null:$('#codeSearch').val(),
  179. 'serial': $('#serialSearch').val()==''?null:$('#serialSearch').val(),
  180. 'warnDept': $('#unitCodeSearch').val()!=null?$('#unitCodeSearch').val()[0]:null,
  181. 'queryScope': $("#queryScopeSearch").val()
  182. }),
  183. success: function (res) {
  184. $('#YWaitDialog').hide();
  185. if (res == '401' || res == 401) {
  186. window.location.href = '/thmz/login/view'
  187. return;
  188. }
  189. if (res.code == 0) {
  190. let html = '';
  191. let flag = '';//区分门诊住院 -1住院 其它门诊
  192. let number = 0;
  193. let totalNumber = 0;
  194. let sex;
  195. for (var i = 0; i < res.data.length; i++) {
  196. let data = res.data[i];
  197. if(flag == ''){
  198. flag = data.id.indexOf("-")!=-1?'0':'1';
  199. number += parseFloat(data.quantity);
  200. }else if(flag == (data.id.indexOf("-")!=-1?'0':'1')){
  201. number += parseFloat(data.quantity);
  202. }else{
  203. html += '<tr class="sjh">';
  204. html += '<td colspan="11" style="text-align: right;font-weight: 700;">小计:' + number + '</td>';
  205. html += '<td colspan="5"></td>';
  206. html += '</tr>';
  207. flag = data.id.indexOf("-")!=-1?'0':'1';
  208. totalNumber += number;
  209. number = parseFloat(data.quantity);
  210. }
  211. if(data.sex == 1){
  212. sex = "男"
  213. }else if(data.sex == 2){
  214. sex = "女"
  215. }else{
  216. sex = "未知"
  217. }
  218. let queryScope = data.id.indexOf("-")!=-1?'门诊':'住院';
  219. let age = data.birthDay!=null?getBirthSlot(data.birthDay,new Date()):'';
  220. html += '<tr class="sjh">';
  221. html += '<td class="xtd" style="text-align: center;">' + data.id + '</td>';
  222. html += '<td class="xtd" style="text-align: center;">' + data.name + '</td>';
  223. html += '<td class="xtd" style="text-align: center;">' + sex + '</td>';
  224. html += '<td class="xtd" style="text-align: center;">' + age.substring(0,age.indexOf('岁')) + '</td>';
  225. html += '<td class="xtd" style="text-align: center;">' + data.warnDeptName + '</td>';
  226. html += '<td>' + data.icdText + '</td>';
  227. html += '<td class="xtd" style="text-align: center;">' + data.chargeCode + '</td>';
  228. html += '<td>' + data.drugName + '</td>';
  229. html += '<td>' + data.specification + '</td>';
  230. html += '<td>' + data.abbrName + '</td>';
  231. html += '<td class="xtd" style="text-align: center;">' + data.quantity + '</td>';
  232. html += '<td class="exclHide" style="text-align: center;">' + data.chargeDate + '</td>';
  233. html += '<td class="xtd" style="text-align: center;">' + data.employeeName.trim().substring(0,1)+new Array(data.employeeName.trim().length).join('*') + '</td>';
  234. html += '<td class="xtd" style="text-align: center;">' + data.supplyName + '</td>';
  235. html += '<td class="xtd" style="text-align: center;">' + data.frequency + '</td>';
  236. html += '<td class="xtd" style="text-align: center;">' + queryScope + '</td>';
  237. html += '</tr>';
  238. }
  239. html += '<tr class="sjh">';
  240. html += '<td colspan="11" style="text-align: right;font-weight: 700;">小计:' + number + '</td>';
  241. html += '<td colspan="5"></td>';
  242. html += '</tr>';
  243. html += '<tr class="sjh">';
  244. html += '<td colspan="11" style="text-align: right;font-weight: 700;">总计:' + parseFloat(totalNumber+number) + '</td>';
  245. html += '<td colspan="5"></td>';
  246. html += '</tr>';
  247. $("#qbtj_table").append(html);
  248. } else if (res.code == -1) {
  249. new PNotify({
  250. title: '错误提示',
  251. text: res.message,
  252. type: 'error',
  253. hide: true,
  254. styling: 'bootstrap3'
  255. });
  256. }
  257. }
  258. });
  259. }
  260. /**
  261. * 获取按钮组选择的下标
  262. * @param id
  263. * @returns {number}
  264. */
  265. function getIndex(id) {
  266. var index = 0;
  267. var item = $("#" + id).find("button");
  268. for (var i = 0; i <= item.length; i++) {
  269. if ($(item[i]).hasClass("btn-primary")) {
  270. index = i;
  271. break;
  272. }
  273. }
  274. return index;
  275. }
  276. /**
  277. * 获取时间选择器的时间数组
  278. * @returns {string[]}
  279. */
  280. function getRePortRangeArr() {
  281. var rePortRange = $('#reportrange span').html();
  282. var rePortRangeArr = rePortRange.split(" - ");
  283. return rePortRangeArr;
  284. }
  285. /**
  286. * 清空查询条件
  287. */
  288. function cleanParams() {
  289. $("#queryScopeSearch").val(0);
  290. $('#queryScopeSearch').selectpicker('refresh');
  291. $('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD 14:00:00") + ' - ' + moment().format("YYYY-MM-DD 13:59:59"));
  292. $('#unitCodeSearch').empty();
  293. $('#drugFlagSearch').val(0);
  294. $('#qbtj_table').show();
  295. $('#jmtj_table').hide();
  296. $('.sjh').remove();
  297. $('#drugFlagSearch').selectpicker('refresh');
  298. $("#unitCodeSearch").html('');
  299. $("#unitCodeSearch").selectpicker('refresh');
  300. $('#searchTextDrug').empty();
  301. $('#codeSearch').empty();
  302. $('#serialSearch').empty();
  303. }
  304. /**
  305. * 打印报表
  306. */
  307. function print() {
  308. setDefaultPrint();
  309. LODOP = getLodop();
  310. LODOP.PRINT_INITA(6, 0, "210mm", "297mm", "药品发放统计表");
  311. LODOP.SET_PRINT_PAGESIZE(2, 0, 0,"A4");
  312. //设置默认打印机
  313. LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
  314. LODOP.SET_PRINT_STYLE("FontSize", 10); //字体大小
  315. LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
  316. //设置默认打印机
  317. LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
  318. LODOP.ADD_PRINT_TEXT('200mm','140mm','40mm','40mm','第#页/共&页');
  319. LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
  320. var strStyle="<style>table,td,th {border-width: 1px;" +
  321. "border-style: solid;border-collapse: collapse;table-layout:fixed;word-wrap:break-word;font-size: 14px}</style>";
  322. LODOP.ADD_PRINT_HTM("2mm", "4mm", "RightMargin:4mm", "BottomMargin:15mm",strStyle+ document.getElementById("report_table_1").innerHTML);
  323. LODOP.PRINT();
  324. //LODOP.PREVIEW();
  325. }
  326. /**
  327. * 统计列表查询参数
  328. */
  329. function queryParams() {
  330. let drugFlags = new Array();
  331. let flag = $("#drugFlagSearch").val();
  332. if(flag == 1){
  333. drugFlags[0] = 2;
  334. drugFlags[1] = 3;
  335. drugFlags[2] = 5;
  336. }else if(flag == 2){
  337. drugFlags[0] = 6;
  338. }else if(flag == 3){
  339. drugFlags[0] = 1;
  340. drugFlags[1] = 4;
  341. }
  342. var temp = {
  343. beginDate: getRePortRangeArr()[0],
  344. endDate: getRePortRangeArr()[1],
  345. chargeItemCode: $('#codeSearch').val(),
  346. unitCode: $('#unitCodeSearch').val()!=null?$('#unitCodeSearch').val()[0]:'',
  347. drugFlags: drugFlags,
  348. queryScope: $("#queryScopeSearch").val()
  349. };
  350. return temp;
  351. }
  352. function init_daterangepickertime() {
  353. if (typeof ($.fn.daterangepicker) === 'undefined') {
  354. return;
  355. }
  356. var optionSet1 = {
  357. startDate: moment().subtract(1, 'days').format("YYYY-MM-DD 00:00:00"),
  358. endDate: moment().subtract(1, 'days').format("YYYY-MM-DD 23:59:59"),
  359. minDate: '2012-01-01',
  360. maxDate: nowString()+' 23:59:59',
  361. dateLimit: {
  362. days: 1200
  363. },
  364. showDropdowns: true,
  365. showWeekNumbers: true,
  366. ranges: {
  367. '今天': [moment(), moment()],
  368. '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  369. '最近7天': [moment().subtract(6, 'days'), moment()],
  370. '最近30天': [moment().subtract(29, 'days'), moment()],
  371. '当月': [moment().startOf('month'), moment().endOf('month')],
  372. '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  373. },
  374. opens: 'right',
  375. buttonClasses: ['btn btn-default'],
  376. applyClass: 'btn-small btn-primary',
  377. cancelClass: 'btn-small',
  378. timePicker: true, //显示时间
  379. timePicker24Hour: true, //时间制
  380. timePickerSeconds: true, //时间显示到秒
  381. timePickerIncrement: 1,
  382. format: 'YYYY-MM-DD HH:mm:ss',
  383. separator: ' to ',
  384. locale: {
  385. applyLabel: '确定',
  386. cancelLabel: '取消',
  387. fromLabel: 'From',
  388. toLabel: 'To',
  389. customRangeLabel: '自定义',
  390. daysOfWeek: ['天', '一', '二', '三', '四', '五', '六'],
  391. monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  392. firstDay: 1
  393. }
  394. };
  395. $('#reportrange').daterangepicker(optionSet1, function (start, end, label) {
  396. $('#reportrange span').html(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
  397. });
  398. $('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD 00:00:00") + ' - ' + moment().subtract(1, 'days').format("YYYY-MM-DD 23:59:59"));
  399. }