MrShi
2024-03-05 84b74d64ecc519882b89278f1011f7ac7525d190
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<template>
    <GlobalWindow
        :title="title"
        width="100%"
        text="投保申请"
        :visible.sync="visible"
        :confirm-working="isWorking"
        @confirm="confirm"
    >
        <div class="list">
            <el-form :inline="true" ref="form" :model="form" :rules="rules" class="demo-form-inline">
                <el-form-item label="保险方案" prop="solutionId">
                    <el-select v-model="form.solutionId" @change="changeSolution" placeholder="请选择">
                        <el-option
                            v-for="item in company"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="期望保险生效起期" prop="applyStartTime">
                    <div style="display: flex; flex-direction: column;">
                        <el-date-picker
                            @change="getTimeVal"
                            v-model="form.applyStartTime"
                            type="date"
                            class="date_picker"
                            :clearable="false"
                            :disabled="!form.solutionId"
                            :picker-options="pickerOptions"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择日期">
                        </el-date-picker>
                        <span style="color: #F95601; font-size: 14px;">(次日生效投保请于17:30前提交,超时提交以保险单为准)</span>
                    </div>
                </el-form-item>
                <el-form-item label="保险生效止期" prop="applyEndTime">
                    <el-date-picker
                        disabled
                        v-model="form.applyEndTime"
                        type="date"
                        class="date_picker"
                        :picker-options="pickerOptions"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="投保年龄" v-if="item">
                    <span>{{item.minAge}} 至 {{item.maxAge}}</span>
                </el-form-item>
                <el-form-item label="费用" v-if="item">
                    <span>{{item.price}}元</span>
                    <span v-if="item.timeUnit === 0">/天</span>
                    <span v-if="item.timeUnit === 1">/半月</span>
                    <span v-if="item.timeUnit === 2">/月</span>
                    <span v-if="item.timeUnit === 3">/年</span>
                    <span>/人</span>
                </el-form-item>
            </el-form>
        </div>
        <div class="btns">
            <div class="btns_item">
                <el-button type="primary" @click="seleUser">选取员工</el-button>
                <el-button type="primary" @click="uploadUser">导入员工</el-button>
                <el-button type="primary" @click="addUser">添加员工</el-button>
                <el-button type="danger" @click="deleItem">删除</el-button>
            </div>
            <div class="btns_item">
                <el-button type="primary" @click="sele">选取派遣单位</el-button>
            </div>
        </div>
        <el-table
            :data="tableData"
            border
            show-summary
            :summary-method="getSummaries"
            ref="multipleTable"
            @selection-change="handleSelectionChange"
            style="width: 100%;margin-bottom: 15px;">
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>
            <el-table-column label="序号" width="80px">
                <template slot-scope="scope">
                    <span>{{scope.$index + 1}}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="memberName"
                label="姓名">
            </el-table-column>
            <el-table-column
                prop="idCard"
                label="身份证号">
            </el-table-column>
            <el-table-column
                label="年龄">
                <template slot-scope="{row}">
                    <template v-if="item">
                        <span style="color: red;" v-if="row.idCard && (getAgeByIdCard(row.idCard) < item.minAge || getAgeByIdCard(row.idCard) > item.maxAge)">{{ getAgeByIdCard(row.idCard) }}</span>
                        <span v-else>{{ getAgeByIdCard(row.idCard) }}</span>
                    </template>
                </template>
            </el-table-column>
            <el-table-column
                prop="duName"
                label="派遣单位">
            </el-table-column>
            <el-table-column
                prop="workTypeName"
                label="所属工种">
            </el-table-column>
            <el-table-column
                prop="fee"
                label="费用">
            </el-table-column>
            <el-table-column
                label="操作">
                <template slot-scope="scope">
                    <el-button type="text" style="color: red;" @click="dele(scope.$index)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="info" v-if="item">
            <span v-if="item.specialAgreement">{{item.specialAgreement}}</span>
            <span v-if="item.specialInfo">{{item.specialInfo}}</span>
            <span v-if="item.ortherInfo">{{item.ortherInfo}}</span>
        </div>
        <!--    选择员工    -->
        <selectEmployees ref="selectEmployees" @result="getValue" />
        <!--    添加员工    -->
        <addEmployee ref="addEmployee" @result="getValue" />
        <!--    导入名单    -->
        <importEmployees ref="importEmployees" @result="getValue" />
        <!--    确认工种    -->
        <confirmJobType ref="confirmJobType" @result="getUser" />
        <!--    查看详单    -->
        <detailsPolicyholder ref="detailsPolicyholder" @success="successEvent" />
    </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import selectEmployees from '@/components/enterprise/selectEmployees'
import addEmployee from '@/components/enterprise/addEmployee'
import importEmployees from '@/components/enterprise/importEmployees'
import confirmJobType from '@/components/enterprise/confirmJobType'
import detailsPolicyholder from '@/components/business/detailsPolicyholder'
import { all, getNewVersion } from '@/api/business/solutions'
import { mapState } from 'vuex'
import { create, getCountCyclePriceVO, getDetail, findList, updateData } from '@/api/business/insuranceApply'
export default {
  name: 'OperaInsuranceApplyWindow2',
  extends: BaseOpera,
  components: { GlobalWindow, selectEmployees, addEmployee, importEmployees, confirmJobType, detailsPolicyholder },
  data () {
    return {
      form: {
          id: null,
          ID: null,
          solutionId: '',
          applyStartTime: '',
          applyEndTime: ''
      },
      solutionName: '',
      type: '',
      pickerOptions: {}, // 存放picker options的变量
      price: '',
      company: [],
      seleData: [],
      item: null,
      // 验证规则
      rules: {
          solutionId: [
              { required: true, message: '请选择保险方案' }
          ],
          applyStartTime: [
              { required: true, message: '请选择期望保险生效起期' }
          ]
      },
      tableData: []
    }
  },
  created () {
      this.config({
          api: '/business/insuranceApply',
          'field.id': 'id'
      })
  },
    computed: {
      ...mapState(['userInfo'])
    },
    methods: {
      successEvent() {
          let arr = JSON.parse(JSON.stringify(this.tableData))
          arr.forEach(item => {
              item.idcardNo = item.idCard
          })
          this.isWorking = true
          // if (!this.form.id) {
              create({
                  applyDetailList: arr,
                  applyStartTime: this.form.applyStartTime,
                  applyEndTime: this.form.applyEndTime,
                  solutionId: this.form.solutionId
              }).then(() => {
                  this.visible = false
                  this.$tip.apiSuccess('操作成功')
                  this.$emit('success')
              })
                  .catch(e => {
                      this.$tip.apiFailed(e)
                  })
                  .finally(() => {
                      this.isWorking = false
                  })
          // } else {
          //     updateData({
          //         id: this.form.id,
          //         applyDetailList: arr,
          //         applyStartTime: this.form.applyStartTime,
          //         applyEndTime: this.form.applyEndTime,
          //         solutionId: this.form.solutionId
          //     }).then(() => {
          //         this.visible = false
          //         this.$tip.apiSuccess('操作成功')
          //         this.$emit('success')
          //     }).catch(e => {
          //         this.$tip.apiFailed(e)
          //     })
          //         .finally(() => {
          //             this.isWorking = false
          //         })
          // }
      },
      open (title, target) {
          this.title = title
          this.tableData = []
          this.form.id = null
          this.item = null
          if (target.type) {
              this.type = target.type
          }
          this.form.solutionId = ''
          this.form.applyStartTime = ''
          this.form.applyEndTime = ''
          if (target && target.id) {
              this.$nextTick(() => {
                  this.$refs.form.resetFields()
                  this.form.id = target.id
                  this.getDetails()
              })
          } else {
              this.$nextTick(() => {
                  this.$refs.form.resetFields()
                  this.form[this.configData['field.id']] = null
              })
          }
          this.getCompany()
          this.visible = true
          this.updatePickerOptions()
      },
        // 获取投保详情
        getDetails() {
            findList({ applyId: this.form.id })
                .then(res => {
                    res.forEach(item => {
                        console.log(item)
                        item.idCard = item.idcardNo
                        item.fee = ''
                        if (this.type === 1) {
                            item.duName = ''
                            item.duId = ''
                            item.worktypeId = ''
                            item.workTypeName = ''
                        }
                    })
                    this.tableData = res
                })
            getDetail(this.form.id)
                .then(res => {
                    // this.form.solutionId = res.solutionId
                    this.changeSolution1(res.solutionId)
                })
        },
        getSummaries(param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '总价'
                    return
                } else if (index === 7) {
                    let total = 0
                    this.tableData.forEach(item => {
                        total += item.fee
                    })
                    sums[index] = total
                    return
                }
            })
            return sums
        },
        deleItem() {
            if (this.seleData.length === 0) {
                this.$message.warning('至少选择一项内容')
                return
            }
            this.seleData.forEach(item => {
                this.tableData.forEach((row, index) => {
                    if (item === row.idCard) {
                        this.tableData.splice(index, 1)
                    }
                })
            })
        },
        confirm() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    if (this.tableData.length === 0) {
                        this.$message.warning('至少添加一项员工')
                        return
                    }
                    for (let i = 0; i < this.tableData.length; i++) {
                        console.log(this.tableData[i].worktypeId)
                        console.log(this.tableData[i].duId)
                        if (!this.tableData[i].worktypeId || !this.tableData[i].duId) {
                            this.$message.warning('请完善派遣单位和工种信息')
                            return
                        }
                    }
 
                    let price = 0
                    this.tableData.forEach(item => {
                        price = price + item.fee
                    })
                    this.$refs.detailsPolicyholder.open('投保详情单', {
                        companyName: this.userInfo.company.name,
                        solutionName: this.item.name,
                        applyStartTime: this.form.applyStartTime,
                        applyEndTime: this.form.applyEndTime,
                        insureNum: this.tableData.length,
                        totalPrice: price,
                        detailList: this.tableData
                    })
 
                }
            })
        },
        // 获取结束时间和价格
        getTimeVal(time) {
            getCountCyclePriceVO({
                solutionsId: this.form.solutionId,
                startDate: time
            }).then(res => {
                this.price = res.cyclePrice
                this.form.applyEndTime = res.endDate
                this.tableData.forEach(item => {
                    item.fee = res.cyclePrice
                })
                this.$forceUpdate()
            })
        },
        getDate(n) { // n为多少天,-代表往前,+代表往后
            let date1 = new Date(),
            time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();//time1表示当前时间
            let date2 = new Date(date1);
            date2.setDate(date1.getDate() + n);
            let time2 = date2.getFullYear() + "-" + ("0" + (date2.getMonth() + 1)).slice(-2) + "-" + ("0" + date2.getDate()).slice(-2);
            return time2
        },
        updatePickerOptions() {
          var that = this;
            this.pickerOptions = {
                disabledDate(time) {
                    if (!that.item) return
                    if (that.item.validType === 1) {
                        // 次月
                        const currentDate = new Date();
                        currentDate.setMonth(currentDate.getMonth() + 1);
                        currentDate.setDate(1);
                        return time.getTime() <= new Date(currentDate.toLocaleString()).getTime() - 8.64e7;
                    } else if (that.item.validType === 0) {
                        // 多少日后生效
                        return time.getTime() <= new Date(that.getDate(that.item.validTypeNum - 1)).getTime();
                    }
                }
            };
        },
        seleUser() {
            if (!this.form.solutionId) {
                this.$message.warning('请先选择保险方案')
                return
            }
            this.$refs.selectEmployees.open('选取员工', { arr: this.tableData, price: this.price, type: 1 })
        },
      addUser() {
          if (!this.form.solutionId) {
              this.$message.warning('请先选择保险方案')
              return
          }
          this.$refs.addEmployee.open('添加员工', { arr: this.tableData, price: this.price })
      },
      uploadUser() {
          if (!this.form.solutionId) {
              this.$message.warning('请先选择保险方案')
              return
          }
          this.$refs.importEmployees.open('上传名单', { arr: this.tableData, solutionId: this.form.solutionId, type: 1, price: this.price })
      },
      // 切换方案
      changeSolution(e) {
          if (!this.form.id) {
              this.tableData = []
          } else {
              this.price = ''
              this.form.applyEndTime = ''
              this.form.applyStartTime = ''
              this.tableData.forEach(item => {
                  item.fee = ''
                  item.duName = ''
                  item.duId = ''
                  item.workTypeName = ''
                  item.workTypeId = ''
              })
          }
          this.company.forEach(item => {
              if (item.id === e) {
                  // this.price = item.price
                  this.item = item
                  this.updatePickerOptions()
              }
          })
          this.tableData.forEach(item => {
              item.fee = this.price
          })
      },
        // 切换方案
        changeSolution1(e) {
            getNewVersion(e)
                .then(res => {
                    this.form.solutionId = res.id
                    this.company.forEach(item => {
                        if (item.id === res.id) {
                            // this.price = item.price
                            this.item = item
                            this.updatePickerOptions()
                        }
                    })
                })
            this.tableData.forEach(item => {
                item.fee = this.price
            })
        },
      dele(index) {
          this.tableData.splice(index, 1)
      },
      getUser(obj) {
          this.seleData.forEach(id => {
              this.tableData.forEach(row => {
                   if (id === row.idCard) {
                       row.workTypeName = obj.workTypeName
                       row.worktypeId = obj.worktypeId
                       row.duName = obj.duName
                       row.duId = obj.duId
                   }
              })
          })
          this.seleData = []
          this.$refs.multipleTable.clearSelection();
      },
      // 选择员工
      sele() {
          if (!this.form.solutionId) {
              this.$message.warning('请选择保险方案')
              return
          }
          if (this.seleData.length === 0) {
              this.$message.warning('请选择员工')
              return
          }
          this.$refs.confirmJobType.open('确认工种', { solutionId: this.form.solutionId })
      },
      // 查询全部方案
      getCompany() {
          all({})
            .then(res => {
                this.company = res
            })
      },
      getAgeByIdCard(idCard){
          const sexAndAge = {}
          //获取用户身份证号码
          const userCard = idCard
          //如果用户身份证号码为undefined则返回空
          if (!userCard) {
              return sexAndAge
          }
          // 获取出生日期
          const yearBirth = userCard.substring(6, 10)
          const monthBirth = userCard.substring(10, 12)
          const dayBirth = userCard.substring(12, 14)
          // 获取当前年月日并计算年龄
          const myDate = new Date()
          const monthNow = myDate.getMonth() + 1
          const dayNow = myDate.getDate()
          let age = myDate.getFullYear() - yearBirth
          if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
              age--
          }
          // 得到年龄
          sexAndAge.age = age
          return sexAndAge.age
      },
      handleSelectionChange (e) {
          this.seleData = e.map(item => item.idCard)
      },
      getValue(list) {
          this.tableData.push(...list)
      }
  }
}
</script>
 
<style>
    .el-picker-panel__footer .el-button--text.el-picker-panel__link-btn {
        display: none;
    }
</style>
 
<style lang="scss" scoped>
    .list {
        width: 100%;
    }
    .btns {
        width: 100%;
        margin-bottom: 15px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .btns_item {
            display: flex;
            align-items: center;
        }
    }
    .submit {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 15px;
    }
    .info {
        width: 100%;
        font-size: 14px;
        color: black;
    }
</style>