/**
 * 人才津贴申报管理初始化
 */
var TalentAllowanceFiletype = {
    id: "TalentAllowanceFiletypeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TalentAllowanceFiletype.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '唯一标识', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '人才标签', field: 'talentType', visible: true, align: 'center', valign: 'middle',
                'class':'uitd_showTip'
            },
            {title: '录入人员', field: 'inputPerson', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    if (value == null || value == '') {
                        return "";
                    } else if (value == 1) {
                        return "企业客户";
                    } else if (value == 2) {
                        return "人才办";
                    }
                }
            },
            {title: '附件名称', field: 'name', visible: true, align: 'center', valign: 'middle','class':'uitd_showTip'},
            {title: '附件api', field: 'api', visible: true, align: 'center', valign: 'middle'},
            {title: '必传', field: 'must', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    if (value == null || value == '') {
                        return "";
                    } else if (value == 1) {
                        return "是";
                    } else if (value == 2) {
                        return "否";
                    }
                }
            },
            {title: '有效', field: 'active', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    if (value == null || value == '') {
                        return "";
                    } else if (value == 1) {
                        return "是";
                    } else if (value == 2) {
                        return "否";
                    }
                }
            },
            {
                title: '模板预览', field: 'templateUrl', visible: true, align: 'center', valign: 'middle', width: 80,
                formatter: function (value, row, index) {
                    if(value==null||value==''){
                        return "无";
                    }
                    var sn = value.lastIndexOf(".");
                    var suffix = value.substring(sn+1,value.length);
                    if(suffix=='gif'||suffix=='jpg'||suffix=='jpeg'||suffix=='bmp'||suffix=='png'){
                        return '<img class=\"imgUrl\"  src=\"'+value+'\" style=\"width:25px;height:25px;\">';
                    }else{
                        return "<button type='button'  onclick=\"Feng.showPdf('"+value+"','"+row.id+"','"+row.name+"')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-pdf-o\" aria-hidden=\"true\"></i></button>";
                    }
                }
            },
            {title: '审核单位', field: 'checkCompany', visible: true, align: 'center', valign: 'middle','class':'uitd_showTip'},
            {title: '排序', field: 'sn', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'description', visible: true, align: 'center', valign: 'middle','class':'uitd_showTip'},
            {title: '创建时间', field: 'createTime', visible: false, align: 'center', valign: 'middle'},
            {title: '创建用户', field: 'createUser', visible: false, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'updateTime', visible: false, align: 'center', valign: 'middle'},
            {title: '更新用户', field: 'updateUser', visible: false, align: 'center', valign: 'middle'}
    ];
};

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

/**
 * 点击添加人才津贴申报
 */
TalentAllowanceFiletype.openAddTalentAllowanceFiletype = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/talentAllowanceFiletype/talentAllowanceFiletype_add'
    });
    TalentAllowanceFiletype.layerIndex = index;
};

/**
 * 打开查看人才津贴申报详情
 */
TalentAllowanceFiletype.openTalentAllowanceFiletypeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才津贴申报详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/talentAllowanceFiletype/talentAllowanceFiletype_update/' + TalentAllowanceFiletype.seItem.id
        });
        TalentAllowanceFiletype.layerIndex = index;
    }
};

/**
 * 删除人才津贴申报
 */
TalentAllowanceFiletype.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceFiletype/delete", function (data) {
            Feng.success("删除成功!");
            TalentAllowanceFiletype.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("talentAllowanceFiletypeId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询人才津贴申报列表
 */
TalentAllowanceFiletype.search = function () {
    var queryData = {};
    queryData['talentType'] = $("#talentType").val();
    queryData['inputPerson'] = $("#inputPerson").val();
    queryData['must'] = $("#must").val();
    queryData['active'] = $("#active").val();
    queryData['checkCompany'] = $("#checkCompany").val();
    queryData['name'] = $("#name").val();
    TalentAllowanceFiletype.table.refresh({query: queryData});
};

/**
 * 根据查询条件导出excel
 */
TalentAllowanceFiletype.export = function(){
    var talentType = $("#talentType").val();
    var inputPerson = $("#inputPerson").val();
    var must = $("#must").val();
    var active = $("#active").val();
    var name = $("#name").val();
    var checkCompany = $("#checkCompany").val();
    var arr = {"talentType":talentType, "inputPerson":inputPerson, "must":must, "active":active, "name":name,
        "checkCompany":checkCompany};
    window.location.href = Feng.setUrlParam(Feng.ctxPath + "/talentAllowanceFiletype/export", arr);
}

$(function () {
    var defaultColunms = TalentAllowanceFiletype.initColumn();
    var table = new BSTable(TalentAllowanceFiletype.id, "/talentAllowanceFiletype/list", defaultColunms);
    table.setPaginationType("server");
    table.setOnLoadSuccess(function(){
        $(".imgUrl").viewer({
            // toolbar:false,
            fullscreen:false
        });
    });
    TalentAllowanceFiletype.table = table.init();
    //下拉框数据动态加载  - 人才类型
    Feng.addAjaxSelect({
        "id": "talentType",
        "displayCode": "code",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/dict/findChildDictByCode?code=un_jbt_talentType"
    });
    //加载审核单位
    Feng.addAjaxSelect({
        "id": "checkCompany",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/company/selectAll"
    });
});
