view-xueyaji.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. var scroller1 = null;
  11. var role = null;
  12. mui.init();
  13. mui.plusReady(function() {
  14. self = plus.webview.currentWebview();
  15. dataId = self.dataId;
  16. deviceId = self.deviceId;
  17. patient = self.patient;
  18. role = self.role;
  19. initPage();
  20. scroller1= new IScrollPullUpDown('wrapper',{
  21. probeType:2,
  22. bounceTime: 250,
  23. bounceEasing: 'quadratic',
  24. mouseWheel:false,
  25. scrollbars:true,
  26. click:true,
  27. fadeScrollbars:true,
  28. interactiveScrollbars:false
  29. },pullDownAction,pullUpAction);
  30. //下拉刷新
  31. function pullDownAction(theScrollerTemp) {
  32. initPage();
  33. }
  34. //上拉加载数据
  35. function pullUpAction(theScrollerTemp) {
  36. scroller1._resize();
  37. }
  38. });
  39. function initPage(){
  40. getDeviceInfo(deviceId);
  41. isValueChange();
  42. bindEvents();
  43. initData(dataId);
  44. }
  45. function initData(dataId){
  46. sendGet("doctor/device/PatientDeviceInfo?id="+dataId,{},
  47. function(res){
  48. mui.toast("设备信息初始化失败!");
  49. },
  50. function(res){
  51. if(res.status==200){
  52. rowData = res.data;
  53. docInfo= JSON.parse(plus.storage.getItem("docInfo"));
  54. // if(rowData.doctor==docInfo.code){
  55. // $("#footer").show();
  56. // }
  57. if(role=="1") {
  58. $("#footer").show();
  59. } else{
  60. $(scroller1.wrapper).css("height","100%");
  61. scroller1._resize();
  62. }
  63. $("#sncode").val(rowData.deviceSn);
  64. checkSnBind(rowData.deviceSn);
  65. userType = rowData.userType;
  66. oldSn = rowData.deviceSn;
  67. if(userType==1){
  68. $(".father").addClass("active");
  69. }
  70. if(userType==2){
  71. $(".monther").addClass("active");
  72. }
  73. if(deviceId == 6){
  74. $("#simDiv").show();
  75. $("#simcode").val(rowData.sim);
  76. }
  77. scroller1._resize();
  78. }else{
  79. mui.toast("设备信息初始化失败!");
  80. }
  81. }
  82. )
  83. }
  84. function getDeviceInfo(deviceId){
  85. sendGet("common/device/DeviceInfo?id="+deviceId,{},
  86. function(res){
  87. mui.toast("设备信息获取失败!");
  88. },
  89. function(res){
  90. if(res.status==200){
  91. var rowData1 = res.data;
  92. type = rowData1.categoryCode;
  93. name = rowData1.name;
  94. photoUrl = rowData1.photo;
  95. var multiUser = JSON.parse(rowData1.multiUser);
  96. for(var key in multiUser){
  97. if(key==1){
  98. $(".key-one").html(multiUser[key]);
  99. }else{
  100. $(".key-two").html(multiUser[key]);
  101. }
  102. }
  103. $(".deviceName").html(name);
  104. $(".div-xueyaji-img img").attr("src",getImgUrl(photoUrl))
  105. }else{
  106. mui.toast("设备信息获取失败!");
  107. }
  108. }
  109. )
  110. }
  111. //绑定事件
  112. function bindEvents(){
  113. //保存方法
  114. $("#del-btn").bind("click",function(){
  115. mui.confirm("设备解绑后,将无法自动从设备获取相关数据。是否继续解绑?", "提示", ["继续解绑","不了,谢谢"], function(e) {
  116. if(e.index==0){
  117. deleteSn(dataId);
  118. return;
  119. }else{
  120. return;
  121. }
  122. });
  123. })
  124. $("#edit-btn").bind("click",function(){
  125. editXueyaji();
  126. })
  127. }
  128. function isValueChange(){
  129. var self = this;
  130. var int= setInterval(function() {
  131. var changeTagStr = $("#sncode").val();
  132. if(oldSn!=changeTagStr){
  133. clearInterval(int);
  134. int = null;
  135. $("#bang-btn").addClass("active");
  136. }
  137. },300);
  138. }
  139. function checkSnBind(snCode,suc){
  140. var b = /^[0-9a-zA-Z]*$/g;
  141. if(!b.test(snCode)){
  142. mui.toast("对不起,您输入的SN有误,请重新输入");
  143. $("#bang-btn").addClass("active");
  144. return false;
  145. }
  146. var params = {};
  147. params.type=type;
  148. params.device_sn = snCode;
  149. params.patient = patient;
  150. sendGet("doctor/device/PatientDeviceIdcard",params,
  151. function(res){
  152. $("#bang-btn").addClass("active");
  153. mui.toast(res);
  154. },function(res){
  155. if(res.status==200){
  156. if(res.data.length==0&&suc){
  157. suc(snCode);
  158. return;
  159. }
  160. //遍历绑定信息
  161. var isbind = false;//是否绑定
  162. var bindnum = 0;
  163. var showTitle = "";
  164. var fatherData = null;
  165. var montherData = null;
  166. //循环取出爸爸妈妈健的数据
  167. for(var j in res.data){
  168. var data = res.data[j];//取出设置
  169. var dataType = data['type'];//按键类型1.爸爸建2.妈妈键
  170. var others = data['others'];//others==1为被别人绑定
  171. if(dataType==1){
  172. fatherData = data;
  173. if(others==1){
  174. bindnum+=1;
  175. if(userType==1) userType = 0 ;//被绑定
  176. $(".father").attr("data-click","0");//设置键1无法点击
  177. $(".fatherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
  178. $(".div-father-band").show();//显示绑定信息
  179. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  180. $(".father").removeClass("active");
  181. showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
  182. }
  183. }
  184. }else{
  185. montherData = data;
  186. if(others==1){
  187. if(userType==2) userType = 0 ;//被绑定
  188. $(".monther").attr("data-click","0");//设置键2无法点击
  189. $(".montherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
  190. $(".div-monther-band").show();//显示绑定信息
  191. bindnum+=1;
  192. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  193. $(".monther").removeClass("active");
  194. showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
  195. }
  196. }
  197. }
  198. }
  199. if(bindnum==2){
  200. mui.confirm("该设备所有快捷键已被绑定,解绑快捷键后,方可再次绑定!", "", ["我知道了"], function(e) {
  201. return;
  202. });
  203. $("#bang-btn").addClass("active");
  204. return false;
  205. }
  206. else if(bindnum==1&&showTitle!=""){//被绑定的按键选项
  207. mui.confirm(showTitle, "", ["我知道了"], function(e) {
  208. return;
  209. });
  210. $("#bang-btn").addClass("active");
  211. return false;
  212. }
  213. if(fatherData!=null){
  214. var others = fatherData['others'];//others==1为被别人绑定
  215. if(others!=1){//被别人绑定了
  216. //被自己绑定
  217. if(dataId == null){
  218. //新增的时候输入被自己绑定的SN码
  219. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  220. $(".monther").attr("data-click","-1");
  221. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  222. $(".father").removeClass("active");
  223. }
  224. mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
  225. return;
  226. });
  227. $("#bang-btn").addClass("active");
  228. return false;//直接退出不保存
  229. }else{
  230. if(!suc){//界面初始化的时候没有校验成功回调
  231. userType = 1;
  232. //选中爸爸键
  233. $(".father").addClass("active");
  234. }else if(oldSn!=snCode){
  235. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  236. $(".monther").attr("data-click","-1");
  237. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  238. $(".father").removeClass("active");
  239. }
  240. mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
  241. return;
  242. });
  243. $("#bang-btn").addClass("active");
  244. return false;//直接退出不保存
  245. }
  246. }
  247. }
  248. }
  249. if(montherData!=null){
  250. var others = montherData['others'];//others==1为被别人绑定
  251. if(others!=1){
  252. //被自己绑定
  253. if(dataId == null){
  254. //新增的时候输入被自己绑定的SN码
  255. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  256. $(".monther").attr("data-click","-1");
  257. //$(".monther").addClass("active");//自己绑定了的键设置高亮
  258. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  259. $(".monther").removeClass("active");
  260. }
  261. mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
  262. return;
  263. });
  264. $("#bang-btn").addClass("active");
  265. return false;//直接退出不保存
  266. }else{
  267. if(!suc){
  268. userType = 2;
  269. //选中妈妈键
  270. $(".monther").addClass("active");
  271. }else if(oldSn!=snCode){
  272. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  273. $(".monther").attr("data-click","-1");
  274. //$(".monther").addClass("active");//自己绑定了的键设置高亮
  275. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  276. $(".monther").removeClass("active");
  277. }
  278. mui.confirm("对不起,该居民已绑定过该设备,解绑后方可继续操作", "", ["我知道了"], function(e) {
  279. return;
  280. });
  281. $("#bang-btn").addClass("active");
  282. return false;//直接退出不保存
  283. }
  284. }
  285. }
  286. }
  287. if(suc){
  288. suc(snCode);
  289. }
  290. }else{
  291. $("#bang-btn").addClass("active");
  292. mui.toast("设备SN校验失败!");
  293. }
  294. }
  295. );
  296. }
  297. function checkSuccess(snCode){
  298. if(userType==0){
  299. mui.toast("请选择要绑定的快捷键!");
  300. $("#bang-btn").addClass("active");
  301. return false;
  302. }
  303. var name1="血压计-"+name;
  304. var params ={};
  305. params.deviceId=deviceId;//设备ID
  306. params.deviceName=name1;//设备名称
  307. params.deviceSn=snCode;//设备SN码
  308. params.categoryCode=type;//设备分类 血糖仪1 血压计 2
  309. params.userType=userType;//是否多用户,1.爸爸建,2.妈妈键
  310. params.user = patient;
  311. if(rowData.id){
  312. params.id = rowData.id;
  313. }
  314. sendPost("doctor/device/SavePatientDevice",{"data":JSON.stringify(params)},
  315. function(res){
  316. mui.toast("设备绑定失败!");
  317. $("#bang-btn").addClass("active");
  318. },
  319. function(res){
  320. if(res.status == '200'){
  321. mui.toast("设备绑定成功!");
  322. setTimeout(function(){
  323. openwdsb();
  324. },1000);
  325. }else{
  326. $("#bang-btn").addClass("active");
  327. mui.toast(res.msg);
  328. }
  329. }
  330. )
  331. }
  332. function openwdsb(){
  333. var page = plus.webview.getWebviewById("health-record");
  334. if(page){
  335. mui.fire(page,'refreshEquipment')
  336. }
  337. var page2 = plus.webview.getWebviewById("my-equipments");
  338. if(page2){
  339. mui.fire(page2,'refreshEquipment')
  340. }
  341. setTimeout(function(){
  342. var pa1 = plus.webview.getWebviewById("list-xueyaji.html");
  343. if(pa1){pa1.close()}
  344. var pa2 = plus.webview.getWebviewById("list-xuetangyi.html");
  345. if(pa2){pa2.close()}
  346. var pa3 = plus.webview.getWebviewById("edit-xueyaji");
  347. if(pa3){pa3.close()}
  348. var pa4 = plus.webview.getWebviewById("edit-xuetangyi");
  349. if(pa4){pa4.close()}
  350. var pa5 = plus.webview.getWebviewById("view-xueyaji.html");
  351. if(pa5){pa5.close()}
  352. var pa6 = plus.webview.getWebviewById("view-xuetangyi.html");
  353. if(pa6){pa6.close()}
  354. plus.nativeUI.closeWaiting();
  355. mui.back()
  356. },1000)
  357. }
  358. function editXueyaji(){
  359. var params = {};
  360. params.deviceId = deviceId;
  361. params.dataId = dataId;
  362. params.patient = patient;
  363. openWebviewExtras("edit-xueyaji.html",params);
  364. }
  365. function deleteSn(code){
  366. plus.nativeUI.showWaiting();
  367. sendPost("doctor/device/DeletePatientDevice?id="+code,{},function(res){
  368. plus.nativeUI.closeWaiting();
  369. if (res && res.msg) {
  370. mui.toast(res.msg);
  371. } else {
  372. mui.toast("解绑设备失败!");
  373. }
  374. },function(res){
  375. if(res.status==200){
  376. $(".c-list").html("");
  377. if(res.data && res.data.length) {
  378. var userName = (res.data[0] && res.data[0].username) || "";
  379. mui.confirm("解绑成功,该血压计还绑定了居民"+userName+",可到该居民页解绑或联系管理员在管理页面进行设备解绑", "", ["我知道了"], function(e) {
  380. openwdsb();
  381. });
  382. } else {
  383. mui.toast("解绑设备成功!");
  384. openwdsb();
  385. }
  386. }else{
  387. plus.nativeUI.closeWaiting();
  388. mui.toast("解绑设备失败!");
  389. }
  390. },"GET")
  391. }