limit-add.js
7.62 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
/*
*@time: 2016/2/15
*@author: chenglong
*/
var $ = require('jquery'),
common = require('../common/common');
require('../common/bootstrap-wysihtml5');
require('../util/datepicker');
var ENMA = {
attachType: {
1: "图片",
2: "视频",
3: "文本"
}
}
//测试数据
var g = new common.grid({
el: "#baseTable",
columns: [{
display: "标题",
render: function(item) {
if (item.isDefault == 1) {
return "默认封面图片";
}
return ENMA.attachType[item.attachType];
}
}, {
display: "内容",
render: function(item) {
item.orderBy == item.__index;
if (item.isDefault == 1) {
return '<input type="file" name="coverImg" id="coverImg" value="' + item.attachUrl + '" placeholder="封面图" required/>';
} else {
if (item.attachType == 1) {
return "<img src='" + item.attachUrl + "' style='width:120px;height:80px' />";
} else if (item.attachType == 2) {
return "<video src='" + item.attachUrl + "' controls></video>";
} else {
return item.attachUrl;
}
}
}
}, {
display: "操作",
render: function(item) {
var htmlArr = [];
if (!item.isDefault) {
htmlArr.push("<button type='button' data-index='" + item.__index + "' class='delete btn btn-danger btn-xs'>删除</button>");
htmlArr.push("<button type='button' data-index='" + item.__index + "' class='edit btn btn-info btn-xs'>编辑</button>");
}
return htmlArr.join(',');
}
}]
});
var __ac = $.trim($("#attachmentContent").val());
g.__rows = __ac ? JSON.parse(__ac) : [{
"attachType": 1,
"attachUrl": "",
"isDefault": 1
}];
g.init(g.__rows);
var e1 = new common.edit('#baseTable');
e1.on("callback", function(obj) {
if (obj.key == "file_onComplete_coverImg") {
g.__rows[0].attachUrl = obj.data;
}
});
e1.init();
var isSave = false;
$(window).on('beforeunload', function() {
if (!isSave) {
return '您输入的内容尚未保存';
}
});
//初始化form表单
var e = new common.edit('#editor-group');
e.on("validate", function() {
var param = {
batchNo: $('#batchNo').val(),
id: $("#id").val()
};
return common.util.__ajax({
url: '/limit/checkBatch',
async: true,
data: param
}, null, true);
});
e.on("validate", function() {
if (!g.__rows[0].attachUrl) {
return "请上传默认封面";
}
});
e.on("validate", function() {
var limitProductType = $("#limitProductType").val();
var activityId = $.trim($("#activityId").val());
if (limitProductType == 2 && activityId == "") {
return "请填写排队限购ID";
}
});
e.on("validate", function() {
var orderBy = $("#orderBy").val();
if (!/^(?:[1-9][0-9]*|0)$/.test(orderBy)) {
return '热门排序值输入格式不正确';
}
});
e.on("validate", function() {
var notSaleOrderBy = $('#notSaleOrderBy').val();
if (!/^(?:[1-9][0-9]*|0)$/.test(notSaleOrderBy)) {
return '未发售排序值输入格式不正确';
}
});
e.on("validate", function() {
var limitProductType = $("#limitProductType").val();
var activityId = $.trim($("#activityId").val());
if (limitProductType == 2 && activityId == "") {
return "请填写排队限购ID";
}
});
e.init();
//添加修改
$('.limit-add-btn').click(function(option) {
isSave = true;
e.submit($('#limit-add-form').attr('action'), function(option) {
//option.debug=true;
option.data.attachmentContent = JSON.stringify(g.__rows);
/*if ($('input[name="dayFlag"]:checked').val() == 0) {
saleTime = new Date(option.data.saleTime.slice(0, -3).replace(/-/g, '/'));
}*/
console.log(option.data);
option.beforeSend = function() {
$('#limit-add-btn').addClass('disabled');
};
option.success = function(res) {
res = res.data;
if (res.code == "200") {
e.$tip('提交成功', function() {
location.href = "/limit/product/index";
}, 'growl-success');
} else {
$('#limit-add-btn').removeClass('disabled');
e.$tip(res.message);
}
return false;
}
option.error = function(res) {
e.$tip("提交失败");
};
});
});
// var $editor = $('#editor'), //文字,图片,视频容器
// type = $('#limit-add-form').attr('type');
var Bll = {
imgVideo: function(title, item, index) {
if (item.attachType == 2 || item.__attachType == 2) {
item.extend = "mp4"
};
common.dialog.confirm(title, common.util.__template($("#picDialogTemp").html(), item), function() {
var _html = $.trim($("#imgVideoText").val());
if (_html) {
if (item.attachType) {
//修改
g.__rows[index].attachUrl = _html;
} else {
//添加
g.__rows.push({
"attachType": item.__attachType,
"attachUrl": _html,
"isDefault": 0,
"attachName": $("#attachName").val()
});
}
g.reload();
e1.init();
}
});
var a = new common.edit("#upload-wrapper");
a.on("callback", function(obj) {
if (obj.key == "file_onComplete_imgVideo") {
$("#imgVideoText").val(obj.data);
}
});
a.init();
},
wenZi: function(title, item, index) {
common.dialog.confirm(title, common.util.__template('<textarea id="text-editor">{attachUrl}</textarea>', item), function() {
var _html = $.trim($("#text-editor").val());
if (_html) {
if (item.attachType) {
//修改
g.__rows[index].attachUrl = _html;
} else {
//添加
g.__rows.push({
"attachType": 3,
"attachUrl": _html,
"isDefault": 0
});
}
g.reload();
e1.init();
}
});
$('#text-editor').wysihtml5();
}
}
//添加文字
$('body').on('click', '#textDialog', function() {
Bll.wenZi("添加文字", {});
return false;
});
$('body').on('click', '#picDialog', function() {
Bll.imgVideo("添加图片", {
name: "图片",
__attachType: 1
});
return false;
});
$('body').on('click', '#videoDialog', function() {
Bll.imgVideo("添加视频", {
name: "视频",
__attachType: 2
});
return false;
});
//删除
$('body').on('click', ".delete", function() {
var index = $(this).data("index");
g.__rows.splice(index, 1);
g.reload();
e1.init();
});
//修改
$('body').on('click', ".edit", function() {
var item = g.rows[$(this).data("index")];
Bll[item.attachType == 3 ? "wenZi" : "imgVideo"]("修改" + ENMA.attachType[item.attachType], item, $(this).data("index"));
});