infoManager.js 7.42 KB
/**
 * Created by wangqianjun on 16/3/22.
 */
var $ = require('jquery');
    common = require('../common/common');
    datepicker = require('../util/datepicker');

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

    StatusEnum: {
        '-1':'已关闭',
           0:'未发布',
           1:'开启',
    },

}

//下拉框
new common.dropDown({
    el: "#articleGender"
});

new common.dropDown({
    el: "#authorId",
    ajax: 'guangGetAuthorList'
});

new common.dropDown({
    el: "#maxSortId",
    ajax: 'guangGetSortList'
});

new common.dropDown({
    el: "#status"
});

new common.dropDown({
    el: '#orderBy'
});


//日期插件
$('.hasDatepicker').fdatepicker({
    format: 'yyyy-mm-dd'
});

var Timmer = {
    toast: function (content, fn) {
        common.dialog.confirm("定时发布", content, function () {
            common.util.__ajax({
                url: '/guang/article/timmer',
                data: fn()
            }, function () {
                g.reload();
                loadTab();
            });
        });
    }
}


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

        return {
            articleTitle: common.util.__input('articleTitle'),
            articleGender: common.util.__input('articleGender'),
            authorId: common.util.__input('authorId'),
            maxSortId: common.util.__input('maxSortId'),
            status: common.util.__input('status'),
            orderBy: common.util.__input('orderBy'),
            startTime: common.util.__input('starttime'),
            endTime: common.util.__input('endtime'),
        };
    },
    columns: [{
        display: 'ID',
        name: "id"
    }, {
        display: "缩略图",
        render: function(item) {

            item.coverImage = common.util.__template(item.coverImage,{mode:2,width:100,height:100});
            return '<img src="' + item.coverImage + '" width="100" height="60"/>'
        }
    }, {
        display: '文章标题',
        name: "articleTitle"
    }, {
        display: '分类',
        name: "maxSortName"
    }, {
        display: '性别',
        render: function (item) {
           return "<p>" + ENUM.GenderEnum[item.articleGender] + "</p>";
        }
    }, {
        display: '作者',
        name: "authorName"
    }, {
        display: '状态',
        render: function (item) {
          return  "<p>" + ENUM.StatusEnum[item.status] + "</p>";
        }
    }, {
        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: "发布时间",

        render: function (item) {
            var t = new Date(item.publishTime * 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 = [];

            if (items.status == 1) {
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-warning btn-xs info-close">关闭</a>');
            } else {
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-success btn-xs info-open">发布</a>');
            }
            HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs info-time">定时</a>');

            if (items.isRecommend == 1) {
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs info-recommend-cancel">取消推荐</a>');
            } else {
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-warning btn-xs info-recommend">推荐</a>');

            }

            HtmArr.push('<a data-index="' + items.__index + '" href="/guang/article/contentEdit/'+items.id+'" class="btn btn-primary btn-xs info-modify">编辑</a>');
            HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs info-del">删除</a>');

            return HtmArr.join('');
        }
    }]
})
g.init('/guang/article/list');



//==================== 按钮点击事件 =====================//
$("#filter-btn").click(function() {
    g.reload(1);
});

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

    common.util.__ajax({
        url: '/guang/article/operation',
        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);
});

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

    common.util.__ajax({
        url: '/guang/article/operation',
        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);
});

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

    common.util.__ajax({
        url: '/guang/article/operation',
        data: {
            id: item.id,
            isRecommend: 1
        }
    }, function(res) {

        if (res.code == 200) {
            common.util.__tip('成功推荐', 'success');
            g.reload();
        } else {
            common.util.__tip(res.message);
        }
    }, true);
});

//取消推荐
$(document).on('click', '.info-recommend-cancel', function() {
    var item = g.rows[$(this).data("index")];

    common.util.__ajax({
        url: '/guang/article/operation',
        data: {
            id: item.id,
            isRecommend: -1
        }
    }, function(res) {

        if (res.code == 200) {
            common.util.__tip('成功取消推荐', 'success');
            g.reload();
        } else {
            common.util.__tip(res.message);
        }
    }, true);
});

//定时
$(document).on("click", ".info-time", function () {
    var item = g.rows[$(this).data("index")];

    //$('#title').val("title");
    var data = function () {

        var dateString = common.util.__input('datepicker');
        if (dateString === '' || $.trim(dateString) === '') {
            return "请填写时间";
        }

        return {
            publishTime: dateString,
            id: item.id
        };
    }
    Timmer.toast(common.util.__template2($("#template").html(), item), data);

    $('#datepicker').fdatepicker({
        format: 'yyyy-mm-dd'
    });
});

// 删除
$(document).on("click", ".info-del", function () {
    var item = g.rows[$(this).data("index")];

    common.dialog.confirm("温馨提示", "您确定要删除吗?", function () {
        common.util.__ajax({
            url: '/guang/article/del',
            data: {
                id:item.id
            }
        }, function () {
            g.reload();
            loadTab();
        });
    });

});

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

});