/**
 * 初始化人才认定申报详情对话框
 */
var TalentAllowanceInfoDlg = {
    talentAllowanceData: {}
};

/**
 * 关闭此对话框
 */
TalentAllowanceInfoDlg.close = function () {
    parent.layer.close(window.parent.TalentAllowanceInfo.layerIndex);
}

/**
 * 初始化工作单位及核查项目情况表
 */
TalentAllowanceInfoDlg.initContract = function () {
    $("#projectTable").bootstrapTable({
        url: Feng.ctxPath + "/enterprise/talentAllowance/findAllowanceContractDetail",
        method: 'POST',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
        showRefresh: false, // 是否显示刷新按钮
        clickToSelect: true, // 是否启用点击选中行
        singleSelect: true, // 设置True 将禁止多选
        striped: true, // 是否显示行间隔色
        escape: true,
        pagination: false, // 设置为 true 会在表格底部显示分页条
        paginationHAlign: "left",
        paginationDetailHAlign: "right",
        sidePagination: "server", // 设置在哪里进行分页，可选值为 'client' 或者 'server'
        showColumns: false,
        detailView: true, //父子表
        queryParams: function (params) {
            return $.extend({"mainId": $("#id").val()}, params)
        },
        columns: TalentAllowanceInfoDlg.initContractColumns(),
        onPostBody: function () {
            $("td.uitd_showTip").bind("mouseover", function () {
                var htm = $(this).html();
                $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
            });
        },
        onLoadSuccess: function (data) {
            $("#projectTable").bootstrapTable('expandAllRows');
        },
        onExpandRow: function (index, row, $detail) {
            var enterpriseId = row.enterpriseId + index;
            var cur_table = $detail.html('<table id="' + enterpriseId + '"></table>').find('table');
            $(cur_table).bootstrapTable({
                url: Feng.ctxPath + "/enterprise/talentAllowance/findAllowanceProject",
                method: 'POST',
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
                showRefresh: false, // 是否显示刷新按钮
                clickToSelect: true, // 是否启用点击选中行
                singleSelect: true, // 设置True 将禁止多选
                striped: true, // 是否显示行间隔色
                escape: true,
                pagination: false, // 设置为 true 会在表格底部显示分页条
                paginationHAlign: "left",
                paginationDetailHAlign: "right",
                sidePagination: "server", // 设置在哪里进行分页，可选值为 'client' 或者 'server'
                showColumns: false,
                queryParams: function (params) {
                    var companyCode = "";
                    if ($("#process").val() == 1) {
                        companyCode = $("#companyCode").val();
                    }
                    return $.extend({"mainId": $("#id").val(), "baseId": row.id, "companyCode": companyCode}, params)
                },
                onPostBody: function () {
                    $("td.uitd_showTip").bind("mouseover", function () {
                        var htm = $(this).html();
                        $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
                    });
                },
                onLoadSuccess: function (data) {
                    $(".imgs").viewer({
                        // toolbar:false,
                        fullscreen: false
                    });
                },
                columns: TalentAllowanceInfoDlg.initProjectColumns(enterpriseId),
            });
        }
    });
    TalentAllowanceInfoDlg.initArrange();
}

/**
 * 初始化人才层次
 */
TalentAllowanceInfoDlg.initArrange = function () {
    $("#arrangeTable").bootstrapTable({
        url: Feng.ctxPath + "/enterprise/talentAllowance/findAllowanceArrange",
        method: 'POST',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
        showRefresh: false, // 是否显示刷新按钮
        clickToSelect: true, // 是否启用点击选中行
        singleSelect: true, // 设置True 将禁止多选
        striped: true, // 是否显示行间隔色
        escape: true,
        pagination: false, // 设置为 true 会在表格底部显示分页条
        paginationHAlign: "left",
        paginationDetailHAlign: "right",
        sidePagination: "server", // 设置在哪里进行分页，可选值为 'client' 或者 'server'
        showColumns: false,
        pageList: [10, 30, 50],
        queryParams: function (params) {
            return $.extend({"mainId": $("#id").val()}, params)
        },
        columns: TalentAllowanceInfoDlg.initArrangeColumn(),
        onPostBody: function () {
            $("td.uitd_showTip").bind("mouseover", function () {
                var htm = $(this).html();
                $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
            });
        }
    });
}

//显示修改工作单位合同情况模态框
TalentAllowanceInfoDlg.showEditContractModel = function (id) {
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            $("#contractForm")[0].reset();
            $("#contractId").val(id);
            $(".date").each(function () {
                laydate.render({elem: "#" + $(this).attr("id"), type: 'date', trigger: 'click'});
            });
            $("#contractModal").modal("show");
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", id);
    ajax.set("type", 1);
    ajax.set("process", $("#process").val())
    ajax.set("companyId", $("#companyId").val())
    ajax.start();
}

//修改合同起止时间提交
TalentAllowanceInfoDlg.editContract = function () {
    var id = $("#contractId").val();
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    if (startTime == null || startTime == '') {
        Feng.info("请选择合同起始时间");
        return;
    }
    if (endTime == null || endTime == '') {
        Feng.info("请选择合同截止时间");
        return;
    }
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/editContract", function (data) {
        if (data.code == 200) {
            Feng.success(data.msg);
            $("#projectTable").bootstrapTable("refresh", {});
            $("#contractModal").modal("hide");
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("提交失败!" + data.responseJSON.message + "!");
    });
    ajax.set({"id": id, "startTime": startTime, "endTime": endTime, "process": $("#process").val()});
    ajax.start();
}
//显示编辑项目模态框
TalentAllowanceInfoDlg.showEditProjectModal = function (project, id, enterpriseId, months, days, content) {
    var desc = $(content).attr("data-value");
    var type = $("#type").val();
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            $("#description").val(desc);
            TalentAllowanceInfoDlg.initICheck();
            switch (project) {
                case "1":
                    $("#contractCheckForm")[0].reset();
                    $("#contractCheckId").val(id);
                    $("#contractEnterpriseId").val(enterpriseId);
                    $("#contractCheckModal").modal("show");
                    break;
                case "4":
                    if (type == 1) {
                        $('#jjAttendanceModal').on('show.bs.modal', function () {
                            $("#jjAttendanceForm")[0].reset();
                            $("#jjmonths input").each(function () {
                                $(this).iCheck("uncheck");
                            });
                            $("#jjAttendanceId").val(id);
                            $("#jjAttendanceEnterpriseId").val(enterpriseId);
                            if (Feng.isNotEmptyStr(months)) {
                                if (months.indexOf(",") != -1) {
                                    var arr = months.split(",");
                                    for (var key in arr) {
                                        $("#jjmonths input").each(function () {
                                            if ($(this).val() == arr[key])
                                                $(this).iCheck("check");
                                        });
                                    }
                                }
                            }
                        });
                        if (days != null && days != '')
                            $("#days").val(days);
                        $("#jjAttendanceModal").modal("show");
                    } else {
                        $("#attendanceModalLabel").html("考勤");
                        $("#heading").html("请填写每月考勤天数<span style=\"color: red\">(不填写或填写0则代表无考勤记录)</span>");
                        $("#attendanceForm")[0].reset();
                        $("#attendanceId").val(id);
                        $("#attendanceEnterpriseId").val(enterpriseId);
                        if (months != null && months != '') {
                            var arr = months.split(",");
                            for (var key in arr) {
                                var num = arr[key].split("=")[0];
                                var day = arr[key].split("=")[1];
                                $("#attendMonths input").each(function () {
                                    if ($(this).attr('num') == num)
                                        $(this).val(day);
                                });
                            }
                        }
                        $("#attendanceModal").modal("show");
                    }
                    break;
                case "15":
                    $("#attendanceModalLabel").html("在境时间");
                    $("#heading").html("请填写每月在境内天数<span style=\"color: red\">(不填写则代表为0天)</span>");
                    $("#attendanceForm")[0].reset();
                    $("#attendanceId").val(id);
                    $("#attendanceEnterpriseId").val(enterpriseId);
                    if (months != null && months != '') {
                        var arr = months.split(",");
                        for (var key in arr) {
                            var num = arr[key].split("=")[0];
                            var day = arr[key].split("=")[1];
                            $("#attendMonths input").each(function () {
                                if ($(this).attr('num') == num)
                                    $(this).val(day);
                            });
                        }
                    }
                    $("#attendanceModal").modal("show");
                    break;
                case "16":
                    $("#attendanceModalLabel").html("境内工作日时间");
                    $("#heading").html("请填写每月境内工作日天数<span style=\"color: red\">(不填写则代表为0天)</span>");
                    $("#attendanceForm")[0].reset();
                    $("#attendanceId").val(id);
                    $("#attendanceEnterpriseId").val(enterpriseId);
                    if (months != null && months != '') {
                        var arr = months.split(",");
                        for (var key in arr) {
                            var num = arr[key].split("=")[0];
                            var day = arr[key].split("=")[1];
                            $("#attendMonths input").each(function () {
                                if ($(this).attr('num') == num)
                                    $(this).val(day);
                            });
                        }
                    }
                    $("#attendanceModal").modal("show");
                    break;
                default:
                    $('#projectModal').on('show.bs.modal', function () {
                        $("#months input").each(function () {
                            $(this).iCheck("uncheck");
                        });
                        $("#projectId").val(id);
                        $("#enterpriseId").val(enterpriseId);
                        TalentAllowanceInfoDlg.initICheck();
                        if (Feng.isNotEmptyStr(months)) {
                            var arr = months.split(",");
                            for (var key in arr) {
                                $("#months input").each(function () {
                                    if ($(this).val() == arr[key])
                                        $(this).iCheck("check");
                                });
                            }
                        }
                    });
                    $("#projectModal").modal("show");
                    break;
            }
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", id);
    ajax.set("type", 2);
    ajax.set("process", $("#process").val())
    ajax.set("companyId", $("#companyId").val())
    ajax.start();
}
//审核合同满两年提交
TalentAllowanceInfoDlg.contractCheckSubmit = function () {
    var id = $("#contractCheckId").val();
    var enterpriseId = $("#contractEnterpriseId").val();
    var description = $("#msg").val();
    var months = $("#state").val();
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/editProject", function (data) {
        if (data.code == 200) {
            Feng.success(data.msg);
            $("#" + enterpriseId).bootstrapTable("refresh", {});
            $("#contractCheckModal").modal("hide");
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("提交失败!" + data.responseJSON.message + "!");
    });
    ajax.set({"id": id, "months": months, "description": description, "process": $("#process").val()});
    ajax.start();
}

//编辑项目提交
TalentAllowanceInfoDlg.editProject = function () {
    var id = $("#projectId").val();
    var enterpriseId = $("#enterpriseId").val();
    var description = $("#description").val();
    var months = "";
    $("#months input").each(function () {
        if (this.checked) {
            months = months + $(this).val() + ",";
        }
    })
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/editProject", function (data) {
        if (data.code == 200) {
            Feng.success(data.msg);
            $("#" + enterpriseId).bootstrapTable("refresh", {});
            $("#projectModal").modal("hide");
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("提交失败!" + data.responseJSON.message + "!");
    });
    ajax.set({"id": id, "months": months, "description": description, "process": $("#process").val()});
    ajax.start();
}

/**
 * 提交晋江市现代产业体系人才的考勤
 */
TalentAllowanceInfoDlg.editJJAttendance = function () {
    var id = $("#jjAttendanceId").val();
    var enterpriseId = $("#jjAttendanceEnterpriseId").val();
    var description = $("#jjDescription").val();
    var days = $("#days").val();
    var months = "";
    $("#jjmonths input").each(function () {
        if (this.checked) {
            months = months + $(this).val() + ",";
        }
    })
    if (months == "" && (days == null || days == "")) {
        Feng.info("请填写考勤信息");
        return;
    }
    if (months != null && months != '' && days != null && days != '') {
        Feng.info("考勤天数和考勤月份只能选择一个填写");
        return;
    }
    $("#attendanceMonths").val(months);
    $("#jjAttendanceForm")[0].submit();
    // var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/editProject", function(data){
    //     if(data.code==200){
    //         Feng.success(data.msg);
    //         $("#"+enterpriseId).bootstrapTable("refresh", {});
    //         $("#jjAttendanceModal").modal("hide");
    //     }else{
    //         Feng.info(data.msg);
    //     }
    // },function(data){
    //     Feng.error("提交失败!" + data.responseJSON.message + "!");
    // });
    // ajax.set({"id":id,"months":months,"days":days,"description":description,"process":$("#process").val()});
    // ajax.start();
}

TalentAllowanceInfoDlg.editAttendanceProject = function () {
    var id = $("#attendanceId").val();
    var enterpriseId = $("#attendanceEnterpriseId").val();
    var description = $("#attendanceDescription").val();
    var months = "";
    var error = "";
    $("#attendMonths input").each(function () {
        var days = $(this).val();
        var num = $(this).attr("num");
        if (isNaN(days)) {
            error = error + num + "月的考勤天数不是数字;";
        } else {
            if (days < 0 || days > 31) {
                error = error + num + "月的考勤天数不在范围内（1-31）;";
            }
        }
        if (days == null || days == '') {
            days = 0;
        }
        months = months + num + "=" + days + ",";
    });
    if (error != "") {
        Feng.error(error);
        return;
    }
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/editProject", function (data) {
        if (data.code == 200) {
            Feng.success(data.msg);
            $("#" + enterpriseId).bootstrapTable("refresh", {});
            $("#attendanceModal").modal("hide");
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("提交失败!" + data.responseJSON.message + "!");
    });
    ajax.set({"id": id, "months": months, "description": description, "process": $("#process").val()});
    ajax.start();
}


/**
 * 锁定工作单位合同
 * @param id
 */
TalentAllowanceInfoDlg.lockContract = function (id) {
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            var operation = function () {
                var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/lockContract", function (data) {
                    if (data.code == 200) {
                        Feng.success(data.msg);
                        $("#projectTable").bootstrapTable("refresh", {});
                    } else {
                        Feng.info(data.msg);
                    }
                }, function (data) {
                    Feng.error("删除失败!" + data.responseJSON.message + "!");
                });
                ajax.set("id", id);
                ajax.set("process", $("#process").val())
                ajax.start();
            }
            Feng.confirm("一旦锁定无法修改，确认锁定吗?", operation);
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", id);
    ajax.set("type", 1);
    ajax.set("process", $("#process").val())
    ajax.set("companyId", $("#companyId").val())
    ajax.start();
}

/**
 * 锁定项目
 * @param id
 */
TalentAllowanceInfoDlg.lockProject = function (id, enterpriseId) {
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            var operation = function () {
                var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/lockProject", function (data) {
                    if (data.code == 200) {
                        Feng.success(data.msg);
                        $("#" + enterpriseId).bootstrapTable("refresh", {});
                    } else {
                        Feng.info(data.msg);
                    }
                }, function (data) {
                    Feng.error("删除失败!" + data.responseJSON.message + "!");
                });
                ajax.set("id", id);
                ajax.set("process", $("#process").val())
                ajax.start();
            }
            Feng.confirm("一旦锁定无法修改，确认锁定吗?", operation);
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", id);
    ajax.set("type", 2);
    ajax.set("process", $("#process").val())
    ajax.set("companyId", $("#companyId").val())
    ajax.start();
}


/**
 * 显示审核模态框
 */
TalentAllowanceInfoDlg.showCheckModal = function () {
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            layer.open({
                type: 1,
                id: "neewFieldFormModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade: 0,
                maxmin: true,
                content: TalentAllowanceInfoDlg.createCheckHtml(),
                btn: ['<i class="fa fa-save"></i>&nbsp;&nbsp;提交', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
                btnAlign: 'c',
                zIndex: layer.zIndex,
                success: function (layero, index) {
                    var projectList = data.obj.projects;
                    var fileList = data.obj.files;
                    var concatList = data.obj.concats;
                    var files = data.obj.info.files;
                    var projects = data.obj.info.projects;
                    var concats = data.obj.info.concats;
                    var fields = data.obj.info.fields;
                    var info = data.obj.info;
                    //初始化附件、核查项目、合同
                    console.log(data.obj);
                    if (projectList != null && projectList.length != 0) {
                        var html = '<ul>';
                        for (var key in projectList) {
                            html = html + '<li style="width: 100%"><input type="checkbox" value="' + projectList[key].id + '"><span>' + projectList[key].projectName + '</span></li>';
                        }
                        html = html + "</ul>";
                        $("#field_project").empty().append(html);
                    }
                    if (fileList != null && fileList.length != 0) {
                        var html = '';
                        for (var key in fileList) {
                            html = html + '<ul><li style="width: 100%"><input type="checkbox" data-type="' + fileList[key].isConditionFile + '" value="' + fileList[key].id + '"><span>' + fileList[key].name + '</span></li></ul>';
                        }
                        $("#field_file").empty().append(html);
                    }
                    if (concatList != null && concatList.length != 0) {
                        var html = '';
                        for (var key in concatList) {
                            html = html + '<ul><li style="width: 100%"><input type="checkbox" value="' + concatList[key].id + '"><span>' + concatList[key].enterpriseName + '</span></li></ul>';
                        }
                        $("#field_concat").empty().append(html);
                    }
                    TalentAllowanceInfoDlg.initICheck();
                    //回显数据
                    $("#checkStateModal").val(info.checkState).trigger("change");
                    $("#toProcess").val(info.toProcess).trigger("change");
                    if (Feng.isNotEmptyStr(info.toDep))
                        $("#toDep").val(info.toDep.split(",")).trigger("chosen:updated");
                    $("#checkMsg").val(info.checkMsg);
                    if (Feng.isNotEmptyStr(projects)) {
                        $("#field_project input").each(function () {
                            if (projects.indexOf($(this).val()) != -1) {
                                $(this).iCheck("check");
                            }
                        });
                    }
                    if (files != null && files != '') {
                        $("#field_file input").each(function () {
                            if (files.indexOf($(this).val()) != -1) {
                                $(this).iCheck("check");
                            }
                        });
                    }
                    if (concats != null && concats != '') {
                        $("#field_concat input").each(function () {
                            if (concats.indexOf($(this).val()) != -1) {
                                $(this).iCheck("check");
                            }
                        });
                    }
                    if (Feng.isNotEmptyStr(fields)) {
                        $("#field_field input").each(function () {
                            if (fields.indexOf($(this).val()) != -1) {
                                $(this).iCheck("check");
                            }
                        });
                    }
                    $("input[type=checkbox][value=allowanceType]").on("ifChanged", function (e) {
                        var isChecked = $(this).is(":checked") ? "check" : "uncheck";
                        $("#field_file input").each(function () {
                            $(this).iCheck(isChecked);
                        })
                        $("#field_project input").each(function () {
                            $(this).iCheck(isChecked);
                        })
                    })
                },
                yes: function (index, layero) {
                    TalentAllowanceInfoDlg.checkSubmit(index);
                }
            });
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", $("#id").val());
    ajax.set("type", 3);
    ajax.set("process", $("#process").val())
    ajax.set("companyId", $("#companyId").val())
    ajax.start();
}

/**
 * 显示/隐藏设置津补贴类型
 */
TalentAllowanceInfoDlg.toggleSetAllowance = function () {
    var checkState = $("#reviewState").val();
    if (checkState == 2) {
        $("#setAllowanceHeading,#setAllowanceBody").css("display", "none");
        $("#processLable,#processDiv").css("display", "block");
        $("#checkMsg").val("审核通过");
    } else if (checkState == 3) {
        $("#setAllowanceHeading,#setAllowanceBody").css("display", "block");
        $("#processLable,#processDiv").css("display", "none");
    }
}

/**
 * 保存复核审核结果
 */
TalentAllowanceInfoDlg.saveReviewCheck = function () {
    var id = $("#id").val();
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            var checkState = $("#reviewState").val();
            var checkMsg = $("#allowanceCheckMsg").val();
            if (checkState == null || checkState == '') {
                Feng.info("请选择审核状态");
                return;
            }
            var toPorcess = $("#toProcess").val();
            var allowanceType = null, months = "", allowanceMsg = null;
            if (checkState == 3) {
                allowanceType = $("#newAllowanceType").val();
                $("#allowanceMonths input[type=checkbox]").each(function () {
                    if (this.checked) {
                        months = months + $(this).val() + ",";
                    }
                });
                allowanceMsg = $("#newAllowanceMsg").val();
            }
            var param = {"id": id, "checkState": checkState, "checkMsg": checkMsg, "process": $("#process").val(),
                "toPorcess": toPorcess, "allowanceType": allowanceType, "allowanceMsg": allowanceMsg, "months": months};
            var checkAjax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/reviewCheck", function (res) {
                if (res.code == 200) {
                    Feng.success(res.msg)
                } else {
                    Feng.error(res.msg);
                }
            }, function (data) {
                Feng.error("提交失败!" + data.responseJSON.message + "!");
            });
            checkAjax.setData(param);
            checkAjax.start();
        } else {
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", id);
    ajax.set("type", 3);
    ajax.set("process", $("#process").val())
    ajax.set("companyId", $("#companyId").val())
    ajax.start();
}


/**
 * 显示字段或者隐藏字段选择
 */
TalentAllowanceInfoDlg.toggleField = function () {
    var checkState = $("#checkStateModal").val();
    var process = $("#process").val();
    if (checkState == 2) {
        $("#toProcessDiv").css("display", process == 3 ? "block" : "none");
        $("#field").show();
    } else {
        if (checkState == 3) {
            $("#checkMsg").val(process == 3 ? "复核通过,待核查征信" : "审核通过");
        }
        $("#field").hide();
        $("#field").find("input[type=checkbox]").each(function () {
            $(this).iCheck("uncheck");
        });
        $("#toProcessDiv").css("display", "none");
    }
}


/**
 * 审核信息提交
 */
TalentAllowanceInfoDlg.checkSubmit = function (index) {
    var id = $("#id").val();
    var checkState = $("#checkStateModal").val();
    var checkMsg = $("#checkMsg").val();
    var process = $("#process").val();
    var companyCode = $("#companyCode").val();
    var companyCodes = "";
    if (Feng.isEmptyStr(checkState)) {
        Feng.info("请选择审核状态");
        return;
    }
    if (Feng.isEmptyStr(checkMsg)) {
        Feng.info("请填写审核意见");
        return;
    }
    var projects = '', files = '', concats = '', fields = "";
    $("#field_project li input").each(function (index) {
        if ($(this).is(":checked")) {
            projects = projects + $(this).val() + ",";
        }
    });
    $("#field_file li input").each(function (index) {
        if ($(this).is(":checked")) {
            files = files + $(this).val() + ",";
        }
    });
    //if(companyCode == CONFIG.COM_RSJ || companyCode == CONFIG.COM_IC){
    $("#field_concat li input").each(function (index) {
        if ($(this).is(":checked")) {
            concats = concats + $(this).val() + ",";
        }
    });
    $("#field_field li input").each(function (index) {
        if ($(this).is(":checked")) {
            fields = fields + $(this).val() + ",";
        }
    });
    fields = fields.substring(0, fields.length - 1);
    if (Feng.isNotEmptyStr(companyCodes)) {
        companyCodes = companyCodes.substring(0, companyCodes.length - 1);
    }
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/check", function (data) {
        if (data.code == 200) {
            layer.close(index);
            Feng.success(data.msg);
        } else {
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("提交审核失败!");
    });
    ajax.setData({"id": id, "checkState": checkState, "checkMsg": checkMsg, "process": $("#process").val(), "projects": projects, "files": files, "concats": concats, "fields": fields, "companyId": $("#companyId").val(), "toProcess": $("#toProcess").val(), "toDep": companyCodes});
    ajax.start();
}


/**
 * 提交审核
 */
TalentAllowanceInfoDlg.submitCheck = function () {
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/submitCheck", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                window.parent.TalentAllowanceInfo.table.refresh();
                TalentAllowanceInfoDlg.close();
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("提交审核失败!" + data.responseJSON.message + "!");
        });
        ajax.setData({"id": $("#id").val(), "process": $("#process").val(), "companyId": $("#companyId").val()});
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，是否审核完毕且无误?", operation);
}


TalentAllowanceInfoDlg.attendanceCallBack = function (data) {
    if (data.code == 200) {
        Feng.success(data.msg);
        $("#" + data.obj).bootstrapTable("refresh", {});
        $("#jjAttendanceModal").modal("hide");
    } else {
        Feng.info(data.msg);
    }
}


TalentAllowanceInfoDlg.initICheck = function () {
    $('input[type=checkbox]').iCheck({
        labelHover: false,
        cursor: true,
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-greene',
        increaseArea: '20%'
    });
}

TalentAllowanceInfoDlg.showAllLog = function () {
    var id = $("#id").val();
    if (Feng.isNotEmptyStr(id)) {
        Feng.getCheckLog("logTable", {"type": CONFIG.project_jbt, "mainId": $("#id").val(), "typeFileId": "", "active": 1})
    }
}

TalentAllowanceInfoDlg.fileChange = function (context) {
    var file = $(context).val();
    var pos = file.lastIndexOf("\\");
    $("#fileInput").val(file.substring(pos + 1));
}

TalentAllowanceInfoDlg.calculator = function () {
    var id = $("#id").val();
    var ajax = new $ax(Feng.ctxPath + "/enterprise/talentAllowance/calculator/id/" + id, function (data) {
        var message = data.recommendAllowanceMsg.join("<br>");
        if (data.recommendAllowanceType != 3) {
            message += "<br>试算补贴金额：<span style='color:red;font-weight:bold;'>" + data.finnalMoney + "</span>";
        }
        $("#cal-result").html(message);
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.start();
}

$(function () {
    if ($("#type").val() == 2) {
        $("#bankNumberSpan,#talentTypeSpan,#introductionModeSpan,#firstInJJTimeSpan").attr("style", "display:none");
    }
    $("select").each(function () {
        +
                $(this).val($(this).attr("value"));
    });
    TalentAllowanceInfoDlg.initFileTable();
    TalentAllowanceInfoDlg.initCommonFileTable();
    TalentAllowanceInfoDlg.initContract();
    TalentAllowanceInfoDlg.showAllLog();
    //批量加载时间控件
    $(".date").each(function () {
        laydate.render({elem: "#" + $(this).attr("id"), type: 'date', trigger: 'click'});
    });
    var process = $("#process").val();
    var compayCode = $("#companyCode").val();
    TalentAllowanceInfoDlg.calculator();
});
