edit-xuetangyi.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. var rowData={};
  2. var sn="";//记录sn码
  3. var dataId = null;
  4. var type = null;
  5. var name = null;
  6. var photoUrl = null;
  7. var deviceId = null;
  8. var patient = null;
  9. var self;
  10. var oldSn="";//旧sn
  11. mui.init();
  12. mui.plusReady(function() {
  13. plus.nativeUI.showWaiting();
  14. self = plus.webview.currentWebview();
  15. dataId = self.dataId;
  16. deviceId = self.deviceId;
  17. patient = self.patient;
  18. initPage();
  19. if(deviceId == 5){
  20. //三诺亲智的设备,建议扫描设备背面的条形码获取SN码。(因为厂家提供的二维码不好扫)
  21. $("#device5Msg").show();
  22. }else{
  23. $("#device5Msg").hide();
  24. }
  25. });
  26. $(function(){
  27. //添加isrcoll
  28. var scroller1 = new IScrollPullUpDown('wrapper',{
  29. probeType:2,
  30. bounceTime: 250,
  31. bounceEasing: 'quadratic',
  32. mouseWheel:false,
  33. scrollbars:true,
  34. click:true,
  35. fadeScrollbars:true,
  36. interactiveScrollbars:false
  37. },null,null);
  38. })
  39. function initPage(){
  40. getDeviceInfo(deviceId);
  41. bindEvents();
  42. if(dataId&&dataId!=null){
  43. $(document).attr("title","编辑血糖仪");
  44. $("#titileH1").html("编辑血糖仪");
  45. initData(dataId);
  46. $("#bang-btn").html("保存");
  47. }else{
  48. $("#titileH1").html("新增血糖仪");
  49. $(document).attr("title","新增血糖仪");
  50. }
  51. $("#bang-btn").addClass("active");
  52. }
  53. function initData(dataId){
  54. var params = {};
  55. params.id=dataId;
  56. sendGet("doctor/device/PatientDeviceInfo",params,
  57. function(res){
  58. if(res.msg){
  59. mui.toast(res.msg);
  60. }else{
  61. mui.toast("设备信息初始化失败!");
  62. }
  63. },
  64. function(res){
  65. if(res.status==200){
  66. rowData = res.data;
  67. oldSn = rowData.deviceSn;
  68. $("#sncode").val(rowData.deviceSn);
  69. }else{
  70. mui.toast("设备信息初始化失败!");
  71. }
  72. })
  73. }
  74. //判断值是否改变过
  75. function isValueChange(){
  76. var changeTagStr = $("#sncode").val();
  77. if(oldSn!=changeTagStr){
  78. }
  79. }
  80. //绑定事件
  81. function bindEvents(){
  82. //保存方法
  83. $("#bang-btn").bind("click",function(){
  84. if($(this).hasClass("active")){
  85. var snCode = $("#sncode").val();
  86. $("#bang-btn").removeClass("active");
  87. if(snCode==null||snCode==""){
  88. mui.toast("请输入设备的SN码进行绑定!");
  89. }else{
  90. plus.nativeUI.showWaiting();
  91. $("#bang-btn").html("正在绑定");
  92. checkSnBind(snCode,checkSuccess);
  93. }
  94. }
  95. });
  96. //扫描二维码
  97. $(".scanText").on('click', function(){
  98. openWebview("scan.html");
  99. });
  100. window.addEventListener("getScanResult", function(e){
  101. var result = e.detail.result;
  102. $("#sncode").val(result);
  103. });
  104. }
  105. function checkSnBind(snCode,checkSuccess){
  106. var b = /^[0-9a-zA-Z]*$/g;
  107. if(!b.test(snCode)){
  108. $("#bang-btn").html("立即绑定");
  109. plus.nativeUI.closeWaiting();
  110. mui.confirm("对不起,您输入的SN有误,请重新输入", "", ["我知道了"], function(e) {
  111. return;
  112. });
  113. $("#bang-btn").addClass("active");
  114. return false;
  115. }
  116. var params = {};
  117. params.type=type;
  118. params.device_sn = snCode;
  119. params.patient = patient;
  120. mui.ajax(server + "doctor/device/PatientDeviceIdcard", {
  121. data: params || {},
  122. async: false,
  123. dataType: 'json',
  124. //crossDomain: true,
  125. type: "get",
  126. timeout: 10000,
  127. error: function(res){
  128. $("#bang-btn").addClass("active");
  129. mui.toast(res);
  130. $("#bang-btn").html("立即绑定");
  131. plus.nativeUI.closeWaiting();
  132. },
  133. success: function(res){
  134. $("#bang-btn").html("立即绑定");
  135. plus.nativeUI.closeWaiting();
  136. if(res.status==200){
  137. var name = "" ;
  138. var others = null;
  139. for(var j in res.data){
  140. name = res.data[j].name;
  141. others = res.data[j].others
  142. }
  143. //没被绑定
  144. if(name==""){
  145. if(checkSuccess!=null){
  146. checkSuccess(snCode);
  147. }
  148. return false;
  149. }else if(others!=null&&others==1){
  150. // $("#bang-btn").removeClass("active");
  151. //被绑定而且被别人绑定
  152. mui.confirm("该设备已被他人绑定,设备解绑后,方可再次绑定", "", ["我知道了"], function(e) {
  153. $("#bang-btn").addClass("active");
  154. return;
  155. });
  156. return false;
  157. }
  158. else if(others!=null&&others==0){
  159. // $("#bang-btn").removeClass("active");
  160. if(oldSn!=snCode){
  161. //新增,编辑/被自己绑定
  162. mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
  163. $("#bang-btn").addClass("active");
  164. return;
  165. });
  166. return;
  167. }else{
  168. if(checkSuccess!=null){
  169. checkSuccess(snCode);
  170. return false;
  171. }
  172. }
  173. }
  174. } else {
  175. $("#bang-btn").addClass("active");
  176. }
  177. }
  178. });
  179. }
  180. function getDeviceInfo(deviceId){
  181. sendGet("common/device/DeviceInfo?id="+deviceId,{},
  182. function(res){
  183. plus.nativeUI.closeWaiting();
  184. mui.toast("设备信息获取失败!");
  185. },
  186. function(res){
  187. plus.nativeUI.closeWaiting();
  188. if(res.status==200){
  189. var rowData1 = res.data;
  190. type = rowData1.categoryCode;
  191. name = rowData1.name;
  192. photoUrl = rowData1.photo;
  193. $(".deviceName").html(name);
  194. $(".div-xuetangyi-img img").attr("src",getImgUrl(photoUrl));
  195. }else{
  196. mui.toast("设备信息获取失败!");
  197. }
  198. })
  199. }
  200. function checkSuccess(snCode){
  201. var name1="血糖仪-"+name;
  202. var params ={};
  203. params.deviceId=deviceId;//设备ID
  204. params.deviceName=name1;//设备名称
  205. params.deviceSn=snCode;//设备SN码
  206. params.categoryCode=type;//设备分类 血糖仪1 血压计 2
  207. params.userType="-1";//是否多用户
  208. params.user=patient;
  209. if(rowData.id){
  210. params.id = rowData.id;
  211. }
  212. sendPost("doctor/device/SavePatientDevice",{"data":JSON.stringify(params)},
  213. function(res){
  214. mui.toast("设备信息获取失败!");
  215. $("#bang-btn").addClass("active");
  216. },
  217. function(res){
  218. if(res.status==200){
  219. mui.toast("设备绑定成功");
  220. openwdsb();
  221. }else{
  222. $("#bang-btn").addClass("active");
  223. mui.toast(res.msg);
  224. return false;
  225. }
  226. }
  227. )
  228. }
  229. function openwdsb(){
  230. var page = plus.webview.getWebviewById("health-record");
  231. if(page){
  232. mui.fire(page,'refreshEquipment')
  233. }
  234. var page2 = plus.webview.getWebviewById("my-equipments");
  235. if(page2){
  236. mui.fire(page2,'refreshEquipment')
  237. }
  238. var page3 = plus.webview.getWebviewById("huanzhe.html");
  239. if(page3){
  240. mui.fire(page3,'refresh')
  241. }
  242. setTimeout(function(){
  243. var cur = plus.webview.currentWebview(),
  244. opener = cur.opener(),
  245. preOpener = opener && opener.opener()
  246. mui.fire(preOpener,'refreshEquipment')
  247. var pa1 = plus.webview.getWebviewById("list-xueyaji.html");
  248. if(pa1){pa1.close()}
  249. var pa2 = plus.webview.getWebviewById("list-xuetangyi.html");
  250. if(pa2){pa2.close()}
  251. var pa3 = plus.webview.getWebviewById("edit-xueyaji");
  252. if(pa3){pa3.close()}
  253. var pa5 = plus.webview.getWebviewById("view-xueyaji.html");
  254. if(pa5){pa5.close()}
  255. var pa6 = plus.webview.getWebviewById("view-xuetangyi.html");
  256. if(pa6){pa6.close()}
  257. var pa4 = plus.webview.getWebviewById("edit-xuetangyi");
  258. if(pa4){pa4.close()}
  259. backToWebviewById(preOpener.id)()
  260. },1000)
  261. }