Browse Source

判断多选单选

wyq 4 years ago
parent
commit
d4707ecdb1
5 changed files with 162 additions and 60 deletions
  1. 4 1
      src/css/staticInfo.less
  2. BIN
      src/images/icon-warn.png
  3. 4 2
      src/js/promise.js
  4. 73 29
      src/js/staticInfo.js
  5. 81 28
      src/js/staticInfoOut.js

+ 4 - 1
src/css/staticInfo.less

@@ -349,7 +349,7 @@
   margin-bottom: 6px;
   .item-list{
     padding: 0 21px;
-    .item-title{
+    .item-title,.item-titles{
       font-size: 14px;
       font-weight: 400;
       color: #333333;
@@ -501,4 +501,7 @@
       padding-right: 75px;
     }
   }
+}
+.chColor{
+  color: red!important;
 }

BIN
src/images/icon-warn.png


+ 4 - 2
src/js/promise.js

@@ -2,6 +2,7 @@ const qs = require('qs');
 const $ = require("jquery");
 // var Promise = require('./rePromise');
 var Promise = require("bluebird");
+let warn = require('./../images/icon-warn.png').replace(/^undefined/g, '')
 let iconWarning = require('./../images/icon_waring_white.png').replace(/^undefined/g, '')
 let iconWarning1 = require('./../images/icon_warning.png').replace(/^undefined/g, '')
 let iconSymptomPush = require('./../images/icon_symptom_push.png').replace(/^undefined/g, '')
@@ -340,8 +341,9 @@ const titleConfigH = {
 const Toast = function (msg, duration) {
   duration = isNaN(duration) ? 3000 : duration;
   var m = document.createElement('div');
-  m.innerHTML = msg;
-  m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0,.7);font-size: 16px;";
+  m.innerHTML = `<img class="warn" style="margin-right:14px" src=${warn}/>`+msg;
+  m.style.cssText = "display:flex;align-items:center;max-width:60%;min-width: 150px;padding:0 14px;height: 30px;color: #FFB609;line-height: 30px;text-align: center;border-radius: 4px;position: fixed;top: 15px;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: #FDF6EA;font-size: 16px;";
+  $('.warn').css('margin-top','10px')
   document.body.appendChild(m);
   setTimeout(function () {
     var d = 0.5;

+ 73 - 29
src/js/staticInfo.js

@@ -24,6 +24,7 @@ let printing = require('./../images/printing.png');
 let printing2 = require('./../images/printing2.png');
 let recommend = require('./../images/recommend.png');
 
+
 let showName, noticeName, clinicalPathwayName
 function getInfomation() {
   var param = {
@@ -134,7 +135,12 @@ function renderContentscale(list, contentWrapClassName, name) {
           var it = items.detailList[k];
           it.content = it.content && it.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
           str = '<div class="contentList" data-id="' + it.parentId + '"><div class="item-list">';
-          str += '<p class="item-title">' + it.content + '</p>'
+          if (it.selectType == 1) {
+            str += '<p class="item-title">' + it.content + '</p>'
+          } else if (it.selectType == 2) {
+            str += '<p class="item-titles">' + it.content + '</p>'
+          }
+
           str += '<div class="item-content" data-id="' + it.id + '">'
           str += '</div></div></div>'
           $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "]").append(str);
@@ -142,10 +148,14 @@ function renderContentscale(list, contentWrapClassName, name) {
             var its = it.subList[0].detailList[l];
             its.content = its.content && its.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
             str = '<div class="radio" name="scale' + its.parentId + '" value="' + its.score + '">';
-            if (it.selectType == 1) {
-              str += '<label><input class="radio_type" type="checkbox" name="scale' + its.parentId + '" type="radio" value="' + its.score + '" />'
-            } else if (it.selectType == 2) {
+            if (it.selectType == 1 && item.resultType == 1) {
+              str += '<label><input class="radio_type" type="checkbox" name="scale' + its.parentId + '" value="' + its.score + '"/>'
+            } else if (it.selectType == 2 && item.resultType == 1) {
               str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.score + '" />'
+            } else if (it.selectType == 1 && item.resultType == 2) {
+              str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="checkbox" value="' + its.result + '" data_obj="' + its.result + '"/>'
+            } else if (it.selectType == 2 && item.resultType == 2) {
+              str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.result + '" data_obj="' + its.result + '"/>'
             }
             str += its.content
             if (item.resultType == 1) {
@@ -181,7 +191,6 @@ function renderContentscale(list, contentWrapClassName, name) {
   // $(`.${contentWrapClassName} .infos`).after(str);
   function addScrollEvent() {
     var scrollTop = $(`.${contentWrapClassName} .infos .infos-box`).scrollTop()
-
     var divHeight = 0;
     for (var i = 0; i < list.length; i++) {
       divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
@@ -230,6 +239,7 @@ function getcheck() {
   $('input:checkbox').click(function () {
     const domName = $(this).attr('name');
     const $radio = $(this);
+
     if ($radio.data('waschecked') == true) {
       $radio.prop('checked', false);
       $("input:checkbox[name='" + domName + "']").data('waschecked', false);
@@ -264,40 +274,74 @@ function getResult(pushInfo) {
   $(".but").click(function () {
     let arr = [];
     let num = 0
+    let result
+    let key = false
     $(".contentList").each(function (i) {
-      if (Number(parseFloat($(this).find('input[type="radio"]:checked').val()))) {
-        num += parseFloat($(this).find('input[type="radio"]:checked').val())
+      if ($(this).find('input[type="radio"]:checked').val() == undefined) {
+        $(this).find(".item-titles").addClass('chColor');
+      } else {
+        $(this).find(".item-titles").removeClass('chColor');
+      }
+      if ($(this).find('input[type="checkbox"]:checked').val() == undefined) {
+        $(this).find(".item-title").addClass('chColor');
+      } else {
+        $(this).find(".item-title").removeClass('chColor');
       }
-    })
-    $('input[type="checkbox"]:checkbox:checked').each(function () {
-      num += parseFloat($(this).val())
     });
-    for (var i = 0; i < pushInfo.length; i++) {
-    if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
+    if (!$(".contentList").find(".item-title").hasClass('chColor')) {
+      $('input[type="radio"]:checked').each(function () {
+        if (Number($(this).val())) {
+          num += parseFloat($(this).val())
+        } else {
+          arr.push($(this).attr("data_obj"))
+        }
+      });
+      $('input[type="checkbox"]:checkbox:checked').each(function () {
+        if (Number($(this).val())) {
+          num += parseFloat($(this).val())
+        } else {
+          arr.push($(this).attr("data_obj"))
+        }
+      });
+      tmp = arr.join(",");
+      if (pushInfo.length > 0) {
+        for (var i = 0; i < pushInfo.length; i++) {
+          if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
+            if (tmp) {
+              result = pushInfo[i].result + ',' + tmp
+            } else {
+              result = pushInfo[i].result
+            }
+          }
+        }
+      } else {
+        console.log(11)
+        result = tmp
+      }
+
       $(".result_title").attr({
-        "title": pushInfo[i].result
+        "title": result
       });
       $(".hel").attr({
-        "title": pushInfo[i].pushInfo
+        "title": result
       });
-
-      $(".result_title").html(pushInfo[i].result);
+      $(".result_title").html(result);
+      $(".score").html('总分:' + num + '分');
+      $(".score").css('display', 'block')
+      $(".result").css('display', 'block')
+      $(".foot").css('display', 'block')
+    } else {
+      Toast('温馨提示:必填选项不能为空~', 5000000000)
     }
-  }
-  $(".score").html('总分:' + num + '分');
-  $(".score").css('display', 'block')
-  $(".result").css('display', 'block')
-  $(".foot").css('display', 'block')
-
-})
+  })
 
-$(".printing").hover(
-  function () {
-    $(".slideImg").attr("src", printing2);
-  }, function () {
-    $(".slideImg").attr("src", printing);
+  $(".printing").hover(
+    function () {
+      $(".slideImg").attr("src", printing2);
+    }, function () {
+      $(".slideImg").attr("src", printing);
 
-  });
+    });
 
 }
 

+ 81 - 28
src/js/staticInfoOut.js

@@ -181,9 +181,10 @@ function renderContentscale(list, contentWrapClassName, name) {
   $(`.${contentWrapClassName} .anchors ul`).append(anchors);
   for (var i = 0; i < list[0].detailList.length; i++) {
     var item = list[0].detailList[i];
+    console.log(item)
     if (item.textType == 11) {
       item.content = item.content && item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
-      str = '<div class="infoBox scaleBox"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
+      str = '<div class="infoBox scaleBox" data-id="' + item.id + '"><div class="title"> <h2 class="titleH2" id="' + contentWrapClassName + i +
         '">'
       str += item.content
       str += '</h2></div>'
@@ -194,21 +195,36 @@ function renderContentscale(list, contentWrapClassName, name) {
         for (var k = 0; k < items.detailList.length; k++) {
           var it = items.detailList[k];
           it.content = it.content && it.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
-          str = '<div class="contentList"><div class="item-list">';
-          str += '<p class="item-title">' + it.content + '</p>'
+          str = '<div class="contentList" data-id="' + it.parentId + '"><div class="item-list">';
+          if (it.selectType == 1) {
+            str += '<p class="item-title">' + it.content + '</p>'
+          } else if (it.selectType == 2) {
+            str += '<p class="item-titles">' + it.content + '</p>'
+          }
+
           str += '<div class="item-content" data-id="' + it.id + '">'
           str += '</div></div></div>'
-          $(`.${contentWrapClassName} .infos .infos-box .infoWrapper .infoBox`).append(str);
+          $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "]").append(str);
           for (var l = 0; l < it.subList[0].detailList.length; l++) {
             var its = it.subList[0].detailList[l];
             its.content = its.content && its.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
             str = '<div class="radio" name="scale' + its.parentId + '" value="' + its.score + '">';
-            str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.score + '" />'
+            if (it.selectType == 1 && item.resultType == 1) {
+              str += '<label><input class="radio_type" type="checkbox" name="scale' + its.parentId + '" value="' + its.score + '"/>'
+            } else if (it.selectType == 2 && item.resultType == 1) {
+              str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.score + '" />'
+            } else if (it.selectType == 1 && item.resultType == 2) {
+              str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="checkbox" value="' + its.result + '" data_obj="' + its.result + '"/>'
+            } else if (it.selectType == 2 && item.resultType == 2) {
+              str += '<label><input class="radio_type" name="scale' + its.parentId + '" type="radio" value="' + its.result + '" data_obj="' + its.result + '"/>'
+            }
             str += its.content
-            str += '<span class="num">' + '(' + its.score + ')' + '</span>'
+            if (item.resultType == 1) {
+              str += '<span class="num">' + '(' + its.score + ')' + '</span>'
+            }
             str += '</label>'
             str += `${item.match ? `<img class="recommend" src=${recommend} />` : ``}</div>`
-            $(".scale .infos .infos-box .infoWrapper .infoBox .contentList .item-content[data-id=" + its.parentId + "]").append(str);
+            $(".scale .infos .infos-box .infoWrapper .infoBox[data-id=" + it.parentId + "] .contentList .item-content[data-id=" + its.parentId + "]").append(str);
           }
         }
       }
@@ -236,7 +252,6 @@ function renderContentscale(list, contentWrapClassName, name) {
   // $(`.${contentWrapClassName} .infos`).after(str);
   function addScrollEvent() {
     var scrollTop = $(`.${contentWrapClassName} .infos .infos-box`).scrollTop()
-
     var divHeight = 0;
     for (var i = 0; i < list.length; i++) {
       divHeight = divHeight + parseInt($('#' + contentWrapClassName + i).css('height')) + parseInt($('#' + contentWrapClassName + i).parent().next().css('height')) + 20
@@ -291,6 +306,9 @@ function getcheck() {
 function copy() {
   $(".copy").click(function () {
     var texts = document.getElementById("result_title").innerText;
+    if (texts == '') {
+      return
+    }
     var inputs = document.getElementById("inputs");
     inputs.value = texts; // 修改文本框的内容(赋值内容)
     inputs.select(); // 选中文本
@@ -305,33 +323,68 @@ function copy() {
 }
 
 function getResult(pushInfo) {
-
   $(".but").click(function () {
     let arr = [];
     let num = 0
+    let result
+    let key = false
     $(".contentList").each(function (i) {
-      if (Number(parseFloat($(this).find('input[type="radio"]:checked').val()))) {
-        num += parseFloat($(this).find('input[type="radio"]:checked').val())
+      if ($(this).find('input[type="radio"]:checked').val() == undefined) {
+        $(this).find(".item-titles").addClass('chColor');
+      } else {
+        $(this).find(".item-titles").removeClass('chColor');
       }
-    })
-    for (var i = 0; i < pushInfo.length; i++) {
-      console.log(pushInfo[i])
-      if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
-        $(".result_title").attr({
-          "title": pushInfo[i].result
-        });
-        $(".hel").attr({
-          "title": pushInfo[i].pushInfo
-        });
-
-        $(".result_title").html(pushInfo[i].result);
+      if ($(this).find('input[type="checkbox"]:checked').val() == undefined) {
+        $(this).find(".item-title").addClass('chColor');
+      } else {
+        $(this).find(".item-title").removeClass('chColor');
+      }
+    });
+    if (!$(".contentList").find(".item-title").hasClass('chColor')) {
+      $('input[type="radio"]:checked').each(function () {
+        if (Number($(this).val())) {
+          num += parseFloat($(this).val())
+        } else {
+          arr.push($(this).attr("data_obj"))
+        }
+      });
+      $('input[type="checkbox"]:checkbox:checked').each(function () {
+        if (Number($(this).val())) {
+          num += parseFloat($(this).val())
+        } else {
+          arr.push($(this).attr("data_obj"))
+        }
+      });
+      tmp = arr.join(",");
+      if (pushInfo.length > 0) {
+        for (var i = 0; i < pushInfo.length; i++) {
+          if (pushInfo[i].content.max >= num >= pushInfo[i].content.min) {
+            if (tmp) {
+              result = pushInfo[i].result + ',' + tmp
+            } else {
+              result = pushInfo[i].result
+            }
+          }
+        }
+      } else {
+        console.log(11)
+        result = tmp
       }
-    }
-    $(".score").html('总分:' + num + '分');
-    $(".score").css('display', 'block')
-    $(".result").css('display', 'block')
-    $(".foot").css('display', 'block')
 
+      $(".result_title").attr({
+        "title": result
+      });
+      $(".hel").attr({
+        "title": result
+      });
+      $(".result_title").html(result);
+      $(".score").html('总分:' + num + '分');
+      $(".score").css('display', 'block')
+      $(".result").css('display', 'block')
+      $(".foot").css('display', 'block')
+    } else {
+      Toast('温馨提示:必填选项不能为空~', 5000000000)
+    }
   })
 
   $(".printing").hover(