guang.articleCategory.Index.js 4.9 KB
webpackJsonp([59],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

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


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

	    StatusEnum: {
	        0:'关闭',
	        1:'开启'
	    }

	}


	var g = new common.grid({
	    el: '#list',
	    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: '排序',
	            name: "orderBy"
	        }, {
	            display: '状态',
	            render: function (item) {
	                return "<p>" + ENUM.StatusEnum[item.status] + "</p>";
	            }
	        }, {
	            display: '上级分类',
	            name: "parentName"
	        }, {
	            display: '分类',
	            name: "name"
	        }, {
	            display: '级别',
	            render: function (item) {
	                var level="一级";
	                if (item.parentId != 0) {
	                    level = "二级"
	                }
	                return "<p>" +level+ "</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>');
	                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/categoryist');

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

	//添加
	$(document).on('click', '#add', function() {
	    articleCategoryOP("新增", '/guang/article/sort/add', {})
	});

	//编辑
	$(document).on('click', '.info-modify', function() {
	    var item = g.rows[$(this).data("index")];
	    articleCategoryOP("修改", '/guang/article/sort/update', item);
	});

	//删除
	$(document).on('click', '.info-del', function() {
	    var item = g.rows[$(this).data("index")];
	    common.dialog.confirm("温馨提示","确定要删除该文章分类?" , function() {
	        common.util.__ajax({
	            url: '/guang/article/sort/del',
	            data: {
	                id: item.id,
	            }
	        }, function(res) {
	            if (res.code == 200) {
	                common.util.__tip('删除成功', 'success');
	                g.reload();
	            } else {
	                common.util.__tip(res.message);
	            }
	        },true);
	    });

	});

	$(document).on("change", "#parentId", function () {
	    if($('#parentId').val() == "-1"){
	        $('#advertCodeCont').show();
	    }else{
	        $('#advertCodeCont').hide();
	    }

	});


	function articleCategoryOP(prefix, url, item) {

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

	    common.dialog.confirm(prefix+'文章分类', common.util.__template2($("#template").html(), item), function () {
	        if(prefix == '修改' && item.parentId != 0){
	            if($('#parentId').val() == "-1"){
	                a.$tip("请选择一级分类");
	                return false;
	            }
	        }
	        return a.submit(url,function(option){
	            option.success=function(res){
	                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();

	    if(prefix == '新增' || item.parentId == 0){
	        $('#advertCodeCont').show();
	    }else{
	        $('#advertCodeCont').hide();
	    }

	    if(prefix == '修改' && item.parentId == 0){
	        $('#maxsord').hide();
	    }else{
	        $('#maxsord').show();
	        new common.dropDown({
	            el: "#parentId",
	            ajax: 'guangGetSortList',
	            params: function () {
	                return {
	                    parentId: 0
	                };
	            }
	        });
	    }




	}

/***/ }
]);