|
|
|
@ -265,7 +265,7 @@ |
|
|
|
<view class="approval-info"> |
|
|
|
<view class="info-item"> |
|
|
|
<text class="info-label">审批流程:</text> |
|
|
|
<text class="info-value">{{approvalData.selectedConfig ? approvalData.selectedConfig.config_name : '新入职申请'}}</text> |
|
|
|
<text class="info-value">{{currentApprovalConfigName}}</text> |
|
|
|
</view> |
|
|
|
<view class="info-note"> |
|
|
|
<text>提交后将进入审批流程,请等待审批完成</text> |
|
|
|
@ -380,6 +380,20 @@ export default { |
|
|
|
maritalStatusOptions: ['未婚', '已婚', '离异', '丧偶'] |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
// 当前审批配置名称 |
|
|
|
currentApprovalConfigName() { |
|
|
|
if (this.approvalData.selectedConfig && this.approvalData.selectedConfig.config_name) { |
|
|
|
return this.approvalData.selectedConfig.config_name |
|
|
|
} |
|
|
|
return '新入职申请' |
|
|
|
}, |
|
|
|
// 是否显示审批配置加载失败 |
|
|
|
shouldShowApprovalError() { |
|
|
|
return this.currentStep === 3 && this.approvalData.useApproval && |
|
|
|
!this.approvalData.selectedConfig && this.approvalConfigs.length === 0 |
|
|
|
} |
|
|
|
}, |
|
|
|
onLoad() { |
|
|
|
// 设置当前日期为默认入职时间 |
|
|
|
const today = new Date() |
|
|
|
@ -544,9 +558,26 @@ export default { |
|
|
|
this.approvalData.selectedConfig = this.approvalConfigs[0] |
|
|
|
this.approvalData.selectedIndex = 0 |
|
|
|
} |
|
|
|
console.log('审批配置加载成功:', this.approvalConfigs) |
|
|
|
} else { |
|
|
|
console.error('审批配置加载失败:', response.data.msg) |
|
|
|
// 如果加载失败,设置默认配置以避免阻塞提交 |
|
|
|
this.approvalData.selectedConfig = { |
|
|
|
id: 0, |
|
|
|
config_name: '新入职申请', |
|
|
|
description: '新入职申请', |
|
|
|
business_type: 'personnel_add' |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('加载审批配置失败:', error) |
|
|
|
// 网络错误时也设置默认配置 |
|
|
|
this.approvalData.selectedConfig = { |
|
|
|
id: 0, |
|
|
|
config_name: '新入职申请', |
|
|
|
description: '新入职申请', |
|
|
|
business_type: 'personnel_add' |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
@ -574,28 +605,103 @@ export default { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 验证审批流程配置 |
|
|
|
console.log('开始提交表单...') |
|
|
|
console.log('当前审批配置:', this.approvalData.selectedConfig) |
|
|
|
|
|
|
|
// 确保有审批配置(如果配置还没加载完,等待一下或使用默认值) |
|
|
|
if (this.approvalData.useApproval && !this.approvalData.selectedConfig) { |
|
|
|
uni.showToast({ |
|
|
|
title: '审批流程配置加载失败,请重试', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
return |
|
|
|
console.log('审批配置未加载,尝试重新加载...') |
|
|
|
await this.loadApprovalConfigs() |
|
|
|
|
|
|
|
// 如果还是没有配置,使用默认配置继续提交 |
|
|
|
if (!this.approvalData.selectedConfig) { |
|
|
|
this.approvalData.selectedConfig = { |
|
|
|
id: 0, |
|
|
|
config_name: '新入职申请', |
|
|
|
description: '新入职申请', |
|
|
|
business_type: 'personnel_add' |
|
|
|
} |
|
|
|
console.log('使用默认审批配置:', this.approvalData.selectedConfig) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.submitting = true |
|
|
|
|
|
|
|
try { |
|
|
|
// 处理字段值:空字符串转为null或空字符串,避免数据库错误 |
|
|
|
const processField = (value, allowEmpty = true) => { |
|
|
|
if (value === null || value === undefined) { |
|
|
|
return null |
|
|
|
} |
|
|
|
if (typeof value === 'string') { |
|
|
|
const trimmed = value.trim() |
|
|
|
return trimmed === '' ? (allowEmpty ? '' : null) : trimmed |
|
|
|
} |
|
|
|
return value |
|
|
|
} |
|
|
|
|
|
|
|
// 处理日期字段:空字符串必须转为null |
|
|
|
const processDateField = (dateValue) => { |
|
|
|
return processField(dateValue, false) // 日期字段不允许空字符串 |
|
|
|
} |
|
|
|
|
|
|
|
// 处理数字字段:空值转为null |
|
|
|
const processNumberField = (numberValue) => { |
|
|
|
if (numberValue === null || numberValue === undefined || numberValue === '') { |
|
|
|
return null |
|
|
|
} |
|
|
|
return numberValue |
|
|
|
} |
|
|
|
|
|
|
|
const submitData = { |
|
|
|
...this.formData, |
|
|
|
...this.detailData, |
|
|
|
// 基本信息(必填字段保持原值) |
|
|
|
name: this.formData.name, |
|
|
|
gender: this.formData.gender, |
|
|
|
phone: this.formData.phone, |
|
|
|
account_type: this.formData.account_type, |
|
|
|
|
|
|
|
// 基本信息(非必填字段) |
|
|
|
head_img: processField(this.formData.head_img), |
|
|
|
birthday: processDateField(this.formData.birthday), |
|
|
|
email: processField(this.formData.email), |
|
|
|
wx: processField(this.formData.wx), |
|
|
|
join_time: processDateField(this.formData.join_time), |
|
|
|
|
|
|
|
// 详细信息(全部非必填) |
|
|
|
ethnicity: processField(this.detailData.ethnicity), |
|
|
|
age: processNumberField(this.detailData.age), |
|
|
|
politics: processField(this.detailData.politics), |
|
|
|
university: processField(this.detailData.university), |
|
|
|
education: processField(this.detailData.education), |
|
|
|
major: processField(this.detailData.major), |
|
|
|
graduation_date: processDateField(this.detailData.graduation_date), |
|
|
|
native_place: processField(this.detailData.native_place), |
|
|
|
household_place: processField(this.detailData.household_place), |
|
|
|
household_type: processField(this.detailData.household_type), |
|
|
|
household_address: processField(this.detailData.household_address), |
|
|
|
current_address: processField(this.detailData.current_address), |
|
|
|
emergency_contact: processField(this.detailData.emergency_contact), |
|
|
|
emergency_phone: processField(this.detailData.emergency_phone), |
|
|
|
marital_status: processField(this.detailData.marital_status), |
|
|
|
bank_card: processField(this.detailData.bank_card), |
|
|
|
bank_name: processField(this.detailData.bank_name), |
|
|
|
remark: processField(this.detailData.remark), |
|
|
|
|
|
|
|
// 处理审批配置 |
|
|
|
use_approval: this.approvalData.useApproval, |
|
|
|
approval_config_id: this.approvalData.selectedConfig ? this.approvalData.selectedConfig.id : 0 |
|
|
|
} |
|
|
|
|
|
|
|
console.log('提交数据:', submitData) |
|
|
|
|
|
|
|
const response = await apiRoute.post('personnel/add', submitData) |
|
|
|
|
|
|
|
if (response.data.code === 1) { |
|
|
|
console.log('提交响应:', response) |
|
|
|
console.log('响应数据结构:', response.data || response) |
|
|
|
console.log('响应码:', response.code, '类型:', typeof response.code) |
|
|
|
|
|
|
|
if (response.code === 1) { |
|
|
|
console.log('提交成功:', response.msg) |
|
|
|
uni.showToast({ |
|
|
|
title: '入职申请已提交,等待审批', |
|
|
|
icon: 'success', |
|
|
|
@ -606,16 +712,26 @@ export default { |
|
|
|
uni.navigateBack() |
|
|
|
}, 2000) |
|
|
|
} else { |
|
|
|
console.error('提交失败:', response.msg) |
|
|
|
uni.showToast({ |
|
|
|
title: response.data.msg || '提交失败', |
|
|
|
title: response.msg || '提交失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('提交员工信息失败:', error) |
|
|
|
// 提供更详细的错误信息 |
|
|
|
let errorMsg = '网络错误,请稍后重试' |
|
|
|
if (error.response) { |
|
|
|
errorMsg = error.response.msg || `服务器错误(${error.response.status})` |
|
|
|
} else if (error.message) { |
|
|
|
errorMsg = error.message |
|
|
|
} |
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
title: '网络错误,请稍后重试', |
|
|
|
icon: 'none' |
|
|
|
title: errorMsg, |
|
|
|
icon: 'none', |
|
|
|
duration: 3000 |
|
|
|
}) |
|
|
|
} finally { |
|
|
|
this.submitting = false |
|
|
|
|