Authored by liuyue

限售商品

... ... @@ -37,14 +37,14 @@ $('#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>');
$('.quota-text').html(textStr);
console.log(textStr);
$oText.appendTo($editor);
});
$('#text-editor').wysihtml5();
... ... @@ -54,17 +54,19 @@ $('#saleTime').on('change', 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>');
$('.quota-img').html(imgStr);
$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 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);
$('.quota-video').html(imgStr);*/
});
return false;
});
... ... @@ -79,7 +81,7 @@ $('.limit-add-btn').click(function () {
var $this = $(this);
limitAddForm.submit('/limit/product/new', function(option, that) {
limitAddForm.submit($('#limit-add-form').attr('action'), function(option, that) {
option.beforeSend = function () {
$this.attr('disabled', 'disabled');
};
... ... @@ -89,7 +91,7 @@ $('.limit-add-btn').click(function () {
if (res.data.code == 200) {
limitAddForm.$tip('提交成功',function(){
window.location.href = '/limit/product/index';
//window.location.href = '/limit/product/index';
}, 'growl-success');
$this.removeAttr('disabled');
... ... @@ -101,6 +103,7 @@ $('.limit-add-btn').click(function () {
limitAddForm.$tip(res.message);
$this.removeAttr('disabled');
};
//option.data.time = $('#saleTime').val();
option.data.attachmentContent = [];
option.data.attachmentContent.push({
attachUrl:option.data.coverImg,
... ... @@ -108,10 +111,43 @@ $('.limit-add-btn').click(function () {
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;
console.log(option.data);
});
});
$('#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();
});
... ...
... ... @@ -48,9 +48,10 @@ exports.res = [
method: 'GET',
view: 'pages/limit/add',
src: '/product/limit-add',
noApi: true,
isJsonRaw:true,
data: {
data: {}
data: {},
action: '/limit/product/new'
}
},{
// 【限购商品】ajax添加
... ... @@ -60,6 +61,10 @@ exports.res = [
isJsonRaw:true,
params: [
{
name: 'productName',
type: 'String'
},
{
name: 'attachmentContent',
type: 'String'
},
... ... @@ -80,6 +85,7 @@ exports.res = [
type: 'Number'
}
]
}, {
route: '/limit/edit/:id',
method: 'GET',
... ... @@ -101,6 +107,14 @@ exports.res = [
isJsonRaw: true,
params: [
{
name: 'id',
type: 'Number'
},
{
name: 'productName',
type: 'String'
},
{
name: 'attachmentContent',
type: 'String'
},
... ...
... ... @@ -6,14 +6,14 @@ exports.uploadFile=function(req,res){
// TODO 代理上传
// 方法1
// if(req.is("multipart/form-data")){
// req.body.file=fs.createReadStream(req.files[req.body.filename].path);
// request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){
// res.json(JSON.parse(body));
// });
// }else{
// res.json({code:"500",message:"请求类型错误"});
// }
/*if(req.is("multipart/form-data")){
req.body.file=fs.createReadStream(req.files[req.body.filename].path);
request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){
res.json(JSON.parse(body));
});
}else{
res.json({code:"500",message:"请求类型错误"});
}*/
res.json({
"code":200,
"data" : "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80",
... ...
... ... @@ -17,7 +17,7 @@
<div class="contentpanel">
<form id="limit-add-form" action="/limit/product/new">
<form id="limit-add-form" action="{{action}}">
{{# data}}
<div class="panel-group">
<div class="pannel">
... ... @@ -41,7 +41,7 @@
<div class="row mt20">
<div class="col-md-1 height40"><label>发售日期*:</label></div>
<div class="col-md-1">
<input id="saleTime" value="{{saleTime}}" type="text" class="form-control" style="width:280px;" placeholder="发售日期" readonly required>
<input id="saleTime" data-time="{{saleTime}}" value="" type="text" class="form-control" style="width:280px;" placeholder="发售日期" readonly required>
</div>
</div>
</div>
... ... @@ -85,16 +85,36 @@
<div class="row mb20">
<h6><label>封面图*:</label></h6>
<div class="col-md-1" id="coverImgBox">
{{# attachment}}
{{#if isDefault}}
<input type="file" name="coverImg" id="coverImg" value="{{attachUrl}}" placeholder="封面图" required/>
{{/if}}
{{/ attachment}}
{{^ attachment}}
<input type="file" name="coverImg" id="coverImg" placeholder="封面图" required/>
{{/ attachment}}
<input type="file" name="coverImg" id="coverImg" placeholder="" required/>
</div>
</div>
<div class="row mb20">
<div class="col-md-12">
<div class="quota-text"></div>
<div id="editor" class="col-md-12">
<!-- <div class="quota-text"></div>
<div class="quota-img"></div>
<div class="quota-video"></div>
<div class="quota-video"></div> -->
{{# attachment}}
{{#if attachUrl}}
{{#unless isDefault}}
<div class="quota-content quota-img" data-type="{{attachType}}"><img src="{{attachUrl}}" alt=""><a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>
{{/unless}}
{{/if}}
{{#if intro}}
<div class="quota-content quota-text" data-type="{{attachType}}"><span>{{intro}}</span><a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>
{{/if}}
{{/ attachment}}
</div>
</div>
... ... @@ -116,8 +136,9 @@
</div>
</div>
</div>
{{/ data}}
<input type="hidden" id="id" value="{{id}}">
</form>
{{/ data}}
</div>
... ...