EditContact.vue
4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<div id="newContact">
<div class="box">
<van-cell-group>
<van-field v-model="userTypeName" label="身份类型" readonly />
<van-field v-model="travelerName" label="姓名" placeholder="需与证件姓名一致" />
<van-cell title="性别">
<template #right-icon>
<van-radio-group v-model="gender" direction="horizontal" style="width:67%;">
<van-radio name="1">男</van-radio>
<van-radio name="2">女</van-radio>
</van-radio-group>
</template>
</van-cell>
<van-field v-model="phone" label="手机号码" maxlength="11" placeholder="请填写手机号码" />
<van-field v-model="travelerIdCard" label="身份证" maxlength="18" placeholder="请填写证件号码" />
</van-cell-group>
</div>
<p class="tip">*请认真核对信息并确保无误</p>
<van-button class="btn" type="primary" @click="addContact">确定</van-button>
</div>
</template>
<script>
export default {
data () {
return {
id: '',
userType: '',
userTypeName: '',
travelerName: '',
phone: '',
gender: '',
travelerIdCard: '',
travelerNum: ''
}
},
mounted () {
let editContact = JSON.parse(localStorage.getItem('editContact'))
this.userType = editContact?.userType
this.userTypeName = editContact?.userType == 1 ? '学生' : '家长'
if (editContact?.travelerIdCard) {
this.travelerIdCard = editContact?.travelerIdCard
}
if (editContact?.travelerMobile) {
this.phone = editContact?.travelerMobile
}
if (editContact?.travelerName) {
this.travelerName = editContact?.travelerName
}
this.userType = editContact?.userType
this.travelerNum = editContact?.travelerNum
},
methods: {
// 确认
addContact () {
if (!this.gender) {
this.$toast('请选择性别')
return;
}
if (!this.phone) {
this.$toast('请输入手机号')
return;
}
if (!this.checkPhone(this.phone)) {
this.$toast('请输入正确的手机号')
return;
}
if (!this.travelerIdCard) {
this.$toast('请输入身份证');
return;
}
if (!this.checkCard(this.travelerIdCard)) {
this.$toast('请输入正确的身份证号')
return;
}
let userInfo = localStorage.getItem('userInfo')
userInfo = userInfo ? JSON.parse(userInfo) : userInfo;
let postData = {
userNum: this.travelerNum,
contactsName: this.travelerName,
contactsMobile: this.phone,
contactsIdCard: this.travelerIdCard,
contactsType: this.userType,
gender: Number(this.gender),
loginMobile: userInfo?.phone
}
this.$toast.loading({
message: '加载中',
duration: 0,
forbidClick: true
})
this.yxAxios.post(`${this.baseUrl}/prod/user/info/addContacts`, postData).then((res) => {
this.$toast.clear()
if (res.data.code == 200) {
this.$toast.success('完善成功')
this.$router.back()
} else {
this.$toast.fail(res.message)
}
})
},
checkPhone (phone) {
if ((/^1[3456789]\d{9}$/.test(phone))) {
return true
} else {
return false
}
},
checkCard (card) {
// 18位身份证校验
if ((/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(card))) {
return true
} else {
return false
}
},
}
}
</script>
<style lang="scss" scoped>
#newContact {
min-height: 100vh;
box-sizing: border-box;
padding: 16px 0;
background: #f6f7fa;
.box {
width: 702px;
margin: 0 auto;
padding: 0 24px;
box-sizing: border-box;
background: #fff;
border-radius: 16px;
.checkbox:not(:last-of-type) {
margin-right: 30px;
}
}
.tip {
margin-top: 16px;
margin-left: 24px;
font-size: 24px;
color: #ff3838;
}
.btn {
position: fixed;
bottom: 100px;
left: 24px;
width: 702px;
height: 90px;
background: #4092ff;
border: 1px solid #4092ff;
box-shadow: 0px 10px 40px 0px #a0c9ff;
border-radius: 45px;
}
}
</style>