| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- //@ sourceURL=pharmacy-com.js
- var readcardUrl = 'http://localhost:8321/readcard/entry';
- var url = '/thmz';
- /**
- * 加载搜索窗口
- */
- function initSearchList(content, searchTextId, width, height) {
- var settings = {
- placement: 'bottom-right',//值: auto,top,right,bottom,left,top-right,top-left,bottom-right,bottom-left 要显示的位置
- trigger: 'click', //值:click,hover 触发方式
- content: '',//内容,内容可以是函数
- width: width,
- //arrow:false,//是否显示箭头
- multi: true,//在页面允许其他弹出层
- closeable: true,//显示关闭按钮
- style: '', //值:'',inverse
- delay: 300,//延迟时间, 悬浮属性才执行
- padding: true,//内容填充
- height: height,
- //offsetTop:10,
- cache: true,//如果缓存设置为false,则popover将销毁并重新创建
- content: content
- };
- $('#' + searchTextId).webuiPopover('destroy').webuiPopover(settings);
- }
- /**
- * 修改列数据
- * @param $table 表格元素
- * @param index 行索引
- * @param field 列名
- * @param value cell值
- */
- function saveCellData($table, index, field, value) {
- $table.bootstrapTable('updateCell', {
- index: index,
- field: field,
- value: value
- })
- }
- /**
- * 科室列表
- */
- function initDeptSelect(flag, id) {
- var url = "";
- if (flag == 0) {
- url = "/thmz/allUnitCode"
- } else if (flag == 1) {
- url = "/thmz/allMzUnitCode"
- }
- //科室列表
- $.ajax({
- type: "GET",
- url: url,
- dataType: "json",
- headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
- success: function (data) {
- if (data == '401' || data == 401) {
- window.location.href = '/thmz/login/view';
- return;
- }
- var html = '';
- $.each(data.data, function (commentIndex, comment) {
- html += '<option value="' + comment.code + '">' + comment.name + '(' + comment.pyCode + ')</option>';
- });
- $('#' + id).empty();
- $('#' + id).html(html);
- $('#' + id).selectpicker('refresh');
- }
- });
- }
- /**
- * 四舍五入保留2位小数(若第二位小数为0,则保留一位小数)
- * @param num
- * @returns {*}
- */
- function keepTwoDecimal(num) {
- var result = parseFloat(num);
- if (isNaN(result)) {
- return false;
- }
- result = Math.round(num * 100) / 100;
- return result;
- }
- //默认打印机下标
- var defaultPrintIndex = -1;
- /**
- * 查询默认打印机
- */
- function setDefaultPrint() {
- if (defaultPrintIndex >= 0) {
- return;
- }
- $.ajax({
- type: "GET",
- url: '/thmz/getLastWindowsByCurrentUser',
- contentType: "application/json;charset=UTF-8",
- dataType: "json",
- headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
- async: false,
- success: function (res) {
- if (res == '401' || res == 401) {
- window.location.href = '/thmz/login/view'
- return;
- }
- if (res.code == 0) {
- defaultPrintIndex = res.data.cgPrintIndex;
- } else {
- defaultPrintIndex = -1;
- }
- }
- });
- }
- //显示查询所有药品悬浮窗
- function showDrugPopover() {
- $('#tb_table_medicine').bootstrapTable('destroy');
- $('#tb_table_medicine').bootstrapTable({
- url: '/thmz/getYp', //请求后台的URL(*)
- method: 'GET', //请求方式(*)
- toolbar: '#toolbar', //工具按钮用哪个容器
- striped: true, //是否显示行间隔色
- cache: true, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
- pagination: false, //是否显示分页(*)
- sortable: true, //是否启用排序
- sortOrder: "asc", //排序方式
- queryParams: {
- searchTextDrug: $("#searchTextDrug").val() == "" ? null : $("#searchTextDrug").val(),
- },
- sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
- pageNumber: 1, //初始化加载第一页,默认第一页
- pageSize: 5, //每页的记录行数(*)
- pageList: [5, 10, 25, 50, 100], //可供选择的每页的行数(*)
- search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
- strictSearch: true,
- showColumns: false, //是否显示所有的列
- showRefresh: false, //是否显示刷新按钮
- minimumCountColumns: 2, //最少允许的列数
- clickToSelect: true, //是否启用点击选中行
- uniqueId: "ID", //每一行的唯一标识,一般为主键列
- showToggle: false, //是否显示详细视图和列表视图的切换按钮
- cardView: false, //是否显示详细视图
- detailView: false,
- //rowStyle:rowStyle,//通过自定义函数设置行样式
- ajaxOptions: {
- headers: {
- 'Accept': 'application/json',
- 'Authorization': 'Bearer ' + localStorage.getItem("token")
- }
- },
- columns: [
- {
- field: 'code',
- title: '编码',
- align: "center",
- valign: 'middle'
- }, {
- field: 'name',
- title: '药品名',
- align: "center",
- valign: 'middle'
- }, {
- field: 'manufactoryName',
- title: '厂家',
- align: "center",
- valign: 'middle'
- },
- {
- field: 'specification',
- title: '规格',
- align: "center",
- valign: 'middle'
- },
- {
- field: 'packRetprice',
- title: '零售价',
- align: "center",
- valign: 'middle'
- }, {
- field: 'delFlag',
- title: '已作废',
- align: "center",
- valign: 'middle',
- formatter: function (value, row, index) {
- return value == 1 ? '<span style="color: red">是</span>' : '否';
- }
- }
- ],
- responseHandler: function (res) {
- if (res == '401' || res == 401) {
- window.location.href = '/thmz/login/view'
- return;
- }
- var ress = eval(res);
- if (ress.code == -1) {
- errorMesage(res);
- return {
- "total": 0,//总页数
- "rows": {} //数据
- };
- }
- return {
- "total": ress.data.length,//总页数
- "rows": ress.data //数据
- };
- },
- onClickRow: function (row, $element) {
- $('#searchTextDrug').webuiPopover('hide');
- $('#codeSearch').val(row.code);
- $('#serialSearch').val(row.serial);
- $('#searchTextDrug').val(row.name);
- }
- });
- }
- /**
- * 将table导出Excel
- * @param tableid
- * @param sheetName
- */
- function tableToExcel(tableid, sheetName) {
- var uri = 'data:application/vnd.ms-excel;base64,';
- var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"' +
- 'xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>'
- + '<x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>'
- + '</x:ExcelWorkbook></xml><![endif]-->' +
- '<style type="text/css">' +
- 'table td{' +
- 'border: 1px solid #000000;' +
- 'width: 150px;' +
- 'height: 30px;' +
- 'text-align: center;' +
- '}' +
- '.xtd{' +
- 'border: 1px solid #000000;' +
- 'width: 50px;' +
- 'height: 30px;' +
- 'text-align: center;' +
- '}' +
- '</style>' +
- '</head><body ><table class="excelTable">{table}</table></body></html>';
- if (!tableid.nodeType) tableid = document.getElementById(tableid);
- var ctx = {worksheet: sheetName || 'Worksheet', table: tableid.innerHTML};
- var blobExel = self.baseExel(uri + base64(formatName(template, ctx))); //把base64位文件转化为exel文件
- document.getElementById("btn_excel").href = URL.createObjectURL(blobExel);
- document.getElementById("btn_excel").download = ctx.worksheet;
- console.log(document.getElementById("btn_excel").href);
- }
- /*处理后端返回的base64位文件变成exel文件进行下载
- * 不要直接把base64位的exel文件直接给a标签的href,
- * 文件过大时base64位长度过长;chrome浏览器对a标签的href长度有限制;导致下载失败;
- * 建议用以下方法处理成本地文件再下载
- * */
- function baseExel(base64) {
- function getContentType(base64) {
- return /data:([^;]*);/i.exec(base64)[1];
- };
- function getData(base64) {
- return base64.substr(base64.indexOf("base64,") + 7, base64.length);
- };
- function b64toBlob(b64Data, contentType, sliceSize) {
- contentType = contentType || '';
- sliceSize = sliceSize || 512;
- var byteCharacters = atob(b64Data);
- var byteArrays = [];
- for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
- var slice = byteCharacters.slice(offset, offset + sliceSize);
- var byteNumbers = new Array(slice.length);
- for (var i = 0; i < slice.length; i++) {
- byteNumbers[i] = slice.charCodeAt(i);
- }
- var byteArray = new Uint8Array(byteNumbers);
- byteArrays.push(byteArray);
- }
- var blob = new Blob(byteArrays, {type: contentType});
- return blob;
- };
- return b64toBlob(getData(base64), getContentType(base64));
- }
- /**
- * 获取jqgrid的所有数据
- * @param tableId
- * @returns {any[]}
- */
- function getJQAllData(tableId) {
- //拿到grid对象
- var obj = $("#" + tableId);
- //获取grid表中所有的rowid值
- var rowIds = obj.getDataIDs();
- //初始化一个数组arrayData容器,用来存放rowData
- var arrayData = new Array();
- if (rowIds.length > 0) {
- for (var i = 0; i < rowIds.length; i++) {
- arrayData.push(obj.getRowData(rowIds[i]));
- }
- }
- return arrayData;
- }
- //base64转码
- function base64(s) {
- return window.btoa(unescape(encodeURIComponent(s)));
- };
- //替换table数据和worksheet名字
- function formatName(s, c) {
- return s.replace(/{(\w+)}/g,
- function (m, p) {
- return c[p];
- });
- };
- /**
- * ajax封装请求
- * @param config
- * @returns {Promise<any>}
- */
- function request(config) {
- return new Promise(((resolve, reject) => {
- $.ajax({
- type: config.method,
- url: url + config.url,
- data: JSON.stringify(config.data),
- contentType: "application/json;charset=UTF-8",
- dataType: "json",
- headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
- success: function (res) {
- if (res == '401' || res == 401) {
- window.location.href = '/thmz/login/view';
- return;
- }
- if (res.code == 0) {
- resolve(res);
- } else {
- new PNotify({
- title: '错误提示',
- text: res.message,
- type: 'error',
- hide: true,
- styling: 'bootstrap3'
- });
- reject(res)
- }
- },
- error: err => {
- new PNotify({
- title: '错误提示',
- text: err.responseText,
- type: 'error',
- hide: true,
- styling: 'bootstrap3'
- });
- reject(err)
- }
- });
- }))
- }
- /**
- * 医保凭证接口
- * @param config
- * @returns {Promise<any>}
- */
- function readcardRequest(config) {
- return new Promise(((resolve, reject) => {
- $.ajax({
- type: config.method,
- url: readcardUrl,
- data: config.data,
- contentType: "application/json;charset=UTF-8",
- dataType: "json",
- headers: {'Accept': 'application/json'},
- success: res => {
- if (res == '401' || res == 401) {
- window.location.href = '/thmz/login/view';
- return;
- }
- if (res.code == 200) {
- resolve(JSON.parse(res.data));
- } else {
- $("#showErrorModal").modal("show");
- reject(res.message)
- }
- },
- error: err => {
- $("#showErrorModal").modal("show");
- reject(err)
- }
- });
- }))
- }
- /**
- * 排序函数
- * @param property
- * @returns {function(*, *): number}
- */
- function compare(property) {
- return function (a,b) {
- var va1 = a[property];
- var va2 = b[property];
- return va1 - va2
- }
- }
- /**
- * 根据对象属性删除对象数组内容
- * @param array 对象数组
- * @param abj 对象
- * @param property 对象属性
- * @returns {*}
- */
- function removeObjArrayByProperty(array,abj,property) {
- for (let j = 0; j < array.length; j++) {
- if(abj != null && array[j][property] === abj[property]){
- array.splice(j,1);
- }
- }
- return array
- }
- /**
- * 获取LocalStorage
- * @param name
- * @param nullReturn
- */
- function getLocalStorage(name,nullReturn) {
- let returnValue = nullReturn ? nullReturn:-1;
- let data = window.localStorage[name];
- if(data){
- try {
- return JSON.parse(data);
- }catch (e) {
- return data;
- }
- }
- return returnValue;
- }
|