209 lines
7.9 KiB
JavaScript
209 lines
7.9 KiB
JavaScript
(function ($) {
|
|
var ComBox, defaults, pluginName;
|
|
pluginName = "ComBox";
|
|
defaults = {
|
|
ComBoxName: "ComBox",
|
|
saledeptid: "0",
|
|
salegroupid: "0",
|
|
inneruserid: "0",
|
|
roleCodes: "",
|
|
companyBusiness: "",
|
|
onSucced: function () { },
|
|
includeUser: true //是否包含组
|
|
};
|
|
ComBox = (function () {
|
|
function ComBox(element, options) {
|
|
this.element = element;
|
|
this.options = $.extend(true, {}, defaults, options);
|
|
this._defaults = defaults;
|
|
this._name = pluginName;
|
|
this.isFirst = true;
|
|
this.init();
|
|
}
|
|
|
|
return ComBox;
|
|
})();
|
|
ComBox.prototype.init = function () {
|
|
var _this, $element, combox_innerGroup, combox_user, urlParameter, queryType, roleCodes, companyBusiness;
|
|
_this = this;
|
|
$element = $(this.element);
|
|
roleCodes = _this.options.roleCodes;
|
|
companyBusiness = _this.options.companyBusiness;
|
|
if (roleCodes.indexOf("[GLY]") > -1 || roleCodes.indexOf("[ZJ]") > -1 || roleCodes.indexOf("[ZJZL]") > -1 || roleCodes.indexOf("[ZJZG]") > -1 || (companyBusiness.indexOf("[渤海]") > -1 && (roleCodes.indexOf("[XHJL]") > -1 || roleCodes.indexOf("[XHBBSJY]") > -1))) {
|
|
queryType = 0;
|
|
}
|
|
else if (roleCodes.indexOf("[BMZG]") > -1) {
|
|
queryType = 1;
|
|
}
|
|
else if (roleCodes.indexOf("[ZG]") > -1) {
|
|
queryType = 2;
|
|
}
|
|
else {
|
|
queryType = 3;
|
|
}
|
|
$.data(this, "queryType", queryType);
|
|
combox_innerGroup = $("<input>", {
|
|
type: "text",
|
|
id: _this.options.ComBoxName + "Group"
|
|
}).css({
|
|
width: "160px"
|
|
});
|
|
combox_user = $("<select>", {
|
|
id: _this.options.ComBoxName + "User"
|
|
}).css({
|
|
cursor: "pointer",
|
|
width: "136px",
|
|
height: "20px",
|
|
lineHeight: "20px"
|
|
}
|
|
);
|
|
$element.append("销售组:");
|
|
$element.append(combox_innerGroup);
|
|
if (_this.options.includeUser) {
|
|
$element.append(" 员工:");
|
|
$element.append(combox_user);
|
|
combox_user.append("<option value=''>--请选择用户--</option>");
|
|
}
|
|
/*---------------------------------------------*/
|
|
urlParameter = "saledeptid=" + _this.options.saledeptid + "&salegroupid="
|
|
+ _this.options.salegroupid + "&inneruserid=" + _this.options.inneruserid + "&roleCodes=" + _this.options.roleCodes;
|
|
_this.data = $.data(_this);
|
|
combox_innerGroup.combotree({
|
|
url: "../../Control/GetUserComBoxTreeList?" + urlParameter,
|
|
onLoadSuccess: function () {
|
|
var tree = $(combox_innerGroup).combotree('tree');
|
|
var root = $(tree).tree("getRoot");
|
|
|
|
if (_this.data.queryType > 0) {
|
|
if (root != null && _this.options.salegroupid !== "0") {
|
|
$(combox_innerGroup).combotree('setValue', _this.options.salegroupid);
|
|
}
|
|
else {
|
|
if (_this.isFirst) {
|
|
_this.options.onSucced();
|
|
_this.isFirst = false;
|
|
}
|
|
}
|
|
//else if (root != null && _this.options.saledeptid !== "0") {
|
|
// $(combox_innerGroup).combotree('setValue', -_this.options.saledeptid);
|
|
//}
|
|
}
|
|
else {
|
|
if (_this.isFirst) {
|
|
_this.options.onSucced();
|
|
_this.isFirst = false;
|
|
}
|
|
}
|
|
},
|
|
onSelect: function (node) {
|
|
_this.Group_Select(node, combox_innerGroup, $(this), combox_user);
|
|
|
|
}
|
|
});
|
|
|
|
};
|
|
ComBox.prototype.Group_Select = function (node, innerGroup, $this, combox_user) {
|
|
var _this = this;
|
|
_this.data = $.data(_this);
|
|
if (parseInt(node.id) > 0) {
|
|
if (_this.data.queryType !== 3) {
|
|
$.data(_this, "org_groups", "" + node.id);
|
|
}
|
|
$.data(_this, "org_groups_value", "" + node.id);
|
|
$.data(_this, "org_depts", "" + node.saleDeptId);
|
|
} else {
|
|
$.data(_this, "org_depts", "" + -parseInt(node.id));
|
|
var tree = $this.tree;
|
|
var isLeaf = tree('isLeaf', node.target);
|
|
if (isLeaf) {//销售部下面没有销售组
|
|
$.data(_this, "org_groups", ""); //没有组
|
|
$.data(_this, "org_groups_value", "");
|
|
$.data(_this, "org_ids", "");//没有员工
|
|
} else {
|
|
var child = innerGroup.combotree("tree").tree("getChildren", node.target);
|
|
var childValues = "";
|
|
for (var i = 0; i < child.length; i++) {
|
|
childValues += "" + child[i].id + ",";
|
|
}
|
|
if (childValues.length > 0) {
|
|
childValues = childValues.substr(0, childValues.length - 1);
|
|
}
|
|
$.data(_this, "org_groups", childValues);
|
|
$.data(_this, "org_groups_value", childValues);
|
|
}
|
|
}
|
|
if (_this.options.includeUser) {
|
|
_this.combox_GetUser(combox_user);
|
|
} else {
|
|
if (_this.isFirst) {
|
|
_this.options.onSucced();
|
|
_this.isFirst = false;
|
|
}
|
|
}
|
|
};
|
|
ComBox.prototype.combox_GetUser = function (combox_user) {
|
|
var _this, groups;
|
|
_this = this;
|
|
_this.data = $.data(_this);
|
|
groups = _this.data.org_groups_value;
|
|
$.data(_this, "defaultIndex", 0);
|
|
if (groups.length > 0)//
|
|
{
|
|
combox_user.html("<option value=''>--正在加载请稍候--</option>");
|
|
$.data(_this, "org_ids", "");
|
|
$.r_post("../../Control/GetUserComboxUserList", {
|
|
queryType: _this.data.queryType, salegroupids: groups, iseid: 0, inneruserid: _this.options.inneruserid
|
|
}, function (data) {
|
|
combox_user.unbind();
|
|
if (_this.data.queryType < 3) {
|
|
combox_user.html("<option value=''>--请选择用户--</option>");
|
|
}
|
|
else {
|
|
combox_user.html("");
|
|
}
|
|
$(data).each(function (n, m) {
|
|
if (_this.data.defaultIndex == 0 && m.id == _this.options.inneruserid && _this.data.queryType === 3) {
|
|
combox_user.append("<option value='" + m.id + "' selected='selected'>" + m.text + "</option>");
|
|
$.data(_this, "org_ids", m.id);
|
|
|
|
}
|
|
else {
|
|
combox_user.append("<option value='" + m.id + "'>" + m.text + "</option>");
|
|
}
|
|
});
|
|
if (_this.isFirst) {
|
|
_this.options.onSucced();
|
|
_this.isFirst = false;
|
|
}
|
|
$.data(_this, "defaultIndex", _this.data.defaultIndex++);
|
|
combox_user.change(function () {
|
|
$.data(_this, "org_ids", $(this).val());
|
|
});
|
|
|
|
}, "json");
|
|
|
|
}
|
|
//if (_this.options.tablist != "") {
|
|
// $('#' + _this.options.tablist).tablegrid("Load");
|
|
//}
|
|
};
|
|
ComBox.prototype.getdept = function () {
|
|
return $.data(this, "org_depts");
|
|
};
|
|
ComBox.prototype.getGroups = function () {
|
|
return $.data(this, "org_groups");
|
|
};
|
|
ComBox.prototype.getUser = function () {
|
|
return $.data(this, "org_ids");
|
|
};
|
|
|
|
$.fn[pluginName] = function (position) {
|
|
// this.each(function () {
|
|
if (!$.data(this, pluginName)) {
|
|
return $.data(this, pluginName, new ComBox(this, position));
|
|
}
|
|
// });
|
|
};
|
|
|
|
})(jQuery);
|