multistage.js
2.75 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
100
101
102
103
104
105
106
107
108
/**
* @author zzf
*/
function OperationList (param){
var config = {
pid : 'cid',
txt : 'cname',
viewid : 'categoryId',
page : 5
};
var _List = [];
var methods = {
heavy : function (obj) {
if(_List.length == 0){
_List.push(obj);
return _List;
};
for (var i=0; i < _List.length; i++) {
for (var k=0; k < _List[i].length; k++) {
if(obj[obj.length - 1][param.pid] == _List[i][k][param.pid]){
return _List;
};
};
};
_List.push(obj);
},
add : function(){
if(_List.length >= param.page){
return false;
};
var data = $(this).prev().find('.title').find('.region-data').html();
data = JSON.parse(data);
methods.heavy(data);
methods.updateData();
return false;
},
del : function(){
var leng = $(this).parent().length;
if(leng <= 1){
$(this).parent().parent().hide();
};
var index = parseInt($(this).parent().attr('page'));
_List.splice(index, 1);
$(this).parent().remove();
methods.updateData();
return false;
},
updateData : function(){
if(_List.length > 0){
$('.'+param.view).show();
};
param.fun(_List);
},
setData : function(){
var vals = [];
var ids = $('#'+param.viewid).val();
$('.'+param.view+' div').each(function(){
vals.push($(this).attr('val'));
});
if(vals.length <= 0){
return false;
};
ids = ids.split(',');
for (var i=0; i < vals.length; i++) {
var aobj = {};
var alist = [];
aobj[config.pid] = ids[i];
aobj[config.txt] = vals[i];
alist.push(aobj);
_List.push(alist);
};
},
dataType : function(){
var ids = $('#'+param.viewid).val();
ids = ids.split(',');
var view = '';
for (var i=0; i < ids.length-1; i++) {
var aobj = {};
var dat = ids[i].split('/');
var alist = [];
if(! dat || ! dat[1]){
return false;
};
aobj[config.pid] = dat[0];
aobj[config.txt] = dat[1];
alist.push(aobj);
_List.push(alist);
view += '<div page="'+i+'" class="more-cell">'+dat[1]+'<span style="visibility: hidden;"></span></div>';
$('.'+param.view).html('');
$('.'+param.view).append(view);
};
}
};
param = $.extend(config, param);
if(param.viewid == "categoryId"){
methods.setData();
}else{
methods.dataType();
};
$('.'+param.add).click(methods.add);
$('.'+param.del).live('click', methods.del);
};