index.js 13 KB
/**
 * Created by wangqianjun on 16/2/23.
 */
var $ = require('jquery'),
    common = require('../common/common');
//require('../util/datepicker');

// 热搜词状态xxz
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//停用词管理页面
};

// 下拉框
new common.dropDown({el: "#status-filter"});
new common.dropDown({el: "#channel-ops"});

// 初始化日期插件
new common.edit("#filter").init();

var type = GetQueryString("type");

function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}
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.PULL_DOWN_WORDS :
            //热搜词管理页面
            case PagEnum.HOT_SEARCH_WORDS :
            //同义词管理页面
            case PagEnum.SYNONYMS_ :
            //停用词管理页面
            case PagEnum.DISABLE_WORDS :
                return {
                    type:type,
                    channelIds: $.trim($('#channel-ops').val()),
                    status: $.trim(common.util.__input("status-filter")),
                    content: $.trim($('#content-filter').val())
                };

        }


    },
    columns:
        (function () {
            console.log('type = ' + type);
            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>' //'+item.url?item.url:""+'
                        }},
                        {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-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-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>'
                        }},
                        {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-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-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-info modify"  data-index="' + item.__index + '">修改</a>';
                        }
                        }
                    ];
            }


        })()



});

g.init($('#route').val());

$("#filter-btn").click(function(){
    g.reload(1);
});

$("#filter-add").click(function() {

    //初始化弹框的底部红色说明
    searchWordOp("添加", '/operations/terms/add', {});
});

$(document).on("click",".modify",function () {

    var item = g.rows[$(this).data('index')];

    searchWordOp("修改", '/operations/terms/modify', item);
});

function searchWordOp (prefix, url, item) {

    var templates = {
        1: {
            templAdd:['template-channel', 'template-content', 'template-url', 'template-sarttime', 'template-endtime','template-tips'],
            title: '默认热搜词',
            templModify:['template-channel', 'template-content', 'template-url', 'template-sarttime', 'template-endtime','template-modify','template-tips'],
            tips: '注:默认热搜索词是默认显示在前台搜索框里的词或者短语'
        },
        2: {
            templAdd:['template-content', 'template-goodsnum', 'template-sort', 'template-tips'],
            templModify:['template-content', 'template-goodsnum', 'template-sort', 'template-modify','template-tips'],
            title: '下拉词',
            tips: '注:下拉词是前台输入框获取焦点之后下拉显示的词'
        },
        3: {
            templAdd:['template-channel', 'template-content', 'template-url', 'template-sort','template-tips'],
            templModify:['template-channel', 'template-content', 'template-url', 'template-sort', 'template-modify','template-tips'],
            title: '热搜词',
            tips: '注:热搜词是前台搜索框下面的词'
        },
        4: {
            templAdd:['template-content', 'template-tips'],
            templModify:['template-content',  'template-modify', 'template-tips'],
            title: '同义词',
            tips: '注:同义词,比如阿迪达斯和三叶草就是一对同义词'
        },
        5: {
            templAdd:['template-content', 'template-tips'],
            templModify:['template-content',  'template-modify', 'template-tips'],
            title: '停用词',
            tips: '注:停用词是指搜索引擎不进行拆分检索的词'
        },
    };

    var t=[];
    var templ = templates[parseInt(type)];

    var tmp = (prefix=="添加")? templ.templAdd:templ.templModify;
    console.log(tmp);
    for(var templID in tmp) {
        t.push($('#'+tmp[templID]).html());
    }

    var a =new common.edit(".confirm");
    item.tips = templ.tips;
    item.type = type;
    common.dialog.confirm(prefix+templ.title, common.util.__template( t.join(""), item), function () {

        //
        return a.submit(url,function(option){
            option.success=function(res){
                res=res.data;
                if(res.code=="200"){
                    a.$tip("提交成功", function() {
                        g.reload();
                    }, 'growl-success');
                }else{
                    a.$tip(res.message);
                }
                return false;
            },
                option.error=function(res){
                    a.$tip(res.message);
                }
        });

    });

    //$('#i-tips').html(templ.tips);

    a.init();
}

// 根据type判断显不显示【开始时间】和【结束时间】
(function () {
    var titles={
        1:{name1:"默认热搜词列表",name2:"默认热搜词列表"},
        2:{name1:"下拉词列表",name2:"下拉词列表"},
        3:{name1:"热搜词列表",name2:"热搜词列表"},
        4:{name1:"同义词列表",name2:"同义词列表"},
        5:{name1:"停用词列表",name2:"停用词列表"}
    }

    //只有默认热搜词才显示时间选择
    if (parseInt(type) == PagEnum.DEF_HOT_SEARCH_WORDS) {
        $('#starttime-filter').show();
        $('#endtime-filter').show();
    } else {
        $('#starttime-filter').hide();
        $('#endtime-filter').hide();

    }
    var tem=common.util.__template($("#template").html(),titles[parseInt(type)]);
    $(".media-body").html(tem);
})()