remove.vue
3.59 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
<template>
<view>
<view class="user-wrap">
<view class="user-group">
<text class="nick-name">头像</text>
<button class="choose-avatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" style="width: 80rpx;padding: 0;margin: 0;">
<image class="user-avatar" :src="arr1.avatar?arr1.avatar:$imgUrl('/img/head.jpg')" mode="aspectFill"></image>
</button>
</view>
<view class="user-group">
<text class="nick-name">昵称</text>
<input class="choose-nickname" type="nickname" v-model="arr1.name" @change="nickNameChange"/>
</view>
<view class="user-group">
<text class="nick-name">性别</text>
<picker mode="selector" @change="bindPickerChange1" :value="arr1.sex" :range="range" :range-key="'text'">
<text>{{arr1.sex}}</text>
<uni-icons type="right" size="15"></uni-icons>
</picker>
</view>
<view class="confirm-user" @tap="backToCenter" >
确认
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
arr1:{
name:'',
avatar:'',
mobilePhone:'',
sex:'',
birthday:'',
occupation:'',
hobby:'',
workAddress:''
},
range: [
{
value: '男',
text: "男"
},
{
value: '女',
text: "女"
},
],
}
},
onShow() {
this.gain()
},
methods: {
gain() {
let that =this
that.$http.sendRequest('/business/getUserDetails', 'GET', {}).then(res => {
that.arr1 = res.data.data
console.log({...that.arr1})
})
},
open() {
this.$refs.calendar.open();
},
confirm(e) {
console.log(e);
this.arr1.birthday = e.fulldate
},
bindPickerChange1(e) {
this.arr1.sex =this.range[Number(e.detail.value)].value
console.log(this.arr1.sex)
},
uploadFilePromise(url) {
console.log(url)
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: this.$upload, // 仅为示例,非真实的接口地址
filePath: url,
name: 'file', // 后端接收的文件参数名
formData: {
filePath: 'user', // 其他表单数据
},
success: (res) => {
this.arr1.avatar = this.$img+ JSON.parse(res.data).data
resolve(JSON.parse(res.data).data)
}
});
})
},
async onChooseAvatar(e) {
console.log(e.detail)
this.arr1.avatar = e.detail.avatarUrl;
await this.uploadFilePromise(this.arr1.avatar)
},
nickNameChange(e) {
this.arr1.name = e.detail.value
},
async backToCenter() {
console.log({...this.arr1})
this.$http.sendRequest('/business/updateAvatar', 'POST', this.arr1).then(res => {
if(res.data.code == 200) {
uni.showToast({
icon: 'none',
title: "修改成功",
})
setTimeout(() => {
uni.reLaunch({
url:'/pages/my/my'
})
}, 500)
}
console.log(res)
})
}
},
}
</script>
<style>
.user-wrap {
padding: 0 30rpx;
background: #fff;
font-size: 26rpx;
/* margin-top: 50rpx; */
}
.user-group {
display: flex;
justify-content: space-between;
align-items: center;
height: 100rpx;
border-bottom: 2rpx solid #ccc;
}
.nick-name {
font-weight: 700;
}
.choose-avatar {
height: 80rpx;
border-radius: 80rpx;
}
.user-avatar {
width: 100%;
height: 100%;
}
.choose-nickname {
text-align: right;
}
.confirm-user {
background-color: #19be6b;
color: #fff;
text-align: center;
width: 90%;
margin: 0 auto;
height: 80rpx;
border-radius: 30rpx;
line-height: 80rpx;
font-size: 32rpx;
position: fixed;
bottom: 30rpx;
left: 5%;
}
</style>