shop.ShopCategory.Edit.js
7.79 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
webpackJsonp([16],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var $ = __webpack_require__(1),
common = __webpack_require__(2);
var curCategoryId = 0,
selectedNum = 0,
curTab = 0;
var g1 = new common.grid({
el: '#productTable',
parms: function() {
return {
categoryId: curCategoryId,
productSKN: common.util.__input("productSKN"),
productName: common.util.__input("productName")
};
},
columns: [
{
display: '商品图片',
name: 'productPic',
render: function (item) {
if (item.productPic) {
return '<a class="list-img" target="_blank" href="' + item.productPic + '">' +
'<img src="' + item.productPic + '"></a>';
} else {
return '';
}
}},
{display: "SKN", name: "productSKN"},
{display: "商品名称", name: "productName"},
{display: "销售价(元)", name: "salePrice"},
{display: "分类", name: "productSort"},
{display: "商品分类", render: function (item) {
var name = item.categoryName ? item.categoryName : '未分类';
var categoryList = '<span class="name" style="display: block; text-align: center">'+ name +'</span>';
if(item.saleCategory && item.saleCategory.length > 1){
categoryList += '<ul class="list" style="display: none;margin: 0; padding: 0;text-align:center">';
for(var i=0; i<item.saleCategory.length; i++){
categoryList += '<li>'+item.saleCategory[i]+'</li>'
}
categoryList += '</ul>' +
'<a href="javascript:" class="moreCategory" style="display: block;text-align: center;color:#999">显示更多</a>';
}
return categoryList;
}},
{display: "操作", render: function (item) {
if(item.checked){
return '<a href="javascript:" class="btn btn-warning btn-xs cancelProduct" data-index="'+item.__index+'">取消选择</a>'
}else{
return '<a href="javascript:" class="btn btn-success btn-xs selectProduct" data-index="'+item.__index+'">选择</a>'
}
}}
],
complete2: function (res) {
selectedNum = res.data.checkedCount;
$('.selectedProductsNum').text(selectedNum);
}
});
var g2 = new common.grid({
el: '#productTable',
parms: function() {
return {
categoryId: curCategoryId,
productSKN: common.util.__input("productSKN"),
productName: common.util.__input("productName")
};
},
columns: [
{
display: '商品图片',
name: 'productPic',
render: function (item) {
if (item.productPic) {
return '<a class="list-img" target="_blank" href="' + item.productPic + '">' +
'<img src="' + item.productPic + '"></a>';
} else {
return '';
}
}},
{display: "SKN", name: "productSKN"},
{display: "商品名称", name: "productName"},
{display: "销售价(元)", name: "salePrice"},
{display: "分类", name: "productSort"},
{display: "商品分类", render: function (item) {
var name = item.categoryName ? item.categoryName : '未分类';
var categoryList = '<span class="name" style="display: block; text-align: center">'+ name +'</span>';
if(item.saleCategory && item.saleCategory.length > 1){
categoryList += '<ul class="list" style="display: none;margin: 0; padding: 0;text-align:center">';
for(var i=0; i<item.saleCategory.length; i++){
categoryList += '<li>'+item.saleCategory[i]+'</li>'
}
categoryList += '</ul>' +
'<a href="javascript:" class="moreCategory" style="display: block;text-align: center;color:#999">显示更多</a>';
}
return categoryList;
}},
{display: "操作", render: function (item) {
return '<a href="javascript:" class="btn btn-warning btn-xs cancelProduct" data-index="'+item.__index+'">取消选择</a>'
}}
],
complete2: function (res) {
selectedNum = res.data.list.length;
$('.selectedProductsNum').text(selectedNum);
}
});
var Bll = {
init: function () {
this.getParamsInUrl();
g1.init('/shops/shopCategory/allProducts');
},
getParamsInUrl: function () {
var paramUrl = location.href + "";
if(paramUrl.indexOf("edit") > 0){
var param = paramUrl.substring(paramUrl.indexOf("edit"));
var paramList = param.split("/");
curCategoryId = paramList[1];
}
}
};
Bll.init();
//tab切换
$(document).on("click", ".nav-tabs li", function () {
if($(this).hasClass('active')) return false;
$(this).addClass('active').siblings().removeClass('active');
curTab = $(this).index();
switch (curTab){
case 0:
$('.cancelAll').hide();
g1.init('/shops/shopCategory/allProducts');
break;
case 1:
$('.cancelAll').show();
g2.init('/shops/shopCategory/selectedProducts');
break;
}
});
//选择商品
$(document).on("click", ".selectProduct", function () {
var self = this;
var index = $(self).data("index");
var item = g1.rows[index];
common.util.__ajax({
url:'/shops/shopCategory/link',
data:{
categoryId: curCategoryId,
productSKN: item.productSKN
}
},function(){
$(self).parent().html('<a href="javascript:" class="btn btn-warning btn-xs cancelProduct" data-index="'+index+'">取消选择</a>');
$('.selectedProductsNum').text(++selectedNum);
}, true);
});
//在全部商品中,取消选择商品
$(document).on("click", ".cancelProduct", function () {
var self = this;
var index = $(self).data("index");
var g = curTab == 0 ? g1 : g2;
var item = g.rows[index];
common.util.__ajax({
url:'/shops/shopCategory/unlink',
data:{
categoryId: curCategoryId,
productSKN: item.productSKN
}
},function(){
if(curTab == 0){
$(self).parent().html('<a href="javascript:" class="btn btn-success btn-xs selectProduct" data-index="'+index+'">选择</a>');
$('.selectedProductsNum').text(--selectedNum);
}
if(curTab == 1){
g2.reload();
}
}, true);
});
//全部取消选择
$(document).on("click", ".cancelAll", function () {
common.dialog.confirm(
"温馨提示", "你确定全部取消选择所有商品么?",
function(){
common.util.__ajax({
url:'/shops/shopCategory/unlinkAll',
data:{
categoryId: curCategoryId
}
},function(){
g2.reload();
}, true);
},
function(){}
);
});
//查看更多销售类目
$(document).on("click", ".moreCategory", function () {
if($(this).hasClass('open')){
$(this).text('显示更多').removeClass('open').prev('ul').hide().prev('span').show();
}else{
$(this).text('收起更多').addClass('open').prev('ul').show().prev('span').hide();
}
});
//筛选
$(document).on("click", ".filter-btn", function () {
if(curTab == 0){
g1.reload();
}else{
g2.reload();
}
});
/***/ }
]);