车间能级提升-智能设备管理系统
zhuguifei
2025-04-27 d7862b2890b68743ec9c4fc05800bb23ec9b412e
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
<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: {
    navigationBarTitleText: '保养工单',
    'app-plus': {
      titleNView: {
        buttons: [
          {
            text: '提交',
            fontSize: '14px',
            color: '#FFFFFF',
          },
          {
            text: '',
            fontSize: '24px',
            color: '#FFFFFF',
          },
        ],
      },
    },
  },
}
</route>
 
<template>
  <z-paging
    ref="paging"
    v-model="dataList"
    @query="queryList"
    :auto="false"
    show-refresher-update-time
  >
    <template #top>
      <wd-cell>
        <template #title>
          <text class="text-color-gray">设备</text>
        </template>
      </wd-cell>
      <view class="h-[2px] w-full bg-base"></view>
      <wd-card type="rectangle">
        <template #title>
          <view class="flex justify-between">
            <view class="flex items-center menu-title-box">
              <view class="menu-indicator"></view>
              <view class="ml-1 text-sm align-center">{{ maintSt.equName }}</view>
              <view class="text-color-gray ml-2 text-mini">{{ maintSt.assetNo }}</view>
            </view>
 
            <view class="flex items-center">
              <text class="text-color-gray text-mini">{{ maintSt.planTime }}</text>
            </view>
          </view>
        </template>
        <view class="flex h-[140rpx]" items-center>
          <image class="slot-img text-center" src="/static/images/camera.png" />
          <view class="flex-1">
            <view class="text-color-gray text-xs mt-1 flex">
              <text class="mr-3">工单总数: {{ maintSt.orderCount }}</text>
              |
              <text class="mx-3">已完成: {{ maintSt.wcCount }}</text>
            </view>
            <view class="text-color-gray text-xs mt-2 flex">
              <text class="mr-3">待保养: {{ maintSt.dbyCount }}</text>
              |
              <text class="mx-3">保养中: {{ maintSt.byCount }}</text>
              |
              <text class="ml-3">待验证: {{ maintSt.dyzCount }}</text>
            </view>
            <view class="text-color-gray text-xs mt-2 flex">
              <text>状态:</text>
              <template v-if="maintSt.status === '1'">
                <wd-icon class="icon-color-success" name="check-outline" size="34rpx"></wd-icon>
                <text class="ml-1">已完成</text>
              </template>
              <template v-else>
                <wd-icon class="icon-color-base" name="detection" size="40rpx"></wd-icon>
                <text class="ml-1">进行中</text>
              </template>
            </view>
 
            <view class="text-color-gray text-xs mt-2 flex">
              创建时间: {{ maintSt.createTime }}
            </view>
          </view>
        </view>
      </wd-card>
    </template>
 
    <view class="bg-base">
      <view class="w-full h-[24rpx]"></view>
      <wd-cell class="mb-[2px]">
        <template #title>
          <text class="text-color-gray">保养项</text>
        </template>
      </wd-cell>
 
      <wd-card type="rectangle" v-for="(item, index) in dataList" :key="item.id">
        <template #title>
          <view class="flex justify-between">
            <view class="flex items-center menu-title-box">
              <view class="menu-indicator"></view>
              <view class="ml-1 text-sm align-center w-[50%]">
                <wd-text :text="item.maintName" :lines="1"></wd-text>
              </view>
              <view class="text-color-gray ml-2 text-mini">{{ item.maintCode }}</view>
            </view>
 
            <view class="flex items-center w-[20%] justify-end">
              <text class="text-color-gray text-mini">
                {{ item?.planTime }}
              </text>
            </view>
          </view>
        </template>
        <view class="flex h-[140rpx]" items-center>
          <image class="slot-img text-center" src="/static/ico/ico-platform.png" />
          <view class="flex-1 text-color-gray text-xs flex-row">
            <view class="mr-3 mt-2">计划保养日期: {{ item.planTime }}</view>
            <view class="mr-3 mt-2">保养开始时间: {{ item.startTime }}</view>
            <view class="mr-3 mt-2">保养结束时间: {{ item.endTime }}</view>
            <view class="text-color-gray text-xs mt-2 flex">
              <text>状态:</text>
              <template v-if="item.status === '0'">
                <wd-icon class="icon-color-warning" name="books" size="34rpx"></wd-icon>
                <text class="ml-1">待保养</text>
              </template>
              <template v-else-if="item.status === '1'">
                <wd-icon class="icon-color-base" name="books" size="34rpx"></wd-icon>
                <text class="ml-1">保养中</text>
              </template>
              <template v-else-if="item.status === '2'">
                <wd-icon class="icon-color-purple" name="books" size="34rpx"></wd-icon>
                <text class="ml-1">待验证</text>
              </template>
              <template v-else-if="item.status === '3'">
                <wd-icon class="icon-color-success" name="check-outline" size="34rpx"></wd-icon>
                <text class="ml-1">已完成</text>
              </template>
              <text class="mx-3">|</text>
              <wd-icon class="icon-color-base" name="camera" size="30rpx"></wd-icon>
              <text class="ml-1">{{ item.maintUserName }}</text>
            </view>
          </view>
          <!--操作工或维修工角色-->
          <template v-if="isOperatorOrRepair()">
            <view class="flex flex-col justify-between"  v-if="item.status === '0'">
              <wd-button
                size="small"
                icon="edit-outline"
                @click.stop="handleStartMaint(item)"
              >
                开始保养
              </wd-button>
 
              <wd-button
                class="mt-3"
                size="small"
                icon="edit-outline"
                @click.stop="handleMaintFinish(item)"
              >
                一键保养
              </wd-button>
            </view>
            <wd-button
              v-if="item.status === '1'"
              size="small"
              icon="edit-outline"
              @click.stop="itemClick(item)"
            >
              保养中
            </wd-button>
 
            <wd-button
              v-if="item.status === '2'"
              size="small"
              icon="edit-outline"
              @click.stop="itemClick(item)"
            >
              待验证
            </wd-button>
 
            <wd-button
              v-if="item.status === '3'"
              size="small"
              icon="check-outline"
              @click.stop="itemClick(item)"
            >
              已完成
            </wd-button>
          </template>
 
          <!--管理员角色-->
          <template v-else-if="isLeader()">
            <wd-button v-if="item.status === '0'" size="small" icon="warn-bold" disabled>
              待保养
            </wd-button>
            <wd-button v-if="item.status === '1'" size="small" icon="warn-bold" disabled>
              保养中
            </wd-button>
 
            <wd-button
              v-if="item.status === '2'"
              size="small"
              icon="edit-outline"
              @click.stop="itemClick(item)"
            >
              待验证
            </wd-button>
 
            <wd-button
              v-if="item.status === '3'"
              size="small"
              icon="check-outline"
              @click.stop="itemClick(item)"
            >
              已完成
            </wd-button>
          </template>
        </view>
      </wd-card>
      <wd-cell>
        <template #title>
          <text class="text-color-gray">其他信息</text>
        </template>
      </wd-cell>
      <view class="h-[2px] w-full bg-base"></view>
      <wd-textarea
        label="特记事项"
        label-width="200rpx"
        type="textarea"
        v-model="maintSt.specialNote"
        auto-height
        :maxlength="200"
        show-word-limit
        placeholder="请输入特记事项"
        clearable
      />
    </view>
  </z-paging>
</template>
<script setup lang="ts">
import type { MaintStVO } from '@/service/maint.d'
import { getMaintSt, getMaintStOrderList, updateMaintOrder, updateMaintSt } from '@/service/maint'
import { ref, reactive } from 'vue'
import { useToast, useMessage } from 'wot-design-uni'
import { isLeader, isOperatorOrRepair } from '@/utils/RoleUtils'
import { formatDate } from '@/utils/DateUtils'
const message = useMessage()
const toast = useToast()
 
const paging = ref(null)
const dataList = ref([])
const maintStId = ref('')
 
interface QueryParams {
  pageNum: number
  pageSize: number
  maintCode: string
  status?: string
}
 
const maintSt = reactive<MaintStVO>({
  id: '',
  equName: '',
  assetNo: '',
  planTime: '',
  createTime: '',
  orderCount: null,
  wcCount: null,
  dbyCount: null,
  byCount: null,
  dyzCount: null,
  specialNote: '',
})
const queryList = (pageNum?: number, pageSize?: number) => {
  const params: QueryParams = {
    pageNum,
    pageSize,
    maintCode: maintCode.value,
  }
  getMaintStOrderList(params)
    .then((res: any) => {
      // 请勿在网络请求回调中给dataList赋值!!只需要调用complete就可以了
      paging.value.completeByTotal(res.rows, res.total)
    })
    .catch((res) => {
      // 如果请求失败写paging.value.complete(false),会自动展示错误页面
      // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
      // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
      paging.value.complete(false)
    })
}
function initMaintSt(id: any) {
  getMaintSt(id)
    .then((res: any) => {
      Object.assign(maintSt, res)
      paging.value.reload()
    })
    .catch((res) => {
      console.error(res)
      toast.error(res?.data?.msg || '请求失败')
    })
}
 
function itemClick(item) {
  goToOrderDetail(item)
}
 
function goToOrderDetail(item) {
  uni.navigateTo({
    url: `/pages/maint/order-detail?id=${item.id}`,
  })
}
 
/**
 * 开始保养
 * @param item
 */
function handleStartMaint(item) {
  // 确认开始修改状态为1-保养中
  const data = Object.assign({}, item)
  data.status = '1'
  message
    .confirm({
      msg: '确定开始保养?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        updateOrder(data, resolve)
      },
    })
    .then(() => {})
    .catch((error) => {
      console.log(error)
    })
}
 
 
/**
 * 一键保养
 * @param item
 */
function handleMaintFinish(item) {
  // 一键保养
  const data = Object.assign({}, item)
  data.status = '2'
  data.startTime = formatDate(new Date())
  data.endTime = formatDate(new Date())
  message
    .confirm({
      msg: '确定使用一键保养?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        updateOrder(data, resolve)
      },
    })
    .then(() => {})
    .catch((error) => {
      console.log(error)
    })
}
 
/**
 * 更新保养工单
 * @param item
 * @param resolve
 */
function updateOrder(data: any, resolve: any) {
 
  updateMaintOrder(data)
    .then((res: any) => {
      resolve(true)
      if (res?.code === 200) {
        reloadData()
        // 保养状态才需要跳转
        if(data?.status === '1'){
          goToOrderDetail(data)
        }
      }
    })
    .catch((res) => {
      console.error(res)
    })
}
 
function handleUpdateMaintSt() {
  if (maintSt.orderCount !== maintSt.wcCount) {
    toast.info('请先完成所有保养项!')
    return false
  }
 
  const data: any = Object.assign(
    {},
    {
      id: maintSt.id,
      orderCount: maintSt.orderCount,
      wcCount: maintSt.wcCount,
      status: maintSt.status,
      specialNote: maintSt.specialNote,
    },
  )
  if (data.orderCount === data.wcCount) {
    data.status = '1'
  }
  message
    .confirm({
      msg: '确定更新工单汇总数据?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        updateMaintSt(data)
          .then((res: any) => {
            resolve(true)
            if (res?.code === 200) {
              reloadData()
              toastSucces()
            }
          })
          .catch((res) => {
            console.error(res)
          })
      },
    })
    .then(() => {})
    .catch((error) => {
      console.log(error)
    })
}
 
function toastSucces() {
  toast.success('操作成功')
}
 
function reloadData() {
  initMaintSt(maintStId.value)
}
onNavigationBarButtonTap((e) => {
  if (e.index === 0) {
    handleUpdateMaintSt()
  }
})
 
onLoad(() => {
  uni.$on('maint-order-refresh', reloadData)
})
onUnload(() => {
  uni.$off('maint-order-refresh', reloadData)
})
 
/**
 * 查询保养明细需要的code
 */
const maintCode = computed(() => `${maintSt.equId}_${maintSt.planTime}`)
 
onLoad((options) => {
  maintStId.value = options.id
  reloadData()
})
</script>
 
<style scoped lang="scss">
.menu-title-box {
  height: 30rpx;
  line-height: 30rpx;
}
 
.slot-img {
  width: 72rpx;
  height: 72rpx;
  margin-right: 24rpx;
}
 
.text-mini {
  font-size: 22rpx;
}
 
.menu-indicator {
  width: 6rpx;
  height: 22rpx;
  border-radius: 10rpx;
  background-color: $uni-color-primary;
}
 
:deep(.wd-card__footer) {
  padding: 10rpx !important;
}
 
.col-title-box {
}
 
.bg-primary {
  background: $uni-color-primary;
}
 
:deep(.wd-navbar__text) {
  font-size: 26rpx;
  color: white;
}
 
:deep(.wd-icon-arrow-left:before),
:deep(.wd-navbar__title) {
  color: white;
  font-weight: 0;
  font-size: 32rpx;
}
</style>