/**
 * 购房补助管理初始化
 */
var HouseRentingPurchaseFees = {
    id: "HouseRentingPurchaseFeesTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
HouseRentingPurchaseFees.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip',
            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: 'cardTypeName', visible: true, align: 'center', valign: 'middle',width:"80px",'class': 'uitd_showTip'},
        {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '人才层次', field: 'talentArrangeName', 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: 'entryTime', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        // {title: '岗位/职务', field: 'post', visible: true, align: 'center', valign: 'middle'},
        // {title: '工作单位地址', field: 'enterpriseAddress', visible: true, align: 'center', valign: 'middle'},
        // {title: '现居地址', field: 'address', visible: true, align: 'center', valign: 'middle'},
        {title: '联系电话', field: 'phone', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        // {title: '电子邮箱', field: 'email', visible: true, align: 'center', valign: 'middle'},
        {title: '婚姻状态', field: 'marryStatusName', visible: true, align: 'center', valign: 'middle',width:"80px",'class': 'uitd_showTip'},
        {title: '配偶姓名', field: 'spouseName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip',
            formatter : function (value,row,index) {
                if(row.spouseSex==1){
                    return value+'<span style="color:#6495ED">【男】</span>';
                }if(row.spouseSex==2){
                    return value+'<span style="color:#FF82AB">【女】</span>';
                }
            }
        },
        {title: '配偶证件类型', field: 'spouseCardTypeName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        {title: '配偶证件号码', field: 'spouseIdCard', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '配偶人才层次', field: 'spouseTalentArrangeName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        // {title: '配偶籍贯', field: 'spouseNativePlace', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        // {title: '配偶入职时间', field: 'spouseEntryTime', visible: true, align: 'center', valign: 'middle'},
        // {title: '配偶岗位/职务', field: 'spousePost', visible: true, align: 'center', valign: 'middle'},
        // {title: '配偶工作单位', field: 'spouseEnterpriseName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        // {title: '配偶工作单位地址', field: 'spouseEnterpriseAddress', visible: true, align: 'center', valign: 'middle'},
        // {title: '配偶现居地址', field: 'spouseAddress', visible: true, align: 'center', valign: 'middle'},
        {title: '配偶联系电话', field: 'spousePhone', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        // {title: '配偶电子邮箱', field: 'spouseEmail', visible: true, align: 'center', valign: 'middle'},
        {title: '房产人才社区', field: 'houseTypeName', visible: true, align: 'center', valign: 'middle',width:"150px",'class': 'uitd_showTip'},
        {title: '房产详细地址', field: 'houseAddress', visible: true, align: 'center', valign: 'middle',width:"150px",'class': 'uitd_showTip'},
        {title: '购房金额', field: 'houseMoney', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        {title: '开户银行网点', field: 'bankAddress', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '银行账号', field: 'bankAccount', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '审核状态', field: 'checkStateName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip',width:"100px"},
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',width:"80px",
            formatter : function (value,row,index){
                return "<span class='label label-success' onclick=\"Feng.getCheckLogModel('"+value+"','"+CONFIG.project_renting_purchase_fees+"',null)\" >" +
                    "<i class=\"fa fa-book\"></i>日志" +
                    "</span>";
            }
        }
    ];
};

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

/**
 * 点击添加购房补助
 */
HouseRentingPurchaseFees.openAddHouseRentingPurchaseFees = function () {
    var index = layer.open({
        type: 2,
        title: '添加购房补助申请',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/api/houseRentingPurchaseFees/houseRentingPurchaseFees_add',
        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.HouseRentingPurchaseFeesInfoDlg.addSubmit();
        },btn2: function(index, layero){
            var obj = layero.find("iframe")[0].contentWindow;
            obj.HouseRentingPurchaseFeesInfoDlg.editSubmit(2);
            return false;
        },
        success :function (layero, index) {
            layer.tips('添加基本信息并上传附件后点击','.layui-layer-btn1',{tips:[1,"#78BA32"],time:0,closeBtn :2});
        },
        end :function () {
            layer.closeAll('tips');
            HouseRentingPurchaseFees.table.refresh();
        }
    });
    HouseRentingPurchaseFees.layerIndex = index;
    layer.full(index);
};

/**
 * 打开查看购房补助详情
 */
HouseRentingPurchaseFees.openHouseRentingPurchaseFeesDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '购房补助详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/api/houseRentingPurchaseFees/houseRentingPurchaseFees_update/' + HouseRentingPurchaseFees.seItem.id+"/1",
            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.HouseRentingPurchaseFeesInfoDlg.editSubmit(1);
            },btn2: function(index, layero){
                var obj = layero.find("iframe")[0].contentWindow;
                obj.HouseRentingPurchaseFeesInfoDlg.editSubmit(2);
                return false;
            },
            success :function (layero, index) {
                layer.tips('添加基本信息并上传附件后点击','.layui-layer-btn1',{tips:[1,"#78BA32"],time:0,closeBtn :2});
            },
            end :function () {
                layer.closeAll('tips');
                HouseRentingPurchaseFees.table.refresh();
            }
        });
        HouseRentingPurchaseFees.layerIndex = index;
        layer.full(index);
    }
};

HouseRentingPurchaseFees.openHouseRentingPurchaseFeesSelect = function(){
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '购房补助详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/api/houseRentingPurchaseFees/houseRentingPurchaseFees_update/' + HouseRentingPurchaseFees.seItem.id+"/2",
        });
        HouseRentingPurchaseFees.layerIndex = index;
        layer.full(index);
    }
}


/**
 * 删除购房补助
 */
HouseRentingPurchaseFees.delete = function () {
    if (this.check()) {
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/api/houseRentingPurchaseFees/delete", function (data) {
                if (data.code == 200){
                    Feng.success(data.msg);
                    HouseRentingPurchaseFees.table.refresh();
                }else{
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("houseRentingPurchaseFeesId", HouseRentingPurchaseFees.seItem.id);
            ajax.start();
        }
        Feng.confirm("删除后无法恢复，确认删除吗?", operation);
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
HouseRentingPurchaseFees.formParams = function() {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['sex'] = $("#sex").val();
    queryData['cardType'] = $("#cardType").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['talentArrange'] = $("#talentArrange").val();
    queryData['marryStatus'] = $("#marryStatus").val();
    queryData['spouseName'] = $("#spouseName").val();
    queryData['spouseSex'] = $("#spouseSex").val();
    queryData['spouseCardType'] = $("#spouseCardType").val();
    queryData['spouseIdcard'] = $("#spouseIdcard").val();
    queryData['spouseTalentArrange'] = $("#spouseTalentArrange").val();
    queryData['houseType'] = $("#houseType").val();
    queryData['checkState'] = $("#checkState").val()
    queryData['houseAddress'] = $("#houseAddress").val();
    return queryData;
}

/**
 * 查询购房补贴列表
 */
HouseRentingPurchaseFees.search = function () {
    HouseRentingPurchaseFees.table.refresh({query: HouseRentingPurchaseFees.formParams()});
};

/**
 * 重置
 */
HouseRentingPurchaseFees.reset = function(){
    $("#name").val("");
    $("#sex").val("");
    $("#cardType").val("");
    $("#idCard").val("");
    $("#talentArrange").val("");
    $("#marryStatus").val("");
    $("#spouseName").val("");
    $("#spouseSex").val("");
    $("#spouseCardType").val("");
    $("#spouseIdcard").val("");
    $("#spouseTalentArrange").val("");
    $("#houseType").val("");
    $("#checkState").val("");
    $("#houseAddress").val("");
}

$(function () {
    var defaultColunms = HouseRentingPurchaseFees.initColumn();
    var table = new BSTable(HouseRentingPurchaseFees.id, "/api/houseRentingPurchaseFees/list", defaultColunms);
    table.setPaginationType("server");
    HouseRentingPurchaseFees.table = table.init();
    //批量加载字典表数据
    var arr = [
        {"name":"marryStatus","code":"un_marryStatus"},
        {"name":"talentArrange","code":"un_talentLevel"},
        {"name":"cardType","code":"un_cardType"},
        {"name":"spouseCardType","code":"un_cardType"},
        {"name":"spouseTalentArrange","code":"un_talentLevel"},
        {"name":"houseType","code":"un_renting_houseType"},
        {"name":"childCardType","code":"un_cardType"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
});
