叶松
2023-11-21 6eaaba4f97028d581df3e019a7705d60b398c26e
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<template>
    <view class="register_index">
        <u-form
            ref="form"
            :model="formRegister"
            :rules="rulesRegister"
            labelWidth="auto"
            labelPosition="left">
            <u-form-item
                label="头像"
                prop="photoUrl"
                borderBottom>
            <u-upload
                :fileList="fileList"
                @afterRead="afterRead"
                @delete="deleteImage"
                name="6"
                :maxCount="1"
                width="60"
                height="60">
                <u-avatar src="" shape="square"></u-avatar>
            </u-upload>
                <u-icon
                    slot="right"
                    name="arrow-right">
                </u-icon>
            </u-form-item>
            <u-form-item
                    label="姓名"
                    prop="realName"
                    borderBottom>
                <u-input
                    v-model="formRegister.realName"
                    placeholder="请输入姓名"
                    border="none">
                </u-input>
            </u-form-item>
            <u-form-item
                    label="性别"
                    prop="sexValue"
                    borderBottom
                    @click="changeSex()">
                <u-input
                    v-model="formRegister.sexValue"
                    placeholder="请选择性别"
                    disabled
                    disabledColor="#FFFFFF"
                    border="none">
                </u-input>
                <u-icon
                    slot="right"
                    name="arrow-right">
                </u-icon>
            </u-form-item>
            <u-form-item
                    label="手机号"
                    prop="phone"
                    borderBottom>
                <u-input
                    v-model="formRegister.phone"
                    placeholder="请输入手机号"
                    border="none">
                </u-input>
            </u-form-item>
            <u-form-item
                    label="身份证号"
                    prop="idNo"
                    borderBottom>
                <u-input
                    v-model="formRegister.idNo"
                    placeholder="请输入身份证号"
                    border="none">
                </u-input>
            </u-form-item>
            <u-form-item
                    label="分公司"
                    prop="companyIdValue"
                    borderBottom
                    @click="changeCompany()">
                <u-input
                    v-model="formRegister.companyIdValue"
                    placeholder="请选择分公司"
                    disabled
                    disabledColor="#FFFFFF"
                    border="none">
                </u-input>
                <u-icon
                    slot="right"
                    name="arrow-right">
                </u-icon>
            </u-form-item>
            <u-form-item
                    label="岗位"
                    prop="posIdValue"
                    borderBottom
                    @click="changePosition()">
                <u-input
                    v-model="formRegister.posIdValue"
                    placeholder="请选择岗位"
                    disabled
                    disabledColor="#FFFFFF"
                    border="none">
                </u-input>
                <u-icon
                    slot="right"
                    name="arrow-right">
                </u-icon>
            </u-form-item>
            <u-form-item
                    label="备注"
                    borderBottom>
                <u-input
                    v-model="formRegister.remark"
                    placeholder="请输入备注"
                    border="none">
                </u-input>
            </u-form-item>
        </u-form>
        <view class="submit_bnt">
            <u-button type="primary" color="#1976FF" text="确认" @click="submitInsertForm()"></u-button>
        </view>
        <u-picker 
            :show="showSex" 
            :columns="sexColumns" 
            keyName="label"
            @cancel="showSex = false"
            @confirm="selectSex">
        </u-picker>
        <u-picker 
            :show="showCompany" 
            :columns="companyColumns" 
            keyName="companyName"
            @cancel="showCompany = false"
            @confirm="selectCompany">
        </u-picker>
        <u-picker 
            :show="showPosition" 
            :columns="positionColumns" 
            keyName="posName"
            @cancel="showPosition = false"
            @confirm="selectPosition">
        </u-picker>
    </view>
</template>
 
<script>
import { basrUrl } from '../../api/http';
import { throttle } from '../../plugins/public';
    export default {
        data() {
            return {
                fileList: [],
                formRegister: {
                    realName: '',
                    sex: '',
                    sexValue: '',
                    phone: '',
                    idNo: '',
                    companyId: '',
                    posId: '',
                    posIdValue: '',
                    remark: ''
                },
                showSex: false, // 性别选择
                sexColumns: [[{
                    value: 0,
                    label: '男'
                }, {
                    value: 1,
                    label: '女'
                }]],
                showCompany: false,
                companyColumns: [],
                showPosition: false,
                positionColumns: [],
                rulesRegister: {
                    realName: [{
                        required: true,
                        message: '请输入姓名',
                        trigger: 'blur'
                    }],
                    sexValue: [{
                        required: true,
                        message: '请选择性别',
                        trigger: ['blur', 'change']
                    }],
                    phone: [{
                        required: true,
                        message: '请输入手机号',
                        trigger: 'blur'
                    },{
                        // 自定义验证函数,见上说明
                        validator: (rule, value, callback) => {
                            return uni.$u.test.mobile(value);
                        },
                        message: '请输入正确的手机号码',
                        trigger: 'blur',
                    }],
                    idNo: [{
                        required: true,
                        message: '请输入身份证号',
                        trigger: 'blur'
                    },{
                        // 自定义验证函数,见上说明
                        validator: (rule, value, callback) => {
                            return uni.$u.test.idCard(value);
                        },
                        message: '请输入正确的身份证号码',
                        trigger: 'blur',
                    }],
                    companyIdValue: [{
                        required: true,
                        message: '请选择分公司',
                        trigger: ['blur', 'change']
                    }],
                    posIdValue: [{
                        required: true,
                        message: '请选择岗位',
                        trigger: ['blur', 'change']
                    }]
                }
            }
        },
        onLoad(option) {
            if(option.data) {
                const data = JSON.parse(option.data);
                this.fileList = [{
                    id: this.fileList.length + 1,
                    data: data.photoUrl,
                    url: `https://szpipe.thhy-tj.com/${data.photoUrl}`
                }]
                this.$set(this.formRegister, 'realName', data.realName);
                this.$set(this.formRegister, 'sex', data.sex);
                this.$set(this.formRegister, 'sexValue', data.sex == 0 ? '男' : data.sex == 1 ? '女' : '');
                this.$set(this.formRegister, 'phone', data.phone);
                this.$set(this.formRegister, 'idNo', data.idNo);
                this.$set(this.formRegister, 'companyIdValue', data.companyName);
                this.$set(this.formRegister, 'companyId', data.companyId);
                this.$set(this.formRegister, 'posIdValue', data.posName);
                this.$set(this.formRegister, 'posId', data.posId);
                this.$set(this.formRegister, 'remark', data.remark);
                this.getPositionData(data.companyId);
            }
        },
        onReady() {
            //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
            this.getCompanyData();
        this.$refs.form.setRules(this.rulesRegister);
    },
        methods: {
            // 获取分公司信息
            async getCompanyData() {
                const { data } = await this.$api.system.getCompanyData();
                this.companyColumns = [data];
            },
            // 获取岗位信息
            async getPositionData(companyId) {
                this.positionColumns = [];
                const { data } = await this.$api.system.getPositionData({
                    companyId: companyId
                });
                this.positionColumns = [data];
            },
            // 读取图片后
            afterRead(event) {
                console.log(event);
                this.fileList.push({
                    status: 'loading',
                    message: '上传中',
                })
                uni.uploadFile({
                    url: `${basrUrl}/file/file/upload`,
                    fileType: 'image',
                    filePath: event.file.url,
                    name: 'file',
                    success: (res) => {
                        const data = JSON.parse(res.data);
                        this.$set(this.fileList, this.fileList.length - 1, {
                            id: this.fileList.length + 1,
                            status: 'success',
                            message: '',
                            data: data.data,
                            url: `https://szpipe.thhy-tj.com/${data.data}`
                        })
                    },
                    fail: (error) => {
                        uni.$u.toast('上传失败!');
                    }
                })
            },
            // 删除图片
            deleteImage(event) {
                console.log(event,'????');
                this.$nextTick(() => {
                    this.fileList.splice(event.index, 1);
                })
            },
            // 打开性别选择
             changeSex() {
                 this.showSex = true;
                 this.$set(this.formRegister, 'sex', '');
                 this.$set(this.formRegister, 'sexValue', '');
             },
             // 确认选择性别
             selectSex({ value }) {
                this.$nextTick(() => {
                    console.log(value,'??????');
                    this.$set(this.formRegister, 'sex', value[0].value);
                    this.$set(this.formRegister, 'sexValue', value[0].label);
                    this.showSex = false;
                 })
             },
             // 打开分公司选择
              changeCompany() {
                  this.showCompany = true;
                  this.$set(this.formRegister, 'companyId', '');
                  this.$set(this.formRegister, 'companyIdValue', '');
              },
             // 确认选择分公司
             selectCompany({ value }) {
                 this.$set(this.formRegister, 'companyId', value[0].companyId);
                 this.$set(this.formRegister, 'companyIdValue', value[0].companyName);
                 this.getPositionData(value[0].companyId);
                 this.showCompany = false;
             },
             // 打开岗位选择
              changePosition() {
                  this.showPosition = true;
                  this.$set(this.formRegister, 'posId', '');
                  this.$set(this.formRegister, 'posIdValue', '');
              },
             // 确认选择岗位
             selectPosition({ value }) {
                 this.$set(this.formRegister, 'posId', value[0].posId);
                 this.$set(this.formRegister, 'posIdValue', value[0].posName);
                 this.showPosition = false;
             },
            // 
            submitInsertForm: throttle(function() {
                this.$refs.form.validate().then((valid) => {
                    if(valid) {
                        const params = Object.assign({}, this.formRegister);
                        params.photoUrl = this.fileList.length > 0 ? this.fileList[0].data : '';
                        params.openId = uni.getStorageSync('openId') || "";
                        delete params.sexValue;
                        delete params.companyIdValue;
                        delete params.posIdValue;
                        this.$api.system.useRegister(params).then((res) => {
                            if(res.success) {
                                uni.$u.toast("注册信息已提交,请等待审核");
                                setTimeout(() => {
                                    uni.navigateBack();
                                }, 1500)
                            } else {
                                uni.$u.toast(res.statusMsg);
                            }
                        })
                    }
                })
            }, 3000)
        }
    }
</script>
 
<style scoped lang="scss">
.register_index {
    position: relative;
    padding: 10px;
    height: calc(100vh - 20px);
}
 
.submit_bnt {
    position: absolute;
    bottom: 5%;
    width: calc(100% - 20px);
}
 
::v-deep .u-input__content__field-wrapper__field {
    text-align: right !important;
}
 
::v-deep .u-upload__wrap {
    justify-content: flex-end;
}
 
::v-deep .u-upload__wrap__preview {
    margin: 0 !important;
}
</style>