123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- //@ sourceURL=to-medicine-test.js
- //待取药队列
- var currentList = new Array();
- //过号名单队列
- var pastList = new Array();
- //正在配药队列
- var dispenseList = new Array();
- //正在取药
- var rightPerson = null;
- //临时待取药队列
- var tempCurrentList = new Array();
- //临时过号名单
- var tempPastList = new Array();
- //临时正在配药队列
- var tempDispenseList = new Array();
- //待取药队列是否已经加载完成
- var currentListHadDone = true;
- //过号名单队列是否已经加载完成
- var pastListHadDone = true;
- //正在配药名单队列是否已经加载完成
- var dispenseListHadDone = true;
- //药房编号
- var groupNo = null;
- $(function () {
- $(".selectpicker").selectpicker({
- dropuAuto: false
- });
- var yesNo = '<option value="71">门诊西药房</option><option value="81">门诊中药房</option><option value="82">颗粒剂药房</option>';
- $('#fyClass').html(yesNo);
- $('#fyClass').selectpicker('refresh');
- $("#editModal").modal("show");
- //进入页面就加载一次
- CurentTime();
- intClock();
- //每秒获取当前时间
- setInterval(CurentTime, 1000);
- //三十秒从后台拉一次数据
- //setInterval(getTableDate, 30000);
- //getTableDate();
- //设置页面宽度
- setHeightForTable();
- $(window).resize(function () {
- //设置页面宽度
- setHeightForTable();
- });
- $(document).keyup(function (event) {
- if (event.keyCode == 13) {
- initTable();
- }
- });
- });
- /**
- * 设置页面宽度
- */
- function setHeightForTable() {
- var height = $(window).height() - 320;
- var realHeigt = height / 7;
- if (realHeigt < 88) {
- realHeigt = 88;
- }
- $("#tableList tr").css("height", realHeigt + "px");
- }
- /**
- * 取当前时间 格式 yyyy年mm月dd日 hh:mm:ss weekday
- * @constructor
- */
- function CurentTime() {
- var now = new Date();
- var year = now.getFullYear(); //年
- var month = now.getMonth() + 1; //月
- var day = now.getDate(); //日
- var hh = now.getHours(); //时
- var mm = now.getMinutes(); //分
- // var ss=now.getSeconds(); //秒
- var weekday = new Array(7) //周
- weekday[0] = "星期日"
- weekday[1] = "星期一"
- weekday[2] = "星期二"
- weekday[3] = "星期三"
- weekday[4] = "星期四"
- weekday[5] = "星期五"
- weekday[6] = "星期六"
- var date = year + "年";
- if (month < 10) date += "0";
- date += month + "月";
- if (day < 10) date += "0";
- date += day + "日 ";
- date += " " + weekday[now.getDay()];
- $("#dateNow").html(date);
- var time = "";
- if (hh < 10) time += "0";
- time += hh + ":";
- if (mm < 10) time += '0';
- time += mm;
- $("#timeNow").html(time)
- }
- /**
- * 初始化时钟
- */
- function intClock() {
- var audioElement = new Audio("");
- //clock plugin constructor
- $('#myclock').thooClock({
- //size:$(document).height()/1.4,
- size: 80,
- onAlarm: function () {
- //all that happens onAlarm
- //$('#alarm1').show();
- // alarmBackground(0);
- //audio element just for alarm sound
- document.body.appendChild(audioElement);
- var canPlayType = audioElement.canPlayType("audio/ogg");
- if (canPlayType.match(/maybe|probably/i)) {
- audioElement.src = 'alarm.ogg';
- } else {
- audioElement.src = 'alarm.mp3';
- }
- // erst abspielen wenn genug vom mp3 geladen wurde
- audioElement.addEventListener('canplay', function () {
- audioElement.loop = true;
- audioElement.play();
- }, false);
- },
- showNumerals: true,
- brandText: 'THOOYORK',
- brandText2: 'Germany',
- onEverySecond: function () {
- //callback that should be fired every second
- },
- //alarmTime:'15:10',
- offAlarm: function () {
- //$('#alarm1').hide();
- audioElement.pause();
- clearTimeout(intVal);
- $('body').css('background-color', '#FCFCFC');
- }
- });
- }
- /**
- * 实例化列表
- */
- function initTable() {
- var winNo = $("#winNo").val();
- groupNo = $("#fyClass").val();
- if (groupNo == null || groupNo == "") {
- alert("未选择药房!");
- return;
- }
- if (winNo == null || winNo == "") {
- alert("窗口号未录入!");
- return;
- }
- var yfName = "门诊西药房";
- if (groupNo == 81) {
- yfName = "门诊中药房";
- } else if (groupNo == 82) {
- yfName = "颗粒剂药房";
- }
- $("#yfName").html(yfName);
- $("#winNum").text(winNo);
- $("#editModal").modal("hide");
- getTableDate();
- }
- /**
- * 获取后台最新数据
- */
- function getTableDate() {
- $.ajax({
- type: "GET",
- contentType: "application/json;charset=UTF-8",
- url: "/thmz/getToMedicineUser?groupNo=" + groupNo,
- headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
- dataType: 'json',
- success: function (result) {
- if (result == '401' || result == 401) {
- window.location.href = '/thmz/login/view'
- return;
- }
- if (result.code == 0) {
- var list = result.currentList;
- for (let i = 0; i < list.length; i++) {
- var current = list[i];
- if (current.confirm_flag == 5) {//已配药待发药
- currentList[currentList.length] = current;
- tempCurrentList[tempCurrentList.length] = current;
- //重置标志
- currentListHadDone = false;
- } else if (current.confirm_flag == 0 || current.confirm_flag == 2) {
- dispenseList[dispenseList.length] = current;
- tempDispenseList[tempDispenseList.length] = current; //重置标志
- dispenseListHadDone = false;
- }
- }
- //10秒刷新一次队列里面的数据,应对数据很多,一页展示不完的情况
- setInterval(refeshTable, 10000);
- } else {
- errorMesage(result);
- }
- }
- });
- }
- /**
- * 刷新列表
- */
- function refeshTable() {
- console.log(new Date().getSeconds());
- for (var i = 1; i < 7; i++) {
- if (tempPastList == null || tempPastList.length == 0) {
- $("#past" + i).text("");
- if (i == 6) {
- currentListHadDone = true;
- //如果过号列表也遍历完成,将待取药列表置空,否责重新遍历待取药列表
- //深度拷贝数组
- tempPastList = $.extend(true, [], pastList);
- }
- } else {
- //删除并返回数组的第一个元素
- var name = tempPastList.shift().name;
- $("#past" + i).text(name);
- }
- }
- for (var i = 1; i < 13; i++) {
- if (tempCurrentList == null || tempCurrentList.length == 0) {
- $("#current" + i).text("");
- if (i == 12) {
- currentListHadDone = true;
- //如果过号列表也遍历完成,将待取药列表置空,否责重新遍历待取药列表
- //深度拷贝数组
- tempCurrentList = $.extend(true, [], currentList);
- }
- } else {
- //删除并返回数组的第一个元素
- var name = tempCurrentList.shift().name;
- $("#current" + i).text(name);
- }
- }
- for (var i = 1; i < 13; i++) {
- if (tempDispenseList == null || tempDispenseList.length == 0) {
- $("#dispense" + i).text("");
- if (i == 12) {
- dispenseListHadDone = true;
- //如果过号列表也遍历完成,将待取药列表置空,否责重新遍历待取药列表
- //深度拷贝数组
- tempDispenseList = $.extend(true, [], dispenseList);
- }
- } else {
- //删除并返回数组的第一个元素
- var name = tempDispenseList.shift().name;
- $("#dispense" + i).text(name);
- }
- }
- }
- /**
- * 清空表格
- */
- function dispenseClear() {
- for (var i = 1; i < 13; i++) {
- $("#dispense" + i).text("");
- }
- }
- /**
- * 清空表格
- */
- function currentClear() {
- for (var i = 1; i < 13; i++) {
- $("#current" + i).text("");
- }
- }
- /**
- * 清空表格
- */
- function pastClear() {
- for (var i = 1; i < 7; i++) {
- $("#past" + i).text("");
- }
- }
- var websocket = null;
- //判断当前浏览器是否支持WebSocket, 主要此处要更换为自己的地址
- if ('WebSocket' in window) {
- websocket = new WebSocket("ws://" + window.location.host + "/thmz/toMedicineSocket/acceptor");
- } else {
- alert('Not support websocket')
- }
- //连接发生错误的回调方法
- websocket.onerror = function () {
- console.log("发药提醒toMedicineSocket发生错误")
- };
- //连接成功建立的回调方法
- websocket.onopen = function (event) {
- console.log("发药提醒toMedicineSocket连接成功");
- }
- //接收到消息的回调方法
- websocket.onmessage = function (event) {
- var data = JSON.parse(event.data);
- if(data.type == 'sf'){
- //添加正在配药列表
- dispenseList[dispenseList.length] = {name: data.name, patient_id: data.patient_id};
- }else if (data.type == 'py') {//来自配药处理成功后的消息
- //删除正在配药列表
- for (let i = 0; i < dispenseList.length; i++) {
- if (dispenseList[i].patient_id == data.patient_id) {
- dispenseList.splice(i, 1);
- }
- }
- //添加等待取药列表
- currentList[currentList.length] = {name: data.name, patient_id: data.patient_id};
- } else if (data.type == 'jh') {
- //判断正在取药是否为空,不为空将上一位放入过号队列
- if ($('#rightPerson').text() != "") {
- pastList[pastList.length] = {name: rightPerson.name, patient_id: rightPerson.patient_id};
- }
- //设置正在取药,清除过号队列
- $('#rightPerson').text(data.name);
- rightPerson = data;
- for (let i = 0; i < pastList.length; i++) {
- if (pastList[i].patient_id == data.patient_id) {
- pastList.splice(i, 1);
- break;
- }
- }
- //清除等待取药
- for (let i = 0; i < currentList.length; i++) {
- if (currentList[i].patient_id == data.patient_id) {
- currentList.splice(i, 1);
- break;
- }
- }
- //清除正在配药
- for (let i = 0; i < dispenseList.length; i++) {
- if (dispenseList[i].patient_id == data.patient_id) {
- dispenseList.splice(i, 1);
- }
- }
- } else if (data.type == 'fy') {
- //将该用户叫号列表清除
- if(rightPerson != '' && rightPerson != null && rightPerson.patient_id == data.patient_id){
- rightPerson = null;
- $('#rightPerson').text("");
- }
- for (let i = 0; i < currentList.length; i++) {
- if (currentList[i].patient_id == data.patient_id) {
- currentList.splice(i, 1);
- break;
- }
- }
- for (let i = 0; i < dispenseList.length; i++) {
- if (dispenseList[i].patient_id == data.patient_id) {
- dispenseList.splice(i, 1);
- }
- }
- for (let i = 0; i < pastList.length; i++) {
- if (pastList[i].patient_id == data.patient_id) {
- pastList.splice(i, 1);
- break;
- }
- }
- }
- }
- //连接关闭的回调方法
- websocket.onclose = function () {
- console.log("发药提醒toMedicineSocket连接关闭");
- }
- //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
- window.onbeforeunload = function () {
- websocket.close();
- }
- //关闭连接
- function closeWebSocket() {
- websocket.close();
- }
|