guang.info.Index.js 9.39 KB
webpackJsonp([46],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by wangqianjun on 16/3/22.
	 */
	var $ = __webpack_require__(1);
	common = __webpack_require__(2);
	datepicker = __webpack_require__(9);

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

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

	    BLKEnum: {
	        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 () {
	            //console.log("fn()",fn());
	            common.util.__ajax({
	                url: '/guang/article/timmer',
	                data: fn()
	            }, function (res) {
	                if (res.code == '200') {
	                    g.reload();
	                }
	            });
	        });
	    }
	};

	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: $('#status').val(),//common.util.__input('status'),
	            orderBy: common.util.__input('orderBy'),
	            startTime: common.util.__input('starttime'),
	            endTime: common.util.__input('endtime'),
	            appType: common.util.__input('appType')
	        };
	    },
	    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" />'
	        }
	    }, {
	        display: '文章标题',
	        //name: "articleTitle",
	        width: '15%',
	        render: function (item) {
	            return '<span class="text-overflow"">' + item.articleTitle + '</span>'
	        }
	    }, {
	        display: '分类',
	        name: "maxSortName"
	    }, {
	        display: '性别',
	        render: function (item) {
	            return "<p>" + ENUM.GenderEnum[item.articleGender] + "</p>";
	        }
	    }, {
	        display: '作者',
	        name: "authorName"
	    }, {
	        display: '状态',
	        render: function (item) {
	            var sta =  ENUM.StatusEnum[item.status];
	            if(item.status == 1 && common.util.__compareDate(Date.now(), item.publishTime * 1000)) {
	                //检查是否为定时发布,当未到达所设定时间时,即使status为1,也显示‘未发布’
	                sta = "未发布";

	            } else {
	            }
	            return "<p>" + sta + "</p>";
	        }
	    }, {
	        display: "创建时间",

	        render: function (item) {
	            if (item.createTime && item.createTime !== 0) {
	                var t = new Date(item.createTime * 1000);
	                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm");
	                return "<p>" + formatted + "</p>";
	            }
	            else {
	                return "";
	            }

	        }
	    }, {
	        display: "发布时间",
	        render: function (item) {
	            //console.log(item.publishTime);
	            if (item.publishTime && item.publishTime !== 0) {
	                var t = new Date(item.publishTime * 1000);
	                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm");
	                return "<p>" + formatted + "</p>";
	            }
	            else {
	                return "";
	            }
	        }
	    }, {
	        display: 'BLK',
	        render: function (item) {
	            return "<p>" + ENUM.BLKEnum[item.appType] + "</p>";
	        }
	    },{
	        display: '操作',
	        //}
	        name: "status",
	        render: function (items) {
	            var HtmArr = [];

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

	            if (items.status == 1) {
	                if(common.util.__compareDate(Date.now(), items.publishTime * 1000)) {
	                    HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-success btn-xs info-open">发布</a>');
	                } else {
	                    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>');
	            }

	            if (items.isRecommend == 1) {
	                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-warning btn-xs info-recommend-cancel">取消推荐</a>');
	            } else {
	                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-success btn-xs info-recommend">推荐</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: 0
	        }
	    }, 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")];
	    var item1= $.extend(true,{},item);
	    if(item.publishTime&&item.publishTime!=0){
	        var t = new Date(item.publishTime * 1000);
	        item1.publishTime= common.util.__dateFormat(t, "yyyy-MM-dd hh:mm");
	    }
	   else{
	        item1.publishTime="yyyy-MM-dd hh:mm"
	    }
	    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(), item1), data);
	    $('#datepicker').fdatepicker({
	        format: 'yyyy-mm-dd hh:ii',
	        pickTime: true
	    });
	});

	// 删除
	$(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();
	        });
	    });
	});



/***/ }
]);