edit-xueyaji.js 18 KB

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