feat:设备运维-添加维修单模块
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
|
||||
})
|
||||
}
|
||||
@ -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>
|
||||
Loading…
Reference in New Issue