|
|
|
@ -135,10 +135,13 @@ Page({ |
|
|
|
* 提交认证 |
|
|
|
*/ |
|
|
|
async submitAuth() { |
|
|
|
// 验证是否上传了身份证和营业执照
|
|
|
|
if (!this.data.idCardFront || !this.data.idCardBack || !this.data.businessLicense) { |
|
|
|
// 验证是否上传了身份证正反面或营业执照
|
|
|
|
const hasIdCard = this.data.idCardFront && this.data.idCardBack; |
|
|
|
const hasBusinessLicense = this.data.businessLicense; |
|
|
|
|
|
|
|
if (!hasIdCard && !hasBusinessLicense) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请上传身份证正反面和营业执照', |
|
|
|
title: '请至少上传身份证正反面或营业执照', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
@ -164,20 +167,20 @@ Page({ |
|
|
|
let businessLicenseUrl = this.data.businessLicenseFile?.path || this.data.businessLicense; |
|
|
|
|
|
|
|
// 检查是否是本地路径(需要上传)还是远程URL(直接使用)
|
|
|
|
const isLocalPath = (path) => path && (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('wxfile://') || path.startsWith('cloud://')); |
|
|
|
const isLocalPath = (path) => path && (path.startsWith('http://tmp/') || path.startsWith('https://tmp/') || path.startsWith('wxfile://')); |
|
|
|
|
|
|
|
// 上传身份证正面(仅当是本地路径时)
|
|
|
|
if (this.data.idcard1?.path && !isLocalPath(this.data.idcard1.path)) { |
|
|
|
if (this.data.idcard1?.path && isLocalPath(this.data.idcard1.path)) { |
|
|
|
idcard1Url = await this.uploadFileToServer(this.data.idcard1.path, 'idCardFront'); |
|
|
|
} |
|
|
|
|
|
|
|
// 上传身份证反面(仅当是本地路径时)
|
|
|
|
if (this.data.idcard2?.path && !isLocalPath(this.data.idcard2.path)) { |
|
|
|
if (this.data.idcard2?.path && isLocalPath(this.data.idcard2.path)) { |
|
|
|
idcard2Url = await this.uploadFileToServer(this.data.idcard2.path, 'idCardBack'); |
|
|
|
} |
|
|
|
|
|
|
|
// 上传营业执照(仅当是本地路径时)
|
|
|
|
if (this.data.businessLicenseFile?.path && !isLocalPath(this.data.businessLicenseFile.path)) { |
|
|
|
if (this.data.businessLicenseFile?.path && isLocalPath(this.data.businessLicenseFile.path)) { |
|
|
|
businessLicenseUrl = await this.uploadFileToServer(this.data.businessLicenseFile.path, 'businessLicense'); |
|
|
|
} |
|
|
|
|
|
|
|
@ -186,15 +189,25 @@ Page({ |
|
|
|
// 准备提交数据
|
|
|
|
const submitData = { |
|
|
|
openid: openid, |
|
|
|
userId: userId, |
|
|
|
idcard1: idcard1Url, |
|
|
|
idcard2: idcard2Url, |
|
|
|
businesslicenseurl: businessLicenseUrl, |
|
|
|
name: this.data.name, |
|
|
|
idNumber: this.data.idNumber, |
|
|
|
address: this.data.address |
|
|
|
userId: userId |
|
|
|
}; |
|
|
|
|
|
|
|
// 只提交已上传的认证材料
|
|
|
|
const hasIdCard = this.data.idCardFront && this.data.idCardBack; |
|
|
|
const hasBusinessLicense = this.data.businessLicense; |
|
|
|
|
|
|
|
if (hasIdCard) { |
|
|
|
submitData.idcard1 = idcard1Url; |
|
|
|
submitData.idcard2 = idcard2Url; |
|
|
|
submitData.name = this.data.name; |
|
|
|
submitData.idNumber = this.data.idNumber; |
|
|
|
submitData.address = this.data.address; |
|
|
|
} |
|
|
|
|
|
|
|
if (hasBusinessLicense) { |
|
|
|
submitData.businesslicenseurl = businessLicenseUrl; |
|
|
|
} |
|
|
|
|
|
|
|
console.log('提交数据:', submitData); |
|
|
|
|
|
|
|
// 调用后端API提交数据
|
|
|
|
@ -262,8 +275,11 @@ Page({ |
|
|
|
* 生命周期函数--监听页面显示 |
|
|
|
*/ |
|
|
|
onShow() { |
|
|
|
// 页面显示时加载已存在的认证信息
|
|
|
|
// 只在页面初次加载时加载认证信息,避免覆盖用户正在编辑的内容
|
|
|
|
if (!this.hasLoadedData) { |
|
|
|
this.loadExistingAuthData(); |
|
|
|
this.hasLoadedData = true; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
|