sortmenu.js
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var $ = require('jquery');
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};