index.js
5.48 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
/**
* 创建供应商
*/
'use strict';
var $ = require('jquery'),
dropDown=require('../common/dropDown');
var grid=require('../common/grid');
require('../util/jquery.gritter');
var select=require('../common/dropDown');
exports.menu=function(callback){
var $navItem = $('.list-group-item');
var $navIcon = $navItem.find('span.icon');
$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');
$('.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.menuid=thisVal;
//获取文案
// var c=[];
// function aa(a){
// var b=a.prev();
// if(b.length>0&&b.find(".glyphicon-minus")){
// aa(b);
// }
// c.push($.trim(a.text()));
// }
// aa($(".attr-item-active[data-val="+thisVal+"]"));
window.menuname=$.trim($(".attr-item-active[data-val="+thisVal+"]").text());//c.join('/');
callback&&callback();
});
}
exports.init = function() {
new select({
el:"#sizeId",
ajax:"sortsize"
});
var g=new grid({
el:"#basicTable",
parms:function(){
return {
sortId:window.menuid?window.menuid:"",
};
},
columns:[
//分类ID 分类名称 尺码ID 尺码名 排序 操作
{display:"分类ID",name:"sortId"},
{display:"分类名称",name:"sortName"},
{display:"尺码ID",name:"sizeId"},
{display:"尺码名",name:"sizeName"},
{display:"排序",name:"orderBy"},
{display:"操作",name:'id',render:function(item){
return '<a data-sortid="'+item.sortId+'" href="javascript:void(0)" class="btn btn-success btn-xs delbtn">删除</a>';
}}
]
});
exports.menu(function(){
g.init('/erpproduct/sortsize/ajax/index');
$("#sortName").val(window.menuname);
});
function __ajax(options,callback){
$.ajax({
type: 'POST',
url: options.url,
dataType: 'json',
data:options.data||{},
success: function(res) {
res=res.data;
if (res.code === 200) {
$.gritter.add({
title: res.message,
class_name: 'growl-success',
sticky: false,
time:1000,
after_open:setTimeout(function() {
callback&&callback();
},1000)
});
} else {
$.gritter.add({
title: res.message,
class_name: 'growl-danger',
sticky: false,
time:1000
});
}
}
});
}
$(document).on("click",".delbtn",function(){
var _sortid=$(this).data("sortid"),
_sizeid=$(this).data("sizeid");
__ajax({
url:'/erpproduct/sortsize/ajax/delete',
data:{sortId:_sortid,sizeId:_sizeid}
},function(){
g.reload();
$("#addAttr").modal('hide');
});
});
$(document).on("click",".add-attr-btn",function(){
var data={sortId:window.menuid,sizeId:$("#sizeId").val(),orderBy:$("#orderBy").val()};
if(!data.sortId){
alert("尺码不可为空");
return;
}
if(!~data.sizeId){
alert("尺码属性不可为空");
return;
}
if(!data.orderBy){
alert("排序不可为空");
return;
}
__ajax({
url:'/erpproduct/sortsize/ajax/add',
data:data
},function(){
g.reload();
$("#addAttr").modal('hide');
});
});
}