hldy_xcx/pages/addoldman/IDcard.vue

298 lines
5.9 KiB
Vue

<template>
<div class="container">
<view class="title-back">
<view class="left-father" @click="goBack">
<image class="back-img" src="https://www.focusnu.com/media/directive/index/left.png" />
<view style="font-size: 30rpx;">监护人信息</view>
</view>
</view>
<view class="white-content">
<view class="content-title">
<view class="shu"></view>
<view class="content-weight">监护人基本信息</view>
</view>
<view class="one">
<view class="one-left">姓名</view>
<input class="one-right" maxlength="11" placeholder="请输入姓名" v-model="form.name" />
</view>
<view class="one">
<view class="one-left">电话</view>
<input class="one-right" type="number" maxlength="11" placeholder="请输入电话" v-model="form.tel" />
</view>
<view class="one">
<view class="one-left">身份证号</view>
<input class="one-right" type="number" maxlength="18" placeholder="请输入身份证号" v-model="form.idCard" />
</view>
<view class="one">
<view class="one-left">家庭住址</view>
<input class="one-right" placeholder="请输入家庭住址" v-model="form.homeAddress" />
</view>
<view class="one">
<view class="one-left">工作单位</view>
<input class="one-right" placeholder="请输入工作单位" v-model="form.workUnit" />
</view>
</view>
<view style="display: flex;width: 100%;position: fixed;bottom: 20rpx;left: 0;">
<view class="finish-button" @click="next">
提交
</view>
</view>
</div>
</template>
<script setup>
import {
ref,
reactive
} from 'vue'
import {
onLoad,
onShow
} from '@dcloudio/uni-app';
import {
base_url
} from '@/request/index.js';
import { savePayer,changePayer } from './api/api.js'
import {
getMessage
} from '@/api/loginApi.js'
const form = reactive({
name: "",
tel: "",
advisoryType: 1,
status: 2,
idCard: "",
homeAddress: "",
workUnit: "",
izJs:1,
openId: uni.getStorageSync('openid'),
})
function isValid11DigitNumber(val) {
return /^(\d{11})$/.test(val);
}
function isValid18DigitNumber(val) {
return /^(\d{18})$/.test(val);
}
const next = () => {
if (!form.name) {
uni.showToast({
title: '请填写姓名',
icon: 'error'
})
} else if (!form.tel) {
uni.showToast({
title: '请填写电话',
icon: 'error'
})
}else if (!isValid11DigitNumber(form.tel)) {
uni.showToast({
title: '电话格式错误',
icon: 'none'
})
return
}
else if (!form.idCard) {
uni.showToast({
title: '请填写身份证号',
icon: 'error'
})
}
else if (!isValid18DigitNumber(form.idCard)) {
uni.showToast({
title: '身份证号格式错误',
icon: 'none'
})
return
} else if (!form.homeAddress) {
uni.showToast({
title: '请填写家庭住址',
icon: 'error'
})
} else if (!form.workUnit) {
uni.showToast({
title: '请填写工作单位',
icon: 'error'
})
} else {
if(uni.getStorageSync('allinfo').name){
form.id = uni.getStorageSync('allinfo').id
changePayer(form).then((res)=>{
// console.log("res",res)
if(res.success){
getMessage(uni.getStorageSync('openid')).then(res=>{
uni.setStorageSync('allinfo', res.result);
uni.reLaunch({
url: "/pages/oldmanindex/index"
});
})
}
})
}else{
savePayer(form).then((res)=>{
if(res.code==401){
savePayer(form).then((res)=>{
if(res.success){
getMessage(uni.getStorageSync('openid')).then(res=>{
uni.setStorageSync('allinfo', res.result);
uni.reLaunch({
url: "/pages/login/callback",
})
})
}
})
}
if(res.success){
getMessage(uni.getStorageSync('openid')).then(res=>{
uni.setStorageSync('allinfo', res.result);
uni.reLaunch({
url: "/pages/login/callback",
})
})
}
})
}
}
}
const goBack = () => {
uni.navigateBack()
}
onLoad(() => {
if (uni.getStorageSync('allinfo').name) {
let data = uni.getStorageSync('allinfo');
const keys = [
"openId",
"name",
"tel",
"advisoryType",
"status",
"idCard",
"homeAddress",
"workUnit",
"izJs",
]
keys.forEach(key => {
form[key] = data[key] || ""
})
}
})
</script>
<style lang="scss" scoped>
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: #F7F7F7;
position: relative;
.white-content {
width: 90%;
margin-left: 5%;
border-radius: 35rpx;
.content-title {
display: flex;
align-items: center;
height: 100rpx;
position: relative;
font-weight: 600;
.content-weight {
font-size: 32rpx;
}
.content-img {
position: absolute;
right: 0;
top: 0;
width: 400rpx;
height: 100%;
}
}
}
}
.finish-button {
display: flex;
justify-content: center;
align-items: center;
width: 80%;
height: 90rpx;
margin: 0rpx auto;
margin-bottom: 80rpx;
margin-top: 20rpx;
color: #fff;
background: linear-gradient(to left, #00C9FF, #0076FF);
border-radius: 35rpx;
font-size: 33rpx;
}
.title-back {
margin-top: 100rpx;
width: 100%;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
.left-father {
display: flex;
align-items: center;
.back-img {
width: 45rpx;
height: 40rpx;
margin-left: 40rpx;
margin-right: 15rpx;
}
}
.shu {
width: 14rpx;
height: 36rpx;
background-color: #0097FF;
border-radius: 10rpx;
margin: 3rpx 20rpx 0 30rpx;
}
.one {
width: 90%;
margin-left: 5%;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10rpx;
.one-left {
margin-left: 10rpx;
font-size: 30rpx;
}
.one-right {
font-size: 30rpx;
height: 100%;
color: #999999;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 350rpx;
display: flex;
}
}
</style>