shop.ShopCategory.Edit.js 7.79 KB
webpackJsonp([16],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

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

	var curCategoryId = 0,
	    selectedNum = 0,
	    curTab = 0;

	var g1 = new common.grid({
	    el: '#productTable',
	    parms: function() {
	        return {
	            categoryId: curCategoryId,
	            productSKN: common.util.__input("productSKN"),
	            productName: common.util.__input("productName")
	        };
	    },
	    columns: [
	        {
	            display: '商品图片',
	            name: 'productPic',
	            render: function (item) {
	                if (item.productPic) {
	                    return '<a class="list-img" target="_blank" href="' + item.productPic + '">' +
	                        '<img src="' + item.productPic + '"></a>';
	                } else {
	                    return '';
	                }
	        }},
	        {display: "SKN", name: "productSKN"},
	        {display: "商品名称", name: "productName"},
	        {display: "销售价(元)", name: "salePrice"},
	        {display: "分类", name: "productSort"},
	        {display: "商品分类", render: function (item) {
	            var name = item.categoryName ? item.categoryName : '未分类';
	            var categoryList = '<span class="name" style="display: block; text-align: center">'+ name +'</span>';
	            if(item.saleCategory && item.saleCategory.length > 1){
	                categoryList += '<ul class="list" style="display: none;margin: 0; padding: 0;text-align:center">';
	                for(var i=0; i<item.saleCategory.length; i++){
	                    categoryList += '<li>'+item.saleCategory[i]+'</li>'
	                }
	                categoryList += '</ul>' +
	                    '<a href="javascript:" class="moreCategory" style="display: block;text-align: center;color:#999">显示更多</a>';
	            }
	            return categoryList;
	        }},
	        {display: "操作", render: function (item) {
	            if(item.checked){
	                return '<a href="javascript:" class="btn btn-warning btn-xs cancelProduct" data-index="'+item.__index+'">取消选择</a>'
	            }else{
	                return '<a href="javascript:" class="btn btn-success btn-xs selectProduct" data-index="'+item.__index+'">选择</a>'
	            }
	        }}
	    ],
	    complete2: function (res) {
	        selectedNum = res.data.checkedCount;
	        $('.selectedProductsNum').text(selectedNum);
	    }
	});

	var g2 = new common.grid({
	    el: '#productTable',
	    parms: function() {
	        return {
	            categoryId: curCategoryId,
	            productSKN: common.util.__input("productSKN"),
	            productName: common.util.__input("productName")
	        };
	    },
	    columns: [
	        {
	            display: '商品图片',
	            name: 'productPic',
	            render: function (item) {
	                if (item.productPic) {
	                    return '<a class="list-img" target="_blank" href="' + item.productPic + '">' +
	                        '<img src="' + item.productPic + '"></a>';
	                } else {
	                    return '';
	                }

	        }},
	        {display: "SKN", name: "productSKN"},
	        {display: "商品名称", name: "productName"},
	        {display: "销售价(元)", name: "salePrice"},
	        {display: "分类", name: "productSort"},
	        {display: "商品分类", render: function (item) {
	            var name = item.categoryName ? item.categoryName : '未分类';
	            var categoryList = '<span class="name" style="display: block; text-align: center">'+ name +'</span>';
	            if(item.saleCategory && item.saleCategory.length > 1){
	                categoryList += '<ul class="list" style="display: none;margin: 0; padding: 0;text-align:center">';
	                for(var i=0; i<item.saleCategory.length; i++){
	                    categoryList += '<li>'+item.saleCategory[i]+'</li>'
	                }
	                categoryList += '</ul>' +
	                    '<a href="javascript:" class="moreCategory" style="display: block;text-align: center;color:#999">显示更多</a>';
	            }
	            return categoryList;
	        }},
	        {display: "操作", render: function (item) {
	            return '<a href="javascript:" class="btn btn-warning btn-xs cancelProduct" data-index="'+item.__index+'">取消选择</a>'
	        }}
	    ],
	    complete2: function (res) {
	        selectedNum = res.data.list.length;
	        $('.selectedProductsNum').text(selectedNum);
	    }
	});

	var Bll = {
	    init: function () {
	        this.getParamsInUrl();
	        g1.init('/shops/shopCategory/allProducts');
	    },
	    getParamsInUrl: function () {
	        var paramUrl = location.href + "";
	        if(paramUrl.indexOf("edit") > 0){
	            var param = paramUrl.substring(paramUrl.indexOf("edit"));
	            var paramList = param.split("/");
	            curCategoryId = paramList[1];
	        }
	    }
	};

	Bll.init();

	//tab切换
	$(document).on("click", ".nav-tabs li", function () {
	    if($(this).hasClass('active')) return false;

	    $(this).addClass('active').siblings().removeClass('active');
	    curTab = $(this).index();
	    switch (curTab){
	        case 0:
	            $('.cancelAll').hide();
	            g1.init('/shops/shopCategory/allProducts');
	            break;
	        case 1:
	            $('.cancelAll').show();
	            g2.init('/shops/shopCategory/selectedProducts');
	            break;
	    }
	});

	//选择商品
	$(document).on("click", ".selectProduct", function () {
	    var self = this;
	    var index = $(self).data("index");
	    var item = g1.rows[index];
	    common.util.__ajax({
	        url:'/shops/shopCategory/link',
	        data:{
	            categoryId: curCategoryId,
	            productSKN: item.productSKN
	        }
	    },function(){
	        $(self).parent().html('<a href="javascript:" class="btn btn-warning btn-xs cancelProduct" data-index="'+index+'">取消选择</a>');
	        $('.selectedProductsNum').text(++selectedNum);
	    }, true);
	});

	//在全部商品中,取消选择商品
	$(document).on("click", ".cancelProduct", function () {
	    var self = this;
	    var index = $(self).data("index");
	    var g = curTab == 0 ? g1 : g2;
	    var item = g.rows[index];
	    common.util.__ajax({
	        url:'/shops/shopCategory/unlink',
	        data:{
	            categoryId: curCategoryId,
	            productSKN: item.productSKN
	        }
	    },function(){
	        if(curTab == 0){
	            $(self).parent().html('<a href="javascript:" class="btn btn-success btn-xs selectProduct" data-index="'+index+'">选择</a>');
	            $('.selectedProductsNum').text(--selectedNum);
	        }
	        if(curTab == 1){
	            g2.reload();
	        }
	    }, true);
	});

	//全部取消选择
	$(document).on("click", ".cancelAll", function () {
	    common.dialog.confirm(
	        "温馨提示", "你确定全部取消选择所有商品么?",
	        function(){
	            common.util.__ajax({
	                url:'/shops/shopCategory/unlinkAll',
	                data:{
	                    categoryId: curCategoryId
	                }
	            },function(){
	                g2.reload();
	            }, true);
	        },
	        function(){}
	    );
	});

	//查看更多销售类目
	$(document).on("click", ".moreCategory", function () {
	    if($(this).hasClass('open')){
	        $(this).text('显示更多').removeClass('open').prev('ul').hide().prev('span').show();
	    }else{
	        $(this).text('收起更多').addClass('open').prev('ul').show().prev('span').hide();
	    }
	});

	//筛选
	$(document).on("click", ".filter-btn", function () {
	    if(curTab == 0){
	        g1.reload();
	    }else{
	        g2.reload();
	    }
	});

/***/ }
]);