health-record-new.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. var d = dialog({contentType:'load', skin:'bk-popup'}).show();
  2. var dd = dialog({contentType:'load', skin:'bk-popup'});
  3. var pagetype = 5;
  4. var Request = GetRequest();
  5. var openid = Request["openid"];
  6. var $tizhengList = $('#tizhengList'),
  7. $baojianList = $('#baojianList');
  8. var id = 0;
  9. var pagesize = 15;
  10. var scroller1 = null;
  11. var xuetangRecord = null,
  12. xuyaRecord = null,
  13. tizhongRecord = null,
  14. yaoweiRecord = null,
  15. yundongRecord = null,
  16. yongyaoRecord = null,
  17. yinshiRecord = null,
  18. tzSta = false,
  19. xtdt = '',
  20. xydt = '',
  21. tzdt = '',
  22. ywdt = '',
  23. yddt = '',
  24. yydt = '',
  25. ysdt = '';
  26. var tagType = Request["tagType"]?Request["tagType"]:0;
  27. var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前'];
  28. $(function() {
  29. checkUserAgent();
  30. scroller1= new IScrollPullUpDown('wrapper2',{
  31. probeType:2,
  32. bounceTime: 250,
  33. bounceEasing: 'quadratic',
  34. mouseWheel:true,
  35. scrollbars:true,
  36. click:true,
  37. fadeScrollbars:true,
  38. interactiveScrollbars:false
  39. },pullDownAction,pullUpAction);
  40. EbindEvents();
  41. //下拉刷新
  42. function pullDownAction(theScrollerTemp) {
  43. // $(".pullUp").show();
  44. // setTimeout(function () {
  45. // $(".c-list").html("");
  46. // id=0;
  47. // getEquipments();
  48. // }, 1000);
  49. }
  50. //上拉加载数据
  51. function pullUpAction(theScrollerTemp) {
  52. $(".pullUp").show();
  53. setTimeout(function () {
  54. getEquipments();
  55. }, 1000);
  56. }
  57. if(tagType == 1){
  58. $('.j-tab-select li').eq(1).addClass('hit');
  59. $('.pt-tab-list').eq(1).addClass('hit');
  60. }else{
  61. $('.j-tab-select li').eq(0).addClass('hit');
  62. $('.pt-tab-list').eq(0).addClass('hit');
  63. }
  64. })
  65. //体征设备绑定事件
  66. function EbindEvents(){
  67. //绑定编辑和删除事件
  68. $(".c-list").on("click","li div",function(){
  69. var code = $(this.parentElement).attr("data-id");
  70. var deviceId = $(this.parentElement).attr("device-id");
  71. var type = $(this.parentElement).attr("data-type");
  72. if(type==1){
  73. location.href="../../wdsb/html/view-xuetangyi.html?deviceId="+deviceId+"&id="+code;
  74. }else if(type==2){
  75. location.href="../../wdsb/html/view-xueyaji.html?deviceId="+deviceId+"&id="+code;
  76. }
  77. })
  78. function deleteSn(code){
  79. sendPost("patient/device/DeletePatientDevice?id="+code,{},"JSON","DELETE",function(res){
  80. if (res && res.msg) {
  81. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  82. } else {
  83. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  84. }
  85. },function(res){
  86. if(res.status==200){
  87. $(".c-list").html("");
  88. id=0;
  89. getEquipments();
  90. }else{
  91. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'删除设备失败'}).show();
  92. }
  93. })
  94. }
  95. //点击血糖仪事件
  96. $(".xuetangyi-icon").on("click",function(){
  97. $(this).addClass("active");
  98. window.location.href = "../../wdsb/html/list-xuetangyi.html?category_code=1";
  99. });
  100. //点击血压计事件
  101. $(".xueyaji-icon").on("click",function(){
  102. $(this).addClass("active");
  103. window.location.href = "../../wdsb/html/list-xueyaji.html?category_code=2";
  104. });
  105. }
  106. function checkDate (v) {
  107. return (v < 10 ? '0' + v : v);
  108. }
  109. appendFamilyMember($('#memberContainer'),function(){
  110. $(".c-list").html("");
  111. $(".div-no-info").hide();
  112. $(".main").show();
  113. id=0;
  114. getEquipments();
  115. getRecentDataInit();
  116. },function(){
  117. //判断有授权家人,修改样式
  118. if($('#memberContainer').is(':hidden')){
  119. $('#wrapper').css('top','0px');
  120. }else{
  121. $('#wrapper').css('top','90px');
  122. }
  123. });
  124. //获取最新的体征记录
  125. function getRecentDataPromise() {
  126. return new Promise(function(resolve, reject) {
  127. sendPost("patient/health_index/last", {}, "json", "get", function() {
  128. d.close();
  129. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  130. }, function(res) {
  131. d.close();
  132. if(res.status == 200) {
  133. console.log(res);
  134. resolve(res)
  135. } else {
  136. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  137. }
  138. });
  139. })
  140. }
  141. //获取最新的体征设备
  142. function getEquipments(){
  143. var params = {};
  144. params.id=id;
  145. params.pagesize = pagesize;
  146. d.show();
  147. sendPost("patient/device/PatientDeviceList",params,"JSON","GET",queryListFailed,queryListSuccess);
  148. }
  149. //获取最新体征设备成功回调
  150. function queryListSuccess(res){
  151. d.close();
  152. if(res.status==200){
  153. if(res.data&&res.data.length>0){
  154. for(var i in res.data){
  155. showList(res.data[i]);
  156. }
  157. id = res.data[res.data.length-1].id;
  158. scroller1.myScroll.refresh();
  159. }else{
  160. if(id==0){
  161. $(".div-no-info").show();
  162. $(".main").hide();
  163. }
  164. }
  165. $(".pullUp").hide();
  166. }else{
  167. queryListFailed(res);
  168. }
  169. }
  170. //获取最新体征设备初始化数据
  171. function showList(rowData){
  172. var img='xuetangyi_icon.png';
  173. if(rowData.categoryCode==2){
  174. img='xueyaji_icon.png';
  175. }
  176. var bindUser ="自己绑定";
  177. if(rowData.doctor){
  178. bindUser = "医生绑定";
  179. }else if(rowData.agent){
  180. bindUser = "家人绑定";
  181. }
  182. var showDomLi = '<li class="inp" device-id="'+rowData.deviceId+'" data-type="'+rowData.categoryCode+'" data-id="'+rowData.id+'">'+
  183. '<div class="icon-div">'+
  184. '<img src="../images/'+img+'">'+
  185. '</div>'+
  186. '<div class="div-content">'+rowData.deviceName+'</div>'+
  187. '<div class="div-sn"><span class="bullspan">&bull; </span>绑定时间:'+rowData.czrq+'</div>'+
  188. '<div class="div-sn" style="top: 70px;color: #ff9526;"><span class="bullspan">&bull;</span> '+bindUser+'</div>'+
  189. '</li>';
  190. $("#shebeiList .Equipment").append(showDomLi);
  191. }
  192. //获取最新体征设备失败回调
  193. function queryListFailed(res) {
  194. d.close();
  195. if (res && res.msg) {
  196. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:res.msg}).show();
  197. } else {
  198. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:'加载设备列表失败'}).show();
  199. }
  200. }
  201. //获取最新保健记录
  202. function getBJRecentDataPromise () {
  203. return new Promise(function( resolve, reject){
  204. sendPost("patient/health_record/recent", {}, "json", "get", function() {
  205. dd.close();
  206. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  207. }, function(res) {
  208. dd.close();
  209. if(res.status == 200) {
  210. resolve(res)
  211. } else {
  212. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  213. }
  214. });
  215. });
  216. }
  217. function getLevelClazz(value,max,min) {
  218. if(!value||(!max && !min)) {
  219. return '';
  220. }
  221. var value = parseFloat(value);
  222. if(value < min) {
  223. return 'low';
  224. } else if(value > max) {
  225. return 'high';
  226. } else {
  227. return ''
  228. }
  229. }
  230. function bindEvents() {
  231. //标签切换
  232. $(".pt-tab li").click(function(){
  233. var id = $(this).attr("id");
  234. $(".pt-tab li").removeClass("hit");
  235. $(this).addClass("hit");
  236. if(id=="tizhengLi"){
  237. $("#tizhengList").show();
  238. $("#baojianList").hide();
  239. $("#shebeiList").hide();
  240. }if(id=="shebeiLi"){
  241. $("#shebeiList").show();
  242. $("#tizhengList").hide();
  243. $("#baojianList").hide();
  244. }if(id=="healthLi"){
  245. $("#baojianList").show();
  246. $("#shebeiList").hide();
  247. $("#tizhengList").hide();
  248. }
  249. });
  250. $('#tizhengList').on('click','li',function() {
  251. var index = $(this).index();
  252. var dat = new Date(),
  253. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  254. if(index == 0) {
  255. window.location.href = 'xuetang-view.html?dateT=' + (xtdt || nowD);
  256. }
  257. if(index == 1) {
  258. window.location.href = 'xueya-view.html?dateT=' + (xydt || nowD);
  259. }
  260. if(index == 2) {
  261. window.location.href = 'tizhong-view.html?dateT=' + (nowD);
  262. }
  263. if(index == 3) {
  264. window.location.href = 'yaowei-view.html?dateT=' + (ywdt || nowD);
  265. }
  266. })
  267. $('#baojianList').on('click','li',function() {
  268. var index = $(this).index();
  269. var dat = new Date(),
  270. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  271. if(index == 0) {
  272. window.location.href = 'yundong-view.html?dateT=' + (yddt || nowD);
  273. }
  274. if(index == 1) {
  275. window.location.href = 'yongyao-view.html?dateT=' + (yydt || nowD);
  276. }
  277. if(index == 2) {
  278. window.location.href = 'yinshi-view.html?dateT=' + (ysdt || nowD);
  279. }
  280. })
  281. //点击新增事件
  282. $(".div-add-btn").click(function(){
  283. $(".modal-overlay").css("background","transparent");
  284. $("#footer").css("z-index",4).hide();
  285. var activeItem = $(".pt-tab li.hit").attr("id");
  286. console.log(activeItem);
  287. if(activeItem=="tizhengLi"){
  288. if($(this).hasClass("active")){
  289. $(".div-dialog-content.div-tizhengtezheng").hide();
  290. }else{
  291. $(".div-dialog-content.div-tizhengtezheng").show();
  292. }
  293. }else if(activeItem=="shebeiLi"){
  294. if($(this).hasClass("active")){
  295. $(".div-dialog-content.div-tizhengshebei").hide();
  296. }else{
  297. $(".div-dialog-content.div-tizhengshebei").show();
  298. }
  299. }else{
  300. if($(this).hasClass("active")){
  301. $(".div-dialog-content.div-baojianjilu").hide();
  302. }else{
  303. $(".div-dialog-content.div-baojianjilu").show();
  304. }
  305. }
  306. if($(this).hasClass("active")){
  307. $(".modal-overlay").removeClass("modal-overlay-visible");
  308. $(this).removeClass("active");
  309. }else{
  310. $(this).addClass("active");
  311. $(".modal-overlay").addClass("modal-overlay-visible");
  312. }
  313. });
  314. //点击遮罩事件
  315. $(".modal-overlay").on("click",function(){
  316. $(".div-add-btn").removeClass("active");
  317. $(".div-dialog-content").hide();
  318. $(".modal-overlay").removeClass("modal-overlay-visible");
  319. $("#footer").show();
  320. });
  321. //取消
  322. $(".quxiao").on("click",function(){
  323. $(".div-add-btn").removeClass("active");
  324. $(".div-dialog-content").hide();
  325. $(".modal-overlay").removeClass("modal-overlay-visible");
  326. $("#footer").show();
  327. });
  328. //新增血糖
  329. $(".addxuetang").on("click",function(){
  330. $(this).addClass("active");
  331. window.open('health-index-add-bloodsugar.html');
  332. });
  333. //新增血压
  334. $(".addxueya").on("click",function(){
  335. $(this).addClass("active");
  336. window.open('health-index-add-bloodpressure.html');
  337. });
  338. //新增体重
  339. $(".addtizhong").on("click",function(){
  340. $(this).addClass("active");
  341. var dat = new Date(),
  342. nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate();
  343. window.open('health-index-add-weight.html?dateT='+nowD);
  344. });
  345. //新增腰围
  346. $(".addyaowei").on("click",function(){
  347. $(this).addClass("active");
  348. window.open('health-index-add-waistline.html');
  349. });
  350. //新增设备管理
  351. $(".addshebei").on("click",function(){
  352. $(this).addClass("active");
  353. window.open('../../wdsb/html/my-equipments.html');
  354. });
  355. //新增运动
  356. $(".addyundong").on("click",function(){
  357. $(this).addClass("active");
  358. window.open('add-sport-record.html');
  359. });
  360. //新增用药
  361. $(".addyongyao").on("click",function(){
  362. $(this).addClass("active");
  363. window.open('add-drug-record.html');
  364. });
  365. //新增饮食
  366. $(".addyinshi").on("click",function(){
  367. $(this).addClass("active");
  368. // 修复bug#2724
  369. window.location.href = 'add-diet-record.html';
  370. });
  371. }
  372. function pushHistory() {
  373. var state = {
  374. title: "title",
  375. url: "#"
  376. };
  377. setTimeout(function (){
  378. window.history.pushState(state, "title", "#");
  379. },1000);
  380. }
  381. pushHistory();
  382. setTimeout( function () {
  383. window.addEventListener("popstate", function(e) {
  384. WeixinJSBridge.call('closeWindow');
  385. }, false);
  386. }, 300);
  387. function getRecordType(isDevice) {
  388. return isDevice === null ? "手动记录" : isDevice != null ? "设备上传" : '';
  389. // return isDevice == "0"?"手动记录":(isDevice=="1"?"设备上传":"");
  390. }
  391. function getBJRecordType(isDevice) {
  392. return isDevice === 0 ? "手动记录" : isDevice == 1 ? "设备上传" : '';
  393. }
  394. var html = template('tizheng_list_temp',{
  395. xuetang:{},
  396. xueya:{},
  397. tizhong:{},
  398. yaowei:{}
  399. });
  400. $tizhengList.html(html);
  401. function getRecentDataInit(){
  402. //体征记录
  403. getRecentDataPromise()
  404. .then(function(res) {
  405. xuetangRecord = _.find(res.data,function(o) {
  406. var d = new Date(o.recordDate.replace(/\-/g, "/"));
  407. o.recordDate = d.getFullYear() + '-' + checkDate(d.getMonth() + 1) + '-' + checkDate(d.getDate());
  408. return o.type =="1";
  409. }) || {};
  410. xuyaRecord = _.find(res.data,function(o) {
  411. return o.type =="2";
  412. }) || {};
  413. tizhongRecord = _.find(res.data,function(o) {
  414. return o.type =="3";
  415. }) || {};
  416. yaoweiRecord = _.find(res.data,function(o) {
  417. return o.type =="4";
  418. }) || {};
  419. var xuetangValue = "";
  420. var xuetangValueIndex;
  421. var during = _.find(xuetangDuring,function(v,i){
  422. xuetangValue = xuetangRecord['value'+[i]];
  423. xuetangValueIndex = i;
  424. return i>0&&xuetangValue;
  425. });
  426. xtdt = xuetangRecord.recordDate;
  427. xydt = xuyaRecord.recordDate;
  428. tzdt = tizhongRecord.recordDate;
  429. ywdt = yaoweiRecord.recordDate;
  430. var duringIndex = xuetangRecord.value2 ? xuetangRecord.value2 : 0;
  431. return {
  432. //血糖中,value1返回最新的值,value2表示当前值对应的时间段的值(1-7)
  433. xuetang: $.extend({},xuetangRecord,{
  434. during: duringIndex ? xuetangDuring[duringIndex] : '',
  435. value: xuetangValue,
  436. levelClazz: (function() {
  437. // 不同时间段对应不同的血糖范围
  438. // var levels = [[],[7.0, 3.9],[11.1, 4.0],
  439. // [7.0, 3.9],[11.1, 4.4],
  440. // [7.0, 3.9],[11.1, 4.4],
  441. // [7.0, 3.9]][xuetangValueIndex];
  442. var levels = [[],[7.0, 3.9],[11.1, 4.0],
  443. [7.0, 3.9],[11.1, 4.0],
  444. [7.0, 3.9],[11.1, 4.0],
  445. [7.0, 3.9]][duringIndex]
  446. return getLevelClazz(xuetangValue, levels[0],levels[1])
  447. })(),
  448. recordType: getRecordType(xuetangRecord.deviceSn)
  449. }),
  450. xueya: $.extend({},xuyaRecord,{
  451. levelClazz: getLevelClazz(xuyaRecord.value1, 139, 90)||getLevelClazz(xuyaRecord.value2, 89, 60),
  452. recordType: getRecordType(xuyaRecord.deviceSn)
  453. }),
  454. tizhong: $.extend({},tizhongRecord,{
  455. recordType: getRecordType(tizhongRecord.deviceSn)
  456. }),
  457. yaowei: $.extend({},yaoweiRecord,{
  458. recordType: getRecordType(yaoweiRecord.deviceSn)
  459. })
  460. }
  461. })
  462. .then(function(data) {
  463. var html = template('tizheng_list_temp',data);
  464. $tizhengList.html(html)
  465. })
  466. .catch(function(e) {
  467. d.close();
  468. console && console.error(e)
  469. });
  470. //保健记录
  471. getBJRecentDataPromise()
  472. .then(function (res) {
  473. yundongRecord = res.data.sprot;
  474. yongyaoRecord = res.data.medication;
  475. yinshiRecord = res.data.diet;
  476. yddt = yundongRecord.recordDate;
  477. yydt = yongyaoRecord.recordDate;
  478. ysdt = yinshiRecord.recordDate;
  479. return {
  480. yundong: (function () {
  481. yundongRecord.recordType = getBJRecordType(yundongRecord.source);
  482. return yundongRecord;
  483. })(),
  484. yongyao: (function () {
  485. yongyaoRecord.recordType = getBJRecordType(yongyaoRecord.source);
  486. return yongyaoRecord;
  487. })() ,
  488. yinshi: (function () {
  489. yinshiRecord.recordType = getBJRecordType(yinshiRecord.source);
  490. return yinshiRecord;
  491. })()
  492. };
  493. }).then(function (data) {
  494. var html = template('baojian_list_tmp',data);
  495. $baojianList.html(html)
  496. });
  497. }
  498. getRecentDataInit();
  499. getEquipments();
  500. bindEvents();