view-xueyaji.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. var rowData={};
  2. var sn="";//记录sn码
  3. var userType=0;
  4. var dataId = null;
  5. var type = null;
  6. var name = null;
  7. var deviceId = null;
  8. var photoUrl = null;
  9. var oldSn="";//旧sn
  10. $(function() {
  11. Request = GetRequest();
  12. dataId = Request["id"];
  13. deviceId = Request["deviceId"];
  14. $('#member').val(window.localStorage.getItem('nowPatientName'));
  15. getDeviceInfo(deviceId);
  16. bindEvents();
  17. initData(dataId);
  18. });
  19. function initData(dataId){
  20. sendPost("patient/device/PatientDeviceInfo?id="+dataId,{},"JSON","GET",
  21. function(res){
  22. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
  23. },
  24. function(res){
  25. if(res.status==200){
  26. rowData = res.data;
  27. $("#sncode").val(rowData.device.deviceSn);
  28. checkSnBind(rowData.device.deviceSn);
  29. userType = rowData.device.userType;
  30. oldSn = rowData.device.deviceSn;
  31. if(userType==1){
  32. $(".father").addClass("active");
  33. }
  34. if(userType==2){
  35. $(".monther").addClass("active");
  36. }
  37. if(deviceId == 6){
  38. $("#simDiv").show();
  39. $("#simcode").val(rowData.device.sim);
  40. }
  41. }else{
  42. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
  43. }
  44. }
  45. )
  46. }
  47. function getDeviceInfo(deviceId){
  48. sendPost("/common/device/DeviceInfo?id="+deviceId,{},"JSON","GET",
  49. function(res){
  50. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true, content:'设备信息获取失败!'}).show();
  51. },
  52. function(res){
  53. if(res.status==200){
  54. var rowData1 = res.data;
  55. type = rowData1.categoryCode;
  56. name = rowData1.name;
  57. photoUrl = getImgUrl(rowData1.photo);
  58. var multiUser = JSON.parse(rowData1.multiUser);
  59. for(var key in multiUser){
  60. if(key==1){
  61. $(".key-one").html(multiUser[key]);
  62. }else{
  63. $(".key-two").html(multiUser[key]);
  64. }
  65. }
  66. $(".deviceName").html(name);
  67. $(".div-xueyaji-img img").attr("src",photoUrl)
  68. }else{
  69. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息获取失败!'}).show();
  70. }
  71. }
  72. )
  73. }
  74. //绑定事件
  75. function bindEvents(){
  76. $("#del-btn").bind("click",function(){
  77. dialog({
  78. content: '解绑设备信息,将会导致医生无法实时<br/>关注到您的体征变化。是否继续解绑?',
  79. okValue:'确定',
  80. ok: function (){
  81. deleteSn(dataId);
  82. },
  83. cancelValue: '取消',
  84. cancel: function () {
  85. return;
  86. }
  87. }).showModal();
  88. })
  89. $("#edit-btn").bind("click",function(){
  90. openedit();
  91. })
  92. }
  93. function isValueChange(){
  94. var self = this;
  95. var int= setInterval(function() {
  96. var changeTagStr = $("#sncode").val();
  97. if(oldSn!=changeTagStr){
  98. clearInterval(int);
  99. int = null;
  100. $("#bang-btn").addClass("active");
  101. }
  102. },300);
  103. }
  104. function checkSnBind(snCode,suc){
  105. var b = /^[0-9a-zA-Z]*$/g;
  106. if(!b.test(snCode)){
  107. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'对不起,您输入的SN有误,请重新输入!'}).show();
  108. return false;
  109. }
  110. var params = {};
  111. params.type=type;
  112. params.device_sn = snCode;
  113. sendPost("patient/device/PatientDeviceIdcard",params,"JSON","GET",
  114. function(res){
  115. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res}).show();
  116. // $("#bang-btn").removeClass("active");
  117. },function(res){
  118. if(res.status==200){
  119. if(res.data.length==0&&suc){
  120. suc(snCode);
  121. return;
  122. }
  123. //遍历绑定信息
  124. var isbind = false;//是否绑定
  125. var bindnum = 0;
  126. var showTitle = "";
  127. var fatherData = null;
  128. var montherData = null;
  129. //循环取出爸爸妈妈健的数据
  130. for(var j in res.data){
  131. var data = res.data[j];//取出设置
  132. var dataType = data['type'];//按键类型1.爸爸建2.妈妈键
  133. var others = data['others'];//others==1为被别人绑定
  134. if(dataType==1){
  135. fatherData = data;
  136. if(others==1){
  137. bindnum+=1;
  138. if(userType==1) userType = 0 ;//被绑定
  139. $(".father").attr("data-click","0");//设置键1无法点击
  140. $(".fatherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
  141. $(".div-father-band").show();//显示绑定信息
  142. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  143. $(".father").removeClass("active");
  144. showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
  145. }
  146. }
  147. }else{
  148. montherData = data;
  149. if(others==1){
  150. if(userType==2) userType = 0 ;//被绑定
  151. $(".monther").attr("data-click","0");//设置键2无法点击
  152. $(".montherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
  153. $(".div-monther-band").show();//显示绑定信息
  154. bindnum+=1;
  155. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  156. $(".monther").removeClass("active");
  157. showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
  158. }
  159. }
  160. }
  161. }
  162. if(bindnum==2){
  163. dialog({
  164. content: "该设备所有快捷键已被绑定,解绑快捷键后,方可再次绑定!",
  165. cancelValue: '我知道了',
  166. cancel: function () {
  167. return;
  168. }
  169. }).showModal();
  170. return false;
  171. }
  172. else if(bindnum==1&&showTitle!=""){//被绑定的按键选项
  173. dialog({
  174. content: showTitle,
  175. cancelValue: '我知道了',
  176. cancel: function () {
  177. return;
  178. }
  179. }).showModal();
  180. return false;
  181. }
  182. if(fatherData!=null){
  183. var others = fatherData['others'];//others==1为被别人绑定
  184. if(others!=1){//被别人绑定了
  185. //被自己绑定
  186. if(dataId == null){
  187. //新增的时候输入被自己绑定的SN码
  188. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  189. $(".monther").attr("data-click","-1");
  190. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  191. $(".father").removeClass("active");
  192. }
  193. dialog({
  194. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  195. cancelValue: '我知道了',
  196. cancel: function () {
  197. return;
  198. }
  199. }).showModal();
  200. return false;//直接退出不保存
  201. }else{
  202. if(!suc){//界面初始化的时候没有校验成功回调
  203. userType = 1;
  204. //选中爸爸键
  205. $(".father").addClass("active");
  206. }else if(oldSn!=snCode){
  207. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  208. $(".monther").attr("data-click","-1");
  209. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  210. $(".father").removeClass("active");
  211. }
  212. dialog({
  213. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  214. cancelValue: '我知道了',
  215. cancel: function () {
  216. return;
  217. }
  218. }).showModal();
  219. return false;//直接退出不保存
  220. }
  221. }
  222. }
  223. }
  224. if(montherData!=null){
  225. var others = montherData['others'];//others==1为被别人绑定
  226. if(others!=1){
  227. //被自己绑定
  228. if(dataId == null){
  229. //新增的时候输入被自己绑定的SN码
  230. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  231. $(".monther").attr("data-click","-1");
  232. //$(".monther").addClass("active");//自己绑定了的键设置高亮
  233. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  234. $(".monther").removeClass("active");
  235. }
  236. dialog({
  237. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  238. cancelValue: '我知道了',
  239. cancel: function () {
  240. return;
  241. }
  242. }).showModal();
  243. return false;//直接退出不保存
  244. }else{
  245. if(!suc){
  246. userType = 2;
  247. //选中妈妈键
  248. $(".monther").addClass("active");
  249. }else if(oldSn!=snCode){
  250. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  251. $(".monther").attr("data-click","-1");
  252. //$(".monther").addClass("active");//自己绑定了的键设置高亮
  253. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  254. $(".monther").removeClass("active");
  255. }
  256. dialog({
  257. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  258. cancelValue: '我知道了',
  259. cancel: function () {
  260. return;
  261. }
  262. }).showModal();
  263. return false;//直接退出不保存
  264. }
  265. }
  266. }
  267. }
  268. if(suc){
  269. suc(snCode);
  270. }
  271. }else{
  272. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备SN校验失败!'}).show();
  273. // $("#bang-btn").removeClass("active");
  274. }
  275. }
  276. );
  277. }
  278. function checkSuccess(snCode){
  279. if(userType==0){
  280. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请选择要绑定的快捷键'}).show();
  281. return false;
  282. }
  283. var name1="血压计-"+name;
  284. var params ={};
  285. params.deviceId=deviceId;//设备ID
  286. params.deviceName=name1;//设备名称
  287. params.deviceSn=snCode;//设备SN码
  288. params.categoryCode=type;//设备分类 血糖仪1 血压计 2
  289. params.userType=userType;//是否多用户,1.爸爸建,2.妈妈键
  290. if(rowData.id){
  291. params.id = rowData.id;
  292. }
  293. sendPost("/patient/device/SavePatientDevice",{"json":JSON.stringify(params)},"JSON","post",
  294. function(res){
  295. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定失败!'}).show();
  296. },
  297. function(res){
  298. if(res.status == '200'){
  299. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定成功!'}).show();
  300. setTimeout(function(){
  301. window.location.href='my-equipments.html';
  302. },500);
  303. }else{
  304. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  305. }
  306. }
  307. )
  308. }
  309. function openedit(){
  310. location.href="edit-xueyaji.html?deviceId="+deviceId+"&id="+dataId+"&categoryCode=" + type;
  311. }
  312. function deleteSn(code){
  313. sendPost("patient/device/DeletePatientDevice?id="+code,{},"JSON","get",function(res){
  314. if (res && res.msg) {
  315. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  316. } else {
  317. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  318. }
  319. },function(res){
  320. if(res.status==200){
  321. location.href="my-equipments.html";
  322. }else{
  323. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  324. }
  325. })
  326. }