MrShi
2024-11-13 b496da6315314d9bd048ac2214d8bc95d2f1df02
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
<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.memberName" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="身份证号" required>
                    <el-input v-model="item.idCard" maxlength="18" placeholder="请输入"></el-input>
                </el-form-item>
              <el-form-item label="派遣单位" v-if="!companyId">
                <el-select v-model="item.duId" @change="selectChange(index)" placeholder="请选择" clearable>
                  <el-option
                      v-for="item in dispatching"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="所属工种" >
                <el-select v-model="item.worktypeId" @change="selectChangeWT(index)"  placeholder="请选择" clearable>
                  <el-option
                      v-for="item1 in item.options"
                      :key="item1.id"
                      :label="item1.name"
                      :value="item1.id">
                  </el-option>
                </el-select>
              </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'
import { findListByDTO } from '@/api/business/dispatchUnit'
import { findListByDTO as worktype } from '@/api/business/worktype'
export default {
  name: 'addEmployee',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      tempIndex: -1,
      dispatching: [],
      solutionId: null,
      companyId: null,
      list: [
        {
          memberName: '',
          idCard: '',
          workTypeName: '',
          worktypeId: '',
          duName: '',
          options: [],
          duId: '',
          fee: ''
        }
      ],
      price: 0,
      arr: []
    }
  },
  methods: {
    open (title, obj, tempIndex) {
      this.title = title
      this.visible = true
      this.tempIndex = tempIndex
      this.solutionId = obj.solutionId
      this.companyId = obj.companyId
      this.dispatching = []
      this.list = [
        {
          memberName: '',
          idCard: '',
          workTypeName: '',
          worktypeId: '',
          duName: '',
          options: [],
          duId: '',
          fee: ''
        }
      ]
      this.arr = obj.arr
      this.price = obj.price
      if (!obj.companyId) {
        this.getFindListByDTO()
      } else {
        worktype({ id: obj.solutionId, queryType: 0 })
          .then(res => {
            this.list[0].options = res
          })
      }
    },
    getFindListByDTO () {
      findListByDTO({
        solutionId: this.solutionId
        // dataType: 0
      }).then(res => {
        this.dispatching = res
      })
    },
    selectChange (index) {
      this.list[index].options = []
      let duSolutionId = ''
      this.list[index].duName = null
      this.dispatching.forEach(item => {
        if (item.id === this.list[index].duId) {
          duSolutionId = item.duSolutionId
          this.list[index].duName = item.name
        }
      })
      worktype({ id: duSolutionId, queryType: 1 })
        .then(res => {
          this.list[index].options = res
        })
    },
    selectChangeWT (index) {
      this.list[index].workTypeName = null
      this.list[index].options.forEach(item => {
        if (item.id === this.list[index].worktypeId) {
          this.list[index].workTypeName = item.name
        }
      })
    },
    add () {
      if (!this.companyId) {
        this.list.push({
          memberName: '',
          idCard: '',
          workTypeName: '',
          worktypeId: '',
          duName: '',
          duId: '',
          options: [],
          fee: '',
          id: this.tempIndex - 1
        })
      } else {
        this.list.push({
          memberName: '',
          idCard: '',
          workTypeName: '',
          worktypeId: '',
          duName: '',
          duId: '',
          options: JSON.parse(JSON.stringify(this.list[0].options)),
          fee: '',
          id: this.tempIndex - 1
        })
      }
    },
    dele (index) {
      this.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].memberName || !this.list[i].idCard) {
      //         this.$message.warning('请先完善信息后再提交')
      //         return
      //     }
      // }
      // 判断新录入数据身份证是否有重复
      const idcardList = this.list.map(item => item.idCard)
      if (this.hasDuplicates(idcardList)) {
        this.$message.warning('身份证有重复')
        return
      }
      // 判断身份证是否有效
      for (let i = 0; i < this.list.length; i++) {
        const regExp = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
        if (!regExp.test(this.list[i].idCard)) {
          this.$message.warning(`第${i + 1}项员工身份证不合法`)
          return
        }
        const s=parseInt(this.list[i].idCard.substring(16,17))
        // const s = parseInt(this.list[i].idCard.slice(16, 1))
        if (s % 2 === 0) {
          this.list[i].sex = 1
        } else {
          this.list[i].sex = 0
        }
      }
      // 判断详情列表数据身份证是否有重复
      let next = true
      this.list.forEach(item => {
        this.arr.forEach(child => {
          if (item.idCard === child.idCard) {
            next = false
          }
        })
      })
      if (next) {
        this.list.forEach(item => {
          item.fee = this.price
        })
        console.log(this.list)
        this.$emit('result', this.list)
        this.visible = false
      } else {
        this.$message.warning('身份证号不能重复!')
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
 
</style>