Index.js
6.86 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
/**
* Created by wangqianjun on 16/3/30.
*/
var $ = require('jquery');
common = require('../../../common/common');
var ZeroClipboard = require("../../../common/util/ZeroClipboard.min");
ZeroClipboard.config({swfPath: "http://cdn.yoho.cn/yohobuy-portal/assets/images/ZeroClipboard.swf"})
var imgArr = [];
var ENUM = {
HotEnum: {
'1': '是',
'0': '否',
},
StatusEnum: {
1: '可用',
2: '不可用',
},
GenderEnum: {
1: '男',
2: '女',
3: '通用',
},
}
//下拉框
new common.dropDown({
el: "#g-status"
});
new common.dropDown({
el: "#g-gender"
});
new common.dropDown({
el: "#g-brandType",
ajax: 'guangPlusSatrChannel',
params: {
status: 1
}
});
new common.dropDown({
el: "#g-brandId",
ajax: 'brand',
params: {
status: 1
}
});
// var client ;
var g = new common.grid({
el: '#basicTable',
size: 10,
parms: function () {
return {
brandType: common.util.__input('g-brandType'),
status: common.util.__input('g-status'),
brandId: common.util.__input('g-brandId'),
gender: common.util.__input('g-gender'),
};
},
columns: [
{
display: 'ID',
name: "id"
},
{
display: '品牌ID',
name: "brandId"
}, {
display: '品牌名称',
name: "brandName"
}, {
display: '频道名称',
name: "categoryName"
}, {
display: '性别',
render: function (item) {
return "<p>" + ENUM.GenderEnum[item.gender] + "</p>";
}
}, {
display: '是否可用',
render: function (item) {
return "<p>" + ENUM.StatusEnum[item.status] + "</p>";
}
},
{
display: '更新时间',
render: function (item) {
var t = new Date(item.updateTime * 1000);
var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
return "<p>" + formatted + "</p>";
}
},
{
display: '操作',
//}
name: "status",
render: function (items) {
var HtmArr = [];
HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs info-copy" data-clipboard-text="http://guang.m.yohobuy.com/plustar/brandinfo?id=' + items.id + '" id="copy-' + items.__index + '">复制链接</a>');
HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-info btn-xs info-modify">查看 / 编辑</a>');
HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs info-del">删除</a>');
return HtmArr.join('');
}
}],
complete: function () {
new ZeroClipboard($(".info-copy"));
}
});
g.init('/guang/plustar/getList');
//==================== 按钮点击事件 =====================//
$("#filter-btn").click(function () {
g.reload(1);
});
//添加
$(document).on('click', '#add-btn', function () {
plusStarOP("新增", '/guang/plustar/addPlustar', {});
});
//编辑
$(document).on('click', '.info-modify', function () {
var item = g.rows[$(this).data("index")];
common.util.__ajax(
{
url: '/guang/plustar/getDetail',
data: {
id: item.id,
}
}, function (res) {
//var item = res.data;
plusStarOP("编辑", '/guang/plustar/updatePlustar', res.data);
}, true);
});
$(document).on('click', '.info-copy', function () {
common.util.__tip("链接已复制好,可贴粘", "success")
});
//删除
$(document).on('click', '.info-del', function () {
var item = g.rows[$(this).data("index")];
common.dialog.confirm("温馨提示", "确定要删除该品牌?", function () {
common.util.__ajax({
url: '/guang/plustar/delPlustar',
data: {
id: item.id,
}
}, function (res) {
if (res.code == 200) {
g.reload();
}
});
});
});
function plusStarOP(prefix, url, item) {
var a = new common.edit("#templete-top", {
"bucket": "plustar"
});
a.on("validate", function () {
if (imgArr.length == 0) {
return "请上传banner图";
}
});
common.dialog.confirm(prefix + '品牌', common.util.__template2($("#template").html(), item), function () {
return a.submit(url, function (option) {
if (imgArr.length) {
option.data.bannerImg = imgArr.toString();
}
imgArr = [];
option.success = function (res) {
if (res.code == "200") {
a.$tip("提交成功", function () {
g.reload();
}, 'growl-success');
} else {
a.$tip(res.message);
}
return false;
},
option.error = function (res) {
a.$tip(res.message);
}
});
});
$(".modal-dialog").css("width","800px");
a.init();
if (prefix == "编辑") {
imgArr = item.bannerImg || [];
$('#brandId').attr('disabled', true);
} else {
imgArr = [];
$('#brandId').attr('disabled', false);
}
uploadImage();
rendBoList(imgArr);
new common.dropDown({
el: "#brandType",
ajax: 'guangPlusSatrChannel',
params: {
status: 1
}
});
new common.dropDown({
el: "#brandId",
ajax: 'brand',
params: {
status: 1
}
});
}
// 图片上传
function uploadImage() {
common.edit.ajaxfileupload(".picfile", {
params: {
__type: "upload",
bucket: "plustar"
},
valid_extensions: ['png', 'jpg', 'jpeg'],
onComplete: function (response) {
if (response.status && response.code == 200) {
console.log("response", response);
if (response.data) {
imgArr.push(response.data);
rendBoList(imgArr);
}
}
else {
common.util.__tip(response.message, 'warning');
}
}
});
}
function rendBoList(pictureBoList) {
$(".image-list").html('');
$("#addPic").append(common.util.__template2($("#imgeUpload").html(),
{
pictureBoList: pictureBoList
}
));
}
//删除单张图片
$(document).on('click', '.remove1', function () {
var index = $(this).data("index");
imgArr.splice(index, 1);
rendBoList(imgArr);
});