/**
 * 初始化硕博人才生活补贴申报详情对话框
 */
var LivingAllowanceInfoInfoDlg = {
    livingAllowanceInfoInfoData: {}
};

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

/**
 * 显示审核模态框
 * @param process
 */
LivingAllowanceInfoInfoDlg.showCheckModal = function (process) {
    var ajax = new $ax(Feng.ctxPath + "/admin/living_allowance/validateIsCheck", function (data) {
        if (data.code == 200) {
            layer.open({
                type: 1,
                id: "neewFieldFormModel",
                title: '审核',
                area: ['800px', '450px'],
                fix: false,
                shade: 0,
                maxmin: true,
                content: $("#checkTemplate").html(),
                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) {
                    layer.setTop(layero);
                    var obj = data.obj.obj;
                    var fileList = data.obj.fileList;
                    var html = '';
                    for (var key in fileList) {
                        html = html + '<ul><li style="width: 100%"><input type="checkbox" value="' + fileList[key].id + '"><span>' + fileList[key].name + '</span></li></ul>';
                    }
                    $("#field_file").empty().append(html);
                    $("#firstCheckForm")[0].reset();
                    $("#state").val(obj.checkState).trigger("change");
                    $("#msg").val(obj.checkMsg);
                    $("#process").val(process);
                    if (Feng.isNotEmptyStr(obj.fields)) {
                        $("#field_info input").each(function () {
                            var arr = obj.fields.split(",");
                            for (var key in arr) {
                                if ($(this).val() == arr[key]) {
                                    this.checked = true;
                                }
                            }
                        });
                    }
                    if (Feng.isNotEmptyStr(obj.files)) {
                        $("#field_file input").each(function () {
                            if (obj.files.indexOf($(this).val()) != -1) {
                                this.checked = true;
                            }
                        });
                    }
                },
                yes: function (index, layero) {
                    var checkState = $("#state").val();
                    var checkMsg = $("#msg").val();
                    if (Feng.isEmptyStr(checkState)) {
                        Feng.info("请选择审核状态");
                        return;
                    }
                    if (Feng.isEmptyStr(checkMsg)) {
                        Feng.info("请填写审核意见");
                        return;
                    }
                    var fields = '';
                    var files = '';
                    $("#field_info li input").each(function (index) {
                        if ($(this).is(":checked")) {
                            fields = fields + $(this).val() + ",";
                        }
                    });
                    $("#field_file li input").each(function (index) {
                        if ($(this).is(":checked")) {
                            files = files + $(this).val() + ",";
                        }
                    });
                    if (checkState == 2 && fields == '' && files == '') {
                        Feng.info("请选择可修改的字段或附件！");
                        return;
                    }
                    var ajax = new $ax(Feng.ctxPath + "/admin/living_allowance/check", function (data) {
                        if (data.code == 200) {
                            layer.close(index);
                            Feng.success(data.msg);
                        } else {
                            Feng.error(data.msg);
                        }
                    }, function (data) {
                        Feng.error("提交失败!" + data.responseJSON.message + "!");
                    });
                    ajax.setData({
                        "id": $("#id").val(),
                        "checkState": checkState,
                        "checkMsg": checkMsg,
                        "process": process,
                        "fields": fields,
                        "files": files
                    })
                    ajax.start();
                }
            });
        } else {
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id", $("#id").val());
    ajax.set("process", process);
    ajax.start();
}

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

LivingAllowanceInfoInfoDlg.fieldCheckd = function (context) {
    if ($(context).get(0).checked) {
        $(context).parent().next().children()[0].checked = true;
        $(context).parent().next().children().eq(0).trigger("change");
    }
}

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

/**
 * 显示字段或者隐藏字段选择
 */
LivingAllowanceInfoInfoDlg.toggleField = function () {
    var checkState = $("#state").val();
    var process = $("#process").val();
    var checkMsg = $("#msg").val();
    if (checkState == 2) {
        $("#field").show();
        $("#msg").val("");
    } else if (checkState == 3) {
        $("#field").hide();
        $("#field").find("input[type=checkbox]").removeAttr("checked");
        if (Feng.isEmptyStr(checkMsg)) {
            if (process == 1) {
                $("#msg").val("初审通过，待部门审核！");
            }
            if (process == 2) {
                $("#msg").val("部门审核通过，待复核！");
            }
            if (process == 3) {
                $("#msg").val("复核通过，待公示！");
            }
        }
    } else if (checkState == -1) {
        $("#field").hide();
        if (process == 1) {
            $("#msg").val("初审不通过！");
        }
        if (process == 2) {
            $("#msg").val("部门审核不通过！");
        }
        if (process == 3) {
            $("#msg").val("复核不通过！");
        }
    }
}

LivingAllowanceInfoInfoDlg.showMiniFileModal = function () {
    Feng.showMiniFileModal(CONFIG.project_master_living_allowance, $("#type").val(), $("#id").val());
}

$(function () {
    Feng.getCheckLog("logTable", {
        "type": CONFIG.project_master_living_allowance,
        "mainId": $("#id").val(),
        "typeFileId": "",
        "active": 1
    });
    $('#identifyTable').bootstrapTable({
        url: Feng.ctxPath + "/admin/talent/getTalentInfoByIdCard",
        method: 'POST',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
        showRefresh: false, // 是否显示刷新按钮
        clickToSelect: true, // 是否启用点击选中行
        singleSelect: true, // 设置True 将禁止多选
        striped: true, // 是否显示行间隔色
        pagination: false, // 设置为 true 会在表格底部显示分页条
        paginationHAlign: "left",
        paginationDetailHAlign: "right",
        sidePagination: "server", // 设置在哪里进行分页，可选值为 'client' 或者 'server'
        showColumns: false,
        queryParams: function (params) {
            return {"idCard": $("#idCard").val(), "cardType": $("#idCard").data("type")};
        },
        rowStyle: function (row, index) {
            return {css: {"word-break": "break-word", "white-space": "inherit"}}
        },
        columns:
                [
                    {title: '申报年度', field: 'apply_year', visible: true, align: 'center', valign: 'middle', width: '80px'},
                    {title: '企业名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
                    {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px",
                        formatter: function (value, row, index) {
                            if (row.sex == 1) {
                                return value + '<span style="color:#6495ED">【男】</span>';
                            }
                            if (row.sex == 2) {
                                return value + '<span style="color:#FF82AB">【女】</span>';
                            }
                        }
                    },
                    {title: '人才层次', field: 'talent_arrange', visible: true, align: 'center', valign: 'middle', width: "100px",
                        formatter: function (value, row, index) {
                            switch (value) {
                                case 1:
                                    return "第一层次";
                                case 2:
                                    return "第二层次";
                                case 3:
                                    return "第三层次";
                                case 4:
                                    return "第四层次";
                                case 5:
                                    return "第五层次";
                                case 6:
                                    return "第六层次";
                                case 7:
                                    return "第七层次";

                            }
                        }
                    },
                    {title: '证件号码', field: 'card_number', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "150px"},
                    {title: '首次提交时间', field: 'first_submit_time', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '最新提交时间', field: 'new_submit_time', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle', width: "100px",
                        formatter: function (value, row, index) {
                            if ([-2, 11, 13, 15, 16, 22, 25, 27].indexOf(value) > -1) {
                                return "<span class='label label-danger'>" + row.checkStateName + "</span>"
                            }
                            if ([9, 10, 12, 14, 21, 23, 24, 26].indexOf(value) > -1) {
                                return "<span class='label label-success'>" + row.checkStateName + "</span>"
                            }
                            if ([28].indexOf(value) > -1) {
                                return "<span class='label label-primary'>" + row.checkStateName + "</span>"
                            } else {
                                return "<span class='label'>" + row.checkStateName + "</span>"
                            }
                        }
                    }
                ]
        ,
        onPostBody: function () {
            $('#identifyTable' + "td.uitd_showTip").bind("mouseover", function () {
                var htm = $(this).html();
                $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
            });
        }
    });
    $('#allowanceTable').bootstrapTable({
        url: Feng.ctxPath + "/admin/talent_allowance/getTalentAllowanceByIdCard",
        method: 'POST',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
        showRefresh: false, // 是否显示刷新按钮
        clickToSelect: true, // 是否启用点击选中行
        singleSelect: true, // 设置True 将禁止多选
        striped: true, // 是否显示行间隔色
        pagination: false, // 设置为 true 会在表格底部显示分页条
        paginationHAlign: "left",
        paginationDetailHAlign: "right",
        sidePagination: "server", // 设置在哪里进行分页，可选值为 'client' 或者 'server'
        showColumns: false,
        queryParams: function (params) {
            return {"idCard": $("#idCard").val(), "cardType": $("#cardType").val()};
        },
        rowStyle: function (row, index) {
            return {css: {"word-break": "break-word", "white-space": "inherit"}}
        },
        columns:
                [
                    {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "60px"},
                    {title: '单位名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
                    {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
                    {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
                    {title: '人才层次', field: 'talentArrangeName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '首次提交时间', field: 'firstSubmitTime', visible: true, align: 'center', valign: 'middle', width: "120px"},
                    {title: '最新提交时间', field: 'newSubmitTime', visible: true, align: 'center', valign: 'middle', width: "120px"},
                    {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px",
                        formatter(value, row, index) {
                            if (value == -1) {
                                return "<span class='label label-warning-light'>审核不通过</span>";
                            } else if (value == 1) {
                                return "<span class='label'>待提交</span>"
                            } else if (value == 10) {
                                return "<span class='label label-danger'>已驳回</span>";
                            } else if (value == 30) {
                                return "<span class='label label-primary'>已通过</span>"
                            } else {
                                return "<span class='label label-success'>审核中</span>";
                            }
                        }
                    },
                    {title: '兑现状态', field: 'publicState', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px",
                        formatter(value, row, index) {
                            if (value == 1)
                                return "<span style='color: #9d8189'>待核查征信</span>";
                            if (value == 2)
                                return "<span style='color: #00d3ee'>待公示</span>";
                            if (value == 3)
                                return "<span style='color: #af2cc5'>公示中</span>";
                            if (value == 4) {
                                return (row.allowanceType == 3) ? "<span style='color: #f55a4e'>不予兑现</span>" : "<span style='color: #ca9fab'>待兑现</span>";
                            }
                            if (value == 5)
                                return "<span style='color: #5cb860'>已兑现</span>";
                        }
                    },
                    {title: '推荐津补贴类型', field: 'recommendAllowanceType', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px",
                        formatter(value, row, index) {
                            if (value == null || value == "")
                                return "<span style='color: black'>未判定</span>";
                            if (value == 1)
                                return "<span style='color: green'>人才津贴</span>";
                            if (value == 2)
                                return "<span style='color: blue'>一次性交通补贴</span>";
                            if (value == 3)
                                return "<span style='color: red'>不予兑现</span>";
                        }
                    },
                    {title: '推荐兑现月份', field: 'recommendMonths', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '推荐兑现金额', field: 'recommendMoney', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '推荐金额说明', field: 'recommendMoneyDesc', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '津补贴类型', field: 'allowanceType', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px",
                        formatter(value, row, index) {
                            if (value == null || value == "")
                                return "<span style='color: black'>未判定</span>";
                            if (value == 1)
                                return "<span style='color: green'>人才津贴</span>";
                            if (value == 2)
                                return "<span style='color: blue'>一次性交通补贴</span>";
                            if (value == 3)
                                return "<span style='color: red'>不予兑现</span>";
                        }
                    },
                    {title: '兑现月份', field: 'months', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
                    {title: '兑现金额', field: 'money', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
                    {title: '金额说明', field: 'moneyDesc', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
                ]
        ,
        onPostBody: function () {
            $('#allowanceTable' + "td.uitd_showTip").bind("mouseover", function () {
                var htm = $(this).html();
                $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
            });
        }
    });
    LivingAllowanceInfoInfoDlg.showMiniFileModal();
});
