var dtjl = { key: "1", state: 0, list: [] }; //试卷对象，list数据存储为↑面的对象集合,key为试卷ID,count剩余考试次数，time剩余考试时间,state：0正常，1交卷,up是否上传
var qccs = 3; //切出窗口的机会

$(function () {
    GetAskApeendHtml();
    GetUserExamTop();
});

function getqa(questionObj) {
    //获得题目的分数
    //参数questionObj为考题对象
    return 0;
}

$(document).ready(
		function () {
		    csm = GetlocalStorage(dtjl.key);
		    dtjlCss(csm);
		});
function dtjlCss(csm) {
    //    if (csm != null) {
    //        dtjl = csm;
    //        // 将历史答题数据赋值
    //        for (var i = 0; i < dtjl.list.length; i++) {
    //            var xuanxiang = $("input[name='" + dtjl.list[i].id + "'],textarea[name ='" + dtjl.list[i].id + "' ]");
    //            if (xuanxiang.length > 1) { // 选择题
    //                xuanxiang.each(function () {
    //                    // 标注学员的选择
    //                    var type = $(this).attr("type");
    //                    if (type == "checkbox") {
    //                        var da = dtjl.list[i].userAnswer;
    //                        for (var j = 0; j < da.length; j++) {
    //                            if ($(this).val() == da.substr(j, 1)) {
    //                                $(this).prop("checked", 'checked');
    //                            }
    //                        }

    //                    } else {
    //                        if ($(this).val() == dtjl.list[i].userAnswer) {
    //                            $(this).prop("checked", 'checked');
    //                        }
    //                    }
    //                });
    //            } else {// 问答题
    //                xuanxiang.val(dtjl.list[i].userAnswer);
    //            }
    //            if (dtjl.state == 0) {
    //                // 将界面小方块变个颜色
    //                $("." + dtjl.list[i].id).addClass("alert-info");
    //            }

    //        }
    //        $("#ques_answer").text(dtjl.list.length);
    //    }

    // 绑定一些界面工具
    $('.xuanxiang input[type=radio]').on(
			'ifChecked',
			function (event) {
			    try {
			        var dqqh = $(this).parents('.list-group-item').eq(0).next().offset().top - 50; // 当前题目高度
			        if ($(this).val() != "" && $(this).val() != "null") {//逻辑跳转题
			            $("#MainCenter").find("div").hide(); //将其他题目隐藏
			            var val = $(this).val();
			            ParentShow($("#" + val)); //只显示本题


			            dqqh = $("#" + val).offset().top - 50; // 当前题目高度
			        }
			        $('html,body').animate({
			            scrollTop: dqqh + 'px'
			        }, 400);
			    } catch (e) {

			    }

			    jisuanqi_btn($(this).prop("name"));

			});
    $('.xuanxiang input[type=checkbox]').on('ifChecked', function (event) {
        jisuanqi_btn($(this).prop("name"));
    });
    $('.qAndAScore').on('ifChecked', function (event) {
        jisuanqi_btn($(this).prop("name"));
    });
    // 以下部分处理下单选复选框的样式
    $('.xuanxiang input').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
    });
    $('#xyt_btns').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '80%' // optional
    });
    $('.xuanxiang li').click(function () {
        $(this).find("input").iCheck('toggle');
    });
}

//nextT 下一个对象
function xiayiti(obj) {
    // 下一题

    var index = $(".list-group-item").index($(obj).parents());
    if ($(".list-group-item").length == index + 1) {

    }
    var dqqh = $('.list-group-item').eq(index + 1).offset().top - 50; // 当前题目高度
    $('html,body').animate({
        scrollTop: dqqh + 'px'
    }, 400);
}
function gotop() {
    // 到页面最顶层
    $('html,body').animate({
        scrollTop: 0 + 'px'
    }, 400);
}
function gobottom() {
    // 到页面最底层
    $('html,body').animate({
        scrollTop: 10000 + 'px'
    }, 400);
}
var shownum = 0;
function shoucang_zhao() {
    // 查找页面中收藏的内容
    var count = $(".alert-warning").length;
    if (count > 0) {
        try {
            var weizhi = $(".alert-warning").eq(shownum).offset().top;
            $('html,body').animate({
                scrollTop: weizhi + 'px'
            }, 400);
            if (shownum < count - 1) {
                shownum++;
            } else {
                shownum = 0;
            }
        } catch (e) {
            shownum = 0;
            shoucang_zhao();
        }
    } else {
        showTipsMsg("您未标记任何题目，点击标题前的五角星可标注题目！", 2000, 3);
    }
}
function wenda(obj) {
    if ($(obj).val() != "") {
        jisuanqi_btn($(obj).prop("name"));
    }
}

function shoucang(obj) {
    // 点击收藏按钮
    if ($(obj).hasClass("alert-warning")) {
        $(obj).removeClass("alert-warning");
    } else {
        $(obj).addClass("alert-warning");
    }

    $("#shoucang_num").text($(".alert-warning").length);
}

function arrive_timer_format(s) {
    // 时间秒数格式化
    var t = "";
    if (s > -1) {
        min = Math.floor(s / 60) % 60;
        sec = s % 60;
        if (min < 10) {
            t += "0";
        }
        t += min + ":";
        if (sec < 10) {
            t += "0";
        }
        t += sec;
    }
    return t;
}
function kaoshi_end() {
    // 考试结束状态
    // 标注小方块
    for (var i = 0; i < dtjl.list.length; i++) {
        if (dtjl.list[i].userScore == dtjl.list[i].paperScore) {
            $("." + dtjl.list[i].id).addClass("alert-success");
            $("#" + dtjl.list[i].id).find(".alert").addClass("alert-success");
            $("#" + dtjl.list[i].id).find("i").addClass("glyphicon-ok");
        } else {
            $("." + dtjl.list[i].id).addClass("alert-danger");
            $("#" + dtjl.list[i].id).find("i").addClass("glyphicon-remove");
            $("#" + dtjl.list[i].id).find(".alert").addClass("alert-danger");
        }
    }
    $(".alert").show(); // 正确答案与解析

    $("#defen").text(dtjl.score);
    $("#yongshi").text(parseInt(dtjl.time - dtjl.stime));
    $("#chengji").show();
    // 禁用全部选项
    $('input').iCheck('disable');
    $("input,textarea").prop("disabled", "disable");
    $('.xuanxiang li').unbind("click");
    // 显示隐藏数据
    $("#sjsubmit").hide();
    if (dtjl.state == 2) {
        $(".alert").hide();
        $(".shengyue").show();

        $('.qAndAScore').removeAttr("disabled");
        $('.shenyue').hide();
    }
}
function jisuanqi_btn(questionid) {
    // 选择每个题目后自动计算分数的方法
    // 参数questionid为题目ID

    // 将界面小方块变个颜色
    $("." + questionid).addClass("alert-info");
    $("#ques_answer").text($(".question_box .alert-info").length);

    // 取出必要题目属性,进行分数计算
    var questionObj = {};
    questionObj.id = questionid;
    //questionObj.answer = $("#" + questionid).find(".answer").text(); // 正确答案
    //questionObj.paperScore = $("#" + questionid).find(".paperScore").text(); // 本题分数
    //questionObj.noScore = $("#" + questionid).find(".noScore").text(); // 未答倒扣
    //questionObj.wrongScore = $("#" + questionid).find(".wrongScore").text(); // 答题倒扣

    var dom = $("input[name ='" + questionid + "' ]");
    var da = "";
    if (dom.length > 1) {
        $("input[name='" + questionid + "']:checked").each(function () {// 将多选题的答案合并
            da = da + this.value;
        })
    } else {// 问答题类
        da = $("textarea[name ='" + questionid + "']").val();
    }
    questionObj.userAnswer = da; // 得到用户选择的答案
    questionObj.questions_Type = $("#" + questionid).find(".questions_Type")
			.text();
    var qAndAScore = $("#" + questionid + " .qAndAScore").val();
    if (questionObj.questions_Type == 4) {
        questionObj.userScore = qAndAScore
    } else {
        questionObj.userScore = getqa(questionObj); // 计算得分
    }
    // 如果原来就存在了，则删除原来的
    for (var i = 0; i < dtjl.list.length; i++) {
        if (dtjl.list[i].id == questionid) {
            dtjl.list.splice(i, 1);
        }
    }
    dtjl.list.push(questionObj); // 插入新的数据

    SetlocalStorage(dtjl.key, dtjl); // 将答题数据保存
}
function jiaojuan_btn(buttonType) {
    //校验数据
    if (CheckSubmit()) {
        if (IsEdit == "" || IsEdit == null) {
            if (!FillinUser()) {
                $(".ClassAskUser").show();
                return false;
            } else {
                $(".ClassAskUser").hide();
            }
        }
        //获取所有答题选项
        $(".AskVolumeTop").each(function () {//循环所有的题目
            if ($(this).find(".isnull")) {//如果为必填
                switch ($(this).children(".questions_Type").html()) {//判断类型
                    case "1": //单选
                        $(this).find(".iradio_square-blue.checked").each(function (i) {
                            var topId = $(this).find("input:first").prop("id");
                            var topdis = $(this).next().val();
                            var SelectedAnswer = new SelectedAnswerObject(topId, topdis);
                            EditSelectedAnswerObjectArray(SelectedAnswer);
                        });
                        break;
                    case "2": //多选
                        $(this).find(".icheckbox_square-blue.checked").each(function (i) {
                            var topId = $(this).find("input:first").prop("id");
                            var topdis = $(this).next().val();
                            var SelectedAnswer = new SelectedAnswerObject(topId, topdis);
                            EditSelectedAnswerObjectArray(SelectedAnswer);
                        });
                        break;
                    case "3": //问答
                        if ($("#" + $(this).prop("id") + "_Reason").val().length > 0) {
                            var topId = $(this).prop("id")
                            var topdis = $("#" + $(this).prop("id") + "_Reason").val();
                            var SelectedAnswer = new SelectedAnswerObject(topId, topdis);
                            EditSelectedAnswerObjectArray(SelectedAnswer);
                        }
                        break;
                }
            }
        });
        jiaojuan();
    } else {
        return;
    }
}
var IsEdit = QueryString("Details_ID");
function jiaojuan() {//提交试卷
    var askjson = JSON.stringify(SelectedAnswerObjectArray);
    var param = "action=InsertUserAnswer&IsEdit=" + IsEdit + "&key=" + QueryString("key") + "&askobj=" + askjson;
    if (IsEdit != "" && IsEdit != null) {
        param += "&UserName=" + $("#I_UserName").val();
        param += "&UserPhone=" + $("#I_UserPhone").val();
    }

    $("#imgloading").show();
    getAjax("/Training/AskVolume/AskVolume.ashx", param, function (rs) {
        if (rs == "0") {
            showTipsMsg("操作成功", 2000, 4);
        } else {
            showTipsMsg("操作失败", 2000, 5);
        }
        $("#imgloading").hide();
    });
}
//编辑试卷 加载
function GetUserExamTop() {
    if (IsEdit != null && IsEdit != "") {
        var param = "action=GetAskVolumeDetailed&key=" + QueryString("Details_ID");
        getAjax("/Training/AskVolume/AskVolume.ashx", param, function (rs) {
            $("#imgloading").show();
            if (rs == "1") {
                showTipsMsg("加载失败", 2000, 5);
                $("#imgloading").hide();
            } else {
                var json = JSON.parse(rs);
                json = $.parseJSON(json);
                $.each(json, function (i, obj) {
                    if ($("#" + obj.TopicOptionId).is("input")) {
                        $("#" + obj.TopicOptionId).prop("checked", "checked");

                    } else {
                        $("#" + obj.TopicOptionId + "_Reason").val(obj.TopicOptionDis);
                    }
                });
                $("#imgloading").hide();
            }
        });
    }
}
function huigu() {
    // 回顾试卷

    // kaoshi_end();
    //  gobottom();
}

function GetlocalStorage(name) {
    // / <summary>
    // / 获得本地数据
    // / </summary>
    if (window.localStorage) {
        var value = localStorage.getItem(name);
        if (value != null) {
            return JSON.parse(value);
        } else {
            return value;
        }
    } else {
        return "";
    }
}
function SetlocalStorage(name, obj) {
    // / <summary>
    // / 重写本地数据
    // / </summary>
    if (window.localStorage) {
        localStorage.setItem(name, JSON.stringify(obj));
    } else {
        return "";
    }
}
//逻辑题业务效果
function ParentShow(obj) {
    $(obj).show();
    if ($(obj).parent("div").is(":hidden")) {
        $(obj).parent("div").show();
        ParentShow($(obj).parent("div"));
    }
    $(obj).find("div").show();

}
///查询试卷 展示
var AskVolumeObj = ""; //声明试卷对象
function GetAskApeendHtml() {
    if (QueryString("key") != "") {
        getAjax("/Training/AskVolume/AskVolume.ashx", "action=GetAskVolume&&key=" + QueryString("key") + "&&IsEdit="+1, function (rs) {
            if (rs == "2") {
                $("#imgloading").hide();
            } else {
                var json = $.parseJSON(rs);
                AskVolumeObj = json;
                TKS_AskVolumeTopicOptionArray = JSON.parse(json.TKS_AskVolumeTopicOptionArray); //选项
                TKS_AskVolumeTitleArray = JSON.parse(json.TKS_AskVolumeTitleArray); //标题
                AskVolumeTopicArray = JSON.parse(json.AskVolumeTopicArray); //题目
                //  循环标题
                GetAddTKS_AskVolumeTitleHtml(TKS_AskVolumeTitleArray);
                //循环题目
              //  GetAddAskVolumeTopicHtml();
                GetAddAskVolumeStaticTopicHtml();
                $(".Volume_Name").html(json.AskVolume_Name);
                if (!strDateTime(json.AskVolume_Start)) {
                    json.AskVolume_Start = ChangeDateFormat(json.AskVolume_Start);
                    json.AskVolume_End = ChangeDateFormat(json.AskVolume_End);
                }
                $("#Volume_Start").html("问卷时间：" + ChangeDateFormat(json.AskVolume_Start) + " 至 " + ChangeDateFormat(json.AskVolume_End) + "");
                $("#Volume_Dis").html(json.AskVolume_Dis);
                $("#Volume_BtnDis").html(json.AskVolume_BtnDis);
                if (json.AskVolume_Count == null || json.AskVolume_Count == "undefined") {
                    json.AskVolume_Count = 0;
                }
                $("#AskVolume_Count").html("已参与人数：" + json.AskVolume_Count);
                $("#imgloading").hide();
            }


        });
    } else {
        $("#imgloading").hide();
    }
}


//循环考试标题
function GetAddTKS_AskVolumeTitleHtml() {
    TKS_AskVolumeTitleArray = TKS_AskVolumeTitleArray.sort(function (a, b) {
        return a.SortIndex - b.SortIndex;
    });
    $.each(TKS_AskVolumeTitleArray, function (i, obj) {
        if (obj.AskVolumeTitle_Fid == "0") {
            $("#MainCenter").append("<div><h3 id=\"" + obj.AskVolumeTitle_ID + "\" dataindex=\"" + obj.SortIndex + "\" class=\"list-group-item\">" + obj.AskVolumeTitle_Name + "</h3></div>");
            GetAddTKS_AskVolumeTitleHtmlTo(obj.AskVolumeTitle_ID);
        }
    });
}
//递归考试循环标题
function GetAddTKS_AskVolumeTitleHtmlTo(fid) {
    $.each(TKS_AskVolumeTitleArray, function (i, obj) {
        if (obj.AskVolumeTitle_Fid == fid) {
            $("#" + fid).after("<div class=\"childTitleDiv\" ><h3 id=\"" + obj.AskVolumeTitle_ID + "\" dataindex=\"" + obj.SortIndex + "\" class=\"list-group-item child\">" + obj.AskVolumeTitle_Name + "</div></h3>");
            GetAddTKS_AskVolumeTitleHtmlTo(obj.AskVolumeTitle_ID);
        }
    });
}
//循环考试题目
function GetAddAskVolumeTopicHtml() {
    AskVolumeTopicArray = AskVolumeTopicArray.sort(function (a, b) {
        return a.SortIndex - b.SortIndex;
    });
    $.each(AskVolumeTopicArray, function (i, obj) {
        var str = ""; //html
        var isnull = ""; //是否允许为空
        var JumpID = "";
        if (parseInt(obj.AskVolumeTopic_IsNull) == 0) {
            isnull = "<span class=\"isnull\" >*</span>";
        }

        switch (parseInt(obj.AskVolumeTopic_Type)) {
            case 1: //问答题
                str = "<div class=\"list-group-item AskVolumeTop\" dataindex=\"" + obj.SortIndex + "\" id=\"" + obj.AskVolumeTopic_ID + "\"><span class=\"sc_btn\" onclick=\"shoucang(this)\" title=\"标记\"><span class=\"glyphicon glyphicon-star\"aria-hidden=\"true\"></span></span>" + isnull + obj.AskVolumeTopic_Name + "<span class=\"questions_Type hide\">3</span><br><textarea class=\"form-control\" rows=\"5\" id=\"" + obj.AskVolumeTopic_ID + "_Reason\" name=\"" + obj.AskVolumeTopic_ID + "\" style=\"width: 100%; margin: 10px 0;\"onblur=\"wenda(this)\"></textarea><button type=\"button\" class=\"btn btn-default\" onclick=\"xiayiti(this)\" style=\"width: 100%;\">下一题</button></div>";
                break;
            case 2: //单选题
                str = "<div class=\"list-group-item AskVolumeTop\" dataindex=\"" + obj.SortIndex + "\" id=\"" + obj.AskVolumeTopic_ID + "\"><span class=\"sc_btn\" onclick=\"shoucang(this)\" title=\"标记\"><span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span></span>" + isnull + obj.AskVolumeTopic_Name + "<span class=\"questions_Type hide\">1</span> <br><ol type=\"A\" class=\"xuanxiang\">";
                $.each(TKS_AskVolumeTopicOptionArray, function (k, option) {
                    if (option.VolumeTopic == obj.AskVolumeTopic_ID) {
                        str += "<li><input type=\"radio\" value=\"" + option.TopicOption_JumpTopic_ID + "\"  name=\"" + obj.AskVolumeTopic_ID + "\"  id=\"" + option.TopicOption_ID + "\">" + option.TopicOption_Name + "<input type=\"text\" id=\"" + option.TopicOption_ID + "_Reason\" value=\"\" class=\"form-control\" placeholder=\"请输入选择理由\" /></li>"
                    }
                });
                str += "</ol></div>";
                break;
            case 3: //多选题
                str = "<div class=\"list-group-item AskVolumeTop\" dataindex=\"" + obj.SortIndex + "\" id=\"" + obj.AskVolumeTopic_ID + "\"><span class=\"sc_btn\" onclick=\"shoucang(this)\" title=\"标记\"><span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span></span>" + isnull + obj.AskVolumeTopic_Name + "<span class=\"questions_Type hide\">2</span><br> <ol type=\"A\" class=\"xuanxiang\">";
                $.each(TKS_AskVolumeTopicOptionArray, function (k, option) {
                    if (option.VolumeTopic == obj.AskVolumeTopic_ID) {
                        str += "<li><input type=\"checkbox\"  name=\"" + obj.AskVolumeTopic_ID + "\" id=\"" + option.TopicOption_ID + "\" >" + option.TopicOption_Name + "<input type=\"text\" value=\"\" id=\"" + option.TopicOption_ID + "_Reason\" class=\"form-control\" placeholder=\"请输入选择理由\" /></li>";
                    }
                });
                str += "</ol><button type=\"button\" class=\"btn btn-default\" onclick=\"xiayiti(this)\" style=\"width: 100%;\">下一题</button></div>";
                break;
        }
        if (obj.AskVolumeTopic_Fid == "0") {
            var isnull = true;
            $("#MainCenter").children().each(function (k, center) {//初始化为空时将不进入循环。那么就无法比对
                var dataindex = parseInt($(center).attr("dataindex"));
                if (parseInt(obj.SortIndex) - 1 == dataindex) {//找到自己相关顺序的
                    isnull = false;
                    $(center).after(str);
                }
            });
            if (isnull) {
                $("#MainCenter").append(str);
            }
        } else {
            var isnull = true;
            $("#" + obj.AskVolumeTopic_Fid).children().each(function (k, center) {//初始化为空时将不进入循环。那么就无法比对
                var dataindex = parseInt($(center).attr("dataindex"));
                if (parseInt(obj.SortIndex) - 1 == dataindex) {//找到自己相关顺序的
                    isnull = false;
                    $(center).after(str);
                }
            });
            if (isnull) {
                $("#" + obj.AskVolumeTopic_Fid).after(str);
            }
        }

        clickTopHtml(obj);
    });
}
//输出题目索引
var index = 0;
function clickTopHtml(obj) {
    index++;
    $(".question_box").append(" <a class=\"" + obj.AskVolumeTopic_ID + "\" href=\"#" + obj.AskVolumeTopic_ID + "\">" + index + "</a>");
}
//验证
function CheckSubmit() {
    //获取所有题目集合
    var isok = true;
    $(".AskVolumeTop").each(function () {//循环所有的题目
        var isnull = false;
        if ($(this).find(".isnull")) {//如果为必填
            switch ($(this).children(".questions_Type").html()) {//判断类型
                case "1": //单选
                    $(this).find(".iradio_square-blue.checked").each(function (i) {
                        if (i >= 0) {
                            isnull = true;
                        }
                    });
                    break;
                case "2": //多选
                    $(this).find(".icheckbox_square-blue.checked").each(function (i) {
                        if (i >= 0) {
                            isnull = true;
                        }
                    });
                    break;
                case "3": //问答
                    if ($("#" + $(this).prop("id") + "_Reason").val().length > 0) {
                        isnull = true;
                    }
                    break;
            }
            if (!isnull) {//如果验证未通过，判断是否隐藏 属于隐藏的，为逻辑跳转题，可不验证
                if ($(this).is(":hidden")) {
                    isnull = true;
                }
            }
        } else {
            isnull = true;
        }
        $(this).css("border", "");

        if (!isnull) {
            $(this).css("border", "1px solid red");
            var dqqh = $(this).offset().top - 50; // 当前题目高度
            $('html,body').animate({
                scrollTop: dqqh + 'px'
            }, 400);
        }
        isok = isnull;
        return isnull;
    });
    return isok;
}
//验证问卷密码
function CheckAskPwd() {
    var pass = $("#AskPassword").val();
    if (pass == AskVolumeObj.AskVolume_Pwd) {
        $(".ClassAskPwd").hide();
        $("#containerCenter").show();
    } else {
        showTipsMsg("密码错误", 2000, 5);
    }
}
//关闭窗口
function closeWindow() {
    var browserName = navigator.appName;
    if (browserName == "Netscape") {
        var opened = window.open('about:blank', '_self');
        opened.close();
    }
    else {
        if (browserName == "Microsoft Internet Explorer") {
            window.open('', '_parent', '');
            window.close();
        }
    }
}
//验证用户
function FillinUser() {

    var UserName = $("#I_UserName").val();
    var UserPhone = $("#I_UserPhone").val();
    var regphone = /^0?1[3|4|5|8][0-9]\d{8}$/;
    if (UserName.length <= 0) {
        showTipsMsg("请输入用户名", 2000, 5);
        return false;
    }
    var isok = regphone.test(UserPhone);
    if (!isok) {
        showTipsMsg("请输入正确的联系方式", 2000, 5);
        return false;
    }

    return true;
}

//查询统计数据
function GetAskStatic() {
    $("#imgloading").show();
    getAjax("/Training/AskVolume/AskVolume.ashx", "action=GetAskStatic&&key=" + QueryString("key"), function (rs) {
        if (rs != "1") {
            var json = $.parseJSON(rs);
            GetAddAskVolumeStaticTopicHtml();
        } else {
            $("#imgloading").hide();
        }
    });
}
//根据题目id 查询数据统计内容
function GetAskOptionStatic(optionid,ExamType) {
    getAjax("/Training/AskVolume/AskVolume.ashx", "action=GetAskOptionStatic&&optionid=" + optionid + "&&ExamType=" + ExamType + "&&key=" + QueryString("key"), function (rs) {
        if (rs != "1") {
            var json = $.parseJSON(rs);
            if (ExamType == 1) {//问卷
                $.each(json, function (i,obj) {
                    $("#" + optionid).find("ol").after("<li>" + option.TopicOption_Name +"</li>");
                });
            }
        } else {
            $("#imgloading").hide();
        }
    });
}
//循环统计数据题目
function GetAddAskVolumeStaticTopicHtml() {
    AskVolumeTopicArray = AskVolumeTopicArray.sort(function (a, b) {
        return b.SortIndex - a.SortIndex;
    });
    $.each(AskVolumeTopicArray, function (i, obj) {
        var str = ""; //html
        var isnull = ""; //是否允许为空
        var JumpID = "";
        switch (parseInt(obj.AskVolumeTopic_Type)) {
            case 1: //问答题
                str = "<div class=\"list-group-item AskVolumeTop\" dataindex=\"" + obj.SortIndex + "\" id=\"" + obj.AskVolumeTopic_ID + "\"><span class=\"sc_btn\" onclick=\"shoucang(this)\" title=\"标记\"><span class=\"glyphicon glyphicon-star\"aria-hidden=\"true\"></span></span>" + obj.AskVolumeTopic_Name + "<span class=\"questions_Type hide\">3</span><br><ol type=\"C\" class=\"xuanxiang\"><br></ol></div>";
                GetAskOptionStatic(obj.AskVolumeTopic_ID,1);
                break;
            case 2: //单选题
                str = "<div class=\"list-group-item AskVolumeTop\" dataindex=\"" + obj.SortIndex + "\" id=\"" + obj.AskVolumeTopic_ID + "\"><span class=\"sc_btn\" onclick=\"shoucang(this)\" title=\"标记\"><span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span></span>" + obj.AskVolumeTopic_Name + "<span class=\"questions_Type hide\">1</span> <br><ol type=\"A\" class=\"xuanxiang\"><br>";
                $.each(TKS_AskVolumeTopicOptionArray, function (k, option) {
                    if (option.VolumeTopic == obj.AskVolumeTopic_ID) {
                        str += "<li>" + option.TopicOption_Name + "<div class=\"progress\"><div class=\"progress-bar progress-bar-warning progress-bar-striped\" role=\"progressbar\"aria-valuenow=\"60\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: " + Calculation(option.TopicOption_Count, AskVolumeObj.AskVolume_Count) + "%\">" + option.TopicOption_Count + " / " + AskVolumeObj.AskVolume_Count + "</div></div></li>";
                    }
                });
                str += "</ol></div>";
                break;
            case 3: //多选题
                str = "<div class=\"list-group-item AskVolumeTop\" dataindex=\"" + obj.SortIndex + "\" id=\"" + obj.AskVolumeTopic_ID + "\"><span class=\"sc_btn\" onclick=\"shoucang(this)\" title=\"标记\"><span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span></span>" + obj.AskVolumeTopic_Name + "<span class=\"questions_Type hide\">2</span><br> <ol type=\"A\" class=\"xuanxiang\">";
                $.each(TKS_AskVolumeTopicOptionArray, function (k, option) {
                    if (option.VolumeTopic == obj.AskVolumeTopic_ID) {
                        str += "<li>" + option.TopicOption_Name + "<div class=\"progress\"><div class=\"progress-bar progress-bar-warning progress-bar-striped\" role=\"progressbar\"aria-valuenow=\"60\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: " + Calculation(option.TopicOption_Count, AskVolumeObj.AskVolume_Count) + "%\">" + option.TopicOption_Count + " / " + AskVolumeObj.AskVolume_Count + "</div></div></li>";
                    }
                });
                str += "</ol></div>";
                break;
        }
        if (obj.AskVolumeTopic_Fid == "0") {
            var isnull = true;
            $("#MainCenter").children().each(function (k, center) {//初始化为空时将不进入循环。那么就无法比对
                var dataindex = parseInt($(center).attr("dataindex"));
                if (parseInt(obj.SortIndex) - 1 == dataindex) {//找到自己相关顺序的
                    isnull = false;
                    $(center).after(str);
                }
            });
            if (isnull) {
                $("#MainCenter").append(str);
            }
        } else {
            var isnull = true;
            $("#" + obj.AskVolumeTopic_Fid).children().each(function (k, center) {//初始化为空时将不进入循环。那么就无法比对
                var dataindex = parseInt($(center).attr("dataindex"));
                if (parseInt(obj.SortIndex) - 1 == dataindex) {//找到自己相关顺序的
                    isnull = false;
                    $(center).after(str);
                }
            });
            if (isnull) {
                $("#" + obj.AskVolumeTopic_Fid).after(str);
            }
        }
        clickTopHtml(obj);
    });
}

//计算统计比率
function Calculation(Optioncount, AskCount) {
    var avg = Optioncount / AskCount*100;
    return avg;
}

                 