view-shezhishijianduan.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. (function ( $, win) {
  2. $(function () {
  3. var d = dialog({contentType:'load', skin:'bk-popup'});
  4. var Request = GetRequest();
  5. var type = Request["type"],
  6. sncode = Request["sncode"],
  7. categoryCode = Request["categoryCode"],
  8. $yqName = $('.yq-name'),
  9. $szTime = $('.sz-time'),
  10. $ttSendBtn = $('.tt-send-btn'),
  11. tips = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖'];
  12. function checkDate( v, index) {
  13. if (v == '') {
  14. switch (index) {
  15. case 0:
  16. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  17. break;
  18. case 1:
  19. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  20. break;
  21. case 2:
  22. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  23. break;
  24. case 3:
  25. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  26. break;
  27. case 4:
  28. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  29. break;
  30. case 5:
  31. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  32. break;
  33. case 6:
  34. dialog({contentType:'tipsbox', skin:'bk-popup',bottom:true , content:tips[index]}).show();
  35. break;
  36. }
  37. d.close();
  38. return true;
  39. }
  40. return false;
  41. }
  42. //添加数据
  43. function addData () {
  44. d.show();
  45. var o = {},
  46. isTrue = false,
  47. isGo = false;
  48. o.deviceSN = sncode;
  49. o.categoryCode = categoryCode; //设备分类 血糖仪1 血压计 2
  50. o.userType = "-1"; //是否多用户
  51. $.each( $szTime, function (index) {
  52. var tArr = ($(this).val()).split('-');
  53. if (!isTrue) {
  54. isTrue = checkDate( $(this).val(), index);
  55. isGo = checkDate( $(this).val(), index);
  56. switch (index) {
  57. case 0:
  58. o.fastingStart = tArr[0] + ':00';
  59. o.fastingEnd = tArr[1] + ':59';
  60. break;
  61. case 1:
  62. o.afterBreakfastStart = tArr[0] + ':00';
  63. o.afterBreakfastEnd = tArr[1] + ':59';
  64. break;
  65. case 2:
  66. o.beforeLunchStart = tArr[0] + ':00';
  67. o.beforeLunchEnd = tArr[1] + ':59';
  68. break;
  69. case 3:
  70. o.afterLunchStart = tArr[0] + ':00';
  71. o.afterLunchEnd = tArr[1] + ':59';
  72. break;
  73. case 4:
  74. o.beforeDinnerStart = tArr[0] + ':00';
  75. o.beforeDinnerEnd = tArr[1] + ':59';
  76. break;
  77. case 5:
  78. o.afterDinnerStart = tArr[0] + ':00';
  79. o.afterDinnerEnd = tArr[1] + ':59';
  80. break;
  81. case 6:
  82. o.beforeSleepStart = tArr[0] + ':00';
  83. o.beforeSleepEnd = tArr[1] + ':59';
  84. break;
  85. }
  86. }
  87. });
  88. if (!isGo) {
  89. console.log(o)
  90. sendPost("patient/device/setBloodTime", o, "json", "get", function(res){
  91. d.close();
  92. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败'}).show();
  93. }, function (res) {
  94. d.close();
  95. if (res.status == 200) {
  96. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  97. setTimeout(function(){
  98. window.location.href='my-equipments.html';
  99. },1000);
  100. } else {
  101. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'保存失败'}).show();
  102. }
  103. });
  104. }
  105. }
  106. function pushHistory() {
  107. var state = {
  108. title: "title",
  109. url: "#"
  110. };
  111. window.history.pushState(state, "title", "#");
  112. }
  113. pushHistory();
  114. function bindEvent () {
  115. setTimeout( function () {
  116. window.addEventListener("popstate", function(e) {
  117. location.href = 'my-equipments.html';
  118. }, false);
  119. }, 300);
  120. $ttSendBtn.on( 'click', function () {
  121. addData();
  122. });
  123. }
  124. bindEvent();
  125. });
  126. })( jQuery, window);