Authored by biao

update for fix upload bug

... ... @@ -13,7 +13,7 @@
<span class="red">*</span>上传凭证:
</div>
<div class="left right-content">
<div class="img-upload">
<div class="img-upload" data-good-index="{{@index}}">
<span class="iconfont">&#xe61f;</span>
</div>
<span class="img-up-tip">0/4</span>
... ...
... ... @@ -17,6 +17,8 @@ var validate = require('./order/validation');
var imgBoxTpl = require('../../tpl/me/thumbnail.hbs');
var changeTypeTpl = require('../../tpl/me/change-type.hbs');
var upload = require('../plugins/upload');
var validateMap = {
user: {
sl: '#user',
... ... @@ -371,51 +373,64 @@ function bindImgDeleteEvent() {
});
}
function bindUploadEvent() {
var $tip = $('.img-up-tip');
function doUpload(count, goodIndex) {
var $el = $('*[data-good-index=' + goodIndex + ']');
$tip.text('0/4');
if (count < 4) {
upload.up({
callback: function(result) {
var img;
var $t;
var o;
var n;
if (result.code === 200) {
n = parseInt($el.siblings('.thumb-box').length, 10);
o = {src: result.data};
if (result.imgs && result.imgs.length) {
o.url = result.imgs[0];
}
$('.img-upload').on('click', function() {
var upload = require('../plugins/upload');
var that = this;
var n = parseInt($(that).siblings('.thumb-box').length, 10);
img = imgBoxTpl(o);
$t = $el.next('.img-up-tip');
$el.before(img);
n += 1;
$t.text(n + '/4');
bindImgDeleteEvent();
if (n >= 4) {
$el.hide();
}
if (n < 4) {
upload.up({
callback: function(result) {
var img;
var $t;
var o;
} else {
new _alert(result.message).show();
}
}
});
}
if (result.code === 200) {
n = parseInt($(that).siblings('.thumb-box').length, 10);
o = {src: result.data};
}
if (result.imgs && result.imgs.length) {
o.url = result.imgs[0];
}
function bindUploadEvent() {
var $tip = $('.img-up-tip');
img = imgBoxTpl(o);
$t = $(that).next('.img-up-tip');
$(that).before(img);
$tip.text('0/4');
n += 1;
$t.text(n + '/4');
bindImgDeleteEvent();
$('.img-upload').each(function(index, uploadBtn) {
$(uploadBtn).on('click', function() {
var that = this;
var n = parseInt($(that).siblings('.thumb-box').length, 10);
var goodIndex = $(that).data('good-index');
if (n >= 4) {
$(that).hide();
}
if (n > 4) {
return false;
}
} else {
new _alert(result.message).show();
}
}
});
}
doUpload(n, goodIndex);
});
});
}
... ...
... ... @@ -26,21 +26,14 @@ $result = $('#yoho-upload-result');
$upload = $('#yoho-upload');
$filename = $upload.find('.file-name');
function up(opt) {
$filename.click();
if (opt) {
callback = opt.callback;
} else {
callback = '';
}
}
function getResponse(cb) {
num = 0;
inter = setInterval(function() {
var res = $result[0].contentDocument.body.innerText || '';
if (res) {
clearInterval(inter);
$result[0].contentDocument.body.innerText = '';
if (cb) {
return cb($.parseJSON(res));
... ... @@ -55,9 +48,20 @@ function getResponse(cb) {
}, 500);
}
$filename.change(function() {
$upload.submit();
getResponse(callback);
});
function up(opt) {
$filename.click();
if (opt) {
callback = null;
callback = opt.callback;
} else {
callback = '';
}
$filename.off('change').on('change', function() {
$upload.submit();
getResponse(callback);
});
}
exports.up = up;
... ...