123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- 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
- mui.init();
- var scroller1,
- self;
- mui.plusReady(function() {
- self = plus.webview.currentWebview();
- dataId = self.dataId;
- deviceId = self.deviceId;
- patient = self.patient;
- if(deviceId == 6){
- //云湃血压计,需要填写SIM码
- $(".scanText").removeClass("c-border-l");
- $("#simDiv").show();
- }
- initPage();
- })
- function initPage(){
- getDeviceInfo(deviceId);
- $("#bang-btn").addClass("active");
- if(dataId){
- $(document).attr("title","编辑血压计");
- $("#titileH1").html("编辑血压计");
- initData(dataId);
- $("#bang-btn").html("保存");
- }else{
- $("#titileH1").html("新增血压计");
- $(document).attr("title","新增血压计");
- }
- isValueChange();
- bindEvents();
-
- 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) {
- scroller1.myScroll.refresh();
- }
-
- //上拉加载数据
- function pullUpAction(theScrollerTemp) {
- scroller1.myScroll.refresh();
- }
- }
- function initData(dataId){
- sendGet("doctor/device/PatientDeviceInfo?id="+dataId,{},
- function(res){
- mui.toast("设备信息初始化失败!");
- },
- function(res){
- if(res.status==200){
- rowData = res.data;
- $("#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){
- $(".scanText").removeClass("c-border-l");
- $("#simDiv").show();
- $("#simcode").val(rowData.sim);
-
- }
- }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(){
- //点击绑定快捷键事件
- $(".c-quick-list").on("click",".li-key",function(){
- $("#sncode").blur();
- var newDom = $(this).find(".key-img");
- var canclick = newDom.attr("data-click");
- var userName = $(this).find(".div-band-info").html();
- if(canclick==0){
- var title = '该快捷键'+userName+',若要绑定该快捷键,需'+userName+'先解绑设备';
- mui.confirm(title, "", ["我知道了"], function(e) {
- return;
- });
- return;
- }else if(canclick==-1){
- var title = '对不起,该居民已绑定过该设备,解绑后方可继续操作';
- mui.confirm(title, "", ["我知道了"], function(e) {
- return;
- });
- return;
- }
- $(".c-quick-list").find(".li-key").find(".key-img").removeClass("active");
- userType = newDom.attr("data-type");
- $(this).find(".key-img").addClass("active");
- })
-
- //保存方法
- $("#bang-btn").bind("click",function(){
- if($(this).hasClass("active")){
- var snCode = $("#sncode").val();
- $("#bang-btn").removeClass("active");
- if(snCode==null||snCode==""){
- $("#bang-btn").addClass("active");
- mui.toast("请输入设备的SN码进行绑定!");
- }else{
- plus.nativeUI.showWaiting();
- $("#bang-btn").html("正在绑定");
- checkSnBind(snCode,checkSuccess);
- }
- }
- })
-
- $("#sncode").on("input",function(){
- var snCode = $(this).val();
- // isValueChange();
- if(snCode!=null||snCode!=""){
- userType=0;
- $(".c-quick-list").find(".li-key").find(".key-img").removeClass("active");
- $(".father").attr("data-click","1");
- $(".monther").attr("data-click","1");
- $(".div-father-band").hide();
- $(".div-monther-band").hide();
- }
- });
-
- //扫描二维码
- $(".scanText").on('click', function(){
- openWebview("scan.html");
- });
-
- window.addEventListener("getScanResult", function(e){
- var result = e.detail.result;
- if(deviceId == 6){
- var arr = result.split(" ");
- $("#sncode").val(arr[1]);
- $("#simcode").val(arr[0]);
- }else{
- $("#sncode").val(result);
- }
-
- });
- }
- 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)){
- $("#bang-btn").html("立即绑定");
- plus.nativeUI.closeWaiting();
- mui.toast("对不起,您输入的SN有误,请重新输入");
- $("#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){
- 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;
- }
- if(deviceId == 6){
- params.sim = $("#simcode").val();
- }
- 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);
- }
- }
- )
- }
- 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()
-
- 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 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()}
- var pa3 = plus.webview.getWebviewById("edit-xueyaji");
- if(pa3){pa3.close()}
-
- backToWebviewById(preOpener.id)()
- },1000)
- }
|