cshenfu
2023-06-14 de93aa62c83d6afb9f70cd5a22838375db0a8cbc
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
<template>
    <view>
        <view class="padding-lr">
            <view class="text text-xl padding-top-sm text-bold">{{isMpBind?'绑定手机':'注册'}}</view>
            <view class="text-lg padding-tb-sm">您好,欢迎来到 {{config.site_title}} </view>
        </view>
        <view class="padding margin flex bg-gray round align-center">
            
            <view class="padding-lr-sm solid-right">
                <view>
                    +86<text class="icon-triangledownfill margin-left-xs"></text>
                </view>
            </view>
            <view class="padding-lr-sm"><input style="width: 100%;" v-model="mobile" type="number" placeholder="请输入手机号" class="text-df" /></view>
        </view>
        <view v-if="config.is_h5_sms == 1" class="padding margin flex bg-gray round align-center">
            <view style="flex-grow: 1;" class="padding-lr-sm"><input type="number" v-model="code" style="width: 100%;" placeholder="请输入验证码" class="text-df" /></view>
            <view @click="getValidate" class="padding-lr-sm solid-left text-orange">{{show?"获取验证码":`已发送${count}s`}}</view>
        </view>
        <view class="padding margin flex bg-gray round align-center">
            <view class="padding-lr-sm"><input v-model="password" type="password" style="width: 100%;" placeholder="请输入登录密码" class="text-df" /></view>
        </view>
        <view class="padding margin flex bg-gray round align-center">
            <view class="padding-lr-sm"><input v-model="passwordd" type="password" style="width: 100%;" placeholder="请确认登录密码" class="text-df" /></view>
        </view>
        <!-- <view class="padding margin flex bg-gray round align-center">
            <view class="padding-lr-sm"><input v-model="parent_id" type="number" style="width: 100%;" placeholder="邀请码(选填)" class="text-df" /></view>
        </view> -->
        <view class="cu-bar justify-center padding-lr" style="width: 100%;">
            <button @click="submit" class="cu-btn bg-gradual-orange lg round" style="width: 100%; padding-top: 45upx;padding-bottom: 45upx;">{{isMpBind?'绑定手机':'注册'}}</button>
        </view>
        <view class="text-center padding-lr-sm padding-tb">
            <text @click="click1" class="text-orange margin-lr-xs">用户服务协议</text><text @click="click2" class="text-orange">隐私协议</text>
        </view>
    </view>
</template>
 
<script>
    import mixin from "@/mixin/checkLoaded";
    export default {
        mixins: [mixin],
        data() {
            return {
                show:true,
                timer:null,
                count:'',
                mobile:'',
                code:'',
                password:'',
                passwordd:'',
                parent_id:'',
                key:'',
                config:{},
                isMpBind:false
            }
        },
        onLoad(op) {
            if(op.share_id){
                this.parent_id = op.share_id
            }
            // #ifdef MP
            if(op.bindMob){
                this.isMpBind = true
            }
            // #endif
            this.config = this.$store.state.config
        },
        methods: {
            getValidate(){
                if(!(/^1(3|4|5|7|8)\d{9}$/.test(this.mobile))){ 
                    uni.showToast({
                        title:"请输入正确的手机号码",
                        icon:"none"
                    })
                    return 
                }
                const TIME_COUNT = 60;
                if (!this.timer) {
                    this.count = TIME_COUNT;
                    this.show = false;
                    //此处写提交获取验证码的请求
                    this.$request("/api/Member/sendSms","POST",{mobile:this.mobile}).then(res=>{
                        if(res.status == 200){
                            uni.showToast({
                                title:res.msg,
                                icon:"none"
                            })
                            this.timer = setInterval(() => {
                                if (this.count > 0 && this.count <= TIME_COUNT) {
                                    this.count--;
                                } else {
                                    this.show = true;
                                    clearInterval(this.timer);
                                    this.timer = null;
                                }
                            }, 1000)
                            uni.setStorageSync('key',res.key)
                            uni.setStorageSync('keyTime',new Date().getTime())
                            this.key = res.key
                        }else{
                            uni.showToast({
                                title:res.msg,
                                icon:"none"
                            })
                            uni.removeStorageSync('key')
                            uni.removeStorageSync('keyTime')
                        }
                    }).catch(err=>{
                        this.$failToast()
                    })
                }
            },
            submit(){
                if(!(this.mobile && this.password)){
                    this.$failToast("请输入手机号和密码")
                    return
                }
                if(this.password != this.passwordd){
                    this.$failToast("密码不一致,请重新输入")
                    return
                }
                if (this.config.is_h5_sms == 1) {
                    if(!this.code){
                        this.$failToast("请输入验证码")
                        return
                    }
                    if(!this.key){
                        this.$failToast("请获取验证码")
                        return
                    }
                }
                
                let m_id = ''
                if(this.$store.state.userInfo.member_id){
                    m_id = this.$store.state.userInfo.member_id
                }
                
                this.$request("/api/Member/add","POST",{
                    key:this.key,
                    code:this.code,
                    mobile:this.mobile,
                    passwd:this.password,
                }).then(res=>{
                    uni.showModal({
                        title:'提示',
                        content:res.msg
                    })
                    if(res.status == 800){
                        setTimeout(function() {
                            uni.reLaunch({
                                url: "/pages/login/login"
                            })
                        }, 500);
                    }
                }).catch(err=>{
                    this.$failToast()
                })
            },
            click1(){
                uni.navigateTo({
                    url:"../content/content?content_id=1"
                })
            },
            click2(){
                uni.navigateTo({
                    url:"../content/content?content_id=2"
                })
            }
        }
    }
</script>
 
<style>
    /*每个页面公共css */
    @import url("@/static/style/color-ui.css");
    page{
        background-color: #fff;
    }
 
</style>