车间能级提升-智能设备管理系统
baoshiwei
2025-06-14 1efdf8fa2f60cc6d9da42b319540d4c2df4b3e0a
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
<route lang="json5" type="page">
{
  layout: 'default',
  needLogin: true,
  style: { navigationBarTitleText: '添加报修', navigationStyle: 'custom' },
}
</route>
 
<template>
  <view class="bg-base">
    <wd-navbar
      title="添加报修"
      left-arrow
      @click-left="goBack"
      right-text="提交"
      @click-right="handleSubmit"
      custom-style="background: #4D80F0;"
      safeAreaInsetTop
    ></wd-navbar>
    <wd-form ref="form" :model="model">
      <wd-cell-group custom-class="group" title="类型信息" border>
        <wd-picker
          prop="reqType"
          :columns="reqList"
          label-key="dictLabel"
          value-key="dictValue"
          label="报修类型"
          v-model="model.reqType"
          @confirm="handleConfirmReqType"
          :disabled="reqTypeDis"
        />
      </wd-cell-group>
 
      <wd-cell-group
        v-if="model.reqType === '1'"
        custom-class="mt-2"
        title="设备信息"
        use-slot
        border
      >
        <template #value>
          <view class="text-color-gray flex items-center">
            <wd-icon class="icon-color-base" name="scan" size="30rpx"></wd-icon>
            <text class="ml-1">扫设备码添加</text>
          </view>
        </template>
        <wd-input
          @click.stop="handleSelectEqu"
          label="设备名称"
          label-width="200rpx"
          prop="equName"
          readonly
          required
          suffix-icon="arrow-right"
          clearable
          v-model="model.equName"
          placeholder="请选择设备"
        />
      </wd-cell-group>
 
      <wd-cell-group
        v-if="model.reqType === '2'"
        custom-class="mt-2"
        title="工具信息"
        use-slot
        border
      >
        <template #value>
          <view class="text-color-gray flex items-center">
            <wd-icon class="icon-color-base" name="scan" size="30rpx"></wd-icon>
            <text class="ml-1">扫工具码添加</text>
          </view>
        </template>
        <wd-input
          @click.stop="handleSelectFixture"
          label="工具名称"
          label-width="200rpx"
          prop="fixtureName"
          readonly
          required
          suffix-icon="arrow-right"
          clearable
          v-model="model.fixtureName"
          placeholder="请选择工具"
        />
      </wd-cell-group>
 
      <wd-cell-group custom-class="mt-2" title="故障信息" border>
        <wd-input
          v-if="false"
          label="报修单号"
          placeholder="请生成报修单号"
          label-width="200rpx"
          v-model="model.code"
          prop="code"
        >
          <template #suffix>
            <wd-button size="small" icon="edit-outline" @click.stop="handleRepairCode">
              生成
            </wd-button>
          </template>
        </wd-input>
 
        <wd-textarea
          label="报修描述"
          label-width="200rpx"
          type="textarea"
          v-model="model.reqDesc"
          auto-height
          :maxlength="200"
          show-word-limit
          placeholder="请输入报修描述"
          clearable
          prop="reqDesc"
        />
        <wd-cell title="报修图片" title-width="200rpx" prop="fileList">
          <wd-upload
            v-model:file-list="model.fileList"
            :action="VITE_UPLOAD_BASEURL"
            @success="handleUploadSuccess"
          ></wd-upload>
        </wd-cell>
 
        <wd-datetime-picker
          label="发生时间"
          label-width="200rpx"
          placeholder="请选择故障发生时间"
          prop="occTime"
          v-model="occTime"
          @open="openOccTime"
          @confirm="handleOccTimeConfirm"
        />
        <!-- <wd-picker
          :columns="urgencyList"
          label-key="dictLabel"
          value-key="dictValue"
          label="紧急程度"
          v-model="model.urgencyLevel"
          @confirm="handleConfirmUrgencyLevel"
        /> -->
        <wd-cell title="紧急程度" title-width="200rpx" prop="urgencyLevel">
          <wd-radio-group v-model="model.urgencyLevel" inline  shape="dot"> @change="handleConfirmUrgencyLevel">
          <wd-radio v-for="item in urgencyList" :value="item.dictValue">{{item.dictLabel}}</wd-radio>
        </wd-radio-group>
        </wd-cell>
 
      </wd-cell-group>
 
 
      <wd-button style="margin: 20px" block @click="handleSubmit">提交</wd-button>
 
      <!-- <wd-cell-group custom-class="mt-2" title="其他信息" border>
        <wd-picker
          :columns="faultList"
          label-key="dictLabel"
          value-key="dictValue"
          label="故障类别"
          v-model="model.faultType"
          @confirm="handleConfirmFaultType"
        />
        <wd-picker
          :columns="urgencyList"
          label-key="dictLabel"
          value-key="dictValue"
          label="紧急程度"
          v-model="model.urgencyLevel"
          @confirm="handleConfirmUrgencyLevel"
        />
      </wd-cell-group> -->
    </wd-form>
  </view>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { getEnvBaseUploadUrl } from '@/utils'
import { generateCode } from '@/service/utils'
import { addRepairReq } from '@/service/repair'
import { formatDate } from '@/utils/DateUtils'
import { useToast, useMessage } from 'wot-design-uni'
import { useUserStore } from '@/store'
import {
  DICT_REPAIR_FAULT_TYPE,
  DICT_REPAIR_REQ_TYPE,
  DICT_REPAIR_URGENCY_LEVEL,
  getDictInfo,
} from '@/service/dict'
 
const VITE_UPLOAD_BASEURL = `${getEnvBaseUploadUrl()}`
const message = useMessage()
const toast = useToast()
const userStore = useUserStore()
 
/**
 * 其他页面传过来的数据
 * assetNo: 资产编号
 * from: 是否是扫码进来的,如果是扫码进来,只能查询固定设备的数据
 */
interface PageParams {
  equId?: string
  equName?: string
  from?: string
}
 
// 页面参数,上个页面传递过来的参数
const option = reactive<PageParams>({
  equId: '',
  equName: '',
  from: '',
})
 
const reqTypeDis = ref(false)
// 报修类型
const reqList = ref<any>([])
// 故障类别
const faultList = ref<any>([])
// 紧急程度
const urgencyList = ref<any>([])
 
const form = ref()
const occTime = ref(0)
const model = reactive<{
  code: string
  status: string
  reqDesc: string
  occTime: string
  reqTime: string
  reqDept: number | string
  reqUser: number | string
  equId: string
  equName: string
  reqType: string
  faultType: string
  urgencyLevel: string
  fixtureId: string
  fixtureName: string
  fileList: []
}>({
  code: '',
  reqDesc: '',
  status: '',
  occTime: '',
  reqTime: '',
  reqDept: null,
  reqUser: null,
  equId: '',
  equName: '',
  reqType: '',
  faultType: '',
  urgencyLevel: '',
  fixtureId: '',
  fixtureName: '',
  fileList: [],
})
const goBack = () => {
  uni.navigateBack()
}
/**
 * 选择设备
 */
function handleSelectEqu() {
  if (reqTypeDis.value) {
    return false
  }
  uni.navigateTo({
    url: '/pages/equ/equ-list',
    events: {
      // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
      selectEqu: function (data) {
        model.equId = data.data.equId
        model.equName = data.data.equName
      },
    },
    success: function (res) {
      // 通过eventChannel向被打开页面传送数据
      res.eventChannel.emit('OnSelectEqu', { data: '点检页面选择设备' })
    },
  })
}
 
/**
 * 选择工具
 */
function handleSelectFixture() {
  uni.navigateTo({
    url: '/pages/fixture/fixture-list',
    events: {
      // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
      selectFixture: function (data) {
        model.fixtureId = data.data.id
        model.fixtureName = data.data.fixtureName
      },
    },
    success: function (res) {
      // 通过eventChannel向被打开页面传送数据
      res.eventChannel.emit('OnSelectFixture', { data: '添加维修页面选择工具' })
    },
  })
}
 
/**
 * 生成报修编号
 */
async function handleRepairCode() {
  try {
    const code: any = await generateCode('BXD')
    model.code = code
    console.log('生成报修单号:', code)
 
    message
      .confirm({
        msg: '确定提交?',
        title: '提示',
        beforeConfirm: ({ resolve }) => {
          resolve(true)
          handleAddRepairReq()
        },
      })
      .then(() => {})
      .catch((error) => {
        console.log(error)
      })
  } catch (error) {
    console.error('生成报修单号失败:', error)
    toast.error('生成报修单号失败,请检查网络后重试')
  }
}
 
function handleAddRepairReq() {
  // 补充必要字段
  model.status = '0' // 报修后默认状态为待接单
  model.reqTime = formatDate(new Date())
  model.reqDept = userStore?.userInfo?.deptId
  model.reqUser = userStore?.userInfo?.userId
  console.log('model', model)
  const map = model.fileList?.map((file) => file.url)
  console.log('map', map)
  model.faultPicture = map.join(',')
  addRepairReq(model)
    .then((res: any) => {
      if (res?.code === 200) {
        toast.success(res?.msg)
        uni.$emit('list-refresh')
        setTimeout(() => {
          uni.navigateBack()
        }, 1500)
      }
    })
    .catch((res) => {
      console.error('添加报修失败:', res)
      toast.error(res?.data?.msg || '请求失败')
    })
}
 
 
function handleUploadSuccess({ file, fileList }) {
  console.log('handleUploadSuccess', file)
  // 判断 file.response是不是 对象,不是对象将json字符串转换为对象
  if (typeof file.response === 'string') {
    file.response = JSON.parse(file.response)
    console.log('file.response', file.response)
    file.ossId = file.response.data.ossId
    file.url = file.response.data.url
  }
}
 
function checkData() {
  if (!model.reqType) {
    toast.error('请选择报修类型')
    return false
  }
  if (model.reqType === '1' && !model.equId) {
    toast.error('请选择报修设备')
    return false
  }
  if (model.reqType === '2' && !model.fixtureId) {
    toast.error('请选择报修工具')
    return false
  }
  if (!model.occTime) {
    toast.error('请选发生时间')
    return false
  }
  return true
}
 
function handleSubmit() {
  if (!checkData()) {
    return false
  }
  handleRepairCode()
}
 
/**
 * 打开发生时间 时间选择器
 */
function openOccTime() {
  occTime.value = Date.now()
  console.log('openOccTime', occTime)
  model.occTime = formatDate(new Date(occTime.value))
}
/**
 * 确认选择发生时间
 */
function handleOccTimeConfirm({ value }) {
  console.log('handleOccTimeConfirm', value)
  model.occTime = formatDate(new Date(value))
}
 
/**
 * 选择报修类型
 */
function handleConfirmReqType({ value }) {}
 
/**
 * 选择故障类别
 */
function handleConfirmFaultType({ value }) {}
 
/**
 * 选择紧急程度
 */
function handleConfirmUrgencyLevel({ value }) {}
 
async function initData() {
  const reqTypeList = await getDictInfo(DICT_REPAIR_REQ_TYPE)
  reqList.value = reqTypeList
 
  const fList = await getDictInfo(DICT_REPAIR_FAULT_TYPE)
  faultList.value = fList
 
  const uList = await getDictInfo(DICT_REPAIR_URGENCY_LEVEL)
  urgencyList.value = uList
}
 
onLoad((options) => {
  Object.assign(option, options)
  // 扫码页面进入的一些初始化
  if (option.from === 'scan') {
    model.equId = option?.equId
    model.equName = option?.equName
    // 设置类型为设备类型
    model.reqType = '1'
    reqTypeDis.value = true
  }
  initData()
})
</script>
<style scoped lang="scss">
.footer {
  background: white;
  padding: 60rpx 42rpx;
}
</style>