149 lines
5.4 KiB
JavaScript
149 lines
5.4 KiB
JavaScript
(function (vc) {
|
|
vc.extends({
|
|
data: {
|
|
addStaffInfo: {
|
|
orgId: '',
|
|
orgName: '',
|
|
username: '',
|
|
sex: '',
|
|
idCard: '',
|
|
tel: '',
|
|
address: '',
|
|
relCd: '',
|
|
relCds: [],
|
|
photo: '',
|
|
areaId: '',
|
|
areas: []
|
|
}
|
|
},
|
|
_initMethod: function () {
|
|
vc.getDict('u_org_staff_rel', "rel_cd", function (_data) {
|
|
$that.addStaffInfo.relCds = _data;
|
|
});
|
|
|
|
vc.getDict('international_area_code_dictionary', 'link_area_type', function (_data) {
|
|
$that.addStaffInfo.areas = _data;
|
|
});
|
|
},
|
|
_initEvent: function () {
|
|
vc.on('addStaff', 'notifyUploadCoverImage', function (data) {
|
|
if (data.length > 0) {
|
|
$that.addStaffInfo.photo = data[0].fileId;
|
|
}
|
|
});
|
|
vc.on('addStaff', 'switchOrg', function (_org) {
|
|
$that.addStaffInfo.orgId = _org.orgId;
|
|
$that.addStaffInfo.orgName = _org.allOrgName;
|
|
});
|
|
},
|
|
methods: {
|
|
addStaffValidate() {
|
|
return vc.validate.validate({
|
|
addStaffInfo: $that.addStaffInfo
|
|
}, {
|
|
'addStaffInfo.username': [{
|
|
limit: "required",
|
|
param: "",
|
|
errInfo: "员工名称不能为空"
|
|
},
|
|
{
|
|
limit: "maxin",
|
|
param: "2,50",
|
|
errInfo: "员工名称长度必须在2位至50位"
|
|
},
|
|
],
|
|
'addStaffInfo.sex': [{
|
|
limit: "required",
|
|
param: "",
|
|
errInfo: "员工性别不能为空"
|
|
}],
|
|
'addStaffInfo.relCd': [{
|
|
limit: "required",
|
|
param: "",
|
|
errInfo: "员工岗位不能为空"
|
|
},
|
|
{
|
|
limit: "num",
|
|
param: "",
|
|
errInfo: "员工岗位错误"
|
|
},
|
|
],
|
|
'addStaffInfo.tel': [{
|
|
limit: "required",
|
|
param: "",
|
|
errInfo: "联系方式不能为空"
|
|
}],
|
|
'addStaffInfo.address': [{
|
|
limit: "required",
|
|
param: "",
|
|
errInfo: "家庭住址不能为空"
|
|
},
|
|
{
|
|
limit: "maxLength",
|
|
param: "200",
|
|
errInfo: "家庭住址不能超过200位"
|
|
},
|
|
],
|
|
'addStaffInfo.orgId': [{
|
|
limit: "required",
|
|
param: "",
|
|
errInfo: "关联组织不能为空"
|
|
}
|
|
]
|
|
});
|
|
},
|
|
saveStaffInfo: function () {
|
|
if (!$that.addStaffValidate()) {
|
|
vc.toast(vc.validate.errInfo);
|
|
return;
|
|
}
|
|
$that.addStaffInfo.name = $that.addStaffInfo.username;
|
|
|
|
// 新增:打印提交数据,检查是否有 areaId
|
|
console.log("提交的员工数据:", $that.addStaffInfo);
|
|
vc.http.apiPost(
|
|
'/user.staff.add',
|
|
JSON.stringify($that.addStaffInfo), {
|
|
emulateJSON: true
|
|
},
|
|
function (json, res) {
|
|
//vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
|
|
let _json = JSON.parse(json)
|
|
if (_json.code == 0) {
|
|
//关闭model
|
|
$('#addStaffModel').modal('hide');
|
|
$that.clearAddStaffInfo();
|
|
vc.goBack();
|
|
vc.toast("添加成功");
|
|
return;
|
|
} else {
|
|
vc.toast(_json.msg);
|
|
}
|
|
},
|
|
function (errInfo, error) {
|
|
vc.toast(errInfo);
|
|
});
|
|
},
|
|
clearAddStaffInfo: function () {
|
|
let _relCds = $that.addStaffInfo.relCds;
|
|
$that.addStaffInfo = {
|
|
orgId: '',
|
|
orgName: '',
|
|
username: '',
|
|
sex: '',
|
|
idCard: '',
|
|
tel: '',
|
|
address: '',
|
|
relCd: '',
|
|
relCds: _relCds,
|
|
photo: '',
|
|
areaId: '', // 重置选中的国籍编码
|
|
areas: _areas // 保留国家字典列表
|
|
};
|
|
},
|
|
_addStaffChangeOrg: function () {
|
|
vc.emit('chooseOrgTree', 'openOrgModal', {});
|
|
}
|
|
}
|
|
});
|
|
})(window.vc); |