limit-add.js
4.71 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
/*
*@time: 2016/2/15
*@author: chenglong
*/
var $ = require('jquery'),
common=require('../common/common'),
edit = require('../common/edit');
require('../common/bootstrap-wysihtml5');
require('../util/datepicker');
require('../util/wangEditor');
// var uploadImg = new edit('#coverImgBox');
// //
// uploadImg.init();
/*var editor = new wangEditor('editor-container');
editor.config.menus = [
'source',
'|',
'img',
'vedio'
];
editor.create();*/
//日期插件
$('#saleTime').fdatepicker({
format: 'yyyy-mm-dd'
});
$('#saleTime').on('change', function() {
console.log($(this).val());
})
var $editor = $('#editor');
$('body').on('click', '#textDialog', function() {
common.dialog.confirm("添加文本",'<textarea id="text-editor"></textarea>',function(){
var textStr = $('#text-editor').val();
var $oText = $('<div class="quota-content quota-text" data-type="3"><span>' + textStr + '</span><a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>');
$oText.appendTo($editor);
});
$('#text-editor').wysihtml5();
return false;
});
$('body').on('click', '#picDialog', function() {
common.dialog.confirm("添加图片",common.util.__template($("#picDialogTemp").html(),{name:"图片"}),function(){
var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">';
var $oImg = $('<div class="quota-content quota-img" data-type="1">' + imgStr + '<a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>');
$oImg.appendTo($editor);
});
return false;
});
$('body').on('click', '#videoDialog', function() {
common.dialog.confirm("添加视频",common.util.__template($("#picDialogTemp").html(),{name:"视频"}),function(){
/*var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">';
var $oVideo = $('<div class="quota-imf"><img src="' + imgStr + '" alt="" /></div>');
$('.quota-video').html(imgStr);*/
});
return false;
});
// 表单验证
var limitAddForm = new edit("#limit-add-form");
limitAddForm.init();
$('.limit-add-btn').click(function () {
var $this = $(this);
limitAddForm.submit($('#limit-add-form').attr('action'), function(option, that) {
option.beforeSend = function () {
$this.attr('disabled', 'disabled');
};
option.success=function(res){
console.log(res);
if (res.data.code == 200) {
limitAddForm.$tip('提交成功',function(){
//window.location.href = '/limit/product/index';
}, 'growl-success');
$this.removeAttr('disabled');
}
};
option.error=function(res){
limitAddForm.$tip(res.message);
$this.removeAttr('disabled');
};
//option.data.time = $('#saleTime').val();
option.data.attachmentContent = [];
option.data.attachmentContent.push({
attachUrl:option.data.coverImg,
isDefault: 1,
attachType: 1,
orderBy: 0
});
if ($('.quota-content').size() > 0) {
$('.quota-content').each(function(i) {
var type = $(this).data('type'),
content = '',
obj = {
attachType: type,
isDefault: 0,
orderBy: i
}
if (type == 3) {
content = $(this).find('span').text();
obj.intro = content;
} else if (type == 1) {
content = $(this).find('img').attr('src');
obj.attachUrl = content;
}
option.data.attachmentContent.push(obj)
});
}
console.log(option.data);
option.data.attachmentContent = JSON.stringify(option.data.attachmentContent);
option.data.saleTime = new Date(option.data.saleTime.replace('-',',')).getTime() / 1000;
});
});
$('#saleTime').val(function() {
if ($(this).data('time')) {
var date = new Date($(this).data('time') * 1000);
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
}
})
$('#limit-add-form').on('click', '.editor-delete', function() {
$(this).parents('.quota-content').remove();
});