MicroCommunityWeb/public/components/frame/orgSelect2/orgSelect2.js
2023-09-04 00:50:33 +08:00

119 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function(vc) {
vc.extends({
propTypes: {
parentModal: vc.propTypes.string
},
data: {
orgSelect2Info: {
orgs: [],
orgId: '-1',
orgName: '',
companyId: '',
departmentId: '',
departmentName: '',
staffId: '',
staffName: '',
orgSelector: {}
}
},
watch: {
orgSelect2Info: {
deep: true,
handler: function() {
vc.emit($namespace, 'departmentSelect2', "setDepartment", this.orgSelect2Info);
}
}
},
_initMethod: function() {
this._initOrgSelect2();
},
_initEvent: function() {
vc.on('orgSelect2', 'setOrg', function(_param) {
vc.copyObject(_param, this.orgSelect2Info);
var option = new Option(_param.orgName, _param.orgId, true, true);
this.orgSelect2Info.orgSelector.append(option);
});
vc.on('orgSelect2', 'clearOrg', function(_param) {
this.orgSelect2Info = {
orgs: [],
orgId: '-1',
orgName: '',
orgSelector: {}
};
});
},
methods: {
_initOrgSelect2: function() {
console.log("调用_initOrgSelect2方法");
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
$.fn.select2.defaults.set('width', '100%');
this.orgSelect2Info.orgSelector = $('#orgSelector').select2({
placeholder: '必填,请选择公司',
allowClear: true, //允许清空
escapeMarkup: function(markup) {
return markup;
}, // 自定义格式化防止xss注入
ajax: {
url: "/app/org.listOrgs",
dataType: 'json',
delay: 250,
headers: {
'APP-ID': '8000418004',
'TRANSACTION-ID': vc.uuid(),
'REQ-TIME': vc.getDateYYYYMMDDHHMISS(),
'SIGN': ''
},
data: function(params) {
var _term = "";
if (params.hasOwnProperty("term")) {
_term = params.term;
}
return {
orgName: _term,
orgLevel: '2',
page: 1,
row: 10,
communityId: vc.getCurrentCommunity().communityId
};
},
processResults: function(data) {
return {
results: this._filterOrgData(data.orgs)
};
},
cache: true
}
});
$('#orgSelector').on("select2:select", function(evt) {
//这里是选中触发的事件
//evt.params.data 是选中项的信息
console.log('select', evt);
this.orgSelect2Info.orgId = evt.params.data.id;
this.orgSelect2Info.orgName = evt.params.data.text;
this.orgSelect2Info.companyId = evt.params.data.id;
});
$('#orgSelector').on("select2:unselect", function(evt) {
//这里是取消选中触发的事件
//如配置allowClear: true后触发
console.log('unselect', evt);
this.orgSelect2Info.orgId = '-1';
this.orgSelect2Info.orgName = '';
});
},
_filterOrgData: function(_Orgs) {
var _tmpOrgs = [];
for (var i = 0; i < _Orgs.length; i++) {
var _tmpOrg = {
id: _Orgs[i].orgId,
text: _Orgs[i].orgName
};
_tmpOrgs.push(_tmpOrg);
}
return _tmpOrgs;
}
}
});
})(window.vc);