diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 62e8558f..b8855a47 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -42,6 +42,12 @@ Route::group(function () { Route::post('send/mobile/:type', 'login.Login/sendMobileCode'); Route::get('testfun1', 'sys.Index/testfun1'); + + //员工端-上传图片 + Route::post('uploadImage', 'upload.Upload/image'); + + //员工端-添加新员工信息 + Route::post('personnel/add', 'apiController.Personnel/add'); }); /** @@ -195,15 +201,14 @@ Route::group(function () { Route::get('common/getClassAll', 'apiController.Common/getClassAll'); //公共端-获取支付类型字典(员工端) Route::get('common/getPaymentTypes', 'apiController.Common/getPaymentTypes'); - +//员工端-获取审批配置列表 + Route::get('personnel/approval-configs', 'apiController.Personnel/getApprovalConfigs'); })->middleware(ApiChannel::class) ->middleware(ApiLog::class); //需要token验证的 Route::group(function () { - //员工端-上传图片 - Route::post('uploadImage', 'upload.Upload/image'); //员工端-上传文档 Route::post('uploadDocument', 'upload.Upload/document'); //员工端详情 @@ -220,10 +225,8 @@ Route::group(function () { Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); //员工端-获取教练数据列表 Route::get('personnel/getCoachList', 'apiController.Personnel/getCoachList'); - //员工端-添加新员工信息 - Route::post('personnel/add', 'apiController.Personnel/add'); - //员工端-获取审批配置列表 - Route::get('personnel/approval-configs', 'apiController.Personnel/getApprovalConfigs'); + + //员工端统计(销售)-获取销售首页数据统计 Route::get('statistics/marketHome', 'apiController.Statistics/marketHome'); diff --git a/uniapp/common/axios.js b/uniapp/common/axios.js index 8e63d835..95bdd8e0 100644 --- a/uniapp/common/axios.js +++ b/uniapp/common/axios.js @@ -61,7 +61,7 @@ const responseInterceptor = (response) => { uni.setStorageSync("expires_time", data.data.expires_time); } } - return data; + // 成功情况直接返回数据 } else if (data.code === 401) { console.error('401错误 - 未授权'); // 未授权或token过期,清除所有用户缓存信息 @@ -98,12 +98,14 @@ const responseInterceptor = (response) => { }, 1500); throw new Error(data.msg || '未授权'); } else { - uni.showToast({ - title: data.msg || '请求失败', - icon: 'none' - }); + // 不要在这里显示toast,让业务层自己处理错误信息 + // uni.showToast({ + // title: data.msg || '请求失败', + // icon: 'none' + // }); } } + // 始终返回数据,让业务层判断成功失败 return data; } }; diff --git a/uniapp/common/config.js b/uniapp/common/config.js index c98a2253..6dfd5008 100644 --- a/uniapp/common/config.js +++ b/uniapp/common/config.js @@ -1,5 +1,5 @@ // 环境变量配置 -const env = 'development' +const env = 'prod' // const env = 'prod' const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退 const isDebug = false // 默认启用调试模式 diff --git a/uniapp/pages/common/personnel/add_personnel.vue b/uniapp/pages/common/personnel/add_personnel.vue index 7aae597f..dd4585ea 100644 --- a/uniapp/pages/common/personnel/add_personnel.vue +++ b/uniapp/pages/common/personnel/add_personnel.vue @@ -265,7 +265,7 @@ 审批流程: - {{approvalData.selectedConfig ? approvalData.selectedConfig.config_name : '新入职申请'}} + {{currentApprovalConfigName}} 提交后将进入审批流程,请等待审批完成 @@ -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