/**
 * Created by user on 2017/2/9.
 */
//CRC评分
function grade(obj, rvalue, rid) {
    var totalVal = 0;
    var num = 0;
    var arrs = [
        '总胆红素-childpugh评分',
        '白蛋白-childpugh评分',
        'PT/INR-childpugh评分',
        'PT-childpugh评分',
        '腹水-childpugh评分',
        '肝性脑病-childpugh评分',
        'INR-childpugh评分',       //91trial  INR-childpugh评分  增加选项 2017/11 濮
        '凝血酶原时间（延长，s）'  //91trial  凝血酶原时间（延长，s） 增加选项 2017/9 濮
    ];
    var pughObj = $('.visit-info input[name="Child-pugh score"],.visit-info input[name="Child-Pugh评分1"]');
    if (rvalue == 'NA' || rvalue == 'ND' || rvalue == 'UK') {

    }
    $.each(arrs, function (i) {
        if (rid == arrs[i]) {
            var rval = Number(rvalue);
            totalVal += rval;
            num++;
        } else {
            var rObj = $('.visit-info').find('input[name="' + arrs[i] + '"]');
            if (rObj.length > 0) {
                rObj.each(function () {
                    if ($(this).val() == 'NA' || $(this).val() == 'ND' || $(this).val() == 'UK') {

                    } else if ($(this).is(':checked')) {
                        var rtval = Number($(this).val());
                        totalVal += rtval;
                        num++;
                    } else {
                        if ($(this).parent().siblings('.radio').find('.pcr').is(':checked')) {
                            var rvalue = $(this).parent().siblings('.radio').find('.pcr').val();
                            pughObj.val(rvalue).attr("readonly", "readonly");
                            var pugChe = pughObj.parents('.pre_td').find('.pcr[value="' + rvalue + '"]');
                            pugChe.attr('checked', true);
                            pugChe.prop({
                                checked: true
                            });
                        }
                    }
                });
            }
        }
    });
    if (num >= 5 && pughObj.length > 0) {
        pughObj.val(totalVal);
    }
}

function gradeTwo(obj) {
    var gradeFlag = 1;
    var arrs = [
        '总胆红素-childpugh评分',
        '白蛋白-childpugh评分',
        'PT/INR-childpugh评分',
        'PT-childpugh评分',
        '腹水-childpugh评分',
        '肝性脑病-childpugh评分'
    ];
    var pdName = $(obj).parents('.pre_td').find('.na_nd_uk_hidden').attr('name');
    if ($.inArray(pdName,arrs) != -1) {
        gradeFlag = 0
    }
    if (gradeFlag == 0) {
        var rvalue = $(obj).val();
        var pdObj = $('.visit-info').find('.pcr:checked')
        var pughObj = $('.visit-info input[name="Child-pugh score"]').parents('.pre_td').find('.pcr[value="' + rvalue + '"]');
        if (rvalue == 'NA' || rvalue == 'ND' || rvalue == 'UK') {
            if (pughObj.length > 0) {
                $('.visit-info input[name="Child-pugh score"]').val(rvalue).attr("readonly", "readonly");
                pughObj.attr('checked', true);
                pughObj.prop({
                    checked: true
                });
            }
        }
    }
}

function gradeThr(obj) {
    var gradeFlag = 1;
    var arrs = [
        '总胆红素-childpugh评分',
        '白蛋白-childpugh评分',
        'PT/INR-childpugh评分',
        'PT-childpugh评分',
        '腹水-childpugh评分',
        '肝性脑病-childpugh评分'
    ];
    var pdName = $(obj).parents('.pre_td').find('.na_nd_uk_hidden').attr('name');
    if ($.inArray(pdName, arrs) != -1) {
        gradeFlag = 0
    }
    if (gradeFlag == 0) {
        var rvalue = $(obj).val();
        var pdObj = $('.visit-info').find('.radio .pcr:checked');
        var pughObj = $('.visit-info input[name="Child-pugh score"]').parents('.pre_td').find('.pcr[value="' + rvalue + '"]');
        if (rvalue == 'NA' || rvalue == 'ND' || rvalue == 'UK') {
            if (pughObj.length > 0) {
                if (pdObj.length == 0) {
                    $('.visit-info input[name="Child-pugh score"]').val('').removeAttr("readonly");
                    pughObj.attr('checked', false);
                    pughObj.prop({
                        checked: false
                    });
                }
                //$('.visit-info input[name="Child-pugh score"]').val('').removeAttr("readonly");
                //pughObj.attr('checked', false);
                //pughObj.prop({
                //    checked: false
                //});
            }
        }
    }
}

function gradeGan(e,jdNum) {
    var gradeFlag = 1;
    var sname = $(e).attr('name');
    var arrs = [
        'albumin',
        'globulin',
        'total protein',
        'A/G ratio'
    ];
    var arrVal = ['NA', 'ND', 'UK'];
    if ($.inArray(sname, arrs) != -1) {
        gradeFlag = 0
    }
    if (gradeFlag == 0) {
        var albumin = $('.visit-info input[name="albumin"]');
        var globulin = $('.visit-info input[name="globulin"]');
        var total = $('.visit-info input[name="total protein"]');
        var AG = $('.visit-info input[name="A/G ratio"]');
        if (albumin.val() != '' && total.val() != '') {
            if ($.inArray(albumin.val(), arrVal) == -1 && $.inArray(total.val(), arrVal) == -1) {
                if (inputctr.public.isdecimals(Number(albumin.val()), jdNum) && inputctr.public.isdecimals(Number(total.val()), jdNum)) {
                    globulin.val((Number(total.val()) - Number(albumin.val())).toFixed(1));
                    AG.val((Number(albumin.val()) / Number(globulin.val())).toFixed(2));
                } else {
                    globulin.val('');
                    AG.val('');
                }
            } else {
                globulin.val('NA');
                AG.val('NA');
            }
        } else {
            globulin.val('');
            AG.val('');
        }
    }


    var gradeFlag_two = 1;
    var arrs_two = [
        'total bilirubin',
        'direct bilirubin',
        'indirect bilirubin'
    ];
    if ($.inArray(sname, arrs_two) != -1) {
        gradeFlag_two = 0
    }
    if (gradeFlag_two == 0) {
        var totalBilirubin = $('.visit-info input[name="total bilirubin"]');
        var directBilirubin = $('.visit-info input[name="direct bilirubin"]');
        var indirectTotal = $('.visit-info input[name="indirect bilirubin"]');
        if (totalBilirubin.val() != '' && directBilirubin.val() != '') {
            if ($.inArray(totalBilirubin.val(), arrVal) == -1 && $.inArray(directBilirubin.val(), arrVal) == -1) {
                if (inputctr.public.isdecimals(Number(totalBilirubin.val())) && inputctr.public.isdecimals(Number(directBilirubin.val()))) {
                    indirectTotal.val((Number(totalBilirubin.val()) - Number(directBilirubin.val())).toFixed(2));
                } else {
                    indirectTotal.val('');
                }
            } else {
                indirectTotal.val('NA');
            }
        } else {
            indirectTotal.val('');
        }
    }
}

//肝穿日期初始化
function ganchuan(e){
    var sname = $(e).attr('name');
    if (sname == 'time of second liver biopsy') {
        var oneGc = $('.visit-info input[name="第一次肝穿时间"]');
        var sval = $('.visit-info input[name="第一次肝穿时间"]').val();
        if (sval != '') {
            $(e).datepicker('setEndDate', sval);
        }
    }
}

//BMI计算
function bmi(e) {
    var sname = $(e).attr('name');
    var val = $(e).val();
    var jdNum = '2';
    if ($(e).attr('accuracy') && Number($(e).attr('accuracy'))) {
       jdNum = $(e).attr('accuracy');
    }
    if (sname == "身高" && inputctr.public.isdecimals(val, jdNum)) {
        var val2 = $('.visit-info input[name="体重"]').val();
        var jdNum2 = $('.visit-info input[name="体重"]').attr('accuracy') ? $('.visit-info input[name="体重"]').attr('accuracy') : '2';
        if (jdNum2 && Number(jdNum2) && inputctr.public.isdecimals(val2, jdNum2)) {
            $('.visit-info input[name="体质指数"]').val((val2 / Math.pow(val / 100, 2)).toFixed(Number(jdNum2)));
            $('.visit-info input[name="体重指数"]').val((val2 / Math.pow(val / 100, 2)).toFixed(Number(jdNum2)));
        } else {
            $('.visit-info input[name="体质指数"]').val("");
            $('.visit-info input[name="体重指数"]').val("");
        }
    } else if (sname == "体重" && inputctr.public.isdecimals(val, jdNum)) {
        var val3 = $('.visit-info input[name="身高"]').val();
        var jdNum3 = $('.visit-info input[name="身高"]').attr('accuracy') ? $('.visit-info input[name="身高"]').attr('accuracy') : '2';
        if (jdNum3 && Number(jdNum3) && inputctr.public.isdecimals(val3, jdNum3)) {
            $('.visit-info input[name="体质指数"]').val((val / Math.pow(val3 / 100, 2)).toFixed(Number(jdNum3)));
            $('.visit-info input[name="体重指数"]').val((val / Math.pow(val3 / 100, 2)).toFixed(Number(jdNum3)));
        } else {
            $('.visit-info input[name="体质指数"]').val("");
            $('.visit-info input[name="体重指数"]').val("");
        }
    }else if (sname == "Height" && inputctr.public.isdecimals(val, jdNum)) {
        var val2 = $('.visit-info input[name="Weight"]').val();
        var jdNum2 = $('.visit-info input[name="Weight"]').attr('accuracy') ? $('.visit-info input[name="Weight"]').attr('accuracy') : '2';
        if (jdNum2 && Number(jdNum2) && inputctr.public.isdecimals(val2, jdNum2)) {
            $('.visit-info input[name="BMI"]').val((val2 / Math.pow(val / 100, 2)).toFixed(Number(jdNum2)));
        } else {
            $('.visit-info input[name="BMI"]').val("");
        }
    } else if (sname == "Weight" && inputctr.public.isdecimals(val, jdNum)) {
        var val3 = $('.visit-info input[name="Height"]').val();
        var jdNum3 = $('.visit-info input[name="Height"]').attr('accuracy') ? $('.visit-info input[name="Height"]').attr('accuracy') : '2';
        if (jdNum3 && Number(jdNum3) && inputctr.public.isdecimals(val3, jdNum3)) {
            $('.visit-info input[name="BMI"]').val((val / Math.pow(val3 / 100, 2)).toFixed(Number(jdNum3)));
        } else {
            $('.visit-info input[name="BMI"]').val("");
        }
    } else if (sname == "height" && inputctr.public.isdecimals(val, jdNum)) {
        var val2 = $('.visit-info input[name="weight"]').val();
        var jdNum2 = $('.visit-info input[name="weight"]').attr('accuracy') ? $('.visit-info input[name="weight"]').attr('accuracy') : '2';
        if (jdNum2 && Number(jdNum2) && inputctr.public.isdecimals(val2, jdNum2)) {
            $('.visit-info input[name="BMI"]').val((val2 / Math.pow(val / 100, 2)).toFixed(Number(jdNum2)));
        } else {
            $('.visit-info input[name="BMI"]').val("");
        }
    } else if (sname == "weight" && inputctr.public.isdecimals(val, jdNum)) {
        var val3 = $('.visit-info input[name="height"]').val();
        var jdNum3 = $('.visit-info input[name="height"]').attr('accuracy') ? $('.visit-info input[name="height"]').attr('accuracy') : '2';
        if (jdNum3 && Number(jdNum3) && inputctr.public.isdecimals(val3, jdNum3)) {
            $('.visit-info input[name="BMI"]').val((val / Math.pow(val3 / 100, 2)).toFixed(Number(jdNum3)));
        } else {
            $('.visit-info input[name="BMI"]').val("");
        }
    }
}

//满足以下条件之一(二选一)
function selOne(cn,name) {
    var arr = [
        '1）应用支气管扩张剂后FEV1/FVC ＜ 0.7',
        '2）有慢性呼吸症状（慢性咳嗽、咳痰、胸闷、气短、呼吸困难、喘息等）和/或高危因素（吸烟、被动吸烟暴露、职业暴露、生物燃料暴露等），且无气流受限：应用支气管扩张剂后FEV1/FVC ≥ 0.7'
    ]
    if (name == arr[0]) {
        if (cn == '0') {
            $('.visit-info input[name="' + arr[1] + '"]').prop({ "checked": false, "disabled": true });
            $('.visit-info input[name="' + arr[1] + '"]').parents('.poradios:first').removeAttr('required');
        } else if (cn == '1') {
            $('.visit-info input[name="' + arr[1] + '"]').prop({ "disabled": false });
            $('.visit-info input[name="' + arr[1] + '"]').parents('.poradios:first').attr('required', 'required');
        }
    } else if (name == arr[1]) {
        if (cn == '0') {
            $('.visit-info input[name="' + arr[0] + '"]').prop({ "checked": false, "disabled": true });
            $('.visit-info input[name="' + arr[0] + '"]').parents('.poradios:first').removeAttr('required');
        } else if (cn == '1') {
            $('.visit-info input[name="' + arr[0] + '"]').prop({ "disabled": false });
            $('.visit-info input[name="' + arr[0] + '"]').parents('.poradios:first').attr('required', 'required');
        }
    }
}

/*

js自身没有trim()函数取消字符串中的空白字符

自定义函数：用正则替换掉空白字符

*/

function trim(s) { return s.replace(/^\s+|\s+$/g, ""); };
//提取身份证出生日期
function getBirthdatByIdNo(iIdNo) {
    var tmpStr = "";
    var idDate = "";
    var tmpInt = 0;
    var strReturn = "";

    iIdNo = trim(iIdNo);

    if ((iIdNo.length != 15) && (iIdNo.length != 18)) {
        //strReturn = "输入的身份证号位数错误";
        strReturn = "";
        return strReturn;
    }

    if (iIdNo.length == 15) {
        tmpStr = iIdNo.substring(6, 12);
        tmpStr = "19" + tmpStr;
        tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6)

        return tmpStr;
    }
    else {
        tmpStr = iIdNo.substring(6, 14);
        tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6)

        return tmpStr;
    }
}

//身份证提取出生日期
function tqbirthday(v) {
    var day = getBirthdatByIdNo(v);
    if ($('.visit-info input[name="birthday"]').length > 0) {
        $('.visit-info input[name="birthday"]').datepicker('setDate', day);
    }
    if ($('.visit-info input[name="出生年月"]').length > 0) {
        $('.visit-info input[name="出生年月"]').datepicker('setDate', day);
    }
    if ($('.visit-info input[name="年龄"]').length > 0 && day && $('.visit-info input[name="id card"]').length > 0) {
        var r = day.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4]);
        if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]) {
            var Y = new Date().getFullYear();
            $('.visit-info input[name="年龄"]').val((Y - r[1]))
            return false;
        }
    }
    if ($('.visit-info input[name="age"]').length > 0 && day && ($('.visit-info input[name="身份证号码"]').length > 0 || $('.visit-info input[name="id card"]').length > 0)) {
        var r = day.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4]);
        if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]) {
            var Y = new Date().getFullYear();
            $('.visit-info input[name="age"]').val((Y - r[1]))
            return false;
        }
    }
}

function tqszm(v) {
    var reNum = /[\u4e00-\u9fa5]/gm;
    if (reNum.test(v)) {
        var szm = pinyinUtil.getFirstLetter(v, false);
        if ($('.visit-info input[name="输入码"]').length > 0) {
            $('.visit-info input[name="输入码"]').val(szm);
        } else if ($('.visit-info input[name="name short"]').length > 0) {
            var qp = pinyinUtil.getPinyin(v, ',', false);
            var lval = '';
            if (v.length == 2) {
                lval = (qp.split(',')[0].substring(0, 2) + qp.split(',')[1].substring(0, 2)).toLocaleUpperCase();
            } else if (v.length == 3) {
                lval = (qp.split(',')[0].substring(0, 1) + qp.split(',')[1].substring(0, 1) + qp.split(',')[2].substring(0, 2)).toLocaleUpperCase();
            } else if (v.length > 3) {
                lval = (qp.split(',')[0].substring(0, 1) + qp.split(',')[1].substring(0, 1) + qp.split(',')[2].substring(0, 1) + qp.split(',')[3].substring(0, 1)).toLocaleUpperCase();
            }
            $('.visit-info input[name="name short"]').val(lval);
        }
    }
}

function pcount(obj, rvalue, rid) {
    var totalVal = 0;
    var num = 0;
    var arrs = [
        '1. 您胸骨后出现烧灼感(烧心)的频率?',
        '2. 感觉到有胃内容物(液体或食物)上返至您的喉咙或口腔(反流)的频率?',
        '3. 您感到上腹部中央疼痛的频率?',
        '4. 您感到恶心的频率?',
        '5. 由于您的烧心和/或反流而难以获得良好夜间睡眠的频率?',
        '6. 除医生告知服用的药物外，您额外服用药物来缓解烧心和/或反流的频率? (如碳酸钙、氢氧化铝等抗酸剂)'
    ];
    var pughObj = $('.visit-info input[name="总分"]');
    var dx = '';
    if ($.inArray(rid, arrs) == -1) {
        arrs = [
            '1. 感觉紧张，焦虑或急切',
            '2. 不能够停止或控制担忧',
            '3. 对各种各样的事情担忧过多',
            '4. 很难放松下来',
            '5. 由于不安而无法静坐',
            '6. 变得容易烦恼或急躁',
            '7. 感到害怕，似乎将有可怕的事情发生'
        ]
        pughObj = $('.visit-info input[name="总分_GAD-7量表"]');
        dx = $('.visit-info input[name="焦虑程度"]');
        if ($.inArray(rid, arrs) == -1) {
            arrs = [
                '1. 做任何事都觉得沉闷或者根本不想做任何事',
                '2. 情绪低落、抑郁或绝望',
                '3. 难于入睡：半夜会醒，或相反，睡觉时间过多',
                '4. 觉得疲倦或没有活力',
                '5. 胃口极差或饮食过量',
                '6. 不喜欢自己—觉得自己做得不好、对自己失望或有负家人期望',
                '7. 难于集中精神做事，例如看报纸或看电视',
                '8. 其他人反映你行动或说话迟缓；或者相反，你比平常活动更多—坐立不安、停不下来',
                '9. 想到自己最好去死或者自残'
            ]
            pughObj = $('.visit-info input[name="总分_PHQ-9量表"]');
            dx = $('.visit-info input[name="抑郁程度"]');
            if ($.inArray(rid, arrs) == -1) {
                arrs = [
                   '是否咳嗽？（0从不咳嗽，5总是咳嗽）',
                   '肺里是否有痰？（0一点痰都没有，5有很多痰）',
                   '有无胸闷的感觉？（0一点也没有胸闷的感觉，5很重的胸闷感觉）',
                   '在爬坡或爬一层楼梯时，是否感觉喘不过气来？（0并不感觉喘不过气来，5感觉非常喘不过气来）',
                   '在家里的活动是否受慢阻肺的影响？（0不受任何影响，5很受影响）',
                   '尽管有肺病，是否有信心外出？（0有信心，5完全没有信心）',
                   '睡眠是否受影响？（0睡得好，5睡得不好）',
                   '精力是否旺盛？（0精力旺盛，5一点精力都没有）'
                ]
                pughObj = $('.visit-info input[name="CAT 总分"]');
            }
        }
    }
    $.each(arrs, function (i) {
        if (rid == arrs[i]) {
            if ($('.visit-info').find('input[name="' + arrs[i] + '"]:checked').length > 0) {
                var rval = Number(rvalue);
                totalVal += rval;
                num++;
            }
        } else {
            var rObj = $('.visit-info').find('input[name="' + arrs[i] + '"]');
            if (rObj.length > 0) {
                rObj.each(function () {
                    if ($(this).is(':checked')) {
                        var rtval = Number($(this).val());
                        totalVal += rtval;
                        num++;
                    }
                });
            }
        }
    });
    if (num >= arrs.length  && pughObj.length > 0) {
        pughObj.val(totalVal);
        if (dx.length > 0) {
            if (dx.attr('name') == '焦虑程度') {
                if (0 <= totalVal && totalVal <= 5) {
                    dx.eq(0).prop('checked', true);
                } else if (6 <= totalVal && totalVal <= 10) {
                    dx.eq(1).prop('checked', true);
                } else if (11 <= totalVal && totalVal <= 15) {
                    dx.eq(2).prop('checked', true);
                } else if (16 <= totalVal && totalVal) {
                    dx.eq(3).prop('checked', true);
                }
            } else if (dx.attr('name') == '抑郁程度') {
                if (0 <= totalVal && totalVal <= 4) {
                    dx.eq(0).prop('checked', true);
                } else if (5 <= totalVal && totalVal <= 9) {
                    dx.eq(1).prop('checked', true);
                } else if (10 <= totalVal && totalVal <= 14) {
                    dx.eq(2).prop('checked', true);
                } else if (15 <= totalVal && totalVal <= 19) {
                    dx.eq(3).prop('checked', true);
                } else if (20 <= totalVal && totalVal) {
                    dx.eq(4).prop('checked', true);
                }
            }
        }
    } else {
        pughObj.val('');
    }
}

function pcountTwo(obj, rvalue, rid) {
    var arrs = '下列哪种情况符合您的日常生活状态？';
    var pughObj = $('.visit-info input[name="呼吸困难评分级别"]');
    if (rid == arrs && $(obj).is(':checked')) {
        pughObj.val(rvalue);
    } else {
        pughObj.val('');
    }
}

//cTNM分期
function cTnm(e) {
    var pname = $(e).attr('name');
    var arr = [
        'T分期',
        'N分期',
        'M分期',
        '期别'
    ]
    var jDom = $();
    if ($.inArray(pname, arr) != -1) {
        var t, n, m, stage = $('input[name="' + arr[3] + '"]');
        $.each(arr, function (i) {
            jDom = jDom.add($('input[name="' + arr[i] + '"]')); //获得所有对象
        });
        jDom.each(function () {
            var flag = 0;  //用来判断是T? N? M?分期
            if ($(this).is(':checked')) {
                var name = $(this).attr('name');
                $.each(arr,function (n) {
                    if (name == arr[n]) {
                        flag = n + 1;
                    }
                });
                //flag 1是T 2是N 3是M
                switch (~~$(this).val()) {
                    case 1:
                        switch (flag) {
                            case 1:
                                t = 0;  //选择了T1
                                break;
                            case 2:
                                n = 0;  //选择了N0
                                break;
                            case 3:
                                m = 0; //选择了M0
                                break;
                        }
                        break;
                    case 2:
                        switch (flag) {
                            case 1:
                                t = 0;  //选择了T2
                                break;
                            case 2:
                                n = 1; //选择了N1a
                                break;
                        }
                        break;
                    case 3:
                        switch (flag) {
                            case 1:
                                t = 1; //选择了T3
                                break;
                            case 2:
                                n = 1; //选择了N1b
                                break;
                        }
                        break;
                    case 4:
                        switch (flag) {
                            case 1:
                                t = 2;//选择了T4a
                                break;
                            case 2:
                                n = 1;//选择了N1c
                                break;
                        }
                        break;
                    case 5:
                        switch (flag) {
                            case 1:
                                t = 3;//选择了T4b
                                break;
                            case 2:
                                n = 2;//选择了N2a
                                break;
                        }
                        break;
                }
            }
        });
        if(t == 1 && n == 0 && m == 0){
            stage.eq(0).prop('checked',true);
        } else if (t == 2 && n == 0 && m == 0) {
            stage.eq(1).prop('checked', true);
        } else if (t == 3 && n == 0 && m == 0) {
            stage.eq(2).prop('checked', true);
        } else if (t == 0 && n == 1 && m == 0) {
            stage.eq(3).prop('checked', true);
        } else if (t == 1 && n == 1 && m == 0 || t == 2 && n == 1 && m == 0) {
            stage.eq(4).prop('checked', true);
        } else if (t == 2 && n == 2 && m == 0) {
            stage.eq(5).prop('checked', true);
        } else {
            stage.prop('checked', false);
        }
    }
}

//神经系统 显示颅脑CT
//呼吸系统（Pulmonary events） 显示逻辑
function sjxt(e) {
    if ($('input[name="肢体感觉或活动异常"][value="1"],input[name="意识障碍"][value="1"],input[name="昏迷"][value="1"]').length > 0) {
        var dom = $('[name="结果_颅脑CT"]').parents('.pre_tr');
        if ($('input[name="肢体感觉或活动异常"][value="1"]:checked,input[name="意识障碍"][value="1"]:checked,input[name="昏迷"][value="1"]:checked').length > 0) {
            dom.show().prev().show();
        } else {
            $('[name="结果_颅脑CT"]').val('');
            dom.hide().prev().hide();
        }
    }


    var arr = [
        '吸空气下SPO2<90%',
        '咳嗽',
        '咳痰',
        '胸片显示肺部感染',
        '胸片显示肺不张',
        '胸片显示胸膜渗出',
        '血培养阳性',
        '呼吸困难需辅助呼吸'
    ]
    if ($.inArray($(e).attr('name'), arr) != -1) {
        var jDom = $(), jcx = $('textarea[name="检查胸片（Do X-ray）"]').parents('.pre_tr:first'), sflag = false,jcxSf = $('input[name="是否检查胸片？"]:first').parents('.pre_tr:first');
        $.each(arr, function (i) {
            jDom = jDom.add($('input[name="' + arr[i] + '"]')); //获得所有对象
        });
        jDom.each(function () {
            if ($(this).prop('checked') == true && $(this).val() == "1") {
                sflag = true;
            }
        });
        if (sflag) {
            //jcx.show();
            jcxSf.show();
        } else {
            jcx.hide();
            jcxSf.hide();
            $('input[name="是否检查胸片？"]:checked').prop('checked', false).attr('clickflag','0');
        }
    }
}

//恢复评分
function hfpf(e) {
    var pname = $(e).attr('name');
    var arr = [
        '自我感觉状态良好',
        '需要他人帮助（特别是医生和护士）',
        '能听从指导和建议，无意识障碍',
        '能自己找到洗手间和洗漱设施',
        '大小便排便无障碍',
        '呼吸无困难',
        '无头痛、背痛或肌痛',
        '无恶心、干呕或呕吐',
        '无重度疼痛或持续的中度疼痛'
    ]
    if ($.inArray(pname, arr) != -1) {
        var jDom = $(), result = 0, n, jg = $('[name="分数 （Score）"]');
        $.each(arr, function (i) {
            jDom = jDom.add($('input[name="' + arr[i] + '"]')); //获得所有对象
        });
        jDom.each(function () {
            if($(this).prop('checked') == true){
                n=1;
                result += (~~$(this).val());
            }
        });
        if (n == 1) {
            jg.val(result);
        } else {
            jg.val("")
        }
    }
}

//糖尿病 存活情况 显示逻辑
function tnb(e) {
    //if ($('input[value="0"][name="是否存活"]:checked').length > 0) {
    //    $('.pcs_al li').not($('.pcs_al li:first,.pcs_al li:last,.pcs_al li:eq(1)')).hide();
    //} else if ($('input[name="是否存活"]').length > 0) {
    //    $('.pcs_al li').not($('.pcs_al li:first,.pcs_al li:last,.pcs_al li:eq(1)')).show();
    //}
}


