Liuyi
2024-10-19 42e5ea86f7edc9361227edd979a8ae1952713161
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
<script setup>
    import { onMounted, ref } from 'vue'
    import { editUserInfoApi,getUserInfo } from '../../api/index.js'
    const isEdit = ref(false)
    const editForm = ref({id:'',userName:'',userPhone:''})
    const userInfo = ref(JSON.parse(uni.getStorageSync('userInfo')))
    function edit(){
        editForm.value.id = userInfo.value.id
        editForm.value.userName = userInfo.value.userName
        editForm.value.userPhone = userInfo.value.userPhone
        isEdit.value = true
        console.log('userInfo',userInfo.value)
    }
    function cancel(){
        isEdit.value = false
        editForm.vlaue = {id:'',userName:'',userPhone:''}
    }
    async function submitEdit(){
        await editUserInfoApi(editForm.value).then(async(res) =>{
            
            if(res.code == 200){
                uni.showToast({
                    title: '修改成功!',
                    duration: 2000,
                });
                await getUserInfo().then((res) =>{
                    userInfo.value.userName = res.data.userInfo.userName
                    userInfo.value.userPhone = res.data.userInfo.userPhone
                    uni.setStorageSync('userInfo',JSON.stringify(userInfo.value))
                })
            }else{
                uni.showToast({
                    title: '网络错误!请重试',
                    duration: 2000,
                    icon:'none'
                });
            }
            isEdit.value = false
            editForm.vlaue = {id:'',userName:'',userPhone:''}
        })
    }
</script>
<template>
    <view class="container">
        <navbar title = '用户资料'></navbar>
        <view class="content">
            <view class="info-box">
                <view class="info-up">
                    <view class="info-img">
                        <text>头像</text>
                        <image src='../../static/images/index/head.png' alt=''></image>
                    </view>
                    <view class="info-name">
                        <text>用户名称</text>
                        <view>
                            <input v-if="isEdit" v-model="editForm.userName" placeholder="请输入新用户名"/>
                            <text v-else class="info-value">{{userInfo.userName}}</text>
                        </view>
                    </view>
                </view>
                <view class="info-list">
                    <view class="item">
                        <text>会员卡号</text>
                        <text v-if="userInfo.waterCardNumber">{{userInfo.waterCardNumber}}</text>
                        <text v-else>未绑定会员卡</text>
                    </view>
                    <view class="item">
                        <text>联系方式</text>
                        <view>
                            <input v-if="isEdit" v-model="editForm.userPhone" placeholder="请输入新联系方式"/>
                            <text v-if="userInfo.userPhone && !isEdit">{{userInfo.userPhone}}</text>
                            <text v-if="!userInfo.userPhone && !isEdit">未添加联系方式</text>
                            <!-- <image class="edit"src="../../static/images//other/more.png" alt=''></image> -->
                        </view>
                    </view>
                </view>
            </view>
            <view v-if="!isEdit" @click="edit()" class="subBtn">修改</view>
            <view v-if="isEdit" @click="cancel()" class="btn btn1">取消</view>
            <view v-if="isEdit" @click="submitEdit()" class="btn btn2">确认修改</view>
        </view>
    </view>
</template>
 
<style lang="scss">
    .container{
        width: 100%;
        height: 100vh;
        .content{
            width: 100%;
            height:calc(100vh - 176rpx);
            background:linear-gradient(to top,#FFFFFF,#E8EFFF);  
            padding-top:36rpx;
            position: relative;
            box-sizing: border-box;
            .info-value{
                font-size:32rpx;
                color: #777777;
            }
            // .edit{
            //     margin-left:15rpx;
            //     width: 20rpx;
            //     height:28rpx;
            // }
            .info-box{
                width: 100%;
                //该页面公用input样式
                input{
                    border-radius: 10rpx;
                    border:1px solid rgba(101, 156, 244, 0.2);
                    padding:5rpx 10rpx;
                    box-shadow: 0 0 12rpx 1rpx rgba(101, 156, 244, 0.2);
                    color: #777777;
                    height:50rpx;
                    line-height:50rpx;
                    width:300rpx;
                }
                .info-up{
                    height:308rpx;
                    width:100%;
                    background: #FFFFFF;
                    padding:32rpx;
                    display: flex;
                    justify-content:space-between;
                    align-items:center;
                    flex-direction: column;
                    box-sizing: border-box;
                    font-size: 32rpx;
                    color: #343434;
                    .info-img{
                        width:100%;
                        display: flex;
                        justify-content:space-between;
                        align-items:center;
                        image{
                            width:100rpx;
                            height:100rpx;
                            border-radius: 50rpx;
                        }
                    }
                    .info-name{
                        width:100%;
                        display: flex;
                        justify-content:space-between;
                        align-items:center;
                    }
                }
                .info-list{
                    width:100%;
                    height:252rpx;
                    display: flex;
                    flex-direction:column;
                    justify-content:space-between;
                    align-items: center;
                    margin-top:20rpx;
                    .item{
                        width:100%;
                        height: 116rpx;
                        background-color: #FFFFFF;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        padding:0 32rpx;
                        box-sizing: border-box;
                        text:last-child{
                            color: #777777;
                        }
                        view{
                            height: 116rpx;
                            display: flex;
                            justify-content:flex-end;
                            align-items: center;
                            text{
                                color: #777777;
                            }
                        }
                    }
                }
            }
            .subBtn{
                width: 686rpx;
                height: 98rpx;
                background:#5EA1FA;
                border-radius:50rpx;
                text-align: center;
                line-height: 98rpx;
                letter-spacing:3rpx;
                font-weight: 300;
                font-size: 36rpx;
                color: #FFFFFF;
                position: absolute;
                bottom:100rpx;
                left:32rpx;
            }
            .btn{
                    width: 200rpx;
                    height: 70rpx;
                    border-radius: 32rpx;
                    text-align: center;
                    line-height: 70rpx;
                    letter-spacing:3rpx;
                    font-weight: 300;
                    font-size: 36rpx;
                    position: absolute;
                    bottom:100rpx;
            }
            .btn1{
                color:#5EA1FA;
                background:#FFFFFF;
                position: absolute;
                left:130rpx;
                border:2rpx solid #5EA1FA;
            }
            .btn2{
                color: #FFFFFF;
                background:#5EA1FA;
                position: absolute;
                right:130rpx;
            }
        }
    }
</style>