/**
 * 学杂费补助管理初始化
 */
var ChildschoolFees = {
    id: "ChildschoolFeesTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ChildschoolFees.initColumn = function () {
    return [
            {field: 'selectItem', radio: true},
            {title: '申报年度', field: 'year', visible: true, align: 'center', valign: 'middle',width:"80px",'class': 'uitd_showTip'},
            {title: '父母姓名', field: 'pName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip',
                formatter : function (value,row,index) {
                    if(row.pSex==1){
                        return value+'<span style="color:#6495ED">【男】</span>';
                    }if(row.pSex==2){
                        return value+'<span style="color:#FF82AB">【女】</span>';
                    }
                }
            },
            {title: '父母证件号码', field: 'pIdcard', visible: true, align: 'center', valign: 'middle',width:"150px",'class': 'uitd_showTip'},
            {title: '人才层次', field: 'talentArrangeName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '人才编号', field: 'certificateNo', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '籍贯', field: 'nativePlace', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '联系电话', field: 'phone', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '子女姓名', field: 'cName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip',
                formatter : function (value,row,index) {
                    if(row.cSex==1){
                        return value+'<span style="color:#6495ED">【男】</span>';
                    }if(row.cSex==2){
                        return value+'<span style="color:#FF82AB">【女】</span>';
                    }
                }
            },
            {title: '子女证件号码', field: 'cIdcard', visible: true, align: 'center', valign: 'middle',width:"150px",'class': 'uitd_showTip'},
            {title: '子女出生日期', field: 'cBirthday', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
            {title: '与申报人关系', field: 'cRelationName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
            {title: '现就读学校', field: 'nowSchool', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '现就读年级', field: 'nowGradeName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '实缴学杂费金额', field: 'paidInMoeny', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
            {title: '开户银行', field: 'bankName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
            {title: '开户银行网点', field: 'bankAddress', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
            {title: '银行账号', field: 'bankNumber', visible: true, align: 'center', valign: 'middle',width:"130px",'class': 'uitd_showTip'},
            {title: '兑现金额', field: 'cashMoney', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
            {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip',
                formatter : function (value,row,index) {
                    if(value==-1){
                        return '<span class=\'label label-danger\'>审核不通过</span>';
                    }if(value==1){
                        return '<span class=\'label\'>待提交</span>';
                    }if(value==2){
                        return '<span class=\'label label-info\'>待审核</span>';
                    }if(value==3){
                        return '<span class=\'label label-success\'>重新提交</span>';
                    }if(value==4){
                        return '<span class=\'label label-danger\'>审核驳回</span>';
                    }if(value==5){
                        return '<span class=\'label label-primary\'>审核通过</span>';
                    }
                }
            },
            {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',width:"80px",
                formatter : function (value,row,index){
                    return "<span class='label label-success' onclick=\"ChildschoolFees.showLog('"+value+"')\" >" +
                        "<i class=\"fa fa-book\"></i>日志" +
                        "</span>";
                }
            }
    ];
};

/**
 * 检查是否选中
 */
ChildschoolFees.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ChildschoolFees.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加学杂费补助
 */
ChildschoolFees.openAddChildschoolFees = function () {
    var ajax = new $ax(Feng.ctxPath + "/api/commonBatch/valiateIsAdd", function (data) {
        if (data.code == 200) {
            var index = layer.open({
                type: 2,
                title: '学杂费补助申报',
                area: 'auto', //宽高
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/api/childschoolFees/childschoolFees_add?year='+data.obj,
                btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交','<i class="fa fa-check layui-bg-green"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
                btnAlign: 'c',
                btn1: function (index, layero) {
                    var obj = layero.find("iframe")[0].contentWindow;
                    obj.ChildschoolFeesInfoDlg.addSubmit();
                },btn2: function(index, layero){
                    var obj = layero.find("iframe")[0].contentWindow;
                    obj.ChildschoolFeesInfoDlg.submitToCheck();
                    return false;
                },
                success :function (layero, index) {
                    layer.tips('添加基本信息并上传附件后点击','.layui-layer-btn1',{tips:[1,"#78BA32"],time:0,closeBtn :2});
                },
                end :function () {
                    layer.closeAll('tips');
                }
            });
            ChildschoolFees.layerIndex = index;
            layer.full(index);
        }else{
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("type",CONFIG.project_schoolFees);
    ajax.start();
};

/**
 * 打开查看学杂费补助详情
 */
ChildschoolFees.openChildschoolFeesDetail = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/api/commonBatch/valiateIsEditOrSubmit", function (data) {
            if (data.code == 200) {
                var index = layer.open({
                    type: 2,
                    title: '学杂费补助修改',
                    area: ['800px', '420px'], //宽高
                    fix: false, //不固定
                    maxmin: true,
                    content: Feng.ctxPath + '/api/childschoolFees/childschoolFees_update/1/' + ChildschoolFees.seItem.id,
                    btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交','<i class="fa fa-check layui-bg-green"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
                    btnAlign: 'c',
                    btn1: function (index, layero) {
                        var obj = layero.find("iframe")[0].contentWindow;
                        obj.ChildschoolFeesInfoDlg.editSubmit();
                    },btn2: function(index, layero){
                        var obj = layero.find("iframe")[0].contentWindow;
                        obj.ChildschoolFeesInfoDlg.submitToCheck();
                        return false;
                    },
                    success :function (layero, index) {
                        layer.tips('添加基本信息并上传附件后点击','.layui-layer-btn1',{tips:[1,"#78BA32"],time:0,closeBtn :2});
                    },
                    end :function () {
                        layer.closeAll('tips');
                        ChildschoolFees.table.refresh();
                    }
                });
                ChildschoolFees.layerIndex = index;
                layer.full(index);
            }else{
                Feng.info(data.msg);
            }
        }, function (data) {
            Feng.error("校验失败!" + data.responseJSON.message + "!");
        });
        ajax.set("type",CONFIG.project_schoolFees);
        ajax.set("year",ChildschoolFees.seItem.year);
        ajax.start();
    }
};

ChildschoolFees.openChildschoolFeesSelect = function(){
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '学杂费补助查看',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/api/childschoolFees/childschoolFees_update/2/' + ChildschoolFees.seItem.id,
        });
        ChildschoolFees.layerIndex = index;
        layer.full(index);
    }
}

/**
 * 删除学杂费补助
 */
ChildschoolFees.delete = function () {
    if (this.check()) {
        if(ChildschoolFees.seItem.checkState != 1){
            Feng.error("仅能删除未提交的数据");
            return  ;
        }
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/api/childschoolFees/delete", function (data) {
                if(data.code == 200){
                    Feng.success(data.msg);
                    ChildschoolFees.table.refresh();
                }else{
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("childschoolFeesId",ChildschoolFees.seItem.id);
            ajax.start();
        }
        Feng.confirm("删除后无法恢复，确认删除吗?", operation);
    }
};


/**
 * 收集数据
 */
ChildschoolFees.formParams = function(){
    var queryData = {};
    queryData['year'] = $("#year").val();
    queryData['pName'] = $("#pName").val();
    queryData['pSex'] = $("#pSex").val();
    queryData['pCardType'] = $("#pCardType").val();
    queryData['pIdcard'] = $("#pIdcard").val();
    queryData['talentArrange'] = $("#talentArrange").val();
    queryData['certificateNo'] = $("#certificateNo").val();
    queryData['address'] = $("#address").val();
    queryData['phone'] = $("#phone").val();
    queryData['cName'] = $("#cName").val();
    queryData['cSex'] = $("#cSex").val();
    queryData['cCardType'] = $("#cCardType").val();
    queryData['cIdcard'] = $("#cIdcard").val();
    queryData['cRelation'] = $("#cRelation").val();
    queryData['nowSchool'] = $("#nowSchool").val();
    queryData['nowGrade'] = $("#nowGrade").val();
    queryData['checkState'] = $("#checkState").val();
    return queryData;
}

/**
 * 重置
 */
ChildschoolFees.reset = function(){
    $("#year").val("");
    $("#pName").val("");
    $("#pSex").val("");
    $("#pCardType").val("");
    $("#pIdcard").val("");
    $("#talentArrange").val("");
    $("#certificateNo").val("");
    $("#address").val("");
    $("#phone").val("");
    $("#cName").val("");
    $("#cSex").val("");
    $("#cCardType").val("");
    $("#cIdcard").val("");
    $("#cRelation").val("");
    $("#nowSchool").val("");
    $("#nowGrade").val("");
    $("#checkState").val("");
}

/**
 * 查询学杂费补助列表
 */
ChildschoolFees.search = function () {
    ChildschoolFees.table.refresh({query: ChildschoolFees.formParams()});
};


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


$(function () {
    var defaultColunms = ChildschoolFees.initColumn();
    var table = new BSTable(ChildschoolFees.id, "/api/childschoolFees/list", defaultColunms);
    table.setPaginationType("server");
    table.setOnDblClickRow(function () {
        ChildschoolFees.openChildschoolFeesDetail();
    });
    ChildschoolFees.table = table.init();
    //批量加载字典表数据
    var arr = [
        {"name":"talentArrange","code":"un_talentLevel"},
        {"name":"cRelation","code":"un_education_relation"},
        {"name":"nowGrade","code":"un_grade"},
        {"name":"pCardType","code":"un_cardType"},
        {"name":"cCardType","code":"un_cardType"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
});
