dropDown.js
2.03 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
require('../util/select2');
var $=require('jquery');
var urlObj={
'supplier':'/supplier/supplier/getSupplierListByIdName',
'brand':'/brand/getBrandNames',
'managerName':'/supplier/storeadmin/managerName',
'sortattribute':'/erpproduct/sortattribute/ajax/automatic',
'sortsize':'/erpproduct/sortsize/ajax/automatic',
'queryBrand': '/goods/query/brand',
'querySupplier': '/goods/query/supplier',
'queryShop': '/goods/query/shop',
'maxSort': '/goods/query/maxSort',
'shopsRest':'/ShopsRest/getShopsByName',
'sortlist':'/product/class/queryAllProductSortList',
'productPool':'queryBaseProductPoolList'
};
var dropDown=function(option){
new dropDown.prototype.init(option);
}
dropDown.prototype={
constructor:dropDown,
init:function(_option){
var option={
el:'.select2-offscreen',
url:urlObj[_option.ajax]
};
for(var i in _option){
if(_option.hasOwnProperty(i)){
option[i]=_option[i];
}
}
if(option.ajax){
$(option.el).select2({
ajax:{
url: option.url,
dataType: 'json',
type:'POST',
delay: 250,
data: function (params) {
var data=$.extend({},{
idName: params.term
},option.params||{});
return data;
},
processResults: function (data, params) {
params.page = params.page || 1;
data.data.data.unshift({id:'-1',text:"请选择"});
return {
results: data.data.data
}
},
cache: true
}
});
}else{
$(option.el).select2();
}
}
}
dropDown.prototype.init.prototype = dropDown.prototype;
module.exports=dropDown;