jiangping
2024-01-29 3dd3abbc68a1dd587021e205d3bebf4bff3eab46
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
<template>
    <GlobalWindow
        :title="title"
        width="100%"
        :visible.sync="visible"
        :confirm-working="isWorking"
        @confirm="confirm"
    >
        <el-form :inline="true" class="demo-form-inline">
            <div v-for="(item, index) in list" :key="index">
                <el-form-item label="姓名" required>
                    <el-input v-model="item.name" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="身份证号" required>
                    <el-input v-model="item.idcardNo" maxlength="18" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-if="index === 0" @click="add">添加</el-button>
                    <el-button type="danger" v-else @click="dele(index)">删除</el-button>
                </el-form-item>
            </div>
        </el-form>
    </GlobalWindow>
</template>
 
<script>
    import BaseOpera from '@/components/base/BaseOpera'
    import GlobalWindow from '@/components/common/GlobalWindow'
    export default {
        name: 'addEmployee',
        extends: BaseOpera,
        components: { GlobalWindow },
        data () {
            return {
                list: [
                    {
                        name: '',
                        idcardNo: ''
                    }
                ],
                arr: []
            }
        },
        methods: {
            open (title, arr) {
                this.title = title
                this.visible = true
                this.list = [
                    {
                        name: '',
                        idcardNo: ''
                    }
                ]
                this.arr = arr
            },
            add() {
                this.list.push({
                    name: '',
                    idCard: ''
                })
            },
            dele(index) {
                this.form.list.splice(index, 1)
            },
            hasDuplicates(arr) {
                return arr.some((value, index) => arr.indexOf(value) !== index);
            },
            confirm() {
                // 判断列表否是有空值
                for (let i = 0; this.list.length; i++) {
                    if (!this.list[i].name || !this.list[i].idcardNo) {
                        this.$message.warning('请先完善信息后再提交')
                        return
                    }
                }
                // 判断新录入数据身份证是否有重复
                let idcardList = this.list.map(item => item.idcardNo)
                if (this.hasDuplicates(idcardList)) {
                    this.$message.warning('身份证有重复')
                    return
                }
                // 判断详情列表数据身份证是否有重复
                let next = true
                this.list.forEach(item => {
                    this.arr.forEach(child => {
                        if (item.idcardNo === child.idcardNo) {
                            next = false
                        }
                    })
                })
                if (next) {
                    this.$emit('result', this.list)
                    this.visible = false
                } else {
                    this.$message.warning('身份证号不能重复!')
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
 
</style>