west_pharmacy_dispensing.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. //@ sourceURL=west_pharmacy_dispensing.js
  2. var LODOP; //声明为全局变量
  3. var printIndex;
  4. var mzCfPrintIndex;
  5. var ekCfPrintIndex;
  6. var jzCfPrintIndex;
  7. $(function () {
  8. init_daterangepicker();
  9. initTable();
  10. $('#printStatusSearch').selectpicker('refresh');
  11. $('#dispensingStatusSearch').selectpicker('refresh');
  12. $("#btn_query").click(function (t) {
  13. initTable();
  14. });
  15. //重置查询参数
  16. $('#btn_clean').click(function () {
  17. cleanParams();
  18. });
  19. });
  20. /**
  21. * 自动打印和不自动打印按钮切换事件
  22. * @param object
  23. */
  24. function printFlgButtonChange(object) {
  25. $("#west_pharmacy_print_group").find("button").each(function (index, element) {
  26. if ($(element).hasClass("btn-primary")) {
  27. $(element).removeClass("btn-primary").addClass("btn-default");
  28. }
  29. });
  30. $(object).removeClass("btn-default").addClass("btn-primary");
  31. var index = getIndex("west_pharmacy_print_group");//获取当前按钮下标
  32. }
  33. /**
  34. * 获取按钮组选择的下标
  35. * @param id
  36. * @returns {number}
  37. */
  38. function getIndex(id) {
  39. var index = 0;
  40. var item = $("#" + id).find("button");
  41. for (var i = 0; i <= item.length; i++) {
  42. if ($(item[i]).hasClass("btn-primary")) {
  43. index = i;
  44. break;
  45. }
  46. }
  47. return index;
  48. }
  49. /**
  50. * 查询处方信息
  51. */
  52. function initTable() {
  53. $('#prescription_table').bootstrapTable("destroy");
  54. $('#prescription_table').bootstrapTable({
  55. url: '/thmz/listMzChargeOrder', //请求后台的URL(*)
  56. method: 'post', //请求方式(*)
  57. toolbar: '#toolbar', //工具按钮用哪个容器
  58. striped: true, //是否显示行间隔色
  59. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  60. pagination: true, //是否显示分页(*)
  61. sortable: true, //是否启用排序
  62. sortOrder: "asc", //排序方式
  63. queryParams: queryParams, //传递参数(*)
  64. sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
  65. pageNumber: 1, //初始化加载第一页,默认第一页
  66. pageSize: 10, //每页的记录行数(*)
  67. pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
  68. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  69. strictSearch: true,
  70. showColumns: false, //是否显示所有的列
  71. showRefresh: false, //是否显示刷新按钮
  72. minimumCountColumns: 2, //最少允许的列数
  73. clickToSelect: true, //是否启用点击选中行
  74. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  75. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  76. cardView: false, //是否显示详细视图
  77. detailView: false,
  78. //rowStyle:rowStyle,//通过自定义函数设置行样式
  79. ajaxOptions: {
  80. headers: {
  81. 'Accept': 'application/json',
  82. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  83. }
  84. },
  85. columns: [
  86. {
  87. field: 'no',
  88. title: '序号',
  89. align: "center",
  90. valign: 'middle',
  91. width: 40,
  92. formatter: function (value, row, index) {
  93. return index + 1;
  94. }
  95. }, {
  96. field: 'patientId',
  97. title: '病人ID',
  98. align: "center",
  99. valign: 'middle'
  100. }, {
  101. field: 'name',
  102. title: '病人姓名',
  103. align: "center",
  104. valign: 'middle'
  105. }, {
  106. field: 'realNo',
  107. title: '流水号',
  108. align: "center",
  109. valign: 'middle'
  110. }, {
  111. field: 'orderNo',
  112. title: '处方号',
  113. align: "center",
  114. valign: 'middle'
  115. }, {
  116. field: 'chargeDate',
  117. title: '缴费时间',
  118. align: "center",
  119. valign: 'middle',
  120. formatter: function (value, row, index) {
  121. return value == null ? "-" : format(value, "yyyy-MM-dd HH:mm:ss");
  122. }
  123. }, {
  124. title: '操作',
  125. field: 'op',
  126. align: "center",
  127. valign: 'middle',
  128. formatter: function (value, row, index) {
  129. var str = '<button type="button" class="registration-no-color-foot-button" title="打印" onclick="printPrescription(\'' + row.patientId + '\',\'' + row.times + '\')" style="color: #35D082;"><i class="fa fa-print"></i></button>';
  130. str += '<button type="button" class="registration-no-color-foot-button" title="配药完成" onclick="dispensingDispose(\'' + row.patientId + '\',\'' + row.orderNo + '\',\'' + row.name + '\',\'' + row.realNo + '\',\'' + row.chargeDate + '\')"><i class="fa fa-check-square-o"></i></button>';
  131. return str;
  132. }
  133. }
  134. ],
  135. responseHandler: function (res) {
  136. if (res == '401' || res == 401) {
  137. window.location.href = '/thmz/login/view'
  138. return;
  139. }
  140. var ress = eval(res);
  141. if (ress.code == -1) {
  142. if (ress.message != null && ress.message != '') {
  143. new PNotify({
  144. title: '错误提示',
  145. text: ress.message,
  146. type: 'error',
  147. hide: true,
  148. styling: 'bootstrap3'
  149. });
  150. }
  151. return {
  152. "total": 0,//总页数
  153. "rows": {} //数据
  154. };
  155. }
  156. return {
  157. "total": ress.data.length,//总页数
  158. "rows": ress.data //数据
  159. };
  160. },
  161. });
  162. }
  163. /**
  164. * 构建列表查询参数
  165. * @param params
  166. */
  167. function queryParams(params) {
  168. var rePortRangeArr = getRePortRangeArr();
  169. var temp = {
  170. /* pageSize: params.limit, //页面大小
  171. pageIndex: params.offset / params.limit, //页码*/
  172. beginTime: new Date(rePortRangeArr[0]),
  173. endTime: new Date(rePortRangeArr[1]),
  174. mzChargeDetail: {
  175. patientId: $("#patientIdSearch").val() == "" ? null : $("#patientIdSearch").val(),
  176. name: $("#nameSearch").val() == "" ? null : $("#nameSearch").val(),
  177. printFlag: $("#printStatusSearch").val() == "" ? null : $("#printStatusSearch").val(),
  178. confirmFlag: $("#dispensingStatusSearch").val() == "" ? null : $("#dispensingStatusSearch").val(),
  179. payMark: 0, //已收费
  180. groupNo: 71, //门诊西药房
  181. windowsNoYf: '04', //4号窗口
  182. groupType: '1' //西药
  183. }
  184. };
  185. return temp;
  186. };
  187. /**
  188. * 配药处理
  189. */
  190. function dispensingDispose(patientId, orderNo, name, realNo, chargeDate) {
  191. if (!confirm("确定要对当前处方进行配药处理吗?")) {
  192. return;
  193. }
  194. var tem = {
  195. "patientId": patientId,
  196. "orderNo": orderNo,
  197. "realNo": realNo,
  198. "chargeDate": chargeDate,
  199. "name": name
  200. }
  201. $.ajax({
  202. type: "POST",
  203. url: '/thmz/dispensingMedicineProcessing',
  204. contentType: "application/json;charset=UTF-8",
  205. dataType: "json",
  206. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  207. data: JSON.stringify(tem),
  208. success: function (res) {
  209. if (res == '401' || res == 401) {
  210. window.location.href = '/thmz/login/view'
  211. return;
  212. }
  213. if (res.code == 0) {
  214. successMesage(res);
  215. initTable();
  216. } else {
  217. errorMesage(res);
  218. }
  219. }
  220. });
  221. }
  222. /**
  223. * 打印处方
  224. */
  225. function printPrescription(patientId, times) {
  226. var tem = {
  227. patientId: patientId,
  228. times: times,
  229. groupNo: 71
  230. };
  231. $.ajax({
  232. type: "POST",
  233. url: '/thmz/getPrintPrescriptionData',
  234. contentType: "application/json;charset=UTF-8",
  235. dataType: "json",
  236. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  237. data: JSON.stringify(tem),
  238. success: function (res) {
  239. if (res == '401' || res == 401) {
  240. window.location.href = '/thmz/login/view'
  241. return;
  242. }
  243. if (res.code == 0) {
  244. successMesage(res);
  245. setPrint();//初始化默认打印机
  246. $('#print_view input').attr("value", "");
  247. if (null != res.data) {
  248. for (var key in res.data) {
  249. $("#" + key + "").attr("value", res.data[key]);
  250. }
  251. }
  252. var list = res.data.list;
  253. /*if (list[0].drugFlag == 2 || list[0].drugFlag == 3) {
  254. $('#drugFlag').attr("value", "麻、精一");
  255. } else if (list[0].drugFlag == 4) {
  256. $('#drugFlag').attr("value", "精二");
  257. }else */
  258. if(res.data.warnDeptName.indexOf("儿科") != -1){
  259. $('#drugFlag').attr("value", "儿科");
  260. printIndex = ekCfPrintIndex;
  261. }else if(res.data.warnDeptName.indexOf("急诊") != -1){
  262. $('#drugFlag').attr("value", "急诊");
  263. printIndex = jzCfPrintIndex;
  264. }else if(list[0].drugFlag == '' || list[0].drugFlag == null || list[0].drugFlag == 6){
  265. $('#drugFlag').attr("value", "普通");
  266. printIndex = mzCfPrintIndex;
  267. }
  268. $('#priceTime').attr("value", format(list[0].priceTime, "yyyy-MM-dd HH:mm"));
  269. $('#employeeName').attr("value", res.data.employeeName + "/" + res.data.employeeCode);
  270. if (res.data.sex == 1) {
  271. $('#sex').attr("value", '男');
  272. } else if (res.data.sex == 2) {
  273. $('#sex').attr("value", '女');
  274. } else {
  275. $('#sex').attr("value", '未知');
  276. }
  277. var tr = '';
  278. for (let i = 0; i < list.length; i++) {
  279. var number = i+1;
  280. let manufactoryName = list[i].manufactoryName == null || list[i].manufactoryName == '' ? '' : '(' + list[i].manufactoryName + ')';
  281. tr += '<tr>\n' +
  282. ' <td style="width: 10px;" align="left" valign="top">'+number+"." +
  283. '</td>\n' +
  284. ' <td style="vertical-align: middle !important;width: 260px;">\n' + list[i].drugName + manufactoryName +
  285. ' </td>\n' +
  286. ' <td style="vertical-align: middle !important;width: 120px;text-align: right;">' + list[i].specification +
  287. '</td>\n' +
  288. ' <td style="vertical-align: middle !important;width: 20px;text-align: right;">×</td>\n' +
  289. ' <td style="vertical-align: middle !important;width: 20px;text-align: right;">' + list[i].quantity +
  290. '</td>\n' +
  291. ' <td style="vertical-align: middle !important;width: 30px;text-align: right;">' + list[i].ypUnitName +
  292. '</td>\n' +
  293. ' </tr>\n' +
  294. ' <tr>\n' +
  295. ' <td colspan="5" style="vertical-align: middle !important;text-align: right;">用法:' + list[i].drugQuan + list[i].drugUnitName + '/次 ' + list[i].frequency + ' ' + list[i].printName +
  296. '</td>\n' +
  297. ' </tr>';
  298. }
  299. $('#tbody_yp').html(tr);
  300. if(list.length < 5){
  301. $('#yxwk').remove();
  302. $('#div_yp').append('<span id="yxwk">以下为空</span>');
  303. }
  304. LODOP = getLodop();
  305. LODOP.PRINT_INITA(6, 0, "141mm", "171mm", "泰和医院处方笺");
  306. LODOP.SET_PRINT_STYLE("FontSize", 9); //字体大小
  307. //设置默认打印机
  308. LODOP.SET_PRINTER_INDEX(printIndex);
  309. LODOP.SET_PRINT_PAGESIZE(1, '141mm', '171mm', "CreateCustomPage");
  310. LODOP.SET_SHOW_MODE("BKIMG_WIDTH", "141mm");
  311. LODOP.SET_SHOW_MODE("BKIMG_HEIGHT", "171mm");
  312. LODOP.SET_PRINT_MODE("CREATE_CUSTOM_PAGE_NAME", "门诊处方笺");//对新建的纸张重命名
  313. LODOP.ADD_PRINT_HTM("10mm", "5mm", "RightMargin:5mm","BottomMargin:5mm", $("div[id='print_view']").html());
  314. LODOP.PRINT();
  315. //LODOP.PREVIEW();
  316. } else {
  317. errorMesage(res);
  318. }
  319. }
  320. });
  321. }
  322. /**
  323. * 获取时间选择器的时间数组
  324. * @returns {string[]}
  325. */
  326. function getRePortRangeArr() {
  327. var rePortRange = $('#reportrange span').html();
  328. var rePortRangeArr = rePortRange.split(" - ");
  329. rePortRangeArr[0] = rePortRangeArr[0] + " 00:00:00"
  330. rePortRangeArr[1] = rePortRangeArr[1] + " 23:59:59"
  331. return rePortRangeArr;
  332. }
  333. /**
  334. * 清空查询条件
  335. */
  336. function cleanParams() {
  337. $('#reportrange span').html(moment().format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD'));
  338. $("#patientIdSearch").val(null);
  339. $("#nameSearch").val(null);
  340. $("#printStatusSearch").val(0);
  341. $("#dispensingStatusSearch").val(0);
  342. $("#printStatusSearch").selectpicker('refresh');
  343. $("#dispensingStatusSearch").selectpicker('refresh');
  344. }
  345. /**
  346. * 查询默认打印机
  347. */
  348. function setPrint() {
  349. if (mzCfPrintIndex >= 0 && ekCfPrintIndex >= 0 && jzCfPrintIndex >= 0) {
  350. return;
  351. }
  352. $.ajax({
  353. type: "GET",
  354. url: '/thmz/getLastDispensingWindowsByCurrentUser',
  355. contentType: "application/json;charset=UTF-8",
  356. dataType: "json",
  357. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  358. async: false,
  359. success: function (res) {
  360. if (res == '401' || res == 401) {
  361. window.location.href = '/thmz/login/view'
  362. return;
  363. }
  364. if (res.code == 0) {
  365. mzCfPrintIndex = res.data.mzCfPrintIndex;
  366. ekCfPrintIndex = res.data.ekCfPrintIndex;
  367. jzCfPrintIndex = res.data.jzCfPrintIndex;
  368. } else {
  369. mzCfPrintIndex = -1;
  370. ekCfPrintIndex = -1;
  371. jzCfPrintIndex = -1;
  372. }
  373. }
  374. });
  375. }
  376. var prescriptionPrintWebsocket = null;
  377. //判断当前浏览器是否支持WebSocket, 主要此处要更换为自己的地址
  378. if ('WebSocket' in window) {
  379. prescriptionPrintWebsocket = new WebSocket("ws://" + window.location.host + "/thmz/prescriptionPrintSocket/PY");
  380. } else {
  381. alert('Not support websocket')
  382. }
  383. //---------prescriptionPrintSocket start
  384. //连接发生错误的回调方法
  385. prescriptionPrintWebsocket.onerror = function () {
  386. console.log("配药连接prescriptionPrintSocket发生错误")
  387. };
  388. //连接成功建立的回调方法
  389. prescriptionPrintWebsocket.onopen = function (event) {
  390. console.log("配药连接prescriptionPrintSocket连接成功");
  391. }
  392. //接收到消息的回调方法
  393. prescriptionPrintWebsocket.onmessage = function (event) {
  394. var printStatus = $("#printStatusSearch").val();
  395. var dispensingStatus = $("#dispensingStatusSearch").val();
  396. var data = JSON.parse(event.data);
  397. if (data.type == 'JF') {//来自缴费成功后的消息
  398. if(printStatus == 0 && dispensingStatus == 0){
  399. initTable();
  400. }
  401. if($("#aotuPrint").is(':checked')){//自动打印
  402. printPrescription(data.patient_id, data.times);
  403. }
  404. }
  405. }
  406. //连接关闭的回调方法
  407. prescriptionPrintWebsocket.onclose = function () {
  408. console.log("配药连接prescriptionPrintSocket连接关闭");
  409. }
  410. //-----------prescriptionPrintSocket -end
  411. //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
  412. window.onbeforeunload = function () {
  413. prescriptionPrintWebsocket.close();
  414. }
  415. //关闭连接
  416. function closeWebSocket() {
  417. prescriptionPrintWebsocket.close();
  418. }