/**
 * 海峡计划申报管理初始化
 */
var ChannelPlanFiletype = {
    id: "ChannelPlanFiletypeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ChannelPlanFiletype.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {
            title: '附件名称',
            field: 'name',
            visible: true,
            align: 'center',
            valign: 'middle',
            width: 200,
            'class': 'uitd_showTip'
        },
        {
            title: 'api',
            field: 'api',
            visible: true,
            align: 'center',
            valign: 'middle',
            width: 120,
            'class': 'uitd_showTip'
        },
        {
            title: '是否必传', field: 'must', visible: true, align: 'center', valign: 'middle', width: 80,
            formatter: function (value, row, index) {
                if (value == null || value == '') {
                    return "";
                } else if (value == 1) {
                    return "是";
                } else if (value == 2) {
                    return "否";
                }
            }
        },
        {
            title: '是否成员', field: 'member', visible: true, align: 'center', valign: 'middle', width: 80,
            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', width: 80,
            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+"')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-pdf-o\" aria-hidden=\"true\"></i></button>";
                }
            }
        },
        {title: '排序', field: 'sn', visible: true, align: 'center', valign: 'middle', width: 80, sortable: true},
        {title: '审核单位', field: 'checkCompany', visible: true, align: 'center', valign: 'middle', width: 120,},
        {
            title: '备注',
            field: 'description',
            visible: true,
            align: 'center',
            valign: 'middle',
            'class': 'uitd_showTip',
            width: 200
        }
    ];
};

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

/**
 * 点击添加海峡计划申报
 */
ChannelPlanFiletype.openAddChannelPlanFiletype = function () {
    var index = layer.open({
        type: 2,
        title: '添加海峡计划申报',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelPlanFiletype/channelPlanFiletype_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看海峡计划申报详情
 */
ChannelPlanFiletype.openChannelPlanFiletypeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '海峡计划申报详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/channelPlanFiletype/channelPlanFiletype_update/' + ChannelPlanFiletype.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 查看
 */
ChannelPlanFiletype.select = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '海峡计划申报详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/channelPlanFiletype/channelPlanFiletype_select/' + ChannelPlanFiletype.seItem.id
        });
        this.layerIndex = index;
    }
}

/**
 * 删除海峡计划申报
 */
ChannelPlanFiletype.delete = function () {
    if (this.check()) {
        Feng.confirm("确认删除吗？",
            function () {
                var ajax = new $ax(Feng.ctxPath + "/channelPlanFiletype/delete", function (data) {
                    Feng.success(data.msg);
                    if (data.code == "200") {
                        ChannelPlanFiletype.table.refresh();
                    }
                }, function (data) {
                    Feng.error("删除失败!" + data.responseJSON.message + "!");
                });
                ajax.set("channelPlanFiletypeId", this.seItem.id);
                ajax.start();
            }
        );
    }
};

/**
 * 查询海峡计划申报列表
 */
ChannelPlanFiletype.search = function () {
    ChannelPlanFiletype.table.refresh({query: ChannelPlanFiletype.formParams()});
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
ChannelPlanFiletype.formParams = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['must'] = $("#must").val();
    queryData['member'] = $("#member").val();
    queryData['active'] = $("#active").val();
    queryData['checkCompany'] = $("#checkCompany").val();
    return queryData;
}

/**
 * 重置
 */
ChannelPlanFiletype.reset = function () {
    $("#name").val("");
    $("#must").val("");
    $("#member").val("");
    $("#active").val("");
    $("#checkCompany").val("");
};

$(function () {
    var defaultColunms = ChannelPlanFiletype.initColumn();
    var table = new BSTable(ChannelPlanFiletype.id, "/channelPlanFiletype/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ChannelPlanFiletype.formParams());
    table.setOnLoadSuccess(function(){
        $(".imgUrl").viewer({
            // toolbar:false,
            fullscreen:false
        });
    });
    ChannelPlanFiletype.table = table.init();
    Feng.addAjaxSelect({
        "id": "checkCompany",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/company/selectAll"
    });
});
