diff --git a/src/views/hrm/empjoin_form.vue b/src/views/hrm/empjoin_form.vue index 9df17526..3ac84a7f 100644 --- a/src/views/hrm/empjoin_form.vue +++ b/src/views/hrm/empjoin_form.vue @@ -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) {