feat:设备运维-添加维修单模块

master
黄伟杰 2 weeks ago
parent aff935a30d
commit ecba2589c6

@ -0,0 +1,67 @@
import upload from '@/utils/upload'
import request from '@/utils/request'
export function getDvRepairPage(params = {}) {
return request({
url: '/admin-api/mes/dv-repair/page',
method: 'get',
params
})
}
export function getDvRepair(id) {
return request({
url: '/admin-api/mes/dv-repair/get',
method: 'get',
params: { id }
})
}
export function createDvRepair(data) {
return request({
url: '/admin-api/mes/dv-repair/create',
method: 'post',
data
})
}
export function updateDvRepair(data) {
return request({
url: '/admin-api/mes/dv-repair/update',
method: 'put',
data
})
}
export function deleteDvRepair(ids) {
return request({
url: '/admin-api/mes/dv-repair/delete',
method: 'delete',
params: { ids }
})
}
export function updateDvRepairStatus(data) {
return request({
url: '/admin-api/mes/dv-repair/updateDvRepairStatus',
method: 'put',
data
})
}
export function getDvRepairLineListByRepairId(repairId) {
return request({
url: '/admin-api/mes/dv-repair-line/list-by-repair-id',
method: 'get',
params: { repairId }
})
}
export function uploadRepairImage(filePath, name = 'file') {
return upload({
url: '/admin-api/infra/file/upload',
name,
filePath,
showLoading: false
})
}

@ -22,6 +22,13 @@ export function getUserProfile() {
})
}
export function getSimpleUserList() {
return request({
url: '/admin-api/system/user/simple-list',
method: 'get'
})
}
// 修改用户个人信息
export function updateUserProfile(data) {
return request({

@ -491,6 +491,20 @@
"navigationStyle": "custom"
}
},
{
"path": "equipmentMaintenance/index",
"style": {
"navigationBarTitleText": "设备维修",
"navigationStyle": "custom"
}
},
{
"path": "equipmentMaintenance/form",
"style": {
"navigationBarTitleText": "设备维修",
"navigationStyle": "custom"
}
},
{
"path": "criticalComponent/index",
"style": {

@ -12,7 +12,9 @@
v-model="searchKeyword"
class="keyword-input"
:placeholder="t('equipmentLedger.searchPlaceholder')"
:focus="keywordFocus"
confirm-type="search"
@blur="keywordFocus = false"
@confirm="handleSearch"
/>
</view>
@ -80,8 +82,8 @@
</template>
<script setup>
import { ref, computed } from 'vue'
import { onLoad, onPageScroll, onReachBottom } from '@dcloudio/uni-app'
import { ref, computed, nextTick } from 'vue'
import { onLoad, onPageScroll, onReachBottom, onShow } from '@dcloudio/uni-app'
import { useI18n } from 'vue-i18n'
import NavBar from '@/components/common/NavBar.vue'
import { getDeviceLedgerPage, updateDeviceLedger } from '@/api/mes/deviceLedger'
@ -108,6 +110,7 @@ const pageSize = ref(10)
const total = ref(0)
const showGoTop = ref(false)
const statusUpdatingMap = ref({})
const keywordFocus = ref(false)
const statusOptions = computed(() => {
const dicts = dictStore.getDict(DICT_TYPE.MES_TZ_STATUS) || []
@ -139,11 +142,16 @@ const selectedLineLabel = computed(() => {
})
onLoad(async () => {
activateKeywordFocus()
await initAllDict()
await fetchLineTree()
await fetchList(true)
})
onShow(() => {
activateKeywordFocus()
})
onReachBottom(() => {
loadMore()
})
@ -218,6 +226,13 @@ function findLinePath(nodes, id, parents = []) {
return []
}
function activateKeywordFocus() {
keywordFocus.value = false
nextTick(() => {
keywordFocus.value = true
})
}
async function fetchList(reset) {
if (reset) {
pageNo.value = 1

@ -0,0 +1,946 @@
<template>
<view class="page-container">
<NavBar :title="pageTitle" />
<scroll-view scroll-y class="form-scroll">
<view class="section-card">
<view class="section-title">基本信息</view>
<view class="form-item">
<text class="form-label">维修单编号</text>
<view class="code-row">
<input
v-model="formData.repairCode"
class="form-input code-input"
type="text"
placeholder="请输入维修单编号"
:disabled="repairCodeDisabled"
/>
<view v-if="mode === 'create'" class="auto-code-wrap" @click="toggleAutoCode">
<text class="auto-code-text">自动生成</text>
<switch :checked="Boolean(formData.isCode)" color="#1f4b79" @change="toggleAutoCode" />
</view>
</view>
</view>
<view class="form-item">
<text class="form-label">维修单名称</text>
<input v-model="formData.repairName" class="form-input" type="text" placeholder="请输入维修单名称" :disabled="readonlyBase" />
</view>
<view class="form-item">
<text class="form-label">报修日期</text>
<picker mode="date" :value="datePickerValue(formData.requireDate)" :disabled="readonlyBase" @change="(e) => onDateChange('requireDate', e)">
<view :class="['picker-field', !formData.requireDate ? 'is-placeholder' : '']">{{ formData.requireDate || '请选择报修日期' }}</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">维修人员</text>
<picker :range="userLabels" :value="acceptedByIndex" :disabled="readonlyMeta" @change="(e) => onUserChange('acceptedBy', e)">
<view :class="['picker-field', !formData.acceptedBy ? 'is-placeholder' : '']">{{ acceptedByLabel }}</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">验收人员</text>
<picker :range="userLabels" :value="confirmByIndex" :disabled="readonlyMeta" @change="(e) => onUserChange('confirmBy', e)">
<view :class="['picker-field', !formData.confirmBy ? 'is-placeholder' : '']">{{ confirmByLabel }}</view>
</picker>
</view>
<view class="form-item">
<view class="form-label-row">
<text class="form-label form-label-inline">设备</text>
<view v-if="!readonlyBase" class="field-scan-btn" @click="handleDeviceScan">
<u-icon name="scan" size="18" color="#1f4b79"></u-icon>
</view>
</view>
<picker :range="deviceLabels" :value="deviceIndex" :disabled="readonlyBase" @change="onDeviceChange">
<view :class="['picker-field', !formData.deviceId ? 'is-placeholder' : '']">{{ selectedDeviceLabel }}</view>
</picker>
</view>
<view class="form-item inline-radio">
<text class="form-label">是否停机</text>
<radio-group class="radio-group" :disabled="readonlyMeta" @change="onShutdownChange">
<label class="radio-item">
<radio :checked="formData.isShutdown === true" :disabled="readonlyMeta" value="true" color="#1f4b79" />
<text></text>
</label>
<label class="radio-item">
<radio :checked="formData.isShutdown === false" :disabled="readonlyMeta" value="false" color="#1f4b79" />
<text></text>
</label>
</radio-group>
</view>
<view class="form-item">
<text class="form-label">单据状态</text>
<view class="value-field">{{ statusLabel }}</view>
</view>
</view>
<view class="section-card">
<view class="section-title">故障信息</view>
<view class="form-item">
<text class="form-label required">故障现象</text>
<input v-model="formData.faultPhenomenon" class="form-input" type="text" placeholder="请输入故障现象" :disabled="readonlyFault" />
</view>
<view class="form-item">
<text class="form-label">故障描述</text>
<textarea v-model="formData.faultDescription" class="form-textarea" :disabled="readonlyFault" maxlength="500" placeholder="请输入故障描述" />
</view>
<view class="form-item">
<text class="form-label">故障图片</text>
<view class="image-list">
<view v-for="(item, index) in faultImageList" :key="`${item}-${index}`" class="image-item">
<image class="preview-image" :src="item" mode="aspectFill" @click="previewImages(faultImageList, index)" />
<view v-if="!readonlyFault" class="image-delete" @click="removeImage('faultImages', index)">×</view>
</view>
<view v-if="!readonlyFault && faultImageList.length < 9" class="image-upload" @click="chooseImages('faultImages')">
<text class="image-upload-icon">+</text>
</view>
</view>
</view>
</view>
<view v-if="showRepairSection" class="section-card">
<view class="section-title">处理结果</view>
<view class="form-item inline-radio">
<text class="form-label required">维修结果</text>
<radio-group class="radio-group" :disabled="readonlyRepair" @change="onRepairStatusChange">
<label class="radio-item">
<radio :checked="String(formData.repairStatus || '0') === '1'" :disabled="readonlyRepair" value="1" color="#1f4b79" />
<text>通过</text>
</label>
<label class="radio-item">
<radio :checked="String(formData.repairStatus || '0') === '2'" :disabled="readonlyRepair" value="2" color="#1f4b79" />
<text>不通过</text>
</label>
</radio-group>
</view>
<view class="form-item">
<text class="form-label required">完成日期</text>
<picker mode="date" :value="datePickerValue(formData.finishDate)" :disabled="readonlyRepair" @change="(e) => onDateChange('finishDate', e)">
<view :class="['picker-field', !formData.finishDate ? 'is-placeholder' : '']">{{ formData.finishDate || '请选择完成日期' }}</view>
</picker>
</view>
<view class="form-item">
<text class="form-label required">验收日期</text>
<picker mode="date" :value="datePickerValue(formData.confirmDate)" :disabled="readonlyRepair" @change="(e) => onDateChange('confirmDate', e)">
<view :class="['picker-field', !formData.confirmDate ? 'is-placeholder' : '']">{{ formData.confirmDate || '请选择验收日期' }}</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">停机时长</text>
<input v-model="formData.downtimeDuration" class="form-input" type="digit" placeholder="请输入停机时长,单位小时" :disabled="readonlyRepair" />
</view>
<view class="form-item">
<text class="form-label">故障原因</text>
<input v-model="formData.faultReason" class="form-input" type="text" placeholder="请输入故障原因" :disabled="readonlyRepair" />
</view>
<view class="form-item">
<text class="form-label">处理措施</text>
<input v-model="formData.handlingMeasures" class="form-input" type="text" placeholder="请输入处理措施" :disabled="readonlyRepair" />
</view>
<view class="form-item">
<text class="form-label">更换配件</text>
<input v-model="formData.replacementParts" class="form-input" type="text" placeholder="请输入更换配件" :disabled="readonlyRepair" />
</view>
<view class="form-item">
<text class="form-label">维修内容</text>
<textarea v-model="formData.repairContent" class="form-textarea" :disabled="readonlyRepair" maxlength="1000" placeholder="请输入维修内容" />
</view>
<view class="form-item">
<text class="form-label">维修后图片</text>
<view class="image-list">
<view v-for="(item, index) in repairedImageList" :key="`${item}-${index}`" class="image-item">
<image class="preview-image" :src="item" mode="aspectFill" @click="previewImages(repairedImageList, index)" />
<view v-if="!readonlyRepair" class="image-delete" @click="removeImage('repairedImages', index)">×</view>
</view>
<view v-if="!readonlyRepair && repairedImageList.length < 9" class="image-upload" @click="chooseImages('repairedImages')">
<text class="image-upload-icon">+</text>
</view>
</view>
</view>
</view>
<view class="section-card last-section">
<view class="section-title">备注</view>
<view class="form-item no-border">
<textarea v-model="formData.remark" class="form-textarea" :disabled="isReadonly" maxlength="300" placeholder="请输入备注" />
</view>
</view>
</scroll-view>
<view class="page-footer">
<view class="footer-btn cancel" @click="goBack"></view>
<view v-if="!isReadonly" class="footer-btn confirm" @click="submitForm">{{ submitButtonText }}</view>
</view>
</view>
</template>
<script setup>
import { computed, reactive, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import { getDeviceLedgerList } from '@/api/mes/deviceLedger'
import {
createDvRepair,
getDvRepair,
updateDvRepair,
updateDvRepairStatus,
uploadRepairImage
} from '@/api/mes/dvrepair'
import { getSimpleUserList } from '@/api/system/user'
const mode = ref('create')
const repairId = ref('')
const users = ref([])
const deviceOptions = ref([])
const loading = ref(false)
const formData = reactive({
id: undefined,
repairCode: '',
repairName: '',
isCode: true,
deviceId: undefined,
machineryId: undefined,
machineryCode: '',
machineryName: '',
machineryBrand: '',
machinerySpec: '',
machineryTypeId: 1,
requireDate: '',
finishDate: '',
confirmDate: '',
repairStatus: '0',
repairResult: '0',
acceptedBy: '',
confirmBy: '',
isShutdown: undefined,
status: '0',
faultPhenomenon: '',
faultDescription: '',
faultImages: '',
downtimeDuration: '',
faultReason: '',
handlingMeasures: '',
replacementParts: '',
repairContent: '',
repairedImages: '',
remark: ''
})
const pageTitle = computed(() => {
if (mode.value === 'repair') return '维修处理'
if (mode.value === 'update') return '编辑设备维修'
if (mode.value === 'detail') return '设备维修详情'
return '新增设备维修'
})
const isReadonly = computed(() => mode.value === 'detail')
const readonlyBase = computed(() => mode.value === 'repair' || mode.value === 'detail')
const readonlyMeta = computed(() => mode.value === 'detail')
const readonlyFault = computed(() => mode.value === 'repair' || mode.value === 'detail')
const readonlyRepair = computed(() => mode.value !== 'repair')
const repairCodeDisabled = computed(() => Boolean(formData.isCode) || mode.value !== 'create')
const showRepairSection = computed(() => mode.value === 'repair' || mode.value === 'detail' || String(formData.repairStatus || '0') !== '0' || String(formData.status || '0') === '1')
const submitButtonText = computed(() => '保存')
const statusLabel = computed(() => {
const normalized = String(formData.repairStatus || '0')
if (normalized === '1') return '通过'
if (normalized === '2') return '不通过'
return '待维修'
})
const userLabels = computed(() => users.value.map((item) => item.nickname || item.name || String(item.id || '')))
const deviceLabels = computed(() => deviceOptions.value.map((item) => item.label))
const acceptedByIndex = computed(() => findUserIndex(formData.acceptedBy))
const confirmByIndex = computed(() => findUserIndex(formData.confirmBy))
const acceptedByLabel = computed(() => resolveUserLabel(formData.acceptedBy, '请选择维修人员'))
const confirmByLabel = computed(() => resolveUserLabel(formData.confirmBy, '请选择验收人员'))
const deviceIndex = computed(() => {
const index = deviceOptions.value.findIndex((item) => String(item.value) === String(formData.deviceId || ''))
return index >= 0 ? index : 0
})
const selectedDeviceLabel = computed(() => {
const current = deviceOptions.value.find((item) => String(item.value) === String(formData.deviceId || ''))
return current?.label || '请选择设备'
})
const faultImageList = computed(() => splitImages(formData.faultImages))
const repairedImageList = computed(() => splitImages(formData.repairedImages))
onLoad(async (options) => {
mode.value = String(options?.mode || 'create')
repairId.value = String(options?.id || '')
await Promise.all([fetchUsers(), fetchDevices()])
if (repairId.value) {
await fetchDetail(repairId.value)
}
})
async function fetchUsers() {
try {
const res = await getSimpleUserList()
const root = res && res.data !== undefined ? res.data : res
const data = Array.isArray(root) ? root : (Array.isArray(root?.data) ? root.data : [])
users.value = Array.isArray(data) ? data : []
} catch (error) {
users.value = []
}
}
async function fetchDevices() {
try {
const res = await getDeviceLedgerList()
const root = res && res.data !== undefined ? res.data : res
const data = Array.isArray(root) ? root : (Array.isArray(root?.data) ? root.data : [])
deviceOptions.value = (Array.isArray(data) ? data : [])
.filter((item) => item && item.id !== undefined && item.id !== null)
.map((item) => ({
value: item.id,
label: `${item.deviceCode || ''} ${item.deviceName || ''}`.trim(),
raw: item
}))
} catch (error) {
deviceOptions.value = []
}
}
async function fetchDetail(id) {
loading.value = true
try {
const res = await getDvRepair(id)
const detail = normalizeDetail(res)
const normalizedRepairStatus = normalizeRepairStatus(detail?.repairStatus ?? detail?.repairResult)
formData.id = detail?.id
formData.repairCode = inputValue(detail?.repairCode)
formData.repairName = inputValue(detail?.repairName)
formData.isCode = detail?.isCode === undefined ? true : Boolean(detail?.isCode)
formData.deviceId = detail?.deviceId ?? detail?.machineryId
formData.machineryId = detail?.machineryId ?? detail?.deviceId
formData.machineryCode = inputValue(detail?.machineryCode)
formData.machineryName = inputValue(detail?.machineryName)
formData.machineryBrand = inputValue(detail?.machineryBrand)
formData.machinerySpec = inputValue(detail?.machinerySpec)
formData.machineryTypeId = Number(detail?.machineryTypeId || 1) || 1
formData.requireDate = formatPickerDate(detail?.requireDate)
formData.finishDate = formatPickerDate(detail?.finishDate)
formData.confirmDate = formatPickerDate(detail?.confirmDate)
formData.repairStatus = normalizedRepairStatus
formData.repairResult = normalizedRepairStatus
formData.acceptedBy = normalizeUserId(detail?.acceptedBy)
formData.confirmBy = normalizeUserId(detail?.confirmBy)
formData.isShutdown = detail?.isShutdown === undefined || detail?.isShutdown === null ? undefined : Boolean(detail?.isShutdown)
formData.status = detail?.status === undefined || detail?.status === null ? '0' : String(detail?.status)
formData.faultPhenomenon = inputValue(detail?.faultPhenomenon)
formData.faultDescription = inputValue(detail?.faultDescription)
formData.faultImages = joinImages(detail?.faultImages)
formData.downtimeDuration = inputValue(detail?.downtimeDuration)
formData.faultReason = inputValue(detail?.faultReason)
formData.handlingMeasures = inputValue(detail?.handlingMeasures)
formData.replacementParts = inputValue(detail?.replacementParts)
formData.repairContent = inputValue(detail?.repairContent)
formData.repairedImages = joinImages(detail?.repairedImages)
formData.remark = inputValue(detail?.remark)
if (formData.deviceId !== undefined && formData.deviceId !== null) {
const exists = deviceOptions.value.some((item) => String(item.value) === String(formData.deviceId))
if (!exists) {
deviceOptions.value.unshift({
value: formData.deviceId,
label: `${formData.machineryCode || ''} ${formData.machineryName || ''}`.trim() || String(formData.deviceId),
raw: {
id: formData.deviceId,
deviceCode: formData.machineryCode,
deviceName: formData.machineryName,
deviceBrand: formData.machineryBrand,
deviceSpec: formData.machinerySpec
}
})
}
}
} catch (error) {
uni.showToast({ title: '加载详情失败', icon: 'none' })
} finally {
loading.value = false
}
}
function normalizeDetail(res) {
const root = res && res.data !== undefined ? res.data : res
if (root?.data && typeof root.data === 'object') return root.data
if (root && typeof root === 'object') return root
return {}
}
function toggleAutoCode(event) {
if (mode.value !== 'create') return
const checked = typeof event?.detail?.value === 'boolean' ? event.detail.value : !formData.isCode
formData.isCode = checked
if (checked) {
formData.repairCode = ''
}
}
function onDateChange(field, event) {
formData[field] = String(event?.detail?.value || '')
}
function onUserChange(field, event) {
const index = Number(event?.detail?.value || 0)
const current = users.value[index]
formData[field] = current ? String(current.id) : ''
}
function onDeviceChange(event) {
const index = Number(event?.detail?.value || 0)
const current = deviceOptions.value[index]
if (!current) return
applyDeviceOption(current)
}
async function handleDeviceScan() {
try {
const res = await uni.scanCode({ scanType: ['qrCode', 'barCode'] })
const scan = parseEquipmentScanResult(res?.result)
if (!scan.id) {
uni.showToast({ title: '请扫描设备二维码', icon: 'none' })
return
}
const matched = deviceOptions.value.find((item) => String(item.value) === String(scan.id))
if (!matched) {
uni.showToast({ title: '未找到对应设备', icon: 'none' })
return
}
applyDeviceOption(matched)
} catch (error) {
const message = String(error?.errMsg || '')
if (message.includes('cancel')) return
uni.showToast({ title: '扫码失败', icon: 'none' })
}
}
function parseEquipmentScanResult(result) {
const text = String(result || '').trim()
const directMatch = text.match(/^([A-Z_]+)-(\d+)$/i)
if (directMatch) {
return {
type: directMatch[1].toUpperCase(),
id: directMatch[1].toUpperCase() === 'EQUIPMENT' ? directMatch[2] : ''
}
}
try {
const parsed = JSON.parse(text)
const type = String(parsed?.type || parsed?.bizType || parsed?.codeType || '').toUpperCase()
const id = String(parsed?.id || parsed?.machineryId || parsed?.deviceId || '').trim()
return {
type,
id: type === 'EQUIPMENT' && id ? id : ''
}
} catch {
return { type: '', id: '' }
}
}
function applyDeviceOption(current) {
formData.deviceId = current.value
formData.machineryId = current.value
formData.machineryCode = inputValue(current.raw?.deviceCode)
formData.machineryName = inputValue(current.raw?.deviceName)
formData.machineryBrand = inputValue(current.raw?.deviceBrand)
formData.machinerySpec = inputValue(current.raw?.deviceSpec)
}
function onShutdownChange(event) {
const value = String(event?.detail?.value || '')
if (value === 'true') formData.isShutdown = true
if (value === 'false') formData.isShutdown = false
}
function onRepairStatusChange(event) {
const value = String(event?.detail?.value || '0')
formData.repairStatus = value
formData.repairResult = value
}
function findUserIndex(value) {
if (value === undefined || value === null || value === '') return 0
const index = users.value.findIndex((item) => String(item.id) === String(value) || item.nickname === String(value))
return index >= 0 ? index : 0
}
function resolveUserLabel(value, placeholder) {
if (value === undefined || value === null || value === '') return placeholder
const current = users.value.find((item) => String(item.id) === String(value) || item.nickname === String(value))
return current?.nickname || current?.name || placeholder
}
function normalizeUserId(value) {
if (value === undefined || value === null || value === '') return ''
const target = String(value)
const matched = users.value.find((item) => String(item.id) === target || item.nickname === target)
return matched ? String(matched.id) : target
}
function normalizeRepairStatus(value) {
if (value === undefined || value === null || value === '' || String(value) === '0') return '0'
return String(value)
}
function datePickerValue(value) {
return value || formatPickerDate(Date.now())
}
function formatPickerDate(value) {
if (value === undefined || value === null || value === '') return ''
const date = parseDate(value)
if (!date) return ''
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
function parseDate(value) {
if (value instanceof Date && !Number.isNaN(value.getTime())) return value
if (typeof value === 'number' || /^\d+$/.test(String(value || ''))) {
const numeric = Number(value)
if (!Number.isNaN(numeric)) {
const date = new Date(numeric)
if (!Number.isNaN(date.getTime())) return date
}
}
if (typeof value === 'string') {
const date = new Date(value.replace(/-/g, '/'))
if (!Number.isNaN(date.getTime())) return date
}
return null
}
function toTimestamp(value) {
if (!value) return undefined
const date = parseDate(value)
return date ? date.getTime() : undefined
}
function splitImages(value) {
if (Array.isArray(value)) return value.map((item) => String(item).trim()).filter(Boolean)
if (!value) return []
return String(value).split(',').map((item) => item.trim()).filter(Boolean)
}
function joinImages(value) {
return splitImages(value).join(',')
}
async function chooseImages(field) {
try {
const currentCount = splitImages(formData[field]).length
const remain = Math.max(0, 9 - currentCount)
if (!remain) {
uni.showToast({ title: '最多上传 9 张图片', icon: 'none' })
return
}
const res = await uni.chooseImage({ count: remain, sizeType: ['compressed'] })
const files = Array.isArray(res?.tempFilePaths) ? res.tempFilePaths : []
if (!files.length) return
uni.showLoading({ title: '上传中', mask: true })
const uploaded = []
for (const filePath of files) {
const uploadRes = await uploadRepairImage(filePath)
const url = String(
uploadRes?.data?.fileUrl ||
uploadRes?.data?.url ||
uploadRes?.data ||
uploadRes?.url ||
''
).trim()
if (url) uploaded.push(url)
}
const merged = [...splitImages(formData[field]), ...uploaded]
formData[field] = merged.join(',')
} catch (error) {
const message = String(error?.errMsg || '')
if (!message.includes('cancel')) {
uni.showToast({ title: '图片上传失败', icon: 'none' })
}
} finally {
uni.hideLoading()
}
}
function removeImage(field, index) {
const next = splitImages(formData[field])
next.splice(index, 1)
formData[field] = next.join(',')
}
function previewImages(list, current) {
uni.previewImage({
urls: list,
current: list[current] || list[0]
})
}
function buildPayload() {
return {
id: formData.id,
repairCode: formData.isCode ? undefined : formData.repairCode.trim(),
repairName: formData.repairName.trim(),
isCode: Boolean(formData.isCode),
deviceId: formData.deviceId,
machineryId: formData.deviceId,
machineryCode: formData.machineryCode || undefined,
machineryName: formData.machineryName || undefined,
machineryBrand: formData.machineryBrand || undefined,
machinerySpec: formData.machinerySpec || undefined,
machineryTypeId: 1,
requireDate: toTimestamp(formData.requireDate),
finishDate: toTimestamp(formData.finishDate),
confirmDate: toTimestamp(formData.confirmDate),
repairStatus: normalizeRepairStatus(formData.repairStatus),
repairResult: normalizeRepairStatus(formData.repairStatus),
acceptedBy: normalizeUserId(formData.acceptedBy) || undefined,
confirmBy: normalizeUserId(formData.confirmBy) || undefined,
isShutdown: formData.isShutdown,
status: mode.value === 'repair' ? '1' : String(formData.status || '0'),
faultPhenomenon: formData.faultPhenomenon.trim(),
faultDescription: formData.faultDescription.trim() || undefined,
faultImages: joinImages(formData.faultImages),
downtimeDuration: formData.downtimeDuration.trim() || undefined,
faultReason: formData.faultReason.trim() || undefined,
handlingMeasures: formData.handlingMeasures.trim() || undefined,
replacementParts: formData.replacementParts.trim() || undefined,
repairContent: formData.repairContent.trim() || undefined,
repairedImages: joinImages(formData.repairedImages),
remark: formData.remark.trim() || undefined
}
}
async function submitForm() {
if (!formData.isCode && !formData.repairCode.trim()) {
uni.showToast({ title: '请输入维修单编号', icon: 'none' })
return
}
if (!formData.repairName.trim()) {
uni.showToast({ title: '请输入维修单名称', icon: 'none' })
return
}
if (!formData.deviceId) {
uni.showToast({ title: '请选择设备', icon: 'none' })
return
}
if (!formData.requireDate) {
uni.showToast({ title: '请选择报修日期', icon: 'none' })
return
}
if (!formData.faultPhenomenon.trim()) {
uni.showToast({ title: '请输入故障现象', icon: 'none' })
return
}
if (mode.value === 'repair') {
if (String(formData.repairStatus || '0') === '0') {
uni.showToast({ title: '请选择维修结果', icon: 'none' })
return
}
if (!formData.finishDate) {
uni.showToast({ title: '请选择完成日期', icon: 'none' })
return
}
if (!formData.confirmDate) {
uni.showToast({ title: '请选择验收日期', icon: 'none' })
return
}
}
const payload = buildPayload()
try {
uni.showLoading({ title: '保存中', mask: true })
if (mode.value === 'create') {
await createDvRepair(payload)
uni.showToast({ title: '新增成功', icon: 'success' })
} else if (mode.value === 'repair') {
await updateDvRepairStatus({
id: payload.id,
requireDate: payload.requireDate,
finishDate: payload.finishDate,
confirmDate: payload.confirmDate,
repairStatus: payload.repairStatus,
repairResult: payload.repairResult,
faultPhenomenon: payload.faultPhenomenon,
faultDescription: payload.faultDescription || null,
faultImages: payload.faultImages,
downtimeDuration: payload.downtimeDuration,
faultReason: payload.faultReason,
handlingMeasures: payload.handlingMeasures,
replacementParts: payload.replacementParts,
repairContent: payload.repairContent,
repairedImages: payload.repairedImages,
remark: payload.remark || '',
updateReqVOList: []
})
uni.showToast({ title: '提交成功', icon: 'success' })
} else {
await updateDvRepair(payload)
uni.showToast({ title: '保存成功', icon: 'success' })
}
setTimeout(() => {
goBack()
}, 300)
} catch (error) {
uni.showToast({ title: mode.value === 'repair' ? '提交失败' : '保存失败', icon: 'none' })
} finally {
uni.hideLoading()
}
}
function inputValue(value) {
if (value === undefined || value === null) return ''
return String(value)
}
function goBack() {
uni.navigateBack()
}
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background: #f4f5f7;
}
.form-scroll {
height: calc(100vh - 112rpx - env(safe-area-inset-bottom));
}
.section-card {
margin: 18rpx 20rpx 0;
padding: 26rpx 24rpx;
background: #ffffff;
border-radius: 20rpx;
}
.last-section {
margin-bottom: 24rpx;
}
.section-title {
margin-bottom: 16rpx;
font-size: 30rpx;
color: #111827;
font-weight: 700;
}
.form-item {
padding: 22rpx 0;
border-bottom: 1rpx solid #f1f5f9;
}
.form-item.no-border {
border-bottom: none;
padding-bottom: 0;
}
.form-label {
display: block;
margin-bottom: 14rpx;
font-size: 26rpx;
color: #4b5563;
}
.form-label-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14rpx;
}
.form-label-inline {
margin-bottom: 0;
}
.field-scan-btn {
width: 52rpx;
height: 52rpx;
border-radius: 12rpx;
background: #eef4fb;
display: flex;
align-items: center;
justify-content: center;
}
.form-label.required::after {
content: ' *';
color: #dc2626;
}
.form-input,
.picker-field,
.value-field,
.form-textarea {
width: 100%;
box-sizing: border-box;
border-radius: 14rpx;
background: #f8fafc;
color: #111827;
font-size: 28rpx;
}
.form-input,
.picker-field,
.value-field {
min-height: 84rpx;
padding: 0 20rpx;
display: flex;
align-items: center;
}
.form-textarea {
min-height: 180rpx;
padding: 20rpx;
}
.picker-field.is-placeholder {
color: #9ca3af;
}
.code-row {
display: flex;
align-items: center;
gap: 16rpx;
}
.code-input {
flex: 1;
}
.auto-code-wrap {
display: flex;
align-items: center;
gap: 10rpx;
white-space: nowrap;
}
.auto-code-text {
font-size: 24rpx;
color: #4b5563;
}
.inline-radio .form-label {
margin-bottom: 20rpx;
}
.radio-group {
display: flex;
align-items: center;
gap: 28rpx;
flex-wrap: wrap;
}
.radio-item {
display: flex;
align-items: center;
gap: 10rpx;
font-size: 28rpx;
color: #111827;
}
.image-list {
display: flex;
gap: 16rpx;
flex-wrap: wrap;
}
.image-item,
.image-upload {
position: relative;
width: 148rpx;
height: 148rpx;
border-radius: 16rpx;
overflow: hidden;
}
.preview-image {
width: 100%;
height: 100%;
background: #e5e7eb;
}
.image-upload {
display: flex;
align-items: center;
justify-content: center;
background: #f8fafc;
border: 2rpx dashed #cbd5e1;
}
.image-upload-icon {
font-size: 60rpx;
line-height: 1;
color: #94a3b8;
}
.image-delete {
position: absolute;
top: 6rpx;
right: 6rpx;
width: 34rpx;
height: 34rpx;
border-radius: 50%;
background: rgba(15, 23, 42, 0.68);
color: #ffffff;
font-size: 26rpx;
display: flex;
align-items: center;
justify-content: center;
}
.page-footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: flex;
gap: 18rpx;
padding: 18rpx 24rpx calc(18rpx + env(safe-area-inset-bottom));
background: #ffffff;
box-shadow: 0 -8rpx 24rpx rgba(15, 23, 42, 0.06);
}
.footer-btn {
flex: 1;
height: 84rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 30rpx;
font-weight: 600;
}
.footer-btn.cancel {
background: #eef2f7;
color: #475569;
}
.footer-btn.confirm {
background: #1f4b79;
color: #ffffff;
}
</style>

@ -0,0 +1,606 @@
<template>
<view class="page-container">
<NavBar title="设备维修" />
<view class="filter-bar">
<view class="keyword-box">
<input
v-model="searchKeyword"
class="keyword-input"
type="text"
placeholder="请输入单号或设备编码"
placeholder-class="placeholder"
:focus="keywordFocus"
confirm-type="search"
@blur="keywordFocus = false"
@confirm="handleSearch"
/>
</view>
<picker :range="statusLabels" :value="statusPickerIndex" @change="onStatusFilterChange">
<view class="status-box">
<text :class="['status-box-text', selectedStatus === '' ? 'placeholder' : '']">{{ selectedStatusLabel }}</text>
<uni-icons type="bottom" size="14" color="#9ca3af"></uni-icons>
</view>
</picker>
<view class="reset-filter-btn" @click="resetFilters"></view>
<view class="scan-btn" @click="handleScan">
<uni-icons type="scan" size="22" color="#111827"></uni-icons>
</view>
</view>
<scroll-view
scroll-y
class="list-scroll"
:scroll-top="scrollTop"
@scroll="onScroll"
@scrolltolower="loadMore"
:lower-threshold="80"
>
<view class="list-wrap">
<view
v-for="item in list"
:key="item.id"
class="repair-card"
@click="openCard(item)"
>
<view class="card-main">
<view class="card-top">
<text class="repair-code">{{ textValue(item.repairCode) }}</text>
<view class="repair-status-wrap">
<text :class="['status-dot', getRepairStatusDotClass(item.repairStatus)]"></text>
<text :class="['repair-status-text', getRepairStatusTextClass(item.repairStatus)]">{{ getRepairStatusText(item.repairStatus) }}</text>
</view>
</view>
<text class="repair-name">{{ textValue(item.machineryName) }}</text>
<view class="card-bottom">
<text class="repair-device-code">{{ textValue(item.machineryCode) }}</text>
<text class="repair-date">{{ formatDateValue(item.requireDate || item.createTime) }}</text>
</view>
</view>
<view class="card-actions">
<view v-if="canEdit(item)" class="card-action edit" @click.stop="openForm('update', item.id)">
<u-icon name="edit-pen" size="22" color="#1d4ed8"></u-icon>
</view>
<view class="card-action delete" @click.stop="confirmDelete(item)">
<u-icon name="trash" size="22" color="#dc2626"></u-icon>
</view>
</view>
</view>
<view v-if="loading && pageNo === 1" class="state-text">...</view>
<view v-else-if="!list.length" class="state-text empty">暂无维修记录</view>
<view v-else-if="loadingMore" class="state-text">加载更多中...</view>
<view v-else-if="finished" class="state-text">没有更多了</view>
</view>
</scroll-view>
<view v-if="showGoTop" class="go-top-btn" @click="goTop">
<uni-icons type="top" size="20" color="#ffffff"></uni-icons>
</view>
<view class="add-btn" @click="openForm('create')">
<text class="add-icon">+</text>
</view>
</view>
</template>
<script setup>
import { computed, nextTick, ref } from 'vue'
import { onLoad, onReachBottom, onShow } from '@dcloudio/uni-app'
import NavBar from '@/components/common/NavBar.vue'
import {
deleteDvRepair,
getDvRepairPage
} from '@/api/mes/dvrepair'
const searchKeyword = ref('')
const selectedStatus = ref('0')
const list = ref([])
const loading = ref(false)
const loadingMore = ref(false)
const finished = ref(false)
const pageNo = ref(1)
const pageSize = ref(10)
const total = ref(0)
const initialized = ref(false)
const scrollTop = ref(0)
const showGoTop = ref(false)
const keywordFocus = ref(false)
const selectedMachineryId = ref('')
const statusOptions = [
{ label: '待维修', value: '0' },
{ label: '通过', value: '1' },
{ label: '不通过', value: '2' }
]
const statusLabels = computed(() => statusOptions.map((item) => item.label))
const statusPickerIndex = computed(() => {
const index = statusOptions.findIndex((item) => item.value === selectedStatus.value)
return index >= 0 ? index : 0
})
const selectedStatusLabel = computed(() => {
const current = statusOptions.find((item) => item.value === selectedStatus.value)
return current ? current.label : '待维修'
})
onLoad(async () => {
initialized.value = true
activateKeywordFocus()
await fetchList(true)
})
onShow(async () => {
activateKeywordFocus()
if (!initialized.value) return
await fetchList(true)
})
onReachBottom(() => {
loadMore()
})
async function fetchList(reset) {
if (reset) {
pageNo.value = 1
finished.value = false
}
if (pageNo.value === 1) {
loading.value = true
} else {
loadingMore.value = true
}
try {
const keyword = searchKeyword.value.trim()
const params = {
pageNo: pageNo.value,
pageSize: pageSize.value,
repairCode: keyword || undefined,
machineryCode: keyword || undefined,
machineryId: selectedMachineryId.value || undefined,
repairResult: selectedStatus.value === '' ? undefined : selectedStatus.value,
repairStatus: selectedStatus.value === '' ? undefined : selectedStatus.value
}
const res = await getDvRepairPage(params)
const page = normalizePageData(res)
total.value = page.total
list.value = reset ? page.list : [...list.value, ...page.list]
finished.value = list.value.length >= total.value || page.list.length < pageSize.value
} catch (error) {
if (!reset) {
pageNo.value = Math.max(1, pageNo.value - 1)
}
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
loadingMore.value = false
}
}
function normalizePageData(res) {
const root = res && res.data !== undefined ? res.data : res
const candidateList = root?.list || root?.rows || root?.records || root?.data?.list || root?.data?.rows || root?.data?.records || []
const candidateTotal = root?.total ?? root?.data?.total ?? (Array.isArray(candidateList) ? candidateList.length : 0)
return {
list: Array.isArray(candidateList) ? candidateList : [],
total: Number(candidateTotal || 0)
}
}
function activateKeywordFocus() {
keywordFocus.value = false
nextTick(() => {
keywordFocus.value = true
})
}
function handleSearch() {
uni.hideKeyboard()
fetchList(true)
}
async function resetFilters() {
searchKeyword.value = ''
selectedStatus.value = '0'
selectedMachineryId.value = ''
activateKeywordFocus()
await fetchList(true)
}
function onStatusFilterChange(event) {
const index = Number(event?.detail?.value || 0)
selectedStatus.value = statusOptions[index]?.value ?? ''
fetchList(true)
}
async function handleScan() {
try {
const res = await uni.scanCode({ scanType: ['qrCode', 'barCode'] })
const result = String(res?.result || '').trim()
if (!result) {
uni.showToast({ title: '未识别到内容', icon: 'none' })
return
}
const scan = parseEquipmentScanResult(result)
if (!scan.id) {
uni.showToast({ title: '请扫描设备二维码', icon: 'none' })
return
}
selectedMachineryId.value = scan.id
searchKeyword.value = ''
await fetchList(true)
} catch (error) {
const message = String(error?.errMsg || '')
if (message.includes('cancel')) return
uni.showToast({ title: '扫码失败', icon: 'none' })
}
}
function parseEquipmentScanResult(result) {
const text = String(result || '').trim()
const directMatch = text.match(/^([A-Z_]+)-(\d+)$/i)
if (directMatch) {
return {
type: directMatch[1].toUpperCase(),
id: directMatch[1].toUpperCase() === 'EQUIPMENT' ? directMatch[2] : ''
}
}
try {
const parsed = JSON.parse(text)
const type = String(parsed?.type || parsed?.bizType || parsed?.codeType || '').toUpperCase()
const id = String(parsed?.id || parsed?.machineryId || parsed?.deviceId || '').trim()
return {
type,
id: type === 'EQUIPMENT' && id ? id : ''
}
} catch {
return { type: '', id: '' }
}
}
function canEdit(item) {
return !isProcessedRepair(item?.repairStatus)
}
function canRepair(item) {
return String(item?.status ?? '0') !== '1' && !isProcessedRepair(item?.repairStatus)
}
function isProcessedRepair(value) {
const normalized = value === '' || value === null || value === undefined ? '0' : String(value)
return normalized !== '0'
}
function openCard(item) {
if (item?.id === undefined || item?.id === null) {
uni.showToast({ title: '缺少维修单 ID', icon: 'none' })
return
}
if (canRepair(item)) {
openForm('repair', item.id)
return
}
openForm('detail', item.id)
}
function openForm(mode, id) {
const query = [`mode=${encodeURIComponent(mode)}`]
if (id !== undefined && id !== null) {
query.push(`id=${encodeURIComponent(String(id))}`)
}
uni.navigateTo({
url: `/pages_function/pages/equipmentMaintenance/form?${query.join('&')}`
})
}
function confirmDelete(item) {
const id = item?.id
if (id === undefined || id === null) return
uni.showModal({
title: '确认删除',
content: `确定删除维修单“${textValue(item?.repairCode)}”吗?`,
success: async (res) => {
if (!res.confirm) return
try {
await deleteDvRepair(String(id))
uni.showToast({ title: '删除成功', icon: 'success' })
await fetchList(true)
} catch (error) {
uni.showToast({ title: '删除失败', icon: 'none' })
}
}
})
}
function onScroll(event) {
const top = event?.detail?.scrollTop || 0
showGoTop.value = top > 500
}
function goTop() {
scrollTop.value = 0
}
async function loadMore() {
if (loading.value || loadingMore.value || finished.value) return
pageNo.value += 1
await fetchList(false)
}
function getRepairStatusText(value) {
const normalized = value === '' || value === null || value === undefined ? '0' : String(value)
if (normalized === '1') return '通过'
if (normalized === '2') return '不通过'
return '待维修'
}
function getRepairStatusTextClass(value) {
const normalized = value === '' || value === null || value === undefined ? '0' : String(value)
if (normalized === '1') return 'text-success'
if (normalized === '2') return 'text-danger'
return 'text-warning'
}
function getRepairStatusDotClass(value) {
const normalized = value === '' || value === null || value === undefined ? '0' : String(value)
if (normalized === '1') return 'dot-success'
if (normalized === '2') return 'dot-danger'
return 'dot-warning'
}
function formatDateValue(value) {
if (value === null || value === undefined || value === '') return '-'
const date = normalizeDate(value)
if (!date) return textValue(value)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
function normalizeDate(value) {
if (value instanceof Date && !Number.isNaN(value.getTime())) return value
if (typeof value === 'number' || /^\d+$/.test(String(value || ''))) {
const numeric = Number(value)
if (!Number.isNaN(numeric)) {
const date = new Date(numeric)
if (!Number.isNaN(date.getTime())) return date
}
}
if (typeof value === 'string') {
const date = new Date(value.replace(/-/g, '/'))
if (!Number.isNaN(date.getTime())) return date
}
return null
}
function textValue(value) {
if (value === 0) return '0'
if (value === null || value === undefined) return '-'
const text = String(value).trim()
return text || '-'
}
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background-color: #f3f4f6;
}
.filter-bar {
display: grid;
grid-template-columns: minmax(0, 1fr) 150rpx 96rpx 64rpx;
align-items: center;
gap: 14rpx;
padding: 18rpx 4rpx 20rpx;
}
.keyword-box,
.status-box,
.reset-filter-btn,
.scan-btn {
height: 66rpx;
background: #ffffff;
border: 1rpx solid #d9dde5;
box-sizing: border-box;
display: flex;
align-items: center;
}
.keyword-box {
padding: 0 20rpx;
}
.keyword-input {
width: 100%;
font-size: 26rpx;
color: #374151;
}
.status-box {
justify-content: space-between;
padding: 0 18rpx;
}
.status-box-text,
.placeholder {
font-size: 26rpx;
}
.status-box-text {
color: #374151;
}
.placeholder {
color: #a8adb7;
}
.scan-btn {
display: flex;
align-items: center;
justify-content: center;
background: #ffffff;
}
.reset-filter-btn {
display: flex;
align-items: center;
justify-content: center;
font-size: 24rpx;
color: #4b5563;
}
.list-scroll {
width: 100%;
}
.list-wrap {
padding: 0 4rpx 140rpx;
}
.repair-card {
margin-bottom: 18rpx;
border-radius: 12rpx;
background: #ffffff;
box-shadow: none;
overflow: hidden;
}
.card-main {
padding: 24rpx;
}
.card-top,
.card-bottom,
.card-actions {
display: flex;
align-items: center;
justify-content: space-between;
}
.repair-code {
max-width: 420rpx;
font-size: 36rpx;
line-height: 44rpx;
color: #24456b;
font-weight: 700;
}
.repair-status-wrap {
display: flex;
align-items: center;
gap: 12rpx;
}
.status-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
}
.repair-status-text {
font-size: 28rpx;
font-weight: 600;
}
.text-warning {
color: #f97316;
}
.text-success {
color: #16a34a;
}
.text-danger {
color: #dc2626;
}
.dot-warning {
background: #f97316;
}
.dot-success {
background: #16a34a;
}
.dot-danger {
background: #dc2626;
}
.repair-name {
display: block;
margin-top: 14rpx;
font-size: 30rpx;
color: #9ca3af;
}
.card-bottom {
margin-top: 18rpx;
}
.repair-device-code,
.repair-date {
font-size: 26rpx;
color: #9ca3af;
}
.card-actions {
padding: 18rpx 24rpx;
border-top: 1rpx solid #f1f5f9;
justify-content: flex-end;
gap: 28rpx;
}
.card-action {
width: 56rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
}
.state-text {
padding: 28rpx 0;
text-align: center;
color: #9ca3af;
font-size: 26rpx;
}
.state-text.empty {
padding-top: 160rpx;
}
.add-btn,
.go-top-btn {
position: fixed;
right: 32rpx;
width: 92rpx;
height: 92rpx;
border-radius: 46rpx;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 14rpx 30rpx rgba(24, 63, 108, 0.24);
}
.add-btn {
right: 28rpx;
bottom: calc(56rpx + env(safe-area-inset-bottom));
background: #1f4b79;
}
.go-top-btn {
bottom: calc(172rpx + env(safe-area-inset-bottom));
background: rgba(31, 75, 121, 0.84);
}
.add-icon {
color: #ffffff;
font-size: 64rpx;
line-height: 1;
margin-top: -4rpx;
}
</style>

@ -40,6 +40,9 @@ const MENU_ROUTE_MAP = {
equipmentcategory: '/pages_function/pages/equipmentCategory/index',
'设备台账': '/pages_function/pages/equipmentLedger/index',
equipmentledger: '/pages_function/pages/equipmentLedger/index',
'设备维修': '/pages_function/pages/equipmentMaintenance/index',
equipmentmaintenance: '/pages_function/pages/equipmentMaintenance/index',
dvrepair: '/pages_function/pages/equipmentMaintenance/index',
'设备关键件': '/pages_function/pages/criticalComponent/index',
criticalcomponent: '/pages_function/pages/criticalComponent/index',
equipmentkeypart: '/pages_function/pages/equipmentKeypart/index',

@ -38,7 +38,7 @@ const upload = <T>(config: RequestUploadConfig): Promise<ResponseData<T>> => {
const code = result.code || 200
// @ts-ignore
const msg = errorCode[code] || result.msg || errorCode['default']
if (code === 200) {
if (code === 200 || code === 0) {
resolve(result)
} else if (code == 401) {
showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {

Loading…
Cancel
Save