zenglf
2023-08-17 7442a435d058bd17d6fc679e1b7956bf3a5d32ae
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
<template>
  <a-modal
    :title='title'
    :width='1200'
    :visible='visible'
    :maskClosable='false'
    @ok='handleOk'
    cancelText='关闭'
    @cancel='handleCancel'
    :confirmLoading='confirmLoading'
  >
 
    <a-spin :spinning='confirmLoading'>
      <a-form-model :form='form' ref='form' :model='model' :rules='validatorRules'>
        <a-row :span='12'>
          <a-col :span='12'>
            <a-form-model-item label='单据号' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='num'>
              <a-input v-model='model.num' placeholder='请输入单据号'></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='调入公司' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='inEnterpriseId'>
              <a-tree-select
                style='width:100%'
                tree-default-expand-all
                :dropdown-style="{ maxHeight: '500px', overflow: 'auto' }"
                :treeData='treeDataSource'
                v-model='model.inEnterpriseId'
                placeholder='请选择调入公司'
                :replace-fields='replaceFields'
                :disabled='false'
                @change='handleChangeInEnterpriseId'>
              </a-tree-select>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-row :Span='24'>
          <a-col :span='12'>
            <a-form-model-item label='调出公司' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='outEnterpriseId'>
              <a-tree-select
                style='width:100%'
                tree-default-expand-all
                :dropdown-style="{ maxHeight: '500px', overflow: 'auto' }"
                :treeData='treeDataSource'
                v-model='model.outEnterpriseId'
                placeholder='请选择调出公司'
                :replace-fields='replaceFields'
                :disabled='false'
                @change='handleChangeOutEnterpriseId' />
            </a-form-model-item>
          </a-col>
 
          <a-col :span='12'>
            <a-form-model-item label='备注' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='remark'>
              <a-textarea v-model='model.remark'  placeholder='请输入备注'></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <a-button
      type='primary'
      :style="{ marginRight: '8px',marginBottom:'8px' }"
      :loading='confirmLoading'
      @click='selectInspectionProjects()'
    >设备信息
    </a-button>
 
    <a-table
      ref='table'
      bordered
      size='middle'
      rowKey='id'
      :columns='columns'
      :dataSource='dataSource'
      :scroll="{ x: 'calc(980px + 40%)', y: 900 }"
    >
 
      <template
        v-for='col in columns'
        :slot='col.dataIndex'
        slot-scope='text, record, index'
      >
        <div :key='col.dataIndex'>
 
 
          <a-select
            :value='text'
            placeholder='请选择'
            v-if="col.dataIndex == 'inDepartId'"
            :options='record.departVoList'
            @change='(e) => handleChange(e, record.key, col, index)'
            style='width: 100%'
          />
          <a-select
            v-if="col.dataIndex == 'inManagerId'"
            :value='text'
            placeholder='请选择'
            :options='record.userVoList'
            @change='(e) => handleChange(e, record.key, col, index)'
            style='width: 100%'
          />
          <a-input
            :value='text'
            placeholder='请输入'
            v-if="col.dataIndex == 'position'"
            @change='(e)=>handleChange(e, record.key, col, index)'
          />
 
 
          <a-select
            v-if="col.dataIndex == 'responsibilityUserId'"
            :value='text'
            placeholder='请选择'
            :options='record.userVoList'
            @change='(e) => handleChange(e, record.key, col, index)'
            style='width: 100%'
          />
          <a-select
            v-if="col.dataIndex == 'responsibilityTeamId'"
            :value='text'
            placeholder='请选择'
            :options='record.teamVoList'
            @change='(e) => handleChange(e, record.key, col, index)'
            style='width: 100%'
          />
          <!--          <a-input
                      :value='text'
                      placeholder='请输入'
                      v-if="col.dataIndex == 'responsibilityTeamId'"
                      @change='(e)=>handleChange(e, record.key, col, index)'
                    />-->
 
          <a-select
            v-if="col.dataIndex == 'useDepartId'"
            :value='text'
            placeholder='请选择'
            :options='record.departVoList'
            @change='(e) => handleChange(e, record.key, col, index)'
            style='width: 100%'
          />
          <a-date-picker
 
            v-if="col.dataIndex == 'demandDate'"
            :value='text'
            format='YYYY-MM-DD HH:mm:ss'
            @change='(e)=>handleChange(e, record.key, col, index)'
          />
          <a-date-picker
            v-if="col.dataIndex == 'actualInDate'"
            :value='text'
            format='YYYY-MM-DD HH:mm:ss'
            @change='(e)=>handleChange(e, record.key, col, index)'
          />
 
          <a-select
            v-if="col.dataIndex == 'equipmentTransferCatrgoryId'"
            :value='text'
            placeholder='请选择'
            :options='record.transferMethodVoList'
            @change='(e) => handleChange(e, record.key, col, index)'
            style='width: 100%'
          />
 
        </div>
      </template>
      <span
        slot='action'
        slot-scope='text, record, index'
      >
        <a-popconfirm
          title='确定删除吗?'
          @confirm='() => handleDelete(text,record, index)'
        >
          <a>删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <template slot='footer'>
      <a-button
        :style="{marginRight: '8px'}"
        @click='handleCancel()'
      >
        关闭
      </a-button>
 
      <a-button
        @click='handleOk()'
        type='primary'
        :loading='confirmLoading'
      >确定
      </a-button>
    </template>
    <j-select-equipment-modal
      ref='equipmentTransferInModalForm'></j-select-equipment-modal>
  </a-modal>
 
</template>
 
<script>
import { getAction, postAction, requestPut } from '@/api/manage'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import Tooltip from 'ant-design-vue/es/tooltip'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JSelectEquipmentModal from '@views/common/JSelectEquipmentModal'
 
export default {
  name: 'EquipmentTransferInDetailModal',
  components: {
    JMultiSelectTag,
    Tooltip,
    JSelectEquipmentModal
  },
  data() {
    return {
      replaceFields: {
        value: 'key'
      },
 
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          },
          width: 100
        },
        {
          title: '设备编码',
          align: 'center',
          width: 100,
          dataIndex: 'equipmentNum'
        },
        {
          title: '设备名称',
          align: 'center',
          width: 100,
          dataIndex: 'equipmentName'
        },
        {
          title: '规格',
          align: 'center',
          width: 100,
          dataIndex: 'specification'
        },
        {
          title: '型号',
          width: 100,
          align: 'center',
          dataIndex: 'model'
        },
        {
          title: '技术状态',
          align: 'center',
          width: 100,
          dataIndex: 'technicalStatus'
        },
        {
          title: '需求日期',
          align: 'center',
          dataIndex: 'demandDate',
          width: 200,
          scopedSlots: {
            customRender: 'demandDate'
          }
 
        },
        {
          title: '调入日期',
          align: 'center',
          width: 200,
          dataIndex: 'actualInDate',
          scopedSlots: {
            customRender: 'actualInDate'
          }
 
        },
        {
          title: '增加方式',
          align: 'center',
          width: 150,
          dataIndex: 'equipmentTransferCatrgoryId',
          scopedSlots: {
            customRender: 'equipmentTransferCatrgoryId'
          }
        },
 
        {
          title: '调入管理部门',
          align: 'center',
          width: 150,
          dataIndex: 'inDepartId',
 
          scopedSlots: {
            customRender: 'inDepartId'
          }
        },
        {
          title: '调入管理人',
          align: 'center',
          width: 150,
          dataIndex: 'inManagerId',
          scopedSlots: {
            customRender: 'inManagerId'
          }
        },
        {
          title: '调入责任班组',
          width: 150,
          align: 'center',
          dataIndex: 'responsibilityTeamId',
          scopedSlots: {
            customRender: 'responsibilityTeamId'
          }
        },
        {
          title: '调入责任人',
          width: 150,
          align: 'center',
          dataIndex: 'responsibilityUserId',
          scopedSlots: {
            customRender: 'responsibilityUserId'
          }
        },
        {
          title: '使用部门',
          width: 150,
          align: 'center',
          dataIndex: 'useDepartId',
          scopedSlots: {
            customRender: 'useDepartId'
          }
        },
 
        {
          title: '调入位置',
          width: 150,
          align: 'center',
          dataIndex: 'position',
          scopedSlots: {
            customRender: 'position'
          }
        },
        {
          title: '操作',
          width: 100,
          align: 'center',
          dataIndex: 'action',
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],
      title: '操作',
      visible: false,
      visible4Confirm: false,
      disableSubmit: false,
      codeDisable: true,
      model: {},
      dateFormat: 'YYYY-MM-DD HH:mm:ss',
      transferMethodVoList: {},
      text: '',
      position: '',
      userVoList: {},
      teamVoList: {},
      departVoList: {},
      workOrder: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        num: [
          { required: true, message: '请输入单号!' },
          { validator: (rule, value, callback) => validateDuplicateValue('mom_eam_equipment_transfer', 'num', value, this.model.id, callback) }
        ],
        outEnterpriseId: [
          { required: true, message: '请输入调出企业!' }
 
        ],
        inEnterpriseId: [
          { required: true, message: '请输入调入企业!' }
 
        ]
      },
 
      url: {
        add: '/eam/equipmentTransfer/add',
        edit: '/eam/equipmentTransfer/edit',
        loadTree: '/base/enterprise/enterpriseTree',
        getTransferMethod: '/eam/equipmentTransferInDetail/getTransferMethod',
        userVoList: '/eam/equipmentTransferInDetail/getUser',
        teamVoList: '/eam/equipmentTransferInDetail/getTeam',
        departVoList: 'eam/equipmentTransferInDetail/getDepart'
      },
      treeDataSource: [],
      dataSource: [],
      enterpriseId: '',
      inEnterpriseId: ''
 
 
    }
  },
  created() {
    //备份model原始值
    this.queryTreeData()
  },
 
  mounted() {
    this.$bus.$on('selectionRows', (data) => {
      for (let i = 0; i < data.length; i++) {
        this.dataSource.push({
          id: data[i].id,
          equipmentId: data[i].id,
          equipmentNum: data[i].num,
          equipmentName: data[i].name,
          model: data[i].model,
          specification: data[i].specification,
          technicalStatus: data[i].technologyStatus_dictText,
          transferMethodVoList: this.transferMethodVoList,
          userVoList: this.userVoList,
          teamVoList: this.teamVoList,
          departVoList: this.departVoList
 
        })
      }
 
    })
  },
 
 
  methods: {
 
    getTransferMethod() {
      getAction(this.url.getTransferMethod, { type: 'add' }).then((res) => {
        if (res.success) {
          this.transferMethodVoList = res.result
        } else {
          this.$message.warn(res.message)
        }
      })
    },
 
    /*获取部门列表*/
    getInDepartList() {
      getAction(this.url.departVoList).then((res) => {
        if (res.success) {
          this.departVoList = res.result
 
        } else {
          this.$message.warn(res.message)
        }
      })
    },
    /*获取管理人列表*/
    getInUseList() {
      getAction(this.url.userVoList).then((res) => {
        if (res.success) {
 
          this.userVoList = res.result
        } else {
          this.$message.warn(res.message)
        }
      })
    },
 
    /*获取责任班组列表*/
    getInTeamList() {
      getAction(this.url.teamVoList).then((res) => {
        if (res.success) {
 
          this.teamVoList = res.result
        } else {
          this.$message.warn(res.message)
        }
      })
    },
 
    /*获取企业树信息*/
    queryTreeData() {
      this.loading = true
      this.cardLoading = true
      getAction(this.url.loadTree, { version: 4 })
        .then((res) => {
          if (res.success) {
            this.treeDataSource = res.result
          } else {
            this.$message.warn(res.message)
          }
        })
        .finally((res) => {
          this.loading = false
          this.cardLoading = false
        })
    },
    //选择点检项目
    selectInspectionProjects: function() {
      let ids = []
      for (let i = 0; i < this.dataSource.length; i++) {
        ids.push(this.dataSource[i].equipmentId)
      }
      this.$refs.equipmentTransferInModalForm.showModals(ids)
      this.$refs.equipmentTransferInModalForm.title = '选择设备信息'
      this.$refs.equipmentTransferInModalForm.disableSubmit = false
    },
 
    add() {
      this.model.transferType = 'add'
      this.edit(this.model, { equipmentTransferInDetailList: [] })
    },
 
 
    edit(record) {
      let that = this
      this.getTransferMethod()
      this.getInDepartList()
      this.getInUseList()
      this.getInTeamList()
      that.dataSource = []
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      if (record.equipmentTransferInDetailList != undefined) {
        const temp = [...record.equipmentTransferInDetailList]
        that.dataSource = temp
      }
      that.$nextTick(() => {
        that.form.setFieldsValue(pick(that.model, 'num', 'inEnterpriseId', 'outEnterpriseId', 'remark'))
      })
      if (record.id) {
        this.codeDisable = true
      } else {
        this.codeDisable = false
      }
    },
 
 
    close() {
      this.$emit('close')
      this.visible = false
    },
 
    handleCancel() {
      this.close()
    },
    handleChangeInEnterpriseId(value) {
      this.enterpriseId = value
      console.log('调出' + this.enterpriseId)
    },
    handleChangeOutEnterpriseId(value) {
      this.inEnterpriseId = value
      console.log('调入' + this.inEnterpriseId)
    },
 
    handleChange(value, key, column, index) {
      let that = this
      const temp = [...that.dataSource]
      const target = temp.filter(item => key === item.key)[index]
      if (target) {
 
        if (column.dataIndex == 'demandDate') {
 
          target[column.dataIndex] = value
 
        } else if (column.dataIndex == 'actualInDate') {
          target[column.dataIndex] = value
 
        } else if (column.dataIndex == 'inManagerId') {
 
          target[column.dataIndex] = value
        } else if (column.dataIndex == 'equipmentTransferCatrgoryId') {
 
          target[column.dataIndex] = value
          this.text = value
 
        } else if (column.dataIndex == 'inDepartId') {
 
          target[column.dataIndex] = value
 
        } else if (column.dataIndex == 'responsibilityUserId') {
 
          target[column.dataIndex] = value
 
        } else if (column.dataIndex == 'useDepartId') {
 
          target[column.dataIndex] = value
 
        } else if (column.dataIndex == 'position') {
 
          target[column.dataIndex] = value.target.value
        } else if (column.dataIndex == 'responsibilityTeamId') {
 
          target[column.dataIndex] = value
        }
        //显示带过来的数据
 
        that.dataSource = temp
 
      }
    },
 
    handleOk() {
      const that = this
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let formData = Object.assign(this.model, valid)
          formData.equipmentTransferInDetailList = that.dataSource
          if (that.dataSource.length ===0){
            that.confirmLoading = false
            that.$message.warning("请添加调入明细")
            return
          }
          formData.equipmentTransferCatrgoryId = this.text
          for (let annItem of that.dataSource) {
            if (annItem.specification == undefined || annItem.specification == null || annItem.specification == '') {
              that.$message.warning('请填写规格')
              that.confirmLoading = false
              return
            }
            if (annItem.model == undefined || annItem.model == null || annItem.model == '') {
              that.$message.warning('请填写型号')
              that.confirmLoading = false
              return
            }
            if (annItem.equipmentName == undefined || annItem.equipmentName == null || annItem.equipmentName == '') {
              that.$message.warning('设备名称不能为空')
              that.confirmLoading = false
              return
            }
            if (annItem.equipmentId == undefined || annItem.equipmentId == null || annItem.equipmentId == '') {
              that.$message.warning('当前设备信息错误,重新选择设备')
              that.confirmLoading = false
              return
            }
            if (annItem.demandDate == undefined || annItem.demandDate == null || annItem.demandDate == '') {
              that.$message.warning('请填写需求日期')
              that.confirmLoading = false
              return
            }
            if (annItem.inDepartId == undefined || annItem.inDepartId == null || annItem.inDepartId == '') {
              that.$message.warning('请填写调入管理部门')
              that.confirmLoading = false
              return
            }
            if (annItem.inManagerId == undefined || annItem.inManagerId == null || annItem.inManagerId == '') {
              that.$message.warning('请填写调入管理人')
              that.confirmLoading = false
              return
            }
            if (annItem.inManagerId == undefined || annItem.useDepartId == null || annItem.useDepartId == '') {
              that.$message.warning('请填写调入责任部门')
              that.confirmLoading = false
              return
            }
 
 
          }
          let obj
          if (!this.model.id) {
            obj = postAction(this.url.add, formData)
          } else {
            obj = requestPut(this.url.edit, formData, { id: this.model.id })
          }
          obj.then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            this.model = {}
            that.confirmLoading = false
            this.$set(this.model, 'auditStatus', 'notSubmitted')
            that.close()
          })
        }
      })
    },
 
    handleDelete(text, record, index) {
      this.dataSource.splice(index, 1)
 
    }
 
 
  }
}
</script>
 
<style lang='less' scoped>
/deep/ .frozenRowClass {
  color: #c9c9c9;
}
 
.fontweight {
  font-weight: bold;
}
 
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}
 
.ant-form-item-control {
  line-height: 0px;
}
 
/** 主表单行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}
 
/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>