车间能级提升-智能设备管理系统
baoshiwei
2025-06-12 bab490d2da009c1a23b352b3b964e0c2dd06a0b3
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
<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: {
    navigationBarTitleText: '维修明细',
    'app-plus': {
      titleNView: {
        buttons: [
          {
            text: '提交',
            fontSize: '14px',
            color: '#FFFFFF',
          },
          {
            text: '保存',
            fontSize: '14px',
            color: '#FFFFFF',
          },
        ],
      },
    },
  },
}
</route>
<template>
  <view class="bg-base container" safeAreaInsetTopBottom>
    <wd-form ref="form" :model="repairRes" :rules="rules">
      <wd-cell-group custom-class="group" title="报修信息" border>
        <wd-cell title="故障类型" title-width="200rpx" is-link>
          <text>{{ reqType?.dictLabel }}</text>
        </wd-cell>
 
        <wd-textarea
          label="报修描述"
          label-width="200rpx"
          type="textarea"
          v-model="repairRes.reqDesc"
          auto-height
          readonly
        />
      </wd-cell-group>
 
      <wd-cell-group
        v-if="repairRes?.reqType === '1'"
        custom-class="mt-2"
        title="设备信息"
        use-slot
        border
      >
        <wd-cell title="设备名称" title-width="200rpx" is-link>
          <text>{{ repairRes?.equName }}</text>
        </wd-cell>
        <wd-cell title="资产编号" title-width="200rpx" is-link>
          <text>{{ repairRes?.assetNo }}</text>
        </wd-cell>
      </wd-cell-group>
 
      <wd-cell-group
        v-if="repairRes?.reqType === '2'"
        custom-class="mt-2"
        title="工具信息"
        use-slot
        border
      >
        <wd-cell title="工具名称" title-width="200rpx" is-link>
          <text>{{ repairRes?.fixtureName }}</text>
        </wd-cell>
        <wd-cell title="资产编号" title-width="200rpx" is-link>
          <text>{{ repairRes?.assetNo }}</text>
        </wd-cell>
      </wd-cell-group>
 
      <wd-cell-group custom-class="mt-2" title="维修信息" use-slot border>
        <wd-cell title="故障类别" title-width="200rpx" prop="faultType">
          <wd-radio-group v-model="repairRes.faultType" inline  shape="dot"> >
            <wd-radio v-for="item in faultList" :value="item.dictValue">{{item.dictLabel}}</wd-radio>
          </wd-radio-group>
        </wd-cell>
        <wd-textarea
          label="原因分析"
          label-width="200rpx"
          type="textarea"
          v-model="repairRes.resReason"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入原因分析"
          clearable
        />
 
        <wd-textarea
          label="处理措施"
          label-width="200rpx"
          type="textarea"
          v-model="repairRes.resHandle"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入处理措施"
          clearable
        />
 
        <wd-textarea
          label="预防措施"
          label-width="200rpx"
          type="textarea"
          v-model="repairRes.resPrevent"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入预防措施"
          clearable
        />
 
        <wd-textarea
          label="备注"
          label-width="200rpx"
          type="textarea"
          v-model="repairRes.remark"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入备注"
          clearable
        />
      </wd-cell-group>
      <wd-cell-group custom-class="mt-2" title="备件信息" use-slot border>
      <!-- 备件信息录入区域 -->
      <view v-if="repairRes.spareParts && repairRes.spareParts.length > 0" class="mt-2">
        <view
          v-for="(part, partIndex) in repairRes.spareParts"
          :key="partIndex"
          class="flex justify-between mt-1"
        >
          <wd-input
            v-model="part.name"
            label="名称:"
            label-width="100rpx"
            placeholder="备件名称"
 
 
          />
          <wd-input
            v-model="part.quantity"
            label="数量:"
            label-width="100rpx"
            placeholder="数量" type="number" :maxlength="5" />
        </view>
      </view>
      <!-- 维修说明区域 -->
      <view class="mt-2 flex justify-end">
        <wd-button type="success" style="margin: 20px" @click.stop="addSparePart()">
          添加备件
        </wd-button>
      </view>
      <view class="h-[2px] w-full bg-base"></view>
      </wd-cell-group>
    </wd-form>
<!--    <wd-button style="margin: 20px" block @click="handleClickRight">提交</wd-button>-->
    <view class="h-[20px] w-full bg-base"></view>
  </view>
 
  <!-- 备件选择弹出层 -->
  <wd-popup v-model="showSparePopup" position="bottom" height="33.33vh">
    <view class="flex justify-between p-2 bg-white">
      <wd-button type="text" @click="closeSparePopup">取消</wd-button>
      <wd-button type="text" @click="addOtherSparePart">其他</wd-button>
 
    </view>
    <wd-input
      v-model="searchKeyword"
      placeholder="请输入备件名称或型号"
      clearable
      @input="filterSpareParts"
    />
    <view class="p-2">
      <view
        v-for="(part, index) in sparePartsList"
        :key="index"
        class="flex justify-between items-center p-2 border-b"
        @click="selectFilteredSparePart(part)"
      >
        <text>{{ part.name }} ({{ part.code }})</text>
        <text>剩余: {{ part.actualStock }}</text>
      </view>
    </view>
  </wd-popup>
</template>
 
<script setup lang="ts">
import { getRepairRes, updateRepairRes } from '@/service/repair'
import { RepairResVO } from '@/service/repair.d'
import { FormRules } from 'wot-design-uni/components/wd-form/types'
import { useToast, useMessage } from 'wot-design-uni'
import { isEquAdmin, isLeader, isLineOrRepair, isRepair } from "@/utils/RoleUtils";
import { DICT_REPAIR_FAULT_TYPE, DICT_REPAIR_REQ_TYPE, getDictInfo } from "@/service/dict";
import { formatDate } from '@/utils/DateUtils'
const toast = useToast()
const message = useMessage()
const showSparePopup = ref(false)
import { getSpareList } from '@/service/spare'
import { ref } from "vue";
const fileList = ref<[]>()
const selectedPartIndex = ref(-1)
const sparePartsList = ref([])
const searchKeyword = ref('')
// 报修单类型
const reqTypeList = ref<any>([])
// 故障类别
const faultList = ref<any>([])
const repairRes = reactive<RepairResVO>({
  id: '',
  resCode: '',
  reqType: '',
  reqDesc: '',
  equName: '',
  assetNo: '',
  fixtureName: '',
  resReason: '',
  status: '',
  resHandle: '',
  resPrevent: '',
  remark: '',
})
 
const rules: FormRules = {
  startTime: [
    {
      required: true,
      message: '请选择保养开始时间',
    },
  ],
}
 
function filterSpareParts() {
  if (!searchKeyword.value) {
    loadSpareParts()
  } else {
    loadSpareParts(searchKeyword.value)
  }
}
// 备件选择相关逻辑
function addSparePart() {
  // if (!item.spareParts) {
  //   item.spareParts = []
  // }
  repairRes.spareParts.value = []
 
  selectSparePart()
}
 
function selectSparePart(item: any) {
  showSparePopup.value = true
 
  loadSpareParts()
}
 
function loadSpareParts(value?: string) {
  getSpareList({ name: value, pageNum: 1, pageSize: 10 }).then((res: any) => {
    sparePartsList.value = res.rows
 
  })
}
 
function selectFilteredSparePart(part: any) {
  repairRes.spareParts.value.push({
    id: part.id,
    name: part.name,
    quantity: '',
  })
  closeSparePopup()
}
function addOtherSparePart() {
  repairRes.spareParts.value.push({
    id:  '',
    name: '',
    quantity: '',
  })
  closeSparePopup();
}
 
function closeSparePopup() {
  showSparePopup.value = false
  selectedPartIndex.value = -1
  searchKeyword.value = ''
}
 
function handleFileChange({ fileList }) {}
 
function initRepairRes(id: any) {
  getRepairRes(id)
    .then((res: any) => {
      Object.assign(repairRes, res)
    })
    .catch((res) => {})
}
 
async function initData(options: any) {
  initRepairRes(options.id)
  const reqList = await getDictInfo(DICT_REPAIR_REQ_TYPE)
  reqTypeList.value = reqList
  const fList = await getDictInfo(DICT_REPAIR_FAULT_TYPE)
  faultList.value = fList
}
 
function hanldeUpdateRepairRes(data: any, resolve: any) {
  updateRepairRes(data)
    .then((res: any) => {
      resolve(true)
      toastSucces()
      uni.$emit('res-list-refresh')
      uni.navigateBack()
    })
    .catch((res) => {
      console.error(res)
    })
}
function toastSucces() {
  toast.success('操作成功')
}
 
function handleClickRight(data: any) {
  message
    .confirm({
      msg: '确定提交?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        hanldeUpdateRepairRes(data, resolve)
      },
    })
    .then(() => {})
    .catch((error) => {
      console.log(error)
    })
}
 
onNavigationBarButtonTap((e) => {
  if (e.index === 0) {
    // 管理员角色
    if (isRepair() || isEquAdmin()) {
      switch (repairRes.status) {
        // 已接单
        case '1':
          break
        // 维修中
        case '2':
          {
            const data = Object.assign({}, repairRes)
            // 提交修改状态为完成
            data.status = '3'
            // 设置维修完成时间
            data.endTime = formatDate(new Date())
            handleClickRight(data)
          }
          break
        // 已完成
        case '3':
          toast.warning('当前维修工单完成状态,不可操作')
          break
      }
    }
  } else if (e.index === 1) {
    if (isRepair() || isEquAdmin()) {
      switch (repairRes.status) {
        // 已接单
        case '1':
          break
        // 维修中
        case '2':
          {
            const data = Object.assign({}, repairRes)
            data.status = '2'
            // 仅保存不修改状态
            handleClickRight(data)
          }
          break
        // 已完成
        case '3':
          toast.warning('当前维修工单完成状态,不可操作')
          break
      }
    }
  }
})
 
const reqType = computed(() =>
  reqTypeList.value.find((item) => item.dictValue === repairRes.reqType),
)
 
onMounted(() => {})
onLoad((options) => {
  initData(options)
})
</script>
 
<style scoped lang="scss">
.container {
}
</style>