123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- var upload_pic = [];
- var upload_file = [];
- var upload = [];
- function loadUpload(i,e,key,upload,assets)
- {
- var value = e.attr('v');
- if (typeof(upload[value]) != "undefined") {
- return;
- }
- upload[value] = true;
- var id = e.attr('id');
- layui.use('upload', function() {
- var layuiUpload = layui.upload;
- var uploadInst = layuiUpload.render({
- elem: '#' + id
- ,data: {'key' : key}
- ,field: 'file'
- ,url: upload
- ,multiple: true
- ,done: function(data) {
- //var data = eval('('+res+')');
- if (data.status) {
- var mul = e.attr('mul');
- if (mul == 'yes') {
- if (e.attr('t') == 'file') {
- if (upload_file.length <= 0 && $("#" + value).val()) {
- upload_file = $("#" + value).val().split(',');
- }
- var m = $('.' +value+'_mul');
- var i = m.find('li').eq(upload_file.length);
- if (i.length) {
- i.find('a').eq(0).html(data.data.name);
- } else {
- m.append('<li><a href="'+data.url+'" target="_blank" title="点此下载" >'+data.data.name+'</a> <a href="javascript:;" title="点此删除" style="color:red;" onclick="fileDel($(this), \''+value+'\')">[删除]</a></li>');
- }
- upload_file.push(data.url);
- $("#" + value).val(upload_file.join(','));
- } else {
- if (upload_pic.length <= 0 && $("#" + value).val()) {
- upload_pic = $("#" + value).val().split(',');
- }
- var m = $('.' +value+'_mul');
- var i = m.find('img').eq(upload_pic.length);
- if (i.length) {
- i.attr('src', data.url);
- } else {
- m.append('<a href="javascript:;" title="点此删除" onclick="picDel($(this), \''+value+'\')"><img src="'+data.url+'" width="150" style="margin-left:5px;" alt="点此删除"/></a>');
- }
- upload_pic.push(data.url);
- $("#" + value).val(upload_pic.join(','));
- }
-
- } else {
- if (e.attr('t') == 'file') {
-
- } else {
- $('#show_'+value).attr('src',data.url).show();
- }
- //$("#"+file.id).find('.data').html('上传完毕');
- $('#'+value).val(data.url);
- }
- } else {
- //$("#"+file.id).find('.data').html("<font color='red'>"+data.message+"</font>");
- return false;
- }
- }
- ,error: function(){
- //请求异常回调
- }
- });
- });
- }
- function picDel(e,v)
- {
- if(confirm('确定要删除图片吗?'))
- {
- if(upload_pic.length <= 0 && $("#" + v).val())
- {
- upload_pic = $("#" + v).val().split(',');
- }
- var p = e.find('img').attr('src');
- e.remove();
- upload_pic.remove(p);
- //console.info(pic);
- $("#" + v).val(upload_pic.join(','));
- }
- }
- function fileDel(e,v)
- {
- if(confirm('确定要删除文件吗?'))
- {
- if(upload_file.length <= 0 && $("#" + v).val())
- {
- upload_file = $("#" + v).val().split(',');
- }
- var parent = e.parent();
- var p = parent.find('a').eq(0).attr('href');
-
- parent.remove();
- upload_file.remove(p);
- //console.info(pic);
- $("#" + v).val(upload_file.join(','));
- }
- }
|