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
<template>
  <view class="record-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="records.length > 0">
      <view v-for="row in records"
            :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.checkPoint || "-" }}</text>
          </view>
          <view class="item-right">
            <up-tag :text="row.checkResult || '-'"
                    :type="row.checkResult === '正常' ? 'success' : 'error'"
                    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.checkContent || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">检查说明</text>
            <text class="detail-value">{{ row.checkDesc || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">检查时间</text>
            <text class="detail-value">{{ row.checkTime || "-" }}</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 size="small"
                    class="action-btn fixed-btn"
                    type="error"
                    :disabled="isCompleted"
                    @click.stop="handleDelete(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 {
    deleteInspectionRecord,
    getInspectionRecords,
  } from "@/api/safeProduction/lineInspection";
 
  const inspectionId = ref(null);
  const inspectionStatus = ref("");
  const records = ref([]);
 
  const isCompleted = computed(() => String(inspectionStatus.value) === "已完成");
 
  const goBack = () => {
    uni.navigateBack();
  };
 
  const fetchRecords = () => {
    if (!inspectionId.value) return;
    uni.showLoading({ title: "加载中...", mask: true });
    getInspectionRecords(inspectionId.value)
      .then(res => {
        records.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/recordEdit?data=${data}`,
    });
  };
 
  const goEdit = row => {
    const data = encodeURIComponent(
      JSON.stringify({ inspectionId: inspectionId.value, row })
    );
    uni.navigateTo({
      url: `/pages/safeProduction/lineInspection/recordEdit?data=${data}`,
    });
  };
 
  const handleDelete = row => {
    if (!row?.id) return;
    uni.showModal({
      title: "删除",
      content: "确认删除该巡检记录吗?",
      success: res => {
        if (!res.confirm) return;
        uni.showLoading({ title: "删除中...", mask: true });
        deleteInspectionRecord([row.id])
          .then(() => {
            uni.showToast({ title: "删除成功", icon: "success" });
            fetchRecords();
          })
          .catch(() => {
            uni.showToast({ title: "删除失败", icon: "none" });
          })
          .finally(() => {
            uni.hideLoading();
          });
      },
    });
  };
 
  onMounted(() => {
    uni.$on("lineInspection:recordsRefresh", fetchRecords);
  });
 
  onLoad(options => {
    if (options?.data) {
      try {
        const obj = JSON.parse(decodeURIComponent(options.data));
        inspectionId.value = obj.inspectionId;
        inspectionStatus.value = obj.inspectionStatus || "";
      } catch (e) {}
    }
  });
 
  onShow(() => {
    fetchRecords();
  });
</script>
 
<style scoped lang="scss">
  @import "../../../styles/sales-common.scss";
 
  .record-list {
    min-height: 100vh;
    background: #f8f9fa;
    padding-bottom: 40rpx;
  }
 
  .top-actions {
    padding: 20rpx;
    display: flex;
    justify-content: flex-end;
  }
 
  .list-scroll {
    flex: 1;
    min-height: 0;
  }
 
  .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>