pharmacy-com.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. //@ sourceURL=pharmacy-com.js
  2. var readcardUrl = 'http://localhost:8321/readcard/entry';
  3. var url = '/thmz';
  4. /**
  5. * 加载搜索窗口
  6. */
  7. function initSearchList(content, searchTextIds, 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. if(Array.isArray(searchTextIds)){
  25. for (let i = 0; i < searchTextIds.length; i++) {
  26. $('#' + searchTextIds[i]).webuiPopover('destroy').webuiPopover(settings);
  27. }
  28. }else{
  29. $('#' + searchTextIds).webuiPopover('destroy').webuiPopover(settings);
  30. }
  31. }
  32. /**
  33. * 修改列数据
  34. * @param $table 表格元素
  35. * @param index 行索引
  36. * @param field 列名
  37. * @param value cell值
  38. */
  39. function saveCellData($table, index, field, value) {
  40. $table.bootstrapTable('updateCell', {
  41. index: index,
  42. field: field,
  43. value: value
  44. })
  45. }
  46. /**
  47. * 初始化下拉列表
  48. */
  49. function initDynamicSelect(url, id, codeColumn, nameColumn) {
  50. codeColumn = codeColumn==null?'code':codeColumn;
  51. nameColumn = nameColumn==null?'name':nameColumn;
  52. $.ajax({
  53. type: "GET",
  54. url: '/thmz/'+url,
  55. dataType: "json",
  56. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  57. success: function (data) {
  58. if (data == '401' || data == 401) {
  59. window.location.href = '/thmz/login/view';
  60. return;
  61. }
  62. var html = '';
  63. $.each(data.data, function (commentIndex, comment) {
  64. let pyCode = typeof comment.pyCode === 'undefined'?'':'(' +comment.pyCode+ ')';
  65. html += '<option value="' + comment[codeColumn] + '">' + comment[nameColumn] + pyCode + '</option>';
  66. });
  67. $('#' + id).empty();
  68. $('#' + id).html(html);
  69. $('#' + id).selectpicker('refresh');
  70. }
  71. });
  72. }
  73. /**
  74. * 初始化员工下拉列表
  75. */
  76. function initEmployeeSelect(id) {
  77. $.ajax({
  78. type: "GET",
  79. url: '/thmz/getEmployee',
  80. dataType: "json",
  81. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  82. success: function (data) {
  83. if (data == '401' || data == 401) {
  84. window.location.href = '/thmz/login/view';
  85. return;
  86. }
  87. var html = '';
  88. $.each(data.data, function (commentIndex, comment) {
  89. let pyCode = typeof comment.pyCode === 'undefined'?'':'(' +comment.pyCode+ ')';
  90. html += '<option value="' + comment['employeeCode'] + '">' + comment['employeeName']+"-"+comment['deptName'] + pyCode + '</option>';
  91. });
  92. $('#' + id).empty();
  93. $('#' + id).html(html);
  94. $('#' + id).selectpicker('refresh');
  95. }
  96. });
  97. }
  98. //初始化药房下拉
  99. function initAllGroup(id) {
  100. $.ajax({
  101. type: "GET",
  102. url: '/thmz/queryAllGroupName',
  103. contentType: "application/json;charset=UTF-8",
  104. dataType: "json",
  105. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  106. success: function (res) {
  107. if (res == '401' || res == 401) {
  108. window.location.href = '/thmz/login/view';
  109. return;
  110. }
  111. if (res.code == 0) {
  112. //初始化部门下拉
  113. var arr = res.data;
  114. if (arr != null && arr.length > 0) {
  115. var html = "";
  116. for (var i = 0; i < arr.length; i++) {
  117. html += "<option value='" + arr[i].groupNo + "'>" + arr[i].groupName + '(' + arr[i].pyCode + ")</option>";
  118. }
  119. $('#'+id).html(html);
  120. $('#'+id).selectpicker('refresh');
  121. } else {
  122. errorMesage(res);
  123. }
  124. }
  125. }
  126. });
  127. }
  128. /**
  129. * 四舍五入保留2位小数(若第二位小数为0,则保留一位小数)
  130. * @param num
  131. * @returns {*}
  132. */
  133. function keepTwoDecimal(num) {
  134. var result = parseFloat(num);
  135. if (isNaN(result)) {
  136. return false;
  137. }
  138. result = Math.round(num * 100) / 100;
  139. return result;
  140. }
  141. //默认打印机下标
  142. var defaultPrintIndex = -1;
  143. /**
  144. * 查询默认打印机
  145. */
  146. function setDefaultPrint() {
  147. if (defaultPrintIndex >= 0) {
  148. return;
  149. }
  150. $.ajax({
  151. type: "GET",
  152. url: '/thmz/getLastWindowsByCurrentUser',
  153. contentType: "application/json;charset=UTF-8",
  154. dataType: "json",
  155. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  156. async: false,
  157. success: function (res) {
  158. if (res == '401' || res == 401) {
  159. window.location.href = '/thmz/login/view'
  160. return;
  161. }
  162. if (res.code == 0) {
  163. defaultPrintIndex = res.data.cgPrintIndex;
  164. } else {
  165. defaultPrintIndex = -1;
  166. }
  167. }
  168. });
  169. }
  170. /**
  171. * 显示查询所有药品悬浮窗
  172. * @param data
  173. */
  174. function showDrugPopover(data) {
  175. let columns = [
  176. {
  177. field: 'code',
  178. title: '编码',
  179. align: "center",
  180. valign: 'middle'
  181. }, {
  182. field: 'name',
  183. title: '药品名',
  184. align: "center",
  185. valign: 'middle'
  186. }, {
  187. field: 'manufactoryName',
  188. title: '厂家',
  189. align: "center",
  190. valign: 'middle'
  191. },
  192. {
  193. field: 'specification',
  194. title: '规格',
  195. align: "center",
  196. valign: 'middle'
  197. },
  198. {
  199. field: 'packRetprice',
  200. title: '零售价',
  201. align: "center",
  202. valign: 'middle'
  203. }
  204. ];
  205. columns = columns.concat(data.columns);
  206. $('#tb_table_medicine').bootstrapTable('destroy');
  207. $('#tb_table_medicine').bootstrapTable({
  208. url: data.url==null?'/thmz/getYp':data.url, //请求后台的URL(*)
  209. method: data.method==null?'GET':data.method, //请求方式(*)
  210. toolbar: '#toolbar', //工具按钮用哪个容器
  211. striped: true, //是否显示行间隔色
  212. cache: true, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  213. pagination: false, //是否显示分页(*)
  214. sortable: true, //是否启用排序
  215. sortOrder: "asc", //排序方式
  216. queryParams: data.data,
  217. sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
  218. pageNumber: 1, //初始化加载第一页,默认第一页
  219. pageSize: 5, //每页的记录行数(*)
  220. pageList: [5, 10, 25, 50, 100], //可供选择的每页的行数(*)
  221. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  222. strictSearch: true,
  223. showColumns: false, //是否显示所有的列
  224. showRefresh: false, //是否显示刷新按钮
  225. minimumCountColumns: 2, //最少允许的列数
  226. clickToSelect: true, //是否启用点击选中行
  227. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  228. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  229. cardView: false, //是否显示详细视图
  230. detailView: false,
  231. ajaxOptions: {
  232. headers: {
  233. 'Accept': 'application/json',
  234. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  235. }
  236. },
  237. columns: columns,
  238. onClickRow: data.onClickRow==null?function (row, $element) {
  239. $('#searchTextDrug').webuiPopover('hide');
  240. $('#codeSearch').val(row.code);
  241. $('#serialSearch').val(row.serial);
  242. $('#searchTextDrug').val(row.name);
  243. }:data.onClickRow,
  244. responseHandler: function (res) {
  245. if (res == '401' || res == 401) {
  246. window.location.href = '/thmz/login/view'
  247. return;
  248. }
  249. var ress = eval(res);
  250. if (ress.code == -1) {
  251. errorMesage(res);
  252. return {
  253. "total": 0,//总页数
  254. "rows": {} //数据
  255. };
  256. }
  257. return {
  258. "total": ress.data.length,//总页数
  259. "rows": ress.data //数据
  260. };
  261. }
  262. });
  263. }
  264. /**
  265. * 显示员工悬浮窗
  266. * @param data
  267. */
  268. function showEmployeePopover(data) {
  269. let columns = [
  270. {
  271. field: 'employeeCode',
  272. title: '员工编码',
  273. align: "center",
  274. valign: 'middle'
  275. }, {
  276. field: 'employeeName',
  277. title: '姓名',
  278. align: "center",
  279. valign: 'middle'
  280. }, {
  281. field: 'deptName',
  282. title: '科室',
  283. align: "center",
  284. valign: 'middle'
  285. }
  286. ];
  287. columns = columns.concat(data.columns);
  288. $('#tb_table_employee').bootstrapTable('destroy');
  289. $('#tb_table_employee').bootstrapTable({
  290. url: data.url==null?'/thmz/getEmployeeBySearchText':data.url, //请求后台的URL(*)
  291. method: 'GET', //请求方式(*)
  292. toolbar: '#toolbar', //工具按钮用哪个容器
  293. striped: true, //是否显示行间隔色
  294. cache: true, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  295. pagination: false, //是否显示分页(*)
  296. sortable: true, //是否启用排序
  297. sortOrder: "asc", //排序方式
  298. queryParams: data.data,
  299. sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
  300. pageNumber: 1, //初始化加载第一页,默认第一页
  301. pageSize: 5, //每页的记录行数(*)
  302. pageList: [5, 10, 25, 50, 100], //可供选择的每页的行数(*)
  303. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  304. strictSearch: true,
  305. showColumns: false, //是否显示所有的列
  306. showRefresh: false, //是否显示刷新按钮
  307. minimumCountColumns: 2, //最少允许的列数
  308. clickToSelect: true, //是否启用点击选中行
  309. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  310. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  311. cardView: false, //是否显示详细视图
  312. detailView: false,
  313. ajaxOptions: {
  314. headers: {
  315. 'Accept': 'application/json',
  316. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  317. }
  318. },
  319. columns: columns,
  320. onClickRow: data.onClickRow,
  321. responseHandler: function (res) {
  322. if (res == '401' || res == 401) {
  323. window.location.href = '/thmz/login/view'
  324. return;
  325. }
  326. var ress = eval(res);
  327. if (ress.code == -1) {
  328. errorMesage(res);
  329. return {
  330. "total": 0,//总页数
  331. "rows": {} //数据
  332. };
  333. }
  334. return {
  335. "total": ress.data.length,//总页数
  336. "rows": ress.data //数据
  337. };
  338. }
  339. });
  340. }
  341. /**
  342. * 显示药品厂家悬浮窗
  343. * @param data
  344. */
  345. function showManufactoryPopover(data) {
  346. let columns = [
  347. {
  348. field: 'code',
  349. title: '编码',
  350. align: "center",
  351. valign: 'middle'
  352. }, {
  353. field: 'name',
  354. title: '厂名',
  355. align: "center",
  356. valign: 'middle'
  357. }
  358. ];
  359. columns = columns.concat(data.columns);
  360. $('#tb_table_manufactory').bootstrapTable('destroy');
  361. $('#tb_table_manufactory').bootstrapTable({
  362. url: data.url==null?'/thmz/getYpZdManufactoryBySearchText':data.url, //请求后台的URL(*)
  363. method: 'GET', //请求方式(*)
  364. toolbar: '#toolbar', //工具按钮用哪个容器
  365. striped: true, //是否显示行间隔色
  366. cache: true, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  367. pagination: false, //是否显示分页(*)
  368. sortable: true, //是否启用排序
  369. sortOrder: "asc", //排序方式
  370. queryParams: data.data,
  371. sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
  372. pageNumber: 1, //初始化加载第一页,默认第一页
  373. pageSize: 5, //每页的记录行数(*)
  374. pageList: [5, 10, 25, 50, 100], //可供选择的每页的行数(*)
  375. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  376. strictSearch: true,
  377. showColumns: false, //是否显示所有的列
  378. showRefresh: false, //是否显示刷新按钮
  379. minimumCountColumns: 2, //最少允许的列数
  380. clickToSelect: true, //是否启用点击选中行
  381. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  382. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  383. cardView: false, //是否显示详细视图
  384. detailView: false,
  385. ajaxOptions: {
  386. headers: {
  387. 'Accept': 'application/json',
  388. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  389. }
  390. },
  391. columns: columns,
  392. onClickRow: data.onClickRow,
  393. responseHandler: function (res) {
  394. if (res == '401' || res == 401) {
  395. window.location.href = '/thmz/login/view'
  396. return;
  397. }
  398. var ress = eval(res);
  399. if (ress.code == -1) {
  400. errorMesage(res);
  401. return {
  402. "total": 0,//总页数
  403. "rows": {} //数据
  404. };
  405. }
  406. return {
  407. "total": ress.data.length,//总页数
  408. "rows": ress.data //数据
  409. };
  410. }
  411. });
  412. }
  413. /**
  414. * 显示供应商悬浮窗
  415. * @param data
  416. */
  417. function showSupplyPopover(data) {
  418. let columns = [
  419. {
  420. field: 'code',
  421. title: '编码',
  422. align: "center",
  423. valign: 'middle'
  424. }, {
  425. field: 'name',
  426. title: '供应商',
  427. align: "center",
  428. valign: 'middle'
  429. }
  430. ];
  431. columns = columns.concat(data.columns);
  432. $('#tb_table_supply').bootstrapTable('destroy');
  433. $('#tb_table_supply').bootstrapTable({
  434. url: data.url==null?'/thmz/getYpZdSupplyBySearchText':data.url, //请求后台的URL(*)
  435. method: 'GET', //请求方式(*)
  436. toolbar: '#toolbar', //工具按钮用哪个容器
  437. striped: true, //是否显示行间隔色
  438. cache: true, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  439. pagination: false, //是否显示分页(*)
  440. sortable: true, //是否启用排序
  441. sortOrder: "asc", //排序方式
  442. queryParams: data.data,
  443. sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
  444. pageNumber: 1, //初始化加载第一页,默认第一页
  445. pageSize: 5, //每页的记录行数(*)
  446. pageList: [5, 10, 25, 50, 100], //可供选择的每页的行数(*)
  447. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  448. strictSearch: true,
  449. showColumns: false, //是否显示所有的列
  450. showRefresh: false, //是否显示刷新按钮
  451. minimumCountColumns: 2, //最少允许的列数
  452. clickToSelect: true, //是否启用点击选中行
  453. uniqueId: "ID", //每一行的唯一标识,一般为主键列
  454. showToggle: false, //是否显示详细视图和列表视图的切换按钮
  455. cardView: false, //是否显示详细视图
  456. detailView: false,
  457. ajaxOptions: {
  458. headers: {
  459. 'Accept': 'application/json',
  460. 'Authorization': 'Bearer ' + localStorage.getItem("token")
  461. }
  462. },
  463. columns: columns,
  464. onClickRow: data.onClickRow,
  465. responseHandler: function (res) {
  466. if (res == '401' || res == 401) {
  467. window.location.href = '/thmz/login/view'
  468. return;
  469. }
  470. var ress = eval(res);
  471. if (ress.code == -1) {
  472. errorMesage(res);
  473. return {
  474. "total": 0,//总页数
  475. "rows": {} //数据
  476. };
  477. }
  478. return {
  479. "total": ress.data.length,//总页数
  480. "rows": ress.data //数据
  481. };
  482. }
  483. });
  484. }
  485. /**
  486. * 将table导出Excel
  487. * @param tableid
  488. * @param sheetName
  489. */
  490. function tableToExcel(tableid, sheetName) {
  491. var uri = 'data:application/vnd.ms-excel;base64,';
  492. var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"' +
  493. 'xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>'
  494. + '<x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>'
  495. + '</x:ExcelWorkbook></xml><![endif]-->' +
  496. '<style type="text/css">' +
  497. 'table td{' +
  498. 'border: 1px solid #000000;' +
  499. 'width: 150px;' +
  500. 'height: 30px;' +
  501. 'text-align: center;' +
  502. '}' +
  503. '.xtd{' +
  504. 'border: 1px solid #000000;' +
  505. 'width: 50px;' +
  506. 'height: 30px;' +
  507. 'text-align: center;' +
  508. '}' +
  509. '</style>' +
  510. '</head><body ><table class="excelTable">{table}</table></body></html>';
  511. if (!tableid.nodeType) tableid = document.getElementById(tableid);
  512. var ctx = {worksheet: sheetName || 'Worksheet', table: tableid.innerHTML};
  513. var blobExel = self.baseExel(uri + base64(formatName(template, ctx))); //把base64位文件转化为exel文件
  514. document.getElementById("btn_excel").href = URL.createObjectURL(blobExel);
  515. document.getElementById("btn_excel").download = ctx.worksheet;
  516. console.log(document.getElementById("btn_excel").href);
  517. }
  518. /*处理后端返回的base64位文件变成exel文件进行下载
  519. * 不要直接把base64位的exel文件直接给a标签的href,
  520. * 文件过大时base64位长度过长;chrome浏览器对a标签的href长度有限制;导致下载失败;
  521. * 建议用以下方法处理成本地文件再下载
  522. * */
  523. function baseExel(base64) {
  524. function getContentType(base64) {
  525. return /data:([^;]*);/i.exec(base64)[1];
  526. };
  527. function getData(base64) {
  528. return base64.substr(base64.indexOf("base64,") + 7, base64.length);
  529. };
  530. function b64toBlob(b64Data, contentType, sliceSize) {
  531. contentType = contentType || '';
  532. sliceSize = sliceSize || 512;
  533. var byteCharacters = atob(b64Data);
  534. var byteArrays = [];
  535. for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  536. var slice = byteCharacters.slice(offset, offset + sliceSize);
  537. var byteNumbers = new Array(slice.length);
  538. for (var i = 0; i < slice.length; i++) {
  539. byteNumbers[i] = slice.charCodeAt(i);
  540. }
  541. var byteArray = new Uint8Array(byteNumbers);
  542. byteArrays.push(byteArray);
  543. }
  544. var blob = new Blob(byteArrays, {type: contentType});
  545. return blob;
  546. };
  547. return b64toBlob(getData(base64), getContentType(base64));
  548. }
  549. /**
  550. * 获取jqgrid的所有数据
  551. * @param tableId
  552. * @returns {any[]}
  553. */
  554. function getJQAllData(tableId) {
  555. //拿到grid对象
  556. var obj = $("#" + tableId);
  557. //获取grid表中所有的rowid值
  558. var rowIds = obj.getDataIDs();
  559. //初始化一个数组arrayData容器,用来存放rowData
  560. var arrayData = new Array();
  561. if (rowIds.length > 0) {
  562. for (var i = 0; i < rowIds.length; i++) {
  563. arrayData.push(obj.getRowData(rowIds[i]));
  564. }
  565. }
  566. return arrayData;
  567. }
  568. //base64转码
  569. function base64(s) {
  570. return window.btoa(unescape(encodeURIComponent(s)));
  571. };
  572. //替换table数据和worksheet名字
  573. function formatName(s, c) {
  574. return s.replace(/{(\w+)}/g,
  575. function (m, p) {
  576. return c[p];
  577. });
  578. };
  579. /**
  580. * ajax封装请求
  581. * @param config
  582. * @returns {Promise<any>}
  583. */
  584. function request(config) {
  585. return new Promise(((resolve, reject) => {
  586. $.ajax({
  587. type: config.method,
  588. url: url + config.url,
  589. data: config.data,
  590. contentType: "application/json;charset=UTF-8",
  591. dataType: "json",
  592. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  593. success: function (res) {
  594. if (res == '401' || res == 401) {
  595. window.location.href = '/thmz/login/view';
  596. return;
  597. }
  598. if (res.code == 0) {
  599. resolve(res);
  600. } else {
  601. new PNotify({
  602. title: '错误提示',
  603. text: res.message,
  604. type: 'error',
  605. hide: true,
  606. styling: 'bootstrap3'
  607. });
  608. reject(res)
  609. }
  610. },
  611. error: err => {
  612. new PNotify({
  613. title: '错误提示',
  614. text: err.responseText,
  615. type: 'error',
  616. hide: true,
  617. styling: 'bootstrap3'
  618. });
  619. reject(err)
  620. }
  621. });
  622. }))
  623. }
  624. /**
  625. * 医保凭证接口
  626. * @param config
  627. * @returns {Promise<any>}
  628. */
  629. function readcardRequest(config) {
  630. return new Promise(((resolve, reject) => {
  631. $.ajax({
  632. type: config.method,
  633. url: readcardUrl,
  634. data: config.data,
  635. contentType: "application/json;charset=UTF-8",
  636. dataType: "json",
  637. headers: {'Accept': 'application/json'},
  638. success: res => {
  639. if (res == '401' || res == 401) {
  640. window.location.href = '/thmz/login/view';
  641. return;
  642. }
  643. if (res.code == 200) {
  644. resolve(JSON.parse(res.data));
  645. } else {
  646. $("#showErrorModal").modal("show");
  647. hideModelTimeout('showErrorModal',3000);
  648. reject(res.message)
  649. }
  650. },
  651. error: err => {
  652. $("#showErrorModal").modal("show");
  653. hideModelTimeout('showErrorModal',3000);
  654. reject(err)
  655. }
  656. });
  657. }))
  658. }
  659. /**
  660. * 排序函数
  661. * @param property
  662. * @returns {function(*, *): number}
  663. */
  664. function compare(property) {
  665. return function (a,b) {
  666. var va1 = a[property];
  667. var va2 = b[property];
  668. return va1 - va2
  669. }
  670. }
  671. /**
  672. * 根据对象属性删除对象数组内容
  673. * @param array 对象数组
  674. * @param abj 对象
  675. * @param property 对象属性
  676. * @returns {*}
  677. */
  678. function removeObjArrayByProperty(array,abj,property) {
  679. for (let j = 0; j < array.length; j++) {
  680. if(abj != null && array[j][property] === abj[property]){
  681. array.splice(j,1);
  682. }
  683. }
  684. return array
  685. }
  686. /**
  687. * 获取LocalStorage
  688. * @param name
  689. * @param nullReturn
  690. */
  691. function getLocalStorage(name,nullReturn) {
  692. let returnValue = nullReturn ? nullReturn:-1;
  693. let data = window.localStorage[name];
  694. if(data){
  695. try {
  696. return JSON.parse(data);
  697. }catch (e) {
  698. return data;
  699. }
  700. }
  701. return returnValue;
  702. }
  703. /**
  704. * 指定区域全屏显示
  705. * @param divStr 指定元素ID
  706. */
  707. function fullScreen(divStr) {
  708. let fullarea = document.getElementById(divStr);
  709. if (fullscreen) {    // 退出全屏
  710. if (document.exitFullscreen) {
  711. document.exitFullscreen();
  712. } else if (document.webkitCancelFullScreen) {
  713. document.webkitCancelFullScreen();
  714. } else if (document.mozCancelFullScreen) {
  715. document.mozCancelFullScreen();
  716. } else if (document.msExitFullscreen) {
  717. document.msExitFullscreen();
  718. }
  719. } else {    // 进入全屏
  720. if (fullarea.requestFullscreen) {
  721. fullarea.requestFullscreen();
  722. } else if (fullarea.webkitRequestFullScreen) {
  723. fullarea.webkitRequestFullScreen();
  724. } else if (fullarea.mozRequestFullScreen) {
  725. fullarea.mozRequestFullScreen();
  726. } else if (fullarea.msRequestFullscreen) {
  727. // IE11
  728. fullarea.msRequestFullscreen();
  729. }
  730. }
  731. fullscreen = !fullscreen;
  732. }
  733. /**
  734. * 定时关闭模态框
  735. * @param str 模态框id
  736. * @param times 毫秒数
  737. */
  738. function hideModelTimeout(str,times){
  739. setTimeout(function () {
  740. $("#"+str).modal("hide");
  741. },times)
  742. }
  743. /**
  744. * 定义serializeObject方法,序列化表单
  745. */
  746. $.fn.serializeObject = function () {
  747. var o = {};
  748. var a = this.serializeArray();
  749. $.each(a, function () {
  750. if (o[this.name]) {
  751. if (!o[this.name].push) {
  752. o[this.name] = [o[this.name]];
  753. }
  754. o[this.name].push(this.value || '');
  755. } else {
  756. o[this.name] = this.value || '';
  757. }
  758. });
  759. return o;
  760. };
  761. /**
  762. * 获取药库药房名称
  763. * @param groupNo 编码
  764. */
  765. function getGroupName(groupNo) {
  766. let groupName;
  767. switch (groupNo){
  768. case '11':
  769. groupName='西药库';
  770. break;
  771. case '22':
  772. groupName='中药库';
  773. break;
  774. case '50':
  775. groupName='医材库';
  776. break;
  777. case '71':
  778. groupName='门诊西药房';
  779. break;
  780. case '73':
  781. groupName='住院药房';
  782. break;
  783. case '91':
  784. groupName='医材药房';
  785. break;
  786. }
  787. return groupName;
  788. }
  789. /**
  790. * 获取药品类型(大类)
  791. * @param groupNo 编码
  792. */
  793. function getYpTypeName(ypType) {
  794. let ypTypeName;
  795. switch (ypType){
  796. case '1':
  797. ypTypeName='西药';
  798. break;
  799. case '2':
  800. ypTypeName='成药';
  801. break;
  802. case '3':
  803. ypTypeName='草药';
  804. break;
  805. default:
  806. ypTypeName='卫生材料';
  807. }
  808. return ypTypeName;
  809. }
  810. //判断字符是否为空的方法
  811. function isEmpty(obj) {
  812. if (typeof obj == "undefined" || obj == null || obj == "") {
  813. return true;
  814. } else {
  815. return false;
  816. }
  817. }
  818. /**
  819. * 根据编码获取性别
  820. * @param code
  821. * @returns {string}
  822. */
  823. function getSex(code) {
  824. var sex = '';
  825. if (code == 1) {
  826. sex = '男';
  827. } else if (code == 2) {
  828. sex = '女';
  829. } else {
  830. sex = '未知';
  831. }
  832. return sex
  833. }
  834. /**
  835. * bootstrapTable修改列数据
  836. * @param index
  837. * @param field
  838. * @param value
  839. */
  840. function saveData(index, field, value,id) {
  841. $('#'+id).bootstrapTable('updateCell', {
  842. index: index, //行索引
  843. field: field, //列名
  844. value: value //cell值
  845. })
  846. }
  847. //将checkbox未选中将设置为指定值并系列化
  848. jQuery.fn.extend({
  849. serializeWithCheckbox: function (uncheckedValue) {
  850. return jQuery.param(this.serializeArrayWithCheckbox(uncheckedValue));
  851. },
  852. serializeArrayWithCheckbox: function (uncheckedValue) {
  853. var
  854. rCRLF = /\r?\n/g,
  855. rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
  856. rsubmittable = /^(?:input|select|textarea|keygen)/i,
  857. rcheckableType = (/^(?:radio)$/i); //仅将radio设置为不发送未选中项
  858. //未指定的转换为false
  859. if (uncheckedValue == undefined)
  860. uncheckedValue = 'false'
  861. uncheckedValue = uncheckedValue + '';//转字符串
  862. return this.map(function () {
  863. // Can add propHook for "elements" to filter or add form elements
  864. var elements = jQuery.prop(this, "elements");
  865. return elements ? jQuery.makeArray(elements) : this;
  866. })
  867. .filter(function () {
  868. var type = this.type;
  869. // Use .is( ":disabled" ) so that fieldset[disabled] works
  870. return this.name && !jQuery(this).is(":disabled") &&
  871. rsubmittable.test(this.nodeName) && !rsubmitterTypes.test(type) &&
  872. (this.checked || !rcheckableType.test(type));
  873. })
  874. .map(function (_i, elem) {
  875. var val = jQuery(this).val();
  876. if (val == null) {
  877. return null;
  878. }
  879. //将未勾选的checkbox值设置为指定值
  880. if (this.type == 'checkbox' && this.checked == false)
  881. val = uncheckedValue;
  882. if (Array.isArray(val)) {
  883. return jQuery.map(val, function (val) {
  884. return { name: elem.name, value: val.replace(rCRLF, "\r\n") };
  885. });
  886. }
  887. return { name: elem.name, value: val.replace(rCRLF, "\r\n") };
  888. }).get();
  889. }
  890. });
  891. /**
  892. * 初始化日期时间范围选择
  893. */
  894. function init_daterangepickertime() {
  895. if (typeof ($.fn.daterangepicker) === 'undefined') {
  896. return;
  897. }
  898. var optionSet1 = {
  899. startDate: moment().subtract(1, 'days').format("YYYY-MM-DD 00:00:00"),
  900. endDate: moment().subtract(1, 'days').format("YYYY-MM-DD 23:59:59"),
  901. minDate: '2012-01-01',
  902. maxDate: nowString() + ' 23:59:59',
  903. /*dateLimit: {
  904. days: 1200
  905. },//起止时间的最大间隔*/
  906. showDropdowns: true,
  907. showWeekNumbers: true,
  908. ranges: {
  909. '今天': [moment(), moment()],
  910. '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  911. '最近7天': [moment().subtract(6, 'days'), moment()],
  912. '最近30天': [moment().subtract(29, 'days'), moment()],
  913. '当月': [moment().startOf('month'), moment().endOf('month')],
  914. '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  915. },
  916. opens: 'right',
  917. buttonClasses: ['btn btn-default'],
  918. applyClass: 'btn-small btn-primary',
  919. cancelClass: 'btn-small',
  920. timePicker: true, //显示时间
  921. timePicker24Hour: true, //时间制
  922. timePickerSeconds: true, //时间显示到秒
  923. timePickerIncrement: 1,
  924. format: 'YYYY-MM-DD HH:mm:ss',
  925. separator: ' to ',
  926. locale: {
  927. applyLabel: '确定',
  928. cancelLabel: '取消',
  929. fromLabel: 'From',
  930. toLabel: 'To',
  931. customRangeLabel: '自定义',
  932. daysOfWeek: ['天', '一', '二', '三', '四', '五', '六'],
  933. monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  934. firstDay: 1
  935. }
  936. };
  937. $('#reportrange').daterangepicker(optionSet1, function (start, end, label) {
  938. $('#reportrange span').html(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
  939. });
  940. $('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD 00:00:00") + ' - ' + moment().subtract(1, 'days').format("YYYY-MM-DD 23:59:59"));
  941. }