<template>
|
<view class="upkeep-task-page">
|
<PageHeader title="定时任务管理"
|
@back="goBack" />
|
<view class="toolbar">
|
<view class="search-section">
|
<view class="search-bar">
|
<view class="search-input">
|
<up-input class="search-text"
|
placeholder="请输入保养任务名称"
|
v-model="queryParams.taskName"
|
clearable />
|
</view>
|
<view class="search-button"
|
@click="handleQuery">
|
<up-icon name="search"
|
size="24"
|
color="#999"></up-icon>
|
</view>
|
</view>
|
</view>
|
<view class="meta-bar">
|
<text class="meta-text">共 {{ total }} 条</text>
|
</view>
|
</view>
|
<view class="list-section">
|
<uni-swipe-action>
|
<uni-swipe-action-item v-for="item in tableData"
|
:key="item.id"
|
:right-options="swipeOptions"
|
@click="onSwipeActionClick($event, item)">
|
<view class="ledger-item">
|
<view class="item-header">
|
<view class="item-left">
|
<view class="document-icon">
|
<up-icon name="file-text"
|
size="14"
|
color="#ffffff"></up-icon>
|
</view>
|
<text class="item-id">{{ item.taskName || "--" }}</text>
|
</view>
|
<view class="item-right">
|
<u-tag :type="getFrequencyTagType(item.frequencyType)"
|
:text="formatFrequency(item.frequencyType) || '未知频次'" />
|
</view>
|
</view>
|
<up-divider></up-divider>
|
<view class="item-details">
|
<view class="detail-row">
|
<text class="detail-label">任务编号</text>
|
<text class="detail-value">{{ item.id || "--" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">设备</text>
|
<text class="detail-value">{{ item.deviceName || "--" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">开始日期与时间</text>
|
<text class="detail-value highlight">{{ formatFrequencyDetail(item.frequencyDetail) }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">登记人</text>
|
<text class="detail-value">{{ item.registrant || "--" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">登记日期</text>
|
<text class="detail-value">{{ item.registrationDate || item.createTime || "--" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">备注</text>
|
<text class="detail-value">{{ item.remarks || "无" }}</text>
|
</view>
|
<up-divider></up-divider>
|
<view class="card-actions">
|
<u-button type="primary"
|
size="small"
|
class="action-btn"
|
@click.stop="handleAdd(item)">编辑</u-button>
|
<u-button type="error"
|
size="small"
|
plain
|
class="action-btn"
|
@click.stop="deleteOne(item)">删除</u-button>
|
</view>
|
</view>
|
</view>
|
</uni-swipe-action-item>
|
</uni-swipe-action>
|
<uni-load-more :status="loadMoreStatus"></uni-load-more>
|
<view v-if="!loading && tableData.length === 0"
|
class="no-data">
|
<text>暂无数据</text>
|
</view>
|
</view>
|
<view class="fab-button"
|
@click="handleAdd()">
|
<up-icon name="plus"
|
size="24"
|
color="#ffffff"></up-icon>
|
</view>
|
<form-dia ref="formDia"
|
@closeDia="handleQuery" />
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, reactive, computed, nextTick } from "vue";
|
import { onShow, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FormDia from "@/pages/equipmentManagement/upkeepTask/components/formDia.vue";
|
import {
|
deviceMaintenanceTaskDel,
|
deviceMaintenanceTaskList,
|
} from "@/api/equipmentManagement/upkeep.js";
|
|
const formDia = ref();
|
const queryParams = reactive({
|
taskName: "",
|
});
|
const pageParams = reactive({
|
current: 1,
|
size: 10,
|
});
|
const total = ref(0);
|
const loading = ref(false);
|
const tableData = ref([]);
|
const swipeOptions = [
|
{
|
text: "删除",
|
style: {
|
backgroundColor: "#ee0a24",
|
},
|
},
|
];
|
|
const noMore = computed(() => tableData.value.length >= total.value);
|
const loadMoreStatus = computed(() => {
|
if (loading.value) return "loading";
|
if (noMore.value) return "noMore";
|
return "more";
|
});
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const formatFrequency = value => {
|
if (value === "DAILY") return "每日";
|
if (value === "WEEKLY") return "每周";
|
if (value === "MONTHLY") return "每月";
|
if (value === "QUARTERLY") return "季度";
|
return "";
|
};
|
|
const getFrequencyTagType = value => {
|
if (value === "DAILY") return "success";
|
if (value === "WEEKLY") return "primary";
|
if (value === "MONTHLY") return "warning";
|
return "info";
|
};
|
|
const formatFrequencyDetail = value => {
|
if (!value || typeof value !== "string") return "--";
|
return value.replace(
|
/MON|TUE|WED|THU|FRI|SAT|SUN/g,
|
item =>
|
({
|
MON: "周一",
|
TUE: "周二",
|
WED: "周三",
|
THU: "周四",
|
FRI: "周五",
|
SAT: "周六",
|
SUN: "周日",
|
})[item] || item
|
);
|
};
|
|
const getList = async () => {
|
if (loading.value) return;
|
loading.value = true;
|
try {
|
const params = {
|
...queryParams,
|
current: pageParams.current,
|
size: pageParams.size,
|
};
|
const res = await deviceMaintenanceTaskList(params);
|
const records = res?.data?.records || res?.records || [];
|
if (pageParams.current === 1) {
|
tableData.value = records;
|
} else {
|
tableData.value = [...tableData.value, ...records];
|
}
|
total.value = Number(res?.data?.total ?? res?.total ?? 0);
|
} catch (error) {
|
if (pageParams.current === 1) {
|
tableData.value = [];
|
}
|
uni.showToast({
|
title: "获取数据失败",
|
icon: "none",
|
});
|
} finally {
|
loading.value = false;
|
}
|
};
|
|
const handleQuery = () => {
|
pageParams.current = 1;
|
total.value = 0;
|
getList();
|
};
|
|
const loadMore = () => {
|
if (loading.value || noMore.value) return;
|
pageParams.current += 1;
|
getList();
|
};
|
|
const handleAdd = row => {
|
nextTick(() => {
|
formDia.value?.openDialog(row ? "edit" : "add", row);
|
});
|
};
|
|
const deleteOne = async row => {
|
if (!row?.id) return;
|
const canDelete = await new Promise(resolve => {
|
uni.showModal({
|
title: "提示",
|
content: "是否确认删除该保养任务?",
|
success: modalRes => resolve(Boolean(modalRes.confirm)),
|
fail: () => resolve(false),
|
});
|
});
|
if (!canDelete) return;
|
try {
|
await deviceMaintenanceTaskDel([row.id]);
|
uni.showToast({
|
title: "删除成功",
|
icon: "success",
|
});
|
handleQuery();
|
} catch (error) {
|
uni.showToast({
|
title: "删除失败",
|
icon: "none",
|
});
|
}
|
};
|
|
const onSwipeActionClick = (event, row) => {
|
if (event?.position !== "right") return;
|
deleteOne(row);
|
};
|
|
onShow(() => {
|
handleQuery();
|
});
|
|
onReachBottom(() => {
|
loadMore();
|
});
|
|
onPullDownRefresh(() => {
|
handleQuery();
|
uni.stopPullDownRefresh();
|
});
|
</script>
|
|
<style scoped>
|
.upkeep-task-page {
|
min-height: 100vh;
|
background: #f6f7fb;
|
}
|
|
.toolbar {
|
padding: 20rpx 24rpx;
|
background: #fff;
|
border-bottom: 1rpx solid #f0f0f0;
|
position: sticky;
|
top: 0;
|
z-index: 10;
|
}
|
|
.search-section {
|
margin-top: 0;
|
}
|
|
.search-bar {
|
display: flex;
|
align-items: center;
|
background: #f7f8fa;
|
border-radius: 14rpx;
|
padding: 8rpx 12rpx 8rpx 16rpx;
|
border: 1rpx solid #eef1f5;
|
}
|
|
.search-input {
|
flex: 1;
|
min-width: 0;
|
}
|
|
.search-text {
|
background: transparent !important;
|
}
|
|
:deep(.search-text .u-input__content),
|
:deep(.search-text .up-input__content) {
|
background: transparent !important;
|
padding: 0 !important;
|
}
|
|
.search-button {
|
width: 64rpx;
|
height: 64rpx;
|
border-radius: 12rpx;
|
background: #ffffff;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
}
|
|
.meta-bar {
|
margin-top: 16rpx;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
background: #f7f9fc;
|
border-radius: 12rpx;
|
padding: 10rpx 16rpx;
|
}
|
|
.meta-text {
|
color: #5c6b8a;
|
font-size: 22rpx;
|
}
|
|
.list-section {
|
padding: 20rpx 24rpx;
|
padding-bottom: calc(132rpx + env(safe-area-inset-bottom));
|
}
|
|
.ledger-item {
|
background: #ffffff;
|
border-radius: 20rpx;
|
margin-bottom: 16rpx;
|
overflow: hidden;
|
box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.05);
|
padding: 0 20rpx;
|
}
|
|
.item-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 22rpx 0;
|
}
|
|
.item-left {
|
display: flex;
|
align-items: center;
|
gap: 10rpx;
|
flex: 1;
|
min-width: 0;
|
}
|
|
.item-right {
|
display: flex;
|
align-items: center;
|
}
|
|
.document-icon {
|
width: 38rpx;
|
height: 38rpx;
|
border-radius: 8rpx;
|
background: #2979ff;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
}
|
|
.item-id {
|
font-size: 28rpx;
|
color: #1f1f1f;
|
font-weight: 600;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
|
.item-details {
|
padding: 18rpx 0 20rpx;
|
}
|
|
.detail-row {
|
display: flex;
|
align-items: flex-end;
|
justify-content: space-between;
|
margin-bottom: 12rpx;
|
}
|
|
.detail-label {
|
min-width: 160rpx;
|
color: #777;
|
font-size: 24rpx;
|
}
|
|
.detail-value {
|
flex: 1;
|
color: #333;
|
font-size: 24rpx;
|
text-align: right;
|
word-break: break-all;
|
margin-left: 12rpx;
|
}
|
|
.detail-value.highlight {
|
color: #2979ff;
|
font-weight: 500;
|
}
|
|
.card-actions {
|
padding-top: 8rpx;
|
display: flex;
|
justify-content: flex-end;
|
}
|
|
.action-btn {
|
min-width: 140rpx;
|
}
|
|
.fab-button {
|
position: fixed;
|
bottom: calc(30px + env(safe-area-inset-bottom));
|
right: 30px;
|
width: 56px;
|
height: 56px;
|
background: #2979ff;
|
border-radius: 50%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
box-shadow: 0 4px 16px rgba(41, 121, 255, 0.3);
|
z-index: 1000;
|
}
|
|
.no-data {
|
padding: 40rpx 0;
|
text-align: center;
|
color: #999;
|
}
|
</style>
|