123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- var rowData={};
- var sn="";//记录sn码
- var userType=0;
- var dataId = null;
- var type = null;
- var name = null;
- var deviceId = null;
- var photoUrl = null;
- var prescriptionCode;
- var oldSn="";//旧sn
- var categoryCode = '';
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var $member = $('#member');
- var userAgent = JSON.parse(window.localStorage.getItem(agentName));
- $(function() {
- Request = GetRequest();
- dataId = Request["id"];
- deviceId = Request["deviceId"];
- categoryCode = Request["categoryCode"];
- prescriptionCode = Request["prescriptionCode"];
- getDeviceInfo(deviceId);
- bindEvents();
- $("#bang-btn").addClass("active");
-
- if(deviceId == 6){ //云湃*脉搏波RBP-980
- $("#simDiv").show();
- $(".scanText").removeClass("c-border-l");
- }
- if(dataId){
- $(document).attr("title","编辑血压计");
- initData(dataId);
- $("#bang-btn").html("保存");
- }else{
- $(document).attr("title","新增血压计");
- }
- isValueChange();
- weixinSign();
- });
- 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();
- }
- }
-
- )
- }
- //获取家庭成员
- Promise.all([familyAllMembers()]).then(function(data){
- var arr_code=_.pluck(data[0], 'code');
- var arr_name=_.pluck(data[0], 'name');
- //关联被代理人
- if(userAgent.represented){
- var one = _.find(data[0],function(item){return item.code == userAgent.represented;})
- $member.attr('data-val',one.code);
- $member.val(one.name);
- }else{
- $member.attr('data-val',arr_code[0]);
- $member.val(arr_name[0]);
- }
- })
- 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(){
-
- //点击绑定快捷键事件
- $(".c-quick-list").on("click",".li-key",function(){
- 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+'注册,需解除与该快捷键的绑定关系后,方能完成绑定';
- dialog({
- content: title,
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- return;
- }else if(canclick==-1){
- var title = '对不起,您已绑定过该设备,解绑后方可继续绑定';
- dialog({
- content: title,
- cancelValue: '我知道了',
- cancel: function () {
- return;
- }
- }).showModal();
- return;
- }
- $(".c-quick-list").find(".li-key").find(".key-img").removeClass("active");
- userType = newDom.attr("data-type");
- $(this).find(".key-img").addClass("active");
- var snCode = $("#sncode").val();
- if(snCode!=null&&snCode!=""){
-
- }
- })
-
- //保存方法
- $("#bang-btn").bind("click",function(){
- if($(this).hasClass("active")){
- var snCode = $("#sncode").val();
- if(snCode==null||snCode==""){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请输入设备的SN码进行绑定!'}).show();
- }else{
- $("#bang-btn").html("正在绑定").css("pointer-events","none");;
- d.show();
- checkSnBind(snCode,checkSuccess);
- }
- }
- })
-
- $("#sncode").on("input",function(){
- var snCode = $(this).val();
- 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(){
- wx.scanQRCode({
- desc: 'scanQRCode desc',
- needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
- scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
- success: function (res) {
- // 回调
- var code = res.resultStr,
- arr = code.split(" ");
- if(deviceId == 6){
- $("#sncode").val(arr[1]);
- $("#simcode").val(arr[0]);
- }else{
- var arr2 = code.split(","); //因为微信扫描条形码的时候,会带上这个码的类型,所以取数组后的码显示
-
- if(arr2.length > 1){
- $("#sncode").val(arr2[1]);
- }else{
- $("#sncode").val(arr2[0]);
- }
- }
- },
- error: function(res){
- if(res.errMsg.indexOf('function_not_exist') > 0){
- alert('版本过低请升级')
- }
- }
- });
- })
- }
- 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)){
- setTimeout(function(){
- $("#bang-btn").html("立即绑定").css("pointer-events","");
- },3000);
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'对不起,您输入的SN有误,请重新输入!'}).show();
- d.close();
- return false;
- }
- var params = {};
- params.type=type;
- params.device_sn = snCode;
- $.ajax(server + "patient/device/PatientDeviceIdcard", {
- data: params,
- dataType: "JSON",
- async:false,
- type: "get",
- timeout:10000,
- beforeSend: function(request) {
- var userAgent = window.localStorage.getItem(agentName);
- request.setRequestHeader("userAgent", userAgent);
- },
- error:function(res){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res}).show();
- setTimeout(function(){
- $("#bang-btn").html("立即绑定").css("pointer-events","");
- d.close();
- },3000);
- },success:function(res){
- d.close();
- setTimeout(function(){
- $("#bang-btn").html("立即绑定").css("pointer-events","");
- },3000);
- if(res.status==200){
- if(res.data.length==0&&suc){
- if (dataId) {
- d.close();
- editSN(snCode);
- } else {
- 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){
- if (dataId) {
- editSN(snCode);
- } else {
- suc(snCode);
- }
- }
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备SN校验失败!'}).show();
- }
- }
- })
-
- }
- function checkSuccess(snCode){
- if(userType==0){
- d.close();
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请选择要绑定的快捷键'}).show();
- return false;
- }
- var sim = $("#simcode").val();
-
- if(deviceId == 6 && !sim){
- d.close();
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请输入SIM码'}).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;
- }
- if(deviceId == 6){
- params.sim = sim;
- }
- sendPost("/patient/device/SavePatientDevice",{"json":JSON.stringify(params)},"JSON","post",
- function(res){
- d.close();
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请求失败'}).show();
- },
- function(res){
- d.close();
- if(res.status == '200'){
- dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定成功'}).show();
- setTimeout(function(){
- if(prescriptionCode){
- window.history.go(-3)
- }else{
- window.location.href='my-equipments.html';
- }
- },500);
- }else{
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"设备绑定失败"}).show();
- }
- }
- )
- }
- function editSN (snCode) {
- var o = {};
- o.deviceSN = oldSn;
- o.newDeviceSN = snCode;
- if(deviceId == 6){
- o.sim = $("#simcode").val();
- }
- o.categoryCode = categoryCode;
- o.userType=userType;
- sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
- d.close();
- if(res.status == 200) {
- setTimeout(function(){
- if(prescriptionCode){
- window.history.go(-3);
- }else{
- window.location.href='my-equipments.html';
- }
- },500);
- } else {
- dialog({
- contentType: 'tipsbox',
- bottom: true,
- skin: 'bk-popup',
- content: res.msg
- }).show();
- }
- });
- }
- function weixinSign(){
- //从后台那边获取签名等信息
- var params = {};
- var url1 = window.location.href;
- params.pageUrl = url1;
- $.ajax(server + "weixin/getSign", {
- data: params,
- dataType: "json",
- type: "post",
- success: function(res){
- if (res.status == 200) {
- var t = res.data.timestamp;
- var noncestr = res.data.noncestr;
- var signature = res.data.signature;
- wx.config({
- appId: appId, // 必填,公众号的唯一标识
- timestamp: t, // 必填,生成签名的时间戳
- nonceStr: noncestr, // 必填,生成签名的随机串
- signature: signature,// 必填,签名,见附录1
- jsApiList: [
- 'chooseImage',
- 'uploadImage',
- 'scanQRCode'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
-
- // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
- wx.ready(function(){
- wx.getNetworkType({
- success: function (res) {
- networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
- }
- });
- });
- }
- }
- });
- }
|