var upload_pic = [];
var upload_file = [];
var upload = [];
function loadUpload(i,e,key,url,assets)
{
var value = e.attr('v');
if (typeof(upload[value]) != "undefined") {
//return;
}
upload[value] = true;
upload_pic[value] = [];
upload_file[value] = [];
var id = e.attr('id');
layui.use(['upload','layer'], function() {
var layer = layui.layer;
var layuiUpload = layui.upload;
var uploadInst = layuiUpload.render({
elem: '#' + id
,data: {'key' : key}
,field: 'file'
,url: url
,multiple: true
,accept:'file'
,choose: function(obj){
layer.load();
}
,done: function(data) {
layer.closeAll('loading');
if (data.status == 1) {
var mul = e.attr('mul');
if (mul == 'yes') {
if (e.attr('t') == 'file') {
if (upload_file[value].length <= 0 && $("#" + value).val()) {
upload_file[value] = $("#" + value).val().split(',');
}
var m = $('.' +value+'_mul');
var i = m.find('li').eq(upload_file[value].length);
if (i.length) {
i.find('a').eq(0).html(data.name);
} else {
m.append('
'+data.name+' [删除]');
}
upload_file[value].push(data.url);
$("#" + value).val(upload_file.join(','));
} else {
if (upload_pic[value].length <= 0 && $("#" + value).val()) {
upload_pic[value] = $("#" + value).val().split(',');
}
var m = $('.' +value+'_mul');
var i = m.find('img').eq(upload_pic[value].length);
if (i.length) {
i.attr('src', data.url);
} else {
m.append('
');
}
upload_pic[value].push(data.url);
$("#" + value).val(upload_pic[value].join(','));
}
} else {
if (e.attr('t') == 'file') {
} else {
$('#show_'+value).attr('src',data.url).show();
$('#show_'+value).click(function()
{
picDel($(this), value, 1);
})
}
$('#'+value).val(data.url);
}
} else {
layer.msg(data.msg, {icon: 4});
return false;
}
}
,error: function(){
//请求异常回调
}
});
});
}
function picDel(e,v,s)
{
if (confirm('确定要删除图片吗?')) {
if (s == 1) {
e.hide();
$("#" + v).val('');
} else {
if (upload_pic[v].length <= 0 && $("#" + v).val()) {
upload_pic[v] = $("#" + v).val().split(',');
}
var p = e.find('img').attr('src');
e.remove();
upload_pic[v].remove(p);
$("#" + v).val(upload_pic[v].join(','));
}
}
}
function fileDel(e,v)
{
if(confirm('确定要删除文件吗?'))
{
if(upload_file[v].length <= 0 && $("#" + v).val())
{
upload_file[v] = $("#" + v).val().split(',');
}
var parent = e.parent();
var p = parent.find('a').eq(0).attr('href');
parent.remove();
upload_file[v].remove(p);
//console.info(pic);
$("#" + v).val(upload_file[v].join(','));
}
}