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
<template>
  <a-modal
    :width="1200"
    :visible="visible"
    :title="title"
    @cancel="handCancel"
    @ok="submitForm"
    :mask-closable="false"
    centered
  >
    <a-spin :spinning="spinning">
      <a-form-model ref="form" :model='tableRowRecord' :rules='validatorRules' :labelCol='labelCol'
                    :wrapperCol='wrapperCol'>
        <a-divider orientation="center" style="font-size: large;font-style: italic;color: #66aeed;">报修基础信息</a-divider>
 
        <a-row>
          <a-col :span='threeColSpan'>
            <a-form-model-item label='工单编号'>
              <a-input :readOnly='inputReadOnly' v-model='tableRowRecord.repairCode'/>
            </a-form-model-item>
          </a-col>
          <a-col :span='threeColSpan'>
            <a-form-model-item label='设备编号'>
              <lx-search-equipment-select disabled v-model='tableRowRecord.equipmentId'/>
            </a-form-model-item>
          </a-col>
          <a-col :span='threeColSpan'>
            <a-form-model-item label='维修负责人'>
              <a-input :readOnly='inputReadOnly' v-model='tableRowRecord.repairer'/>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-row>
          <a-col :span="threeColSpan">
            <a-form-model-item label="故障开始时间">
              <a-input :readOnly='inputReadOnly' v-model="tableRowRecord.faultStartTime"/>
            </a-form-model-item>
          </a-col>
 
          <a-col :span="threeColSpan">
            <a-form-model-item label="是否停机">
              <j-dict-select-tag type='radio' v-model='tableRowRecord.breakdownFlag' dictCode='breakdown_flag'
                                 disabled/>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-row>
          <a-col :span='threeColSpan*3'>
            <a-form-model-item label='报修图片' :labelCol='labelColLong' :wrapperCol='wrapperColLong'>
              <lx-upload :returnUrl="false" :isMultiple="true" file-type="image" disabled :number="3"
                         v-model="tableRowRecord.reportImageFiles"/>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-divider orientation="center" style="font-size: large;font-style: italic;color: #66aeed;">是否需要领用备件</a-divider>
 
        <a-tabs v-model="activeTabKey">
          <a-tab-pane key="1" tab="领用备件">
            <a-row>
              <a-col :span="twoColSpan*2">
                <a-form-model-item label="是否需要领用备件" prop="isUseSpare">
                  <a-radio-group v-model="tableRowRecord.isUseSpare">
                    <a-radio :value="1">是</a-radio>
                    <a-radio :value="0">否</a-radio>
                  </a-radio-group>
                </a-form-model-item>
              </a-col>
 
              <template v-if="tableRowRecord.isUseSpare===0">
                <a-col :span="twoColSpan*2">
                  <a-form-model-item label="故障原因" prop="faultReason">
                    <a-input :readOnly="disableSubmit||tableRowRecord.repairStatus!=='UNDER_REPAIR'"
                             v-model="tableRowRecord.faultReason" rows="4"
                             placeholder="请输入故障原因"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="twoColSpan*2">
                  <a-form-model-item label="维修结果描述" prop="repairDescription">
                    <a-textarea :readOnly="disableSubmit||tableRowRecord.repairStatus!=='UNDER_REPAIR'"
                                v-model="tableRowRecord.repairDescription"
                                placeholder="请输入维修结果描述"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="twoColSpan*2">
                  <a-form-model-item label="维修图片">
                    <lx-upload :returnUrl="false" :isMultiple="true" file-type="image" :number="3"
                               :disabled="disableSubmit||tableRowRecord.repairStatus!=='UNDER_REPAIR'"
                               v-model="tableRowRecord.imageFiles"/>
                  </a-form-model-item>
                </a-col>
              </template>
            </a-row>
          </a-tab-pane>
 
          <a-tab-pane key='2' tab='流程节点'>
            <a-card :bordered="false">
              <a-timeline>
                <a-timeline-item v-for="(item,index) in hitaskDataSource" :key="index">
                  <div>
                    <h3 style="font-weight: bold">{{item.taskName}}</h3>
                    <div>处理人:{{item.assignee_dictText}}</div>
                    <div v-if="index !==0">处理时长:{{item.duration}}</div>
                    <div v-if="item.name !== '提交申请'">处理类型:{{item.sequenceFlowName}}</div>
                    <div v-if="item.description">处理意见:{{item.description}}</div>
                  </div>
                </a-timeline-item>
              </a-timeline>
            </a-card>
          </a-tab-pane>
 
          <a-tab-pane key='3' tab='流程图'>
            <img :src="imageSrc" alt="Fetched Image"/>
          </a-tab-pane>
        </a-tabs>
 
        <template v-if="isDisplayConfirmSpare">
          <a-divider orientation="center" style="font-size: large;font-style: italic;color: #66aeed;">管理员领用备件
          </a-divider>
 
          <a-row>
            <a-col :span="twoColSpan*2">
              <a-form-model-item prop="sparePartDescription" label="备件描述">
                <a-textarea :readOnly="disableSubmit||tableRowRecord.repairStatus!=='WAIT_SPARES'"
                            v-model="tableRowRecord.sparePartDescription"/>
              </a-form-model-item>
            </a-col>
          </a-row>
        </template>
 
        <template v-if="tableRowRecord.sparePartDescription">
          <a-divider orientation="center" style="font-size: large;font-style: italic;color: #66aeed;">维修结果上报</a-divider>
          <a-row>
            <a-col :span="twoColSpan*2">
              <a-form-model-item label="故障原因" prop="faultReason">
                <a-input :readOnly="disableSubmit||isDisableSubmitRepairResult" v-model="tableRowRecord.faultReason"
                         rows="4" placeholder="请输入故障原因"/>
              </a-form-model-item>
            </a-col>
          </a-row>
 
          <a-row>
            <a-col :span="twoColSpan*2">
              <a-form-model-item label="维修结果描述" prop="repairDescription">
                <a-textarea :readOnly="disableSubmit||isDisableSubmitRepairResult"
                            v-model="tableRowRecord.repairDescription"
                            placeholder="请输入维修结果描述"/>
              </a-form-model-item>
            </a-col>
          </a-row>
 
          <a-row>
            <a-col :span="twoColSpan*2">
              <a-form-model-item label="维修图片">
                <lx-upload :disabled="disableSubmit||isDisableSubmitRepairResult" :returnUrl="false" :isMultiple="true"
                           file-type="image" :number="3"
                           v-model="tableRowRecord.imageFiles"/>
              </a-form-model-item>
            </a-col>
          </a-row>
        </template>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>
 
<script>
  import '@assets/less/TableExpand.less'
  import { getAction, deleteAction, postAction, downFile, httpAction } from '@api/manage'
  import LxSearchEquipmentSelect from '../../../eam/equipment/modules/LxSearchEquipmentSelect'
 
  export default {
    name: 'RepairOrderApprovalModal',
    components: { LxSearchEquipmentSelect },
    props: {
      selectShenpiData: {
        type: Object,
        required: true
      }
    },
    data() {
      return {
        title: '',
        threeColSpan: 8,
        twoColSpan: 12,
        inputReadOnly: true,
        disableSubmit: false,
        spinning: false,
        tableRowRecord: {},
        hitaskDataSource: [],
        imageSrc: null,
        activeTabKey: '1',
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        labelColLong: {
          xs: { span: 24 },
          sm: { span: 2 }
        },
        wrapperColLong: {
          xs: { span: 24 },
          sm: { span: 20 }
        },
        validatorRules: {
          isUseSpare: [
            { required: true, message: '请选择是否需要领用备件' }
          ],
          sparePartDescription: [
            { required: true, message: '请输入备件描述' }
          ],
          faultReason: [
            { required: true, message: '请输入故障原因' }
          ],
          repairDescription: [
            { required: true, message: '请输入维修结果描述' }
          ]
        },
        approveData: {},
        visible: false,
        // 表头
        url: {
          queryBomDataById: '/eam/eamRepairOrder/queryById',
          diagramView: '/assign/flow/diagramView',
          queryHisTaskList: '/assign/flow/queryHisTaskList',
          approve: '/eam/eamRepairOrder/perform'
        }
      }
    },
    computed: {
      isDisplayConfirmSpare() {
        return ['WAIT_SPARES', 'WAIT_CONFIRM', 'COMPLETE'].includes(this.tableRowRecord.repairStatus)
      },
      isDisableSubmitRepairResult() {
        return ['WAIT_CONFIRM', 'COMPLETE'].includes(this.tableRowRecord.repairStatus)
      }
    },
    methods: {
      /**
       * 获取流程节点和流程图
       * @param record 待办记录信息
       */
      getAllApproveData(record) {
        console.log('record----->', record)
        const { procInstId, processDefinitionId, processInstanceId, processDefinitionKey } = record
        const param = { procInstId }
        const imageParam = { processDefinitionId, processInstanceId, TaskDefinitionKey: processDefinitionKey }
        const that = this
 
        getAction(this.url.queryHisTaskList, param)
          .then(res => {
            that.hitaskDataSource = res.result
          })
 
        downFile(this.url.diagramView, imageParam, 'get')
          .then((res => {
            const urlObject = window.URL.createObjectURL(new Blob([res]))
            that.imageSrc = urlObject
          }))
          .catch(err => {
            that.$notification.error({
              message: '消息',
              description: res.message
            })
          })
      },
 
      /**
       * 获取待办记录的基本信息
       * @param record 待办记录信息
       */
      getBasicInformation(record) {
        this.spinning = true
        const that = this
        const param = { id: record.dataId }
        this.tableRowRecord = {}
        this.activeTabKey = '1'
        getAction(this.url.queryBomDataById, param)
          .then((res => {
            if (res.success) {
              that.tableRowRecord = Object.assign({}, res.result, {
                isUseSpare: res.result.isUseSpare === null ? 0 : res.result.isUseSpare,
                imageFiles: JSON.parse(res.result.imageFiles),
                reportImageFiles: JSON.parse(res.result.reportImageFiles)
              })
              console.log('this.tableRowRecord----->', that.tableRowRecord)
            }
          }))
          .finally(() => {
            that.spinning = false
          })
      },
 
      submitForm() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            const { isUseSpare, faultReason, repairDescription, sparePartDescription, imageFiles, equipmentId } = that.tableRowRecord
            const { dataId, id, procInstId, taskDefKey, variables } = that.selectShenpiData
 
            const flowTaskVo = {}
            flowTaskVo.isUseSpare = isUseSpare
            flowTaskVo.faultReason = faultReason
            flowTaskVo.repairDescription = repairDescription
            flowTaskVo.sparePartDescription = sparePartDescription
            flowTaskVo.imageFilesResult = imageFiles
            flowTaskVo.equipmentId = equipmentId
            flowTaskVo.id = dataId
            flowTaskVo.dataId = dataId
            flowTaskVo.taskId = id
            flowTaskVo.instanceId = procInstId
            flowTaskVo.targetKey = taskDefKey
            flowTaskVo.values = variables
            console.log('表单提交数据', flowTaskVo)
            httpAction(this.url.approve, flowTaskVo, 'post')
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.$emit('ok')
                } else {
                  that.$message.warning(res.message)
                }
              }).finally(() => {
              that.confirmLoading = false
            })
          } else {
            return false
          }
        })
      },
 
      handCancel() {
        this.visible = false
        if (this.$refs.form) this.$refs.form.clearValidate()
      }
    }
  }
</script>