/**
 * 显示审核日志
 */
TalentInfo.showLog = function (id){
    layer.open({
        type: 1,
        title:"日志",
        fixed:false,
        content: '<table id="'+id+'"></table>',
        area: ['80%', '80%'],
        maxmin: true,
        success :function (layero, index) {
            Feng.getCheckLog(id,{"type":CONFIG.project_rcrd,"mainId":id,"typeFileId":"","active":1})
        }
    });
}


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
TalentInfo.formParams = function() {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['sex'] = $("#sex").val();
    queryData['nation'] = $("#nation").val();
    queryData['nationality'] = $("#nationality").val();
    queryData['provinceCode'] = $("#provinceCode").val();
    queryData['politics'] = $("#politics").val();
    queryData['enterpriseId'] = $("#enterpriseId").val();
    queryData['industryField'] = $("#industryField").val();
    queryData['source'] = $("#source").val();
    queryData['fromCity'] = $("#fromCity").val();
    queryData['introductionMode'] = $("#introductionMode").val();
    queryData['highEducation'] = $("#highEducation").val();
    queryData['major'] = $("#major").val();
    queryData['title'] = $("#title").val();
    queryData['studyAbroad'] = $("#studyAbroad").val();
    queryData['phone'] = $("#phone").val();
    queryData['email'] = $("#email").val();
    queryData['breakFaith'] = $("#breakFaith").val();
    queryData['talentType'] = $("#talentType").val();
    queryData['talentArrange'] = $("#talentArrange").val();
    queryData['address'] = $("#address").val();
    if($("#identifyCondition").val() == null || $("#identifyCondition").val() == '' || $("#identifyCondition").val()=="null"){
        queryData['identifyCondition'] = "";
    }else{
        queryData['identifyCondition'] = $("#identifyCondition").val();
    }
    queryData['identifyMonth'] = $("#identifyMonth").val();
    queryData['checkState'] = $("#checkState").val();
    queryData['isPublic'] = $("#isPublic").val();
    queryData['active'] = $("#active").val()
    queryData['year'] = $("#year").val();
    queryData['isEffect'] = $("#isEffect").val();
    return queryData;
}

/**
 * 查询人才认定申报列表
 */
TalentInfo.search = function () {
    TalentInfo.table.refresh({query: TalentInfo.formParams()});
};

/**
 * 重置
 */
TalentInfo.reset = function (){
    $("#name").val("");
    $("#idCard").val("");
    $("#sex").val("");
    $("#nation").val("");
    $("#nationality").val("");
    $("#provinceCode").val("");
    $("#politics").val("");
    $("#enterpriseId").val("").trigger("chosen:updated");
    $("#industryField").val("");
    $("#source").val("");
    $("#fromCity").val("");
    $("#introductionMode").val("");
    $("#highEducation").val("");
    $("#major").val("");
    $("#title").val("");
    $("#studyAbroad").val("");
    $("#phone").val("");
    $("#email").val("");
    $("#breakFaith").val("");
    $("#talentType").val("");
    $("#talentArrange").val("");
    $("#address").val("");
    $("#identifyCondition").val("").trigger("chosen:updated");;
    $("#checkState").val("");
    $("#identifyMonth").val("");
    $("#isPublic").val("");
    $("#active").val("")
    $("#year").val("");
    $("#isEffect").val("");
}



/**
 * 获取人才认定
 */
TalentInfo.getIdentifyCondition = function() {
    // var level = $("#talentArrange").val();
    // if(level==null||level==''){
    //     $("#identifyCondition").empty();
    //     $("#identifyCondition").trigger('chosen:updated');
    //     return;
    // }
    Feng.addAjaxSelect({
        "id": "identifyCondition",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/common/api/findIdentifyConditionByLevel"
    });
    $("#identifyCondition").trigger('chosen:updated');
}

/**
 * 显示导出模态框
 */
TalentInfo.showExportModal = function(){
    $("#exportForm")[0].reset();
    $("#commonExportModal").modal("show");
}

/**
 * 导出提交
 */
TalentInfo.export = function(process){
    var names = '';
    var values = '';
    $("#field_info li input").each(function(index){
        if($(this).is(":checked")){
            values = values + $(this).val() + ",";
            names = names + $(this).next().text() + ",";
        }
    });
    var queryData = TalentInfo.formParams();
    $("#commonExportModal").modal('hide');
    var url = Feng.ctxPath + "/talentInfoExport/commonExport?names="+names+"&values="+values +
                    "&name=" + queryData.name +
                    "&idCard=" + queryData.idCard +
                    "&sex=" + queryData.sex +
                    "&nation=" + queryData.nation +
                    "&nationality=" + queryData.nationality +
                    "&provinceCode=" + queryData.provinceCode +
                    "&politics=" + queryData.politics +
                    "&enterpriseId=" + queryData.enterpriseId +
                    "&industryField=" + queryData.industryField +
                    "&source=" + queryData.source +
                    "&fromCity=" + queryData.fromCity +
                    "&introductionMode=" + queryData.introductionMode +
                    "&highEducation=" + queryData.highEducation +
                    "&major=" + queryData.major +
                    "&title=" + queryData.title +
                    "&studyAbroad=" + queryData.studyAbroad +
                    "&phone=" + queryData.phone +
                    "&email=" + queryData.email +
                    "&talentType=" + queryData.talentType +
                    "&talentArrange=" + queryData.talentArrange +
                    "&identifyCondition=" + queryData.identifyCondition +
                    "&identifyMonth="+queryData.identifyMonth+
                    "&address=" + queryData.address +
                    "&checkState=" + queryData.checkState +
                    "&breakFaith=" + queryData.breakFaith +
                    "&isPublic=" + queryData.isPublic +
                    "&active=" + queryData.active +
                    "&year="+queryData.year +
                    "&isEffect="+queryData.isEffect+
                    "&process=" + process;
    window.location.href = encodeURI(encodeURI(url));
}

/**
 * 页面初始化
 */
TalentInfo.init = function(){
    //批量加载字典表数据
    var arr = [
        {"name":"nation","code":"nation"},
        {"name":"nationality","code":"nationality"},
        {"name":"politics","code":"politics"},
        {"name":"industryField","code":"industry_field"},
        {"name":"introductionMode","code":"introduction_model"},
        {"name":"highEducation","code":"highest_degree"},
        {"name":"talentType","code":"talent_type"},
        {"name":"talentArrange","code":"talent_arrange"},
        {"name":"source","code":"source"},
        {"name":"address","code":"street"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
    TalentInfo.getIdentifyCondition();
    $("#identifyCondition,#enterpriseId").on('chosen:ready', function(e, params) {
        $(".chosen-container-single .chosen-single").css("padding","4px 0px 0px 4px");
    });
    $("#identifyCondition,#enterpriseId").chosen({
        search_contains:true,       //关键字模糊搜索。设置为true，只要选项包含搜索词就会显示；设置为false，则要求从选项开头开始匹配
        disable_search: false,
        width:"100%",
        enable_split_word_search: true
    });
}

/**
 * 下载附件
 */
TalentInfo.download = function(){
    if (this.check()) {
        window.location.href = encodeURI(encodeURI(Feng.ctxPath + "/common/api/downloadZip?type=1&id="+TalentInfo.seItem.id));
    }
}

/**
 * 批量下载头像
 */
TalentInfo.downloadPhoto = function (){
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }
    var ids = "";
    for (let i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    window.location.href = encodeURI(encodeURI(Feng.ctxPath + "/api/commonDownload/downloadPhotos?type=1&ids="+ids));
}

/**
 * 全选
 */
TalentInfo.checkAll = function(){
    $("#field_info input").each(function () {
        this.checked = true;
    })
}
/**
 * 反选
 */
TalentInfo.unCheckAll = function(){
    $("#field_info input").each(function () {
        if(this.checked){
            this.checked = false;
        }else{
            this.checked = true;
        }
    })
}

