spring
2026-05-12 09f98ab6b6ac0779f12bd003443e1e6065cad256
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<template>
  <view class="report-entry-page">
    <PageHeader title="生产报工"
                @back="goBack" />
 
    <view class="scan-section">
      <view class="scan-card"
            @click="startScan">
        <up-icon name="scan"
                 size="28"
                 color="#2979ff" />
        <view class="scan-text-wrap">
          <text class="scan-title">扫码报工</text>
        </view>
        <up-icon name="arrow-right"
                 size="18"
                 color="#c0c4cc" />
      </view>
    </view>
 
    <scroll-view v-if="tableData.length > 0"
                 scroll-y
                 class="list-body"
                 @scrolltolower="loadMore">
      <view v-for="(item, index) in tableData"
            :key="item.id || index"
            class="ledger-item"
            @click="onCardClick(item)">
        <view class="item-header">
          <view class="item-left">
            <view class="document-icon">
              <up-icon name="file-text"
                       size="16"
                       color="#ffffff" />
            </view>
            <text class="item-id">{{ item.workOrderNo || "-" }}</text>
          </view>
          <view class="item-right operation-header-right">
            <view class="operation-pill">
              <text class="operation-pill-text">{{ operationNameOf(item) }}</text>
            </view>
            <view v-if="item.endOrder"
                  class="end-pill">
              <text class="end-pill-text">已结束</text>
            </view>
          </view>
        </view>
        <up-divider />
        <view class="item-details">
          <view class="detail-row">
            <text class="detail-label">生产订单号</text>
            <text class="detail-value">{{ item.npsNo || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">产品名称</text>
            <text class="detail-value">{{ item.productName || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">规格</text>
            <text class="detail-value">{{ item.model || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">单位</text>
            <text class="detail-value">{{ item.unit || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">需求数量</text>
            <text class="detail-value">{{ item.planQuantity ?? "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">完成数量</text>
            <text class="detail-value">{{ item.completeQuantity ?? "-" }}</text>
          </view>
        </view>
      </view>
      <up-loadmore :status="loadStatus" />
    </scroll-view>
 
    <view v-else-if="!loading"
          class="no-data">
      <up-empty mode="data"
                text="暂无工单数据" />
    </view>
  </view>
</template>
 
<script setup>
  import { ref, reactive } from "vue";
  import { onShow } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import { productWorkOrderPage } from "@/api/productionManagement/workOrder.js";
  import { getProductWorkOrderById } from "@/api/productionManagement/productionReporting";
  import modal from "@/plugins/modal";
  import useUserStore from "@/store/modules/user";
 
  const userStore = useUserStore();
 
  const loading = ref(false);
  const tableData = ref([]);
  const loadStatus = ref("loadmore");
 
  const page = reactive({
    current: 1,
    size: 10,
    total: 0,
  });
 
  const goBack = () => {
    uni.navigateBack();
  };
 
  const operationNameOf = item =>
    item?.operationName || item?.processName || "-";
 
  const reportPermissionMessage = row => {
    if (row.endOrder) return "该订单已结束,无法报工";
    const pq = Number(row.planQuantity);
    if (Number.isFinite(pq) && pq <= 0) return "待生产数量为0,无法报工";
    // if (row.userIds) {
    //   try {
    //     const userIds =
    //       typeof row.userIds === "string" ? JSON.parse(row.userIds) : row.userIds;
    //     if (
    //       Array.isArray(userIds) &&
    //       userIds.length > 0 &&
    //       !userIds.some(id => String(id) === String(userStore.id))
    //     ) {
    //       return "您不在该工单的指定报工人范围内";
    //     }
    //   } catch {
    //     return "工单报工权限校验失败";
    //   }
    // }
    return "";
  };
 
  const navigateToReport = orderRowStr => {
    uni.navigateTo({
      url: `/pages/productionManagement/productionReport/index?orderRow=${encodeURIComponent(orderRowStr)}`,
    });
  };
 
  const onCardClick = row => {
    const msg = reportPermissionMessage(row);
    if (msg) {
      uni.showToast({ title: msg, icon: "none" });
      return;
    }
    navigateToReport(JSON.stringify(row));
  };
 
  const handleQuery = () => {
    page.current = 1;
    tableData.value = [];
    getList();
  };
 
  const getList = () => {
    if (loading.value) return;
    loading.value = true;
    const params = { ...page };
    productWorkOrderPage(params)
      .then(res => {
        loading.value = false;
        const records = res.data?.records || [];
        tableData.value =
          page.current === 1 ? records : [...tableData.value, ...records];
        page.total = res.data?.total ?? 0;
        loadStatus.value =
          tableData.value.length >= page.total ? "nomore" : "loadmore";
      })
      .catch(() => {
        loading.value = false;
        uni.showToast({ title: "加载失败", icon: "none" });
      });
  };
 
  const loadMore = () => {
    if (loadStatus.value === "nomore" || loading.value) return;
    page.current++;
    getList();
  };
 
  const startScan = () => {
    uni.scanCode({
      success: async res => {
        const scanResult = res.result;
        let orderRow = "";
 
        const isNumericId = /^\d+$/.test(String(scanResult).trim());
 
        if (isNumericId) {
          const workOrderId = String(scanResult).trim();
          modal.loading("正在获取工单信息...");
          try {
            const workRes = await getProductWorkOrderById({ id: workOrderId });
            modal.closeLoading();
            if (workRes.code === 200 && workRes.data) {
              const workData = workRes.data;
              if (workData.endOrder === true) {
                modal.msgError("该订单已结束,无法报工");
                return;
              }
              orderRow = JSON.stringify(workData);
            } else {
              modal.msgError("未找到对应的工单信息");
              return;
            }
          } catch (error) {
            modal.closeLoading();
            modal.msgError(
              "获取工单信息失败: " + (error?.message || "未知错误")
            );
            return;
          }
        } else {
          try {
            const orderRowStart = scanResult.indexOf("orderRow={");
            if (orderRowStart !== -1) {
              orderRow = scanResult.substring(orderRowStart + 9);
            } else {
              orderRow = scanResult;
            }
            JSON.parse(orderRow);
          } catch {
            try {
              const parsed = JSON.parse(scanResult);
              orderRow = JSON.stringify(parsed);
            } catch {
              modal.msgError("订单解析失败,请检查二维码格式");
              return;
            }
          }
        }
 
        navigateToReport(orderRow);
      },
      fail: () => {
        uni.showToast({ title: "扫码失败", icon: "none" });
      },
    });
  };
 
  onShow(() => {
    handleQuery();
  });
</script>
 
<style scoped lang="scss">
  @import "@/styles/sales-common.scss";
 
  .report-entry-page {
    min-height: 100vh;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
  }
 
  .scan-section {
    padding: 12px 16px 8px;
  }
 
  .scan-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }
 
  .scan-text-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
 
  .scan-title {
    font-size: 16px;
    font-weight: 600;
    color: #303133;
  }
 
  .scan-desc {
    font-size: 12px;
    color: #909399;
  }
 
  .list-body {
    flex: 1;
    height: 0;
    padding: 12px 16px 20px;
    box-sizing: border-box;
  }
 
  .operation-header-right {
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
 
  .operation-pill {
    max-width: 58%;
    min-width: 0;
    padding: 5px 12px;
    border-radius: 20px;
    background: #e8f1ff;
    flex-shrink: 0;
  }
 
  .operation-pill-text {
    font-size: 12px;
    line-height: 1.35;
    color: #2979ff;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
  }
 
  .end-pill {
    padding: 5px 10px;
    border-radius: 20px;
    background: #fef0f0;
    flex-shrink: 0;
  }
 
  .end-pill-text {
    font-size: 12px;
    line-height: 1.35;
    color: #f56c6c;
    font-weight: 500;
  }
 
  .no-data {
    flex: 1;
    padding-top: 80px;
  }
</style>