/**
 * 走访小组配置管理初始化
 */
var VisitGroup = {
    id: "VisitGroupTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
VisitGroup.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '申报年度', field: 'year', visible: true, align: 'center', valign: 'middle',width:"120px"},
            {title: '核查小组', field: 'groupName', visible: true, align: 'center', valign: 'middle',width:"150px"},
            {title: '核查范围', field: 'talentType', visible: true, align: 'center', valign: 'middle'},
            // {title: '所属镇街', field: 'streetNames', visible: true, align: 'center', valign: 'middle'}
    ];
};

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

/**
 * 点击添加走访小组配置
 */
VisitGroup.openAddVisitGroup = function () {
    var index = layer.open({
        type: 2,
        title: '添加走访小组配置',
        area: ['1000px', '600px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/visitGroup/visitGroup_add'
    });
    VisitGroup.layerIndex = index;
};

/**
 * 打开查看走访小组配置详情
 */
VisitGroup.openVisitGroupDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '走访小组配置详情',
            area: ['1000px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/visitGroup/visitGroup_update/' + VisitGroup.seItem.id
        });
        VisitGroup.layerIndex = index;
    }
};

/**
 * 删除走访小组配置
 */
VisitGroup.delete = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/visitGroup/delete", function (data) {
                if(data.code == 200){
                    Feng.success(data.msg);
                    VisitGroup.table.refresh();
                }else{
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("visitGroupId",VisitGroup.seItem.id);
            ajax.start();
        }
        Feng.confirm("删除后无法恢复，确认删除吗?", operation);
    }
};

VisitGroup.formParams = function(){
    var queryData = {};
    queryData['year'] = $("#year").val();
    queryData['name'] = $("#name").val();
    return queryData;
}


/**
 * 查询走访小组配置列表
 */
VisitGroup.search = function () {
    VisitGroup.table.refresh({query: VisitGroup.formParams()});
};

VisitGroup.reset = function(){
    $("#year").val("");
    $("#name").val("");
}


$(function () {
    var defaultColunms = VisitGroup.initColumn();
    var table = new BSTable(VisitGroup.id, "/visitGroup/list", defaultColunms);
    table.setPaginationType("server");
    VisitGroup.table = table.init();
    var arr = [{"name":"name","code":"un_visit_group"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
});
