view-shezhishijianduan-new.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var Request = GetRequest();
  3. var type = Request["type"],
  4. sncode = Request["sncode"],
  5. categoryCode = Request["categoryCode"],
  6. $yqName = $('.yq-name'),
  7. $szTime = $('.sz-time'),
  8. $ttSendBtn = $('.tt-send-btn'),
  9. tips = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖'];
  10. $(function(){
  11. var list = [{
  12. name: '早餐前血糖',
  13. value1: '',
  14. value2: ''
  15. },{
  16. name: '早餐后血糖',
  17. value1: '',
  18. value2: ''
  19. },{
  20. name: '午餐前血糖',
  21. value1: '',
  22. value2: ''
  23. },{
  24. name: '午餐后血糖',
  25. value1: '',
  26. value2: ''
  27. },{
  28. name: '晚餐前血糖',
  29. value1: '',
  30. value2: ''
  31. },{
  32. name: '晚餐后血糖',
  33. value1: '',
  34. value2: ''
  35. },{
  36. name: '睡前血糖',
  37. value1: '',
  38. value2: ''
  39. }];
  40. var html = template('time-tmp', {list: list});
  41. $(".time-list").empty().append(html);
  42. bindEvents();
  43. });
  44. function addData(){
  45. d.show();
  46. var o = {},
  47. isTrue = true,
  48. isGo = true;
  49. o.deviceSN = sncode;
  50. o.categoryCode = categoryCode; //设备分类 血糖仪1 血压计 2
  51. o.userType = "-1"; //是否多用户
  52. $.each($(".time-item"), function(index) {
  53. var value1 = $(this).find(".sz-time:eq(0)").val(),
  54. value2 = $(this).find(".sz-time:eq(1)").val();
  55. if(isTrue) {
  56. isTrue = checkDate(value1, value2, index);
  57. isGo = checkDate(value1, value2, index);
  58. switch(index) {
  59. case 0:
  60. o.fastingStart = value1 + ':00';
  61. o.fastingEnd = value2 + ':59';
  62. break;
  63. case 1:
  64. o.afterBreakfastStart = value1 + ':00';
  65. o.afterBreakfastEnd = value2 + ':59';
  66. break;
  67. case 2:
  68. o.beforeLunchStart = value1 + ':00';
  69. o.beforeLunchEnd = value2 + ':59';
  70. break;
  71. case 3:
  72. o.afterLunchStart = value1 + ':00';
  73. o.afterLunchEnd = value2 + ':59';
  74. break;
  75. case 4:
  76. o.beforeDinnerStart = value1 + ':00';
  77. o.beforeDinnerEnd = value2 + ':59';
  78. break;
  79. case 5:
  80. o.afterDinnerStart = value1 + ':00';
  81. o.afterDinnerEnd = value2 + ':59';
  82. break;
  83. case 6:
  84. o.beforeSleepStart = value1 + ':00';
  85. o.beforeSleepEnd = value2 + ':59';
  86. break;
  87. }
  88. }
  89. });
  90. if(isGo) {
  91. sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
  92. d.close();
  93. if(res.status == 200) {
  94. dialog({
  95. contentType: 'tipsbox',
  96. bottom: true,
  97. skin: 'bk-popup',
  98. content: res.msg
  99. }).show();
  100. setTimeout(function(){
  101. window.location.href='my-equipments.html';
  102. },1000);
  103. } else {
  104. dialog({
  105. contentType: 'tipsbox',
  106. bottom: true,
  107. skin: 'bk-popup',
  108. content: '保存失败'
  109. }).show();
  110. }
  111. });
  112. }
  113. }
  114. function bindEvents(){
  115. //绑定时间控件弹出
  116. $(".time-list").on('click', '.change-date', function(){
  117. var $this = $(this),
  118. $parent = $this.closest(".time-item"),
  119. $next = $parent.next();
  120. var picker = new mui.DtPicker({type: 'time'});
  121. picker.show(function(rs) {
  122. /*
  123. * rs.value 拼合后的 value
  124. * rs.text 拼合后的 text
  125. * rs.y 年,可以通过 rs.y.vaue 和 rs.y.text 获取值和文本
  126. * rs.m 月,用法同年
  127. * rs.d 日,用法同年
  128. * rs.h 时,用法同年
  129. * rs.i 分(minutes 的第二个字母),用法同年
  130. */
  131. $this.val(rs.text);
  132. if($next && !$this.hasClass("first")){
  133. var h = rs.h.text,
  134. i = rs.i.text;
  135. if(parseInt(i)+1 == 60){
  136. i = 0;
  137. h = parseInt(h) + 1;
  138. if(parseInt(h) < 10){
  139. h = '0' + h;
  140. }
  141. }else{
  142. i = parseInt(i)+1;
  143. }
  144. if(i < 10){
  145. i = '0'+ i;
  146. }
  147. $next.find(".sz-time").eq(0).val(h+":"+i);
  148. }
  149. // picker.dispose();
  150. });
  151. });
  152. setTimeout( function () {
  153. window.addEventListener("popstate", function(e) {
  154. location.href = 'my-equipments.html';
  155. }, false);
  156. }, 300);
  157. $(".tt-send-btn").on( 'click', function () {
  158. addData();
  159. });
  160. }
  161. function checkDate(v1, v2, index) {
  162. if(v1 == '' || v2 == '') {
  163. var content = "请选择"+tips[index]+"检测时间";
  164. dialog({
  165. contentType: 'tipsbox',
  166. skin: 'bk-popup',
  167. bottom: true,
  168. content: content
  169. }).show();
  170. d.close();
  171. return false;
  172. }else{
  173. var v1 = v1.split(":"),
  174. v2 = v2.split(":"),
  175. v1_h = v1[0],
  176. v1_m = v1[1],
  177. v2_h = v2[0],
  178. v2_m = v2[1];
  179. if(v1_h == v2_h){
  180. if(v1_m > v2_m){
  181. var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
  182. dialog({
  183. contentType: 'tipsbox',
  184. skin: 'bk-popup',
  185. bottom: true,
  186. content: content
  187. }).show();
  188. d.close();
  189. return false;
  190. }
  191. }else if(v1_h > v2_h){
  192. var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
  193. dialog({
  194. contentType: 'tipsbox',
  195. skin: 'bk-popup',
  196. bottom: true,
  197. content: content
  198. }).show();
  199. d.close();
  200. return false;
  201. }
  202. }
  203. return true;
  204. }