attr.js
6.41 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
/*
*@time: 2016/2/1
*@author: chenglong
*/
var $ = require('jquery');
var edit = require('../common/edit');
var dropDown = require('../common/dropDown');
var grid=require('../common/grid');
var baseNum = 1;
// 把Y、N转换成是、否
function convertNorY(val) {
if (val === 'N') {
return '否';
} else {
return '是';
}
}
var tableGird = new grid({
el:"#attr-table",
parms:function(){
console.log(window.categoryId);
return {
categoryId: window.categoryId * baseNum
};
},
columns:[
{display: "属性名称", name: "attributeName"},
{display: "属性类型",name: "attributeValues"},
{display: "输入类型",name: "inputType"},
{display: "是否必选",
name:"isMust",
render:function(item){
return convertNorY(item.isMust);
}
}, {
display: "是否可搜索",
name: "isSearch",
render: function(item){
return convertNorY(item.isSearch);
}
}, {
display:"操作",
name:"categoryId",
render:function(items){
return ('<button attribute-id="' + items.attributeId + '" class="btn btn-success btn-xs edit-class-btn">编辑</button>');
}
}
]
});
var $attributeName = $('#attributeName');
var $saleType = $('#saleType');
var $inputType = $('#inputType');
var $isMust = $('#isMust');
var $isSearch = $('#isSearch');
var $maxValueLen = $('#maxValueLen');
var $isAllowAlias = $('#isAllowAlias');
var $orderBy = $('#orderBy');
var $attributeValues = $('#attributeValues');
var $displayPosition = $('#displayPosition');
var $remark = $('#remark');
var $attributeId = $('#attributeId');
function removeAttr() {
$attributeName.val('');
$saleType.val('');
$inputType.val('');
$isMust.val('');
$isSearch.val('');
$maxValueLen.val('');
$isAllowAlias.val('');
$orderBy.val('');
$attributeValues.val('');
$displayPosition.val('');
$remark.val('');
$attributeId.val('');
}
//产品属性列表三级导航
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'));
//列表渲染
//queryAttrList($this.attr('data-val'));
window.categoryId = $this.attr('data-val');
tableGird.init('/product/attr/queryProductAttributeList');
}
} 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');
}
}
});
//添加属性
//表单验证
var addAttrVerification = new edit("#add-attr-form");
$('.add-attr-btn').click(function(){
if (!!$('#attributeName').attr('update')) {
$('#add-attr-form').attr('action','/product/attr/update');
}
addAttrVerification.submit($("#add-attr-form").attr("action"), function(option,that) {
option.success=function(res){
console.log(res);
$('#addAttr').modal('toggle');
removeAttr();
tableGird.reload();
};
option.error=function(res){
console.log(res);
}
});
return false;
});
// 编辑产品属性
$(document).on('click', '.edit-class-btn', function () {
var $this = $(this);
var attrId = $this.attr('attribute-id');
$.ajax({
type: 'POST',
dataType: 'json',
url: '/product/attr/getProductAttribute',
data: {
attributeId: attrId*baseNum
}
}).then(function (d) {
var data = d.data.data;
$attributeName.val(data.attributeName).attr('update', 'true');
$saleType.val(data.saleType);
$inputType.val(data.inputType);
$isMust.val(data.isMust);
$isSearch.val(data.isSearch);
$maxValueLen.val(data.maxValueLen);
$isAllowAlias.val(data.isAllowAlias);
$orderBy.val(data.orderBy);
$attributeValues.val(data.attributeValues);
$displayPosition.val(data.displayPosition);
$remark.val(data.remark);
$attributeId.val(attrId);
// 显示dialog
$('#addAttr').modal('toggle');
tableGird.reload();
console.log(d);
});
});
$('.add-attr-btn-close').click(function () {
removeAttr();
});