pharmacy-com.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. //@ sourceURL=pharmacy-com.js
  2. var readcardUrl = 'http://localhost:8321/readcard/entry';
  3. var url = '/thmz';
  4. /**
  5. * 加载搜索窗口
  6. */
  7. function initSearchList(content, searchTextId, width, height) {
  8. var settings = {
  9. placement: 'bottom-right',//值: auto,top,right,bottom,left,top-right,top-left,bottom-right,bottom-left 要显示的位置
  10. trigger: 'click', //值:click,hover 触发方式
  11. content: '',//内容,内容可以是函数
  12. width: width,
  13. //arrow:false,//是否显示箭头
  14. multi: true,//在页面允许其他弹出层
  15. closeable: true,//显示关闭按钮
  16. style: '', //值:'',inverse
  17. delay: 300,//延迟时间, 悬浮属性才执行
  18. padding: true,//内容填充
  19. height: height,
  20. //offsetTop:10,
  21. cache: true,//如果缓存设置为false,则popover将销毁并重新创建
  22. content: content
  23. };
  24. $('#' + searchTextId).webuiPopover('destroy').webuiPopover(settings);
  25. }
  26. /**
  27. * 修改列数据
  28. * @param $table 表格元素
  29. * @param index 行索引
  30. * @param field 列名
  31. * @param value cell值
  32. */
  33. function saveCellData($table, index, field, value) {
  34. $table.bootstrapTable('updateCell', {
  35. index: index,
  36. field: field,
  37. value: value
  38. })
  39. }
  40. /**
  41. * 科室列表
  42. */
  43. function initDeptSelect(flag, id) {
  44. var url = "";
  45. if (flag == 0) {
  46. url = "/thmz/allUnitCode"
  47. } else if (flag == 1) {
  48. url = "/thmz/allMzUnitCode"
  49. }
  50. //科室列表
  51. $.ajax({
  52. type: "GET",
  53. url: url,
  54. dataType: "json",
  55. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  56. success: function (data) {
  57. if (data == '401' || data == 401) {
  58. window.location.href = '/thmz/login/view';
  59. return;
  60. }
  61. var html = '';
  62. $.each(data.data, function (commentIndex, comment) {
  63. html += '<option value="' + comment.code + '">' + comment.name + '(' + comment.pyCode + ')</option>';
  64. });
  65. $('#' + id).empty();
  66. $('#' + id).html(html);
  67. $('#' + id).selectpicker('refresh');
  68. }
  69. });
  70. }
  71. /**
  72. * 四舍五入保留2位小数(若第二位小数为0,则保留一位小数)
  73. * @param num
  74. * @returns {*}
  75. */
  76. function keepTwoDecimal(num) {
  77. var result = parseFloat(num);
  78. if (isNaN(result)) {
  79. return false;
  80. }
  81. result = Math.round(num * 100) / 100;
  82. return result;
  83. }
  84. //默认打印机下标
  85. var defaultPrintIndex = -1;
  86. /**
  87. * 查询默认打印机
  88. */
  89. function setDefaultPrint() {
  90. if (defaultPrintIndex >= 0) {
  91. return;
  92. }
  93. $.ajax({
  94. type: "GET",
  95. url: '/thmz/getLastWindowsByCurrentUser',
  96. contentType: "application/json;charset=UTF-8",
  97. dataType: "json",
  98. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  99. async: false,
  100. success: function (res) {
  101. if (res == '401' || res == 401) {
  102. window.location.href = '/thmz/login/view'
  103. return;
  104. }
  105. if (res.code == 0) {
  106. defaultPrintIndex = res.data.cgPrintIndex;
  107. } else {
  108. defaultPrintIndex = -1;
  109. }
  110. }
  111. });
  112. }
  113. //显示查询所有药品悬浮窗
  114. function showDrugPopover() {
  115. $('#tb_table_medicine').bootstrapTable('destroy');
  116. $('#tb_table_medicine').bootstrapTable({
  117. url: '/thmz/getYp', //请求后台的URL(*)
  118. method: 'GET', //请求方式(*)
  119. toolbar: '#toolbar', //工具按钮用哪个容器
  120. striped: true, //是否显示行间隔色
  121. cache: true, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  122. pagination: false, //是否显示分页(*)
  123. sortable: true, //是否启用排序
  124. sortOrder: "asc", //排序方式
  125. queryParams: {
  126. searchTextDrug: $("#searchTextDrug").val() == "" ? null : $("#searchTextDrug").val(),
  127. },
  128. sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
  129. pageNumber: 1, //初始化加载第一页,默认第一页
  130. pageSize: 5, //每页的记录行数(*)
  131. pageList: [5, 10, 25, 50, 100], //可供选择的每页的行数(*)
  132. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  133. strictSearch: true,
  134. showColumns: false, //是否显示所有的列
  135. showRefresh: false, //是否显示刷新按钮
  136. minimumCountColumns: 2, //最少允许的列数
  137. clickToSelect: true, //是否启用点击选中行
  138. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  139. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  140. cardView: false, //是否显示详细视图
  141. detailView: false,
  142. //rowStyle:rowStyle,//通过自定义函数设置行样式
  143. ajaxOptions: {
  144. headers: {
  145. 'Accept': 'application/json',
  146. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  147. }
  148. },
  149. columns: [
  150. {
  151. field: 'code',
  152. title: '编码',
  153. align: "center",
  154. valign: 'middle'
  155. }, {
  156. field: 'name',
  157. title: '药品名',
  158. align: "center",
  159. valign: 'middle'
  160. }, {
  161. field: 'manufactoryName',
  162. title: '厂家',
  163. align: "center",
  164. valign: 'middle'
  165. },
  166. {
  167. field: 'specification',
  168. title: '规格',
  169. align: "center",
  170. valign: 'middle'
  171. },
  172. {
  173. field: 'packRetprice',
  174. title: '零售价',
  175. align: "center",
  176. valign: 'middle'
  177. }, {
  178. field: 'delFlag',
  179. title: '已作废',
  180. align: "center",
  181. valign: 'middle',
  182. formatter: function (value, row, index) {
  183. return value == 1 ? '<span style="color: red">是</span>' : '否';
  184. }
  185. }
  186. ],
  187. responseHandler: function (res) {
  188. if (res == '401' || res == 401) {
  189. window.location.href = '/thmz/login/view'
  190. return;
  191. }
  192. var ress = eval(res);
  193. if (ress.code == -1) {
  194. errorMesage(res);
  195. return {
  196. "total": 0,//总页数
  197. "rows": {} //数据
  198. };
  199. }
  200. return {
  201. "total": ress.data.length,//总页数
  202. "rows": ress.data //数据
  203. };
  204. },
  205. onClickRow: function (row, $element) {
  206. $('#searchTextDrug').webuiPopover('hide');
  207. $('#codeSearch').val(row.code);
  208. $('#serialSearch').val(row.serial);
  209. $('#searchTextDrug').val(row.name);
  210. }
  211. });
  212. }
  213. /**
  214. * 将table导出Excel
  215. * @param tableid
  216. * @param sheetName
  217. */
  218. function tableToExcel(tableid, sheetName) {
  219. var uri = 'data:application/vnd.ms-excel;base64,';
  220. var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"' +
  221. 'xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>'
  222. + '<x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>'
  223. + '</x:ExcelWorkbook></xml><![endif]-->' +
  224. '<style type="text/css">' +
  225. 'table td{' +
  226. 'border: 1px solid #000000;' +
  227. 'width: 150px;' +
  228. 'height: 30px;' +
  229. 'text-align: center;' +
  230. '}' +
  231. '.xtd{' +
  232. 'border: 1px solid #000000;' +
  233. 'width: 50px;' +
  234. 'height: 30px;' +
  235. 'text-align: center;' +
  236. '}' +
  237. '</style>' +
  238. '</head><body ><table class="excelTable">{table}</table></body></html>';
  239. if (!tableid.nodeType) tableid = document.getElementById(tableid);
  240. var ctx = {worksheet: sheetName || 'Worksheet', table: tableid.innerHTML};
  241. var blobExel = self.baseExel(uri + base64(formatName(template, ctx))); //把base64位文件转化为exel文件
  242. document.getElementById("btn_excel").href = URL.createObjectURL(blobExel);
  243. document.getElementById("btn_excel").download = ctx.worksheet;
  244. console.log(document.getElementById("btn_excel").href);
  245. }
  246. /*处理后端返回的base64位文件变成exel文件进行下载
  247. * 不要直接把base64位的exel文件直接给a标签的href,
  248. * 文件过大时base64位长度过长;chrome浏览器对a标签的href长度有限制;导致下载失败;
  249. * 建议用以下方法处理成本地文件再下载
  250. * */
  251. function baseExel(base64) {
  252. function getContentType(base64) {
  253. return /data:([^;]*);/i.exec(base64)[1];
  254. };
  255. function getData(base64) {
  256. return base64.substr(base64.indexOf("base64,") + 7, base64.length);
  257. };
  258. function b64toBlob(b64Data, contentType, sliceSize) {
  259. contentType = contentType || '';
  260. sliceSize = sliceSize || 512;
  261. var byteCharacters = atob(b64Data);
  262. var byteArrays = [];
  263. for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  264. var slice = byteCharacters.slice(offset, offset + sliceSize);
  265. var byteNumbers = new Array(slice.length);
  266. for (var i = 0; i < slice.length; i++) {
  267. byteNumbers[i] = slice.charCodeAt(i);
  268. }
  269. var byteArray = new Uint8Array(byteNumbers);
  270. byteArrays.push(byteArray);
  271. }
  272. var blob = new Blob(byteArrays, {type: contentType});
  273. return blob;
  274. };
  275. return b64toBlob(getData(base64), getContentType(base64));
  276. }
  277. /**
  278. * 获取jqgrid的所有数据
  279. * @param tableId
  280. * @returns {any[]}
  281. */
  282. function getJQAllData(tableId) {
  283. //拿到grid对象
  284. var obj = $("#" + tableId);
  285. //获取grid表中所有的rowid值
  286. var rowIds = obj.getDataIDs();
  287. //初始化一个数组arrayData容器,用来存放rowData
  288. var arrayData = new Array();
  289. if (rowIds.length > 0) {
  290. for (var i = 0; i < rowIds.length; i++) {
  291. arrayData.push(obj.getRowData(rowIds[i]));
  292. }
  293. }
  294. return arrayData;
  295. }
  296. //base64转码
  297. function base64(s) {
  298. return window.btoa(unescape(encodeURIComponent(s)));
  299. };
  300. //替换table数据和worksheet名字
  301. function formatName(s, c) {
  302. return s.replace(/{(\w+)}/g,
  303. function (m, p) {
  304. return c[p];
  305. });
  306. };
  307. /**
  308. * ajax封装请求
  309. * @param config
  310. * @returns {Promise<any>}
  311. */
  312. function request(config) {
  313. return new Promise(((resolve, reject) => {
  314. $.ajax({
  315. type: config.method,
  316. url: url + config.url,
  317. data: JSON.stringify(config.data),
  318. contentType: "application/json;charset=UTF-8",
  319. dataType: "json",
  320. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  321. success: function (res) {
  322. if (res == '401' || res == 401) {
  323. window.location.href = '/thmz/login/view';
  324. return;
  325. }
  326. if (res.code == 0) {
  327. resolve(res);
  328. } else {
  329. new PNotify({
  330. title: '错误提示',
  331. text: res.message,
  332. type: 'error',
  333. hide: true,
  334. styling: 'bootstrap3'
  335. });
  336. reject(res)
  337. }
  338. },
  339. error: err => {
  340. new PNotify({
  341. title: '错误提示',
  342. text: err.responseText,
  343. type: 'error',
  344. hide: true,
  345. styling: 'bootstrap3'
  346. });
  347. reject(err)
  348. }
  349. });
  350. }))
  351. }
  352. /**
  353. * 医保凭证接口
  354. * @param config
  355. * @returns {Promise<any>}
  356. */
  357. function readcardRequest(config) {
  358. return new Promise(((resolve, reject) => {
  359. $.ajax({
  360. type: config.method,
  361. url: readcardUrl,
  362. data: config.data,
  363. contentType: "application/json;charset=UTF-8",
  364. dataType: "json",
  365. headers: {'Accept': 'application/json'},
  366. success: res => {
  367. if (res == '401' || res == 401) {
  368. window.location.href = '/thmz/login/view';
  369. return;
  370. }
  371. if (res.code == 200) {
  372. resolve(JSON.parse(res.data));
  373. } else {
  374. $("#showErrorModal").modal("show");
  375. reject(res.message)
  376. }
  377. },
  378. error: err => {
  379. $("#showErrorModal").modal("show");
  380. reject(err)
  381. }
  382. });
  383. }))
  384. }
  385. /**
  386. * 排序函数
  387. * @param property
  388. * @returns {function(*, *): number}
  389. */
  390. function compare(property) {
  391. return function (a,b) {
  392. var va1 = a[property];
  393. var va2 = b[property];
  394. return va1 - va2
  395. }
  396. }
  397. /**
  398. * 根据对象属性删除对象数组内容
  399. * @param array 对象数组
  400. * @param abj 对象
  401. * @param property 对象属性
  402. * @returns {*}
  403. */
  404. function removeObjArrayByProperty(array,abj,property) {
  405. for (let j = 0; j < array.length; j++) {
  406. if(abj != null && array[j][property] === abj[property]){
  407. array.splice(j,1);
  408. }
  409. }
  410. return array
  411. }
  412. /**
  413. * 获取LocalStorage
  414. * @param name
  415. * @param nullReturn
  416. */
  417. function getLocalStorage(name,nullReturn) {
  418. let returnValue = nullReturn ? nullReturn:-1;
  419. let data = window.localStorage[name];
  420. if(data){
  421. try {
  422. return JSON.parse(data);
  423. }catch (e) {
  424. return data;
  425. }
  426. }
  427. return returnValue;
  428. }