Authored by liuyue

限售商品

@@ -36,15 +36,15 @@ $('#saleTime').fdatepicker({ @@ -36,15 +36,15 @@ $('#saleTime').fdatepicker({
36 $('#saleTime').on('change', function() { 36 $('#saleTime').on('change', function() {
37 console.log($(this).val()); 37 console.log($(this).val());
38 }) 38 })
39 - 39 +
  40 + var $editor = $('#editor');
40 $('body').on('click', '#textDialog', function() { 41 $('body').on('click', '#textDialog', function() {
41 common.dialog.confirm("添加文本",'<textarea id="text-editor"></textarea>',function(){ 42 common.dialog.confirm("添加文本",'<textarea id="text-editor"></textarea>',function(){
42 43
43 var textStr = $('#text-editor').val(); 44 var textStr = $('#text-editor').val();
  45 + 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>');
44 46
45 - $('.quota-text').html(textStr);  
46 -  
47 - console.log(textStr); 47 + $oText.appendTo($editor);
48 48
49 }); 49 });
50 $('#text-editor').wysihtml5(); 50 $('#text-editor').wysihtml5();
@@ -54,17 +54,19 @@ $('#saleTime').on('change', function() { @@ -54,17 +54,19 @@ $('#saleTime').on('change', function() {
54 common.dialog.confirm("添加图片",common.util.__template($("#picDialogTemp").html(),{name:"图片"}),function(){ 54 common.dialog.confirm("添加图片",common.util.__template($("#picDialogTemp").html(),{name:"图片"}),function(){
55 55
56 var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">'; 56 var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">';
  57 + var $oImg = $('<div class="quota-content quota-img" data-type="1">' + imgStr + '<a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>');
57 58
58 - $('.quota-img').html(imgStr); 59 + $oImg.appendTo($editor);
59 }); 60 });
60 return false; 61 return false;
61 }); 62 });
62 $('body').on('click', '#videoDialog', function() { 63 $('body').on('click', '#videoDialog', function() {
63 common.dialog.confirm("添加视频",common.util.__template($("#picDialogTemp").html(),{name:"视频"}),function(){ 64 common.dialog.confirm("添加视频",common.util.__template($("#picDialogTemp").html(),{name:"视频"}),function(){
64 65
65 - var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">'; 66 + /*var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">';
  67 + var $oVideo = $('<div class="quota-imf"><img src="' + imgStr + '" alt="" /></div>');
66 68
67 - $('.quota-video').html(imgStr); 69 + $('.quota-video').html(imgStr);*/
68 }); 70 });
69 return false; 71 return false;
70 }); 72 });
@@ -79,7 +81,7 @@ $('.limit-add-btn').click(function () { @@ -79,7 +81,7 @@ $('.limit-add-btn').click(function () {
79 81
80 var $this = $(this); 82 var $this = $(this);
81 83
82 - limitAddForm.submit('/limit/product/new', function(option, that) { 84 + limitAddForm.submit($('#limit-add-form').attr('action'), function(option, that) {
83 option.beforeSend = function () { 85 option.beforeSend = function () {
84 $this.attr('disabled', 'disabled'); 86 $this.attr('disabled', 'disabled');
85 }; 87 };
@@ -89,7 +91,7 @@ $('.limit-add-btn').click(function () { @@ -89,7 +91,7 @@ $('.limit-add-btn').click(function () {
89 if (res.data.code == 200) { 91 if (res.data.code == 200) {
90 92
91 limitAddForm.$tip('提交成功',function(){ 93 limitAddForm.$tip('提交成功',function(){
92 - window.location.href = '/limit/product/index'; 94 + //window.location.href = '/limit/product/index';
93 }, 'growl-success'); 95 }, 'growl-success');
94 $this.removeAttr('disabled'); 96 $this.removeAttr('disabled');
95 97
@@ -101,6 +103,7 @@ $('.limit-add-btn').click(function () { @@ -101,6 +103,7 @@ $('.limit-add-btn').click(function () {
101 limitAddForm.$tip(res.message); 103 limitAddForm.$tip(res.message);
102 $this.removeAttr('disabled'); 104 $this.removeAttr('disabled');
103 }; 105 };
  106 + //option.data.time = $('#saleTime').val();
104 option.data.attachmentContent = []; 107 option.data.attachmentContent = [];
105 option.data.attachmentContent.push({ 108 option.data.attachmentContent.push({
106 attachUrl:option.data.coverImg, 109 attachUrl:option.data.coverImg,
@@ -108,10 +111,43 @@ $('.limit-add-btn').click(function () { @@ -108,10 +111,43 @@ $('.limit-add-btn').click(function () {
108 attachType: 1, 111 attachType: 1,
109 orderBy: 0 112 orderBy: 0
110 }); 113 });
  114 + if ($('.quota-content').size() > 0) {
  115 + $('.quota-content').each(function(i) {
  116 + var type = $(this).data('type'),
  117 + content = '',
  118 + obj = {
  119 + attachType: type,
  120 + isDefault: 0,
  121 + orderBy: i
  122 + }
  123 +
  124 + if (type == 3) {
  125 + content = $(this).find('span').text();
  126 + obj.intro = content;
  127 + } else if (type == 1) {
  128 + content = $(this).find('img').attr('src');
  129 + obj.attachUrl = content;
  130 + }
  131 + option.data.attachmentContent.push(obj)
  132 + });
  133 + }
  134 + console.log(option.data);
111 option.data.attachmentContent = JSON.stringify(option.data.attachmentContent); 135 option.data.attachmentContent = JSON.stringify(option.data.attachmentContent);
112 136
113 137
114 option.data.saleTime = new Date(option.data.saleTime.replace('-',',')).getTime() / 1000; 138 option.data.saleTime = new Date(option.data.saleTime.replace('-',',')).getTime() / 1000;
115 - console.log(option.data); 139 +
116 }); 140 });
117 }); 141 });
  142 +
  143 +$('#saleTime').val(function() {
  144 + if ($(this).data('time')) {
  145 + var date = new Date($(this).data('time') * 1000);
  146 + return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
  147 + }
  148 +
  149 +})
  150 +
  151 +$('#limit-add-form').on('click', '.editor-delete', function() {
  152 + $(this).parents('.quota-content').remove();
  153 +});
@@ -48,9 +48,10 @@ exports.res = [ @@ -48,9 +48,10 @@ exports.res = [
48 method: 'GET', 48 method: 'GET',
49 view: 'pages/limit/add', 49 view: 'pages/limit/add',
50 src: '/product/limit-add', 50 src: '/product/limit-add',
51 - noApi: true, 51 + isJsonRaw:true,
52 data: { 52 data: {
53 - data: {} 53 + data: {},
  54 + action: '/limit/product/new'
54 } 55 }
55 },{ 56 },{
56 // 【限购商品】ajax添加 57 // 【限购商品】ajax添加
@@ -60,6 +61,10 @@ exports.res = [ @@ -60,6 +61,10 @@ exports.res = [
60 isJsonRaw:true, 61 isJsonRaw:true,
61 params: [ 62 params: [
62 { 63 {
  64 + name: 'productName',
  65 + type: 'String'
  66 + },
  67 + {
63 name: 'attachmentContent', 68 name: 'attachmentContent',
64 type: 'String' 69 type: 'String'
65 }, 70 },
@@ -80,6 +85,7 @@ exports.res = [ @@ -80,6 +85,7 @@ exports.res = [
80 type: 'Number' 85 type: 'Number'
81 } 86 }
82 ] 87 ]
  88 +
83 }, { 89 }, {
84 route: '/limit/edit/:id', 90 route: '/limit/edit/:id',
85 method: 'GET', 91 method: 'GET',
@@ -101,6 +107,14 @@ exports.res = [ @@ -101,6 +107,14 @@ exports.res = [
101 isJsonRaw: true, 107 isJsonRaw: true,
102 params: [ 108 params: [
103 { 109 {
  110 + name: 'id',
  111 + type: 'Number'
  112 + },
  113 + {
  114 + name: 'productName',
  115 + type: 'String'
  116 + },
  117 + {
104 name: 'attachmentContent', 118 name: 'attachmentContent',
105 type: 'String' 119 type: 'String'
106 }, 120 },
@@ -6,14 +6,14 @@ exports.uploadFile=function(req,res){ @@ -6,14 +6,14 @@ exports.uploadFile=function(req,res){
6 6
7 // TODO 代理上传 7 // TODO 代理上传
8 // 方法1 8 // 方法1
9 - // if(req.is("multipart/form-data")){  
10 - // req.body.file=fs.createReadStream(req.files[req.body.filename].path);  
11 - // request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){  
12 - // res.json(JSON.parse(body));  
13 - // });  
14 - // }else{  
15 - // res.json({code:"500",message:"请求类型错误"});  
16 - // } 9 + /*if(req.is("multipart/form-data")){
  10 + req.body.file=fs.createReadStream(req.files[req.body.filename].path);
  11 + request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){
  12 + res.json(JSON.parse(body));
  13 + });
  14 + }else{
  15 + res.json({code:"500",message:"请求类型错误"});
  16 + }*/
17 res.json({ 17 res.json({
18 "code":200, 18 "code":200,
19 "data" : "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80", 19 "data" : "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80",
@@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
17 17
18 <div class="contentpanel"> 18 <div class="contentpanel">
19 19
20 - <form id="limit-add-form" action="/limit/product/new">  
21 - {{# data}} 20 + <form id="limit-add-form" action="{{action}}">
  21 + {{# data}}
22 <div class="panel-group"> 22 <div class="panel-group">
23 <div class="pannel"> 23 <div class="pannel">
24 <div class="panel-heading"> 24 <div class="panel-heading">
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 <div class="row mt20"> 41 <div class="row mt20">
42 <div class="col-md-1 height40"><label>发售日期*:</label></div> 42 <div class="col-md-1 height40"><label>发售日期*:</label></div>
43 <div class="col-md-1"> 43 <div class="col-md-1">
44 - <input id="saleTime" value="{{saleTime}}" type="text" class="form-control" style="width:280px;" placeholder="发售日期" readonly required> 44 + <input id="saleTime" data-time="{{saleTime}}" value="" type="text" class="form-control" style="width:280px;" placeholder="发售日期" readonly required>
45 </div> 45 </div>
46 </div> 46 </div>
47 </div> 47 </div>
@@ -85,16 +85,36 @@ @@ -85,16 +85,36 @@
85 <div class="row mb20"> 85 <div class="row mb20">
86 <h6><label>封面图*:</label></h6> 86 <h6><label>封面图*:</label></h6>
87 <div class="col-md-1" id="coverImgBox"> 87 <div class="col-md-1" id="coverImgBox">
  88 + {{# attachment}}
  89 + {{#if isDefault}}
  90 + <input type="file" name="coverImg" id="coverImg" value="{{attachUrl}}" placeholder="封面图" required/>
  91 +
  92 + {{/if}}
  93 + {{/ attachment}}
  94 +
  95 + {{^ attachment}}
  96 + <input type="file" name="coverImg" id="coverImg" placeholder="封面图" required/>
  97 + {{/ attachment}}
88 98
89 - <input type="file" name="coverImg" id="coverImg" placeholder="" required/>  
90 </div> 99 </div>
91 </div> 100 </div>
92 101
93 <div class="row mb20"> 102 <div class="row mb20">
94 - <div class="col-md-12">  
95 - <div class="quota-text"></div> 103 + <div id="editor" class="col-md-12">
  104 + <!-- <div class="quota-text"></div>
96 <div class="quota-img"></div> 105 <div class="quota-img"></div>
97 - <div class="quota-video"></div> 106 + <div class="quota-video"></div> -->
  107 + {{# attachment}}
  108 + {{#if attachUrl}}
  109 + {{#unless isDefault}}
  110 + <div class="quota-content quota-img" data-type="{{attachType}}"><img src="{{attachUrl}}" alt=""><a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>
  111 + {{/unless}}
  112 + {{/if}}
  113 +
  114 + {{#if intro}}
  115 + <div class="quota-content quota-text" data-type="{{attachType}}"><span>{{intro}}</span><a href="javascript:;" class="editor-delete btn btn-default">删除</a></div>
  116 + {{/if}}
  117 + {{/ attachment}}
98 </div> 118 </div>
99 </div> 119 </div>
100 120
@@ -116,8 +136,9 @@ @@ -116,8 +136,9 @@
116 </div> 136 </div>
117 </div> 137 </div>
118 </div> 138 </div>
119 - {{/ data}} 139 + <input type="hidden" id="id" value="{{id}}">
120 </form> 140 </form>
  141 + {{/ data}}
121 </div> 142 </div>
122 143
123 144