shop.ShopCategory.Edit.js 8.85 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 ENUM = {
	    status: {
	        '0': '未上架',
	        '1': '已上架'
	    }
	}

	var g1 = new common.grid({
	    el: '#productTable',
	    parms: function() {
	        return {
	            categoryId: curCategoryId,
	            productSKN: common.util.__input("productSKN"),
	            productName: common.util.__input("productName"),
	            maxSortId: tabTree.selected[0] ? tabTree.selected[0].id : "",
	            middleSortId: tabTree.selected[1] ? tabTree.selected[1].id : "",
	            smallSortId: tabTree.selected[2] ? tabTree.selected[2].id : "",
	            status: common.util.__input("status-select")
	        };
	    },
	    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: "storage"},
	        {display: "上下架状态", render: function(item) {
	            return ENUM.status[item.status];
	        }},
	        {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"),
	            maxSortId: tabTree.selected[0] ? tabTree.selected[0].id : "",
	            middleSortId: tabTree.selected[1] ? tabTree.selected[1].id : "",
	            smallSortId: tabTree.selected[2] ? tabTree.selected[2].id : "",
	            status: common.util.__input("status-select")
	        };
	    },
	    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: "storage"},
	        {display: "上下架状态", render: function(item) {
	            return ENUM.status[item.status];
	        }},
	        {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 tabTree = new common.tabTree("#sortTree");
	tabTree.init();

	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();
	    }
	});

/***/ }
]);