cuilei
5 天以前 2094d14b908959353558ef5af1a85a8322031c58
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
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
 
    <a-spin :spinning="spinning">
      <a-form-model ref="form" :model="model" :rules="validatorRules" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-model-item prop="standardCode" label="工单号">
              <a-input placeholder="工单号自动生成" v-model="model.orderNum" readOnly/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item prop="equipmentId" label="设备编号">
              <a-select placeholder="请选择设备" v-model="model.equipmentId" :options="inspectionEquipmentOptions" @change="handleEquipmentChange"></a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item prop="standardName" label="标准名称">
              <a-input placeholder="选择设备后自动带出" readOnly v-model="model.standardName"/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-model-item prop="standardCode" label="标准编码">
              <a-input placeholder="选择设备后自动带出" readOnly v-model="model.standardCode"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="保养周期">
              <a-input placeholder="选择设备后自动带出" v-model="model.maintenancePeriod" readOnly/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <vxe-table
            ref="table"
            border
            show-overflow
            show-header-overflow
            :scroll-x="{enabled: true}"
            :data="dataSource"
            :edit-config="{trigger: 'click', mode: 'cell'}"
            :edit-rules="editRules"
          >
            <vxe-table-column title="序号" field="itemCode" width="50" align="center"></vxe-table-column>
            <vxe-table-column title="部位" field="itemPart" align="center"></vxe-table-column>
            <vxe-table-column title="保养项目" field="itemName" align="center"></vxe-table-column>
            <vxe-table-column title="检查标准或要求" field="itemDemand" align="center"></vxe-table-column>
            <vxe-table-column title="保养要求" field="itemDemandAlias" align="center"></vxe-table-column>
            <vxe-table-column title="检查方法" field="checkMethod" align="center"></vxe-table-column>
            <vxe-table-column title="点检结果" field="inspectionResult" align="center"
                              :edit-render="{name: '$select', options: inspectionResultOptions}">
              <template #default="{ row }">
                <span v-if="row.inspectionResult">{{ getInspectionResultLabel(row.inspectionResult) }}</span>
                <span v-else class="placeholder-text">请选择点检结果</span>
              </template>
            </vxe-table-column>
            <vxe-table-column title="异常描述" field="exceptionDescription" align="center"
                              :edit-render="{name: '$input', placeholder: '请输入异常描述'}">
              <template #default="{ row }">
                <span v-if="row.inspectionResult === '2' && !row.exceptionDescription" class="placeholder-text">请输入异常描述</span>
                <span v-else-if="row.exceptionDescription">{{ row.exceptionDescription }}</span>
              </template>
              <template #edit="{ row }">
                <vxe-input v-if="row.inspectionResult === '2'" v-model="row.exceptionDescription" placeholder="请输入异常描述" />
              </template>
            </vxe-table-column>
          </vxe-table>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>
 
<script>
import { postAction, getAction, putAction } from '@api/manage'
 
export default {
  name: 'MesProductionWorkOrderReportModal',
  data () {
    return {
      title: '设备点检',
      width: 1200,
      visible: false,
      loading: false,
      disableSubmit: false,
      model: {},
      spinning: false,
      validatorRules: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 },
      },
      inspectionResultOptions: [
        {
          label: '正常',
          value: '1'
        },
        {
          label: '异常',
          value: '2'
        }
      ],
      dataSource: [],
      editRules: {
        inspectionResult: [
          { required: true, message: '检查结果必须选择' }
        ],
        exceptionDescription: [
          {
            required: true,
            message: '异常描述不能为空',
            validator: ({ cellValue, row }) => {
              // 当点检结果为异常时,异常描述必填
              if (row.inspectionResult === '2') {
                return cellValue && cellValue.trim() !== '' ? true : new Error('异常描述必须填写');
              }
              return true;
            }
          }
        ]
      },
      url: {
        report: '/mesworkreporting/mesWorkReporting/add',
        listInspectionEquipment: '/eam/equipment/listProductionLineInspectionEquipment',
        queryByEquipmentId: '/eam/maintenanceStandard/queryByEquipmentId',
        addInspectionOrder: '/eam/eamInspectionOrder/add',
        updateOrderInspectionStatus: '/mes/mesProductionWorkOrder/edit'
      },
      inspectionEquipmentOptions: [],
      workOrderId: null
    }
  },
  computed: {
    formDisabled(){
      return this.disabled
    }
  },
  methods: {
    getInspectionResultLabel(value) {
      const option = this.inspectionResultOptions.find(item => item.value === value);
      return option ? option.label : value;
    },
    inspect (record) {
      this.resetFormData()
      this.workOrderId = record.id
      getAction(this.url.listInspectionEquipment, {orderId: record.id}).then(res => {
        if (res.success) {
          this.inspectionEquipmentOptions = res.result
        }
      })
      this.visible = true
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleEquipmentChange(id) {
      getAction(this.url.queryByEquipmentId, {equipmentId: id}).then(res => {
        if (res.success) {
          console.log(res.result)
          this.model = {
            ...this.model,
            standardId: res.result.id,
            standardName: res.result.standardName,
            standardCode: res.result.standardCode,
            maintenancePeriod: res.result.maintenancePeriod
          }
          this.dataSource = res.result.maintenanceStandardDetailList
        }
      })
    },
    handleOk () {
      this.$refs.table.validate((valid) => {
        if (valid) {
          this.$message.error("请完成所有必填信息后再提交!")
        } else {
          let tableData = this.$refs.table.getTableData().fullData
          const data = {
            ...this.model,
            workOrderId: this.workOrderId,
            tableDetailList: tableData
          }
          postAction(this.url.addInspectionOrder, data).then(res=> {
            if (res.success) {
              this.$message.success(res.message)
              getAction(this.url.listInspectionEquipment, {orderId: this.workOrderId}).then(res => {
                if (res.success) {
                  if (res.result && res.result.length > 0) {
                    // 还有设备需要点检,清空表单和表格数据
                    this.inspectionEquipmentOptions = res.result
                    this.resetFormData()
                  } else {
                    // 没有需要点检的设备,更新点检状态
                    putAction(this.url.updateOrderInspectionStatus, {id: this.workOrderId, equipmentInspectionFlag: '1'}).then(res => {
                      if (res.success) {
                        this.$message.success('设备点检完成')
                        this.submitCallback()
                      } else {
                        this.$message.warning(res.message)
                      }
                    })
                    this.submitCallback()
                  }
                }
              })
            } else {
              this.$message.warning(res.message)
            }
          })
        }
      })
    },
    resetFormData() {
      this.$refs.form.resetFields()
      this.model = {}
      this.dataSource = []
    },
    submitCallback(){
      this.$emit('ok');
      this.visible = false;
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>
 
<style scoped>
 
.placeholder-text {
  color: #999;
  font-style: italic;
}
 
</style>