/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
TalentTypeChange.formParams = function() {
    var queryData = {};
    queryData['talentName'] = $("#talentName").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['enterpriseName'] = $("#enterpriseName").val();
    queryData['oldTalentArrange'] = $("#oldTalentArrange").val();
    queryData['newTalentArrange'] = $("#newTalentArrange").val();
    queryData['checkState'] = $("#checkState").val();
    queryData['oldIdentifyCondition'] = $("#oldIdentifyCondition").val();
    queryData['newIdentifyCondition'] = $("#newIdentifyCondition").val();
    queryData['oldIdentifyMonth'] = $("#oldIdentifyMonth").val();
    queryData['newIdentifyMonth'] = $("#newIdentifyMonth").val();
    if($("#oldIdentifyCondition").val() == null || $("#oldIdentifyCondition").val() == '' || $("#oldIdentifyCondition").val()=="null"){
        queryData['oldIdentifyCondition'] = "";
    }else{
        queryData['oldIdentifyCondition'] = $("#oldIdentifyCondition").val();
    }
    if($("#newIdentifyCondition").val() == null || $("#newIdentifyCondition").val() == '' || $("#newIdentifyCondition").val()=="null"){
        queryData['newIdentifyCondition'] = "";
    }else{
        queryData['newIdentifyCondition'] = $("#newIdentifyCondition").val();
    }
    queryData['isPublic'] = $("#isPublic").val();
    queryData['oldYear'] = $("#oldYear").val();
    queryData['newYear'] = $("#newYear").val();
    return queryData;
}

/**
 * 重置
 */
TalentTypeChange.reset = function (){
    $("#talentName").val("");
    $("#idCard").val("");
    $("#enterpriseName").val("");
    $("#oldTalentArrange").val("").trigger("change");
    $("#newTalentArrange").val("").trigger("change");
    $("#checkState").val("");
    $("#oldIdentifyCondition").val("").trigger("chosen:updated");;
    $("#newIdentifyCondition").val("").trigger("chosen:updated");;
    $("#oldIdentifyMonth").val("");
    $("#newIdentifyMonth").val("");
    $("#isPublic").val("");
    $("#oldYear").val("");
    $("#newYear").val("");
}

/**
 * 查询人才类别变更列表
 */
TalentTypeChange.search = function () {
    TalentTypeChange.table.refresh({query: TalentTypeChange.formParams()});
};

/**
 * 显示审核日志
 */
TalentTypeChange.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_levelchange,"mainId":id,"typeFileId":"","active":1})
        }
    });
}

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

/**
 * 页面初始化
 */
TalentTypeChange.init = function(){
    //批量加载字典表数据
    var arr = [
        {"name":"oldTalentArrange","code":"un_talentLevel"},
        {"name":"newTalentArrange","code":"un_talentLevel"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
    TalentTypeChange.getIdentifyCondition();
    $("#oldIdentifyCondition,#newIdentifyCondition").on('chosen:ready', function(e, params) {
        $(".chosen-container-single .chosen-single").css("padding","4px 0px 0px 4px");
    });
    $("#oldIdentifyCondition,#newIdentifyCondition").chosen({
        search_contains:true,       //关键字模糊搜索。设置为true，只要选项包含搜索词就会显示；设置为false，则要求从选项开头开始匹配
        disable_search: false,
        width:"100%",
        enable_split_word_search: true
    });
    //批量加载时间控件
    $(".time").each(function(){
        laydate.render({
            elem: "#"+$(this).attr("id")
            ,type: "date"
            ,trigger: 'click'
        });
    });
}

/**
 * 导出提交
 */
TalentTypeChange.export = function(process){
    var queryData = TalentTypeChange.formParams();
    var url = Feng.ctxPath + "/talentTypeChangeExport/commonExport?"+
        "&talentName=" + queryData.talentName +
        "&idCard=" + queryData.idCard +
        "&enterpriseName=" + queryData.enterpriseName +
        "&oldTalentType=" + queryData.oldTalentType +
        "&oldTalentArrange=" + queryData.oldTalentArrange +
        "&newTalentType=" + queryData.newTalentType +
        "&newTalentArrange=" + queryData.newTalentArrange +
        "&oldIdentifyCondition=" + queryData.oldIdentifyCondition +
        "&newIdentifyCondition=" + queryData.newIdentifyCondition +
        "&oldIdentifyMonth=" + queryData.oldIdentifyMonth +
        "&newIdentifyMonth=" + queryData.newIdentifyMonth +
        "&checkState=" + queryData.checkState +
        "&isPublic=" + queryData.isPublic+
        "&oldYear="+queryData.oldYear+
        "&newYear="+queryData.newYear+
        "&process=" + process;
    window.location.href = encodeURI(encodeURI(url));
}

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