view-xuetangyi.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. var rowData={};
  2. var sn="";//记录sn码
  3. var dataId = null;
  4. var type = null;
  5. var name = null;
  6. var type = null;
  7. var photoUrl = null;
  8. var deviceId = null;
  9. var oldSn="";//旧sn
  10. $(function() {
  11. Request = GetRequest();
  12. dataId = Request["id"];
  13. deviceId = Request["deviceId"];
  14. getDeviceInfo(deviceId);
  15. bindEvents();
  16. initData(dataId);
  17. });
  18. function initData(dataId){
  19. var params = {};
  20. params.id=dataId;
  21. sendPost("patient/device/PatientDeviceInfo",params,"JSON","GET",
  22. function(res){
  23. if(res.msg){
  24. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  25. }else{
  26. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
  27. }
  28. },
  29. function(res){
  30. if(res.status==200){
  31. rowData = res.data;
  32. oldSn = rowData.deviceSn;
  33. $("#sncode").val(rowData.device.deviceSn);
  34. // var html = template('listTempl',res.data.time);
  35. // $('#duringList').html(html);
  36. console.log(rowData);
  37. var fasting = (rowData.time['fasting'].replace(/ /g, '')).split('-'),
  38. afterBreakFast = (rowData.time['afterBreakFast'].replace(/ /g, '')).split('-'),
  39. beforeLunch = (rowData.time['beforeLunch'].replace(/ /g, '')).split('-'),
  40. afterLunch = (rowData.time['afterLunch'].replace(/ /g, '')).split('-'),
  41. beforeDinner = (rowData.time['beforeDinner'].replace(/ /g, '')).split('-'),
  42. afterDinner = (rowData.time['afterDinner'].replace(/ /g, '')).split('-'),
  43. beforeSleep = (rowData.time['beforeSleep'].replace(/ /g, '')).split('-');
  44. $('#mobIn1').val(fasting[0].substring(0,5) + '-' + fasting[1].substring(0,5));
  45. $('#mobIn2').val(afterBreakFast[0].substring(0,5) + '-' + afterBreakFast[1].substring(0,5));
  46. $('#mobIn3').val(beforeLunch[0].substring(0,5) + '-' + beforeLunch[1].substring(0,5));
  47. $('#mobIn4').val(afterLunch[0].substring(0,5) + '-' + afterLunch[1].substring(0,5));
  48. $('#mobIn5').val(beforeDinner[0].substring(0,5) + '-' + beforeDinner[1].substring(0,5));
  49. $('#mobIn6').val(afterDinner[0].substring(0,5) + '-' + afterDinner[1].substring(0,5));
  50. $('#mobIn7').val(beforeSleep[0].substring(0,5) + '-' + beforeSleep[1].substring(0,5));
  51. // $('#mobIn1').val(rowData.time['fasting'].replace(/ /g,''));
  52. // $('#mobIn2').val(rowData.time['afterBreakFast'].replace(/ /g,''));
  53. // $('#mobIn3').val(rowData.time['beforeLunch'].replace(/ /g,''));
  54. // $('#mobIn4').val(rowData.time['afterLunch'].replace(/ /g,''));
  55. // $('#mobIn5').val(rowData.time['beforeDinner'].replace(/ /g,''));
  56. // $('#mobIn6').val(rowData.time['afterDinner'].replace(/ /g,''));
  57. // $('#mobIn7').val(rowData.time['beforeSleep'].replace(/ /g,''));
  58. }else{
  59. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
  60. }
  61. }
  62. )
  63. }
  64. //判断值是否改变过
  65. function isValueChange(){
  66. var changeTagStr = $("#sncode").val();
  67. if(oldSn!=changeTagStr){
  68. }
  69. }
  70. //绑定事件
  71. function bindEvents(){
  72. //添加isrcoll
  73. // var scroller1 = new IScrollPullUpDown('wrapper',{
  74. // probeType:2,
  75. // bounceTime: 250,
  76. // bounceEasing: 'quadratic',
  77. // mouseWheel:false,
  78. // scrollbars:true,
  79. // click:true,
  80. // fadeScrollbars:true,
  81. // interactiveScrollbars:false
  82. // },null,null);
  83. $("#del-btn").bind("click",function(){
  84. dialog({
  85. content: '解绑设备信息,将会导致医生无法实时<br/>关注到您的体征变化。是否继续解绑?',
  86. okValue:'确定',
  87. ok: function (){
  88. deleteSn(dataId);
  89. },
  90. cancelValue: '取消',
  91. cancel: function () {
  92. return;
  93. }
  94. }).showModal();
  95. })
  96. $("#edit-btn").bind("click",function(){
  97. openedit();
  98. })
  99. }
  100. function checkSnBind(snCode,checkSuccess){
  101. var b = /^[0-9a-zA-Z]*$/g;
  102. if(!b.test(snCode)){
  103. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'对不起,您输入的SN有误,请重新输入!'}).show();
  104. return false;
  105. }
  106. var params = {};
  107. params.type=type;
  108. params.device_sn = snCode;
  109. sendPost("patient/device/PatientDeviceIdcard",params,"JSON","GET",
  110. function(res){
  111. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备SN校验失败!'}).show();
  112. },function(res){
  113. if(res.status==200){
  114. var name = "" ;
  115. var others = null;
  116. for(var j in res.data){
  117. name = res.data[j].name;
  118. others = res.data[j].others
  119. }
  120. //没被绑定
  121. if(name==""){
  122. $("#bang-btn").addClass("active");
  123. if(checkSuccess!=null){
  124. checkSuccess(snCode);
  125. }
  126. }else if(others!=null&&others==1){
  127. // $("#bang-btn").removeClass("active");
  128. //被绑定而且被别人绑定
  129. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'该设备已被他人绑定,设备解绑后,方可再次绑定!'}).show();
  130. }
  131. else if(others!=null&&others==0){
  132. // $("#bang-btn").removeClass("active");
  133. if(deviceId==null||!deviceId||deviceId==""){
  134. //新增,编辑/被自己绑定
  135. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'对不起,您已绑定过该设备,解绑后方可继续绑定!'}).show();
  136. }else{
  137. if(checkSuccess!=null){
  138. checkSuccess(snCode);
  139. }
  140. }
  141. }
  142. }
  143. }
  144. );
  145. }
  146. function getDeviceInfo(deviceId){
  147. sendPost("/common/device/DeviceInfo?id="+deviceId,{},"JSON","GET",
  148. function(res){
  149. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息获取失败!'}).show();
  150. },
  151. function(res){
  152. if(res.status==200){
  153. var rowData1 = res.data;
  154. type = rowData1.categoryCode;
  155. name = rowData1.name;
  156. photoUrl = getImgUrl(rowData1.photo);
  157. $(".deviceName").html(name);
  158. $(".div-xuetangyi-img img").attr("src",photoUrl);
  159. }else{
  160. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息获取失败!'}).show();
  161. }
  162. }
  163. )
  164. }
  165. function checkSuccess(snCode){
  166. var name1="血糖仪-"+name;
  167. var params ={};
  168. params.deviceId=deviceId;//设备ID
  169. params.deviceName=name1;//设备名称
  170. params.deviceSn=snCode;//设备SN码
  171. params.categoryCode=type;//设备分类 血糖仪1 血压计 2
  172. params.userType="-1";//是否多用户
  173. if(rowData.id){
  174. params.id = rowData.id;
  175. }
  176. sendPost("/patient/device/SavePatientDevice",{"json":JSON.stringify(params)},"JSON","post",
  177. function(res){
  178. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定失败!'}).show();
  179. },
  180. function(res){
  181. if(res.status==200){
  182. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定成功!'}).show();
  183. setTimeout(function(){
  184. window.location.href='my-equipments.html';
  185. },1000);
  186. }else{
  187. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  188. return false;
  189. }
  190. }
  191. )
  192. }
  193. function openedit(){
  194. location.href="edit-xuetangyi.html?deviceId="+deviceId+"&id="+dataId+"&categoryCode=" + type;
  195. }
  196. function deleteSn(code){
  197. sendPost("patient/device/DeletePatientDevice?id="+code,{},"JSON","get",function(res){
  198. if (res && res.msg) {
  199. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  200. } else {
  201. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  202. }
  203. },function(res){
  204. if(res.status==200){
  205. location.href="my-equipments.html";
  206. }else{
  207. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  208. }
  209. })
  210. }