layui.use(['upload','form'],function(){
var $ = layui.jquery
,form = layui.form
,upload = layui.upload;
var a= $('#test1').attr('data-url');
// console.log(a);
//普通图片上传
var uploadInst = upload.render({
elem: '#test1'
,url: a
,before: function(obj){
//预读本地文件示例,不支持ie8
obj.preview(function(index, file, result){
$('#demo1').attr('src', result); //图片链接(base64)
});
}
,done: function(res){
//如果上传失败
if(res.code == 1){
$('#bimg').val(res.data);
}
//上传成功
return layer.msg(res.msg);
}
,error: function(){
//演示失败状态,并实现重传
var demoText = $('#demoText');
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function(){
uploadInst.upload();
});
}
});
form.on('submit(demo1)',function(data){
// console.log(data);
$.ajax({
url:data.elem.baseURI,
data:data.field,
type:"post",
success:function(obj){
if(obj.code == 1){
layer.msg(obj.msg,{icon:6},function(){
window.parent.location.reload();
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
})
}
}
})
return false;
})
})
/****************************图片-添加***************************/
function add(title,url){
layer.open({
type: 2,
title: 'layer mobile页',
shadeClose: true,
shade: 0.8,
area: ['1100px', '90%'],
content: url //iframe的url
});
}
/******************************图片-编辑**********************/
function edit(title,url,id){
layer.open({
type: 2,
title: 'layer mobile页',
shadeClose: true,
shade: 0.8,
area: ['1100px', '90%'],
content: url+'?id='+id //iframe的url
});
}
/************************************图片-删除**********************/
function picture_del(obj,id,url){
layer.confirm('确认要删除吗?',function(index){
console.log(index);
$.ajax({
type: 'POST',
url:url,
data:{id:id},
dataType: 'json',
success: function(data){
// console.log(data);
$(obj).parents("tr").remove();
layer.msg('已删除!',{icon:1,time:1000});
},
// error:function(data) {
// console.log(data.msg);
// },
});
});
}