dropDown.js
9.29 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
require('./util/select2');
var $ = require('jquery');
var urlObj = {
'supplier': '/supplier/supplier/getSupplierListByIdName',
'brand': '/erpproduct/brands/getBrandNames',
'managerName': '/ShopsAdminRest/getUsersByIdentity', //根据身份选择管理员
'sortattribute': '/product/querySizeAttributesByName', // 品类关联实物测量属性
'sortsize': '/product/querySizeByNameForSelect', //尺码模糊查询【验证通过】
'queryBrand': '/erpproduct/brands/queryAllBrands', //查询品牌列表接口
'querySupplier': '/supplier/supplier/queryAllSupplier', //查询供应商列表接口
'queryShop': '/ShopsRest/queryAllShops', // 查询店铺列表接口
'queryShopPass': '/ShopsRest/selectCheckPassShopsByName', // 查询通过审核店铺列表接口
'queryShopNames': '/ShopsRest/selectShopsByName', // 店铺创建、店铺信息管理、店铺审核管理页面,下拉选择店铺名称,列表筛选
'maxSort': '/product/queryMaxSortByName', //查询一级类目列表接口
'shopsRest': '/ShopsRest/selectCheckPassShopsByName', // 店铺列表
'couponShops': '/ShopsRest/selectAllCouponShops', // 优惠券店铺列表
'xiangouID': '/DrawlineActivityRest/selectActivityListForSelect', //限购ID
'sortsize2': '/product/querySizeListBySortId4Html', //尺码
'sortsize3':'/product/querySizeListBySkn',//尺码
'sortbybrand': '/ShopsRest/queryShopsByBrandId',
'getjitSup': '/AgreementRest/getJitSupplierByBrandId',
// 'getsort':'/goods/query/querySortBySmallSort',
'queryStortType':'/standardSort/getAllStandardSortBySortIdForSelect', // 查询产品参数类型,
'sortlist': '/product/class/queryAllProductSortList',//no select
'sortSubList': '/product/class/queryProductSortList',
'productPool': '/runManage/subjectManage/queryBaseProductPoolListByName',
'firstCategory': '/operations/helpcategory/getCategoryListByPid',
'getByCategoryId': '/operations/helpcontent/getSecondCategoryList',
'getAllHelpCategory': '/operations/helpcontent/getAllHelpCategory',
'getHelpCategory': '/operations/helpcontent/getHelpCategory',
'queryAll4Select': '/goods/brandSeries/queryAll4Select', //品牌款型系列
'getSelectItems': '/meterManage/brand/getSelectItems', //品牌获取选择选项的枚举
// 逛
'guangGetAuthorList': '/guang/article/getAuthorList', // 逛-获取作者
'guangGetUsedAuthorList': '/guang/article/getUsedAuthorList', // 逛-获取可用的作者
'guangGetSortList': '/guang/article/getSortList', // 逛-获取作者
'guangGetTagCategoryByStatus': '/guang/tagSort/getTagItems',
'guangCommentGetFilterItems': '/guang/comment/getItems', // 逛-评论列表-获取筛选条件
'guangPlusSatrChannel': '/guang/plustarcategory/getCategoryNames', // 逛-plus star 频道
'queryBrandByShopId': '/query/brandByshopId', //查询店铺下关联品牌
'querySupplierByShopId': '/query/supplierByshopId', //查询店铺下关联供应商
'guangGetSort':'/guang/article/getSortList',//逛-分类
// 货到付款
'codGetSknList':'/payDelivery/queryPayDeliveryProductSkn',
'codGetBrandList':'/payDelivery/queryPayDeliveryBrandName',
//发券
'couponID':'/coupon/queryList',//优惠券ID
//获取所有APP版本号列表
'appVersions':'/suggest/suggest/getAllAppVersions',
'fuzzySearchProductSortIds':"/product/fuzzySearchProductSortIds",
'searchAllSortLevel':"/product/searchAllSortLevel",
'queryRefundExchangeProductSkn':"/refundExchangeAttribute/queryRefundExchangeProductSkn",
'selectAppEntranceIconCategory':"/appEntranceIcon/selectCategory",
'userProfileByRole':"/profile/queryUserProfileByRole",
'queryModelListForSelect':"/model/queryModelListForSelect",
'queryProdSizeListForSel':"/productSize/queryProdSizeListForSel",
//不校验用户,获取所有或模糊匹配名称的品牌
'getAllBrandNameList':"/erpproduct/brands/getAllBrandNameList",
// 搜索广告的相关的
'searchPostion' : "/operations/search/queryPositionListForDown",
'searchTemplet' : "/operations/search/queryTempletListForDown"
};
var minimumResultsForSearch = ["sortbybrand", "getjitSup", "querySupplier","sortsize3","queryStortType"];
var dropDown = function(option) {
return new dropDown.prototype.init(option);
}
dropDown.prototype = {
constructor: dropDown,
init: function(_option) {
var __self = this;
var option = {
el: '.select2-offscreen',
url: urlObj[_option.ajax]
};
for (var i in _option) {
if (_option.hasOwnProperty(i)) {
option[i] = _option[i];
}
}
if (minimumResultsForSearch.indexOf(_option.ajax) > -1) {
option.minimumResultsForSearch = Infinity
}
__self.option = option;
if (option.ajax) {
var defaultName = "请选择";
if ($(option.el).val() == -1) {
defaultName = $(option.el).find("option[value='-1']").text()
}
if (option.hash) {
// if ($(option.el).val() == null) {
//
// var name = option.el.replace(/\.|#/g, '');
// var arr = location.hash.replace(/^#/, '').split("&");
// var map = {};
// arr.forEach(function(item) {
// var _a = item.split('=');
// if (_a && _a[0]) {
// map[_a[0]] = _a[1];
// }
// });
//
// var id = map[name];
// var text = map[name + "Name"];
// $(option.el).html('');
// $(option.el).append("<option value=" + id + " >" + text + "</option>");
// }
// $(document).on("change", option.el, function() {
// var name = option.el.replace(/\.|#/g, '');
// var id = $(option.el).val();
// var text = $(option.el).find("option[value='" + id + "']").text();
// var arr = location.hash.replace(/^#/, '').split("&");
// var map = {};
// arr.forEach(function(item) {
// var _a = item.split('=');
// if (_a && _a[0]) {
// map[_a[0]] = _a[1];
// }
// });
// map[name] = id;
// map[name + "Name"] = text;
// var urlHash = '';
// $.each(map, function(key, value) {
// if (value || value == '0') {
// urlHash += key + '=' + value + '&';
// }
// });
// location.hash = urlHash;
// });
}
__self.select2 = $(option.el).select2({
minimumResultsForSearch: option.minimumResultsForSearch || 0,
ajax: {
url: option.url+"?__dataTime="+new Date(),
dataType: 'json',
type: 'POST',
delay: 250,
data: function(params) {
console.log('params=', params);
var param = {};
if (Object.prototype.toString.call(option.params) == "[object Function]") {
param = option.params();
} else {
param = option.params;
}
var data = $.extend({}, {
idName: params.term
}, param || {});
return data;
},
processResults: function(data, params) {
params.page = params.page || 1;
data.data.unshift({
id: '-1',
text: defaultName
});
option.midData&&option.midData(data.data);
return {
results: data.data
}
},
cache: true
}
});
} else {
__self.select2 = $(option.el).select2();
}
},
getValue: function() {
var option = this.option;
var ret = {};
ret.name = option.el.replace(/\.|#/g, '');
ret.id = $(option.el).val();
if (ret.id != -1) {
ret.text = $(option.el).find("option[value='" + ret.id + "']").text();
}
else {
ret.text="";
}
return ret;
},
setValue: function (value) {
var option = this.option;
$(option.el).val(value.id);
if (option.ajax) {
if (value.text) {
$(option.el).html('');
$(option.el).append("<option value=" + value.id + " >" + value.text + "</option>");
this.select2.parent().find(".select2-selection__rendered").text(value.text);
}
}
else {
this.select2.val(value.id);
}
}
};
dropDown.prototype.init.prototype = dropDown.prototype;
module.exports = dropDown;