diff --git a/src/components/UploadImgFormData/index.vue b/src/components/UploadImgFormData/index.vue index 145f78a..a85258e 100644 --- a/src/components/UploadImgFormData/index.vue +++ b/src/components/UploadImgFormData/index.vue @@ -190,6 +190,31 @@ export default { // 文件发生变化 handleChange(file, fileList) { console.log(file, fileList, 'file, fileList') + + const isFormat = this.fileType.some((e) => file.name.endsWith(e)) + if (!isFormat) { + this.$modal.msgError( + `文件格式不正确, 请上传${this.fileType.join( + '、', + )}格式的文件!`, + ) + + this.$emit( + 'update:fileList', + fileList.filter((item) => item.uid !== file.uid), + ) + return false + } + // 判断文件大小 + const isLt = file.size / 1024 / 1024 < this.fileSize + if (!isLt) { + this.$modal.msgError(`图片大小不能超过 ${this.fileSize} MB`) + this.$emit( + 'update:fileList', + fileList.filter((item) => item.uid !== file.uid), + ) + return false + } this.$emit('update:fileList', fileList) this.$emit('onUploadChange', fileList) }, diff --git a/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue b/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue index afeadad..a94dcc2 100644 --- a/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue +++ b/src/views/construction-person/entry-and-exit-manage/person-entry/add-or-edit-form.vue @@ -481,6 +481,7 @@ label-width="140px" ref="salaryCardInfoFormRef" :model="salaryCardInfoForm" + :rules="salaryCardInfoFormRules" > - + - + { if (valid2) { this.$refs.contractInfoFormRef.validate( async (valid3) => { if (valid3) { - const fieldsToCheck_1 = [ - 'contractCode', // 合同编号 - 'wageCriterion', // 工资核定标准 - 'contractStopDate', // 合同终止日期 - 'contractStartDate', // 合同签订日期 - ] - const fieldsToCheck_2 = [ - 'bankName', // 银行名称 - 'bankCardCode', // 银行卡号 - 'bankBranchName', // 银行支行名称 - ] - const status_1 = this.checkFormStatus( - fieldsToCheck_1, - this.contractImageList, - 1, - ) - const status_2 = this.checkFormStatus( - fieldsToCheck_2, - this.bankImageList, - 2, - ) + this.$refs.salaryCardInfoFormRef.validate( + async (valid4) => { + if (valid4) { + const fieldsToCheck_1 = [ + 'contractCode', // 合同编号 + 'wageCriterion', // 工资核定标准 + 'contractStopDate', // 合同终止日期 + 'contractStartDate', // 合同签订日期 + ] + const fieldsToCheck_2 = [ + 'bankName', // 银行名称 + 'bankCardCode', // 银行卡号 + 'bankBranchName', // 银行支行名称 + ] + const status_1 = + this.checkFormStatus( + fieldsToCheck_1, + this + .contractImageList, + 1, + ) + const status_2 = + this.checkFormStatus( + fieldsToCheck_2, + this.bankImageList, + 2, + ) - // 组装参数 - const params = { - ...this.keyInfoForm, - ...this.idCardInfoForm, - } + // 组装参数 + const params = { + ...this.keyInfoForm, + ...this.idCardInfoForm, + } - const { faceImg } = this.idCardInfoForm - const formData = new FormData() - const fileMsg = [] - let fileIdList = [] + const { faceImg } = + this.idCardInfoForm + const formData = + new FormData() + const fileMsg = [] + let fileIdList = [] - if (this.queryDetailsId) { - params.id = this.queryDetailsId - params.einStatus = this.einStatus - } + if (this.queryDetailsId) { + params.id = + this.queryDetailsId + params.einStatus = + this.einStatus + } - delete params.faceImg // 删除无关字段 确保参数的正确性 + delete params.faceImg // 删除无关字段 确保参数的正确性 - // 人脸图片 - faceImg.forEach((item) => { - if (!item.id) { - formData.append( - 'files', - item.raw, - ) - fileMsg.push({ - type: 1, - name: 'faceImg', - }) - } - }) - - if ( - status_1 === 'all_filled' && - !this.isEditContract - ) { - params.bmWorkerContract = - this.contractInfoForm - this.contractImageList.forEach( - (item) => { - item.fileList.forEach( - (j) => { + // 人脸图片 + faceImg.forEach((item) => { + if (!item.id) { formData.append( 'files', - j.raw, + item.raw, ) fileMsg.push({ - type: item.type, - name: item.name, + type: 1, + name: 'faceImg', }) - }, - ) - }, - ) - } + } + }) - if (status_1 === 'partial') { - this.$modal.msgError( - '请完善合同见证中的必填信息(除附件外)后再提交', - ) - - return reject( - new Error('合同信息未完善'), - ) - } - if (status_2 === 'all_filled') { - params.bmWorkerWageCard = - this.salaryCardInfoForm - - if (this.queryDetailsId) { - let reserveFileList = [] - this.bankImageList.forEach( - (item) => { - item.fileList.forEach( - (j) => { - if (j.id) { - reserveFileList.push( - j.id, - ) - } + if ( + status_1 === + 'all_filled' && + !this.isEditContract + ) { + params.bmWorkerContract = + this.contractInfoForm + this.contractImageList.forEach( + (item) => { + item.fileList.forEach( + (j) => { + formData.append( + 'files', + j.raw, + ) + fileMsg.push( + { + type: item.type, + name: item.name, + }, + ) + }, + ) }, ) - }, - ) - - if ( - reserveFileList.length > 0 - ) { - fileIdList = - this.editUploadFileList - .filter( - (item) => - !reserveFileList.includes( - item.id, - ), - ) - .map((j) => j.id) - - if (fileIdList.length > 0) { - params.bmWorkerWageCard.delIds = - fileIdList.join(',') } - } - } - this.bankImageList.forEach( - (item) => { - item.fileList.forEach( - (j) => { - if (!j.id) { - formData.append( - 'files', - j.raw, - ) - fileMsg.push({ - type: item.type, - name: item.name, - }) + if ( + status_1 === 'partial' + ) { + this.$modal.msgError( + '请完善合同见证中的必填信息(除附件外)后再提交', + ) + + return reject( + new Error( + '合同信息未完善', + ), + ) + } + if ( + status_2 === + 'all_filled' + ) { + params.bmWorkerWageCard = + this.salaryCardInfoForm + + if ( + this.queryDetailsId + ) { + let reserveFileList = + [] + this.bankImageList.forEach( + (item) => { + item.fileList.forEach( + (j) => { + if ( + j.id + ) { + reserveFileList.push( + j.id, + ) + } + }, + ) + }, + ) + + if ( + reserveFileList.length > + 0 + ) { + fileIdList = + this.editUploadFileList + .filter( + ( + item, + ) => + !reserveFileList.includes( + item.id, + ), + ) + .map( + ( + j, + ) => + j.id, + ) + + if ( + fileIdList.length > + 0 + ) { + params.bmWorkerWageCard.delIds = + fileIdList.join( + ',', + ) + } } - }, + } + + this.bankImageList.forEach( + (item) => { + item.fileList.forEach( + (j) => { + if ( + !j.id + ) { + formData.append( + 'files', + j.raw, + ) + fileMsg.push( + { + type: item.type, + name: item.name, + }, + ) + } + }, + ) + }, + ) + } + + if ( + status_2 === 'partial' + ) { + this.$modal.msgError( + '请完善工资卡见证中的必填信息(除附件外)后再提交', + ) + + return reject( + new Error( + '工资卡信息未完善', + ), + ) + } + + if ( + status_2 === + 'all_empty' && + this.queryDetailsId + ) { + if ( + this + .editUploadFileList + .length > 0 + ) { + params.bmWorkerWageCard.delIds = + this.editUploadFileList + .map( + (j) => + j.id, + ) + .join(',') + } + } + + formData.append( + 'params', + JSON.stringify(params), + ) + formData.append( + 'fileMsg', + JSON.stringify(fileMsg), ) - }, - ) - } - if (status_2 === 'partial') { - this.$modal.msgError( - '请完善工资卡见证中的必填信息(除附件外)后再提交', - ) + const API = this + .queryDetailsId + ? editEntryPersonAPI + : addEntryPersonAPI - return reject( - new Error('工资卡信息未完善'), - ) - } + const res = await API( + formData, + ) + if (res.code === 200) { + this.$modal.msgSuccess( + this.queryDetailsId + ? '修改人员成功' + : '新增人员成功', + ) - if ( - status_2 === 'all_empty' && - this.queryDetailsId - ) { - if ( - this.editUploadFileList.length > - 0 - ) { - params.bmWorkerWageCard.delIds = - this.editUploadFileList - .map((j) => j.id) - .join(',') - } - } + // 更新一下红绿灯状态 + const result = + await updatePersonLightStatusAPI( + this + .queryDetailsId + ? this + .workerId + : res.data, + ) + console.log( + result, + 'result红绿灯状态更新结果', + ) - formData.append( - 'params', - JSON.stringify(params), + resolve() + } else { + this.$modal.msgError( + res.msg, + ) + reject( + new Error(res.msg), + ) + } + } else { + reject( + new Error( + '工资卡信息表单验证失败', + ), + ) + this.$modal.msgError( + '请完善工资卡信息表单', + ) + } + }, ) - formData.append( - 'fileMsg', - JSON.stringify(fileMsg), - ) - - const API = this.queryDetailsId - ? editEntryPersonAPI - : addEntryPersonAPI - - const res = await API(formData) - if (res.code === 200) { - this.$modal.msgSuccess( - this.queryDetailsId - ? '修改人员成功' - : '新增人员成功', - ) - - // 更新一下红绿灯状态 - const result = - await updatePersonLightStatusAPI( - this.queryDetailsId - ? this.workerId - : res.data, - ) - console.log( - result, - 'result红绿灯状态更新结果', - ) - - resolve() - } else { - this.$modal.msgError(res.msg) - reject(new Error(res.msg)) - } } else { reject( new Error('合同信息表单验证失败'), + this.$modal.msgError( + '请完善合同信息表单', + ), ) } }, @@ -1254,6 +1345,7 @@ export default { } else { // 关键信息表单验证失败 reject(new Error('关键信息表单验证失败')) + this.$modal.msgError('请完善关键信息表单') } }) }) diff --git a/src/views/construction-person/red-green-light-mange/contract-witness/contract-witness-upload.vue b/src/views/construction-person/red-green-light-mange/contract-witness/contract-witness-upload.vue index 73ddaf5..391ddc9 100644 --- a/src/views/construction-person/red-green-light-mange/contract-witness/contract-witness-upload.vue +++ b/src/views/construction-person/red-green-light-mange/contract-witness/contract-witness-upload.vue @@ -66,7 +66,7 @@ - + - + - + - + - + { - const status = this.checkFormStatus() + this.$refs.salaryCardInfoFormRef.validate(async (valid) => { + if (valid) { + const status = this.checkFormStatus() - // 1. 提前声明并初始化params - let params = { - ...this.salaryCardInfoForm, - workerId: this.workerId, - } - let fileIdList = [] - const filesList = [] - const formData = new FormData() - - // 2. 对表单进行校验 - // 部分填写:提示错误并终止 - if (status === 'partial') { - this.$modal.msgError( - '请完善工资卡见证中的必填信息(除附件外)后再提交', - ) - return reject(new Error('工资卡信息未完善')) - } - - // 全空:弹窗确认,处理后阻断后续代码 - if (status === 'all_empty') { - await new Promise((innerResolve, innerReject) => { - this.$confirm( - '当前工资卡信息为空,将不做任何上传逻辑,确定后将关闭该上传页面', - '温馨提示', - ) - .then(() => innerResolve()) - .catch(() => innerReject()) - }) - .then(() => resolve('isClose')) - .catch(() => reject()) - - return - } - - if (status === 'all_filled') { - if (this.queryDetailsId) { - params.id = this.queryDetailsId - - let reserveFileList = [] - this.bankImageList.forEach((item) => { - item.fileList.forEach((j) => { - if (j.id) { - reserveFileList.push(j.id) - } - }) - }) - - if (reserveFileList.length > 0) { - fileIdList = this.editUploadFileList - .filter( - (item) => - !reserveFileList.includes(item.id), - ) - .map((j) => j.id) - - params.delIds = fileIdList.join(',') + // 1. 提前声明并初始化params + let params = { + ...this.salaryCardInfoForm, + workerId: this.workerId, } - } + let fileIdList = [] + const filesList = [] + const formData = new FormData() - this.bankImageList.forEach((item) => { - item.fileList.forEach((file) => { - if (!file.id) { - filesList.push({ - type: item.type, - name: 'wageCard', + // 2. 对表单进行校验 + // 部分填写:提示错误并终止 + if (status === 'partial') { + this.$modal.msgError( + '请完善工资卡见证中的必填信息(除附件外)后再提交', + ) + return reject(new Error('工资卡信息未完善')) + } + + // 全空:弹窗确认,处理后阻断后续代码 + if (status === 'all_empty') { + await new Promise((innerResolve, innerReject) => { + this.$confirm( + '当前工资卡信息为空,将不做任何上传逻辑,确定后将关闭该上传页面', + '温馨提示', + ) + .then(() => innerResolve()) + .catch(() => innerReject()) + }) + .then(() => resolve('isClose')) + .catch(() => reject()) + + return + } + + if (status === 'all_filled') { + if (this.queryDetailsId) { + params.id = this.queryDetailsId + + let reserveFileList = [] + this.bankImageList.forEach((item) => { + item.fileList.forEach((j) => { + if (j.id) { + reserveFileList.push(j.id) + } + }) }) - formData.append('files', file.raw) + + if (reserveFileList.length > 0) { + fileIdList = this.editUploadFileList + .filter( + (item) => + !reserveFileList.includes( + item.id, + ), + ) + .map((j) => j.id) + + params.delIds = fileIdList.join(',') + } } - }) - }) - } - formData.append('params', JSON.stringify(params)) - formData.append('fileMsg', JSON.stringify(filesList)) + this.bankImageList.forEach((item) => { + item.fileList.forEach((file) => { + if (!file.id) { + filesList.push({ + type: item.type, + name: 'wageCard', + }) + formData.append('files', file.raw) + } + }) + }) + } - // 3. 捕获API调用异常,避免未处理的reject - try { - const res = await uploadWageCardAPI(formData) + formData.append('params', JSON.stringify(params)) + formData.append('fileMsg', JSON.stringify(filesList)) - if (res.code === 200) { - this.$modal.msgSuccess('工资卡信息上传成功') + // 3. 捕获API调用异常,避免未处理的reject + try { + const res = await uploadWageCardAPI(formData) - // 更新一下红绿灯状态 - const result = await updatePersonLightStatusAPI( - this.workerId, - ) - console.log(result, 'result红绿灯状态更新结果') + if (res.code === 200) { + this.$modal.msgSuccess('工资卡信息上传成功') - resolve() + // 更新一下红绿灯状态 + const result = await updatePersonLightStatusAPI( + this.workerId, + ) + console.log(result, 'result红绿灯状态更新结果') + + resolve() + } else { + this.$modal.msgError(res.msg) + reject() + } + } catch (err) { + this.$modal.msgError('工资卡信息上传失败,请重试') + reject(err) + } } else { - this.$modal.msgError(res.msg) - reject() + reject(new Error('工资卡信息表单验证失败')) } - } catch (err) { - this.$modal.msgError('工资卡信息上传失败,请重试') - reject(err) - } + }) }) },