drug_in_out_count.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //@ sourceURL=drug_in_out_count.js
  2. var LODOP; //声明为全局变量
  3. var groupYk = window.localStorage["groupYk"];
  4. $(function () {
  5. if (groupYk == null) {
  6. return errorMesageSimaple('药库参数未设置,请在发药参数设置中设置');
  7. }
  8. init_daterangepicker();
  9. setTimeout(function () {
  10. getLodop();
  11. }, 800);
  12. $("#kind_table").hide();
  13. $("#class_sum_table").hide();
  14. $(".selectpicker").selectpicker({
  15. dropuAuto: false
  16. });
  17. //初始化页面上面的按钮事件
  18. $("#btn_search").click(function (t) {
  19. $('.sjh').remove();
  20. getRecordData();
  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 statisticalMethod = $("#statisticalMethod").val();
  30. let id = "";
  31. if (statisticalMethod === "0") {
  32. id = 'sum_table';
  33. } else if (statisticalMethod === "2") {
  34. id = 'class_sum_table';
  35. } else {
  36. id = 'kind_table';
  37. }
  38. $("#" + id).table2excel({
  39. exclude: ".exclHide",
  40. filename: $("#" + id + " .title").html() + "(" + getRePortRangeArr()[0].substring(0, getRePortRangeArr()[0].indexOf(" ") + 1) + ").xls"
  41. })
  42. });
  43. $("#statisticalMethod").change(function (t, d, e) {
  44. let statisticalMethod = $("#statisticalMethod").val();
  45. if (statisticalMethod === "0") {
  46. $("#sum_table").show();
  47. $("#kind_table").hide();
  48. $("#class_sum_table").hide();
  49. }else if (statisticalMethod === "2") {
  50. $("#sum_table").hide();
  51. $("#kind_table").hide();
  52. $("#class_sum_table").show();
  53. } else {
  54. $("#kind_table").show();
  55. $("#sum_table").hide();
  56. $("#class_sum_table").hide();
  57. }
  58. $(".dateRange").html($('#reportrange span').html());
  59. $(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
  60. });
  61. });
  62. /**
  63. * 获取汇总药品统计报表
  64. */
  65. function getRecordData() {
  66. let statisticalMethod = $('#statisticalMethod').val();
  67. let data = {
  68. 'beginDate': getRePortRangeArr()[0],
  69. 'endDate': getRePortRangeArr()[1],
  70. 'flag': statisticalMethod,
  71. 'groupNo': groupYk,
  72. };
  73. $('#YWaitDialog').css('top', $('.xtd').offset().top);
  74. $('#YWaitDialog').show();
  75. $(".dateRange").html($('#reportrange span').html());
  76. $(".groupName").html(getGroupName(groupYk));
  77. $(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
  78. $.ajax({
  79. type: "POST",
  80. url: '/thmz/getDrugMoneyCount',
  81. contentType: "application/json;charset=UTF-8",
  82. dataType: "json",
  83. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  84. data: JSON.stringify(data),
  85. success: function (res) {
  86. $('#YWaitDialog').hide();
  87. if (res == '401' || res == 401) {
  88. window.location.href = '/thmz/login/view'
  89. return;
  90. }
  91. if (res.code == 0) {
  92. let html = '';
  93. let totalInMoneyBuy = 0;
  94. let totalInMoneyRet = 0;
  95. let totalOutMoneyRet = 0;
  96. for (var i = 0; i < res.data.length; i++) {
  97. let data = res.data[i];
  98. let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
  99. let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
  100. let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
  101. if (statisticalMethod == 0) {
  102. html += '<tr class="sjh">';
  103. html += '<td class="xtd" style="text-align: center;">' + (i + 1) + '</td>';
  104. html += '<td class="xtd" style="text-align: center;">' + data.countDate + '</td>';
  105. html += '<td class="xtd" style="text-align: right;">' + inMoneyBuy + '</td>';
  106. html += '<td class="xtd" style="text-align: right;">' + inMoneyRet + '</td>';
  107. html += '<td class="xtd" style="text-align: right;">' + outMoneyRet + '</td>';
  108. html += '</tr>';
  109. totalInMoneyBuy += inMoneyBuy;
  110. totalInMoneyRet += inMoneyRet;
  111. totalOutMoneyRet += outMoneyRet;
  112. }else if (statisticalMethod == 2) {
  113. let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
  114. let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
  115. let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
  116. html += '<tr class="sjh">';
  117. html += '<td colspan="2" class="xtd" style="text-align: left;">' + data.kindName + '</td>';
  118. html += '<td class="xtd" style="text-align: right;">' + inMoneyBuy + '</td>';
  119. html += '<td class="xtd" style="text-align: right;">' + inMoneyRet + '</td>';
  120. html += '<td class="xtd" style="text-align: right;">' + outMoneyRet + '</td>';
  121. html += '</tr>';
  122. totalInMoneyBuy += inMoneyBuy;
  123. totalInMoneyRet += inMoneyRet;
  124. totalOutMoneyRet += outMoneyRet
  125. } else {
  126. let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
  127. let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
  128. html += '<tr class="sjh">';
  129. html += '<td class="xtd" style="text-align: left;">' + data.name + '</td>';
  130. html += '<td class="xtd" style="text-align: right;">' + inMoneyBuy + '</td>';
  131. html += '<td class="xtd" style="text-align: right;">' + inMoneyRet + '</td>';
  132. totalInMoneyRet += inMoneyBuy;
  133. totalOutMoneyRet += inMoneyRet
  134. }
  135. }
  136. if (statisticalMethod == 0 || statisticalMethod == 2) {
  137. html += '<tr class="sjh">';
  138. html += '<td colspan="2" style="text-align: right;font-weight: 700;">总计:</td>';
  139. html += '<td style="text-align: right;">' + keepTwoDecimal(totalInMoneyBuy) + '</td>';
  140. html += '<td style="text-align: right;">' + keepTwoDecimal(totalInMoneyRet) + '</td>';
  141. html += '<td style="text-align: right;">' + keepTwoDecimal(totalOutMoneyRet) + '</td>';
  142. html += '</tr>';
  143. }else{
  144. html += '<tr class="sjh">';
  145. html += '<td style="text-align: right;font-weight: 700;">总计:</td>';
  146. html += '<td style="text-align: right;">' + keepTwoDecimal(totalInMoneyRet) + '</td>';
  147. html += '<td style="text-align: right;">' + keepTwoDecimal(totalOutMoneyRet) + '</td>';
  148. html += '</tr>';
  149. }
  150. if (statisticalMethod == 0) {
  151. $("#sum_table").append(html);
  152. }else if (statisticalMethod == 2) {
  153. $("#class_sum_table").append(html);
  154. }else {
  155. $("#kind_table").append(html);
  156. }
  157. } else if (res.code == -1) {
  158. new PNotify({
  159. title: '错误提示',
  160. text: res.message,
  161. type: 'error',
  162. hide: true,
  163. styling: 'bootstrap3'
  164. });
  165. }
  166. }
  167. });
  168. }
  169. /**
  170. * 获取时间选择器的时间数组
  171. * @returns {string[]}
  172. */
  173. function getRePortRangeArr() {
  174. var rePortRange = $('#reportrange span').html();
  175. var rePortRangeArr = rePortRange.split(" - ");
  176. return rePortRangeArr;
  177. }
  178. /**
  179. * 清空查询条件
  180. */
  181. function cleanParams() {
  182. $("#statisticalMethod").val(0);
  183. $('#statisticalMethod').selectpicker('refresh');
  184. $('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD") + ' - ' + moment().subtract(1, 'days').format("YYYY-MM-DD"));
  185. $('#sum_table').show();
  186. $('#kind_table').hide();
  187. $('#class_sum_table').hide();
  188. $('.sjh').remove();
  189. }
  190. /**
  191. * 打印报表
  192. */
  193. function print() {
  194. setDefaultPrint();
  195. LODOP = getLodop();
  196. LODOP.PRINT_INITA(6, 0, "210mm", "297mm", "药品出入库统计表");
  197. LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
  198. //设置默认打印机
  199. LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
  200. LODOP.SET_PRINT_STYLE("FontSize", 10); //字体大小
  201. LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
  202. //设置默认打印机
  203. LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
  204. LODOP.ADD_PRINT_TEXT('285mm', '100mm', '40mm', '40mm', '第#页/共&页');
  205. LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
  206. var strStyle = "<style>table,td,th {border-width: 1px;" +
  207. "border-style: solid;border-collapse: collapse;table-layout:fixed;word-wrap:break-word;font-size: 14px}</style>";
  208. LODOP.ADD_PRINT_HTM("2mm", "4mm", "RightMargin:4mm", "BottomMargin:15mm", strStyle + document.getElementById("report_table_1").innerHTML);
  209. LODOP.PRINT();
  210. //LODOP.PREVIEW();
  211. }