edit-xueyaji.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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 prescriptionCode;
  10. var oldSn="";//旧sn
  11. var categoryCode = '';
  12. var d = dialog({contentType:'load', skin:'bk-popup'});
  13. var $member = $('#member');
  14. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  15. $(function() {
  16. Request = GetRequest();
  17. dataId = Request["id"];
  18. deviceId = Request["deviceId"];
  19. categoryCode = Request["categoryCode"];
  20. prescriptionCode = Request["prescriptionCode"];
  21. getDeviceInfo(deviceId);
  22. bindEvents();
  23. $("#bang-btn").addClass("active");
  24. if(deviceId == 6){ //云湃*脉搏波RBP-980
  25. $("#simDiv").show();
  26. $(".scanText").removeClass("c-border-l");
  27. }
  28. if(dataId){
  29. $(document).attr("title","编辑血压计");
  30. initData(dataId);
  31. $("#bang-btn").html("保存");
  32. }else{
  33. $(document).attr("title","新增血压计");
  34. }
  35. isValueChange();
  36. weixinSign();
  37. });
  38. function initData(dataId){
  39. sendPost("patient/device/PatientDeviceInfo?id="+dataId,{},"JSON","GET",
  40. function(res){
  41. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
  42. },
  43. function(res){
  44. if(res.status==200){
  45. rowData = res.data;
  46. $("#sncode").val(rowData.device.deviceSn);
  47. checkSnBind(rowData.device.deviceSn);
  48. userType = rowData.device.userType;
  49. oldSn = rowData.device.deviceSn;
  50. if(userType==1){
  51. $(".father").addClass("active");
  52. }
  53. if(userType==2){
  54. $(".monther").addClass("active");
  55. }
  56. if(deviceId == 6){
  57. $("#simDiv").show();
  58. $("#simcode").val(rowData.device.sim);
  59. }
  60. }else{
  61. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息初始化失败!'}).show();
  62. }
  63. }
  64. )
  65. }
  66. //获取家庭成员
  67. Promise.all([familyAllMembers()]).then(function(data){
  68. var arr_code=_.pluck(data[0], 'code');
  69. var arr_name=_.pluck(data[0], 'name');
  70. //关联被代理人
  71. if(userAgent.represented){
  72. var one = _.find(data[0],function(item){return item.code == userAgent.represented;})
  73. $member.attr('data-val',one.code);
  74. $member.val(one.name);
  75. }else{
  76. $member.attr('data-val',arr_code[0]);
  77. $member.val(arr_name[0]);
  78. }
  79. })
  80. function getDeviceInfo(deviceId){
  81. sendPost("/common/device/DeviceInfo?id="+deviceId,{},"JSON","GET",
  82. function(res){
  83. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true, content:'设备信息获取失败!'}).show();
  84. },
  85. function(res){
  86. if(res.status==200){
  87. var rowData1 = res.data;
  88. type = rowData1.categoryCode;
  89. name = rowData1.name;
  90. photoUrl = getImgUrl(rowData1.photo);
  91. var multiUser = JSON.parse(rowData1.multiUser);
  92. for(var key in multiUser){
  93. if(key==1){
  94. $(".key-one").html(multiUser[key]);
  95. }else{
  96. $(".key-two").html(multiUser[key]);
  97. }
  98. }
  99. $(".deviceName").html(name);
  100. $(".div-xueyaji-img img").attr("src",photoUrl)
  101. }else{
  102. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备信息获取失败!'}).show();
  103. }
  104. }
  105. )
  106. }
  107. //绑定事件
  108. function bindEvents(){
  109. //点击绑定快捷键事件
  110. $(".c-quick-list").on("click",".li-key",function(){
  111. var newDom = $(this).find(".key-img");
  112. var canclick = newDom.attr("data-click");
  113. var userName = $(this).find(".div-band-info").html();
  114. if(canclick==0){
  115. var title = '该快捷键'+userName+'注册,需解除与该快捷键的绑定关系后,方能完成绑定';
  116. dialog({
  117. content: title,
  118. cancelValue: '我知道了',
  119. cancel: function () {
  120. return;
  121. }
  122. }).showModal();
  123. return;
  124. }else if(canclick==-1){
  125. var title = '对不起,您已绑定过该设备,解绑后方可继续绑定';
  126. dialog({
  127. content: title,
  128. cancelValue: '我知道了',
  129. cancel: function () {
  130. return;
  131. }
  132. }).showModal();
  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. var snCode = $("#sncode").val();
  139. if(snCode!=null&&snCode!=""){
  140. }
  141. })
  142. //保存方法
  143. $("#bang-btn").bind("click",function(){
  144. if($(this).hasClass("active")){
  145. var snCode = $("#sncode").val();
  146. if(snCode==null||snCode==""){
  147. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请输入设备的SN码进行绑定!'}).show();
  148. }else{
  149. $("#bang-btn").html("正在绑定").css("pointer-events","none");;
  150. d.show();
  151. checkSnBind(snCode,checkSuccess);
  152. }
  153. }
  154. })
  155. $("#sncode").on("input",function(){
  156. var snCode = $(this).val();
  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. $(".scanText").on('click', function(){
  167. wx.scanQRCode({
  168. desc: 'scanQRCode desc',
  169. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  170. scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  171. success: function (res) {
  172. // 回调
  173. var code = res.resultStr,
  174. arr = code.split(" ");
  175. if(deviceId == 6){
  176. $("#sncode").val(arr[1]);
  177. $("#simcode").val(arr[0]);
  178. }else{
  179. var arr2 = code.split(","); //因为微信扫描条形码的时候,会带上这个码的类型,所以取数组后的码显示
  180. if(arr2.length > 1){
  181. $("#sncode").val(arr2[1]);
  182. }else{
  183. $("#sncode").val(arr2[0]);
  184. }
  185. }
  186. },
  187. error: function(res){
  188. if(res.errMsg.indexOf('function_not_exist') > 0){
  189. alert('版本过低请升级')
  190. }
  191. }
  192. });
  193. })
  194. }
  195. function isValueChange(){
  196. var self = this;
  197. var int= setInterval(function() {
  198. var changeTagStr = $("#sncode").val();
  199. if(oldSn!=changeTagStr){
  200. clearInterval(int);
  201. int = null;
  202. $("#bang-btn").addClass("active");
  203. }
  204. },300);
  205. }
  206. function checkSnBind(snCode,suc){
  207. var b = /^[0-9a-zA-Z]*$/g;
  208. if(!b.test(snCode)){
  209. setTimeout(function(){
  210. $("#bang-btn").html("立即绑定").css("pointer-events","");
  211. },3000);
  212. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'对不起,您输入的SN有误,请重新输入!'}).show();
  213. d.close();
  214. return false;
  215. }
  216. var params = {};
  217. params.type=type;
  218. params.device_sn = snCode;
  219. $.ajax(server + "patient/device/PatientDeviceIdcard", {
  220. data: params,
  221. dataType: "JSON",
  222. async:false,
  223. type: "get",
  224. timeout:10000,
  225. beforeSend: function(request) {
  226. var userAgent = window.localStorage.getItem(agentName);
  227. request.setRequestHeader("userAgent", userAgent);
  228. },
  229. error:function(res){
  230. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res}).show();
  231. setTimeout(function(){
  232. $("#bang-btn").html("立即绑定").css("pointer-events","");
  233. d.close();
  234. },3000);
  235. },success:function(res){
  236. d.close();
  237. setTimeout(function(){
  238. $("#bang-btn").html("立即绑定").css("pointer-events","");
  239. },3000);
  240. if(res.status==200){
  241. if(res.data.length==0&&suc){
  242. if (dataId) {
  243. d.close();
  244. editSN(snCode);
  245. } else {
  246. suc(snCode);
  247. }
  248. return;
  249. }
  250. //遍历绑定信息
  251. var isbind = false;//是否绑定
  252. var bindnum = 0;
  253. var showTitle = "";
  254. var fatherData = null;
  255. var montherData = null;
  256. //循环取出爸爸妈妈健的数据
  257. for(var j in res.data){
  258. var data = res.data[j];//取出设置
  259. var dataType = data['type'];//按键类型1.爸爸建2.妈妈键
  260. var others = data['others'];//others==1为被别人绑定
  261. if(dataType==1){
  262. fatherData = data;
  263. if(others==1){
  264. bindnum+=1;
  265. if(userType==1) userType = 0 ;//被绑定
  266. $(".father").attr("data-click","0");//设置键1无法点击
  267. $(".fatherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
  268. $(".div-father-band").show();//显示绑定信息
  269. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  270. $(".father").removeClass("active");
  271. showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
  272. }
  273. }
  274. }else{
  275. montherData = data;
  276. if(others==1){
  277. if(userType==2) userType = 0 ;//被绑定
  278. $(".monther").attr("data-click","0");//设置键2无法点击
  279. $(".montherbf").html("已经被"+data['name']+"绑定");//设置绑定信息
  280. $(".div-monther-band").show();//显示绑定信息
  281. bindnum+=1;
  282. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  283. $(".monther").removeClass("active");
  284. showTitle = '该快捷键已经被'+data['name']+'绑定,若要绑定该快捷键,需'+data['name']+'先解绑设备';
  285. }
  286. }
  287. }
  288. }
  289. if(bindnum==2){
  290. dialog({
  291. content: "该设备所有快捷键已被绑定,解绑快捷键后,方可再次绑定!",
  292. cancelValue: '我知道了',
  293. cancel: function () {
  294. return;
  295. }
  296. }).showModal();
  297. return false;
  298. }
  299. else if(bindnum==1&&showTitle!=""){//被绑定的按键选项
  300. dialog({
  301. content: showTitle,
  302. cancelValue: '我知道了',
  303. cancel: function () {
  304. return;
  305. }
  306. }).showModal();
  307. return false;
  308. }
  309. if(fatherData!=null){
  310. var others = fatherData['others'];//others==1为被别人绑定
  311. if(others!=1){//被别人绑定了
  312. //被自己绑定
  313. if(dataId == null){
  314. //新增的时候输入被自己绑定的SN码
  315. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  316. $(".monther").attr("data-click","-1");
  317. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  318. $(".father").removeClass("active");
  319. }
  320. dialog({
  321. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  322. cancelValue: '我知道了',
  323. cancel: function () {
  324. return;
  325. }
  326. }).showModal();
  327. return false;//直接退出不保存
  328. }else{
  329. if(!suc){//界面初始化的时候没有校验成功回调
  330. userType = 1;
  331. //选中爸爸键
  332. $(".father").addClass("active");
  333. }else if(oldSn!=snCode){
  334. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  335. $(".monther").attr("data-click","-1");
  336. if($(".father").hasClass("active")){//用户已经选择了爸爸建,就重置
  337. $(".father").removeClass("active");
  338. }
  339. dialog({
  340. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  341. cancelValue: '我知道了',
  342. cancel: function () {
  343. return;
  344. }
  345. }).showModal();
  346. return false;//直接退出不保存
  347. }
  348. }
  349. }
  350. }
  351. if(montherData!=null){
  352. var others = montherData['others'];//others==1为被别人绑定
  353. if(others!=1){
  354. //被自己绑定
  355. if(dataId == null){
  356. //新增的时候输入被自己绑定的SN码
  357. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  358. $(".monther").attr("data-click","-1");
  359. //$(".monther").addClass("active");//自己绑定了的键设置高亮
  360. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  361. $(".monther").removeClass("active");
  362. }
  363. dialog({
  364. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  365. cancelValue: '我知道了',
  366. cancel: function () {
  367. return;
  368. }
  369. }).showModal();
  370. return false;//直接退出不保存
  371. }else{
  372. if(!suc){
  373. userType = 2;
  374. //选中妈妈键
  375. $(".monther").addClass("active");
  376. }else if(oldSn!=snCode){
  377. $(".father").attr("data-click","-1");//设置爸爸妈妈键不能点击
  378. $(".monther").attr("data-click","-1");
  379. //$(".monther").addClass("active");//自己绑定了的键设置高亮
  380. if($(".monther").hasClass("active")){//用户已经选择了爸爸建,就重置
  381. $(".monther").removeClass("active");
  382. }
  383. dialog({
  384. content: "对不起,您已绑定过该设备,解绑后方可继续绑定!",
  385. cancelValue: '我知道了',
  386. cancel: function () {
  387. return;
  388. }
  389. }).showModal();
  390. return false;//直接退出不保存
  391. }
  392. }
  393. }
  394. }
  395. if(suc){
  396. if (dataId) {
  397. editSN(snCode);
  398. } else {
  399. suc(snCode);
  400. }
  401. }
  402. }else{
  403. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备SN校验失败!'}).show();
  404. }
  405. }
  406. })
  407. }
  408. function checkSuccess(snCode){
  409. if(userType==0){
  410. d.close();
  411. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请选择要绑定的快捷键'}).show();
  412. return false;
  413. }
  414. var sim = $("#simcode").val();
  415. if(deviceId == 6 && !sim){
  416. d.close();
  417. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请输入SIM码'}).show();
  418. return false;
  419. }
  420. var name1="血压计-"+name;
  421. var params ={};
  422. params.deviceId=deviceId;//设备ID
  423. params.deviceName=name1;//设备名称
  424. params.deviceSn=snCode;//设备SN码
  425. params.categoryCode=type;//设备分类 血糖仪1 血压计 2
  426. params.userType=userType;//是否多用户,1.爸爸建,2.妈妈键
  427. if(rowData.id){
  428. params.id = rowData.id;
  429. }
  430. if(deviceId == 6){
  431. params.sim = sim;
  432. }
  433. sendPost("/patient/device/SavePatientDevice",{"json":JSON.stringify(params)},"JSON","post",
  434. function(res){
  435. d.close();
  436. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'请求失败'}).show();
  437. },
  438. function(res){
  439. d.close();
  440. if(res.status == '200'){
  441. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'设备绑定成功'}).show();
  442. setTimeout(function(){
  443. if(prescriptionCode){
  444. window.history.go(-3)
  445. }else{
  446. window.location.href='my-equipments.html';
  447. }
  448. },500);
  449. }else{
  450. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"设备绑定失败"}).show();
  451. }
  452. }
  453. )
  454. }
  455. function editSN (snCode) {
  456. var o = {};
  457. o.deviceSN = oldSn;
  458. o.newDeviceSN = snCode;
  459. if(deviceId == 6){
  460. o.sim = $("#simcode").val();
  461. }
  462. o.categoryCode = categoryCode;
  463. o.userType=userType;
  464. sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
  465. d.close();
  466. if(res.status == 200) {
  467. setTimeout(function(){
  468. if(prescriptionCode){
  469. window.history.go(-3);
  470. }else{
  471. window.location.href='my-equipments.html';
  472. }
  473. },500);
  474. } else {
  475. dialog({
  476. contentType: 'tipsbox',
  477. bottom: true,
  478. skin: 'bk-popup',
  479. content: res.msg
  480. }).show();
  481. }
  482. });
  483. }
  484. function weixinSign(){
  485. //从后台那边获取签名等信息
  486. var params = {};
  487. var url1 = window.location.href;
  488. params.pageUrl = url1;
  489. $.ajax(server + "weixin/getSign", {
  490. data: params,
  491. dataType: "json",
  492. type: "post",
  493. success: function(res){
  494. if (res.status == 200) {
  495. var t = res.data.timestamp;
  496. var noncestr = res.data.noncestr;
  497. var signature = res.data.signature;
  498. wx.config({
  499. appId: appId, // 必填,公众号的唯一标识
  500. timestamp: t, // 必填,生成签名的时间戳
  501. nonceStr: noncestr, // 必填,生成签名的随机串
  502. signature: signature,// 必填,签名,见附录1
  503. jsApiList: [
  504. 'chooseImage',
  505. 'uploadImage',
  506. 'scanQRCode'
  507. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  508. });
  509. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  510. wx.ready(function(){
  511. wx.getNetworkType({
  512. success: function (res) {
  513. networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
  514. }
  515. });
  516. });
  517. }
  518. }
  519. });
  520. }