jialh
2025-08-20 2d2756dc0e61ed8cd38c2796daf5cacdfdd49bf2
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
<template>
    <view>
        <view class="block__title">房屋信息</view>
        <view class="cu-form-group">
            <view class="title">小区</view>
            <picker bindchange="PickerChange" :value="communityIndex" :range="communitys" :range-key="'name'"
                @change="communityChange">
                <view class="picker">
                    {{communitys[communityIndex].name}}
                </view>
            </picker>
        </view>
        <view class="cu-form-group arrow" v-if="communityId" @tap="chooseRoom">
            <view class="title">房屋</view>
            <input readonly v-model="roomName" class="text-right" placeholder="请选择房屋" icon="arrow"></input>
            <text class='cuIcon-right'></text>
        </view>
        <view class="block__title">人员信息</view>
        <!-- <view class="cu-form-group">
            <view class="title">人员名称</view>
            <input v-model="ownerName" placeholder="请输入名称" class="text-right"></input>
        </view> -->
        <view class="cu-form-group">
            <view class="title">手机号</view>
            <input v-model="link" placeholder="请输入手机号" class="text-right"></input>
            <text v-if="errorMessage" class="error-message">{{ errorMessage }}</text>
        </view>
        <view class="cu-form-group">
            <view class="title">人员类型</view>
            <picker :value="typeCdIndex" :range="typeCds" range-key="name" @change="_changeTypeCd">
                <view class="picker">
                    {{typeCds[typeCdIndex].name}}
                </view>
            </picker>
        </view>
 
        <view class="flex flex-direction margin-top margin-bottom">
            <button class="cu-btn bg-blue margin-tb-sm lg" @click="_doAuthOwner()">提交</button>
        </view>
    </view>
</template>
 
<script>
    import {
        getCommunitys
    } from '../../api/community/communityApi.js';
    import {
        getUserTel
    } from '../../api/user/userApi.js';
    import {
        authOwner
    } from '../../api/owner/ownerApi.js';
 
    export default {
        data() {
            return {
                communityIndex: 0,
                communityId: '',
                roomId: '',
                roomName: '',
                link: '',
                ownerName: '',
                communitys: [{
                    communityId: '',
                    name: '请选择小区'
                }],
                typeCds: [{
                        value: '1001',
                        name: '业主'
                    },
                    {
                        value: '1002',
                        name: '成员'
                    }
                ],
                typeCdIndex: 0,
                ownerTypeCd: "1001",
                errorMessage: '' // 新增一个用于存放错误信息的字段
            }
        },
        onLoad(options) {
            this._loadCommunitys();
            this.link = getUserTel();
        },
        onShow() {
            let _selectRoom = uni.getStorageSync('selectRoom');
            if (_selectRoom) {
                this.roomName = _selectRoom.roomName;
                this.roomId = _selectRoom.roomId;
                uni.removeStorageSync('selectRoom');
            }
        },
        methods: {
            communityChange: function(e) {
                this.communityIndex = e.target.value //取其下标
                let selected = this.communitys[this.communityIndex] //获取选中的数组
                this.communityId = selected.communityId; //选中的id
            },
            _loadCommunitys: function() {
                let _that = this;
                getCommunitys({
                    page: 1,
                    row: 500
                }).then(_communitys => {
                    _communitys.forEach(_c => {
                        _that.communitys.push(_c);
                    })
                })
            },
            chooseRoom: function() {
                uni.navigateTo({
                    url: '/pages/family/selectRoom?communityId=' + this.communityId
                })
            },
            _changeTypeCd: function(e) {
                this.typeCdIndex = e.detail.value;
                this.ownerTypeCd = this.typeCds[this.typeCdIndex].value;
            },
            _doAuthOwner: function() {
                正则验证手机号格式
                const phoneRegex = /^1[3-9]\d{9}$/; // 正确的手机号格式
                if (!phoneRegex.test(this.link)) {
                    this.errorMessage = '请输入有效的手机号'; // 设置错误信息
                    return; // 如果手机号格式不对,停止执行
                } else {
                    this.errorMessage = ''; // 清除错误信息
                }
 
                authOwner({
                    communityId: this.communityId,
                    roomName: this.roomName,
                    roomId: this.roomId,
                    link: this.link,
                    ownerName: this.ownerName,
                    ownerTypeCd: this.ownerTypeCd,
                }).then(_data => {
                    // todo 跳转到认证历史页面
                    uni.navigateTo({
                        url: '/pages/index/authOwnerLog'
                    })
                }).catch(err => {
                    // 处理错误情况
                    wx.showToast({
                        icon: 'none',
                        title: err || '认证失败,请重试' // 提供一个默认的错误提示
                    });
                });
 
            }
        }
    }
</script>
 
<style>
    .block__title {
        margin: 0;
        font-weight: 400;
        font-size: 14px;
        color: rgba(69, 90, 100, .6);
        padding: 40rpx 30rpx 20rpx;
    }
 
    .error-message {
        color: red;
        /* 错误信息的红色字体 */
    }
</style>