...
|
...
|
@@ -10,15 +10,19 @@ var $ = require('jquery'), |
|
|
require('../common/bootstrap-wysihtml5');
|
|
|
|
|
|
var ENMA={
|
|
|
attachType:{1:"图片",2:"视频",3:"文本"},
|
|
|
type:{}
|
|
|
attachType:{1:"图片",2:"视频",3:"文本"}
|
|
|
}
|
|
|
|
|
|
|
|
|
//日期插件
|
|
|
$('#saleTime').fdatepicker({
|
|
|
format: 'yyyy-mm-dd'
|
|
|
});
|
|
|
function getLocalTime(nS) {
|
|
|
var date= new Date(parseInt(nS) * 1000);
|
|
|
var mm=date.getMonth()+1;
|
|
|
var dd=date.getDate();
|
|
|
return date.getFullYear()+"-"+(mm<10?"0"+mm:mm)+"-"+(dd<10?"0"+dd:dd);
|
|
|
}
|
|
|
if($("#saleTime").data("time")){
|
|
|
var date=getLocalTime($("#saleTime").data("time"));
|
|
|
$("#saleTime").val(date);
|
|
|
}
|
|
|
|
|
|
//测试数据
|
|
|
var g=new common.grid({
|
...
|
...
|
@@ -31,8 +35,9 @@ var g=new common.grid({ |
|
|
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" placeholder="封面图" required/>';
|
|
|
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' />";
|
...
|
...
|
@@ -46,60 +51,167 @@ var g=new common.grid({ |
|
|
{display:"操作",render:function(item){
|
|
|
var htmlArr=[];
|
|
|
if(!item.isDefault){
|
|
|
htmlArr.push("<button type='button' data-index='0' class='delete btn btn-danger btn-xs'>删除</button>");
|
|
|
htmlArr.push("<button type='button' data-index='0' class='delete btn btn-info btn-xs'>编辑</button>");
|
|
|
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(',');
|
|
|
}}
|
|
|
]
|
|
|
});
|
|
|
g.__rows=[
|
|
|
{
|
|
|
"attachType": 1,
|
|
|
"attachUrl": "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80",
|
|
|
"isDefault": 1,
|
|
|
"orderBy": 1
|
|
|
},
|
|
|
|
|
|
var __ac=$.trim($("#attachmentContent").val());
|
|
|
g.__rows=__ac?JSON.parse(__ac):[
|
|
|
{
|
|
|
"attachType": 1,
|
|
|
"attachUrl": "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80",
|
|
|
"isDefault": 0,
|
|
|
"orderBy": 2
|
|
|
},
|
|
|
{
|
|
|
"attachType": 3,
|
|
|
"intro": "限售商品详情",
|
|
|
"isDefault": 0,
|
|
|
"orderBy": 3
|
|
|
"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();
|
|
|
|
|
|
//初始化form表单
|
|
|
var $editorgroup = $('#editor-group');
|
|
|
|
|
|
$editorgroup.init();
|
|
|
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.init();
|
|
|
|
|
|
//添加修改
|
|
|
$('.limit-add-btn').click(function (option) {
|
|
|
e.submit($('#limit-add-form').attr('action'),function(option){
|
|
|
//option.debug=true;
|
|
|
option.data.attachmentContent=JSON.stringify(g.__rows);
|
|
|
option.data.saleTime = new Date(option.data.saleTime.replace('-',',')).getTime() / 1000;
|
|
|
option.success=function(res){
|
|
|
res=res.data;
|
|
|
if(res.code=="200"){
|
|
|
e.$tip('提交成功',function(){
|
|
|
location.href="/limit/product/index";
|
|
|
},'growl-success');
|
|
|
}else{
|
|
|
e.$tip(res.message);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
option.error=function(res){
|
|
|
e.$tip("提交失败");
|
|
|
};
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
// var $editor = $('#editor'), //文字,图片,视频容器
|
|
|
// type = $('#limit-add-form').attr('type');
|
|
|
|
|
|
// //添加文字
|
|
|
// $('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>');
|
|
|
var Bll={
|
|
|
imgVideo:function(title,item,index){
|
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// $oText.appendTo($editor);
|
|
|
//添加文字
|
|
|
$('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"));
|
|
|
});
|
|
|
|
|
|
// });
|
|
|
// $('#text-editor').wysihtml5();
|
|
|
// return false;
|
|
|
// });
|
|
|
|
|
|
// //添加图片
|
|
|
// $('body').on('click', '#picDialog', function() {
|
...
|
...
|
|