var rowData={}; var sn="";//记录sn码 var dataId = null; var type = null; var name = null; var photoUrl = null; var deviceId = null; var patient = null; var self; var oldSn="";//旧sn mui.init(); mui.plusReady(function() { plus.nativeUI.showWaiting(); self = plus.webview.currentWebview(); dataId = self.dataId; deviceId = self.deviceId; patient = self.patient; initPage(); if(deviceId == 5){ //三诺亲智的设备,建议扫描设备背面的条形码获取SN码。(因为厂家提供的二维码不好扫) $("#device5Msg").show(); }else{ $("#device5Msg").hide(); } }); $(function(){ //添加isrcoll var scroller1 = new IScrollPullUpDown('wrapper',{ probeType:2, bounceTime: 250, bounceEasing: 'quadratic', mouseWheel:false, scrollbars:true, click:true, fadeScrollbars:true, interactiveScrollbars:false },null,null); }) function initPage(){ getDeviceInfo(deviceId); bindEvents(); if(dataId&&dataId!=null){ $(document).attr("title","编辑血糖仪"); $("#titileH1").html("编辑血糖仪"); initData(dataId); $("#bang-btn").html("保存"); }else{ $("#titileH1").html("新增血糖仪"); $(document).attr("title","新增血糖仪"); } $("#bang-btn").addClass("active"); } function initData(dataId){ var params = {}; params.id=dataId; sendGet("doctor/device/PatientDeviceInfo",params, function(res){ if(res.msg){ mui.toast(res.msg); }else{ mui.toast("设备信息初始化失败!"); } }, function(res){ if(res.status==200){ rowData = res.data; oldSn = rowData.deviceSn; $("#sncode").val(rowData.deviceSn); }else{ mui.toast("设备信息初始化失败!"); } }) } //判断值是否改变过 function isValueChange(){ var changeTagStr = $("#sncode").val(); if(oldSn!=changeTagStr){ } } //绑定事件 function bindEvents(){ //保存方法 $("#bang-btn").bind("click",function(){ if($(this).hasClass("active")){ var snCode = $("#sncode").val(); $("#bang-btn").removeClass("active"); if(snCode==null||snCode==""){ mui.toast("请输入设备的SN码进行绑定!"); }else{ plus.nativeUI.showWaiting(); $("#bang-btn").html("正在绑定"); checkSnBind(snCode,checkSuccess); } } }); //扫描二维码 $(".scanText").on('click', function(){ openWebview("scan.html"); }); window.addEventListener("getScanResult", function(e){ var result = e.detail.result; $("#sncode").val(result); }); } function checkSnBind(snCode,checkSuccess){ var b = /^[0-9a-zA-Z]*$/g; if(!b.test(snCode)){ $("#bang-btn").html("立即绑定"); plus.nativeUI.closeWaiting(); mui.confirm("对不起,您输入的SN有误,请重新输入", "", ["我知道了"], function(e) { return; }); $("#bang-btn").addClass("active"); return false; } var params = {}; params.type=type; params.device_sn = snCode; params.patient = patient; mui.ajax(server + "doctor/device/PatientDeviceIdcard", { data: params || {}, async: false, dataType: 'json', //crossDomain: true, type: "get", timeout: 10000, error: function(res){ $("#bang-btn").addClass("active"); mui.toast(res); $("#bang-btn").html("立即绑定"); plus.nativeUI.closeWaiting(); }, success: function(res){ $("#bang-btn").html("立即绑定"); plus.nativeUI.closeWaiting(); if(res.status==200){ var name = "" ; var others = null; for(var j in res.data){ name = res.data[j].name; others = res.data[j].others } //没被绑定 if(name==""){ if(checkSuccess!=null){ checkSuccess(snCode); } return false; }else if(others!=null&&others==1){ // $("#bang-btn").removeClass("active"); //被绑定而且被别人绑定 mui.confirm("该设备已被他人绑定,设备解绑后,方可再次绑定", "", ["我知道了"], function(e) { $("#bang-btn").addClass("active"); return; }); return false; } else if(others!=null&&others==0){ // $("#bang-btn").removeClass("active"); if(oldSn!=snCode){ //新增,编辑/被自己绑定 mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) { $("#bang-btn").addClass("active"); return; }); return; }else{ if(checkSuccess!=null){ checkSuccess(snCode); return false; } } } } else { $("#bang-btn").addClass("active"); } } }); } function getDeviceInfo(deviceId){ sendGet("common/device/DeviceInfo?id="+deviceId,{}, function(res){ plus.nativeUI.closeWaiting(); mui.toast("设备信息获取失败!"); }, function(res){ plus.nativeUI.closeWaiting(); if(res.status==200){ var rowData1 = res.data; type = rowData1.categoryCode; name = rowData1.name; photoUrl = rowData1.photo; $(".deviceName").html(name); $(".div-xuetangyi-img img").attr("src",getImgUrl(photoUrl)); }else{ mui.toast("设备信息获取失败!"); } }) } function checkSuccess(snCode){ var name1="血糖仪-"+name; var params ={}; params.deviceId=deviceId;//设备ID params.deviceName=name1;//设备名称 params.deviceSn=snCode;//设备SN码 params.categoryCode=type;//设备分类 血糖仪1 血压计 2 params.userType="-1";//是否多用户 params.user=patient; if(rowData.id){ params.id = rowData.id; } sendPost("doctor/device/SavePatientDevice",{"data":JSON.stringify(params)}, function(res){ mui.toast("设备信息获取失败!"); $("#bang-btn").addClass("active"); }, function(res){ if(res.status==200){ mui.toast("设备绑定成功"); openwdsb(); }else{ $("#bang-btn").addClass("active"); mui.toast(res.msg); return false; } } ) } function openwdsb(){ var page = plus.webview.getWebviewById("health-record"); if(page){ mui.fire(page,'refreshEquipment') } var page2 = plus.webview.getWebviewById("my-equipments"); if(page2){ mui.fire(page2,'refreshEquipment') } var page3 = plus.webview.getWebviewById("huanzhe.html"); if(page3){ mui.fire(page3,'refresh') } setTimeout(function(){ var cur = plus.webview.currentWebview(), opener = cur.opener(), preOpener = opener && opener.opener() mui.fire(preOpener,'refreshEquipment') var pa1 = plus.webview.getWebviewById("list-xueyaji.html"); if(pa1){pa1.close()} var pa2 = plus.webview.getWebviewById("list-xuetangyi.html"); if(pa2){pa2.close()} var pa3 = plus.webview.getWebviewById("edit-xueyaji"); if(pa3){pa3.close()} var pa5 = plus.webview.getWebviewById("view-xueyaji.html"); if(pa5){pa5.close()} var pa6 = plus.webview.getWebviewById("view-xuetangyi.html"); if(pa6){pa6.close()} var pa4 = plus.webview.getWebviewById("edit-xuetangyi"); if(pa4){pa4.close()} backToWebviewById(preOpener.id)() },1000) }