//@ sourceURL=spirit_anesthetic_print.js
var LODOP; //声明为全局变量
$(function () {
initDeptSelect(0,"unitCodeSearch");
init_daterangepickertime();
setTimeout(function () {
getLodop();
}, 800);
$("#jmtj_table").hide();
$(".selectpicker").selectpicker({
dropuAuto: false
});
//初始化页面上面的按钮事件
$("#btn_search").click(function (t) {
$('.sjh').remove();
if($('#drugFlagSearch').val() == 0){
getSendDrugRecordData();
}else{
getSpiritAnestheticPrintData();
}
});
$('#btn_clean').click(function () {
cleanParams();
});
$("#btn_daily").click(function (t) {
print();
});
$("#btn_excel").click(function (t) {
let id = "qbtj_table";
let name = "药品发药明细统计表";
if($("#qbtj_table").is(':hidden')){
id = "jmtj_table";
let drugFlag = $("#drugFlagSearch").val();
if(drugFlag == 1){
name = "麻、精一及麻黄碱类药品使用登记";
}else if(drugFlag == 2){
name = "终止妊娠药统计";
}else if(drugFlag == 3){
name = "精二类统计";
}
}
$("#"+id).table2excel({
exclude:".exclHide",
filename:name+"("+getRePortRangeArr()[0].substring(0,getRePortRangeArr()[0].indexOf(" ")+1)+").xls"
})
});
$("#drugFlagSearch").change(function (t,d,e) {
let drugFlag = $("#drugFlagSearch").val();
let title = "";
if(drugFlag == 1){
title = "麻、精一及麻黄碱类药品使用登记";
$("#jmtj_table").show();
$("#qbtj_table").hide();
}else if(drugFlag == 2){
title = "终止妊娠药统计";
$("#jmtj_table").show();
$("#qbtj_table").hide();
}else if(drugFlag == 3){
title = "精二类统计";
$("#jmtj_table").show();
$("#qbtj_table").hide();
}else if(drugFlag == 0){
title = "药品发药明细统计表";
$("#qbtj_table").show();
$("#jmtj_table").hide();
}
$(".title").html(title);
$(".dateRange").html($('#reportrange span').html());
$(".printDate").html(format(new Date(),"yyyy-MM-dd HH:mm"));
});
//初始化药品查询弹出框
initSearchList('
',
'searchTextDrug', 700, 250);
$('#searchTextDrug').on('input focus',function(e){
showDrugPopover();
if($('#searchTextDrug').val() == ''){
$('#codeSearch').val("");
$('#serialSearch').val("");
}
});
});
/**
* 获取精麻药统计报表
*/
function getSpiritAnestheticPrintData() {
$(".dateRange").html($('#reportrange span').html());
$(".printDate").html(format(new Date(),"yyyy-MM-dd HH:mm"));
$.ajax({
type: "GET",
url: '/thmz/getSpiritAnestheticPrint',
contentType: "application/json;charset=UTF-8",
dataType: "json",
headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
data: queryParams(),
success: function (res) {
if (res == '401' || res == 401) {
window.location.href = '/thmz/login/view'
return;
}
if (res.code == 0) {
let html = '';
let code = '';
let number = 0;
let sex;
let drugFlag = $("#drugFlagSearch").val();
for (var i = 0; i < res.data.length; i++) {
let data = res.data[i];
if(code == ''){
code = data.chargeItemCode;
number += parseFloat(data.quantity);
}else if(code == data.chargeItemCode){
number += parseFloat(data.quantity);
}else{
html += '';
html += '共计:' + number + ' | ';
html += '
';
code = data.chargeItemCode;
number = parseFloat(data.quantity);
}
if(data.sex == 1){
sex = "男"
}else if(data.sex == 2){
sex = "女"
}else{
sex = "未知"
}
html += '';
html += '' + data.chargeDate.substring(5,11) + ' | ';
html += '' + data.patientId + ' | ';
html += '' + data.name + ' | ';
html += '' + sex + ' | ';
html += '' + data.age + ' | ';
html += '' + data.socialNo + ' | ';
html += '' + data.icdText + ' | ';
html += '' + data.chargeItemCode + ' | ';
html += '' + data.drugname + ' | ';
html += '' + data.specification + ' | ';
html += '' + data.quantity + ' | ';
html += '' + data.employeeName.trim() + ' | ';
html += '' + data.warnDeptName + ' | ';
html += ' | ';
html += ' | ';
html += '
';
}
html += '';
html += '共计:' + number + ' | ';
html += '
';
$("#jmtj_table").append(html);
} else if (res.code == -1) {
new PNotify({
title: '错误提示',
text: res.message,
type: 'error',
hide: true,
styling: 'bootstrap3'
});
}
}
});
}
/**
* 获取所有药品类型统计报表
*/
function getSendDrugRecordData() {
$('#YWaitDialog').css('top',$('.xtd').offset().top);
$('#YWaitDialog').show();
$(".dateRange").html($('#reportrange span').html());
$(".printDate").html(format(new Date(),"yyyy-MM-dd HH:mm"));
$.ajax({
type: "POST",
url: '/thmz/getSendDrugRecord',
contentType: "application/json;charset=UTF-8",
dataType: "json",
headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
data: JSON.stringify({
'beginDate': getRePortRangeArr()[0],
'endDate': getRePortRangeArr()[1],
'chargeCode': $('#codeSearch').val()==''?null:$('#codeSearch').val(),
'serial': $('#serialSearch').val()==''?null:$('#serialSearch').val(),
'warnDept': $('#unitCodeSearch').val()!=null?$('#unitCodeSearch').val()[0]:null,
'queryScope': $("#queryScopeSearch").val()
}),
success: function (res) {
$('#YWaitDialog').hide();
if (res == '401' || res == 401) {
window.location.href = '/thmz/login/view'
return;
}
if (res.code == 0) {
let html = '';
let flag = '';//区分门诊住院 -1住院 其它门诊
let number = 0;
let totalNumber = 0;
let sex;
for (var i = 0; i < res.data.length; i++) {
let data = res.data[i];
if(flag == ''){
flag = data.id.indexOf("-")!=-1?'0':'1';
number += parseFloat(data.quantity);
}else if(flag == (data.id.indexOf("-")!=-1?'0':'1')){
number += parseFloat(data.quantity);
}else{
html += '';
html += '小计:' + number + ' | ';
html += ' | ';
html += '
';
flag = data.id.indexOf("-")!=-1?'0':'1';
totalNumber += number;
number = parseFloat(data.quantity);
}
if(data.sex == 1){
sex = "男"
}else if(data.sex == 2){
sex = "女"
}else{
sex = "未知"
}
let queryScope = data.id.indexOf("-")!=-1?'门诊':'住院';
let age = data.birthDay!=null?getBirthSlot(data.birthDay,new Date()):'';
html += '';
html += '' + data.id + ' | ';
html += '' + data.name + ' | ';
html += '' + sex + ' | ';
html += '' + age.substring(0,age.indexOf('岁')) + ' | ';
html += '' + data.warnDeptName + ' | ';
html += '' + data.icdText + ' | ';
html += '' + data.chargeCode + ' | ';
html += '' + data.drugName + ' | ';
html += '' + data.specification + ' | ';
html += '' + data.abbrName + ' | ';
html += '' + data.quantity + ' | ';
html += '' + data.chargeDate + ' | ';
html += '' + data.employeeName.trim().substring(0,1)+new Array(data.employeeName.trim().length).join('*') + ' | ';
html += '' + data.supplyName + ' | ';
html += '' + data.frequency + ' | ';
html += '' + queryScope + ' | ';
html += '
';
}
html += '';
html += '小计:' + number + ' | ';
html += ' | ';
html += '
';
html += '';
html += '总计:' + parseFloat(totalNumber+number) + ' | ';
html += ' | ';
html += '
';
$("#qbtj_table").append(html);
} else if (res.code == -1) {
new PNotify({
title: '错误提示',
text: res.message,
type: 'error',
hide: true,
styling: 'bootstrap3'
});
}
}
});
}
/**
* 获取按钮组选择的下标
* @param id
* @returns {number}
*/
function getIndex(id) {
var index = 0;
var item = $("#" + id).find("button");
for (var i = 0; i <= item.length; i++) {
if ($(item[i]).hasClass("btn-primary")) {
index = i;
break;
}
}
return index;
}
/**
* 获取时间选择器的时间数组
* @returns {string[]}
*/
function getRePortRangeArr() {
var rePortRange = $('#reportrange span').html();
var rePortRangeArr = rePortRange.split(" - ");
return rePortRangeArr;
}
/**
* 清空查询条件
*/
function cleanParams() {
$("#queryScopeSearch").val(0);
$('#queryScopeSearch').selectpicker('refresh');
$('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD 14:00:00") + ' - ' + moment().format("YYYY-MM-DD 13:59:59"));
$('#unitCodeSearch').empty();
$('#drugFlagSearch').val(0);
$('#qbtj_table').show();
$('#jmtj_table').hide();
$('.sjh').remove();
$('#drugFlagSearch').selectpicker('refresh');
$("#unitCodeSearch").html('');
$("#unitCodeSearch").selectpicker('refresh');
$('#searchTextDrug').empty();
$('#codeSearch').empty();
$('#serialSearch').empty();
}
/**
* 打印报表
*/
function print() {
setDefaultPrint();
LODOP = getLodop();
LODOP.PRINT_INITA(6, 0, "210mm", "297mm", "药品发放统计表");
LODOP.SET_PRINT_PAGESIZE(2, 0, 0,"A4");
//设置默认打印机
LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
LODOP.SET_PRINT_STYLE("FontSize", 10); //字体大小
LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
//设置默认打印机
LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
LODOP.ADD_PRINT_TEXT('200mm','140mm','40mm','40mm','第#页/共&页');
LODOP.SET_PRINT_STYLEA(0,"ItemType",2);
var strStyle="";
LODOP.ADD_PRINT_HTM("2mm", "4mm", "RightMargin:4mm", "BottomMargin:15mm",strStyle+ document.getElementById("report_table_1").innerHTML);
LODOP.PRINT();
//LODOP.PREVIEW();
}
/**
* 统计列表查询参数
*/
function queryParams() {
let drugFlags = new Array();
let flag = $("#drugFlagSearch").val();
if(flag == 1){
drugFlags[0] = 2;
drugFlags[1] = 3;
drugFlags[2] = 5;
}else if(flag == 2){
drugFlags[0] = 6;
}else if(flag == 3){
drugFlags[0] = 1;
drugFlags[1] = 4;
}
var temp = {
beginDate: getRePortRangeArr()[0],
endDate: getRePortRangeArr()[1],
chargeItemCode: $('#codeSearch').val(),
unitCode: $('#unitCodeSearch').val()!=null?$('#unitCodeSearch').val()[0]:'',
drugFlags: drugFlags,
queryScope: $("#queryScopeSearch").val()
};
return temp;
}
function init_daterangepickertime() {
if (typeof ($.fn.daterangepicker) === 'undefined') {
return;
}
var optionSet1 = {
startDate: moment().subtract(1, 'days').format("YYYY-MM-DD 00:00:00"),
endDate: moment().subtract(1, 'days').format("YYYY-MM-DD 23:59:59"),
minDate: '2012-01-01',
maxDate: nowString()+' 23:59:59',
dateLimit: {
days: 1200
},
showDropdowns: true,
showWeekNumbers: true,
ranges: {
'今天': [moment(), moment()],
'昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'最近7天': [moment().subtract(6, 'days'), moment()],
'最近30天': [moment().subtract(29, 'days'), moment()],
'当月': [moment().startOf('month'), moment().endOf('month')],
'上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
opens: 'right',
buttonClasses: ['btn btn-default'],
applyClass: 'btn-small btn-primary',
cancelClass: 'btn-small',
timePicker: true, //显示时间
timePicker24Hour: true, //时间制
timePickerSeconds: true, //时间显示到秒
timePickerIncrement: 1,
format: 'YYYY-MM-DD HH:mm:ss',
separator: ' to ',
locale: {
applyLabel: '确定',
cancelLabel: '取消',
fromLabel: 'From',
toLabel: 'To',
customRangeLabel: '自定义',
daysOfWeek: ['天', '一', '二', '三', '四', '五', '六'],
monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
firstDay: 1
}
};
$('#reportrange').daterangepicker(optionSet1, function (start, end, label) {
$('#reportrange span').html(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
});
$('#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"));
}