zhangwencui
2 天以前 34af9a2cd41fb88985d05d57e9fa425bc98990cc
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
<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>