drug_delivery.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. //@ sourceURL=drug_delivery.js
  2. var groupNo = window.localStorage["groupYk"];//药房编码
  3. var outDetlList = [];//出库数据集
  4. var delDetlList = [];//删除出库数据集
  5. $(function () {
  6. init_daterangepicker();
  7. $('.datetime').datetimepicker({
  8. language: 'zh-CN',
  9. format: 'yyyy-mm-dd',
  10. autoclose: true,
  11. minView: 2,
  12. startView: 2,
  13. });
  14. initDetailed();
  15. initInDetlDetailed();
  16. initDynamicSelect("allUnitCode",'deptCode');
  17. initSearchList('<div id="medicinePopoverContent"><table id="tb_table_medicine"></table></div>',
  18. 'drugName', 600, 250);
  19. $('#drugName').on('input focus', function (e) {
  20. showDrugPopover({
  21. method: 'POST',
  22. data: JSON.stringify({
  23. searchText: $("#drugName").val() == "" ? null : $("#drugName").val(),
  24. groupNo: groupNo,
  25. delFlag: 0
  26. }),
  27. url: '/thmz/getYpZdDictBase',
  28. columns: [
  29. {
  30. field: 'stockAmount',
  31. title: '库存',
  32. align: "center",
  33. valign: 'middle',
  34. formatter: function (value, row, index) {
  35. return value.toFixed(0);
  36. }
  37. }, {
  38. field: 'jbFlag',
  39. title: '基本药物',
  40. align: "center",
  41. valign: 'middle',
  42. formatter: function (cellvalue, options, rowObject) {
  43. return cellvalue === '1' ? '国家基本药物' : '';
  44. }
  45. }],
  46. onClickRow: function (row, $element) {
  47. if($("#statusLabel").html() === '未审核'){
  48. warningMesageSimaple('出库单已确认,请另起一张新的出库单');
  49. return;
  50. }
  51. let dataRow = {
  52. chargeCode: row['code'],
  53. name: row['name'],
  54. specification: row['specification'],
  55. packRetprice: row['packRetprice'],
  56. buyPrice: row['buyPrice'],
  57. amount: 0,
  58. amountOut: 0,
  59. amountOutMoney: 0,
  60. buyInMoney: 0,
  61. jbFlag: row['jbFlag'],
  62. nationalCode: row['nationalCode'],
  63. serial: row['serial']
  64. };
  65. addRowToLast("tb_table_detailed", dataRow);
  66. $('#drugName').webuiPopover('hide');
  67. $('#drugName').val('');
  68. }
  69. });
  70. });
  71. $('#buyAmt').on('input focus', function (e) {
  72. $("#buyValue").val((e.target.value * $("#buyPrice").val()).toFixed(2));
  73. });
  74. $('#buyPrice').on('input focus', function (e) {
  75. $("#buyValue").val((e.target.value * $("#buyAmt").val()).toFixed(2));
  76. });
  77. $('#reportrange span').html(moment().subtract(29, 'days').format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD'));
  78. $(".selectpicker").selectpicker();
  79. if (groupNo == null) {
  80. return errorMesageSimaple('药库参数未设置,请在药品管理参数设置中设置');
  81. }
  82. $("input").each(function () {
  83. this.onkeydown = function (e) { // 监听键盘事件
  84. let theEvent = window.event || e;
  85. let code = theEvent.keyCode || theEvent.which;
  86. if (code === 13) {//回车事件
  87. $("#btn_query").click(); //触发搜索按钮点击事件
  88. }
  89. }
  90. });
  91. $("#btn_query").click(function (t) {
  92. initRecordTable();
  93. });
  94. $("#btn_record").click(function () {
  95. $("#recordModal").modal("show");
  96. $('#reportrange span').html(moment().subtract(7, 'days').format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD'));
  97. $("#recordForm")[0].reset();
  98. $("#statusFlagSearch").selectpicker('refresh');
  99. initRecordTable();
  100. });
  101. $("#btn_save").on('click', function () {
  102. if(isEmpty($("#deptCode").val())){
  103. return errorMesageSimaple('领药科室为空!');
  104. }
  105. if ((outDetlList == null || outDetlList.length === 0) && (delDetlList == null || delDetlList.length === 0)) {
  106. return errorMesageSimaple('没有可保存数据!');
  107. }
  108. var data = $("#tb_table_detailed").jqGrid("getRowData");
  109. for (let i = 0; i < data.length; i++) {
  110. if (parseFloat(data[i].amountOut === '' ? 0 : data[i].amountOut) <= 0) {
  111. data[i].drawNo = $("#drawNoLabel").html();
  112. outDetlList.push(data[i])
  113. }
  114. }
  115. request({
  116. url: '/saveYpOutDetlList',
  117. method: 'POST',
  118. data: JSON.stringify({
  119. drawNo: $("#drawNoLabel").html(),
  120. list: outDetlList,
  121. delList: delDetlList,
  122. outType: $("#outType1Search").val(),
  123. deptCode: $("#deptCode").val()[0],
  124. groupNo:groupNo,
  125. editFlag: ($("#statusLabel").html() === '未审核')?1:0
  126. })
  127. }).then((res) => {
  128. $("#btn_clean").click();
  129. successMesage(res);
  130. });
  131. });
  132. $("#btn_audit").on('click', function () {
  133. if ($("#statusLabel").html() !== '已确认' && $("#statusLabel").html() !== '未审核') {
  134. return warningMesageSimaple('没有可审核的数据!');
  135. }
  136. if (!confirm("确定审核出库吗?(注意:审核后本张出库单将不能再修改)")) {
  137. return;
  138. }
  139. request({
  140. url: '/auditYpOutDetl',
  141. method: 'GET',
  142. data: {
  143. drawNo: $("#drawNoLabel").html()
  144. }
  145. }).then((res) => {
  146. $("#btn_clean").click();
  147. successMesage(res);
  148. });
  149. });
  150. $("#btn_daily").click(function (t) {
  151. setPrintHtml();
  152. });
  153. $("#btn_clean").on('click', function () {
  154. $("#deptCode").selectpicker('val', '');
  155. $("#deptCode").removeAttr('disabled');
  156. $("#deptCode").selectpicker('refresh');
  157. $("#drawNoLabel").text('');
  158. $("#planDateLabel").text('');
  159. $("#inputNameLabel").text('');
  160. $("#keeperNameLabel").text('');
  161. $("#confirmNameLabel").text('');
  162. $("#statusLabel").text('未确认');
  163. $("#xxform")[0].reset();
  164. $("#tb_table_indetl_detailed").jqGrid('clearGridData');
  165. $("#tb_table_detailed").jqGrid('clearGridData');
  166. outDetlList = [];
  167. delDetlList = [];
  168. });
  169. });
  170. /**
  171. * 查询列表
  172. */
  173. function initRecordTable() {
  174. let url = '/thmz/getYpInPlanPage';
  175. if ($("#statusFlagSearch").val() === '3' || $("#statusFlagSearch").val() === '4') {
  176. url = '/thmz/getYpOutDetlYk';
  177. }
  178. let statusFlagSearch = $("#statusFlagSearch").val();
  179. let isAudit = statusFlagSearch === "4";
  180. $('#tb_record').bootstrapTable('destroy');
  181. $('#tb_record').bootstrapTable({
  182. url: url, //请求后台的URL(*)
  183. method: 'POST', //请求方式(*)
  184. toolbar: '#toolbar', //工具按钮用哪个容器
  185. striped: true, //是否显示行间隔色
  186. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  187. pagination: true, //是否显示分页(*)
  188. sortable: true, //是否启用排序
  189. sortOrder: "asc", //排序方式
  190. queryParams: recordTableQueryParams, //传递参数(*)
  191. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  192. pageNumber: 1, //初始化加载第一页,默认第一页
  193. pageSize: 10, //每页的记录行数(*)
  194. pageList: [10, 20, 40, 100], //可供选择的每页的行数(*)
  195. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  196. strictSearch: true,
  197. showColumns: false, //是否显示所有的列
  198. showRefresh: false, //是否显示刷新按钮
  199. minimumCountColumns: 2, //最少允许的列数
  200. clickToSelect: true, //是否启用点击选中行
  201. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  202. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  203. cardView: false, //是否显示详细视图
  204. detailView: false,
  205. ajaxOptions: {
  206. headers: {
  207. 'Accept': 'application/json',
  208. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  209. }
  210. },
  211. columns: [
  212. {
  213. title: '操作',
  214. field: 'op',
  215. align: "center",
  216. valign: 'middle',
  217. formatter: function (value, row, index) {
  218. return '<button type="button" class="registration-no-color-foot-button" title="详细" onclick="getDetail(\'' + row.drawNo + '\')"><i class="fa fa-plus"></i></button>';
  219. }
  220. }, {
  221. field: 'planDate',
  222. title: '请领日期',
  223. align: "center",
  224. valign: 'middle',
  225. visible: statusFlagSearch === '1',
  226. formatter: function (value, row, index) {
  227. return format(value, "yyyy-MM-dd HH:mm:ss");
  228. }
  229. }, {
  230. field: 'outDate',
  231. title: '确认日期',
  232. align: "center",
  233. valign: 'middle',
  234. visible: statusFlagSearch === '3' || isAudit,
  235. formatter: function (value, row, index) {
  236. return format(value, "yyyy-MM-dd HH:mm:ss");
  237. }
  238. }, {
  239. field: 'confirmDate',
  240. title: '审核出库日期',
  241. align: "center",
  242. valign: 'middle',
  243. visible: isAudit,
  244. formatter: function (value, row, index) {
  245. return format(value, "yyyy-MM-dd HH:mm:ss");
  246. }
  247. }, {
  248. field: 'drawNo',
  249. title: '出库单号' ,
  250. align: "center",
  251. visible: (statusFlagSearch === '3' || isAudit),
  252. valign: 'middle'
  253. }, {
  254. field: 'drawYf',
  255. title: '请领单号',
  256. align: "center",
  257. valign: 'middle',
  258. formatter: function (value, row, index) {
  259. if(statusFlagSearch === '1'){
  260. return row.drawNo==null?"-":row.drawNo;
  261. }
  262. return value==null?"-":value;
  263. }
  264. }, {
  265. field: (statusFlagSearch === '3' || isAudit) ? 'groupNoOut' : 'groupNo',
  266. title: '申请库房',
  267. align: "center",
  268. valign: 'middle',
  269. formatter: function (value, row, index) {
  270. return getGroupName(value);
  271. }
  272. },
  273. {
  274. field: 'drawerName',
  275. title: '申请人',
  276. align: "center",
  277. valign: 'middle'
  278. },
  279. {
  280. field: 'keeperName',
  281. title: '经发人',
  282. align: "center",
  283. valign: 'middle',
  284. visible: (statusFlagSearch === '2' || statusFlagSearch === '3' || isAudit)
  285. },
  286. {
  287. field: 'confirmName',
  288. title: '审核人',
  289. align: "center",
  290. valign: 'middle',
  291. visible: (statusFlagSearch === '3' || isAudit)
  292. },
  293. {
  294. field: (statusFlagSearch === '3' || isAudit) ? 'groupNo' : 'groupYk',
  295. title: '发药库房',
  296. align: "center",
  297. valign: 'middle',
  298. formatter: function (value, row, index) {
  299. return getGroupName(value);
  300. }
  301. }
  302. ],
  303. onDblClickRow: function (row) {
  304. getDetail(row.drawNo);
  305. },
  306. responseHandler: function (res) {
  307. if (res == '401' || res == 401) {
  308. window.location.href = '/thmz/login/view';
  309. return;
  310. }
  311. var ress = eval(res);
  312. if (ress.code == -1) {
  313. errorMesage(res);
  314. return {
  315. "total": 0,//总页数
  316. "rows": {} //数据
  317. };
  318. }
  319. return {
  320. "total": ress.total,//总页数
  321. "rows": ress.data //数据
  322. };
  323. }
  324. });
  325. }
  326. function getDetail(drawNo) {
  327. $("#statusLabel").html($("#statusFlagSearch option:checked").text());
  328. $("#recordModal").modal("hide");
  329. $("#tb_table_indetl_detailed").jqGrid("clearGridData");
  330. loadDetailed(drawNo);
  331. }
  332. function recordTableQueryParams(params) {
  333. let rePortRangeArr = getRePortRangeArr();
  334. let temp = {
  335. drawNo: $("#drawNoSearch").val() === '' ? null : $("#drawNoSearch").val(),
  336. beginTime: rePortRangeArr[0],
  337. endTime: rePortRangeArr[1],
  338. pageSize: params.limit, //页面大小
  339. pageIndex: params.offset / params.limit //页码
  340. };
  341. if ($("#statusFlagSearch").val() === '3' || $("#statusFlagSearch").val() === '4') {
  342. temp.confirmFlag = $("#statusFlagSearch").val() === '3' ? '0' : '1';
  343. temp.outType = '0,1';
  344. temp.groupNo = groupNo;
  345. } else {
  346. temp.statusFlag = $("#statusFlagSearch").val();
  347. temp.groupYk = groupNo
  348. }
  349. return JSON.stringify(temp);
  350. }
  351. /**
  352. * 加载详细表格数据
  353. * @param inDocuNo
  354. */
  355. function loadDetailed(drawNo) {
  356. let url = '/thmz/getYpInPlanDrugYk';
  357. if ($("#statusFlagSearch").val() === '3' || $("#statusFlagSearch").val() === '4') {
  358. url = '/thmz/getYpOutDetlDrugYk';
  359. }
  360. $("#tb_table_detailed").jqGrid('setGridParam', {
  361. datatype: 'JSON',
  362. url: url,
  363. postData: {drawNo: drawNo}
  364. }).trigger('reloadGrid');
  365. }
  366. /**
  367. * 加载详细表格数据
  368. * @param inDocuNo
  369. */
  370. function loadInDetlDetailed(data) {
  371. $("#tb_table_indetl_detailed").jqGrid('setGridParam', {
  372. datatype: 'JSON',
  373. postData: JSON.stringify({
  374. currentStock: 0.0,
  375. chargeCode: data.chargeCode,
  376. serial: data.serial,
  377. groupNo: groupNo,
  378. drawNo: data.drawNo
  379. })
  380. }).trigger('reloadGrid');
  381. }
  382. /**
  383. * 初始化药品入库详细表格
  384. */
  385. function initInDetlDetailed() {
  386. $.jgrid.gridUnload("tb_table_indetl_detailed");
  387. $("#tb_table_indetl_detailed").jqGrid({
  388. datatype: 'local',
  389. mtype: 'POST',
  390. url: '/thmz/getYpInDetl',
  391. loadBeforeSend: function (jqXHR) {
  392. jqXHR.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  393. jqXHR.setRequestHeader("Accept", 'application/json;charset=UTF-8');
  394. jqXHR.setRequestHeader("Content-Type", 'application/json;charset=UTF-8');
  395. },
  396. ajaxCellOptions: {
  397. beforeSend: function (XMLHttpRequest) {
  398. XMLHttpRequest.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  399. }
  400. },
  401. height: screen.height * 0.15,
  402. styleUI: 'Bootstrap',
  403. autowidth: true,
  404. autoScroll: true,
  405. shrinkToFit: true,
  406. rowNum: -1,//取消分页
  407. caption: '入库记录',
  408. cellEdit: true,
  409. sortable: false,
  410. loadonce: false, //一次加载全部数据到客户端,由客户端进行排序。
  411. cellsubmit: "clientArray",
  412. colNames: ['入库日期', '入库数量', '购入价', '供应商', '生产厂家', '效期', '入库单号', '现时库存', '出库量', '生产批号', '入库序号', '药品编码', 'serial'],
  413. colModel: [
  414. {
  415. name: 'inDate', index: 'inDate', align: 'center', width: 100,
  416. formatter: function (cellvalue, options, rowObject) {
  417. return cellvalue == null ? "" : format(cellvalue, "yyyy-MM-dd");
  418. }
  419. },
  420. {name: 'buyAmt', index: 'buyAmt', align: 'center', width: 100},
  421. {name: 'buyPrice', index: 'buyPrice', align: 'center', width: 100},
  422. {name: 'supplyName', index: 'supplyName', align: 'left', width: 160},
  423. {name: 'manufactoryName', index: 'manufactoryName', align: 'left', width: 160},
  424. {
  425. name: 'effDate', index: 'effDate', align: 'center', width: 120,
  426. formatter: function (cellvalue, options, rowObject) {
  427. return cellvalue == null ? "" : format(cellvalue, "yyyy-MM-dd");
  428. }
  429. },
  430. {name: 'inDocuNo', index: 'inDocuNo', align: 'center', width: 100},
  431. {
  432. name: 'currentStock', index: 'currentStock', align: 'center', width: 100,
  433. formatter: function (cellvalue, options, rowObject) {
  434. return keepTwoDecimal(cellvalue)
  435. }
  436. },
  437. {
  438. name: 'amountOut', index: 'amountOut', align: 'center', width: 100, editable: true, edittype: 'text'
  439. , editrules: {edithidden: true, number: true, minValue: 0},
  440. formatter: function (cellvalue, options, rowObject) {
  441. if (parseFloat(rowObject.currentStock) < parseFloat(cellvalue)) {
  442. warningMesageSimaple("出库量不允许大于现时库存!");
  443. return '';
  444. }
  445. return isEmpty(cellvalue) ? 0 : cellvalue;
  446. }
  447. },
  448. {name: 'manuNo', index: 'manuNo', align: 'center', width: 100},
  449. {name: 'inSeri', index: 'inSeri', align: 'center', hidden: true},
  450. {name: 'chargeCode', index: 'chargeCode', align: 'center'},
  451. {name: 'serial', index: 'serial', align: 'center', hidden: true}
  452. ],
  453. jsonReader: {
  454. root: "data", repeatitems: false
  455. },
  456. beforeSubmitCell: function (rowid, cellname, cellvalue, iRow, iCol) {
  457. let rowId = $("#tb_table_detailed").jqGrid("getGridParam", "selrow");
  458. var rowData = $("#tb_table_detailed").jqGrid('getRowData', rowId);
  459. var data = $("#tb_table_indetl_detailed").jqGrid("getRowData");
  460. let amountOut = 0;//总出库量
  461. for (let j = 0; j < data.length; j++) {
  462. let rowObject = data[j];
  463. for (let i = 0; i < outDetlList.length; i++) {
  464. let data = outDetlList[i];
  465. if (data.inSeri === rowObject.inSeri && data.inDocuNo === rowObject.inDocuNo && data.chargeCode === rowObject.chargeCode && data.manuNo === rowObject.manuNo) {
  466. outDetlList.splice(i, 1);
  467. break;
  468. }
  469. }
  470. rowObject.drawNo = rowData.drawNo;
  471. if(rowid == (j+1)){
  472. rowObject.amountOut = cellvalue == '' ? 0 : parseFloat(cellvalue);
  473. }
  474. outDetlList.push(rowObject);
  475. if (rowObject.amountOut.length > 10) {
  476. amountOut += rowObject.amountOut;
  477. } else {
  478. amountOut += parseFloat(rowObject.amountOut == '' ? 0 : rowObject.amountOut)
  479. }
  480. }
  481. $("#tb_table_detailed").jqGrid('setCell', rowId, "amountOut", amountOut);
  482. $("#tb_table_detailed").jqGrid('setCell', rowId, "amountOutMoney", keepTwoDecimal(amountOut * parseFloat(rowData.packRetprice)));
  483. $("#tb_table_detailed").jqGrid('setCell', rowId, "buyInMoney", keepTwoDecimal(amountOut * parseFloat(rowData.buyPrice)));
  484. $("#tb_table_detailed").jqGrid('setCell', rowId, "inSeri", rowData.inSeri);
  485. var rowNum=parseInt($("#tb_table_detailed").getGridParam("records"),20);//获取行数
  486. if(rowNum>0){
  487. $(".ui-jqgrid-sdiv").show();
  488. let amountOutMoney=$("#tb_table_detailed").getCol("amountOutMoney",false,"sum");//需要统计的列
  489. let buyInMoney=$("#tb_table_detailed").getCol("buyInMoney",false,"sum");
  490. $("#tb_table_detailed").footerData("set",{"amountOut":"合计","amountOutMoney":keepTwoDecimal(amountOutMoney),"buyInMoney":keepTwoDecimal(buyInMoney)}); //将合计值显示出来
  491. }else{
  492. $(".ui-jqgrid-sdiv").hide();
  493. }
  494. },
  495. loadComplete: function (res) { //加载完成(初始加载),回调函数
  496. if (res == '401' || res == 401) {
  497. window.location.href = '/thmz/login/view';
  498. return;
  499. }
  500. if (res.code == -1) {
  501. errorMesage(res);
  502. }
  503. }
  504. });
  505. }
  506. /**
  507. * 初始化详细表格
  508. */
  509. function initDetailed() {
  510. let selectRowId;//选中的行号
  511. $.jgrid.gridUnload("tb_table_detailed");
  512. $("#tb_table_detailed").jqGrid({
  513. datatype: 'local',
  514. mtype: 'GET',
  515. url: url,
  516. loadBeforeSend: function (jqXHR) {
  517. jqXHR.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  518. jqXHR.setRequestHeader("Accept", 'application/json');
  519. },
  520. ajaxCellOptions: {
  521. beforeSend: function (XMLHttpRequest) {
  522. XMLHttpRequest.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  523. }
  524. },
  525. height: screen.height * 0.3,
  526. toolbar: [true, "top"],
  527. styleUI: 'Bootstrap',
  528. autowidth: true,
  529. autoScroll: true,
  530. shrinkToFit: true,
  531. rowNum: -1,//取消分页
  532. caption: '请领单明细',
  533. cellEdit: false,
  534. sortable: false,
  535. loadonce: false, //一次加载全部数据到客户端,由客户端进行排序。
  536. footerrow:true,//设置属性,显示统计行
  537. cellsubmit: "remote",
  538. colNames: ['单号', '药品编码', '药品名称', '规格', '零售价', '购入价', '请领数量', '出库量', '金额', '购入金额', '基本药物', '药品国家医保编码', 'serial'],
  539. colModel: [
  540. {name: 'drawNo', index: 'drawNo', align: 'center'},
  541. {name: 'chargeCode', index: 'chargeCode', align: 'center'},
  542. {name: 'name', index: 'name', align: 'left'},
  543. {name: 'specification', index: 'specification', align: 'left'},
  544. {name: 'packRetprice', index: 'packRetprice', align: 'center'},
  545. {name: 'buyPrice', index: 'buyPrice', align: 'center'},
  546. {name: 'amount', index: 'amount', align: 'center'},
  547. {
  548. name: 'amountOut', index: 'amountOut', align: 'center',
  549. formatter: function (cellvalue, options, rowObject) {
  550. return cellvalue === null ? '' : '<span style="color: red">' + cellvalue + '</span>'
  551. }
  552. },
  553. {
  554. name: 'amountOutMoney', index: 'amountOutMoney', align: 'center',
  555. formatter: function (cellvalue, options, rowObject) {
  556. if(!isEmpty(cellvalue) && cellvalue+"".indexOf("span") != -1){
  557. return cellvalue;
  558. }
  559. return keepTwoDecimal((isEmpty(rowObject.amount) ? rowObject.outAmt : rowObject.amountOut) * rowObject.packRetprice);
  560. }
  561. },
  562. {
  563. name: 'buyInMoney', index: 'buyInMoney', align: 'center',
  564. formatter: function (cellvalue, options, rowObject) {
  565. if(!isEmpty(cellvalue) && cellvalue+"".indexOf("span") != -1){
  566. return cellvalue;
  567. }
  568. return keepTwoDecimal((isEmpty(rowObject.amount) ? rowObject.outAmt : rowObject.amountOut) * rowObject.buyPrice);
  569. }
  570. },
  571. {
  572. name: 'jbFlag', index: 'jbFlag', align: 'center',
  573. formatter: function (cellvalue, options, rowObject) {
  574. return cellvalue === '1' ? '国家基本药物' : '';
  575. }
  576. },
  577. {name: 'nationalCode', index: 'nationalCode', align: 'center'},
  578. {name: 'serial', index: 'serial', hidden: true}
  579. ],
  580. jsonReader: {
  581. root: "data", repeatitems: false
  582. },
  583. onCellSelect: function (rowid, iCol, cellcontent, e) {
  584. selectRowId = rowid;
  585. loadInDetlDetailed($("#tb_table_detailed").getRowData(rowid));
  586. },
  587. gridComplete:function(){
  588. var rowNum=parseInt($(this).getGridParam("records"),20);//获取行数
  589. if(rowNum>0){
  590. $(".ui-jqgrid-sdiv").show();
  591. let amountOutMoney=$(this).getCol("amountOutMoney",false,"sum");//需要统计的列
  592. let buyInMoney=$(this).getCol("buyInMoney",false,"sum");
  593. $(this).footerData("set",{"amountOut":"合计","amountOutMoney":keepTwoDecimal(amountOutMoney),"buyInMoney":keepTwoDecimal(buyInMoney)}); //将合计值显示出来
  594. }else{
  595. $(".ui-jqgrid-sdiv").hide();
  596. }
  597. },
  598. loadComplete: function (res) { //加载完成(初始加载),回调函数
  599. if (res.data != null && res.data.length > 0) {
  600. $("#xxform")[0].reset();
  601. let data = res.data[0];
  602. let no = "<span id=\"drawNoLabel\" style='color: green'>" + data['drawNo'] + "</span>";
  603. if ($("#statusFlagSearch").val() === '3' || $("#statusFlagSearch").val() === '4') {
  604. $("#planDateLabel").text(format(data['outDate'], "yyyy-MM-dd HH:mm"));
  605. $("label[for='drawNoLabel']")[0].innerHTML = "出库单号:" + no;
  606. $("#groupNoLabel").val(getGroupName(data['groupNoOut']));
  607. } else {
  608. $("#planDateLabel").text(format(data['planDate'], "yyyy-MM-dd HH:mm"));
  609. $("label[for='drawNoLabel']")[0].innerHTML = "请领单号:" + no;
  610. $("#groupNoLabel").val(getGroupName(data['groupNo']));
  611. }
  612. $("#deptCode").selectpicker('val', data['deptCode']);
  613. $("#deptCode").attr('disabled', true);
  614. $("#deptCode").selectpicker('refresh');
  615. $("#inputNameLabel").text(data['inputName']);
  616. $("#confirmNameLabel").text(data['confirmName']);
  617. $("#keeperNameLabel").text(data['keeperName']);
  618. }
  619. if (res == '401' || res == 401) {
  620. window.location.href = '/thmz/login/view';
  621. return;
  622. }
  623. if (res.code == -1) {
  624. errorMesage(res);
  625. }
  626. }
  627. });
  628. $("#t_tb_table_detailed").append("<button class='registration-no-color-foot-button' title='删除药品' id='remove' style='color: red;margin-left: 10px;'><i class='fa fa-trash-o'></i></button>");
  629. $("#t_tb_table_detailed").append("<input id='drugName' name='drugName' type='text' style='margin-left: 10px;' placeholder='添加药品...'>");
  630. $("#remove").on('click', function () {
  631. if (selectRowId == null) {
  632. return warningMesageSimaple('请选择一行进行删除!');
  633. }
  634. let selectRowData = $("#tb_table_detailed").jqGrid("getRowData", selectRowId);
  635. if(!isEmpty(selectRowData.drawNo)){
  636. delDetlList.push(selectRowData);
  637. }
  638. for (let i = 0; i < outDetlList.length; i++) {
  639. if(outDetlList[i].chargeCode == selectRowData.chargeCode && outDetlList[i].serial == selectRowData.serial){
  640. outDetlList.splice(i, 1);
  641. break;
  642. }
  643. }
  644. $("#tb_table_detailed").jqGrid("delRowData", selectRowId);
  645. selectRowId = null;
  646. });
  647. }
  648. /**
  649. * 生产报表数据
  650. */
  651. function setPrintHtml() {
  652. let date = {drawNo: $("#drawNoLabel").text()};
  653. request({
  654. url: '/getYpOutDetlPrint',
  655. method: 'POST',
  656. data: JSON.stringify(date)
  657. }).then((res) => {
  658. let html = '';
  659. let packRetpriceSum = 0;
  660. let buyPriceSum = 0;
  661. $('.sjh').remove();
  662. for (let i = 0; i < res['data'].length; i++) {
  663. let data = res['data'][i];
  664. let packRetprice = keepTwoDecimal(parseFloat(data['outAmt']) * parseFloat(data['packRetprice']));
  665. let buyPrice = keepTwoDecimal(parseFloat(data['outAmt']) * parseFloat(data['buyPrice']));
  666. packRetpriceSum += packRetprice;
  667. buyPriceSum += buyPrice;
  668. if (i === 0) {
  669. $(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
  670. let w_code = $("#deptCode").find("option:selected").text();
  671. $(".groupName").html(w_code.substring(0, w_code.lastIndexOf("(")));
  672. $(".drawNo").html(data['drawNo']);
  673. $(".planDate").html($("#planDateLabel").html());
  674. $(".confirmDate").html(format(data['confirmDate'], "yyyy-MM-dd HH:mm"));
  675. $(".lister").html($(".current_user")[0].innerText);
  676. $(".listerAudit").html(data['confirmName']);
  677. }
  678. if(data['outAmt'] != 0) {
  679. html += '<tr class="sjh">';
  680. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + data['chargeCode'] + '</td>';
  681. html += '<td style="text-align: center; border: 1px solid black;" width="8%;">' + data['location'] + '</td>';
  682. html += '<td style="text-align: left; border: 1px solid black;" width="13%;">' + data['name'] + '</td>';
  683. html += '<td style="text-align: left; border: 1px solid black;" width="12%;">' + data['specification'] + '</td>';
  684. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + data['outAmt'] + '</td>';
  685. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + data['buyPrice'] + '</td>';
  686. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + data['packRetprice'] + '</td>';
  687. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + buyPrice + '</td>';
  688. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + packRetprice + '</td>';
  689. html += '<td style="text-align: center; border: 1px solid black;" width="8%;">' + data['manuNo'] + '</td>';
  690. html += '<td style="text-align: left; border: 1px solid black;" width="13%;">' + data['manufactoryName'] + '</td>';
  691. html += '<td style="text-align: center; border: 1px solid black;" width="10%;">' + format(data['effDate'], "yyyy-MM-dd") + '</td>';
  692. html += '<td style="text-align: center; border: 1px solid black;" width="5%;">' + keepTwoDecimal(data['stockAmount']) + '</td>';
  693. html += '</tr>';
  694. }
  695. }
  696. html += '<tr class="sjh" style="border:0;border-top:2px solid #fff;overflow:hidden;font-size: 13px;">';
  697. html += '<td colspan="6" style="text-align: right;border: transparent !important;font-weight: bold;"></td>';
  698. html += '<td colspan="4" style="text-align: right;border: transparent !important;font-weight: bold;">合计:零售总额:<span class="packRetpriceSum"></span></td>';
  699. html += '<td colspan="2" style="text-align: right;border: transparent !important;font-weight: bold;">购入总额:<span class="buyPriceSum"></span></td></tr>';
  700. $("#print-body").after(html);
  701. $(".packRetpriceSum").html(keepTwoDecimal(packRetpriceSum));
  702. $(".buyPriceSum").html(keepTwoDecimal(buyPriceSum));
  703. print();
  704. });
  705. }
  706. /**
  707. * 打印报表
  708. */
  709. function print() {
  710. setDefaultPrint();
  711. LODOP = getLodop();
  712. LODOP.PRINT_INITA(6, 0, "226mm", "280mm", "出库单打印");
  713. //设置默认打印机
  714. LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
  715. LODOP.SET_PRINT_STYLE("FontSize", 11); //字体大小
  716. LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
  717. LODOP.SET_SHOW_MODE("BKIMG_WIDTH", "297mm");
  718. LODOP.SET_SHOW_MODE("BKIMG_HEIGHT", "210mm");
  719. var strStyle = "<style>table,td,th {border-width: 1px;padding-bottom:0px;" +
  720. "border-style: solid;border-collapse: collapse;table-layout:fixed;word-wrap:break-word;font-size: 13}</style>";
  721. LODOP.ADD_PRINT_TABLE(138, "2%", "95%", 830, strStyle+document.getElementById("print-table").innerHTML);
  722. LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
  723. LODOP.ADD_PRINT_HTM(12, "2%", "95%", 154, document.getElementById("print-head").innerHTML);
  724. LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
  725. LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
  726. LODOP.ADD_PRINT_HTM(980, "2%", "95%", 54, document.getElementById("print-foot").innerHTML);
  727. LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
  728. LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
  729. LODOP.PRINT();
  730. // LODOP.PREVIEW();
  731. }
  732. //最后一行新增数据
  733. function addRowToLast(gridID, dataRow) {
  734. var ids = jQuery("#" + gridID).jqGrid('getDataIDs');
  735. if (ids.length == 0) {
  736. ids = [0];
  737. }
  738. //获得当前最大行号(数据编号)
  739. var rowid = Math.max.apply(Math, ids);
  740. //获得新添加行的行号(数据编号)
  741. var newrowid = rowid + 1;
  742. $("#" + gridID).jqGrid("addRowData", newrowid, dataRow, "last");
  743. return newrowid;
  744. }