123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- var rowData={};
- var sn="";//记录sn码
- var userType=0;
- var dataId = null;
- var type = null;
- var name = null;
- var deviceId = null;
- var photoUrl = null;
- var oldSn="";//旧sn
- var scroller1 = null;
- var role = null;
- mui.init();
- mui.plusReady(function() {
- self = plus.webview.currentWebview();
- dataId = self.dataId;
- deviceId = self.deviceId;
- patient = self.patient;
- role = self.role;
- initPage();
- scroller1= new IScrollPullUpDown('wrapper',{
- probeType:2,
- bounceTime: 250,
- bounceEasing: 'quadratic',
- mouseWheel:false,
- scrollbars:true,
- click:true,
- fadeScrollbars:true,
- interactiveScrollbars:false
- },pullDownAction,pullUpAction);
- //下拉刷新
- function pullDownAction(theScrollerTemp) {
- initPage();
- }
-
- //上拉加载数据
- function pullUpAction(theScrollerTemp) {
- scroller1._resize();
- }
- });
- function initPage(){
- getDeviceInfo(deviceId);
- isValueChange();
- bindEvents();
- initData(dataId);
- }
- function initData(dataId){
- sendGet("doctor/device/PatientDeviceInfo?id="+dataId,{},
- function(res){
- mui.toast("设备信息初始化失败!");
- },
- function(res){
- if(res.status==200){
- rowData = res.data;
- docInfo= JSON.parse(plus.storage.getItem("docInfo"));
- // if(rowData.doctor==docInfo.code){
- // $("#footer").show();
- // }
- if(role=="1") {
- $("#footer").show();
- } else{
- $(scroller1.wrapper).css("height","100%");
- scroller1._resize();
- }
- $("#sncode").val(rowData.deviceSn);
- checkSnBind(rowData.deviceSn);
- userType = rowData.userType;
- oldSn = rowData.deviceSn;
- if(userType==1){
- $(".father").addClass("active");
- }
- if(userType==2){
- $(".monther").addClass("active");
- }
- if(deviceId == 6){
- $("#simDiv").show();
- $("#simcode").val(rowData.sim);
-
- }
- scroller1._resize();
- }else{
- mui.toast("设备信息初始化失败!");
- }
- }
-
- )
- }
- function getDeviceInfo(deviceId){
- sendGet("common/device/DeviceInfo?id="+deviceId,{},
- function(res){
- mui.toast("设备信息获取失败!");
- },
- function(res){
- if(res.status==200){
- var rowData1 = res.data;
- type = rowData1.categoryCode;
- name = rowData1.name;
- photoUrl = rowData1.photo;
- var multiUser = JSON.parse(rowData1.multiUser);
- for(var key in multiUser){
- if(key==1){
- $(".key-one").html(multiUser[key]);
- }else{
- $(".key-two").html(multiUser[key]);
- }
- }
- $(".deviceName").html(name);
- $(".div-xueyaji-img img").attr("src",getImgUrl(photoUrl))
-
- }else{
- mui.toast("设备信息获取失败!");
- }
- }
- )
- }
- //绑定事件
- function bindEvents(){
-
- //保存方法
- $("#del-btn").bind("click",function(){
- mui.confirm("设备解绑后,将无法自动从设备获取相关数据。是否继续解绑?", "提示", ["继续解绑","不了,谢谢"], function(e) {
- if(e.index==0){
- deleteSn(dataId);
- return;
- }else{
- return;
- }
- });
- })
- $("#edit-btn").bind("click",function(){
- editXueyaji();
- })
- }
- function isValueChange(){
- var self = this;
- var int= setInterval(function() {
- var changeTagStr = $("#sncode").val();
- if(oldSn!=changeTagStr){
- clearInterval(int);
- int = null;
- $("#bang-btn").addClass("active");
- }
- },300);
- }
- function checkSnBind(snCode,suc){
- var b = /^[0-9a-zA-Z]*$/g;
- if(!b.test(snCode)){
- mui.toast("对不起,您输入的SN有误,请重新输入");
- $("#bang-btn").addClass("active");
- return false;
- }
- var params = {};
- params.type=type;
- params.device_sn = snCode;
- params.patient = patient;
- sendGet("doctor/device/PatientDeviceIdcard",params,
- function(res){
- $("#bang-btn").addClass("active");
- mui.toast(res);
- },function(res){
-
- if(res.status==200){
- if(res.data.length==0&&suc){
- suc(snCode);
- return;
- }
- //遍历绑定信息
- var isbind = false;//是否绑定
- var bindnum = 0;
- var showTitle = "";
- var fatherData = null;
- var montherData = null;
- //循环取出爸爸妈妈健的数据
- for(var j in res.data){
- var data = res.data[j];//取出设置
- var dataType = data['type'];//按键类型1.爸爸建2.妈妈键
- var others = data['others'];//others==1为被别人绑定
- if(dataType==1){
- fatherData = data;
- if(others==1){
- bindnum+=1;
- if(userType==1) userType = 0 ;//被绑定
- $(".father").attr("data-click","0");//设置键1无法点击
- $(".fatherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
- $(".div-father-band").show();//显示绑定信息
- if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
- $(".father").removeClass("active");
- showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
- }
- }
- }else{
- montherData = data;
- if(others==1){
- if(userType==2) userType = 0 ;//被绑定
- $(".monther").attr("data-click","0");//设置键2无法点击
- $(".montherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
- $(".div-monther-band").show();//显示绑定信息
- bindnum+=1;
- if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
- $(".monther").removeClass("active");
- showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
- }
- }
- }
- }
- if(bindnum==2){
- mui.confirm("该设备所有快捷键已被绑定,解绑快捷键后,方可再次绑定!", "", ["我知道了"], function(e) {
- return;
- });
- $("#bang-btn").addClass("active");
- return false;
- }
- else if(bindnum==1&&showTitle!=""){//被绑定的按键选项
- mui.confirm(showTitle, "", ["我知道了"], function(e) {
- return;
- });
- $("#bang-btn").addClass("active");
- return false;
- }
- if(fatherData!=null){
- var others = fatherData['others'];//others==1为被别人绑定
- if(others!=1){//被别人绑定了
- //被自己绑定
- if(dataId == null){
- //新增的时候输入被自己绑定的SN码
- $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
- $(".monther").attr("data-click","-1");
- if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
- $(".father").removeClass("active");
- }
- mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
- return;
- });
- $("#bang-btn").addClass("active");
- return false;//直接退出不保存
- }else{
- if(!suc){//界面初始化的时候没有校验成功回调
- userType = 1;
- //选中爸爸键
- $(".father").addClass("active");
- }else if(oldSn!=snCode){
- $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
- $(".monther").attr("data-click","-1");
- if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
- $(".father").removeClass("active");
- }
- mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
- return;
- });
- $("#bang-btn").addClass("active");
- return false;//直接退出不保存
- }
- }
- }
-
- }
- if(montherData!=null){
- var others = montherData['others'];//others==1为被别人绑定
- if(others!=1){
- //被自己绑定
- if(dataId == null){
- //新增的时候输入被自己绑定的SN码
- $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
- $(".monther").attr("data-click","-1");
- //$(".monther").addClass("active");//自己绑定了的键设置高亮
- if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
- $(".monther").removeClass("active");
- }
- mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
- return;
- });
- $("#bang-btn").addClass("active");
- return false;//直接退出不保存
- }else{
- if(!suc){
- userType = 2;
- //选中妈妈键
- $(".monther").addClass("active");
- }else if(oldSn!=snCode){
- $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
- $(".monther").attr("data-click","-1");
- //$(".monther").addClass("active");//自己绑定了的键设置高亮
- if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
- $(".monther").removeClass("active");
- }
- mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
- return;
- });
- $("#bang-btn").addClass("active");
- return false;//直接退出不保存
- }
-
- }
- }
- }
- if(suc){
- suc(snCode);
- }
- }else{
- $("#bang-btn").addClass("active");
- mui.toast("设备SN校验失败!");
- }
- }
- );
- }
- function checkSuccess(snCode){
- if(userType==0){
- mui.toast("请选择要绑定的快捷键!");
- $("#bang-btn").addClass("active");
- return false;
- }
- var name1="血压计-"+name;
- var params ={};
- params.deviceId=deviceId;//设备ID
- params.deviceName=name1;//设备名称
- params.deviceSn=snCode;//设备SN码
- params.categoryCode=type;//设备分类 血糖仪1 血压计 2
- params.userType=userType;//是否多用户,1.爸爸建,2.妈妈键
- 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("设备绑定成功!");
- setTimeout(function(){
- openwdsb();
- },1000);
- }else{
- $("#bang-btn").addClass("active");
- mui.toast(res.msg);
- }
- }
- )
- }
- 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')
- }
- setTimeout(function(){
- 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 pa4 = plus.webview.getWebviewById("edit-xuetangyi");
- if(pa4){pa4.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()}
- plus.nativeUI.closeWaiting();
- mui.back()
- },1000)
- }
- function editXueyaji(){
- var params = {};
- params.deviceId = deviceId;
- params.dataId = dataId;
- params.patient = patient;
- openWebviewExtras("edit-xueyaji.html",params);
- }
- function deleteSn(code){
- plus.nativeUI.showWaiting();
- sendPost("doctor/device/DeletePatientDevice?id="+code,{},function(res){
- plus.nativeUI.closeWaiting();
- if (res && res.msg) {
- mui.toast(res.msg);
- } else {
- mui.toast("解绑设备失败!");
- }
- },function(res){
-
- if(res.status==200){
- $(".c-list").html("");
- if(res.data && res.data.length) {
- var userName = (res.data[0] && res.data[0].username) || "";
- mui.confirm("解绑成功,该血压计还绑定了居民"+userName+",可到该居民页解绑或联系管理员在管理页面进行设备解绑", "", ["我知道了"], function(e) {
- openwdsb();
- });
- } else {
- mui.toast("解绑设备成功!");
- openwdsb();
- }
-
- }else{
- plus.nativeUI.closeWaiting();
- mui.toast("解绑设备失败!");
- }
- },"GET")
- }
|