edit-xuetangyi-new.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. var rowData = {};
  2. var sn = ""; //记录sn码
  3. var dataId = null;
  4. var type = null;
  5. var name = null;
  6. var type = null;
  7. var photoUrl = null;
  8. var deviceId = null;
  9. var oldSn = ""; //旧sn
  10. var sncode = '';
  11. var categoryCode = '';
  12. var prescriptionCode;
  13. var $szTime = $('.sz-time');
  14. var d = dialog({
  15. contentType: 'load',
  16. skin: 'bk-popup'
  17. }),
  18. tips = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖'];
  19. $(function() {
  20. Request = GetRequest();
  21. dataId = Request["id"];
  22. deviceId = Request["deviceId"];
  23. prescriptionCode = Request["prescriptionCode"];
  24. categoryCode = Request["categoryCode"];
  25. $('#member').val(window.localStorage.getItem('nowPatientName'));
  26. getDeviceInfo(deviceId);
  27. bindEvents();
  28. if(dataId) {
  29. $(document).attr("title", "编辑血糖仪");
  30. initData(dataId);
  31. $('.xt-time-list').show();
  32. $("#bang-btn").html("保存");
  33. } else {
  34. $(document).attr("title", "新增血糖仪");
  35. }
  36. if(deviceId == 5){
  37. //三诺亲智的设备,建议扫描设备背面的条形码获取SN码。(因为厂家提供的二维码不好扫)
  38. $("#device5Msg").show();
  39. }else{
  40. $("#device5Msg").hide();
  41. }
  42. $("#bang-btn").addClass("active");
  43. weixinSign();
  44. });
  45. function initData(dataId) {
  46. var params = {};
  47. params.id = dataId;
  48. sendPost("patient/device/PatientDeviceInfo", params, "JSON", "GET",
  49. function(res) {
  50. if(res.msg) {
  51. dialog({
  52. contentType: 'tipsbox',
  53. skin: 'bk-popup',
  54. content: res.msg
  55. }).show();
  56. } else {
  57. dialog({
  58. contentType: 'tipsbox',
  59. skin: 'bk-popup',
  60. bottom: true,
  61. content: '设备信息初始化失败!'
  62. }).show();
  63. }
  64. },
  65. function(res) {
  66. if(res.status == 200) {
  67. rowData = res.data;
  68. oldSn = rowData.device.deviceSn;
  69. $("#sncode").val(rowData.device.deviceSn);
  70. sncode = rowData.device.deviceSn;
  71. var fasting = (rowData.time['fasting'].replace(/ /g, '')).split('-'),
  72. afterBreakFast = (rowData.time['afterBreakFast'].replace(/ /g, '')).split('-'),
  73. beforeLunch = (rowData.time['beforeLunch'].replace(/ /g, '')).split('-'),
  74. afterLunch = (rowData.time['afterLunch'].replace(/ /g, '')).split('-'),
  75. beforeDinner = (rowData.time['beforeDinner'].replace(/ /g, '')).split('-'),
  76. afterDinner = (rowData.time['afterDinner'].replace(/ /g, '')).split('-'),
  77. beforeSleep = (rowData.time['beforeSleep'].replace(/ /g, '')).split('-');
  78. var list = [{
  79. name: '早餐前血糖',
  80. value1: fasting[0].substring(0,5),
  81. value2: fasting[1].substring(0,5)
  82. },{
  83. name: '早餐后血糖',
  84. value1: afterBreakFast[0].substring(0,5),
  85. value2: afterBreakFast[1].substring(0,5)
  86. },{
  87. name: '午餐前血糖',
  88. value1: beforeLunch[0].substring(0,5),
  89. value2: beforeLunch[1].substring(0,5)
  90. },{
  91. name: '午餐后血糖',
  92. value1: afterLunch[0].substring(0,5),
  93. value2: afterLunch[1].substring(0,5)
  94. },{
  95. name: '晚餐前血糖',
  96. value1: beforeDinner[0].substring(0,5),
  97. value2: beforeDinner[1].substring(0,5)
  98. },{
  99. name: '晚餐后血糖',
  100. value1: afterDinner[0].substring(0,5),
  101. value2: afterDinner[1].substring(0,5)
  102. },{
  103. name: '睡前血糖',
  104. value1: beforeSleep[0].substring(0,5),
  105. value2: beforeSleep[1].substring(0,5)
  106. }];
  107. var html = template('time-tmp', {list: list});
  108. $(".time-list").empty().append(html);
  109. } else {
  110. dialog({
  111. contentType: 'tipsbox',
  112. skin: 'bk-popup',
  113. bottom: true,
  114. content: '设备信息初始化失败!'
  115. }).show();
  116. }
  117. }
  118. )
  119. }
  120. //判断值是否改变过
  121. function isValueChange() {
  122. var changeTagStr = $("#sncode").val();
  123. if(oldSn != changeTagStr) {
  124. }
  125. }
  126. //绑定事件
  127. function bindEvents() {
  128. $('#sncode').on('click', function() {
  129. $(this).focus();
  130. });
  131. //保存方法
  132. $("#bang-btn").bind("click", function() {
  133. if($(this).hasClass("active")) {
  134. var snCode = $("#sncode").val();
  135. if(snCode == null || snCode == "") {
  136. dialog({
  137. contentType: 'tipsbox',
  138. skin: 'bk-popup',
  139. bottom: true,
  140. content: '请输入设备的SN码进行绑定!'
  141. }).show();
  142. } else {
  143. if(!dataId) {
  144. $("#bang-btn").html("正在绑定").css("pointer-events", "none");
  145. }
  146. d.show();
  147. checkSnBind(snCode, checkSuccess);
  148. }
  149. }
  150. })
  151. $(".scanText").on('click', function(){
  152. wx.scanQRCode({
  153. desc: 'scanQRCode desc',
  154. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  155. scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  156. success: function (res) {
  157. // 回调
  158. var code = res.resultStr,
  159. arr = code.split(",");//因为微信扫描条形码的时候,会带上这个码的类型,所以取数组后的码显示
  160. if(arr.length > 1){
  161. $("#sncode").val(arr[1]);
  162. }else{
  163. $("#sncode").val(arr[0]);
  164. }
  165. },
  166. error: function(res){
  167. if(res.errMsg.indexOf('function_not_exist') > 0){
  168. alert('版本过低请升级')
  169. }
  170. }
  171. });
  172. });
  173. //绑定时间控件弹出
  174. $(".time-list").on('click', '.change-date', function(){
  175. var $this = $(this),
  176. $parent = $this.closest(".time-item"),
  177. $next = $parent.next();
  178. var picker = new mui.DtPicker({type: 'time'});
  179. picker.show(function(rs) {
  180. /*
  181. * rs.value 拼合后的 value
  182. * rs.text 拼合后的 text
  183. * rs.y 年,可以通过 rs.y.vaue 和 rs.y.text 获取值和文本
  184. * rs.m 月,用法同年
  185. * rs.d 日,用法同年
  186. * rs.h 时,用法同年
  187. * rs.i 分(minutes 的第二个字母),用法同年
  188. */
  189. $this.val(rs.text);
  190. if($next && !$this.hasClass("first")){
  191. var h = rs.h.text,
  192. i = rs.i.text;
  193. if(parseInt(i)+1 == 60){
  194. i = 0;
  195. h = parseInt(h) + 1;
  196. if(parseInt(h) < 10){
  197. h = '0' + h;
  198. }
  199. }else{
  200. i = parseInt(i)+1;
  201. }
  202. if(i < 10){
  203. i = '0'+ i;
  204. }
  205. $next.find(".sz-time").eq(0).val(h+":"+i);
  206. }
  207. // picker.dispose();
  208. });
  209. })
  210. }
  211. function checkSnBind(snCode, checkSuccess) {
  212. if (dataId && snCode == oldSn) {
  213. addData(snCode);
  214. } else {
  215. var b = /^[0-9a-zA-Z]*$/g;
  216. if(!b.test(snCode)) {
  217. setTimeout(function() {
  218. $("#bang-btn").html("立即绑定").css("pointer-events", "");
  219. }, 3000);
  220. d.close();
  221. dialog({
  222. contentType: 'tipsbox',
  223. skin: 'bk-popup',
  224. bottom: true,
  225. content: '对不起,您输入的SN有误,请重新输入!'
  226. }).show();
  227. return false;
  228. }
  229. var params = {};
  230. params.type = type;
  231. params.device_sn = snCode;
  232. $.ajax(server + "patient/device/PatientDeviceIdcard", {
  233. data: params,
  234. dataType: "JSON",
  235. async: false,
  236. type: "get",
  237. timeout: 10000,
  238. beforeSend: function(request) {
  239. var userAgent = window.localStorage.getItem(agentName);
  240. request.setRequestHeader("userAgent", userAgent);
  241. },
  242. error: function(res) {
  243. dialog({
  244. contentType: 'tipsbox',
  245. skin: 'bk-popup',
  246. bottom: true,
  247. content: '设备SN校验失败!'
  248. }).show();
  249. setTimeout(function() {
  250. $("#bang-btn").html("立即绑定").css("pointer-events", "");
  251. d.close();
  252. }, 3000);
  253. },
  254. success: function(res) {
  255. setTimeout(function() {
  256. $("#bang-btn").html("立即绑定").css("pointer-events", "");
  257. d.close();
  258. }, 3000);
  259. if(res.status == 200) {
  260. var name = "";
  261. var others = null;
  262. for(var j in res.data) {
  263. name = res.data[j].name;
  264. others = res.data[j].others
  265. }
  266. //没被绑定
  267. if(name == "") {
  268. $("#bang-btn").addClass("active");
  269. if(dataId){
  270. editSN(snCode);
  271. } else {
  272. if(checkSuccess != null) {
  273. checkSuccess(snCode);
  274. }
  275. }
  276. } else if(others != null && others == 1) {
  277. // $("#bang-btn").removeClass("active");
  278. //被绑定而且被别人绑定
  279. dialog({
  280. contentType: 'tipsbox',
  281. skin: 'bk-popup',
  282. bottom: true,
  283. content: '该设备已被他人绑定,设备解绑后,方可再次绑定!'
  284. }).show();
  285. } else if(others != null && others == 0) {
  286. // $("#bang-btn").removeClass("active");
  287. if(deviceId == null || !deviceId || deviceId == "") {
  288. //新增,编辑/被自己绑定
  289. dialog({
  290. contentType: 'tipsbox',
  291. skin: 'bk-popup',
  292. bottom: true,
  293. content: '对不起,您已绑定过该设备,解绑后方可继续绑定!'
  294. }).show();
  295. } else {
  296. if(dataId){
  297. editSN(snCode);
  298. } else {
  299. if(checkSuccess != null) {
  300. checkSuccess(snCode);
  301. }
  302. }
  303. }
  304. }
  305. } else {
  306. dialog({
  307. contentType: 'tipsbox',
  308. skin: 'bk-popup',
  309. bottom: true,
  310. content: '该设备已被他人绑定,设备解绑后,方可再次绑定!'
  311. }).show();
  312. }
  313. }
  314. });
  315. }
  316. }
  317. function getDeviceInfo(deviceId) {
  318. sendPost("/common/device/DeviceInfo?id=" + deviceId, {}, "JSON", "GET",
  319. function(res) {
  320. dialog({
  321. contentType: 'tipsbox',
  322. skin: 'bk-popup',
  323. bottom: true,
  324. content: '设备信息获取失败!'
  325. }).show();
  326. },
  327. function(res) {
  328. if(res.status == 200) {
  329. var rowData1 = res.data;
  330. type = rowData1.categoryCode;
  331. name = rowData1.name;
  332. photoUrl = getImgUrl(rowData1.photo);
  333. $(".deviceName").html(name);
  334. $(".div-xuetangyi-img img").attr("src", photoUrl);
  335. } else {
  336. dialog({
  337. contentType: 'tipsbox',
  338. skin: 'bk-popup',
  339. bottom: true,
  340. content: '设备信息获取失败!'
  341. }).show();
  342. }
  343. }
  344. )
  345. }
  346. function checkSuccess(snCode) {
  347. var name1 = "血糖仪-" + name;
  348. var params = {};
  349. params.deviceId = deviceId; //设备ID
  350. params.deviceName = name1; //设备名称
  351. params.deviceSn = snCode; //设备SN码
  352. params.categoryCode = type; //设备分类 血糖仪1 血压计 2
  353. params.userType = "-1"; //是否多用户
  354. if(rowData.id) {
  355. params.id = rowData.id;
  356. }
  357. sendPost("/patient/device/SavePatientDevice", {
  358. "json": JSON.stringify(params)
  359. }, "JSON", "post",
  360. function(res) {
  361. dialog({
  362. contentType: 'tipsbox',
  363. skin: 'bk-popup',
  364. bottom: true,
  365. content: '设备绑定失败!'
  366. }).show();
  367. },
  368. function(res) {
  369. if(res.status == 200) {
  370. dialog({
  371. contentType: 'tipsbox',
  372. skin: 'bk-popup',
  373. bottom: true,
  374. content: '设备绑定成功!'
  375. }).show();
  376. setTimeout(function() {
  377. window.location.href = 'view-shezhishijianduan.html?type=1&sncode=' + $('#sncode').val()+'&categoryCode='+type;
  378. }, 500);
  379. } else {
  380. dialog({
  381. contentType: 'tipsbox',
  382. skin: 'bk-popup',
  383. bottom: true,
  384. content: res.msg
  385. }).show();
  386. return false;
  387. }
  388. }
  389. )
  390. }
  391. function checkDate(v1, v2, index) {
  392. if(v1 == '' || v2 == '') {
  393. var content = "请选择"+tips[index]+"检测时间";
  394. dialog({
  395. contentType: 'tipsbox',
  396. skin: 'bk-popup',
  397. bottom: true,
  398. content: content
  399. }).show();
  400. d.close();
  401. return false;
  402. }else{
  403. var v1 = v1.split(":"),
  404. v2 = v2.split(":"),
  405. v1_h = v1[0],
  406. v1_m = v1[1],
  407. v2_h = v2[0],
  408. v2_m = v2[1];
  409. if(v1_h == v2_h){
  410. if(v1_m > v2_m){
  411. var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
  412. dialog({
  413. contentType: 'tipsbox',
  414. skin: 'bk-popup',
  415. bottom: true,
  416. content: content
  417. }).show();
  418. d.close();
  419. return false;
  420. }
  421. }else if(v1_h > v2_h){
  422. var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
  423. dialog({
  424. contentType: 'tipsbox',
  425. skin: 'bk-popup',
  426. bottom: true,
  427. content: content
  428. }).show();
  429. d.close();
  430. return false;
  431. }
  432. }
  433. return true;
  434. }
  435. function editSN (snCode) {
  436. var o = {};
  437. o.deviceSN = oldSn;
  438. o.newDeviceSN = snCode;
  439. o.categoryCode = categoryCode;
  440. o.userType = "-1"; //是否多用户
  441. sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
  442. d.close();
  443. if(res.status == 200) {
  444. addData(snCode);
  445. } else {
  446. dialog({
  447. contentType: 'tipsbox',
  448. bottom: true,
  449. skin: 'bk-popup',
  450. content: res.msg
  451. }).show();
  452. }
  453. });
  454. }
  455. //添加数据
  456. function addData(snCode) {
  457. d.show();
  458. var o = {},
  459. isTrue = true,
  460. isGo = true;
  461. o.deviceSN = snCode;
  462. o.userType = "-1"; //是否多用户
  463. o.categoryCode = categoryCode;
  464. $.each($(".time-item"), function(index) {
  465. var value1 = $(this).find(".sz-time:eq(0)").val(),
  466. value2 = $(this).find(".sz-time:eq(1)").val();
  467. if(isTrue) {
  468. isTrue = checkDate(value1, value2, index);
  469. isGo = checkDate(value1, value2, index);
  470. switch(index) {
  471. case 0:
  472. o.fastingStart = value1 + ':00';
  473. o.fastingEnd = value2 + ':59';
  474. break;
  475. case 1:
  476. o.afterBreakfastStart = value1 + ':00';
  477. o.afterBreakfastEnd = value2 + ':59';
  478. break;
  479. case 2:
  480. o.beforeLunchStart = value1 + ':00';
  481. o.beforeLunchEnd = value2 + ':59';
  482. break;
  483. case 3:
  484. o.afterLunchStart = value1 + ':00';
  485. o.afterLunchEnd = value2 + ':59';
  486. break;
  487. case 4:
  488. o.beforeDinnerStart = value1 + ':00';
  489. o.beforeDinnerEnd = value2 + ':59';
  490. break;
  491. case 5:
  492. o.afterDinnerStart = value1 + ':00';
  493. o.afterDinnerEnd = value2 + ':59';
  494. break;
  495. case 6:
  496. o.beforeSleepStart = value1 + ':00';
  497. o.beforeSleepEnd = value2 + ':59';
  498. break;
  499. }
  500. }
  501. });
  502. if(isGo) {
  503. sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
  504. d.close();
  505. if(res.status == 200) {
  506. dialog({
  507. contentType: 'tipsbox',
  508. bottom: true,
  509. skin: 'bk-popup',
  510. content: res.msg
  511. }).show();
  512. setTimeout(function() {
  513. if(prescriptionCode){
  514. window.history.go(-3);
  515. }else{
  516. window.location.href='my-equipments.html';
  517. }
  518. }, 500);
  519. } else {
  520. dialog({
  521. contentType: 'tipsbox',
  522. bottom: true,
  523. skin: 'bk-popup',
  524. content: '保存失败'
  525. }).show();
  526. }
  527. });
  528. }
  529. }
  530. function weixinSign(){
  531. //从后台那边获取签名等信息
  532. var params = {};
  533. var url1 = window.location.href;
  534. params.pageUrl = url1;
  535. $.ajax(server + "weixin/getSign", {
  536. data: params,
  537. dataType: "json",
  538. type: "post",
  539. success: function(res){
  540. if (res.status == 200) {
  541. var t = res.data.timestamp;
  542. var noncestr = res.data.noncestr;
  543. var signature = res.data.signature;
  544. wx.config({
  545. appId: appId, // 必填,公众号的唯一标识
  546. timestamp: t, // 必填,生成签名的时间戳
  547. nonceStr: noncestr, // 必填,生成签名的随机串
  548. signature: signature,// 必填,签名,见附录1
  549. jsApiList: [
  550. 'chooseImage',
  551. 'uploadImage',
  552. 'scanQRCode'
  553. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  554. });
  555. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  556. wx.ready(function(){
  557. wx.getNetworkType({
  558. success: function (res) {
  559. networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
  560. }
  561. });
  562. });
  563. }
  564. }
  565. });
  566. }