Index.js 13.1 KB
/**
 * Created by wangqianjun on 16/2/23.
 */
var $ = require('jquery'),
    common = require('../../../common/common');

// 热搜词状态
var StatusEnum = {
    ON: 2,// 开启
    OFF: 1 // 关闭
};
//界面分类值
var PagEnum = {
    DEF_HOT_SEARCH_WORDS: 1, //默认热搜词管理页面
    PULL_DOWN_WORDS: 2,//下拉词管理页面
    HOT_SEARCH_WORDS: 3,//热搜词管理页面
    SYNONYMS_: 4,//同义词管理页面
    DISABLE_WORDS: 5//停用词管理页面
};
//界面分类显示
var titles = {
    1: {
        name1: "默认热搜词列表",
        name2: "默认热搜词列表",
        title: "默认热搜词",
        tips: '注:默认热搜索词是默认显示在前台搜索框里的词或者短语'
    },
    2: {
        name1: "下拉词列表",
        name2: "下拉词列表",
        title: "下拉词",
        tips: '注:下拉词是前台输入框获取焦点之后下拉显示的词'
    },
    3: {
        name1: "热搜词列表",
        name2: "热搜词列表",
        title: "热搜词",
        tips: '注:热搜词是前台搜索框下面的词'
    },
    4: {
        name1: "同义词列表",
        name2: "同义词列表",
        title: "同义词",
        tips: '注:同义词,比如阿迪达斯和三叶草就是一对同义词'
    },
    5: {
        name1: "停用词列表",
        name2: "停用词列表",
        title: "停用词",
        tips: '注:停用词是指搜索引擎不进行拆分检索的词'
    }
};
// 下拉框
new common.dropDown({
    el: "#status-filter"
});
new common.dropDown({
    el: "#channel-ops"
});

// 初始化日期插件
new common.edit("#filter").init();
var edit = new common.edit2(".modal-body");
var Bll = {
    module: null,
    getQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return null;
    },
    _render1: function () {
        //只有默认热搜词才显示时间选择
        if (parseInt(type) == PagEnum.DEF_HOT_SEARCH_WORDS) {
            $('#starttime-filter').parent().show();
            $('#endtime-filter').parent().show();
            $('#channel-ops').parent().parent().show();
        } else {
            $('#starttime-filter').parent().hide();
            $('#endtime-filter').parent().hide();
            $('#channel-ops').parent().parent().hide();
        }
        var tem = common.util.__template2($("#template").html(), titles[parseInt(type)]);
        $(".media-body").html(tem);
    },
    __render: function (selecter, templater, data) {
        $(selecter).html(common.util.__template2($("#" + templater).html(), data));
    },
    //弹框
    toast: function (url, module, hint) {
        module.tips = titles[module._type].tips;
        Bll.module = module;
        var d = new common.dialog({
            title: hint + titles[module._type].title,
            content: common.util.__template2($("#template-content").html(), Bll.module),
            width: '30%',
            button: [
                {
                    value: "保存",
                    callback: function () {
                        if (edit.validate()) {
                            common.util.__ajax({
                                url: url,
                                data: Bll.module
                            }, function () {
                                g.reload();
                                d.close();
                            });
                        }
                        return false;
                    },
                    css: "btn-primary"
                },
                {
                    "value": "取消",
                    "css": "btn-info"
                }
            ]
        });
        Bll.__editRender();
    },
    renderDialog: function (templater) {
        Bll.__render(".modal-body", templater, Bll.module);
        Bll.__editRender();
    },
    __editRender: function () {
        edit.init();
    }
};
/**
 * 全局变量,当前界面的类型
 * @type {*}
 */
var type = Bll.getQueryString("type");
/**
 * 加载界面
 */
Bll._render1();
/**
 * 界面表格
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#search-words-list',
    parms: function () {
        switch (parseInt(type)) {
            //默认热搜词管理页面
            case PagEnum.DEF_HOT_SEARCH_WORDS :
                return {
                    type: type,
                    channelIds: $.trim($('#channel-ops').val()),
                    status: $.trim(common.util.__input("status-filter")),
                    startTime: $.trim($('#starttime-filter').val()),
                    endTime: $.trim($('#endtime-filter').val()),
                    content: $.trim($('#content-filter').val())
                };
            //热搜词管理页面
            case PagEnum.HOT_SEARCH_WORDS :
            //下拉词管理页面
            case PagEnum.PULL_DOWN_WORDS :
            //同义词管理页面
            case PagEnum.SYNONYMS_ :
            //停用词管理页面
            case PagEnum.DISABLE_WORDS :
                return {
                    type: type,
                    status: $.trim(common.util.__input("status-filter")),
                    content: $.trim($('#content-filter').val())
                };
        }
    },
    columns: (function () {
        switch (parseInt(type)) {
            //默认热搜词管理页面
            case PagEnum.DEF_HOT_SEARCH_WORDS :
                return [
                    {display: "序号", name: "id"},
                    {display: "内容", name: "content"},
                    {display: "频道", name: "channelNames"},
                    {
                        display: "链接", name: "url", render: function (item) {
                        var url = item.url ? item.url : "";
                        return '<a href="' + url + '" target="_blank"> ' + url + '</a>'
                    }
                    },
                    {
                        display: "状态", name: "status", render: function (item) {
                        if (item.status === StatusEnum.ON) {
                            return "<span>开启</span>";
                        } else {
                            return "<span>关闭</span>";
                        }
                    }
                    },
                    {display: "开始时间", name: "startTime"},
                    {display: "结束时间", name: "endTime"},
                    {display: "添加人", name: "creatorUsrname"},
                    {display: "添加时间", name: "createdTime"},
                    {display: "修改人", name: "modifyUsrname"},
                    {display: "修改时间", name: "modifyTime"},
                    {
                        display: "操作", name: "", render: function (item) {
                        return '<a class="btn btn-xs btn-info modify"  data-index="' + item.__index + '">修改</a>';
                    }
                    }
                ];

            //下拉词管理页面
            case PagEnum.PULL_DOWN_WORDS :
                return [
                    {display: "序号", name: "id"},
                    {display: "内容", name: "content"},
                    {
                        display: "状态", name: "status", render: function (item) {
                        if (item.status === StatusEnum.ON) {
                            return "<span>开启</span>";
                        } else {
                            return "<span>关闭</span>";
                        }
                    }
                    },
                    {display: "排序", name: "sort"},
                    {display: "商品数", name: "goodsNum"},
                    {display: "添加人", name: "creatorUsrname"},
                    {display: "添加时间", name: "createdTime"},
                    {display: "修改人", name: "modifyUsrname"},
                    {display: "修改时间", name: "modifyTime"},
                    {
                        display: "操作", name: "", render: function (item) {
                        return '<a class="btn btn-xs btn-info modify" data-index="' + item.__index + '">修改</a>';
                    }
                    }
                ];

            //热搜词管理页面
            case PagEnum.HOT_SEARCH_WORDS :
                return [
                    {display: "序号", name: "id"},
                    {display: "内容", name: "content"},
                    {display: "频道", name: "channelNames"},
                    {
                        display: "链接", name: "url", render: function (item) {
                        var url = item.url ? item.url : "";
                        return '<a href="' + url + '" target="_blank"> ' + url + '</a>' //'+item.url?item.url:""+'
                    }
                    },
                    {
                        display: "状态", name: "status", render: function (item) {
                        if (item.status === StatusEnum.ON) {
                            return "<span>开启</span>";
                        } else {
                            return "<span>关闭</span>";
                        }
                    }
                    },
                    {display: "排序", name: "sort"},
                    {display: "添加人", name: "creatorUsrname"},
                    {display: "添加时间", name: "createdTime"},
                    {display: "修改人", name: "modifyUsrname"},
                    {display: "修改时间", name: "modifyTime"},
                    {
                        display: "操作", name: "", render: function (item) {
                        return '<a class="btn btn-xs btn-info modify" data-index="' + item.__index + '">修改</a>';
                    }
                    }
                ];

            //同义词管理页面
            case PagEnum.SYNONYMS_ :
                return [
                    {display: "序号", name: "id"},
                    {display: "内容", name: "content"},
                    {
                        display: "状态", name: "status", render: function (item) {
                        if (item.status === StatusEnum.ON) {
                            return "<span>开启</span>";
                        } else {
                            return "<span>关闭</span>";
                        }
                    }
                    },
                    {display: "添加人", name: "creatorUsrname"},
                    {display: "添加时间", name: "createdTime"},
                    {display: "修改人", name: "modifyUsrname"},
                    {display: "修改时间", name: "modifyTime"},
                    {
                        display: "操作", name: "", render: function (item) {
                        return '<a class="btn btn-xs btn-info modify" data-index="' + item.__index + '">修改</a>';
                    }
                    }
                ];

            //停用词管理页面
            case PagEnum.DISABLE_WORDS :
                return [
                    {display: "序号", name: "id"},
                    {display: "内容", name: "content"},
                    {
                        display: "状态", name: "status", render: function (item) {
                        if (item.status === StatusEnum.ON) {
                            return "<span>开启</span>";
                        } else {
                            return "<span>关闭</span>";
                        }
                    }
                    },
                    {display: "添加人", name: "creatorUsrname"},
                    {display: "添加时间", name: "createdTime"},
                    {display: "修改人", name: "modifyUsrname"},
                    {display: "修改时间", name: "modifyTime"},
                    {
                        display: "操作", name: "", render: function (item) {
                        return '<a class="btn btn-xs btn-info modify"  data-index="' + item.__index + '">修改</a>';
                    }
                    }
                ];
        }
    })()
});
g.init('/operation/terms/searchWordsList');

/**
 * 监听输入框变化
 */
$(document).on("change", ".observe", function () {
    var $this = $(this);
    var name = $this.data("field");
    Bll.module = common.util.__buildobj(name, '.', Bll.module, function (obj, name1) {
        obj[name1] = $this.val();
    });
});
/**
 * 查询按钮
 */
$("#filter-btn").click(function () {
    g.reload(1);
});
/**
 * 添加
 */
$("#filter-add").click(function () {
    var item = {
        "type": parseInt(type),
        "content": "",
        "channelIds": "",
        "url": "",
        "startTime": "",
        "endTime": "",
        "goodsNum": 0,
        "sort": 1
    };
    item._status = "add";
    item._type = parseInt(type);
    Bll.toast('/operations/terms/add', item, "添加");
});
/**
 * 修改
 */
$(document).on("click", ".modify", function () {
    var item = g.rows[$(this).data('index')];
    item._status = "update";
    item._type = parseInt(type);
    Bll.toast('/operations/terms/modify', item, "修改");
});