const $ = require('jquery');
require("../css/allotCheckTask.less");
require('./modal.js');
const {api,ywCheckApi} = require('./api.js')
const {post,getCookie,emptyBox,listenScroll,getScoreTabList} = require('./utils.js')
require('./../resource/jquery-ui/jquery-ui.min.js');
require('./../resource/jquery-ui/jquery-ui.min.css');
const iconCheck= require("./../images/icon_check.png")
const iconUnCheck = require("./../images/icon_unchecked.png")
const iconRadio=require("./../images/radio.png")
const iconUnRadio=require("./../images/unradio.png")
const iconCalenBlue= require("./../images/icon_calen_blue.png")
const iconCalenGrey= require("./../images/icon_calen_grey.png")
const iconDown= require("./../images/arrow_down.png")
const iconUp = require("./../images/arrow_up.png")
const loadingImg = require("./../images/loading.gif")
const arrowLeft= require("./../images/arrow_left.png")
const arrowRight = require("./../images/arrow_right.png")
listenScroll()
let tabList = [], data_desc=["leaveHospitalDate"],data_asc=[],task_desc=["leaveHospitalDate"],task_asc=[];
let global_DeptCheckers = {},global_Checkers={4:[],5:[],6:[]},global_CheckerId='',global_CheckerName='',
global_DeptId='',//左边质控员科室筛选id
global_DeptMId="", //左边质检员选中/数字点击科室id
global_DeptAllId='', //右边任务科室筛选id(非科室任务才有)
global_deptData = {},global_activeTabCode='0',
global_TaskCodes=[],global_TaskDept=[],global_deleted=false,global_score='';
let isPlacefile = getCookie('isPlacefile')||1
/*if(isPlacefile != 1){
data_desc=["behospital_date"]
}*/
$(function() {
$(window.parent.document).find(".modaltip").hide();//切换页面过快时toast隐藏
const checkAuth = getCookie('checkAuth');
/*if(!checkAuth){
$(".tabs").hide();
toast("没有质控核查权限!");
return
}*/
const tabs = (checkAuth||'').replace(/[^456]/g,'');
if(tabs.length===0){
$(".tabs").hide();
toast("没有质控核查权限!");
return;
}else if(tabs.length<2){
//只有一个权限,隐藏tab切换
$(".tabs").hide();
}else{//隐藏没有权限的tab
const last = "456".replace(tabs,'');
$(".tabs [data-code="+(last-4)+"]").parent().hide();
}
global_activeTabCode=tabs.substr(0,1)-4;
$(".tabs [data-code="+global_activeTabCode+"]").addClass("active");
if(global_activeTabCode=='0'){
$(".patDeptFilter").hide();
}
//初始化日期
$.datepicker.regional['zh-CN'] = {
clearText: '清除',
clearStatus: '清除已选日期',
closeText: '关闭',
closeStatus: '不改变当前选择',
prevText: '<上月',
prevStatus: '显示上月',
prevBigText: '<<',
prevBigStatus: '显示上一年',
nextText: '下月>',
nextStatus: '显示下月',
nextBigText: '>>',
nextBigStatus: '显示下一年',
currentText: '今天',
currentStatus: '显示本月',
monthNames: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
monthNamesShort: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
yearNamesShort: ['一月','二月','三月','四月','五月','六月', '七月','八月','九月','十月','十一月','十二月'],
monthStatus: '选择月份',
yearStatus: '选择年份',
weekHeader: '周',
weekStatus: '年内周次',
dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
dayNamesMin: ['日','一','二','三','四','五','六'],
dayStatus: '设置 DD 为一周起始',
dateStatus: '选择 m月 d日, DD',
dateFormat: 'yy-mm-dd',
firstDay: 1,
initStatus: '请选择日期',
isRTL: false};
$.datepicker.setDefaults($.datepicker.regional['zh-CN']);
const days = new Date().getDate()-1;
let startDate = "-"+days+"d",endDate=new Date();
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd",
}).datepicker( "setDate", startDate);
$( "#datepicker2" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd",
}).datepicker( "setDate",endDate);
$( "#datepicker3" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd",
});
$( "#datepicker4" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd",
});
$('.datapickerBox').append(``)
$('.iconCalen').on("mouseenter", function(e){
$(this).attr("src", iconCalenBlue)
})
$('.iconCalen').on("mouseleave", function(e){
$(this).attr("src", iconCalenGrey)
})
$('.iconCalen').on("click", function(e){
$(this).parent().find("input").focus()
})
//保存分配
$(".save-btn").click(function(){
allotTask(0);
})
//菜单选中状态
$(".menu .page", parent.document).removeClass("active")
$(parent.document).find(".menu .page[code=YH-ZKHC-FPHCRW]").addClass("active")
//表格容器高度计算
setBoxHeight();
$(window).resize(function() {
setBoxHeight();
});
//切换tab
$(".tabBox .tabs button").on("click",(e)=>{
const me = e.target;
global_activeTabCode = $(me).attr("data-code");
$(".tabBox .tabs button").removeClass("active");
$(me).addClass("active");
if(global_activeTabCode=='0'){
$(".patDeptFilter").hide();
}else{
$(".patDeptFilter").show();
}
clearCheckerFilter();
clearFilter();
//刷新质控员、任务列表
//getCheckerList();
//const data = global_Checkers[+global_activeTabCode+4];
getCheckerList();
getTabData(1);
/*rendeDeptList();
rendeCheckerList();
renderCheckerTable();*/
});
//任务筛选
$(".filter").on("click", function(e){
const behosDateStart1 = $("#datepicker").val() //生成日期
const behosDateEnd1 = $("#datepicker2").val()
const behosDateStartTime1 = new Date(behosDateStart1).getTime()
const behosDateEndTime1 = new Date(behosDateEnd1).getTime()
const behosDateStart = $("#datepicker3").val() //出院日期
const behosDateEnd = $("#datepicker4").val()
const behosDateStartTime = new Date(behosDateStart).getTime()
const behosDateEndTime = new Date(behosDateEnd).getTime()
console.log(222,behosDateStartTime1,behosDateEndTime1)
if(behosDateStartTime1 > behosDateEndTime1){
$.alerModal({"message":'生成日期开始时间不能大于结束时间~',type:"tip",time:'1000',isFather: true, fatherWrapper: $("#mainBox", parent.document)});
return
}
if(behosDateStartTime > behosDateEndTime){
$.alerModal({"message":'出院日期开始时间不能大于结束时间~',type:"tip",time:'1000',isFather: true, fatherWrapper: $("#mainBox", parent.document)});
return
}
getTabData(1)
})
//重置
$(".abnormalClear").on("click", function(e){
clearFilter();
getTabData(1)
})
//关闭弹窗事件
$(".modal-container .close").click(function(){
$(".modal-container").hide();
if(global_deleted){
//移除后关闭弹窗时清空质控员选中状态:质控员id/name/科室id及右侧选中任务code
//并刷新左侧和右侧列表
global_CheckerId='';
global_CheckerName='';
global_DeptMId='';
global_TaskCodes=[];
getCheckerList();
getTabData(1);
}
});
//科室选择
$('.selectDept').on("click", function(e){
e.stopPropagation()
$(".checkerList ").css("display", "none")
$(".deptAllList ").css("display","none")
$(".scoreList ").css("display","none")
$(".selectChecker .arrow").attr("src",iconDown)
$(".deptList ").css("display","block")
})
//筛选分值选择
$('.selectScore').on("click", function(e){
e.stopPropagation();
$(".deptList ").css("display","none")
$(".checkerList ").css("display", "none")
$(".deptAllList ").css("display","none")
$(".selectDept .arrow").attr("src",iconDown)
$(".selectScore .arrow").attr("src",iconDown)
$(".scoreList ").css("display","block")
})
//病人科室选择
$('.selectAllDept').on("click", function(e){
e.stopPropagation()
$(".checkerList ").css("display", "none")
$(".scoreList").css("display", "none")
$(".deptList ").css("display", "none")
$(".deptAllList ").css("display","block")
})
//质控员选择
$('.selectChecker').on("click", function(e){
e.stopPropagation()
$(".deptList ").css("display", "none")
$(".scoreList").css("display", "none")
$(".checkerList").css("display","block")
})
//关闭下拉事件
$(document).on("click", function(){
$(".deptList ").css("display", "none")
$(".deptAllList ").css("display", "none")
$(".checkerList").css("display", "none")
$(".scoreList").css("display", "none")
/*$(".scoreDept .arrow").attr("src",iconDown)
$(".selectDept .arrow").attr("src",iconDown)
$(".selectAllDept .arrow").attr("src",iconDown)
$(".selectChecker .arrow").attr("src",iconDown)*/
})
getScoreTabList((data)=>{rendeScoreList(data)})
//获取科室列表
getAllDeptList()
//获取核查人员列表
getCheckerList()
getTabData(1)
});
//高度适应
function setBoxHeight() {
const ht = window.innerHeight;
$('.table-cont').height(ht - 319 + 'px');
$('.overAuto').height(ht - 174 + 'px');
}
//病人列表获取筛选值
function getFilterData(){
const obj = {};
$(".overAuto.fr .filterBox input[code]").map((i,it)=>{
obj[$(it).attr("code")]=$(it).val()
})
return obj;
}
//获取分配核查任务列表数据
function getTabData(activePage){
const filterData = getFilterData();
let dept = '';
if(global_activeTabCode!='0'){ //除科室任务外,待分配任务列表科室参数只受筛选项影响
dept = global_DeptAllId;
}else{
dept = global_DeptMId||global_DeptId||global_DeptAllId;
}
const deptList=dept.trim()?[dept]:[];
const param = {
current:activePage,
asc:data_asc, //升序
desc:data_desc, //降序
size: 15,
jobType:global_activeTabCode, //0-科室任务 1-院级 2-质控科
...filterData,
deptList:deptList,
values:global_score.trim()?[global_score]:[],
endTime:filterData.endTime+" 23:59:59"
};
$('.pagination').html("");
$('.patientTable .tbody').html(emptyBox('努力加载中...','',8))
return post(ywCheckApi.getAllotCheckList,param).then(res =>{
if(res.data.code == '0'){
const data = res.data.data||{};
tabList = data.records;
const totalPage = data.pages;
const totalNum = data.total;
renderTab(tabList)
renderPagination(totalPage,Number(activePage),totalNum)
if(totalPage > 0){
renderPagination(totalPage,Number(activePage),totalNum)
} else{
$('.pagination').html("")
}
}else{
$.alerModal({"message":res.data.msg,type:"tip",time:'1000',isFather: true, fatherWrapper: $("#mainBox", parent.document)});
}
}).catch((e) =>{
})
}
function clearCheckerFilter(){
$('.selectDept i').text('全部')
$('.selectAllDept i').text('全部')
$(".deptList").css("display", "none")
$(".deptAllList").css("display", "none")
$('.selectChecker i').text('全部')
$(".checkerList").css("display", "none")
global_DeptMId="";
global_DeptId="";
global_CheckerId="";
global_CheckerName="";
}
function clearFilter(){
$(".overAuto.fr input").val("");
data_desc=["leaveHospitalDate"];
$('.selectAllDept i').text('全部')
$('.selectAllDept').attr('title','全部')
$(".deptAllList").css("display", "none")
$('.selectScore i').html('全部')
$(".scoreList").css("display", "none")
global_score='';
global_DeptAllId="";
/*if(isPlacefile != 1){
data_desc=["behospital_date"]
}*/
data_asc=[];
//默认日期为本月
const days = new Date().getDate()-1;
let startDate = "-"+days+"d",endDate=new Date();
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd",
}).datepicker( "setDate", startDate);
$( "#datepicker2" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd"
}).datepicker( "setDate",endDate);
$( "#datepicker3" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd",
});
$( "#datepicker4" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat:"yy-mm-dd"
});
$("th[code]").removeClass("asc desc")
}
//病人列表排序事件
function bindOrder(){
$(".patientTable th[code]").off("click").on("click",function(e){
const code=$(this).attr("code");
if(data_asc[0]===code){
data_desc=[code];
data_asc=[];
$("th[code]").removeClass("asc desc");
$(this).addClass("desc");
}else{
data_desc=[];
data_asc=[code];
$("th[code]").removeClass("asc desc");
$(this).addClass("asc");
}
getTabData(1);
// console.log(code)
});
}
//已分配列表排序事件
function bindTaskOrder(){
$(".taskTable th[code]").off("click").on("click",function(e){
const code=$(this).attr("code");
if(task_asc[0]===code){
task_desc=[code];
task_asc=[];
$(".taskTable th[code]").removeClass("asc desc");
$(this).addClass("desc");
}else{
task_desc=[];
task_asc=[code];
$(".taskTable th[code]").removeClass("asc desc");
$(this).addClass("asc");
}
getTasksList();
// console.log(code)
});
}
//筛选分值下拉
function rendeScoreList(list){
if(list.length == 0){
$('.scoreList').html("")
return
}
let str = `