zhangwencui
7 小时以前 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<template>
  <view class="line-inspection">
    <PageHeader title="线路巡检"
                @back="goBack" />
    <view class="search-section">
      <view class="search-bar">
        <view class="search-input">
          <up-input class="search-text"
                    placeholder="请输入巡检编号/巡检名称/线路名称"
                    v-model="keyword"
                    @change="handleQuery"
                    clearable />
        </view>
        <view class="filter-button"
              @click="handleQuery">
          <up-icon name="search"
                   size="24"
                   color="#999"></up-icon>
        </view>
      </view>
    </view>
    <scroll-view scroll-y
                 class="list-scroll ledger-list"
                 @scrolltolower="loadMore"
                 v-if="list.length > 0">
      <view v-for="row in list"
            :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.inspectionCode || "-" }}</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.inspectionName || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">线路名称</text>
            <text class="detail-value">{{ row.lineName || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">巡检类型</text>
            <text class="detail-value">{{ row.inspectionType || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">计划巡检时间</text>
            <text class="detail-value">{{ row.planTime || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">巡检人</text>
            <text class="detail-value">{{ row.inspectorName || "-" }}</text>
          </view>
        </view>
        <view class="action-buttons action-buttons-bottom">
          <u-button size="small"
                    class="action-btn fixed-btn"
                    :disabled="!canEdit(row)"
                    @click.stop="goEdit(row)">编辑</u-button>
          <u-button size="small"
                    class="action-btn fixed-btn"
                    type="primary"
                    @click.stop="goRecords(row)">巡检记录</u-button>
          <u-button size="small"
                    class="action-btn fixed-btn"
                    type="primary"
                    @click.stop="goHazards(row)">隐患管理</u-button>
          <u-button v-if="String(row.status) === '巡检中'"
                    size="small"
                    class="action-btn fixed-btn"
                    type="success"
                    @click.stop="handleComplete(row)">
            完成巡检
          </u-button>
          <u-button size="small"
                    class="action-btn fixed-btn"
                    type="error"
                    :disabled="!canDelete(row)"
                    @click.stop="handleDelete(row)">删除</u-button>
        </view>
      </view>
      <up-loadmore :status="loadStatus" />
    </scroll-view>
    <view v-else
          class="no-data">
      <up-empty mode="data"
                text="暂无数据"></up-empty>
    </view>
    <view class="fab-button"
          @click="goAdd">
      <up-icon name="plus"
               size="24"
               color="#ffffff"></up-icon>
    </view>
  </view>
</template>
 
<script setup>
  import { onMounted, reactive, ref } from "vue";
  import { onShow } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import {
    completeLineInspection,
    deleteLineInspection,
    getLineInspectionList,
  } from "@/api/safeProduction/lineInspection";
 
  const keyword = ref("");
 
  const page = reactive({ current: 1, size: 20, total: 0 });
  const list = ref([]);
  const loadStatus = ref("loadmore");
  const loading = ref(false);
 
  const goBack = () => {
    uni.navigateBack();
  };
 
  const statusType = status => {
    const map = {
      待巡检: "info",
      巡检中: "warning",
      已完成: "success",
    };
    return map[status] || "info";
  };
 
  const canEdit = row => String(row?.status) === "待巡检";
  const canDelete = row => String(row?.status) === "待巡检";
 
  const fetchList = () => {
    if (loading.value) return;
    loading.value = true;
    loadStatus.value = "loading";
    const kw = String(keyword.value || "").trim();
    getLineInspectionList({
      inspectionCode: kw,
      inspectionName: kw,
      lineName: kw,
      ...page,
    })
      .then(res => {
        const records = res?.data?.records || [];
        const total = Number(res?.data?.total || 0);
        page.total = total;
        list.value = page.current === 1 ? records : [...list.value, ...records];
        loadStatus.value =
          list.value.length >= page.total ? "nomore" : "loadmore";
      })
      .catch(() => {
        loadStatus.value = "loadmore";
        uni.showToast({ title: "加载失败", icon: "none" });
      })
      .finally(() => {
        loading.value = false;
      });
  };
 
  const handleQuery = () => {
    page.current = 1;
    list.value = [];
    fetchList();
  };
 
  const loadMore = () => {
    if (loadStatus.value !== "loadmore") return;
    page.current++;
    fetchList();
  };
 
  const goAdd = () => {
    uni.navigateTo({ url: "/pages/safeProduction/lineInspection/edit" });
  };
 
  const goEdit = row => {
    const data = encodeURIComponent(JSON.stringify(row || {}));
    uni.navigateTo({
      url: `/pages/safeProduction/lineInspection/edit?data=${data}`,
    });
  };
 
  const goRecords = row => {
    const params = encodeURIComponent(
      JSON.stringify({ inspectionId: row.id, inspectionStatus: row.status || "" })
    );
    uni.navigateTo({
      url: `/pages/safeProduction/lineInspection/recordList?data=${params}`,
    });
  };
 
  const goHazards = row => {
    const params = encodeURIComponent(
      JSON.stringify({ inspectionId: row.id, inspectionStatus: row.status || "" })
    );
    uni.navigateTo({
      url: `/pages/safeProduction/lineInspection/hazardList?data=${params}`,
    });
  };
 
  const handleDelete = row => {
    if (!row?.id) return;
    uni.showModal({
      title: "删除",
      content: "确认删除该巡检任务吗?",
      success: res => {
        if (!res.confirm) return;
        uni.showLoading({ title: "删除中...", mask: true });
        deleteLineInspection([row.id])
          .then(() => {
            uni.showToast({ title: "删除成功", icon: "success" });
            handleQuery();
          })
          .catch(() => {
            uni.showToast({ title: "删除失败", icon: "none" });
          })
          .finally(() => {
            uni.hideLoading();
          });
      },
    });
  };
 
  const handleComplete = row => {
    if (!row?.id) return;
    uni.showModal({
      title: "完成巡检",
      content: "确认完成该巡检任务吗?",
      success: res => {
        if (!res.confirm) return;
        uni.showLoading({ title: "提交中...", mask: true });
        completeLineInspection(row.id)
          .then(() => {
            uni.showToast({ title: "巡检已完成", icon: "success" });
            handleQuery();
          })
          .catch(() => {
            uni.showToast({ title: "操作失败", icon: "none" });
          })
          .finally(() => {
            uni.hideLoading();
          });
      },
    });
  };
 
  onMounted(() => {
    handleQuery();
  });
 
  onShow(() => {
    handleQuery();
  });
</script>
 
<style scoped lang="scss">
  @import "../../../styles/sales-common.scss";
 
  .line-inspection {
    min-height: 100vh;
    background: #f8f9fa;
    position: relative;
    padding-bottom: 140rpx;
  }
 
  .list-scroll {
    flex: 1;
    min-height: 0;
  }
 
  .action-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 20rpx;
    padding-bottom: 30rpx;
  }
 
  .fixed-btn {
    width: 160rpx;
    margin: 0 !important;
  }
 
  .fab-button {
    position: fixed;
    right: 30rpx;
    bottom: 140rpx;
    width: 96rpx;
    height: 96rpx;
    background: #3c9cff;
    border-radius: 48rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8rpx 24rpx rgba(60, 156, 255, 0.3);
    z-index: 1001;
  }
 
  .no-data {
    padding-top: 200rpx;
  }
</style>