123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var Request = GetRequest();
- var type = Request["type"],
- sncode = Request["sncode"],
- categoryCode = Request["categoryCode"],
- $yqName = $('.yq-name'),
- $szTime = $('.sz-time'),
- $ttSendBtn = $('.tt-send-btn'),
- tips = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖'];
-
- $(function(){
- var list = [{
- name: '早餐前血糖',
- value1: '',
- value2: ''
- },{
- name: '早餐后血糖',
- value1: '',
- value2: ''
- },{
- name: '午餐前血糖',
- value1: '',
- value2: ''
- },{
- name: '午餐后血糖',
- value1: '',
- value2: ''
- },{
- name: '晚餐前血糖',
- value1: '',
- value2: ''
- },{
- name: '晚餐后血糖',
- value1: '',
- value2: ''
- },{
- name: '睡前血糖',
- value1: '',
- value2: ''
- }];
- var html = template('time-tmp', {list: list});
- $(".time-list").empty().append(html);
- bindEvents();
- });
- function addData(){
- d.show();
- var o = {},
- isTrue = true,
- isGo = true;
- o.deviceSN = sncode;
- o.categoryCode = categoryCode; //设备分类 血糖仪1 血压计 2
- o.userType = "-1"; //是否多用户
- $.each($(".time-item"), function(index) {
- var value1 = $(this).find(".sz-time:eq(0)").val(),
- value2 = $(this).find(".sz-time:eq(1)").val();
- if(isTrue) {
- isTrue = checkDate(value1, value2, index);
- isGo = checkDate(value1, value2, index);
- switch(index) {
- case 0:
- o.fastingStart = value1 + ':00';
- o.fastingEnd = value2 + ':59';
- break;
- case 1:
- o.afterBreakfastStart = value1 + ':00';
- o.afterBreakfastEnd = value2 + ':59';
- break;
- case 2:
- o.beforeLunchStart = value1 + ':00';
- o.beforeLunchEnd = value2 + ':59';
- break;
- case 3:
- o.afterLunchStart = value1 + ':00';
- o.afterLunchEnd = value2 + ':59';
- break;
- case 4:
- o.beforeDinnerStart = value1 + ':00';
- o.beforeDinnerEnd = value2 + ':59';
- break;
- case 5:
- o.afterDinnerStart = value1 + ':00';
- o.afterDinnerEnd = value2 + ':59';
- break;
- case 6:
- o.beforeSleepStart = value1 + ':00';
- o.beforeSleepEnd = value2 + ':59';
- break;
- }
- }
- });
- if(isGo) {
- sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
- d.close();
- if(res.status == 200) {
- dialog({
- contentType: 'tipsbox',
- bottom: true,
- skin: 'bk-popup',
- content: res.msg
- }).show();
- setTimeout(function(){
- window.location.href='my-equipments.html';
- },1000);
- } else {
- dialog({
- contentType: 'tipsbox',
- bottom: true,
- skin: 'bk-popup',
- content: '保存失败'
- }).show();
- }
- });
- }
- }
- function bindEvents(){
- //绑定时间控件弹出
- $(".time-list").on('click', '.change-date', function(){
- var $this = $(this),
- $parent = $this.closest(".time-item"),
- $next = $parent.next();
- var picker = new mui.DtPicker({type: 'time'});
- picker.show(function(rs) {
- /*
- * rs.value 拼合后的 value
- * rs.text 拼合后的 text
- * rs.y 年,可以通过 rs.y.vaue 和 rs.y.text 获取值和文本
- * rs.m 月,用法同年
- * rs.d 日,用法同年
- * rs.h 时,用法同年
- * rs.i 分(minutes 的第二个字母),用法同年
- */
- $this.val(rs.text);
- if($next && !$this.hasClass("first")){
- var h = rs.h.text,
- i = rs.i.text;
- if(parseInt(i)+1 == 60){
- i = 0;
- h = parseInt(h) + 1;
- if(parseInt(h) < 10){
- h = '0' + h;
- }
- }else{
- i = parseInt(i)+1;
- }
- if(i < 10){
- i = '0'+ i;
- }
-
- $next.find(".sz-time").eq(0).val(h+":"+i);
- }
- // picker.dispose();
- });
- });
-
- setTimeout( function () {
- window.addEventListener("popstate", function(e) {
- location.href = 'my-equipments.html';
- }, false);
- }, 300);
-
- $(".tt-send-btn").on( 'click', function () {
- addData();
- });
- }
- function checkDate(v1, v2, index) {
- if(v1 == '' || v2 == '') {
- var content = "请选择"+tips[index]+"检测时间";
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: content
- }).show();
- d.close();
- return false;
- }else{
- var v1 = v1.split(":"),
- v2 = v2.split(":"),
- v1_h = v1[0],
- v1_m = v1[1],
- v2_h = v2[0],
- v2_m = v2[1];
- if(v1_h == v2_h){
- if(v1_m > v2_m){
- var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: content
- }).show();
- d.close();
- return false;
- }
- }else if(v1_h > v2_h){
- var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: content
- }).show();
- d.close();
- return false;
- }
- }
- return true;
- }
|