edit-xuetangyi-new.js 21 KB

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