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
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <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" :hidden=true>
            <a-form-model-item label="变动方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeMethod">
              <a-input v-model="model.changeMethod" placeholder="请输入变动方式" defaultValue="seal"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="设备封存明细" :key="refKeys[0]" :forceRender="true">
        <j-vxe-table keep-source :ref="refKeys[0]" :loading="equipmentSealDetailTable.loading"
          :columns="equipmentSealDetailTable.columns" :dataSource="equipmentSealDetailTable.dataSource" :maxHeight="300"
          :disabled="formDisabled" :rowNumber="true" :rowSelection="true" :toolbar="true" :toolbarConfig="toolbarConfig"
          :linkage-config="linkageConfig">
          <template slot="toolbarPrefix">
            <a-button type="primary" @click="selectEquipmentList" :disabled="formDisabled">选择设备
            </a-button>
          </template>
 
          <!-- state.address.regionName -->
          <template v-slot:maintenanceStandardId="props">
            <a-form-model ref="form" :model="props.row">
              <a-form-model-item style="margin-bottom: 0;" v-if="props.row.maintenanceAfterUnseal == 'Y'" label=""
                :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceStandardId"
                :rules="[{ required: true, message: '必填项',trigger: 'change' }]">
                <a-select v-model="props.row.maintenanceStandardId" @change="(e) => handleChange(e, props.row)"
                  :options="manageList" />
              </a-form-model-item>
              <a-form-model-item style="margin-bottom: 0;" v-else label="" :labelCol="labelCol" :wrapperCol="wrapperCol"
                prop="maintenanceStandardId">
                <a-select v-model="props.row.maintenanceStandardId" :options="manageList"
                  @change="(e) => handleChange(e, props.row.maintenanceAfterUnseal)" />
              </a-form-model-item>
            </a-form-model>
          </template>
          <!-- 设备图片插槽 -->
          <template v-slot:equipmentPhoto='props'>
            <Tooltip
          placement="top"
          title="预览图片"
          >
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img v-else :src="getImgView(text)" :preview="props.rowId" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </Tooltip>
          </template>
          <template v-slot:action="props">
            <a-popconfirm title="确定删除吗?" @confirm="handleDL(props)">
              <a>删除</a>
            </a-popconfirm>
          </template>
        </j-vxe-table>
      </a-tab-pane>
    </a-tabs>
    <equipment-select-modal ref="EquipmentSelectModal"></equipment-select-modal>
    <!-- <equipment-selection @selectionRows="selectionRows" :equipmentStatus="['2', '3']"
      ref="EquipmentSelection"></equipment-selection> -->
  </a-spin>
</template>
 
<script>
 
 
import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
import { randomUUID, randomNumber } from '@/utils/util'
 
import { validateDuplicateValue } from '@/utils/util'
import pick from 'lodash.pick'
import { getAction, postAction, requestPut } from '@api/manage'
// import EquipmentSelection from '@/components/tools/EquipmentSelection.vue'
import EquipmentSelectModal from './EquipmentSelectModal.vue'
 
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@comp/jeecg/JVxeTable'
import { getRefPromise, VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
 
import JFormContainer from '@/components/jeecg/JFormContainer'
 
export default {
  name: 'EquipmentSealForm',
  mixins: [JVxeTableModelMixin],
  components: {
    EquipmentSelectModal,
    JFormContainer
  },
  data() {
    return {
      changeMethod: 'seal',
      toolbarConfig: {
        // prefix 前缀;suffix 后缀
        slot: ['prefix', 'suffix'],
        // add 新增按钮;remove 删除按钮;clearSelection 清空选择按钮
        btn: ['remove', 'clearSelection']
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      manageList: [
        { label: '空', value: '' },
        { label: '保养标准一', value: '1001' },
        { label: '保养标准二', value: '1002' }
      ],
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 0,
      model: {},
      validatorRules: {
        num: [
          { required: true, message: '请输入单据号!' },
          { validator: (rule, value, callback) => validateDuplicateValue('mom_eam_equipment_change', 'num', value, this.model.id, callback) }
        ],
        remark: [
          { required: false, message: '请输入备注!' }
        ]
      },
      linkageConfig: [
        { handleVerify: this.handleVerify, key: 'maintenanceAfterUnseal' }
      ],
      refKeys: ['equipmentSealDetail'],
      tableKeys: ['equipmentSealDetail'],
      activeKey: 'equipmentSealDetail',
      // 设备封存明细
      equipmentSealDetailTable: {
        loading: false,
        dataSource: [],
        columns: [
          // {
          //   title: '操作',
          //   key: 'action',
          //   width: '60px',
          //   type: FormTypes.slot, // 定义该列为 自定义插值列
          //   slotName: 'action' // slot 的名称,对应 v-slot 冒号后面和等号前面的内容
          // },
          {
            title: '设备封存明细id',
            key: 'id',
            type: JVXETypes.hidden,
            width: '100px',
            fixed: 'left'
          },
          {
            title: '设备变动单id',
            key: 'equipmentChangeId',
            type: JVXETypes.hidden,
 
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '设备ID',
            key: 'equipmentId',
            type: JVXETypes.hidden,
            defaultValue: ''
          },
          {
            title: '设备编码',
            key: 'equipmentNum',
            type: JVXETypes.normal,
            width: '120px',
            // placeholder: '请输入${title}',
            fixed: 'left'
          },
          {
            title: '设备资产编码',
            key: 'assetNumber',
            type: JVXETypes.normal,
            width: '120px',
            fixed: 'left',
            defaultValue: ''
          },
          {
            title: '封存原因',
            key: 'sealReason',
            type: JVXETypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              {
                required: true, // 必填
                message: '请输入${title}' // 显示的文本
              }]
          },
          {
            title: '封存日期',
            key: 'sealDate',
            type: JVXETypes.datetime,
            width: '100px',
            placeholder: '请选择${title}',
            defaultValue: '',
            validateRules: [
              {
                required: true, // 必填
                message: '请输入${title}' // 显示的文本
              }]
 
          },
          {
            title: '预计启封日期',
            key: 'planUnsealDate',
            type: JVXETypes.date,
            width: '120px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          // {
          //   title: '强制启封',
          //   key: 'isForceUnseal',
          //   type: JVXETypes.checkbox,
          //   customValue: ['Y', 'N'],
          //   width: '120px',
          //   placeholder: '请输入${title}',
          //   defaultValue: ''
          // },
          // {
          //   title: '强制启封日期',
          //   key: 'forceUnsealDate',
          //   type: JVXETypes.date,
          //   width: '120px',
          //   placeholder: '请输入${title}',
          //   defaultValue: ''
          // },
          // {
          //   title: '强制启封后保养',
          //   key: 'maintenanceAfterUnseal',
          //   type: JVXETypes.checkbox,
          //   customValue: ['Y', 'N'],
          //   width: '150px',
          //   placeholder: '请输入${title}',
          //   defaultValue: 'N',
 
          // },
          // {
          //   title: '保养标准',
          //   key: 'maintenanceStandardId',
          //   type: JVXETypes.slot,
          //   width: '260px',
          //   slotName: 'maintenanceStandardId'
          // },
 
          {
            title: '特种设备',
            key: 'specificEquipment',
            type: JVXETypes.hidden,
            disabled: true,
 
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '特种设备',
            key: 'specificEquipment_dictText',
            type: JVXETypes.normal,
            disabled: true,
            width: '100px',
            defaultValue: ''
          },
          {
            title: '设备名称',
            key: 'equipmentName',
            type: JVXETypes.normal,
            disabled: true,
            width: '200px',
 
            defaultValue: ''
          },
          {
            title: '设备型号',
            key: 'model',
            type: JVXETypes.normal,
            disabled: true,
            width: '120px',
            defaultValue: ''
          },
          {
            title: '设备规格',
            key: 'specification',
            type: JVXETypes.normal,
            disabled: true,
            width: '120px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '设备状态',
            key: 'equipmentStatus_dictText',
            type: JVXETypes.normal,
            disabled: true,
            width: '100px',
            // placeholder: '请输入${title}',
            defaultValue: ''
          },
          // {
          //   title: '设备状态',
          //   key: 'equipmentStatus',
          //   type: JVXETypes.select,
          //   options: [],
          //   dictCode: 'equipment_status',
          //   disabled: true,
          //   width: '200px',
          //   // placeholder: '请输入${title}',
          //   defaultValue: ''
          // },
          {
            title: '技术状态',
            key: 'technologyStatus_dictText',
            type: JVXETypes.normal,
            disabled: true,
            width: '100px',
            defaultValue: ''
          },
          {
            title: '设备位置',
            key: 'location',
            type: JVXETypes.normal,
            disabled: true,
            width: '120px'
 
          },
          {
            title: '重要度',
            key: 'equipmentImportanceId_dictText',
            type: JVXETypes.normal,
            disabled: true,
            width: '100px',
            // placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '重要度',
            key: 'equipmentImportanceId',
            type: JVXETypes.hidden
          },
          {
            title: '设备图片',
            key: 'equipmentPhoto',
            type: JVXETypes.slot,
            disabled: true,
            width: '120px',
            slotName:'equipmentPhoto'
 
          },
          {
            title: '操作',
            key: 'action',
            type: JVXETypes.slot,
            disabled: true,
            width: '100px',
            slotName: 'action',
          },
 
        ]
      },
      url: {
        add: '/eam/equipmentSeal/add',
        edit: '/eam/equipmentSeal/edit',
        queryById: '/eam/equipmentSeal/queryById',
        equipmentSealDetail: {
          list: '/eam/equipmentSeal/listEquipmentSealDetailByMainId'
        }
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
  },
  mounted() {
    this.$bus.$on('selectionRows', (data) => {
      // 增加选中的设备到列表中
      this.addSelectedEquipments(data)
 
    })
  },
  methods: {
    handleChange(value, data) {
      this.$nextTick(() => {
        this.$set(data, 'maintenanceAfterUnseal', data.maintenanceAfterUnseal)
      })
    },
    handleVerify(parent) {
      if (parent == 'Y') {
        // 必填。
      }
    },
    selectionRows(data) {
      // 增加选中的设备到列表中
      this.addSelectedEquipments(data)
    },
    handleDL(props) {
        // 调用删除方法
        props.target.removeRows(props.row)
      },
 
    //选择设备
    selectEquipmentList() {
      let ids = []
      let tableData = this.$refs.equipmentSealDetail.getTableData()
      let deleteData = this.$refs.equipmentSealDetail.getDeleteData()
      for (let i = 0; i < tableData.length; i++) {
        ids.push(tableData[i].equipmentId)
      }
      // this.$refs.EquipmentSelection.showModals(ids, tableData)
      // this.$refs.EquipmentSelection.title = '选择设备'
      // this.$refs.EquipmentSelection.disableSubmit = false
      this.$refs.EquipmentSelectModal.showModals(ids)
      this.$refs.EquipmentSelectModal.title = '选择设备'
      this.$refs.EquipmentSelectModal.disableSubmit = false
    },
    addSelectedEquipments(data) {
      let tableData = this.$refs.equipmentSealDetail.getTableData()
      let tableStr = tableData.toString()
      let addRows = []
      for (let i = 0; i < data.length; i++) {
        var sealDetail = {}
        if (tableStr.indexOf(data[i].id) == -1) {
          sealDetail = {
            equipmentId: data[i].id,
            equipmentNum: data[i].num,
            equipmentName: data[i].name,
            assetNumber: data[i].assetNumber,
            specificEquipment_dictText: data[i].specificEquipment_dictText,
            specificEquipment: data[i].specificEquipment,
            model: data[i].model,
            specification: data[i].specification,
            equipmentStatus_dictText: data[i].equipmentStatus_dictText,
            equipmentStatus: data[i].equipmentStatus,
            technologyStatus_dictText: data[i].technologyStatus_dictText,
            technologyStatus: data[i].technologyStatus,
            equipmentPhoto: data[i].equipmentPhoto,
            location: data[i].location,
            equipmentImportanceId_dictText: data[i].equipmentImportanceId_dictText,
            equipmentImportanceId: data[i].equipmentImportanceId
          }
        }
        addRows.push(sealDetail)
      }
      // this.$refs.equipmentSealDetail.clearAllData()
      this.$refs.equipmentSealDetail.pushRows(addRows)
    },
    addBefore() {
      this.equipmentSealDetailTable.dataSource = []
    },
    getAllTable() {
      let values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      this.$nextTick(() => {
      })
      // 加载子表数据
      if (this.model.id) {
        let params = { equipmentChangeId: this.model.id }
        this.requestSubTableData(this.url.equipmentSealDetail.list, params, this.equipmentSealDetailTable)
      }
    },
    //校验所有一对一子表表单
    validateSubForm(allValues) {
      return new Promise((resolve, reject) => {
        Promise.all([]).then(() => {
          resolve(allValues)
        }).catch(e => {
          if (e.error === VALIDATE_FAILED) {
            // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
            this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
          } else {
            console.error(e)
          }
        })
      })
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        equipmentSealDetailList: allValues.tablesValue[0].tableData
      }
    },
    validateError(msg) {
      this.$message.error(msg)
    }
 
  }
 
}
</script>
 
<style scoped>
/** tab panel 中有下拉框/日期 这类带下拉效果的,需要加此样式 */
 
::v-deep .jeecg-tabs-top {
  overflow: visible;
}
 
::v-deep .ant-form-explain {
  position: absolute;
  right: -50px;
  top: 12px;
}
</style>