operations.activitytemplate.Product.js
6.69 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
webpackJsonp([99],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/**
* Created by ty on 2016/7/4.
* 模板商品管理
*/
var $ = __webpack_require__(1), common = __webpack_require__(2);
var id = $("#basicForm").data("id");
/*下拉选择*/
new common.dropDown({
el: "#brandId",
ajax: "brand",
hash: true,
params:function(){
return {userLimitFlag:true};
}
});
var tabTree = new common.tabTree("#sort");
tabTree.init();
var g = new common.grid({
el: '#product-list',
parms: function () {
var select = tabTree.getAddress();
return {
templateId: id,
productSkn: common.util.__input("productSkn"),
brandId: common.util.__input("brandId"),
maxSortId: select[0] ? select[0].id : "",
middleSortId: select[1] ? select[1].id : "",
smallSortId: select[2] ? select[2].id : "",
sortId: select[3] ? select[3].id : ""
};
},
columns: [
{
display: '',
type: 'checkbox',
render: function (item) {
var htmlContent = "";
if(iList.length == 0 ){
htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
}else{
$.each(iList,function(n,value) {
if(item.id == value){
htmlContent = "<input type='checkbox' checked='checked' class='wqt_checkbox' data-index='"+item.__index+"'>";
return false
}else{
htmlContent = "<input type='checkbox' class='wqt_checkbox'data-index='"+item.__index+"'>";
}
})
}
return htmlContent;
}
},
{
display: "ID",
name: "id"
},
{
display: "SKN",
name: "productSkn"
},
{
display: '操作',
render: function (item) {
var HtmArr = [];
HtmArr.push(' 排序<input type="text" class="number" value="'+ item.orderBy +'" id="orderBy'+ item.__index +'"/>');
HtmArr.push(' <input type="checkbox" id="status'+ item.__index +'" '+ (item.status?"checked":"") +'>');
HtmArr.push('启用 ');
HtmArr.push('<a data-index="'+ item.__index +'" class="btn btn-primary btn-xs edit">修改</a>');
HtmArr.push('<a data-index="'+ item.__index +'" class="btn btn-danger btn-xs del">删除</a>');
return HtmArr.join('');
}
}
]
});
g.init("/activityTemplate/getProductListByCondition");
common.edit.ajaxfileupload("#uploadBox", {
params: {
type: "activityProduct",
__type: "batch-import",
args:id
},
valid_extensions: ['xls', 'xlsx'],
onComplete: function (response) {
if (response.status && response.code == 200) {
common.util.__tip(response.message, 'success');
g.reload();
}
else {
common.util.__tip(response.message, 'warning');
g.reload();
}
}
});
//编辑
$(document).on("click", ".edit", function () {
var index = $(this).data("index");
var item = g.rows[index];
var status = $("#status" + index).prop("checked") ? 1 : 0;
var isRecommend = item.isRecommend ? 1 : 0;
common.util.__ajax({
url: "/activityTemplate/updateProduct",
data: {
id:item.id,
isRecommend:isRecommend,
orderBy:$("#orderBy"+index).val(),
status: status
}
}, function () {
g.reload();
});
});
//删除
$(document).on("click", ".del", function () {
var index = $(this).data("index");
var item = g.rows[index];
common.dialog.confirm("温馨提示","你确定删除吗?",function() {
common.util.__ajax({
url: "/activityTemplate/delOneProduct",
data: {
id: item.id
}
}, function () {
g.reload();
});
});
});
$(document).on("click", "#filter-btn", function () {
g.reload(1);
});
//输入限制
$(document).on("keyup",".number", function () {
$(this).val($(this).val().replace(/\D/g, ''));
});
$(document).on("click", "#chooseFile", function () {
$("#uploadBox").click();
});
//批量删除
$(document).on("click","#batchDel",function(){
var len = iList.length;
if (len <= 0) {
common.util.__tip('请选择需要删除的数据', 'warning');
return;
}
var data = {
ids: iList.join(",")
};
common.dialog.confirm("温馨提示","你确定删除吗?",function() {
common.util.__ajax({
url: "/activityTemplate/batchDelProducts",
data: data
}, function () {
iList.splice(0,iList.length);
g.reload();
});
});
});
/*
*可通用于翻页勾选
* 将checkbox选中存入一个数组,勾选push,取消remove
* 进入页面判断id是否在数组中存在,如果存在,checked
*/
var iList = [];
$(document).on("change", ".wqt_checkbox", function () {
var checked = $(this).prop("checked");
var index = $(this).data("index");
var val = g.rows[index];
var index_;
if(checked){
iList.push(val['id']);
}else{
index_ = $.inArray(val['id'],iList);
iList.splice(index_,1);
}
console.log("iList:"+iList);
});
/**
* 全选事件
*/
$(g.grid).on("change", ".wqt_all", function() {
$(".wqt_checkbox").each(function () {
var checked = $(this).prop("checked");
var index = $(this).data("index");
var index_;
var val = g.rows[index];
if (checked) {
index_ = $.inArray(val['id'], iList);
if (index_ < 0) {
iList.push(val['id']);
}
} else {
index_ = $.inArray(val['id'], iList);
iList.splice(index_, 1);
}
});
console.log("iList:"+iList);
});
/** 清空 */
$(document).on("click", "#clearProduct", function() {
console.log(id);
common.dialog.confirm("温馨提示","你确定要清空所有商品吗?",function() {
common.util.__ajax({
url: "/activityTemplate/delProductByTemplateId",
data: {
templateId: id
}
}, function () {
g.reload(1);
});
});
});
/***/ }
]);