baserule.CateSizeAttr.js 9.01 KB
webpackJsonp([8],{

/***/ 0:
/***/ function(module, exports, __webpack_require__) {

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

	sortmenu.init(function () {
	    g.init('/erpproduct/sortattribute/ajax/index');
	});

	var g = new common.grid({
	    el: "#basicTable",
	    parms: function () {
	        return {
	            sortId: window.sortid ? window.sortid : ""
	        };
	    },
	    columns: [
	        //分类ID  分类名称    尺码属性ID  尺码属性名   排序  操作
	        {display: "分类ID", name: "sortId"},
	        {display: "分类名称", name: "sortName"},
	        {display: "尺码属性ID", name: "attributeId"},
	        {display: "尺码属性名", name: "attributeName"},
	        {display: "排序", name: "orderBy"},
	        {
	            display: "操作", render: function (item) {
	            var htmlArr = [];
	            // 子类目不能删除父类目所创建的属性
	            if (window.sortid == item.sortId) {
	                htmlArr.push('<a data-index="' + item.__index + '" href="javascript:void(0)" class="btn btn-success btn-xs delbtn">删除</a>')
	                htmlArr.push('<a data-index="' + item.__index + '" href="javascript:void(0)" class="btn btn-primary btn-xs editBtn">修改</a>')
	            }
	            return htmlArr.join("");
	        }
	        }
	    ]
	});


	/**
	 * 验证
	 */
	var edit = new common.edit2(".modal-body");

	/**
	 * 通用
	 * @type {{module: null, toast: Bll.toast}}
	 */
	var Bll = {
	    module: null,
	    attri: [],
	    orderBys: [],
	    getOrderBy: function () {
	        common.util.__ajax({
	            url: '/erpproduct/sortattribute/ajax/index',
	            data: {
	                "sortId": window.sortid ? window.sortid : ""
	            }
	        }, function (res) {
	            Bll.orderBys = [];
	            if (res.data && res.data.list) {
	                var list = res.data.list;
	                list.forEach(function (x) {
	                    if (x.orderBy != 0) {
	                        Bll.orderBys.push(x.orderBy);
	                    }
	                })
	            }
	        }, true);
	    },
	    dropDown: function () {
	        common.util.__ajax({
	            url: '/erpproduct/sortattribute/ajax/automatic',
	            data: {
	                "sortId": window.sortid ? window.sortid : ""
	            }
	        }, function (res) {
	            $("#attri-content").html(common.util.__template2($("#search-attri").html(), res));
	            new common.dropDown({el: "#choose-attri"});
	            Bll.attri = res.data;
	        }, true);
	    },
	    //弹框
	    toast: function (hint, module, url) {
	        Bll.module = module;
	        Bll.getOrderBy();
	        if (Bll.module.__state == 'add') {
	            Bll.dropDown();
	        }
	        var d = new common.dialog({
	            title: hint + "尺码属性",
	            content: common.util.__template2($("#template").html(), Bll.module),
	            width: '30%',
	            button: [
	                {
	                    value: "保存",
	                    callback: function () {
	                        var flag = true;
	                        if (Bll.orderBys.length > 0) {
	                            for (var i = 0; i < Bll.orderBys.length; i++) {
	                                if (Bll.orderBys[i] == Bll.module.orderBy) {
	                                    flag = false;
	                                    common.util.__tip("排序值不可重复", "warning");
	                                }
	                            }
	                        }
	                        if (edit.validate() && flag) {
	                            common.util.__ajax({
	                                url: url,
	                                data: Bll.module
	                            }, function () {
	                                g.reload();
	                                d.close();
	                            });
	                        }
	                        return false;
	                    },
	                    css: "btn-primary"
	                },
	                {
	                    "value": "取消",
	                    "css": "btn-info"
	                }
	            ]
	        });
	        edit.init();
	    }
	};
	/**
	 * 监听输入框变化
	 */
	$(document).on("change", ".observe", function () {
	    var $this = $(this);
	    var name = $this.data("field");
	    Bll.module = common.util.__buildobj(name, '.', Bll.module, function (obj, name1) {
	        obj[name1] = $this.val();
	    });
	});
	/**
	 * 添加
	 */
	$(document).on("click", "#btn-add", function () {
	    var item = {
	        __state: "add",
	        name: "尺码属性",
	        sortName: window.sortname,
	        sortId: window.sortid,
	        attributeName: "",
	        attributeId: "",
	        orderBy: 0
	    };
	    Bll.toast("新增", item, '/erpproduct/sortattribute/ajax/add');
	});
	/**
	 * 修改
	 */
	$(document).on("click", ".editBtn", function () {
	    var item = g.rows[$(this).data("index")];
	    item = $.extend(true, {}, item);
	    item.__state = "update";
	    item.name = "尺码属性";
	    Bll.toast("修改", item, "/sortAttribute/updateOrderBy");
	});
	/**
	 * 删除
	 */
	$(document).on("click", ".delbtn", function () {
	    var item = g.rows[$(this).data("index")];
	    common.dialog.confirm("温馨提示", "你确定要删除吗?", function () {
	        common.util.__ajax({
	            url: '/erpproduct/sortattribute/ajax/delete',
	            data: {sortId: item.sortId, attributeId: item.attributeId}
	        }, function () {
	            g.reload();
	        });
	    });
	});
	/**
	 * 下拉变化
	 */
	$(document).on("change", "#choose-attri", function () {
	    var attributeId = $(this).val();
	    Bll.module.attributeId = attributeId;
	    for (var i = 0; i < Bll.attri.length; i++) {
	        if (Bll.attri[i].id == attributeId) {
	            Bll.module.attributeName = Bll.attri[i].text;
	        }
	    }
	});

	$("#cateSizeListUL .level1, #cateSizeListUL .level2").click(function() {
	    $("#btn-add").prop("disabled", true);
	});

/***/ },

/***/ 30:
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	var $ = __webpack_require__(1);

	var init=function(callback){
	    var $navItem = $('.list-group-item');
	    var $navIcon = $navItem.find('span.icon');
	    $navItem.each(function() {

	        if ($(this).hasClass('level1') && !$(this).next().hasClass('level2') || $(this).hasClass('level2') && !$(this).next().hasClass('level3') || $(this).hasClass('level3') && !$(this).next().hasClass('level4')) {
	            $(this).find('.expand-icon').css('visibility', 'hidden');
	        }
	    });

	    $navItem.click(function (event) {
	        var $this = $(this),
	            $thisNext = $this.nextAll(),
	            thisVal = $(this).attr('data-val'),
	            $target = $(event.target);
	        if (!$this.attr('data-active')) {
	            if ($target.hasClass('list-group-item')) {
	                $navItem.removeClass('attr-item-active');
	                $(this).addClass('attr-item-active').attr('data-active', 'data-active');
	                 if ($this.attr('data-level') && ($this.attr('data-level') == 1 || $this.attr('data-level') == 2)) {   // 一级 二级品类下面不能新增挂靠尺码
	                    $('.model-attr-btn').attr('disabled', 'disabled');
	                } else {
	                    $('.model-attr-btn').removeAttr('disabled');
	                }
	                $('input#categoryId').val($this.attr('data-val'));
	            }
	        } else {
	            if ($target.hasClass('list-group-item')) {
	                $(this).removeClass('attr-item-active').removeAttr('data-active');
	                $('.model-attr-btn').attr('disabled', 'disabled');
	            }
	        }

	        if ($this.attr('data-status') === 'close') {
	            if ($target.hasClass('icon')) {
	                $thisNext.filter(function (index) {
	                    return $(this).attr('data-parent') === thisVal;
	                }).removeClass('hidden');
	                $this.attr('data-status', 'open').find('span')
	                    .removeClass('glyphicon-plus').addClass('glyphicon-minus');
	            }
	        } else {
	            if ($target.hasClass('icon')) {
	                $thisNext.filter(function (index) {
	                    var thisR = $(this).attr('data-parent') === thisVal;
	                    if (thisR && $(this).attr('data-status') === 'open') {
	                        $(this).find('span.icon').trigger('click');
	                    }
	                    return thisR;
	                }).addClass('hidden');
	                $this.attr('data-status', 'close').find('span')
	                    .removeClass('glyphicon-minus').addClass('glyphicon-plus');
	            }
	        }
	        window.sortid=thisVal;
	        window.sortname=$.trim($(".attr-item-active[data-val="+thisVal+"]").text());//c.join('/');
	        callback&&callback();
	    });

	}

	module.exports={init:init};

/***/ }

});