车间能级提升-智能设备管理系统
baoshiwei
2025-06-27 88e10f5656a0ad5530a9e37892fb327153d9dc8a
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
<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: { navigationBarTitleText: '工单明细', navigationStyle: 'custom' },
}
</route>
<template>
  <view class="bg-base container" safeAreaInsetTopBottom>
    <wd-navbar
      title="保养工单"
      left-arrow
      @click-left="goBack"
      right-text="提交"
      @click-right="handleClickRight"
      custom-style="background: #4D80F0;"
      safeAreaInsetTop
    >
      <template #right>
        <text v-if="isLineOrRepair()" class="text-white">提交</text>
        <text v-else-if="isLeader()" class="text-white">验证</text>
      </template>
    </wd-navbar>
    <wd-form ref="form" :model="order" :rules="rules">
      <wd-cell-group custom-class="group" title="设备信息" border>
        <wd-cell title="设备名称" title-width="200rpx" is-link>
          <text>{{ order?.equName }}</text>
        </wd-cell>
        <wd-cell title="资产编号" title-width="200rpx" is-link>
          <text>{{ order?.assetNo }}</text>
        </wd-cell>
      </wd-cell-group>
 
      <wd-cell-group custom-class="mt-2" title="保养信息" border>
        <wd-cell title="保养单号" title-width="200rpx" is-link>
          <text>{{ order?.maintCode }}</text>
        </wd-cell>
        <wd-cell title="保养项" title-width="200rpx" is-link>
          <text>{{ order?.maintName }}</text>
        </wd-cell>
        <wd-cell title="计划保养日期" title-width="200rpx" is-link>
          <text>{{ order?.planTime }}</text>
        </wd-cell>
        <wd-cell title="保养开始时间" title-width="200rpx" is-link>
          <text>{{ order?.startTime }}</text>
        </wd-cell>
        <wd-cell title="保养完成时间" title-width="200rpx" is-link>
          <text>{{ order?.endTime }}</text>
        </wd-cell>
 
        <wd-textarea
          label="工作描述"
          label-width="200rpx"
          type="textarea"
          v-model="order.maintDesc"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入工作描述"
          clearable
        />
        <wd-cell title="保养图片" title-width="200rpx" prop="fileList">
          <wd-upload
            :file-list="fileList"
            @change="handleFileChange"
          ></wd-upload>
        </wd-cell>
        <wd-textarea
          label="备注"
          label-width="200rpx"
          type="textarea"
          v-model="order.remark"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入备注"
          clearable
        />
      </wd-cell-group>
      <view class="h-[2px] w-full bg-base"></view>
      <!--是否显示管理员验证按钮 (工单状态为2-待验证  且登录人role-leader管理员角色)-->
      <wd-cell
        title="验证通过(管理员)"
        title-width="200px"
        v-if="order.status === '2' && isLeader()"
      >
        <view style="text-align: right">
          <wd-switch v-model="isVerify" />
        </view>
      </wd-cell>
 
      <!--是否显示操作工保养完成 (工单状态为1-保养中 且登录人role-操作工角色)-->
      <wd-cell
        title="保养完成(操作工)"
        title-width="200px"
        v-if="order.status === '1' && isLineOrRepair()"
      >
        <view style="text-align: right">
          <wd-switch v-model="isFinish" />
        </view>
      </wd-cell>
    </wd-form>
    <view class="h-[100rpx]"></view>
  </view>
</template>
 
<script setup lang="ts">
import { getMaintOrder, updateMaintOrder } from '@/service/maint'
import { reactive, onMounted } from 'vue'
import { FormRules } from 'wot-design-uni/components/wd-form/types'
import { useToast, useMessage } from 'wot-design-uni'
import { isLeader, isLineOrRepair } from '@/utils/RoleUtils'
const toast = useToast()
const message = useMessage()
 
const fileList = ref<[]>()
 
// 管理员验是否通过
const isVerify = ref(false)
// 操作工保养是完成
const isFinish = ref(false)
 
interface MaintOrder {
  id: string
  equName: string
  assetNo: string
  status: string
  maintCode: string
  maintName: string
  planTime: string
  startTime: string
  endTime?: string
  maintDesc: string
  remark: string
  picture: string
}
 
const order = reactive<MaintOrder>({
  id: '',
  equName: '',
  assetNo: '',
  status: '',
  maintCode: '',
  maintName: '',
  planTime: '',
  startTime: '',
  endTime: '',
  maintDesc: '',
  remark: '',
})
 
const rules: FormRules = {
  startTime: [
    {
      required: true,
      message: '请选择保养开始时间',
    },
  ],
  endTime: [
    {
      required: true,
      message: '请选择保养结束时间',
    },
  ],
  maintDesc: [
    {
      required: true,
      message: '请输入工作描述',
    },
  ],
}
 
function handleFileChange({ fileList }) {}
 
function initMaintOrder(id: any) {
  getMaintOrder(id)
    .then((res: any) => {
      Object.assign(order, res)
    })
    .catch((res) => {})
}
 
function updateOrder(data: any, resolve: any) {
  updateMaintOrder(data)
    .then((res: any) => {
      resolve(true)
      toastSucces()
      uni.$emit('maint-order-refresh')
    })
    .catch((res) => {
      console.error(res)
    })
}
function toastSucces() {
  toast.success('操作成功')
}
 
function handleSubmit(data: any) {
  message
    .confirm({
      msg: '确定提交?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        updateOrder(data, resolve)
      },
    })
    .then(() => {
      goBack()
    })
    .catch((error) => {
      console.log(error)
    })
}
 
const goBack = () => {
  uni.navigateBack()
}
function handleClickRight() {
  // 管理员角色 且待验证状态
  if (isLeader()) {
    switch (order.status) {
      case '0':
      case '1':
        toast.warning('当前工单等待操作工保养状态,不可操作')
        break
      case '2':
        // 勾选验证,可提交
        if (isVerify.value) {
          // 修改工单状态为已完成
          const data: any = Object.assign({}, { id: order.id, status: order.status })
          data.status = '3'
          handleSubmit(data)
        } else {
          toast.warning('请选择是否验证通过')
        }
        break
      case '3':
        toast.warning('当前工单完成状态,不可操作')
        break
    }
  } else if (isLineOrRepair()) {
    switch (order.status) {
      case '0':
        break
      case '1':
        {
          const data = Object.assign({}, order)
          // 勾选工单完成,改变状态
          if (isFinish.value) {
            // 修改工单状态为待验证
            data.status = '2'
          }
          handleSubmit(data)
        }
        break
      case '2':
        toast.warning('当前工单等待管理验证状态,不可操作')
        break
      case '3':
        toast.warning('当前工单完成状态,不可操作')
        break
    }
  }
}
 
onMounted(() => {})
onLoad((options) => {
  initMaintOrder(options.id)
})
</script>
 
<style scoped lang="scss">
.container {
  height: 100vh;
}
</style>