bannerIndex.js 6.03 KB
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');
require('../../../common/util/datepicker');


var g = new common.grid({
    el: '#basicTable',
    size: 10,
    parms: function() {
        return {
            positionId: common.util.__input('postionId'),
            caption : $("#caption").val()
        };
    },
    columns: [{
       display: "ID",
        name: "id"
    }, {
        display: '名称',
        name: "caption"
    }, {
        display: '位置',
        name: "positionName"
    }, {
        display: '模板',
        name: "templetName"
    }, {
        display: '大分类',
        name: "maxSortName"
    }, {
        display: '中分类',
        name: "middleSortName"
    }, {
        display: '尺码',
        name: "sizeName"
    }, {
        display: '品牌',
        name: "brandNameList"
    }, {
        display: '风格',
        width: '8%',
        name: "styleNameList"
    }, {
        display: '颜色',
        name: "colorName"
    }, {
        display: '价格',
        name: "price"
    }, {
        display: '性别',
        name: "gender",
        render: function(item) {
            if(item.gender==1){
                var name ="男" ;
            }else if (item.gender==2){
                var name ="女" ;
            }else {
                var name ="通用" ;
            }
            return name;
        }
    },{
        display: '状态',
        name: "status",
        render: function(item) {
            if(item.status==1){
                var name ="开启" ;
            }else {
                var name ="关闭" ;
            }
            return name;
        }
    }, {
        display: '创建时间',
        name: "createTimeStr"
    }, {
        display: '操作',
        name: "status",
        render: function(items) {
            var HtmArr = [];
            if (items.status === '1') {
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs close-banner">关闭</a>');
            } else {
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-warning btn-xs open-banner">开启</a>');
            }
            HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-info btn-xs del-banner">删除</a>');
            HtmArr.push('<a href="/search/bannerEdit/' + items.id + '" class="btn btn-info btn-xs edit-banner">修改</a>');
            HtmArr.push('<a href="/search/bannerView/' + items.id + '" target="_blank" class="btn btn-info btn-xs view-banner">预览</a>');
            return HtmArr.join('');
        }
    }]
})
g.init('/operations/search/getBannerList');

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

//关闭操作
$('tbody').on('click', '.close-banner', function() {
    var item = g.rows[$(this).data("index")];

    new common.dialog({
        title: "关闭搜索广告管理",
        width: "360px",
        content: '确认关闭搜索广告管理么?',
        zIndex: 52,
        button: [
            {value: "确认", css:"btn-primary", callback: function () {
                        common.util.__ajax({
                            url: '/operations/search/updateBannerStatus',
                            data: {
                                id: item.id,
                                status: 0
                            }
                        }, function(res) {
                            if (res.code == 200) {
                                common.util.__tip('关闭成功', 'success');
                                g.reload();
                            } else {
                                common.util.__tip(res.message);
                            }
                        }, true);
            }},
            {value: "取消", css:"btn-default"}
        ]
    });

});
//开启操作
$('tbody').on('click', '.open-banner', function() {
    var item = g.rows[$(this).data("index")];
    new common.dialog({
        title: "开启搜索广告管理",
        width: "360px",
        content: '确认开启搜索广告管理么?',
        zIndex: 52,
        button: [
            {value: "确认", css:"btn-primary", callback: function () {
                        common.util.__ajax({
                            url: '/operations/search/updateBannerStatus',
                            data: {
                                id: item.id,
                                status: 1
                            }
                        }, function(res) {
                            if (res.code == 200) {
                                common.util.__tip('开启成功', 'success');
                                g.reload();
                            } else {
                                common.util.__tip(res.message);
                            }
                        }, true);
            }},
            {value: "取消", css:"btn-default"}
        ]
    });

});
//删除操作
$('tbody').on('click', '.del-banner', function() {
    var item = g.rows[$(this).data("index")];
    new common.dialog({
        title: "删除搜索广告管理",
        width: "360px",
        content: '确认删除搜索广告管理么?',
        zIndex: 52,
        button: [
            {value: "确认", css:"btn-primary", callback: function () {
                    common.util.__ajax({
                        url: '/operations/search/delBannerById',
                        data: {
                            id: item.id
                        }
                    }, function(res) {
                        if (res.code == 200) {
                            common.util.__tip('删除成功', 'success');
                            g.reload();
                        } else {
                            common.util.__tip(res.message);
                        }
                    }, true);
            }},
            {value: "取消", css:"btn-default"}
        ]
    });
    
});

new common.dropDown({el:"#postionId", ajax:"searchPostion", params:function(){
    return {postionId:$("#postionId").val()};
}});