<template>
|
<view class="hazard-list">
|
<PageHeader title="隐患管理"
|
@back="goBack" />
|
<view class="top-actions">
|
<u-button type="primary"
|
size="small"
|
:disabled="isCompleted"
|
@click="goAdd">上报隐患</u-button>
|
</view>
|
<scroll-view scroll-y
|
class="list-scroll ledger-list"
|
v-if="hazards.length > 0">
|
<view v-for="row in hazards"
|
:key="row.id"
|
class="ledger-item">
|
<view class="item-header">
|
<view class="item-left">
|
<view class="document-icon">
|
<up-icon name="file-text"
|
size="16"
|
color="#ffffff"></up-icon>
|
</view>
|
<text class="item-id">{{ row.hazardCode || "隐患" }}</text>
|
</view>
|
<view class="item-right">
|
<up-tag :text="row.status || '-'"
|
:type="statusType(row.status)"
|
size="mini" />
|
</view>
|
</view>
|
<up-divider></up-divider>
|
<view class="item-details">
|
<view class="detail-row">
|
<text class="detail-label">隐患描述</text>
|
<text class="detail-value">{{ row.hazardDesc || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">隐患等级</text>
|
<text class="detail-value">{{ row.hazardLevel || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">隐患位置</text>
|
<text class="detail-value">{{ row.hazardLocation || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">整改责任人</text>
|
<text class="detail-value">{{ row.rectifyUserName || "-" }}</text>
|
</view>
|
</view>
|
<view class="action-buttons">
|
<u-button size="small"
|
class="action-btn fixed-btn"
|
:disabled="isCompleted"
|
@click.stop="goEdit(row)">编辑</u-button>
|
<u-button v-if="String(row.status) !== '已整改'"
|
size="small"
|
class="action-btn fixed-btn"
|
type="success"
|
:disabled="isCompleted"
|
@click.stop="goRectify(row)">
|
整改
|
</u-button>
|
</view>
|
</view>
|
</scroll-view>
|
<view v-else
|
class="no-data">
|
<up-empty mode="data"
|
text="暂无隐患"></up-empty>
|
</view>
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from "vue";
|
import { onLoad, onShow } from "@dcloudio/uni-app";
|
import PageHeader from "@/components/PageHeader.vue";
|
import { getHazardsByInspectionId } from "@/api/safeProduction/lineInspection";
|
|
const inspectionId = ref(null);
|
const inspectionStatus = ref("");
|
const hazards = ref([]);
|
|
const isCompleted = computed(() => String(inspectionStatus.value) === "已完成");
|
|
const statusType = status => {
|
const map = {
|
待整改: "error",
|
整改中: "warning",
|
已整改: "success",
|
};
|
return map[status] || "info";
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const fetchHazards = () => {
|
if (!inspectionId.value) return;
|
uni.showLoading({ title: "加载中...", mask: true });
|
getHazardsByInspectionId(inspectionId.value)
|
.then(res => {
|
hazards.value = res?.data || [];
|
})
|
.catch(() => {
|
uni.showToast({ title: "加载失败", icon: "none" });
|
})
|
.finally(() => {
|
uni.hideLoading();
|
});
|
};
|
|
const goAdd = () => {
|
const data = encodeURIComponent(
|
JSON.stringify({ inspectionId: inspectionId.value })
|
);
|
uni.navigateTo({
|
url: `/pages/safeProduction/lineInspection/hazardEdit?data=${data}`,
|
});
|
};
|
|
const goEdit = row => {
|
const data = encodeURIComponent(
|
JSON.stringify({ inspectionId: inspectionId.value, row })
|
);
|
uni.navigateTo({
|
url: `/pages/safeProduction/lineInspection/hazardEdit?data=${data}`,
|
});
|
};
|
|
const goRectify = row => {
|
const data = encodeURIComponent(JSON.stringify({ row }));
|
uni.navigateTo({
|
url: `/pages/safeProduction/lineInspection/hazardRectify?data=${data}`,
|
});
|
};
|
|
onMounted(() => {
|
uni.$on("lineInspection:hazardsRefresh", fetchHazards);
|
});
|
|
onLoad(options => {
|
if (options?.data) {
|
try {
|
const obj = JSON.parse(decodeURIComponent(options.data));
|
inspectionId.value = obj.inspectionId;
|
inspectionStatus.value = obj.inspectionStatus || "";
|
} catch (e) {}
|
}
|
});
|
|
onShow(() => {
|
fetchHazards();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "../../../styles/sales-common.scss";
|
|
.hazard-list {
|
min-height: 100vh;
|
background: #f8f9fa;
|
padding-bottom: 40rpx;
|
}
|
|
.top-actions {
|
padding: 20rpx;
|
display: flex;
|
justify-content: flex-end;
|
}
|
|
.action-buttons {
|
display: flex;
|
justify-content: flex-end;
|
gap: 20rpx;
|
padding-bottom: 30rpx;
|
}
|
|
.fixed-btn {
|
width: 160rpx;
|
margin: 0 !important;
|
}
|
|
.no-data {
|
padding-top: 200rpx;
|
}
|
</style>
|