Files
PropertyDeployment/resources/Web/MicroCommunityWeb/html/pages/frame/staff/staff.js
2025-12-09 20:22:03 +08:00

209 lines
8.8 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) {
var DEFAULT_PAGE = 1;
var DEFAULT_ROWS = 10;
vc.extends({
data: {
staffInfo: {
moreCondition: false,
branchOrgs: [],
departmentOrgs: [],
relCds: [],
conditions: {
branchOrgId: '',
departmentOrgId: '',
orgId: '',
orgName: '',
orgLevel: '2',
parentOrgId: '',
name: '',
tel: '',
staffId: '',
parentOrgName: '',
parentTwoOrgId: ''
}
},
staffData: [],
countryDicts: [],
},
watch: {
"staffInfo.conditions.branchOrgId": { //深度监听,可监听到对象、数组的变化
handler(val, oldVal) {
$that._getOrgsByOrgLevelStaff(DEFAULT_PAGE, DEFAULT_ROWS, 3, val);
$that.staffInfo.conditions.branchOrgId = val;
$that.staffInfo.conditions.parentOrgId = val;
$that.staffInfo.conditions.departmentOrgId = '';
$that.loadData(DEFAULT_PAGE, DEFAULT_ROWS);
},
deep: true
},
"staffInfo.conditions.departmentOrgId": { //深度监听,可监听到对象、数组的变化
handler(val, oldVal) {
$that.staffInfo.conditions.orgId = val;
$that.loadData(DEFAULT_PAGE, DEFAULT_ROWS);
},
deep: true
}
},
_initMethod: function () {
// 查询岗位列表
vc.getDict('u_org_staff_rel', "rel_cd", function (_data) {
$that.staffInfo.relCds = _data;
// 岗位列表获取比较慢, 获取到岗位列表后再加载数据
$that.loadData(1, 10);
$that._getOrgsByOrgLevelStaff(DEFAULT_PAGE, DEFAULT_ROWS, 2, '');
});
$that._loadCountryDicts();
},
_initEvent: function () {
// $that.$on('pagination_page_event', function (_currentPage) {
// console.log(_currentPage);
// $that.currentPage(_currentPage);
// });
vc.on('pagination', 'page_event', function (_currentPage) {
$that.loadData(_currentPage, DEFAULT_ROWS);
});
vc.on('staff', 'notify', function () {
$that.loadData(1, DEFAULT_ROWS);
});
$that.$on('addStaff_reload_event', function () {
$that.loadData(1, 10);
});
$that.$on('editStaff_reload_event', function () {
$that.loadData(1, 10);
});
$that.$on('deleteStaff_reload_event', function () {
$that.loadData(1, 10);
});
},
methods: {
_loadCountryDicts: function () {
let param = {
params: {
specId: '9', // 国家字典的 specId与 listOwner 一致)
page: 1,
row: 1000 // 加载足够多的字典项
}
};
vc.http.apiGet('/dict.listDict',
param,
function (json, res) {
let _data = JSON.parse(json);
$that.countryDicts = _data.data; // 存储国家字典
}, function (errInfo, error) {
console.log('获取国家字典失败:', errInfo);
}
);
},
loadData: function (_page, _rows) {
$that.staffInfo.conditions.page = _page;
$that.staffInfo.conditions.rows = _rows;
$that.staffInfo.conditions.row = _rows;
let param = {
params: $that.staffInfo.conditions
};
param.params.name = param.params.name.trim();
param.params.tel = param.params.tel.trim();
param.params.staffId = param.params.staffId.trim();
//发送get请求
vc.http.apiGet('/query.staff.infos',
param,
function (json) {
let _staffInfo = JSON.parse(json);
// 员工列表 和 岗位列表匹配
console.log("后端接口原始返回:", _staffInfo);
let staffList = _staffInfo.staffs;
// 新增:打印后端返回的员工数据,查看是否有 areaId
console.log("后端返回的员工列表:", staffList);
let relCdsList = $that.staffInfo.relCds;
staffList.forEach((staff) => {
relCdsList.forEach((rel) => {
if (staff.relCd == rel.statusCd) {
staff.relCdName = rel.name;
}
});
if (staff.areaId) { // 假设后端返回“国家编码”的字段为 areaId
let country = $that.countryDicts.find(c => c.statusCd === staff.areaId);
staff.countryName = country ? country.name : staff.areaId; // 有匹配则显示名称,否则显示编码
} else {
staff.countryName = '-'; // 无编码时显示“-”
}
})
$that.staffData = staffList;
$that.$emit('pagination_info_event', {
total: _staffInfo.records,
dataCount: _staffInfo.total,
currentPage: _page
});
},
function () {
console.log('请求失败处理');
}
);
},
currentPage: function (_currentPage) {
$that.loadData(_currentPage, 10);
},
openEditStaff: function (_staffInfo) {
$that.$emit('edit_staff_event', _staffInfo);
},
openDeleteStaff: function (_staffInfo) {
$that.$emit('delete_staff_event', _staffInfo);
},
_moreCondition: function () {
if ($that.staffInfo.moreCondition) {
$that.staffInfo.moreCondition = false;
} else {
$that.staffInfo.moreCondition = true;
}
},
_getOrgsByOrgLevelStaff: function (_page, _rows, _orgLevel, _parentOrgId) {
let param = {
params: {
page: _page,
row: _rows,
orgLevel: _orgLevel,
parentOrgId: _parentOrgId
}
};
//发送get请求
vc.http.apiGet('/org.listOrgs',
param,
function (json, res) {
let _orgInfo = JSON.parse(json);
if (_orgLevel == 2) {
$that.staffInfo.branchOrgs = _orgInfo.orgs;
} else {
$that.staffInfo.departmentOrgs = _orgInfo.orgs;
}
},
function (errInfo, error) {
console.log('请求失败处理');
}
);
},
_openAddStaffStepPage: function () {
vc.jumpToPage("/#/pages/frame/addStaff")
},
//查询
_queryStaffMethod: function () {
$that.loadData(DEFAULT_PAGE, DEFAULT_ROWS)
},
//重置
_resetStaffMethod: function () {
$that.staffInfo.conditions.branchOrgId = "";
$that.staffInfo.conditions.orgId = "";
$that.staffInfo.conditions.departmentOrgId = "";
$that.staffInfo.conditions.name = "";
$that.staffInfo.conditions.tel = "";
$that.staffInfo.conditions.staffId = "";
$that.loadData(DEFAULT_PAGE, DEFAULT_ROWS)
},
_resetStaffPwd: function (_staff) {
vc.emit('resetStaffPwd', 'openResetStaffPwd', _staff);
},
openStaffDetail: function (_staff) {
vc.jumpToPage('/#/pages/staff/staffDetail?staffId=' + _staff.userId)
}
},
});
})(window.vc);