plusStarCategory.js 4.41 KB
/**
 * Created by wangqianjun on 16/3/30.
 */

var $ = require('jquery');
common = require('../common/common');


var ENUM = {
    HotEnum: {
        '1': '是',
        '0': '否',
    },

    StatusEnum: {
        1:'可用',
        2:'不可用',
    },

    GenderEnum: {
        1:'男',
        2:'女',
        3:'通用',
    },

}

//下拉框
new common.dropDown({
    el: "#g-status",
});

var g = new common.grid({
    el: '#basicTable',
    size: 10,
    parms: function () {

        return {
            status: common.util.__input('g-status'),
        };
    },
    columns: [
        {
            display: 'ID',
            name: "id"
        }, {
            display: '名称',
            name: "categoryName"
        }, {
            display: '资源位码(head)',
            name: "contentCode"
        }, {
            display: '资源位码(foot)',
            name: "contentCodeFoot"
        }, {
            display: '更新时间',
            render: function (item) {
                var t = new Date(item.createTime * 1000);
                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
                return "<p>" + formatted + "</p>";
            }
        },
        {
            display: '操作',
            //}
            name: "status",
            render: function (items) {
                var HtmArr = [];

                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs info-modify">编辑</a>');

                if (items.status == 1) {
                    HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs info-close">关闭入口</a>');
                } else {
                    HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-success btn-xs info-open">开启入口</a>');
                }

                return HtmArr.join('');
            }
        }]
});
g.init('/guang/plustarcategory/getList');

//==================== 按钮点击事件 =====================//

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

//添加
$(document).on('click', '#add-btn', function() {
    plusStarOP("新增", '/guang/plustarcategory/addCategory', {});

});

//编辑
$(document).on('click', '.info-modify', function() {
    var item = g.rows[$(this).data("index")];
    plusStarOP("编辑", '/guang/plustarcategory/updateCategory', item);
});

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

    common.dialog.confirm("温馨提示","确定要关闭该入口?" , function() {
        common.util.__ajax({
            url: '/guang/plustarcategory/updateCategory',
            data: {
                id: item.id,
                status: 0
            }
        }, function(res) {
            if (res.code == 200) {
                g.reload();
            }
        });
    });
});

//开启
$(document).on('click', '.info-open', function() {
    var item = g.rows[$(this).data("index")];

    common.dialog.confirm("温馨提示","确定要开启该入口?" , function() {
        common.util.__ajax({
            url: '/guang/plustarcategory/updateCategory',
            data: {
                id: item.id,
                status: 1
            }
        }, function(res) {
            if (res.code == 200) {
                g.reload();
            }
        });
    });
});
function plusStarOP(prefix, url, item) {

    var a =new common.edit(".confirm");

    common.dialog.confirm(prefix+'plustar分类', common.util.__template2($("#template").html(), 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);
                }
        });

    });

    a.init();


    new common.dropDown({
        el: "#brandType",
        ajax: 'guangPlusSatrChannel',
        params : {
            status: 1
        }

    });

    new common.dropDown({
        el: "#brandId",
        ajax: 'brand',
        params : {
            status: 1
        }

    });



}