TalentAllowanceInfo.commonColumns = function(){
    return [
        {field:"selectItem",checkbox:true},
        {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle',width:"10%"},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',width:"10%"},
        {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle',width:"35%"},
        {title: '企业名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle',width:"35%"},
        {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"15%",
            formatter(value,row,index){
                if(value==-1){
                    return "<span class='label label-warning-light'>审核不通过</span>";
                }
                if( value==30){
                    return "<span class='label label-primary'>已通过</span>"
                }
            }
        },
        {title: '公示状态', field: 'publicState', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"15%",
            formatter(value,row,index){
                if(value==1)return "<span class='label label-danger'>待核查征信</span>";
                if(value==2)return "<span class='label label-warning'>待公示</span>";
                if(value==3)return "<span class='label label-success'>公示中</span>";
                if(value==4)return "<span class='label label-info'>待兑现</span>";
                if(value==5)return "<span class='label label-primary'>已兑现</span>";
            }
        },
    ];
}

TalentAllowanceInfo.cashColumns = function(){
    return [
        {field:"selectItem",checkbox:true},
        {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle',width:"10%"},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',width:"10%"},
        {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle',width:"20%"},
        {title: '津补贴类型', field: 'allowanceType', visible: true, align: 'center', valign: 'middle',width:"10%",
            formatter(value,row,index){
                if(value==null || value=="")return "未判定";
                if(value==1)return "人才津贴";
                if(value==2)return "一次性交通补贴";
                if(value==3)return "不予兑现";
            }
        },
        {title: '兑现月份', field: 'months', visible: true, align: 'center', valign: 'middle',width:"25%"},
        {title: '兑现金额', field: 'money', visible: true, align: 'center', valign: 'middle',width:"20%"},
    ];
}


TalentAllowanceInfo.showPrepareDataModal = function(type){
    var columns = TalentAllowanceInfo.commonColumns();
    $("#hczxForm").css("display","none");
    switch (type) {
        case 1:             //核查征信
            $("#exportPrepareModalLable").text("待核查征信导出");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.exportHczx()").text("导出");
            break;
        case 2:             //征信通过
            $("#exportPrepareModalLable").text("批量征信通过");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.hczxPass()").text("提交");
            break;
        case 3:             //公示(不予兑现)
            $("#exportPrepareModalLable").text("批量公示(不予兑现)");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.public()").text("提交");
            $("#hczxForm").css("display","block");
            break;
        case 4:             //公示(兑现)
            $("#exportPrepareModalLable").text("批量公示(兑现)");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.public()").text("提交");
            $("#hczxForm").css("display","block");
            break;
        case 5:             //公示通过
            $("#exportPrepareModalLable").text("批量公示通过");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.publicPass()").text("提交");
            break;
        case 6:             //兑现
            $("#exportPrepareModalLable").text("批量兑现");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.cashPass()").text("提交");
            columns = TalentAllowanceInfo.cashColumns();
            break;
        case 7:             //公示预览（不予兑现）
            $("#exportPrepareModalLable").text("公示预览(不予兑现)");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.publishExportBefore(1)").text("提交");
            break;
        case 8:             //公示预览(兑现)
            $("#exportPrepareModalLable").text("公示预览(兑现)");
            $("#prepareButton").attr("onclick","TalentAllowanceInfo.publishExportBefore(2)").text("提交");
            break;
    }
    $('#prepareTable').bootstrapTable('destroy');
    $('#prepareTable').bootstrapTable({
        url: Feng.ctxPath + "/talentAllowanceInfo/findTalentAllowanceByPage?type="+type,
        method: 'POST',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        search: false,					// 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
        showRefresh: false,				// 是否显示刷新按钮
        clickToSelect: true,			// 是否启用点击选中行
        singleSelect: false,				// 设置True 将禁止多选
        striped: true,  				// 是否显示行间隔色
        pagination: true,   			// 设置为 true 会在表格底部显示分页条
        paginationHAlign: "left",
        paginationDetailHAlign: "right",
        sidePagination: "client",   	// 设置在哪里进行分页，可选值为 'client' 或者 'server'
        pageNumber:1,                       //初始化加载第一页，默认第一页
        pageSize: 10,                       //每页的记录行数（*）
        pageList: [10, 25, 50, 100,500,1000,1500],        //可供选择的每页的行数（*）
        maintainSelected:true,              //全表全选需要开启
        showColumns: false,
        responseHandler : function(res){
            $(".time").each(function(){
                laydate.render({
                    elem: "#"+$(this).attr("id")
                    ,type: 'date'
                    ,format:'yyyy年MM月dd日'
                });
            });
            $("#exportPrepareModal").modal("show");
            return res.obj.rows;
        },
        columns:columns
    });
}

TalentAllowanceInfo.exportHczx = function(){
    var selected = $('#prepareTable').bootstrapTable('getSelections');
    if(!selected || selected.length<1){
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for(var i=0; i<selected.length; i++){
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0,ids.length-1);
    var operation = function(){
        window.location.href = Feng.ctxPath + "/talentAllowanceExportPrepare/exportHczx?ids="+ids;
    }
    Feng.confirm("确定导出吗?", operation);
}

/**
 * 征信通过
 */
TalentAllowanceInfo.hczxPass = function(){
    var selected = $('#prepareTable').bootstrapTable('getSelections');
    if(!selected || selected.length<1){
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for(var i=0; i<selected.length; i++){
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0,ids.length-1);
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/hczxPass", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
                $("#exportPrepareModal").modal("hide");
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("核查征信失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids",ids);
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，确定核查征信通过吗?", operation);
}

/**
 * 公式预览
 * @param type 1-不予兑现，2-兑现
 */
TalentAllowanceInfo.publishExportBefore = function(type){
    var selected = $('#prepareTable').bootstrapTable('getSelections');
    if(!selected || selected.length<1){
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for(var i=0; i<selected.length; i++){
        ids = ids + selected[i].id + ",";
    }
    var operation = function(){
        $("#exportPrepareModal").modal("hide");
        var url = (type==1)?"/talentAllowanceExportPrepare/exportPublicNotCash?ids="+ids:"/talentAllowanceExportPrepare/exportPublicNeedCash?ids="+ids;
        window.location.href = encodeURI(encodeURI(Feng.ctxPath + url));
    }
    Feng.confirm("确定要公示预览吗?", operation);
}


/**
 * 批量公示
 */
TalentAllowanceInfo.public = function(){
    var selected = $('#prepareTable').bootstrapTable('getSelections');
    if(!selected || selected.length<1){
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for(var i=0; i<selected.length; i++){
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0,ids.length-1);
    var isMessage = $("input[name='isSend']:checked").val();
    var typeName = $("#typeName").val();
    var address = $("#web").val();
    var publicStartTime = $("#publicStartTime").val();
    var publicEndTime = $("#publicEndTime").val();
    var dep = $("#dep").val();
    var phone = $("#publicPhone").val();
    var email = $("#publicemail").val();
    if(isMessage == 1){
        if(typeName == null || typeName == ''){
            Feng.info("请填写公示类型");return ;
        }if(address == null || address == ''){
            Feng.info("请填写公示平台");return ;
        }if(publicStartTime == null || publicStartTime == ''){
            Feng.info("请填写公示开始时间");return ;
        }if(publicEndTime == null || publicEndTime == ''){
            Feng.info("请填写公示截止时间");return ;
        }if(dep == null || dep == ''){
            Feng.info("请填写反映单位");return ;
        }if(phone == null || phone == ''){
            Feng.info("请填写联系电话");return ;
        }if(email == null || email == ''){
            Feng.info("请填写联系邮箱");return ;
        }
    }
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/publicBatch", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
                $("#exportPrepareModal").modal("hide");
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("公示失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids",ids);
        ajax.set("typeName",typeName);
        ajax.set("address",address);
        ajax.set("publicStartTime",publicStartTime);
        ajax.set("publicEndTime",publicEndTime);
        ajax.set("dep",dep);
        ajax.set("phone",phone);
        ajax.set("email",email);
        ajax.set("isMessage",isMessage);
        ajax.start();
    }
    Feng.confirm("一旦公示，无法恢复，确定公示吗?", operation);
}


/**
 * 公示通过
 */
TalentAllowanceInfo.publicPass = function(){
    var selected = $('#prepareTable').bootstrapTable('getSelections');
    if(!selected || selected.length<1){
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for(var i=0; i<selected.length; i++){
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0,ids.length-1);
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/publicPass", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
                $("#exportPrepareModal").modal("hide");
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("公示失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids",ids);
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，确定公示通过吗?", operation);
}

/**
 * 兑现
 */
TalentAllowanceInfo.cashPass =function(){
    var selected = $('#prepareTable').bootstrapTable('getSelections');
    if(!selected || selected.length<1){
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for(var i=0; i<selected.length; i++){
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0,ids.length-1);
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/cash", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
                $("#exportPrepareModal").modal("hide");
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("兑现失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids",ids);
        ajax.start();
    }
    Feng.confirm("一旦兑现无法修改，确定兑现吗?", operation);
}

/**
 * 是否发送短信
 */
TalentAllowanceInfo.toggleMessage = function(){
    var isMessage = $("input[name='isSend']:checked").val();
    if (isMessage==1) {
        $("#messageEdit").css("display","block");
    } else if ( isMessage == 2){
        $("#messageEdit").css("display","none");
    }
}


/***
 * 显示核查征信失信
 */
TalentAllowanceInfo.showHczxRejectModal = function(){
    if (this.check()) {
        if(TalentAllowanceInfo.seItem.publicState!=1){
            Feng.info("当前记录不是待核查征信状态，无法核查");
            return;
        }
        layer.open({
            type: 1,
            id: "neewFieldFormModel",
            title: '征信失信',
            area: ['800px', '450px'], //宽高
            fix: false, //不固定
            shade: 0,
            maxmin: true,
            content: '<form id="hczxRejectForm" class="form-horizontal">\n' +
                '                    <input type="hidden" name="hczxId" id="hczxId" >\n' +
                '                    <div class="form-group" style="margin: 10px;">\n' +
                '                            <label class=" control-label">失信原因</label>\n' +
            '                                <textarea id="hczxMsg" name="hczxMsg" class="form-control"></textarea>\n' +
                '                    </div>\n' +
                '                </form>',
            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) {
                $("#hczxId").val(TalentAllowanceInfo.seItem.id);
                $("#hczxMsg").val("");
            },
            yes :function (index, layero) {
                var id = $("#hczxId").val();
                var msg = $("#hczxMsg").val();
                if(msg==null || msg==''){
                    Feng.info("请填写失信原因");
                    return;
                }
                var operation = function(){
                    var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/hczxReject", function (data) {
                        if(data.code==200){
                            Feng.success(data.msg);
                            TalentAllowanceInfo.table.refresh();
                            layer.close(index);
                        }else{
                            Feng.error(data.msg);
                        }
                    }, function (data) {
                        Feng.error("核查征信失败!" + data.responseJSON.message + "!");
                    });
                    ajax.setData({"id":id,"outMsg":msg});
                    ajax.start();
                }
                Feng.confirm("一旦提交无法修改，确定提交吗?", operation);
            }
        });
    }
}


/***
 * 公示再审核
 */
TalentAllowanceInfo.afterCheck = function(){
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '津补贴公示再审核',
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/talentAllowanceInfo/toSupplePage/' + TalentAllowanceInfo.seItem.id ,
            btn: ['<i class="fa fa-save layui-bg-green"></i>&nbsp;&nbsp;计算津补贴', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            btnAlign: 'c',
            yes: function(index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentAllowanceInfoDlg.showCheckModal();
            },
        });
        layer.full(index);
        TalentAllowanceInfo.layerIndex = index;
    }
}


/**
 * 公示后审核提交
 */
TalentAllowanceInfo.afterCheckSubmit = function(){
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/afterCheck", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
                $("#checkModal").modal("hide");
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("审核失败!" + data.responseJSON.message + "!");
        });
        ajax.setData({"id":$("#mainId").val(),"checkState":$("#checkState").val(),"checkMsg":$("#msg").val(),"toProcess":$("#toProcess").val()});
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，确定提交吗?", operation);
}


TalentAllowanceInfo.toggleProcess = function(){
    var checkState = $("#checkState").val();
    if(checkState==-1)$("#processDiv").hide();
    if(checkState==2)$("#processDiv").show();
}

/**
 * 核查征信回调
 */
TalentAllowanceInfo.hczxCallBack = function (data) {
    Feng.info(data.msg);
}

/**
 * 刷新检索
 */
TalentAllowanceInfo.prepareSearch = function () {
    var name = $("#preName").val();
    var idCard = $("#preIdCard").val();
    $('#prepareTable').bootstrapTable("refresh",{"query":{"name":name,"idCard":idCard}});
}

/**
 * 重置
 */
TalentAllowanceInfo.prepareReset = function () {
    $("#preName").val("");
    $("#preIdCard").val("");
}
