123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- 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
- $(function() {
- Request = GetRequest();
- dataId = Request["id"];
- deviceId = Request["deviceId"];
- $('#member').val(window.localStorage.getItem('nowPatientName'));
- getDeviceInfo(deviceId);
- bindEvents();
- initData(dataId);
- });
- function initData(dataId){
- sendPost("patient/device/PatientDeviceInfo?id="+dataId,{},"JSON","GET",
- function(res){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
- },
- function(res){
- if(res.status==200){
- rowData = res.data;
- $("#sncode").val(rowData.device.deviceSn);
- checkSnBind(rowData.device.deviceSn);
- userType = rowData.device.userType;
- oldSn = rowData.device.deviceSn;
- if(userType==1){
- $(".father").addClass("active");
- }
- if(userType==2){
- $(".monther").addClass("active");
- }
- if(deviceId == 6){
- $("#simDiv").show();
- $("#simcode").val(rowData.device.sim);
- }
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
- }
- }
-
- )
- }
- function getDeviceInfo(deviceId){
- sendPost("/common/device/DeviceInfo?id="+deviceId,{},"JSON","GET",
- function(res){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true, content:'设备信息获取失败!'}).show();
- },
- function(res){
- if(res.status==200){
- var rowData1 = res.data;
- type = rowData1.categoryCode;
- name = rowData1.name;
- photoUrl = getImgUrl(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",photoUrl)
-
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息获取失败!'}).show();
- }
- }
- )
- }
- //绑定事件
- function bindEvents(){
- $("#del-btn").bind("click",function(){
- dialog({
- content: '解绑设备信息,将会导致医生无法实时<br/>关注到您的体征变化。是否继续解绑?',
- okValue:'确定',
- ok: function (){
- deleteSn(dataId);
- },
- cancelValue: '取消',
- cancel: function () {
- return;
- }
- }).showModal();
- })
-
- $("#edit-btn").bind("click",function(){
- openedit();
- })
-
- }
- 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)){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'对不起,您输入的SN有误,请重新输入!'}).show();
- return false;
- }
- var params = {};
- params.type=type;
- params.device_sn = snCode;
- sendPost("patient/device/PatientDeviceIdcard",params,"JSON","GET",
- function(res){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res}).show();
- // $("#bang-btn").removeClass("active");
- },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){
- dialog({
- content: "该设备所有快捷键已被绑定,解绑快捷键后,方可再次绑定!",
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- return false;
- }
- else if(bindnum==1&&showTitle!=""){//被绑定的按键选项
- dialog({
- content: showTitle,
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- 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");
- }
- dialog({
- content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- 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");
- }
- dialog({
- content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- 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");
- }
- dialog({
- content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- 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");
- }
- dialog({
- content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- return false;//直接退出不保存
- }
-
- }
-
-
- }
- }
- if(suc){
- suc(snCode);
- }
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备SN校验失败!'}).show();
- // $("#bang-btn").removeClass("active");
- }
- }
- );
-
-
- }
- function checkSuccess(snCode){
- if(userType==0){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请选择要绑定的快捷键'}).show();
- 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.妈妈键
- if(rowData.id){
- params.id = rowData.id;
- }
- sendPost("/patient/device/SavePatientDevice",{"json":JSON.stringify(params)},"JSON","post",
- function(res){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定失败!'}).show();
- },
- function(res){
- if(res.status == '200'){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定成功!'}).show();
- setTimeout(function(){
- window.location.href='my-equipments.html';
- },500);
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
- }
- }
- )
- }
- function openedit(){
- location.href="edit-xueyaji.html?deviceId="+deviceId+"&id="+dataId+"&categoryCode=" + type;
- }
- function deleteSn(code){
- sendPost("patient/device/DeletePatientDevice?id="+code,{},"JSON","get",function(res){
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
- }
- },function(res){
- if(res.status==200){
- location.href="my-equipments.html";
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
- }
- })
- }
|