From acf06d6f25e861f48d101eb694278611f4414573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Thu, 22 Jan 2026 12:50:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=A5=E9=A9=BB=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=AE=8C=E6=95=B4=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=8F=90=E4=BA=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/settlement/index.js | 291 ++++++++++++++++---------------------- utils/api.js | 13 +- 2 files changed, 121 insertions(+), 183 deletions(-) diff --git a/pages/settlement/index.js b/pages/settlement/index.js index a906649..a7f1a22 100644 --- a/pages/settlement/index.js +++ b/pages/settlement/index.js @@ -132,11 +132,10 @@ Page({ // 检查是否有保存的表单数据 const savedProgress = wx.getStorageSync('settlement_data'); if (savedProgress) { - console.log('发现保存的表单数据,恢复表单数据并自动提交申请'); + console.log('发现保存的表单数据,恢复表单数据'); // 恢复表单数据 this.loadSettlementProgress(); - // 自动提交申请 - this.submitApplication(); + // 不再自动提交申请,避免重复提交 } }, 500); } @@ -208,6 +207,12 @@ Page({ console.log('清除入驻进度'); }, + // 实时保存表单数据 + saveFormData() { + this.saveSettlementProgress(); + console.log('表单数据已实时保存'); + }, + // 更新全局入驻状态 updateGlobalSettlementStatus(status) { // 可以在这里调用全局状态管理 @@ -351,6 +356,8 @@ Page({ collaborationid: identity, // 使用数据库字段名 showIdentityError: false }); + // 实时保存表单数据 + this.saveFormData(); }, // 公司名称输入(带实时验证) @@ -374,6 +381,8 @@ Page({ showCompanyNameError: showError, companyNameError: errorMessage }); + // 实时保存表单数据 + this.saveFormData(); }, // 公司名称获得焦点 @@ -419,6 +428,8 @@ Page({ showRegionError: showError, regionError: errorMessage }); + // 实时保存表单数据 + this.saveFormData(); }, // 详细地址输入(带实时验证) @@ -439,6 +450,8 @@ Page({ showDetailedAddressError: showError, detailedAddressError: errorMessage }); + // 实时保存表单数据 + this.saveFormData(); }, // 详细地址获得焦点 @@ -508,6 +521,8 @@ Page({ currentCooperationDetail: null, pendingCooperationValue: '' }); + // 实时保存表单数据 + this.saveFormData(); }, // 选择合作模式(内部调用,带验证) @@ -519,6 +534,8 @@ Page({ showCooperationError: false, cooperationError: '' }); + // 实时保存表单数据 + this.saveFormData(); }, // 上传LICENSE @@ -535,6 +552,8 @@ Page({ name: `营业执照_${new Date().getTime()}.jpg` } }); + // 实时保存表单数据 + this.saveFormData(); } }); }, @@ -542,6 +561,8 @@ Page({ // 删除LICENSE deleteBusinessLicense() { this.setData({ businesslicenseurl: null }); // 使用数据库字段名 + // 实时保存表单数据 + this.saveFormData(); }, // 上传动物检疫合格证明 @@ -558,6 +579,8 @@ Page({ name: `动物检疫合格证明_${new Date().getTime()}.jpg` } }); + // 实时保存表单数据 + this.saveFormData(); } }); }, @@ -565,6 +588,8 @@ Page({ // 删除动物检疫合格证明 deleteAnimalQuarantine() { this.setData({ proofurl: null }); // 使用数据库字段名 + // 实时保存表单数据 + this.saveFormData(); }, // 上传法人身份证 @@ -581,6 +606,8 @@ Page({ name: `法人身份证_${new Date().getTime()}.jpg` } }); + // 实时保存表单数据 + this.saveFormData(); } }); }, @@ -588,6 +615,8 @@ Page({ // 删除法人身份证 deleteIdCard() { this.setData({ proofurl: null }); // 使用与动物检疫合格证明相同的字段名 + // 实时保存表单数据 + this.saveFormData(); }, // 上传品牌授权链文件 @@ -604,6 +633,8 @@ Page({ name: `品牌授权链_${new Date().getTime()}.jpg` } }); + // 实时保存表单数据 + this.saveFormData(); } }); }, @@ -611,6 +642,8 @@ Page({ // 删除品牌授权链文件 deleteBrandAuth() { this.setData({ brandurl: null }); // 使用数据库字段名 + // 实时保存表单数据 + this.saveFormData(); }, // 获取文件类型显示名称 @@ -652,15 +685,19 @@ Page({ // 提交申请 async submitApplication() { - // 检查用户是否已登录 + console.log('===== 开始提交入驻申请 ====='); + + // 第一步:保存当前表单数据(确保数据不丢失) + this.saveSettlementProgress(); + console.log('表单数据已保存到本地存储'); + + // 第二步:检查用户是否已登录 const openid = wx.getStorageSync('openid'); const userId = wx.getStorageSync('userId'); // 如果未登录,显示登录弹窗 if (!openid || !userId) { console.log('用户未登录,显示授权弹窗'); - // 保存当前表单数据 - this.saveSettlementProgress(); // 显示一键登录弹窗 this.setData({ showOneKeyLoginModal: true @@ -670,7 +707,11 @@ Page({ console.log('使用已登录用户信息提交申请:', openid, userId); - // 先上传所有文件 + // 第三步:重新加载最新数据(确保使用最新的表单数据) + this.loadSettlementProgress(); + console.log('提交前重新加载数据完成'); + + // 第四步:先上传所有文件 wx.showLoading({ title: '正在上传文件...', mask: true @@ -717,15 +758,13 @@ Page({ wx.hideLoading(); } - // 准备提交数据(与后端API要求的字段名匹配) - // 尝试多种方式获取手机号,确保contactPhone不为空 - // 1. 先尝试直接获取常见的手机号存储键 + // 第五步:准备提交数据 + // 尝试多种方式获取手机号 let contactPhone = wx.getStorageSync('phone') || wx.getStorageSync('userPhone') || wx.getStorageSync('mobile') || ''; - // 2. 如果上述方式没获取到,尝试从userInfo对象中获取 if (!contactPhone) { const userInfo = wx.getStorageSync('userInfo'); if (userInfo && userInfo.phoneNumber && userInfo.phoneNumber !== '未绑定') { @@ -735,154 +774,85 @@ Page({ console.log('最终获取到的手机号:', contactPhone); - // 根据后端API要求构建submitData对象(使用独立的省市区字段) + // 手机号为空时使用默认值 + if (!contactPhone) { + contactPhone = 'default_phone'; + console.log('使用默认手机号:', contactPhone); + } + + // 构建submitData对象(使用最新的表单数据) const submitData = { openid: openid, - collaborationid: this.data.collaborationid, // 合作商身份ID - company: this.data.company || '', // 客户公司名称 - province: this.data.province, // 省份 - city: this.data.city, // 城市 - district: this.data.district, // 区县 - detailedaddress: this.data.detailedaddress || '', // 详细地址(即使为空也要传递) - cooperation: this.data.cooperation === '货源委托' ? 'wholesale' : this.data.cooperation, // 合作模式映射为后端期望的值 - phoneNumber: contactPhone, // 后端期望的字段名是phoneNumber - businesslicenseurl: uploadedFiles.businessLicenseFile || '', // 营业执照URL - proofurl: uploadedFiles.animalQuarantineFile || '', // 动物检疫证明或法人身份证URL(两者共用一个字段) - brandurl: uploadedFiles.brandAuthFile || '', // 品牌授权链URL + collaborationid: this.data.collaborationid, + company: this.data.company || '', + province: this.data.province, + city: this.data.city, + district: this.data.district, + detailedaddress: this.data.detailedaddress || '', + cooperation: this.data.cooperation === '货源委托' ? 'wholesale' : this.data.cooperation, + phoneNumber: contactPhone, + businesslicenseurl: uploadedFiles.businessLicenseFile || '', + proofurl: uploadedFiles.animalQuarantineFile || '', + brandurl: uploadedFiles.brandAuthFile || '', userId: userId }; - // 特别记录详细地址字段,确保它被正确提交 - console.log('详细地址字段值:', submitData.detailedaddress); - console.log('详细地址字段类型:', typeof submitData.detailedaddress); - console.log('详细地址字段是否存在:', 'detailedaddress' in submitData); - - // 记录省市区字段内容 - console.log('省市区字段内容(提交数据):', submitData.province, submitData.city, submitData.district); + // 详细日志记录 + console.log('===== 提交数据详细信息 ====='); + console.log('公司名称:', submitData.company); + console.log('合作商身份:', submitData.collaborationid); + console.log('合作模式:', submitData.cooperation); + console.log('详细地址:', submitData.detailedaddress); + console.log('省市区:', submitData.province, submitData.city, submitData.district); + console.log('手机号:', submitData.phoneNumber); + console.log('营业执照URL:', submitData.businesslicenseurl); + console.log('资质文件URL:', submitData.proofurl); + console.log('============================='); // 保存提交数据到本地存储,供首页检查使用 wx.setStorageSync('preSubmitData', submitData); console.log('已保存preSubmitData:', submitData); - // 检查必填字段是否为空 - console.log('提交数据检查 - contactPhone:', contactPhone); - console.log('提交数据检查 - identityType:', this.data.collaborationid); - console.log('提交数据检查 - cooperationMode:', this.data.cooperation); - console.log('提交数据检查 - cooperationValue:', submitData.cooperation); // 检查映射后的值 - console.log('提交数据检查 - contactName:', this.data.company); - console.log('提交数据检查 - 省市区:', submitData.province, submitData.city, submitData.district); - // 检查所有字段是否完整 - console.log('提交数据完整性检查:', { - hasOpenid: !!submitData.openid, - hasCollaborationid: !!submitData.collaborationid, - hasCompany: !!submitData.company, - hasProvince: !!submitData.province, - hasCity: !!submitData.city, - hasDistrict: !!submitData.district, - hasDetailedAddress: !!submitData.detailedaddress, - hasCooperation: !!submitData.cooperation, - hasPhoneNumber: !!submitData.phoneNumber, - hasBusinessLicense: !!submitData.businesslicenseurl, - hasProofUrl: !!submitData.proofurl, - hasBrandUrl: !!submitData.brandurl - }); + // 第六步:严格的表单验证 + console.log('开始表单验证'); - // 表单验证 - 检查必填字段 - if (!openid) { - wx.showToast({ - title: '请先登录', - icon: 'none' - }); - return; - } - - if (!this.data.collaborationid) { - wx.showToast({ - title: '请选择合作商身份', - icon: 'none' - }); - return; - } - - if (!this.data.cooperation) { - wx.showToast({ - title: '请选择合作模式', - icon: 'none' - }); - return; - } + // 检查必填字段 + const requiredFields = [ + { name: '合作商身份', value: this.data.collaborationid, error: '请选择合作商身份' }, + { name: '公司名称', value: this.data.company, error: '请填写公司名称' }, + { name: '省份', value: this.data.province, error: '请选择省份' }, + { name: '城市', value: this.data.city, error: '请选择城市' }, + { name: '区县', value: this.data.district, error: '请选择区县' }, + { name: '详细地址', value: this.data.detailedaddress, error: '请填写详细地址' }, + { name: '合作模式', value: this.data.cooperation, error: '请选择合作模式' }, + { name: '营业执照', value: this.data.businesslicenseurl, error: '请上传营业执照' }, + { name: '资质文件', value: this.data.proofurl, error: this.data.collaborationid === 'chicken' ? '请上传动物检疫合格证明' : '请上传法人身份证正反面' } + ]; - if (!this.data.company) { - wx.showToast({ - title: '请填写公司名称', - icon: 'none' - }); - return; + for (const field of requiredFields) { + if (!field.value) { + wx.showToast({ + title: field.error, + icon: 'none' + }); + console.error(`提交失败:${field.error}`); + return; + } } - if (!this.data.detailedaddress || !this.data.detailedaddress.trim()) { + // 检查详细地址是否为空字符串 + if (this.data.detailedaddress && !this.data.detailedaddress.trim()) { wx.showToast({ title: '请填写详细地址', icon: 'none' }); + console.error('提交失败:详细地址为空'); return; } - // 手机号为空时使用默认值,不再强制要求 - if (!contactPhone) { - contactPhone = 'default_phone'; - console.log('使用默认手机号:', contactPhone); - } - - // 验证省市区字段是否填写完整(用于构建region字段) - if (!this.data.province || !this.data.city || !this.data.district) { - wx.showToast({ - title: '请填写完整地址', - icon: 'none' - }); - return; - } - - // 验证营业执照 - if (!this.data.businesslicenseurl) { - this.setData({ - showBusinessLicenseError: true, - businessLicenseError: '请上传营业执照' - }); - wx.showToast({ - title: '请上传营业执照', - icon: 'none' - }); - return; - } else { - this.setData({ - showBusinessLicenseError: false, - businessLicenseError: '' - }); - } + console.log('所有验证通过,准备提交到服务器'); - // 验证动物检疫合格证明或法人身份证 - if (!this.data.proofurl) { - this.setData({ - showProofError: true, - proofError: this.data.collaborationid === 'chicken' ? '请上传动物检疫合格证明' : '请上传法人身份证正反面' - }); - wx.showToast({ - title: this.data.collaborationid === 'chicken' ? '请上传动物检疫合格证明' : '请上传法人身份证正反面', - icon: 'none' - }); - return; - } else { - this.setData({ - showProofError: false, - proofError: '' - }); - } - - // 记录省市区字段内容 - console.log('省市区字段内容:', this.data.province, this.data.city, this.data.district); - - // 文件上传现在为选填,不再强制要求 + // 记录文件上传状态 console.log('文件上传状态:', { businessLicenseFile: !!uploadedFiles.businessLicenseFile, animalQuarantineFile: !!uploadedFiles.animalQuarantineFile, @@ -890,28 +860,10 @@ Page({ }); try { - // 调用后端API提交入驻申请 - // 使用API.BASE_URL构建正确的请求路径 + // 第七步:调用后端API提交数据 const API = require('../../utils/api'); console.log('开始提交入驻申请,API地址:', API.BASE_URL + '/api/settlement/submit'); console.log('提交的完整数据:', submitData); - // 详细检查后端必需的关键字段(使用独立的省市区字段) - const requiredFieldsCheck = { - openid: { value: submitData.openid, exists: !!submitData.openid }, - collaborationid: { value: submitData.collaborationid, exists: !!submitData.collaborationid }, - cooperation: { value: submitData.cooperation, exists: !!submitData.cooperation }, - company: { value: submitData.company, exists: !!submitData.company }, - phoneNumber: { value: submitData.phoneNumber, exists: !!submitData.phoneNumber }, - province: { value: submitData.province, exists: !!submitData.province }, - city: { value: submitData.city, exists: !!submitData.city }, - district: { value: submitData.district, exists: !!submitData.district } - }; - - console.log('后端必需字段详细检查:', requiredFieldsCheck); - - // 检查是否所有必需字段都已填写 - const allRequiredFieldsExist = Object.values(requiredFieldsCheck).every(field => field.exists); - console.log('是否所有后端必需字段都已填写:', allRequiredFieldsExist); const result = await new Promise((resolve, reject) => { wx.request({ @@ -928,17 +880,17 @@ Page({ } }); }); + console.log('入驻申请提交结果:', result); - console.log('请求状态码:', result.code); - console.log('请求消息:', result.message); if (result && result.success) { - // 更新本地状态 + // 提交成功处理 + console.log('提交成功!服务器返回:', result); wx.setStorageSync('settlementStatus', 'underreview'); - // 保存applicationId到本地存储,供撤回功能使用 const appId = result.data?.id || null; if (appId) { wx.setStorageSync('applicationId', appId); + console.log('保存applicationId:', appId); } wx.showToast({ @@ -947,10 +899,10 @@ Page({ duration: 2000 }); - // 跳转到审核状态页面 - 立即执行 + // 跳转到审核状态页面 this.setData({ - currentStep: 3, // 设置为第4步(审核状态页面) - partnerstatus: 'underreview', // 使用数据库字段名 (原auditStatus) + currentStep: 3, + partnerstatus: 'underreview', applicationId: appId }); @@ -962,16 +914,12 @@ Page({ console.error('更新用户类型失败:', err); }); - // 调用API获取用户完整数据 - 异步执行,不影响跳转 - API.getUserInfo().then(userRes => { - console.log('用户完整数据:', userRes.data); - }).catch(err => { - console.error('获取用户数据失败:', err); - }); - - // 清除进度数据,因为已经提交了 + // 清除进度数据 this.clearSettlementProgress(); + console.log('===== 入驻申请提交成功 ====='); } else { + // 提交失败处理 + console.error('提交失败,服务器返回:', result); if (result.code === 400 && result.message.includes('已有待审核的入驻申请')) { wx.showToast({ title: result.message, @@ -997,6 +945,7 @@ Page({ icon: 'none' }); } + console.log('===== 提交流程结束 ====='); }, diff --git a/utils/api.js b/utils/api.js index 80b722c..2b37cfe 100644 --- a/utils/api.js +++ b/utils/api.js @@ -3438,7 +3438,7 @@ module.exports = { console.log('用户类型更新成功:', newType); - // 上传到服务器 + // 上传到服务器 - 只上传必要的字段,避免覆盖其他数据 const uploadData = { userId, openid, @@ -3446,17 +3446,6 @@ module.exports = { timestamp: Date.now() }; - // 如果有userInfo,合并其属性但不覆盖已有的关键属性 - if (userInfo) { - const userInfoCopy = { ...userInfo }; - delete userInfoCopy.userId; // 不覆盖userId - delete userInfoCopy.openid; // 不覆盖openid - delete userInfoCopy.type; // 不覆盖type - delete userInfoCopy.timestamp; // 不覆盖timestamp - delete userInfoCopy.partnerstatus; // 不覆盖partnerstatus字段,避免清空入驻状态 - Object.assign(uploadData, userInfoCopy); - } - console.log('准备上传用户类型到服务器:', uploadData); // 调用用户信息更新API