function ribao_init() {
  $('#btnRB').on('click', function () {
    window.location.href = "/yeweihui/home.html";
  });

}

//近日报告
function ribaoInitialization(reportId) {
  if (reportId == null)
    return;
  $.ajax({
    url: '/home/home/queryRibaoRefresh',
    data: {
      reportId: reportId
    },
    type: 'GET',
    success: function (data) {
      console.log(data);
      if (data.data.length > 0) {
        hasData = true;
        data.data.forEach(function (v) {
          ribao_cell(v);
        });
      } else {

      }
    },
    error: function () {
    }
  });
}

//刷新今日日报
function ribao_refrash() {
  var userId = $("#userId").val();
  $.ajax({
    url: '/home/home/queryRibao',
    data: {
      userCreate: userId
    },
    type: 'GET',
    success: function (data) {
      console.log(data);
      if (data.data.length > 0) {
        hasData = true;
        $('#rb_family').empty();
        data.data.forEach(function (v) {
          ribao_cell(v);
        });
      } else {

      }
    },
    error: function () {
    }
  });
}

function ribao_cell(v) {
  var conditionStatusList = v.conditionStatus.split(',');
  var conditionStatus = v.userName + "：";
  if (conditionStatusList[0] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;咳嗽"
  if (conditionStatusList[1] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;发烧"
  if (conditionStatusList[2] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;腹泻"
  if (conditionStatusList[3] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;酸痛"
  if (conditionStatusList[4] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;乏力"
  if (conditionStatusList[5] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;其他"
  if (v.medical > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;确诊"
  else
    conditionStatus += "&nbsp;&nbsp;&nbsp;未确诊"
  $('#rb_family').append($('<div class="weui-media-box weui-media-box_text">\n' +
    '                                      <h4 class="weui-media-box__title">' + conditionStatus + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style="color: #2a62bc" onclick=\'deleteSuspected(' + JSON.stringify(v.suspectedId) + ')\'>删除</a></h4>\n' +
    '                                      <p class="weui-media-box__desc">' + v.remarks + '</p>\n' +
    '                                    </div>\n' +
    '                              '));
}

function ribao_add() {
  $('#btnAdd').on('click', function () {
    if ($('#ribao')[0].style.display == 'none') {
      $('#notOpenRibao').toggle();
      $('#ribao')[0].style.display = '';
    } else {
      $('#notOpenRibao')[0].style.display = '';
      $('#ribao')[0].style.display = 'none';
    }
  });
}

function ribao_cancel() {
  $('#cancel').on('click', function () {
    if ($('#ribao')[0].style.display == 'none') {
      $('#notOpenRibao').toggle();
      $('#ribao')[0].style.display = '';
    } else {
      $('#notOpenRibao')[0].style.display = '';
      $('#ribao')[0].style.display = 'none';
    }
  });
}

function ribaoCommit() {
  var userId = $("#userId").val();
  var user_name = $("#js_input_user_name").val();
  if (user_name == "") {
    alert("请填写家人姓名");
    return;
  }
  if (user_name.length > 25) {
    alert("请填写正确格式家人姓名");
    return;
  }
  var remarks = $("#rb_remarks").val();
  if (remarks == "") {
    alert("请填写病情描述");
    return;
  }
  if (remarks.length > 100) {
    alert("病情描述内容太长");
    return;
  }
  var medical = "";
  if ($("input[name='medical']:checked").val() == "on")
    medical = "1";
  else
    medical = "0";
  var conditionStatus = "";
  if ($("input[name='checkbox1']:checked").val() == "on")
    conditionStatus += "1";
  else
    conditionStatus += "0";
  if ($("input[name='checkbox2']:checked").val() == "on")
    conditionStatus += ",2";
  else
    conditionStatus += ",0";
  if ($("input[name='checkbox3']:checked").val() == "on")
    conditionStatus += ",3";
  else
    conditionStatus += ",0";
  if ($("input[name='checkbox4']:checked").val() == "on")
    conditionStatus += ",4";
  else
    conditionStatus += ",0";
  if ($("input[name='checkbox5']:checked").val() == "on")
    conditionStatus += ",5";
  else
    conditionStatus += ",0";
  if ($("input[name='checkbox6']:checked").val() == "on")
    conditionStatus += ",4";
  else
    conditionStatus += ",6";

  $.ajax({
    url: '/home/addRibao',
    type: "post",
    data: {
      "userCreate": userId,
      "userName": user_name,
      "conditionStatus": conditionStatus,
      "medical": medical,
      "remarks": remarks,
    },
    success: function (data) {
      if ($('#ribao')[0].style.display == 'none') {
        $('#notOpenRibao').toggle();
        $('#ribao')[0].style.display = '';
      } else {
        $('#notOpenRibao')[0].style.display = '';
        $('#ribao')[0].style.display = 'none';
      }
      ribao_refrash();
    },
  });
}

function deleteSuspected(suspectedId) {
  $.ajax({
    url: '/home/deleteSuspected',
    type: "post",
    data: {
      "suspectedId": suspectedId
    },
    success: function (data) {
      ribao_refrash();
    },
  });
}


function addReport() {
  var userId = $("#userId").val();
  var safety_num = $("#ribao_safety_num").val();
  if (safety_num == "") {
    alert("请填写居家人数");
    return;
  }
  $.ajax({
    url: '/home/addReport',
    type: "post",
    data: {
      "userCreate": userId,
      "safetyNum": safety_num,
    },
    success: function (data) {
      $.toast("操作成功");
    },
  });
}

$("#my-input-ribao").calendar({
  dateFormat: 'yyyy-mm-dd',
  inputReadOnly: false,
  onChange: function (p, values, displayValues) {
    var reportDate = values.toString();
    var userId = $("#userId").val();
    $.ajax({
      url: '/home/home/queryRibaoReportDate',
      data: {
        "userCreate": userId,
        "reportDate": reportDate,
      },
      type: 'GET',
      success: function (data) {
        if (data.data == undefined) {
          $('#ribao_famliy').empty();
        }
        else {
          if (data.data.length > 0) {
            $('#ribao_famliy').empty();
            data.data.forEach(function (v) {
              helpValue1(v);
            });
          } else {

          }
        }
      },
      error: function () {
      }
    });
  }
});


function helpValue1(v) {
  var conditionStatusList = v.conditionStatus.split(',');
  var conditionStatus = v.userName + "：";
  if (conditionStatusList[0] > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;咳嗽"
  if (conditionStatusList[1] > 0) {
    conditionStatus += "&nbsp;&nbsp;&nbsp;发烧"
  }
  if (conditionStatusList[2] > 0) {
    conditionStatus += "&nbsp;&nbsp;&nbsp;腹泻"
  }
  if (conditionStatusList[3] > 0) {
    conditionStatus += "&nbsp;&nbsp;&nbsp;酸痛"
  }
  if (conditionStatusList[4] > 0) {
    conditionStatus += "&nbsp;&nbsp;&nbsp;乏力"
  }
  if (conditionStatusList[5] > 0) {
    conditionStatus += "&nbsp;&nbsp;&nbsp;其他"
  }
  if (v.medical > 0)
    conditionStatus += "&nbsp;&nbsp;&nbsp;确诊"
  else
    conditionStatus += "&nbsp;&nbsp;&nbsp;未确诊"
  $('#ribao_famliy').append($('<div class="weui-media-box weui-media-box_text">\n' +
    '                                      <h4 class="weui-media-box__title">' + conditionStatus + '</h4>\n' +
    '                                      <p class="weui-media-box__desc">' + v.remarks + '</p>\n' +
    '                                    </div>\n' +
    '                              '));
}
