refund.js
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(function($) {
// 插件的定义
$.fn.Refund = function(options) {
var defaults = {
'boxId':'',
'showBoxEvent' : [],
'tpl' : '',
'imgInputTpl':'imgInputTpl',
'imageUploadButton':'upload',
'imageProject' : 'evidenceImages',
'imgTpl' : 'imgTpl',
'imageSize' : '100x100',
'maxImageNum' : 4
};
var params = $.extend(defaults, options);
var imageNum = new Array();
// iterate and reformat each matched element
return this.each(function() {
$(this).change(function(){
params['textid'] = $(this).attr('textid');
var boxKey = params.boxId + '_' + params.textid;
var showStatus = false;
if(typeof(params.showBoxEvent) != undefined || params.showBoxEvent != {}){
var id = $(this).val();
for (k in params.showBoxEvent)
{
if(params.showBoxEvent[k] == id)
{
showStatus = true;
}
}
}else{
showStatus = true;
}
$('#' + boxKey).html('').parent().hide();
if(showStatus == false)
{
return false;
}
if(typeof(params.boxId) == undefined || params.boxId == ''){
alert('请设置容器ID');
return false;
}
if(typeof(params.tpl) == undefined || params.tpl == '')
{
alert('请设置内容模版');
return false;
}
if(typeof(params.imageUploadButton) == undefined || params.imageUploadButton == '')
{
alert('请设置上传图片的按钮ID');
return false;
}
$('#' + boxKey).html('').html($('#' + params.tpl).html().replace(/{{textid}}/g,params.textid)).parent().show();
imageNum[params.textid] = new Array();
for(var t = 0; t < params.maxImageNum; t++)
{
imageNum[params.textid][t] = 0;
}
$('#' + params.imageUploadButton + '_' + params.textid).QFSUpload({
'formData' : {'project':params.imageProject},
'height' : 33,
'width' : 116,
'multi' : true,
'file_queue_limit' : params.maxImageNum,
'buttonImage' : 'http://static.yohobuy.com/images/v2/common/up_pic_btn.png',
'onSuccess' : function(imageUrl, selector){
idArr = selector.split('_');
var textid = 0;
if(idArr.length == 2)
{
textid = idArr[1];
}
for(var i = 0; i < imageNum[textid].length; i++){
if(imageNum[textid][i] == 0){
var _image = QGlobal.Common.QFSFImages(imageUrl,params.imageProject,params.imageSize,2);
//设置隐藏域
var html = $('#' + params.imgInputTpl).html().replace(/{{textid}}/g,textid).replace('{{num}}', i).replace('{{image}}', imageUrl);
$('#' + params.boxId + '_' + textid).append(html);
//显示效果
var template = $('#' + params.imgTpl).html().replace('{{imageSrc}}', _image);
$('#' + params.boxId + '_' + textid + ' li:eq('+i+')').html(template);
//删除上传图片
$('#' + params.boxId + '_' + textid + ' a:eq('+i+')').click(function(){
$('#img_' + textid + '_' + i).remove();
$(this).parent().html('');
imageNum[textid][i] = 0;
});
imageNum[textid][i] = 1;
return false;
}
}
}
});
});
});
};
})(jQuery);