Authored by zhangxiaoru

editorial

... ... @@ -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',
... ... @@ -300,6 +302,9 @@ function bindConfirmEvent() {
var $f = $good.find('.form');
var $specialReason = $good.find('.special-reason');
$imgs = null;
imgs = [];
goodObj.product_skn = $c.data('skn');
goodObj.product_skc = $c.data('skc');
goodObj.product_sku = $c.data('sku');
... ... @@ -371,51 +376,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;
$('.img-upload').on('click', function() {
var upload = require('../plugins/upload');
var that = this;
var n = parseInt($(that).siblings('.thumb-box').length, 10);
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];
}
if (n < 4) {
upload.up({
callback: function(result) {
var img;
var $t;
var o;
img = imgBoxTpl(o);
$t = $el.next('.img-up-tip');
$el.before(img);
if (result.code === 200) {
n = parseInt($(that).siblings('.thumb-box').length, 10);
o = {src: result.data};
n += 1;
$t.text(n + '/4');
bindImgDeleteEvent();
if (result.imgs && result.imgs.length) {
o.url = result.imgs[0];
}
if (n >= 4) {
$el.hide();
}
img = imgBoxTpl(o);
$t = $(that).next('.img-up-tip');
$(that).before(img);
} else {
new _alert(result.message).show();
}
}
});
}
n += 1;
$t.text(n + '/4');
bindImgDeleteEvent();
}
if (n >= 4) {
$(that).hide();
}
function bindUploadEvent() {
var $tip = $('.img-up-tip');
} else {
new _alert(result.message).show();
}
}
});
}
$tip.text('0/4');
$('.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) {
return false;
}
doUpload(n, goodIndex);
});
});
}
... ...
... ... @@ -16,6 +16,8 @@ var $result,
$upload,
$filename;
var uping;
var num,
inter,
callback;
... ... @@ -27,8 +29,12 @@ $upload = $('#yoho-upload');
$filename = $upload.find('.file-name');
function up(opt) {
if (uping) {
return;
}
$filename.click();
if (opt) {
if (opt && typeof opt.callback === 'function') {
callback = opt.callback;
} else {
callback = '';
... ... @@ -40,22 +46,24 @@ function getResponse(cb) {
inter = setInterval(function() {
var res = $result[0].contentDocument.body.innerText || '';
if (num > 20 || res) {
uping = false;
clearInterval(inter);
}
num++;
if (res) {
$result[0].contentDocument.body.innerText = '';
if (cb) {
return cb($.parseJSON(res));
}
}
if (num > 20 || res) {
clearInterval(inter);
}
num++;
}, 500);
}
$filename.change(function() {
uping = true;
$upload.submit();
getResponse(callback);
});
... ...