fix(hrm): 人员交接详情抽屉数据不回显

el-drawer 早期渲染插槽时 t_id 仍为 null,mounted() 走到 else
分支把 localMode 设成 add,后续 prop 变化 getTid 不再触发。
改用 watch t_id (immediate:true),prop 何时到位都能拉数据。
同时给 system.post.list 单独加 try/catch 并对 state_ 做空安全
访问,避免内层异常吃掉主数据赋值。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
TianyangZhang 2026-05-15 17:03:06 +08:00
parent 64060a6e2f
commit cacb548517
1 changed files with 26 additions and 15 deletions

View File

@ -188,15 +188,22 @@ export default {
})
},
deep: true,
},
t_id: {
handler(val) {
this.localMode = this.mode;
if (val) {
this.getTid();
} else {
this.formData = { person: [] };
this.localMode = "add";
}
},
immediate: true,
}
},
mounted() {
this.getGroup();
if (this.t_id) {
this.getTid();
} else {
this.localMode = "add";
}
},
methods: {
async getTid() {
@ -204,18 +211,22 @@ export default {
let res = await this.$API.hrm.empjoin.item.req(this.t_id);
// post_name
if (res.person && res.person.length > 0) {
const postRes = await this.$API.system.post.list.req({ page: 0 });
const postList = Array.isArray(postRes) ? postRes : (postRes.results || postRes.data || []);
const postMap = {};
postList.forEach(p => { postMap[p.id] = p.name; });
res.person.forEach(p => {
if (p.post && !p.post_name) {
p.post_name = postMap[p.post] || '';
}
});
try {
const postRes = await this.$API.system.post.list.req({ page: 0 });
const postList = Array.isArray(postRes) ? postRes : (postRes.results || postRes.data || []);
const postMap = {};
postList.forEach(p => { postMap[p.id] = p.name; });
res.person.forEach(p => {
if (p.post && !p.post_name) {
p.post_name = postMap[p.post] || '';
}
});
} catch (postErr) {
console.error('获取岗位列表失败:', postErr);
}
}
this.formData = res;
if (res.ticket_ && res.ticket_.state_.type == 1 && res.create_by == this.$TOOL.data.get("USER_INFO").id) {
if (res.ticket_ && res.ticket_.state_ && res.ticket_.state_.type == 1 && res.create_by == this.$TOOL.data.get("USER_INFO").id) {
this.localMode = "edit";
}
} catch (error) {