SelectContact.vue
6.47 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
<div id="selectContact">
<div class="control">
<div class="add_btn" @click="showAddChildPopupGroup=true">
<van-icon name="add-o" />
新增学生
</div>
<div class="add_btn" @click="addContact">
<van-icon name="add-o" />
新增家长
</div>
</div>
<div class="box">
<template v-for="(item,index) in contactList">
<div class="contact_item" v-if="!hideParent&&item.userType!=1||item.userType==1" :key="index">
<van-checkbox class="checkbox" v-model="item.checked" shape="square"></van-checkbox>
<div class="info">
<p class="name">{{item.travelerName}}<span v-if="!item.travelerIdCard||!item.gender">需完善</span></p>
<p class="des">{{item.userType==1?'学生':'家长'}}·{{item.travelerMobile}}</p>
</div>
<van-icon class="edit" name="edit" @click="editContact(index)" />
</div>
</template>
</div>
<van-button class="btn" type="primary" @click="selectContact">确定</van-button>
<van-popup style="background: transparent;" get-container="body" v-model="showAddChildPopupGroup">
<AddChildPopupGroup @complete="complete" step='1'></AddChildPopupGroup>
</van-popup>
</div>
</template>
<script>
import AddChildPopupGroup from '@/views/Home/component/AddChildPopupGroup'
export default {
data () {
return {
limit: '',
hideParent: false,
contactList: [],
showAddChildPopupGroup: false
}
},
mounted () {
this.limit = this.$route.query.limit;
this.hideParent = this.$route.query.hideParent ? true : false;
console.log(this.hideParent)
this.getContactList()
},
methods: {
// 获取联系人列表
getContactList () {
this.$toast.loading({
message: '加载中...',
duration: 0,
forbidClick: true
})
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
this.yxAxios.get(`${this.baseUrl}/prod/user/info/getPortalUserByNum?userNum=${userInfo.centerNo}`).then((res) => {
this.$toast.clear()
if (res.data.code == 200) {
let userInfo = res.data.data.userInfo;
let contactList = userInfo.subUsers
// 把家长添加到列表
contactList.unshift({
travelerMobile: userInfo?.phone,
travelerNum: userInfo?.centerNo,
travelerIdCard: userInfo?.idCard,
userType: 2,
travelerName: userInfo?.nickName,
gender: userInfo?.gender,
})
this.contactList = contactList
}
})
},
// 修改联系人
editContact (index) {
let contactItem = this.contactList[index]
let editContact = {
travelerMobile: contactItem.travelerMobile,
userType: contactItem.userType,
travelerIdCard: contactItem.travelerIdCard,
travelerNum: contactItem.travelerNum,
travelerName: contactItem.travelerName,
gender: contactItem.gender,
}
localStorage.setItem('editContact', JSON.stringify(editContact))
this.$router.push({ name: 'EditContact' })
},
// 添加家长
addContact () {
this.$router.push({ name: 'EditContact', query: { add: 1 } })
},
complete () {
this.showAddChildPopupGroup = false;
this.getContactList()
},
// 选择联系人完成
selectContact () {
let contactList = this.contactList;
let selectedArr = [];
for (let i in contactList) {
if (contactList[i]?.checked) {
if ((!contactList[i].travelerIdCard || !contactList[i].gender) && !this.hideParent) {
this.$toast('请先完善您选择的出行人信息')
return;
} else {
selectedArr.push({
travelerName: contactList[i].travelerName,
travelerMobile: contactList[i].travelerMobile,
travelerNum: contactList[i].travelerNum,
userType: contactList[i].userType,
})
}
}
}
console.log(this.limit, selectedArr.length)
if (this.limit && this.limit != selectedArr.length) {
this.$toast(`请选择${this.limit}位出行人`)
return;
}
// 判断是否选择学生
let hasStudent = false;
for (let i in selectedArr) {
if (selectedArr[i].userType == 1) {
hasStudent = true
}
}
if (!hasStudent) {
this.$dialog.alert({
title: '温馨提示',
message: '活动参与主体为学生本人,请选择出行学生!未绑定学生,请新增出行学生进行添加。',
confirmButtonColor: '#3385FF'
})
return;
}
// console.log(selectedArr)
localStorage.setItem('selectedContactArr', JSON.stringify(selectedArr))
this.$router.back()
}
},
components: {
AddChildPopupGroup
}
}
</script>
<style lang="scss" scoped>
#selectContact {
min-height: 100vh;
box-sizing: border-box;
padding: 16px 0;
background: #f6f7fa;
.control {
width: 702px;
margin: 0 auto;
padding: 0 24px;
box-sizing: border-box;
background: #fff;
border-radius: 16px;
margin-bottom: 24px;
.add_btn {
display: inline-block;
width: 50%;
line-height: 104px;
font-size: 28px;
color: #4092ff;
text-align: center;
}
}
.box {
width: 702px;
margin: 0 auto;
padding: 0 24px;
padding-bottom: 200px;
box-sizing: border-box;
background: #fff;
border-radius: 16px;
.contact_item {
display: flex;
align-items: center;
justify-content: space-between;
.edit {
padding: 20px 0px 20px 20px;
font-size: 40px;
color: #4092ff;
}
.info {
width: 500px;
padding: 28px 0;
.name {
display: flex;
align-items: center;
font-size: 30px;
span {
display: inline-block;
padding: 2px 8px;
margin-left: 16px;
font-size: 20px;
color: #fe3b3b;
background: #ffeeee;
border-radius: 4px;
}
}
.des {
font-size: 26px;
color: #999;
}
}
.checkbox {
padding: 20px 20px 20px 0px;
}
}
}
.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>