jiangping
2024-06-19 bf15135228cbb9ac186cc8cc39e9da32d3f1d90f
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
<template>
    <GlobalWindow
        :title="title"
        width="30%"
        :visible.sync="visible"
        :confirm-working="isWorking"
        @confirm="confirm"
    >
      <p class="tip-warn" v-if="type ==1"><i class="el-icon-warning"></i>提醒:<br>
         <span style="">加保人员名单中,人员姓名、身份证号、派遣单位和工种信息均为必填项,备注信息可为空,请录入合法数据。</span>
      </p>
      <p class="tip-warn"  v-if="type !=1"><i class="el-icon-warning"></i>提醒:<br>
        <span style="">减保人员名单中,人员姓名、身份证号均为必填项,备注信息可为空,请录入合法数据。</span>
      </p>
        <el-form class="demo-form-inline">
            <el-form-item label="上传名单" required>
                <div style="width: 100%;display: flex;align-items: center;">
                    <el-button type="primary" @click="clickRef" :loading="importing">点击上传</el-button>
                    <el-button type="text" @click="exportTemplate">名单模板.EXCEL</el-button>
                </div>
                <div style="font-size: 14px; color: black;" v-if="fileName">{{fileName}}</div>
            </el-form-item>
        </el-form>
        <input type="file"   @cancel="importing=false"  style="position: fixed; left: 0; top: -50px;" accept=".xlsx" ref="fileExcel" @change="result" />
      <template  v-slot:footer>
        <el-button type="primary"   :loading="confirming" @click="confirm">确定</el-button>
        <el-button @click="visible=false">返回</el-button>
      </template>
    </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { importExcel,importReuduceExcel } from '@/api/business/member'
export default {
  name: 'importEmployees',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      importing:false,
      confirming:false,
      list: [],
      price: 0,
      type: null,
      solutionId: null,
      applyId: null,
      addList: [],
      delList: [],
      fileName: ''
    }
  },
  methods: {
    open (title, obj) {
      this.title = title
      this.addList = []
      this.delList = []
      this.fileName = ''
      this.type = obj.type
      this.visible = true
      this.solutionId = obj.solutionId
      this.applyId = obj.insuranceApplyId
      this.list = obj.arr
      this.price = obj.price
      this.importing= false
      this.confirming= false
    },
    // 导出模板
    exportTemplate () {
      // 投保申请
      if (this.type === 1) {
        window.open('/template/personnel_add.xlsx')
      } else {
        window.open('/template/personnel_reduce.xlsx')
      }
    },
    clickRef () {
      if(this.importing){
        return
      }
      this.importing=true
      this.$refs.fileExcel.click()
    },
    result(e){
      if (this.type === 1) {
        this.result1(e)
      } else {
        this.result2(e)
      }
    },
    result1 (e) {
      this.addList = []
      const data = new FormData()
      data.append('file', e.target.files[0])
      data.append('solutionId', this.solutionId)
      importExcel(data)
        .then(res => {
          res.forEach(item => {
            item.memberName = item.name
            item.fee = ''
          })
          this.addList = res
          this.fileName = e.target.files[0].name
          this.importing =false
        })
        .catch(err => {
          this.importing =false
          this.$message.error(err)
          this.fileName = ''
        })
        .finally(() => {
          this.importing =false
          this.$refs.fileExcel.value = null
        })
    },
    result2 (e) {
      this.delList = []
      const data = new FormData()
      data.append('file', e.target.files[0])
      data.append('applyId', this.applyId)
      importReuduceExcel(data)
        .then(res => {
          res.forEach(item => {
            item.memberName = item.name
          })
          this.delList = res
          this.fileName = e.target.files[0].name
          this.importing =false
        })
        .catch(err => {
          this.importing = false
          this.$message.error(err)
          this.fileName = ''
        })
        .finally(() => {
          this.importing =false
          this.$refs.fileExcel.value = null
        })
    },
    confirm () {
      if (this.type === 1) {
        this.confirm1()
      } else {
        this.confirm2()
      }
    },
    confirm1 () {
      if(this.addList==null || this.addList.length ==0){
        this.$message.error('导入人员名单为空,请先上传人员名单')
        return
      }
      if(this.confirming){
        return
      }
      this.confirming = true
      for (let i = 0; i < this.addList.length; i++) {
        for (let a = 0; a < this.list.length; a++) {
          if (this.addList[i].idCard === this.list[a].idcardNo) {
            this.$message.warning(`【${this.addList[i].name}】员工身份证【${this.addList[i].idCard}】重复`)
            this.confirming = false
            return
          }
          if (this.addList[i].idCard === this.list[a].idCard) {
            this.$message.warning(`【${this.addList[i].name}】员工身份证【${this.addList[i].idCard}】重复`)
            this.confirming = false
            return
          }
        }
      }
      this.addList.forEach(item => {
        item.fee = this.price
      })
      this.visible = false
      this.$emit('result', this.addList)
    },
    confirm2() {
      if(this.delList==null || this.delList.length ==0){
        this.$message.error('导入人员名单为空,请先上传人员名单')
        return
      }
      if(this.confirming){
        return
      }
      this.confirming = true
      for (let i = 0; i < this.delList.length; i++) {
        for (let a = 0; a < this.list.length; a++) {
          if (this.delList[i].idCard === this.list[a].idcardNo) {
            this.$message.warning(`【${this.delList[i].name}】员工身份证【${this.delList[i].idCard}】重复`)
            this.confirming = false
            return
          }
          if (this.delList[i].idCard === this.list[a].idCard) {
            this.$message.warning(`【${this.delList[i].name}】员工身份证【${this.delList[i].idCard}】重复`)
            this.confirming = false
            return
          }
        }
      }
      this.visible = false
      this.$emit('result', this.delList)
    }
  }
}
</script>
 
<style lang="scss" scoped>
 
</style>