officialAccount/pages/addjigou/name.vue

616 lines
15 KiB
Vue
Raw Normal View History

2025-06-09 17:33:50 +08:00
<template>
<div class="container">
<u-modal v-model="show" :content="content"></u-modal>
<view class="title-back">
<view class="left-father" @click="goBack">
2025-06-19 17:03:31 +08:00
<image class="back-img" src="https://www.focusnu.com/media/directive/index/left.png" />
2025-06-23 17:31:43 +08:00
<view style="font-size: 30rpx;">企业加盟</view>
2025-06-09 17:33:50 +08:00
</view>
</view>
<view class="white-content">
<view class="content-title">
2025-06-23 17:31:43 +08:00
<view class="shu"></view>
<view class="content-weight">身份证</view>
<view style="font-size: 20rpx;margin: 12rpx 0 0 15rpx;">(必填)</view>
2025-06-09 17:33:50 +08:00
</view>
2025-06-23 17:31:43 +08:00
<view class="white-photo" @click="selectphoto(0)">
2025-06-09 17:33:50 +08:00
<view class="photo-left">
<view class="photo-weight">人像面</view>
<view class="photo-font">请上传身份证人像面</view>
</view>
<view style="position: relative;">
2025-06-23 17:31:43 +08:00
<image class="photo"
:src="headImge ? headImge : `https://www.focusnu.com/media/directive/index/IDcard.png`" />
2025-06-19 17:03:31 +08:00
<image v-if="!headImge"
2025-06-09 17:33:50 +08:00
style="position: absolute;top: 50%;left: 50%;width: 70rpx;height: 60rpx;transform: translate(-50%,-50%);"
2025-06-19 17:03:31 +08:00
src="https://www.focusnu.com/media/directive/index/takephoto.png" />
2025-06-09 17:33:50 +08:00
</view>
</view>
2025-06-23 17:31:43 +08:00
<view class="white-photo" style="margin-top: 30rpx;" @click="selectphoto(1)">
2025-06-09 17:33:50 +08:00
<view class="photo-left">
<view class="photo-weight">国徽面</view>
<view class="photo-font">请上传身份证国徽面</view>
</view>
<view style="position: relative;">
2025-06-23 17:31:43 +08:00
<image class="photo"
:src="backImge ? backImge : `https://www.focusnu.com/media/directive/index/backIDcard.png`" />
2025-06-19 17:03:31 +08:00
<image v-if="!backImge"
2025-06-11 17:33:34 +08:00
style="position: absolute;top: 50%;left: 50%;width: 70rpx;height: 60rpx;transform: translate(-50%,-50%);"
2025-06-19 17:03:31 +08:00
src="https://www.focusnu.com/media/directive/index/takephoto.png" />
2025-06-09 17:33:50 +08:00
</view>
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
</view>
2025-06-23 17:31:43 +08:00
<view class="content-title" style="margin: 20rpx 0;">
<view class="shu"></view>
<view class="content-weight">确认身份证信息</view>
<!-- <view style="font-size: 20rpx;margin: 15rpx 0 0 15rpx;">(必填)</view> -->
</view>
2025-06-09 17:33:50 +08:00
<view class="white-message">
2025-06-23 17:31:43 +08:00
<!-- <view class="message-title">
2025-06-09 17:33:50 +08:00
<view class="shu"></view>
<view class="message-weight">
确认身份证信息
</view>
2025-06-23 17:31:43 +08:00
</view> -->
<view>
2025-06-09 17:33:50 +08:00
<view v-for="(item,index) in nameArray" :key="index" class="one"
@click="openLook(textArray[index])">
<view class="one-left">{{item}}</view>
<!-- <view class="one-right">{{textArray[index] ? textArray[index] : "自动获取" }}</view> -->
<view class="one-right">{{textArray[index] ? textArray[index] : "自动获取" }}</view>
</view>
</view>
</view>
</view>
<view class="gray-font">
2025-06-23 17:31:43 +08:00
<view style="color: #333333;">注意事项:</view>
<view style="margin-top: 30rpx;font-size: 28rpx;">
<view class="line">1.同一个身份证号只能认证一个账号</view>
<view class="line">2.国徽与正面信息应为同一身份证的信息且在有效期内</view>
<view class="line">3.所有上传照片需清晰且未遮挡请勿进行美化和修改</view>
<view class="line">4.所有上传信息均会被妥善保管不会用于其他商业用途或传输给第三方</view>
</view>
2025-06-09 17:33:50 +08:00
</view>
<view style="display: flex;width: 100%;">
<!-- <view class="finish-button" @click="goBack">
上一步
</view> -->
<view class="finish-button" @click="next">
2025-06-23 17:31:43 +08:00
确认并继续
2025-06-09 17:33:50 +08:00
</view>
</view>
2025-06-23 17:31:43 +08:00
<u-action-sheet :list="bottomlist" @click="photoclick" v-model="bottomshow"></u-action-sheet>
2025-06-09 17:33:50 +08:00
</div>
</template>
<script setup>
import {
ref,
reactive
} from 'vue'
import {
2025-06-20 17:32:20 +08:00
onLoad,
onShow
2025-06-09 17:33:50 +08:00
} from '@dcloudio/uni-app';
2025-06-11 17:33:34 +08:00
import {
base_url
} from '@/request/index.js';
import {
changemessage
} from './api/addjigou.js'
2025-06-09 17:33:50 +08:00
const show = ref(false);
const content = ref("");
2025-06-23 17:31:43 +08:00
const bottomshow = ref(false);
const bottomlist = [{
text: '拍摄图片',
fontSize: 40
}, {
text: '图片预览',
fontSize: 40
}]
2025-06-09 17:33:50 +08:00
const nameArray = ["姓名", "性别", "身份证号码", "民族", "出生日期", "住址", "签发机关", "有效期限"];
const textArray = reactive(["", "", "", "", "", "", "", ""]);
2025-06-11 17:33:34 +08:00
const states = ["审核中", "审核未通过", "审核通过"];
const fontphoto = ref("");
const endphoto = ref("");
2025-06-09 17:33:50 +08:00
const statesTarget = ref(0);
const shenhe = () => {
2025-06-11 17:33:34 +08:00
if (statesTarget.value == 2) {
statesTarget.value = 0
} else {
2025-06-09 17:33:50 +08:00
statesTarget.value++
}
}
2025-06-23 17:31:43 +08:00
const photoclick = (element) => {
if(element){
uni.previewImage({
urls: [headImge.value,backImge.value], // 必填,所有要预览的图片地址数组
current: targetphoto.value?backImge.value:headImge.value , // 可选,当前显示图片的地址,默认是 urls[0]
indicator: 'default', // 可选指示器样式H5/App 有效,值为 'default'(圆点)或 'number'(数字)
longPressActions: { // 可选,仅 App 支持,长按图片时弹出的操作项
itemList: ['保存图片到相册'],
},
});
}else{
getMessage()
}
}
2025-06-09 17:33:50 +08:00
// 本地保存的临时文件路径
const tempImagePath = ref('')
2025-06-23 17:31:43 +08:00
const targetphoto = ref(0)
const selectphoto = (number) =>{
if(backImge.value && headImge.value){
targetphoto.value = number
bottomshow.value = true;
}else{
getMessage()
}
}
2025-06-09 17:33:50 +08:00
// 拍照并上传
function getMessage() {
// 使用 UniApp 的 API 调用摄像头
uni.chooseImage({
count: 1,
2025-06-23 17:31:43 +08:00
sourceType: ['album', 'camera'],
2025-06-09 17:33:50 +08:00
success: chooseRes => {
tempImagePath.value = chooseRes.tempFilePaths[0]
// 拍照成功后,调用上传函数
2025-06-23 17:31:43 +08:00
uni.navigateTo({
url: `/compontent/public/camera?url=${chooseRes.tempFilePaths[0]}&type=0`
});
2025-06-09 17:33:50 +08:00
},
fail: err => {
console.error('拍照失败:', err)
}
})
}
const headImge = ref("");
const backImge = ref("");
2025-06-11 17:33:34 +08:00
// 日期转换
function formatChineseDate(chineseDate) {
return chineseDate.replace(/(\d+)年(\d+)月(\d+)日/, (_, y, m, d) => {
return `${y}.${m}.${d}`;
});
}
2025-06-09 17:33:50 +08:00
2025-06-11 17:33:34 +08:00
function toIsoDate(dateStr) {
return dateStr.replace(
/(\d{2,4})\.(\d{1,2})\.(\d{1,2})/,
(_, y, m, d) => {
// 月日补齐两位
const mm = m.padStart(2, '0');
const dd = d.padStart(2, '0');
return `${y}-${mm}-${dd}`;
}
);
}
2025-06-09 17:33:50 +08:00
// 上传图片到服务器
function uploadImage(filePath) {
2025-06-13 13:42:14 +08:00
uping.value = false;
2025-06-09 17:33:50 +08:00
uni.showLoading()
uni.uploadFile({
url: `${base_url}/api/ocr/idCard`, // 替换为你的POST接口地址
filePath,
name: 'file', // 后端接收时的字段名
header: {
'X-Access-Token': uni.getStorageSync('token') || '',
},
formData: {},
success: uploadRes => {
2025-06-11 17:33:34 +08:00
console.log("token", uni.getStorageSync('token'))
2025-06-09 17:33:50 +08:00
if (!JSON.parse(uploadRes.data).success) {
uni.showToast({
title: '识别失败',
2025-06-23 17:31:43 +08:00
icon: 'error',
duration: 2000
2025-06-09 17:33:50 +08:00
})
2025-06-23 17:31:43 +08:00
uping.value = true;
2025-06-09 17:33:50 +08:00
uni.hideLoading()
return
}
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.face) {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.face.data;
textArray[0] = father.name;
textArray[1] = father.sex;
textArray[2] = father.idNumber;
textArray[3] = father.ethnicity;
textArray[4] = father.birthDate;
textArray[5] = father.address;
uni.showToast({
title: '识别成功',
})
headImge.value = filePath;
2025-06-11 17:33:34 +08:00
savephoto(filePath, 0);
2025-06-09 17:33:50 +08:00
uni.hideLoading()
2025-06-23 17:31:43 +08:00
} else if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.back)
{
2025-06-09 17:33:50 +08:00
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.back.data;
textArray[6] = father.issueAuthority;
textArray[7] = father.validPeriod;
uni.showToast({
title: '识别成功',
})
backImge.value = filePath;
2025-06-11 17:33:34 +08:00
savephoto(filePath, 1);
2025-06-09 17:33:50 +08:00
uni.hideLoading()
2025-06-23 17:31:43 +08:00
} else {
uni.showToast({
title: '识别失败',
icon: 'error',
duration: 2000
})
uping.value = false;
uni.hideLoading()
2025-06-09 17:33:50 +08:00
}
},
fail: err => {
uni.showToast({
title: '上传出错',
icon: 'error'
})
uni.hideLoading()
}
})
}
2025-06-13 13:42:14 +08:00
const uping = ref(true)
2025-06-11 17:33:34 +08:00
const savephoto = (filePath, type) => {
2025-06-09 17:33:50 +08:00
uni.uploadFile({
url: `${base_url}/sys/common/upload`, // 替换为你的POST接口地址
filePath,
name: 'file', // 后端接收时的字段名
header: {
'X-Access-Token': uni.getStorageSync('token') || '',
},
formData: {
biz: `temp`
},
success: uploadRes => {
2025-06-11 17:33:34 +08:00
if (!type) {
fontphoto.value = JSON.parse(uploadRes.data).message
} else {
endphoto.value = JSON.parse(uploadRes.data).message
}
2025-06-13 13:42:14 +08:00
uping.value = true;
2025-06-09 17:33:50 +08:00
},
fail: err => {
uni.showToast({
title: '上传出错',
icon: 'error'
})
uni.hideLoading()
}
})
}
const openLook = (res) => {
if (res) {
content.value = res;
show.value = true
}
}
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
const next = () => {
2025-06-23 17:31:43 +08:00
// console.log("??????")
2025-06-11 17:33:34 +08:00
const allNonEmpty = textArray.every(item => {
// 如果想忽略前后空格,可用 item.trim() !== ''
return item !== '';
2025-06-09 17:33:50 +08:00
});
2025-06-23 17:31:43 +08:00
if (!uping.value) {
2025-06-13 13:42:14 +08:00
return
}
2025-06-11 17:33:34 +08:00
if (allNonEmpty) {
const range = textArray[7];
const [start, end] = range.split('-');
let pushMessage = {
id: uni.getStorageSync('specicalid') || "",
tel: uni.getStorageSync('tel'),
name: textArray[0],
sex: textArray[1],
idCard: textArray[2],
national: textArray[3],
birthDate: textArray[4],
idCardAddress: textArray[5],
issuingAuthority: textArray[6],
startTime: start,
endTime: end,
2025-06-23 17:31:43 +08:00
cardZmPath: fontphoto.value,
cardFmPath: endphoto.value
2025-06-11 17:33:34 +08:00
}
// console.log("????",pushMessage)
changemessage(pushMessage).then(res => {
2025-06-23 17:31:43 +08:00
if (res.success) {
if (res.message == `保存成功!`) {
2025-06-11 17:33:34 +08:00
uni.navigateTo({
url: "/pages/addjigou/card"
});
2025-06-23 17:31:43 +08:00
} else {
2025-06-11 17:33:34 +08:00
uni.setStorageSync('specicalid', res.result.id);
uni.navigateTo({
url: "/pages/addjigou/card"
});
}
2025-06-23 17:31:43 +08:00
} else {
2025-06-11 17:33:34 +08:00
uni.showToast({
title: res.message,
icon: 'error'
})
}
})
} else {
uni.showToast({
title: '请完善信息',
icon: 'error'
})
}
2025-06-09 17:33:50 +08:00
}
const goBack = () => {
uni.navigateBack()
}
onLoad(() => {
2025-06-23 17:31:43 +08:00
if (uni.getStorageSync('baddata')) {
2025-06-13 13:42:14 +08:00
let data = uni.getStorageSync('baddata');
textArray[0] = data.name;
textArray[1] = data.sex;
textArray[2] = data.idCard;
textArray[3] = data.national;
textArray[4] = data.birthDate;
textArray[5] = data.idCardAddress;
textArray[6] = data.issuingAuthority;
textArray[7] = `${data.startTime}-${data.endTime}`;
headImge.value = `${base_url}/sys/common/static/${data.cardZmPath}`;
backImge.value = `${base_url}/sys/common/static/${data.cardFmPath}`;
fontphoto.value = data.cardZmPath
endphoto.value = data.cardFmPath
}
2025-06-11 17:33:34 +08:00
2025-06-09 17:33:50 +08:00
})
2025-06-20 17:32:20 +08:00
onShow(() => {
2025-06-23 17:31:43 +08:00
const img = uni.getStorageSync('imgkey0')
if (img) {
uploadImage(img)
uni.removeStorageSync('imgkey0')
}
2025-06-20 17:32:20 +08:00
})
2025-06-09 17:33:50 +08:00
</script>
<style lang="scss" scoped>
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
2025-06-23 17:31:43 +08:00
background-color: #F7F7F7;
2025-06-09 17:33:50 +08:00
position: relative;
2025-06-23 17:31:43 +08:00
// box-shadow: 2rpx 2rpx 4rpx rgba(0, 0, 0, 0.1);
2025-06-09 17:33:50 +08:00
.white-content {
width: 90%;
margin-left: 5%;
// margin-top: 30rpx;
// height: 1200rpx;
border-radius: 35rpx;
2025-06-23 17:31:43 +08:00
// background-color: rgb(245, 251, 254);
2025-06-09 17:33:50 +08:00
.content-title {
display: flex;
2025-06-23 17:31:43 +08:00
align-items: center;
2025-06-09 17:33:50 +08:00
height: 100rpx;
position: relative;
2025-06-23 17:31:43 +08:00
font-weight: 600;
2025-06-09 17:33:50 +08:00
.content-weight {
// font-size: 35rpx;
2025-06-23 17:31:43 +08:00
// margin-left: 10rpx;
font-size: 32rpx;
// margin-top: 20rpx;
2025-06-09 17:33:50 +08:00
}
.content-img {
position: absolute;
right: 0;
top: 0;
width: 400rpx;
height: 100%;
}
}
}
.white-photo {
2025-06-23 17:31:43 +08:00
width: 100%;
// margin-left: 5%;
2025-06-09 17:33:50 +08:00
// margin-top: 30rpx;
height: 300rpx;
border-radius: 35rpx;
background-color: #fff;
2025-06-23 17:31:43 +08:00
// box-shadow: 4rpx 4rpx 8rpx rgba(0, 0, 0, 0.1);
2025-06-09 17:33:50 +08:00
justify-content: space-around;
align-items: center;
display: flex;
.photo {
width: 300rpx;
height: 200rpx;
}
}
.white-message {
2025-06-23 17:31:43 +08:00
width: 100%;
// margin-left: 5%;
margin-top: 20rpx;
padding-top: 20rpx;
padding-bottom: 20rpx;
2025-06-09 17:33:50 +08:00
margin-bottom: 30rpx;
// height: 800rpx;
border-radius: 35rpx;
background-color: #fff;
2025-06-23 17:31:43 +08:00
// box-shadow: 4rpx 4rpx 8rpx rgba(0, 0, 0, 0.1);
2025-06-09 17:33:50 +08:00
justify-content: space-around;
// align-items: center;
display: flex;
flex-direction: column;
.message-title {
width: 100%;
height: 100rpx;
align-items: center;
display: flex;
2025-06-23 17:31:43 +08:00
2025-06-09 17:33:50 +08:00
.message-weight {
font-size: 30rpx;
// font-weight: 600;
}
}
.one {
width: 90%;
margin-left: 5%;
2025-06-23 17:31:43 +08:00
// border-bottom: 1rpx solid #F7F7F7;
height: 100rpx;
2025-06-09 17:33:50 +08:00
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10rpx;
.one-left {
margin-left: 10rpx;
2025-06-23 17:31:43 +08:00
font-size: 30rpx;
2025-06-09 17:33:50 +08:00
}
.one-right {
margin-right: 10rpx;
2025-06-23 17:31:43 +08:00
font-size: 30rpx;
2025-06-09 17:33:50 +08:00
color: #999999;
overflow: hidden;
/* 隐藏超出内容 */
white-space: nowrap;
/* 不换行 */
text-overflow: ellipsis;
2025-06-23 17:31:43 +08:00
max-width: 380rpx;
2025-06-09 17:33:50 +08:00
}
}
}
}
.photo-left {
.photo-weight {
2025-06-23 17:31:43 +08:00
font-size: 32rpx;
2025-06-09 17:33:50 +08:00
font-weight: 600;
2025-06-23 17:31:43 +08:00
color: #333;
2025-06-09 17:33:50 +08:00
}
.photo-font {
2025-06-23 17:31:43 +08:00
font-size: 28rpx;
2025-06-09 17:33:50 +08:00
margin-top: 10rpx;
2025-06-23 17:31:43 +08:00
color: #666;
2025-06-09 17:33:50 +08:00
}
}
.gray-font {
2025-06-23 17:31:43 +08:00
padding: 20rpx 60rpx;
padding-bottom: 35rpx;
2025-06-09 17:33:50 +08:00
color: #999999;
}
.finish-button {
display: flex;
justify-content: center;
align-items: center;
2025-06-23 17:31:43 +08:00
width: 92%;
height: 90rpx;
2025-06-09 17:33:50 +08:00
margin: 0rpx auto;
margin-bottom: 80rpx;
2025-06-23 17:31:43 +08:00
margin-top: 20rpx;
2025-06-09 17:33:50 +08:00
color: #fff;
background: linear-gradient(to right, #00C9FF, #0076FF);
border-radius: 50rpx;
font-size: 35rpx;
}
2025-06-11 17:33:34 +08:00
.title-back {
2025-06-20 17:32:20 +08:00
margin-top: 100rpx;
2025-06-09 17:33:50 +08:00
width: 100%;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
2025-06-11 17:33:34 +08:00
.left-father {
2025-06-09 17:33:50 +08:00
display: flex;
align-items: center;
2025-06-11 17:33:34 +08:00
.back-img {
2025-06-23 17:31:43 +08:00
width: 40rpx;
height: 40rpx;
2025-06-09 17:33:50 +08:00
margin-left: 40rpx;
2025-06-23 17:31:43 +08:00
margin-right: 15rpx;
2025-06-09 17:33:50 +08:00
}
}
2025-06-11 17:33:34 +08:00
.rightStautes {
2025-06-09 17:33:50 +08:00
width: 170rpx;
height: 62rpx;
border-radius: 60rpx;
background-color: #FF913A;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
margin-right: 30rpx;
}
2025-06-11 17:33:34 +08:00
.rightStautesred {
2025-06-09 17:33:50 +08:00
width: 170rpx;
height: 62rpx;
border-radius: 60rpx;
2025-06-11 17:33:34 +08:00
background: linear-gradient(to right, #FF4A76, #FF553A);
2025-06-09 17:33:50 +08:00
display: flex;
justify-content: center;
align-items: center;
color: #fff;
margin-right: 30rpx;
}
2025-06-11 17:33:34 +08:00
.rightStautesblue {
2025-06-09 17:33:50 +08:00
width: 170rpx;
height: 62rpx;
border-radius: 60rpx;
2025-06-11 17:33:34 +08:00
background: linear-gradient(to right, #00C9FF, #0076FF);
2025-06-09 17:33:50 +08:00
display: flex;
justify-content: center;
align-items: center;
color: #fff;
margin-right: 30rpx;
}
2025-06-23 17:31:43 +08:00
.shu {
width: 14rpx;
height: 36rpx;
background-color: #0097FF;
border-radius: 10rpx;
margin: 3rpx 20rpx 0 30rpx;
}
.line {
margin: 10rpx 0;
}
2025-06-09 17:33:50 +08:00
</style>