var request = getRequest(),
    prescriptionCode = request.prescriptionCode,
    fv_id = request.fv_id,
    type = request.type,
    state = request.state, //问卷状态
    project_id = request.projectId;

var project_data = {};

$(function(){
    if(state == 2){ //未填写
        $("#fvBtn").hide();
    }else{
        $("#fvBtn").show();
    }
    //获得模板中的数据显示
    var arr = project_id.split(",");
    for(i=0; i<arr.length; i++){
        $.extend(true, project_data, gTemplate[arr[i]]);
    }
    
    getDetail();
    bindEvents();
});

function getDetail(){
    var params = {
        prescriptioncode: prescriptionCode,
        followupProject: project_id
    };
    
    consultingAPI.getSurveyInfo(params).then(function(res){
        if(res.status == 200){
            for(key in project_data){
                project_data[key].value = res.data?res.data[key]:'';
            }
            var html = template("item", {
                data:project_data
            });
            
            $("#question_form .form-info").append(html);
            initChosen();
        }else{
            showErrorMsg(res.msg);
        }
    })
}

function initChosen(){
    $(".my_select_box").chosen({
        disable_search: true,
        inherit_select_classes: true, //将设定的样式添加到插件的控件中
        disable_search_threshold: 10,
        no_results_text: "",
        width: "100%"
    });
}

function bindEvents(){
    $("#backBtn").on('click', function(){
        history.go(-1);
    });
    
    $("#fvBtn").on('click', function(){
        var params = {
            followupid: fv_id,
            prescriptioncode: prescriptionCode,
            type: type
        };
        consultingAPI.importfollowupcontent(params).then(function(res){
            if(res.status == 200){
                showSuccessMsg("填入随访记录成功");
                setTimeout(function(){
                    history.go(-1);
                }, 500);
                
            }else{
                showErrorMsg(res.msg);
            }
        });
    })
}
