index.js
7.33 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
'use strict';
var $ = require('jquery'),
common = require('../common/common');
var renderHd = false;
var g = new common.grid({
el: "#basicTable",
parms: function() {
return {
state: $('.state-select').find('.current').find('input').val()
}
},
columns: [{
display: '',
name: 'foler',
render: function(item) {
var html = '';
if (!renderHd) {
html += $('#tableHdTemp').html();
html += common.util.__template2($('#tableTemp').html(), item);
renderHd = true;
} else {
html += common.util.__template2($('#tableTemp').html(), item);
}
return html;
}
}
]
});
g.init($("#gridurl").val());
//编辑排序
$(document).on('change', '.saleCategoryNumInput', function() {
if(checkNumInput($(this))){
$(this).removeClass("errorNumInput");
var categoryId = $(this).attr("categoryId");
var orderBy = $(this).val();
savePosition(categoryId,orderBy);
}
});
//排序框校验
function checkNumInput(inputObj){
if(inputObj.val()){
if(!isNaN(inputObj.val())){
if(inputObj.val() < 0){
inputObj.focus().select().addClass("errorNumInput");
common.util.__tip("排序数字请大于等于0!");
return false;
}
}else{
inputObj.focus().select().addClass("errorNumInput");
common.util.__tip("排序必须为数字!");
return false;
}
}else{
inputObj.focus().addClass("errorNumInput");
common.util.__tip("排序不能为空!");
return false;
}
return true;
}
//排序实时保存
function savePosition(categoryId, orderBy){
common.util.__ajax({
url:'/sale/salesCategory/updateSC',
data: {
"categoryId": categoryId,
"orderBy": orderBy
}
},function(rs){
common.util.__tip("排序保存成功!","success");
},true);
}
//打开层级类目
$(document).on('click', '.folder', function() {
var $wrap = $(this).parent();
if (!$(this).hasClass('open')) {
if ($wrap.find('.level-2-wrap').size() > 0) {
$wrap.find('.level-2-wrap').show();
$(this).addClass('open');
} else if ($wrap.find('.level-3-wrap').size() > 0) {
$wrap.find('.level-3-wrap').show();
$(this).addClass('open');
}
} else {
$(this).removeClass('open');
if ($wrap.find('.level-2-wrap').size() > 0) {
$wrap.find('.level-2-wrap').hide();
} else if ($wrap.find('.level-3-wrap').size() > 0) {
$wrap.find('.level-3-wrap').hide();
}
}
});
var e = null,
tabTree = null,
tabTreeArr = [],
editHtml = $('#editTemp').html();
function initForm(data) {
common.dialog.open({
title: '销售类目编辑',
content: common.util.__template2(editHtml, data),
width: 900
});
e = new common.edit('#basicForm', {
bucket: 'taobaocms'
});
e.init();
}
//添加根分类
$('#add-root-category').on('click', function() {
var data = {};
data.action = '/sale/salesCategory/addSC';
initForm(data);
tabTreeArr=[];
tabTree = new common.tabTree(".sortTree", {
status: 1,
sortLevel: 1
});
tabTree.init();
tabTreeArr.push(tabTree);
checkSortNum();
});
//添加子分类
$(document).on('click', '.add-sub-category', function() {
var categoryId = $(this).parent().data('id');
common.util.__ajax({
url: '/sale/salesCategory/querySCById',
data: {
categoryId: categoryId
}
}, function(res) {
var data = {};
data.action = '/sale/salesCategory/addSC';
data.parentSC = res.data.parentSC;
data.subCategoryName = res.data.categoryName;
data.parentId = res.data.categoryId;
initForm(data);
tabTreeArr = [];
tabTree = new common.tabTree(".sortTree", {
status: 1,
sortLevel: 1
});
tabTree.init();
tabTreeArr.push(tabTree);
checkSortNum();
}, true);
});
//编辑销售类目
$(document).on('click', '.edit-btn', function() {
var categoryId = $(this).parent().data('id');
common.util.__ajax({
url: '/sale/salesCategory/querySCById',
data: {
categoryId: categoryId
}
}, function(res) {
res.data.action = '/sale/salesCategory/updateSC';
initForm(res.data);
//渲染物理类目
var selectedArr = [];
$.each(res.data.relationProductSort, function(i, item) {
var sort = [{id: item.id, sortName: item.sortName}];
addSelected(sort, item);
selectedArr.push(sort);
});
if (selectedArr.length > 0) {
$('.sort-wrap').empty();
tabTreeArr = [];
$.each(selectedArr, function(i, item) {
var $sortGroup = $($('#sortWrap').html());
$sortGroup.appendTo($('.sort-wrap'));
checkSortNum();
tabTree = new common.tabTree(".sortTree:last", {
status: 1,
sortLevel: 1
});
tabTreeArr.push(tabTree);
tabTree.init(item);
});
} else {
tabTree = new common.tabTree(".sortTree", {
status: 1,
sortLevel: 1
});
tabTree.init();
tabTreeArr.push(tabTree);
}
}, true);
});
function addSelected(arr, item) {
if (item && item.parentPS) {
arr.unshift({id: item.parentPS.id, sortName: item.parentPS.sortName});
addSelected(arr, item.parentPS)
}
}
function checkSortNum() {
if ($('.sort-wrap').find('.row').size() > 1) {
$('.sort-wrap').find('.row').find('.add-sort-btn').hide().end().find('.del-sort-btn').show();
$('.sort-wrap').find('.row:last').find('.add-sort-btn').show().end().find('.del-sort-btn').show();
} else {
$('.sort-wrap').find('.row:first').find('.add-sort-btn').show().end().find('.del-sort-btn').hide();
}
}
//添加物理类目
$(document).on('click', '.add-sort-btn',function() {
var $sortGroup = $($('#sortWrap').html());
$sortGroup.appendTo($('.sort-wrap'));
tabTree = new common.tabTree(".sortTree:last", {
status: 1,
sortLevel: 1
});
tabTreeArr.push(tabTree);
tabTree.init();
checkSortNum();
});
//删除物理类目
$(document).on('click', '.del-sort-btn', function() {
var sortIndex = $(this).parents('.row').index();
$(this).parents('.row').remove();
tabTreeArr.splice(sortIndex, 1);
checkSortNum();
});
//保存销售类目
$(document).on('click', '#save_brand', function() {
e.submit($('#basicForm').attr('action'), function(option) {
var selected = [];
$.each(tabTreeArr, function(i, item){
if (item.selected.length > 0) {
selected.push(item.selected[item.selected.length - 1].id);
}
});
option.data.relationParameter = selected.join(',');
option.success = function(res) {
res = res.data;
if (res.code == '200') {
e.$tip(res.message, function() {
//location.reload();
}, 'growl-success');
} else {
e.$tip(res.message);
}
return false;
}
});
});
//开启销售类目
$(document).on('click', '.open-category', function() {
var categoryId = $(this).parent().data('id'),
categoryName = $(this).parent().data('name');
common.dialog.confirm("温馨提示", "确定开启(" + categoryName + ")分类吗", function() {
common.util.__ajax({
url: '/sale/salesCategory/updateSC',
data: {
categoryId: categoryId,
state: 1
}
}, function(res){
if (res.code == 200) {
g.reload();
}
})
});
})
//关闭销售类目
$(document).on('click', '.close-category', function() {
var categoryId = $(this).parent().data('id'),
categoryName = $(this).parent().data('name');
common.dialog.confirm("温馨提示", "确定关闭(" + categoryName + ")分类吗", function() {
common.util.__ajax({
url: '/sale/salesCategory/updateSC',
data: {
categoryId: categoryId,
state: 0
}
}, function(res){
if (res.code == 200) {
g.reload();
}
})
});
})
//切换状态重载列表
$('input[name="state"]').on('change', function() {
$(this).parent().addClass('current').siblings().removeClass('current');
g.reload();
});