shop.ShopCategory.Index.js 2.94 KB
webpackJsonp([17],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var currentShopCategoryNum = 0;  //店铺商品分类数量

	var Bll = {
	    init: function () {
	        common.util.__ajax({
	            url:'/shops/shopCategory/list',
	            data: {}
	        }, function (res) {
	            var data = res.data;
	            console.log(data);
	            currentShopCategoryNum = data.length;
	            $('#showCategory').html(common.util.__template2($("#listTemplate").html(),{data:data})).show();
	        },true)
	    },
	    //新增,编辑商品分类名称
	    toast: function (type, url, name, id) {
	        var self = this;
	        common.dialog.confirm(
	            type == 0 ? "新增商品分类" : "编辑商品分类",
	            common.util.__template2($("#addTemplate").html(),{data:name}),
	            function () {
	                var categoryName = $('#categoryName').val();
	                if($.trim(categoryName) != ''){
	                    common.util.__ajax({
	                        url:url,
	                        data: {
	                            categoryId: id,
	                            categoryName: categoryName
	                        }
	                    },function (rs) {
	                        self.init();
	                    });
	                }else{
	                    common.util.__tip('店铺商品分类名称不能为空!');
	                    return false;
	                }
	            }
	        )
	    },
	    //删除商品分类
	    deleteCategory: function (categoryId) {
	        var self = this;
	        common.util.__ajax({
	            url:'/shops/shopCategory/delete',
	            data: {
	                categoryId:categoryId
	            }
	        }, function (res) {
	            self.init();
	        })
	    }
	};

	Bll.init();

	//新增类目
	$(document).on('click', '.addBtn', function () {
	    if(currentShopCategoryNum < 20){
	        Bll.toast(0, '/shops/shopCategory/add', '', null);
	    }else {
	        common.util.__tip('店铺最多添加只能添加20个商品分类!');
	    }
	});

	//编辑类目名称
	$(document).on('click', '.editCategory', function () {
	    var categoryName = $(this).parent().parent().find('td').eq(1).text();
	    var categoryId = $(this).data('categoryid');
	    Bll.toast(1, '/shops/shopCategory/update', categoryName, categoryId);
	});

	//删除类目
	$(document).on('click', '.deleteBtn', function () {
	    var categoryName = $(this).parent().parent().find('td').eq(1).text();
	    var categoryId = $(this).data('categoryid');
	    common.dialog.confirm(
	        "删除店铺商品分类",
	        "你确定<b style='color: #ff0000'>&nbsp;删除&nbsp;</b>商品分类<b style='color:#428bca'>&nbsp;"+categoryName+"&nbsp;</b>么?",
	        function () {
	            Bll.deleteCategory(categoryId);
	        }
	    )
	});

/***/ }
]);