yf_special_mark.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. //@ sourceURL=yf_special_mark.js
  2. var pharmacyGroupNo = window.localStorage["groupNo"];//药房编码
  3. var chargeNo;//药品表选中的行号
  4. var batchNo;//批次表选中的行号
  5. $(function () {
  6. $(".selectpicker").selectpicker();
  7. //$("#pharmacyModal").modal("show");
  8. if(pharmacyGroupNo == null){
  9. return errorMesageSimaple('药房参数未设置,请在发药参数设置中设置');
  10. }
  11. initTable();
  12. initBatch();
  13. $('#btn_search').on('click',function(e){
  14. loadTbTable();
  15. });
  16. $('#searchText').on('blur',function(e){
  17. loadTbTable();
  18. });
  19. });
  20. /**
  21. * 查询列表
  22. */
  23. function initTable() {
  24. $.jgrid.gridUnload("tb_table");
  25. $("#tb_table").jqGrid({
  26. datatype: 'local',
  27. mtype: 'get',
  28. url: '/thmz/getYpSpecialMark',
  29. loadBeforeSend: function (jqXHR) {
  30. jqXHR.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  31. jqXHR.setRequestHeader("Accept", 'application/json');
  32. },
  33. ajaxCellOptions: {
  34. beforeSend: function (XMLHttpRequest) {
  35. XMLHttpRequest.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  36. }
  37. },
  38. styleUI: 'Bootstrap',
  39. viewrecords: true,
  40. autowidth: false,
  41. rowNum: -1,//取消分页
  42. height: screen.height*0.3,
  43. caption: '药品信息',
  44. shrinkToFit:false,
  45. autoScroll: false,
  46. cellEdit: true,
  47. cellsubmit: "remote",
  48. cellurl: '/thmz/modifYpSpecialMark',
  49. colNames: ['门诊停用','住院停用','库存为零','处方限制天数','编码','序号', '药品名','厂家', '库存量', '大规格(汇总)', '规格', '虚存2','启用虚存2', '3天用量', '7天用量', '14天用量','30天用量','货位号','药性分类'],
  50. colModel: [
  51. {name: 'visibleFlagMz', index: 'visibleFlagMz',align:'center',width:100,formatter : "checkbox",editable : true,edittype:'checkbox', editoptions:{value:"1:0"}},
  52. {name: 'visibleFlagZy', index: 'visibleFlagZy',align:'center',width:100,formatter : "checkbox",editable : true,edittype:'checkbox', editoptions:{value:"1:0"}},
  53. {name: 'visibleFlagStop', index: 'visibleFlagStop',align:'center',width:100,formatter : "checkbox",editable : true,edittype:'checkbox', editoptions:{value:"1:0"}},
  54. {name: 'prescriptionLimitDays', index: 'prescriptionLimitDays',width:100,align:'center',editable : true,edittype:'text'
  55. ,editrules: {edithidden:false,number:true,minValue:0}
  56. },
  57. {name: 'chargeCode', index: 'chargeCode',align:'center',width:100},
  58. {name: 'serial', index: 'serial',align:'center',width:100,hidden:true},
  59. {name: 'name', index: 'name',width:180},
  60. {name: 'manufactoryName', index: 'manufactoryName',width:180},
  61. {name: 'stockAmount', index: 'stockAmount',align:'center',width:100},
  62. {name: 'stockAmountLarge', index: 'stockAmountLarge',align:'center',width:100},
  63. {name: 'specification', index: 'specification',align:'center',width:100},
  64. {name: 'stockAmountVirtual2', index: 'stockAmountVirtual2',width:100,align:'center',editable : true,edittype:'text'
  65. ,editrules: {edithidden:true,number:true,minValue:0}
  66. },
  67. {name: 'openVirtual2', index: 'openVirtual2',width:100,align:'center',formatter : "checkbox",editable : true,edittype:'checkbox', editoptions:{value:"1:0"}},
  68. {name: 'threeDayDosage', index: 'threeDayDosage', formatter: 'number',formatoptions:{decimalPlaces:0},align:'center',width:100},
  69. {name: 'sevenDayDosage', index: 'sevenDayDosage', formatter: 'number',formatoptions:{decimalPlaces:0},align:'center',width:100},
  70. {name: 'fourteenDayDosage', index: 'fourteenDayDosage', formatter: 'number',formatoptions:{decimalPlaces:0},align:'center',width:100},
  71. {name: 'thirtyDayDosage', index: 'thirtyDayDosage', formatter: 'number',formatoptions:{decimalPlaces:0},align:'center',width:100},
  72. {name: 'location', index: 'location',width:100,align:'center',editable : true,edittype:'text'
  73. ,editrules: {edithidden:false}},
  74. {name: 'className', index: 'className',width:100,align:'center'}
  75. ],
  76. jsonReader: {
  77. root: "data", repeatitems: false
  78. },
  79. beforeSubmitCell:function(rowid, cellname, value, iRow, iCol){
  80. let record = $("#tb_table").getRowData(rowid);
  81. let temp = eval('(' + '{ "'+cellname+'": "'+value+'"}' + ')');
  82. if(cellname === 'prescriptionLimitDays' && value == 0){
  83. if (!confirm("确定放开当前药品的处方天数限制吗?")) {
  84. return;
  85. }
  86. }
  87. if(cellname !== 'prescriptionLimitDays'){
  88. temp.prescriptionLimitDays = record.prescriptionLimitDays;
  89. }
  90. temp.chargeCode = record.chargeCode;
  91. temp.serial = record.serial;
  92. temp.groupNo = pharmacyGroupNo;
  93. return temp
  94. },
  95. onCellSelect: function(rowid,iCol,cellcontent,e){
  96. let record = jQuery("#tb_table").getRowData(rowid);
  97. loadBatch(record.chargeCode);
  98. chargeNo = rowid;
  99. },
  100. loadComplete: function (res) { //加载完成(初始加载),回调函数
  101. if (res == '401' || res == 401) {
  102. window.location.href = '/thmz/login/view';
  103. return;
  104. }
  105. if (res.code == -1) {
  106. errorMesage(res);
  107. }
  108. }
  109. });
  110. }
  111. /**
  112. * 加载药品批次表格数据
  113. */
  114. function loadTbTable() {
  115. $("#tb_table").jqGrid('setGridParam', {
  116. datatype:'json',
  117. postData: { searchText: $("#searchText").val(), groupNo: pharmacyGroupNo }
  118. }).trigger('reloadGrid');
  119. }
  120. /**
  121. * 加载药品批次表格数据
  122. * @param chargeCode
  123. */
  124. function loadBatch(chargeCode) {
  125. batchNo = null;
  126. $("#tb_table_batch").jqGrid('setGridParam', {
  127. datatype:'json',
  128. postData: { chargeCode: chargeCode }
  129. }).trigger('reloadGrid');
  130. }
  131. /**
  132. * 初始化药品批次表格
  133. */
  134. function initBatch() {
  135. $.jgrid.gridUnload("tb_table_batch");
  136. $("#tb_table_batch").jqGrid({
  137. datatype: 'json',
  138. mtype: 'get',
  139. url: '/thmz/getYpZdYpbh',
  140. loadBeforeSend: function (jqXHR) {
  141. jqXHR.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  142. jqXHR.setRequestHeader("Accept", 'application/json');
  143. },
  144. ajaxCellOptions: {
  145. beforeSend: function (XMLHttpRequest) {
  146. XMLHttpRequest.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  147. }
  148. },
  149. toolbar : [ true, "top" ],
  150. styleUI: 'Bootstrap',
  151. viewrecords: true,
  152. autowidth: true,
  153. rowNum: -1,//取消分页
  154. caption: '药品批次维护',
  155. cellEdit: true,
  156. sortable: true,
  157. loadonce:true, //一次加载全部数据到客户端,由客户端进行排序。
  158. sortname: 'fDate', //设置默认的排序列
  159. sortorder: 'desc',
  160. cellsubmit: "remote",
  161. cellurl: '/thmz/modifYpZdYpbh',
  162. editurl: '/thmz/addYpZdYpbh',
  163. colNames: ['停用标记','药品编号','药品批号','入库时间'],
  164. colModel: [
  165. {name: 'usingFlag', index: 'usingFlag',align:'center',width:100,formatter : "checkbox",editable : true,edittype:'checkbox', editoptions:{value:"1:0"}},
  166. {name: 'chargeCode', index: 'chargeCode',align:'center',width:100},
  167. {name: 'ypbh', index: 'ypbh',align:'center',width:100,editable : true,edittype:'text'},
  168. {name: 'fDate', index: 'fDate',align:'center', formatter:"date", formatoptions: {srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},sortable: true,width:100,
  169. editable:true,
  170. edittype:"text",editoptions: {
  171. size: 10, maxlengh: 10,
  172. dataInit: function(element) {
  173. $(element).datetimepicker({language:'zh-CN',dateFormat: 'yyyy-mm-dd hh:ii'})
  174. }
  175. }
  176. }
  177. ],
  178. jsonReader: {
  179. root: "data", repeatitems: false
  180. },
  181. beforeSubmitCell:function(rowid, cellname, value, iRow, iCol){
  182. let record = jQuery("#tb_table_batch").getRowData(rowid);
  183. let temp = eval('(' + '{ "'+cellname+'": "'+value+'"}' + ')');
  184. temp.chargeCode = record.chargeCode;
  185. temp.ypbh = record.ypbh;
  186. return temp
  187. },
  188. onCellSelect: function(rowid,iCol,cellcontent,e){
  189. batchNo = rowid;
  190. },
  191. beforeEditCell: function(rowid,iCol,cellcontent,e){
  192. batchNo = rowid;
  193. },
  194. loadComplete: function (res) { //加载完成(初始加载),回调函数
  195. var ids = jQuery("#tb_table_batch").jqGrid("getDataIDs");
  196. for (let i = 0; i < ids.length; i++) {
  197. $("#tb_table_batch").jqGrid("setCell",ids[i],"ypbh",'','not-editable-cell');//列不可编辑
  198. }
  199. if (res == '401' || res == 401) {
  200. window.location.href = '/thmz/login/view';
  201. return;
  202. }
  203. if (res.code == -1) {
  204. errorMesage(res);
  205. }
  206. }
  207. });
  208. $("#t_tb_table_batch").append("<button class='registration-no-color-foot-button' title='新增一行' id='addBatch' style='color: #35D082;margin-left: 10px;'><i class='fa fa-plus'></i></button>");
  209. $("#t_tb_table_batch").append("<button class='registration-no-color-foot-button' title='删除一行' id='removeBatch' style='color: red;margin-left: 10px;'><i class='fa fa-trash-o'></i></button>");
  210. $("#t_tb_table_batch").append("<button class='registration-no-color-foot-button' title='保存新增行' id='saveBatch' style='color: green;margin-left: 10px;'><i class='fa fa-floppy-o'></i></button>");
  211. $("#addBatch").on('click',function(e){
  212. var ids = jQuery("#tb_table_batch").jqGrid("getDataIDs");//得到jqgrid当前行数
  213. var rowid = Math.max.apply(Math,ids);//获得当前最大行号
  214. let record = jQuery("#tb_table").getRowData(chargeNo);
  215. let data= {chargeCode:record['chargeCode'],usingFlag:0,ypbh:"",fDate:new Date()};
  216. $("#tb_table_batch").addRowData(rowid+1, data,'first');
  217. jQuery("#tb_table_batch").jqGrid('editRow', rowid+1);
  218. batchNo = rowid+1;
  219. });
  220. $("#removeBatch").on('click',function(e){
  221. if(batchNo == null){
  222. return errorMesageSimaple('请选择一行进行删除!');
  223. }
  224. let record = jQuery("#tb_table_batch").getRowData(batchNo);
  225. if(!(record['ypbh'].indexOf("<input") != -1)){
  226. let data= {chargeCode:record['chargeCode'],ypbh:record['ypbh']};
  227. $.ajax({
  228. type: "GET",
  229. url: '/thmz/removeYpZdYpbh',
  230. contentType: "application/json;charset=UTF-8",
  231. dataType: "json",
  232. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  233. data: data,
  234. success: function (res) {
  235. if (res == '401' || res == 401) {
  236. window.location.href = '/thmz/login/view';
  237. return;
  238. }
  239. if (res.code == 0) {
  240. $("#tb_table_batch").jqGrid("delRowData", batchNo);
  241. batchNo = null;
  242. successMesage(res);
  243. } else {
  244. errorMesage(res);
  245. }
  246. }
  247. });
  248. }else{
  249. $("#tb_table_batch").jqGrid("delRowData", batchNo);
  250. }
  251. });
  252. $("#saveBatch").on('click',function(e){
  253. if(batchNo == null){
  254. return errorMesageSimaple('没有可保存数据!');
  255. }
  256. let record = jQuery("#tb_table_batch").getRowData(batchNo);
  257. let data= {usingFlag:record['usingFlag'],chargeCode:record['chargeCode'],ypbh:$('#'+batchNo+'_ypbh').val(),fDate:$('#'+batchNo+'_fDate').val()};
  258. $.ajax({
  259. type: "POST",
  260. url: '/thmz/addYpZdYpbh',
  261. contentType: "application/json;charset=UTF-8",
  262. dataType: "json",
  263. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  264. data: JSON.stringify(data),
  265. success: function (res) {
  266. if (res == '401' || res == 401) {
  267. window.location.href = '/thmz/login/view';
  268. return;
  269. }
  270. if (res.code == 0) {
  271. let record = jQuery("#tb_table").getRowData(chargeNo);
  272. loadBatch(record.chargeCode);
  273. batchNo = null;
  274. successMesage(res);
  275. } else {
  276. errorMesage(res);
  277. }
  278. }
  279. });
  280. });
  281. }