|
|
|
@ -1,4 +1,5 @@ |
|
|
|
// pages/profile/authentication/index.js
|
|
|
|
const API = require('../../../utils/api.js'); |
|
|
|
Page({ |
|
|
|
/** |
|
|
|
* 页面的初始数据 |
|
|
|
@ -6,6 +7,8 @@ Page({ |
|
|
|
data: { |
|
|
|
idCardFront: '', // 身份证人像面
|
|
|
|
idCardBack: '', // 身份证国徽面
|
|
|
|
idcard1: null, // 身份证正面文件信息
|
|
|
|
idcard2: null, // 身份证反面文件信息
|
|
|
|
name: '', // 姓名
|
|
|
|
idNumber: '', // 身份证号
|
|
|
|
address: '', // 居住地址
|
|
|
|
@ -40,26 +43,27 @@ Page({ |
|
|
|
*/ |
|
|
|
uploadImage(field) { |
|
|
|
const _this = this; |
|
|
|
wx.chooseMedia({ |
|
|
|
wx.chooseImage({ |
|
|
|
count: 1, |
|
|
|
mediaType: ['image'], |
|
|
|
sizeType: ['compressed'], |
|
|
|
sourceType: ['album', 'camera'], |
|
|
|
success(res) { |
|
|
|
// 获取图片临时路径
|
|
|
|
const tempFilePaths = res.tempFiles; |
|
|
|
success: (res) => { |
|
|
|
const tempFilePaths = res.tempFilePaths; |
|
|
|
if (tempFilePaths && tempFilePaths.length > 0) { |
|
|
|
// 更新页面数据
|
|
|
|
_this.setData({ |
|
|
|
[field]: tempFilePaths[0].tempFilePath |
|
|
|
[field === 'idCardFront' ? 'idCardFront' : 'idCardBack']: tempFilePaths[0], |
|
|
|
[field === 'idCardFront' ? 'idcard1' : 'idcard2']: { |
|
|
|
path: tempFilePaths[0], |
|
|
|
name: `身份证${field === 'idCardFront' ? '正面' : '反面'}_${new Date().getTime()}.jpg` |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 这里可以添加图片上传到服务器的逻辑
|
|
|
|
// 模拟识别成功后填充信息
|
|
|
|
_this.simulateOcrResult(); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail(err) { |
|
|
|
fail: (err) => { |
|
|
|
console.error('选择图片失败:', err); |
|
|
|
wx.showToast({ |
|
|
|
title: '选择图片失败', |
|
|
|
@ -83,10 +87,35 @@ Page({ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 上传文件到服务器 |
|
|
|
*/ |
|
|
|
async uploadFileToServer(filePath, fileType) { |
|
|
|
try { |
|
|
|
console.log(`开始上传${fileType}文件:`, filePath); |
|
|
|
|
|
|
|
const result = await API.uploadSettlementFile(filePath, fileType); |
|
|
|
|
|
|
|
if (result && result.fileUrl) { |
|
|
|
console.log(`${fileType}上传成功:`, result.fileUrl); |
|
|
|
return result.fileUrl; |
|
|
|
} else { |
|
|
|
throw new Error(`${fileType}上传失败`); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error(`${fileType}上传失败:`, error); |
|
|
|
wx.showToast({ |
|
|
|
title: `${fileType}上传失败`, |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
throw error; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 提交认证 |
|
|
|
*/ |
|
|
|
submitAuth() { |
|
|
|
async submitAuth() { |
|
|
|
// 验证是否上传了身份证
|
|
|
|
if (!this.data.idCardFront || !this.data.idCardBack) { |
|
|
|
wx.showToast({ |
|
|
|
@ -96,11 +125,47 @@ Page({ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 这里可以添加提交认证信息到服务器的逻辑
|
|
|
|
wx.showLoading({ title: '提交中...' }); |
|
|
|
// 检查用户是否已登录
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
|
|
|
|
|
// 模拟提交成功
|
|
|
|
setTimeout(() => { |
|
|
|
if (!openid || !userId) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请先登录', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
wx.showLoading({ title: '正在上传文件...', mask: true }); |
|
|
|
|
|
|
|
try { |
|
|
|
// 上传身份证正面
|
|
|
|
const idcard1Url = await this.uploadFileToServer(this.data.idcard1.path, 'idCardFront'); |
|
|
|
// 上传身份证反面
|
|
|
|
const idcard2Url = await this.uploadFileToServer(this.data.idcard2.path, 'idCardBack'); |
|
|
|
|
|
|
|
console.log('所有文件上传完成'); |
|
|
|
|
|
|
|
// 准备提交数据
|
|
|
|
const submitData = { |
|
|
|
openid: openid, |
|
|
|
userId: userId, |
|
|
|
idcard1: idcard1Url, |
|
|
|
idcard2: idcard2Url, |
|
|
|
name: this.data.name, |
|
|
|
idNumber: this.data.idNumber, |
|
|
|
address: this.data.address |
|
|
|
}; |
|
|
|
|
|
|
|
console.log('提交数据:', submitData); |
|
|
|
|
|
|
|
// 调用后端API提交数据
|
|
|
|
const result = await API.request('/api/user/update', 'POST', submitData); |
|
|
|
|
|
|
|
console.log('认证提交结果:', result); |
|
|
|
|
|
|
|
if (result && result.success) { |
|
|
|
wx.hideLoading(); |
|
|
|
wx.showToast({ |
|
|
|
title: '认证成功', |
|
|
|
@ -112,7 +177,21 @@ Page({ |
|
|
|
setTimeout(() => { |
|
|
|
this.navigateBack(); |
|
|
|
}, 1500); |
|
|
|
}, 1000); |
|
|
|
} else { |
|
|
|
wx.hideLoading(); |
|
|
|
wx.showToast({ |
|
|
|
title: result.message || '认证失败', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
wx.hideLoading(); |
|
|
|
console.error('认证提交失败:', error); |
|
|
|
wx.showToast({ |
|
|
|
title: '提交失败,请重试', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
|