Houjie
2025-04-25 1d18ff904468e4a864312bdcf6d7c6a7c0477721
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
<template>
    <view>
        <cu-custom bgColor="bg-gradual-pink" :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">编辑资料</block>
        </cu-custom>
        <form>
            <view class="cu-form-group">
                <view class="title">姓名</view>
                <input placeholder="请输入姓名" name="input" v-model="myFormData.realname"></input>
            </view>
            <view class="cu-form-group">
                <view class="title">用户名</view>
                <input placeholder="用户名" name="input" v-model="myFormData.username" disabled></input>
            </view>
            <view class="cu-form-group">
                <view class="title">头像</view>
                <view class="grid col-4 grid-square flex-sub">
                    <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
                     <image :src="imgList[index]" mode="aspectFill"></image>
                        <view class="cu-tag bg-red radius" @tap.stop="DelImg" :data-index="index">
                            <text class='cuIcon-close'></text>
                        </view>
                    </view>
                    <view class="solids" @tap="ChooseImage" v-if="imgList.length<1">
                        <text class='cuIcon-cameraadd'></text>
                    </view>
                </view>
            </view>
            
            <view class="cu-form-group margin-top">
                <view class="title">性别</view>
                <switch class='switch-sex' @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch>
            </view>
            
            
            
            <view class="cu-form-group margin-top">
                <view class="title">手机号码</view>
                <input placeholder="输入手机号码" name="input" v-model="myFormData.phone"></input>
                <view class="cu-capsule radius">
                    <view class='cu-tag bg-blue '>
                        +86
                    </view>
                    <view class="cu-tag line-blue">
                        中国大陆
                    </view>
                </view>
            </view>
            <view class="cu-form-group">
                <view class="title">邮箱</view>
                <input placeholder="输入邮箱" name="input"  v-model="myFormData.email"></input>
            </view>
            <view class="padding flex flex-direction">
                <button class="cu-btn bg-blue lg"  @click="onSubmit">提交</button>
            </view>
        </form>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                index: -1,
                switchC: true,
                imgList: [],
                uploadUrl:"/sys/common/upload",
                myFormData:{
                    avatar:'',
                    realname:'',
                    username:'',
                    sex:1,
                    birthday:'',
                    orgCode:'',
                    workNo:'',
                    phone:'',
                    email:'',
                    id:'',
                },
            };
        },
        onLoad: function (option) {
            console.log("this.$Route.query",this.$Route.query);
            let query=this.$Route.query
            if(query){
                this.myFormData=query;
                if(this.myFormData.sex=='女'){
                  this.switchC = false
                }else if(this.myFormData.sex=='男'){
                  this.switchC = true
                }
                if(this.myFormData.avatar){
                  this.imgList=[this.myFormData.avatar]
                }
                if(!this.myFormData.birthday){
                  this.myFormData.birthday= '无'
                }
                if(this.myFormData.identity=='普通成员'){
                  this.myFormData.identity = 1
                }else if(this.myFormData.identity=='上级'){
                  this.myFormData.identity = 2
                }
                if(this.myFormData.status=='正常'){
                  this.myFormData.status = 1
                }else if(this.myFormData.status=='冻结'){
                  this.myFormData.status = 2
                }
                 this.Avatar=this.myFormData.avatar
    
                Object.keys(this.myFormData).map(key=>{
                  if(this.myFormData[key]=='无'){
                    this.myFormData[key] = ''
                  }
                })
                console.log("this.myFormData",this.myFormData)
            }
        },
        methods: {
            onSubmit() {
              let myForm = this.myFormData
              let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
              let checkEmail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
              console.log("myForm",myForm)
              if(!myForm.phone || myForm.phone.length==0){
                this.$tip.alert('请输入手机号');
                return false
              }
              if(!checkPhone.test(myForm.phone)){
                this.$tip.alert('请输入正确的手机号');
                return false
              }
              if(!checkEmail.test(myForm.email)){
                this.$tip.alert('请输入正确的邮箱地址');
                return false
              }
                this.myFormData.id = this.$store.getters.userid
                if(this.switchC){
                    this.myFormData.sex=1
                }else{
                    this.myFormData.sex=2
                }
                console.log('myform',this.myFormData)
                this.$tip.loading();
                this.$http.put('/sys/user/appEdit',this.myFormData).then(res=>{
                    console.log(res)
                    this.$tip.loaded();
                    if (res.data.success){
                        this.$tip.toast('提交成功')
                        this.$Router.replace({name:'userdetail'})
                        /* uni.navigateTo({
                            url: '/pages/user/userdetail'
                        }) */
                    }
                }).catch(()=>{
                    this.$tip.loaded();
                    this.$tip.error('提交失败')
                });
            },
            DateChange(e) {
                this.myFormData.birthday = e.detail.value
            },
            SwitchC(e) {
                this.switchC = e.detail.value
            },
            ChooseImage() {
                var that=this;
                uni.chooseImage({
                    count: 4, //默认9
                    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
                    sourceType: ['album'], //从相册选择
                    success: (res) => {
                        that.$http.upload(that.uploadUrl, {
                                filePath: res.tempFilePaths[0],
                                name: 'file'
                            })
                            .then(res => {
                                that.myFormData.avatar=res.data.message;
                            })
                            .catch(err => {
                                that.$tip.error(err.data.message)
                            });
                            console.log(res.tempFilePaths)
                        this.imgList = res.tempFilePaths
                    }
                });
            },
            ViewImage(e) {
                uni.previewImage({
                    urls: this.imgList,
                    current: e.currentTarget.dataset.url
                });
            },
            DelImg(e) {
                uni.showModal({
                    title: '召唤师',
                    content: '确定要删除这段回忆吗?',
                    cancelText: '再看看',
                    confirmText: '再见',
                    success: res => {
                        if (res.confirm) {
                            this.imgList.splice(e.currentTarget.dataset.index, 1)
                        }
                    }
                })
            }
        }
    }
</script>
 
<style>
    .cu-form-group .title {
        min-width: calc(4em + 15px);
    }
</style>