index.vue
4.91 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
<!-- 我的页面 -->
<template>
<view class="my">
<!-- banner图 -->
<view class="banner">
<!-- 头像用户名 -->
<view class="headBox" @click="toLogin">
<image :src="avatarUrl" />
<view class="userName">{{nickName}}</view>
</view>
</view>
<!-- 地址簿,实名认证,专属快递员 -->
<view class="list-top">
<view class="list-item" @click="handleToAddress">
<view class="left">
<image class="icon" src='../../static/my-address.png' />
<view class="label">地址簿</view>
</view>
<image class="arrow" src='../../static/icon15.png' />
</view>
<view class="list-item" @click="handleTorealName">
<view class="left">
<image class="icon" src='../../static/my-name.png' />
<view class="label">实名认证</view>
</view>
<image class="arrow" src='../../static/icon15.png' />
</view>
<view class="list-item" @click="handleSecondQi">
<view class="left">
<image class="icon" src='../../static/my-send.png' />
<view class="label">专属快递员</view>
</view>
<image class="arrow" src='../../static/icon15.png' />
</view>
</view>
<view class="list-bottom" v-if="token">
<picker mode="selector" @change="changeSex" :value="sex" :range="sexList">
<view class="list-item sex">
<view class="label">性别</view>
<view class="item-value">{{sex?'男':'女'}}</view>
<image class="arrow" src='../../static/icon15.png' />
</view>
</picker>
<view class="line"></view>
<picker mode="date" :value="birthday" :start="startDate" :end="endDate" @change="getDateChange">
<view class="list-item">
<view class="label">生日</view>
<view class="item-value">{{birthday}}</view>
<image class="arrow" src='../../static/icon15.png' />
</view>
</picker>
</view>
<view class="logout" @click="handleLogout" v-if="token">退出登录</view>
</view>
<!-- end -->
</template>
<script setup>
import {
ref,
reactive,
} from 'vue';
import {
getUserInfo,
updateUserInfo
} from '@/pages/api/my.js';
import {
onShow,
} from '@dcloudio/uni-app';
import {
handleSecondQi
} from '@/utils/index.js'
const token = ref()
const sexList = reactive(['女', '男'])
let nickName = ref('')
let avatarUrl = ref('')
let startDate = ref()
let endDate = ref()
let idCard = ref('')
let name = ref('')
let sex = ref(1)
let birthday = ref('1995-09-01')
const isRealNameAuth = ref(false)
onShow(() => {
startDate.value = getDate('start')
endDate.value = getDate('end')
nickName.value = uni.getStorageSync('nickName') || '地利用户'
avatarUrl.value = uni.getStorageSync('avatarUrl') || '../../static/defaultHeadImg.png'
token.value = uni.getStorageSync('token')
baseUserInfo()
})
//退出登录
const handleLogout = () => {
uni.removeStorageSync('token');
uni.removeStorageSync('nickName');
uni.removeStorageSync('avatarUrl');
uni.switchTab({
url: '/pages/index/index'
});
}
const baseUserInfo = () => {
getUserInfo().then((res) => {
if (res) {
isRealNameAuth.value = Boolean(res.data.idCardNoVerify)
idCard.value = res.data.idCardNo || ''
name.value = res.data.name
sex.value = res.data.sex
birthday.value = res.data.birthday
nickName.value = res.data.phone
uni.setStorageSync('nickName', res.data.phone);
}
})
}
const getDate = (type) => {
const date = new Date()
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
if (type === "start") {
year = year - 60
} else {
year = year + 2
}
month = month > 9 ? month : "0" + month
day = day > 9 ? day : '0' + day
return `${year}-${month}-${day}`
}
const toLogin = () => {
if (uni.getStorageSync('token')) {
getUserInfoFunc()
} else {
uni.navigateTo({
url: '/pages/login/index'
});
}
}
//跳转到地址簿
const handleToAddress = () => {
uni.navigateTo({
url: uni.getStorageSync('token') ? '/pages/address/index?type=address&isFromAddress=true' :
'/pages/login/index'
});
}
//跳转到实名认证页面
const handleTorealName = () => {
if (!uni.getStorageSync('token')) {
return uni.navigateTo({
url: '/pages/login/index'
});
}
if (isRealNameAuth.value) {
uni.navigateTo({
url: '/subPages/authentication-success/index?name=' + name.value + '&idCard=' + idCard.value
});
} else {
uni.navigateTo({
url: '/subPages/realName-authentication/index'
});
}
}
const getDateChange = (e) => {
updateUserInfo({
birthday: e.detail.value
}).then((res) => {
baseUserInfo()
}).catch((err) => {
uni.showToast({
title: '网络异常',
duration: 2000,
icon: 'none'
});
})
}
const changeSex = (e) => {
updateUserInfo({
sex: Number(e.detail.value)
}).then((res) => {
baseUserInfo()
}).catch((err) => {
uni.showToast({
title: '网络异常',
duration: 2000,
icon: 'none'
});
})
}
</script>
<style src="./index.scss" lang="scss" scoped></style>