index.js
4.52 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
*@time: 2016/1/26
*@author: chenglong
*/
var $ = require('jquery');
var edit = require('../common/edit');
var dropDown = require('../common/dropDown');
require('../util/select2');
exports.init = function () {
//列表展示效果
var $toggleTd = $('.toggle-td');
$toggleTd.click(function () {
var $this = $(this),
$thisNext = $this.closest('tr').nextAll(),
thisVal = $(this).closest('tr').attr('data-val');
if ($this.closest('tr').attr('data-status') === 'close') {
$thisNext.filter(function (index) {
return $(this).attr('data-parent') === thisVal;
}).removeClass('hidden');
$this.closest('tr').attr('data-status', 'open').find('.toggle-td').find('span')
.removeClass('glyphicon-folder-close').addClass('glyphicon-folder-open');
} else {
$thisNext.filter(function (index) {
var thisR = $(this).attr('data-parent') === thisVal;
if (thisR && $(this).attr('data-status') === 'open') {
$(this).find('.toggle-td').trigger('click');
}
return thisR;
}).addClass('hidden');
$this.closest('tr').attr('data-status', 'close').find('.toggle-td').find('span')
.removeClass('glyphicon-folder-open').addClass('glyphicon-folder-close');
}
});
//列表编辑
var $table = $('.toggle-table');
$table.click(function (event) {
var $target = $(event.target),
id;
//编辑
if ($target.hasClass('edit-class-btn')) {
} else if ($target.hasClass('open-close-btn')) {
var status;
if ($target.attr('data-status') === '1') {
status = 0;
} else if ($target.attr('data-status') === '0') {
status = 1;
}
console.log(status);
$.ajax({
type: 'POST',
dataType: 'json',
url: '/product/class/update',
data: {
id: $target.closest('td').attr('data-id'),
status: status
}
}).then(function (data) {
if (data.code === 200) {
$target.attr('data-status', status);
if ($target.hasClass('btn-danger')) {
$target.text('开启');
$target.removeClass('btn-danger')
.addClass('btn-warning').closest('td').prev('td').text('关闭');
} else {
$target.text('关闭');
$target.removeClass('btn-warning')
.addClass('btn-danger').closest('td').prev('td').text('开启');
}
}
});
event.preventDefault();
}
});
new dropDown({
el:'.level-select'
});
//产品属性列表三级导航
var $navItem = $('.list-group-item');
$navItem.click(function () {
var $this = $(this),
$thisNext = $this.nextAll(),
thisVal = $(this).attr('data-val');
if ($this.attr('data-status') === 'close') {
$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 {
$thisNext.filter(function (index) {
var thisR = $(this).attr('data-parent') === thisVal;
if (thisR && $(this).attr('data-status') === 'open') {
$(this).trigger('click');
}
return thisR;
}).addClass('hidden');
$this.attr('data-status', 'close').find('span')
.removeClass('glyphicon-minus').addClass('glyphicon-plus');
}
});
//添加属性
//表单验证
var addAttrVerification = new edit("#add-attr-form");
$('.add-attr-btn').click(function(){
addAttrVerification.submit($("#add-attr-form").attr("action"), function(option,that) {
option.success=function(res){
//todo
};
option.error=function(res){
//todo
}
});
return false;
});
//添加产品属性下拉框实例化
new dropDown({
el:'.attr-select'
});
};