edit-xueyaji.js 13 KB

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