spring
2025-11-20 5384750e59bbb27c54e090100429c48eaba46df0
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<template>
  <view class="report-manage-page">
    <view class="pt-2 fixed-header-card">
      <wd-card class="card_bg header-card">
        <template #title>
          <view class="flex justify-between w-full">
            <text class="font-medium text-[#252525]">报工管理</text>
            <wd-button
              icon="file-add"
              :round="false"
              size="small"
              custom-class="add_btn"
              @click="handleAdd"
            >
              新增
            </wd-button>
          </view>
        </template>
        <wd-row class="my-2">
          <wd-col :span="24">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                领用杆号:
                <text class="text-[#252525]">{{ parentData?.poleNumber || "" }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="24">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                杆型号:
                <text class="text-[#252525]">{{ parentData?.poleModel || "" }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="24">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                杆包号:
                <text class="text-[#252525]">{{ parentData?.polePackageNumber || "" }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="24">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                杆重:
                <text class="text-[#252525]">{{ parentData?.poleWeight || "" }}kg</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
      </wd-card>
    </view>
 
    <view class="page-content">
      <wd-card
        v-for="(child, childIndex) in childList"
        :key="child.id || child.tempId || childIndex"
        class="card_bg"
      >
        <template #title>
          <text class="font-medium text-[#252525]">单丝盘号: {{ child.monofilamentNumber }}</text>
        </template>
        <wd-row class="my-2" v-if="child.model">
          <wd-col :span="12">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                规格型号:
                <text class="text-[#252525]">{{ child.model }}</text>
              </text>
            </view>
          </wd-col>
          <wd-col :span="12">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                盘型号:
                <text class="text-[#252525]">{{ child.dishModel }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="12" v-if="child.oneLength">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                盘长(m):
                <text class="text-[#252525]">{{ child.oneLength }}</text>
              </text>
            </view>
          </wd-col>
          <wd-col :span="12" v-if="child.isJoint !== undefined && child.isJoint !== null">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                是否接头:
                <text class="text-[#252525]">
                  {{ child.isJoint === 1 ? "是" : child.isJoint === 0 ? "否" : "" }}
                </text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="14" v-if="child.actuallyLength">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                实际长度(m):
                <text class="text-[#252525]">{{ child.actuallyLength }}</text>
              </text>
            </view>
          </wd-col>
          <wd-col :span="10" v-if="child.productUser">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                生产人:
                <text class="text-[#252525]">{{ child.productUser }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="24" v-if="child.actuallyWeight">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                实际重量(kg):
                <text class="text-[#252525]">{{ child.actuallyWeight }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="24" v-if="child.productTime">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                生产日期:
                <text class="text-[#252525]">{{ child.productTime }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <wd-row class="my-2">
          <wd-col :span="24" v-if="child.processHour">
            <view class="flex">
              <view class="icon_box">
                <wd-icon name="folder" color="#0D867F"></wd-icon>
              </view>
              <text class="text-[#646874] mx-2">
                加工时间(h):
                <text class="text-[#252525]">{{ child.processHour }}</text>
              </text>
            </view>
          </wd-col>
        </wd-row>
        <template #footer>
          <view class="flex gap-2">
            <wd-button plain size="small" @click="toAttachment(child)" style="margin-right: 10px">
              附件
            </wd-button>
            <wd-button plain type="error" size="small" @click="handleDeleteSingle(child)">
              删除
            </wd-button>
          </view>
        </template>
      </wd-card>
    </view>
 
    <!-- 新增报工弹框 -->
    <wd-popup v-model="addDialogVisible" position="bottom" custom-class="yl-popup">
      <view class="add-dialog">
        <view class="dialog-header">
          <text class="dialog-title">新增报工</text>
          <wd-icon name="close" class="close-icon" @click="closeAddDialog"></wd-icon>
        </view>
        <view class="dialog-content">
          <wd-cell-group>
            <wd-input
              v-model="newChildData.dishModel"
              label="盘型号"
              label-width="100px"
              placeholder="请输入盘型号"
            />
            <wd-input
              v-model="newChildData.actuallyLength"
              label="实际长度(m)"
              label-width="100px"
              type="number"
              placeholder="请输入实际长度"
            />
            <wd-input
              v-model="newChildData.actuallyWeight"
              label="实际重量(kg)"
              label-width="100px"
              type="number"
              placeholder="请输入实际重量"
            />
            <wd-cell title="是否接头" label-width="100px">
              <wd-radio-group v-model="newChildData.isJoint">
                <wd-radio :value="1">是</wd-radio>
                <wd-radio :value="0">否</wd-radio>
              </wd-radio-group>
            </wd-cell>
          </wd-cell-group>
        </view>
        <view class="dialog-footer">
          <wd-button plain @click="closeAddDialog" style="margin-right: 10px">取消</wd-button>
          <wd-button type="primary" class="ml-2" @click="handleSaveNewChild">保存</wd-button>
        </view>
      </view>
    </wd-popup>
 
    <wd-toast />
  </view>
</template>
 
<script setup lang="ts">
import { ref, watch, nextTick } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { useToast, dayjs } from "wot-design-uni";
import WireApi from "@/api/product/wire";
import { getTeamId } from "@/utils/cache";
import { useUserStore } from "@/store/modules/user";
 
const toast = useToast();
const userStore = useUserStore();
 
const paramsId = ref();
const parentData = ref<any>(null);
const childList = ref<any[]>([]);
const model = ref();
const oneLength = ref();
const allChildDataList = ref<any[]>([]);
const wireDetail = ref<any>(null);
 
// 新增弹框相关
const addDialogVisible = ref(false);
const newChildData = ref({
  dishModel: "",
  actuallyLength: "",
  actuallyWeight: "",
  isJoint: 0,
  meterWeight: 0, // 米重
});
 
// 获取详情数据
const getDetailData = async (id: string) => {
  try {
    const { data } = await WireApi.getWireDetailById({ id });
    wireDetail.value = data;
    model.value = data.model;
    oneLength.value = data.oneLength;
  } catch (error) {
    console.error("获取详情失败:", error);
  }
};
 
// 初始化数据
const getData = async () => {
  try {
    const { code, data } = await WireApi.getWireOutputTree({
      wireId: paramsId.value,
    });
 
    if (code == 200) {
      allChildDataList.value = [];
      const parentMap = new Map();
 
      data.forEach((item: any) => {
        const parentKey = `${item.poleNumber}-${item.poleModel}-${item.polePackageNumber}`;
 
        if (item.node && Array.isArray(item.node)) {
          item.node.forEach((child: any) => {
            const childData = {
              ...child,
              parentKey: parentKey,
              poleNumber: item.poleNumber,
              poleModel: item.poleModel,
              polePackageNumber: item.polePackageNumber,
              supplier: item.supplier,
            };
            allChildDataList.value.push(childData);
          });
        }
      });
 
      // 刷新当前页面的子级列表
      const parentKey = `${parentData.value.poleNumber}-${parentData.value.poleModel}-${parentData.value.polePackageNumber}`;
      childList.value = allChildDataList.value
        .filter((child) => child.parentKey === parentKey)
        .map((child, index) => ({
          ...child,
          customIndex: index + 1,
          selected: false,
        }));
    }
  } catch (error) {
    console.error("获取数据失败:", error);
    toast.error("获取数据失败");
  }
};
 
// 打开新增弹框
const handleAdd = () => {
  const lastChild = childList.value[childList.value.length - 1];
 
  // 从详情数据中获取米重
  const meterWeight =
    Number(wireDetail.value?.meterWeight) ||
    Number(wireDetail.value?.weight) ||
    Number(wireDetail.value?.theoryWeight) ||
    0;
 
  // 初始化新数据,如果有最后一条数据,使用其值作为默认值
  newChildData.value = {
    dishModel: lastChild?.dishModel || "",
    actuallyLength: lastChild?.actuallyLength || "",
    actuallyWeight: lastChild?.actuallyWeight || "",
    isJoint: lastChild?.isJoint || 0,
    meterWeight: meterWeight,
  };
 
  addDialogVisible.value = true;
};
 
// 保存新增的子级数据
const handleSaveNewChild = async () => {
  if (!newChildData.value.actuallyLength || !newChildData.value.actuallyWeight) {
    toast.error("请输入完整信息(实际长度和重量为必填项)");
    return;
  }
 
  const lastChild = childList.value[childList.value.length - 1];
 
  // 生成新的单丝盘号
  const newMonofilamentNumber = addMonofilamentNumber(lastChild?.monofilamentNumber, "拉丝");
 
  const newChild = {
    id: null,
    tempId: `temp_${Date.now()}`,
    parentKey: `${parentData.value.poleNumber}-${parentData.value.poleModel}-${parentData.value.polePackageNumber}`,
    teamId: getTeamId(),
    type: "拉丝",
    wireId: paramsId.value,
    poleNumber: parentData.value.poleNumber,
    poleModel: parentData.value.poleModel,
    supplier: parentData.value.supplier,
    polePackageNumber: parentData.value.polePackageNumber,
    dishModel: newChildData.value.dishModel || null,
    poleWeight: parentData.value.poleWeight,
    monofilamentNumber: newMonofilamentNumber,
    model: model.value || "",
    oneLength: oneLength.value || null,
    theoryWeight: lastChild?.theoryWeight || null,
    actuallyLength: newChildData.value.actuallyLength,
    actuallyWeight: newChildData.value.actuallyWeight,
    processHour: lastChild?.processHour || null,
    productUser: userStore.userInfo?.nickname || userStore.userInfo?.nickName || "",
    productTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
    customIndex: childList.value.length + 1,
    isJoint: newChildData.value.isJoint,
    selected: false,
  };
 
  // 为每个子级数据添加杆重信息
  const childrenWithPoleWeight = [
    {
      ...newChild,
      poleWeight: parentData.value.poleWeight,
    },
  ];
 
  try {
    const { code, data } = await WireApi.addWireOutputList(childrenWithPoleWeight);
    if (code == 200) {
      if (data) {
        toast.warning(data);
      } else {
        toast.success("保存成功");
      }
      closeAddDialog();
      await getData();
    }
  } catch (error) {
    console.error("保存失败:", error);
    toast.error("保存失败");
  }
};
 
// 关闭新增弹框
const closeAddDialog = () => {
  addDialogVisible.value = false;
  // 重置表单数据
  newChildData.value = {
    dishModel: "",
    actuallyLength: "",
    actuallyWeight: "",
    isJoint: 0,
    meterWeight: 0,
  };
};
 
// 生成新的单丝盘号
const addMonofilamentNumber = (val: string, type: string) => {
  if (val) {
    if (type == "拉丝") {
      const arr = val.split("-");
      if (arr.length >= 3) {
        const prefix = `${arr[0]}-${arr[1]}`;
 
        let count = 0;
        allChildDataList.value.forEach((child) => {
          if (child.monofilamentNumber) {
            const childArr = child.monofilamentNumber.split("-");
            if (childArr.length >= 3) {
              const childPrefix = `${childArr[0]}-${childArr[1]}`;
              if (childPrefix === prefix) {
                count++;
              }
            }
          }
        });
 
        childList.value.forEach((child) => {
          if (child.monofilamentNumber && !child.id) {
            const childArr = child.monofilamentNumber.split("-");
            if (childArr.length >= 3) {
              const childPrefix = `${childArr[0]}-${childArr[1]}`;
              if (childPrefix === prefix) {
                count++;
              }
            }
          }
        });
 
        const a = count + 1;
        const paddedA = a < 10 ? `0${a}` : `${a}`;
        return `${prefix}-${paddedA}`;
      }
    }
  }
  return "";
};
 
// 跳转到附件页面
const toAttachment = (item: any) => {
  uni.navigateTo({
    url: "/pages/production/wire/attachment/index",
    success: () => {
      // 页面跳转成功后发送事件传递数据
      uni.$emit("detailData", item);
    },
    fail: (error) => {
      console.error("跳转附件页面失败:", error);
      toast.error("跳转失败");
    },
  });
};
 
// 删除单个子级数据
const handleDeleteSingle = async (child: any) => {
  try {
    const res = await uni.showModal({
      title: "提示",
      content: `确定删除这条数据吗?`,
    });
 
    if (res.confirm) {
      // 如果是已保存的数据,调用删除接口
      if (child.id) {
        await WireApi.deleteWireOutput({ id: child.id });
        await getData();
        toast.success("删除成功");
      } else {
        // 如果是未保存的数据,直接从列表中移除
        const index = childList.value.findIndex((row) => row.tempId === child.tempId);
        if (index !== -1) {
          childList.value.splice(index, 1);
          // 重新计算序号
          childList.value.forEach((item, idx) => {
            item.customIndex = idx + 1;
          });
          toast.success("删除成功");
        }
      }
    }
  } catch (error) {
    console.error("删除失败:", error);
    toast.error("删除失败");
  }
};
 
// 自动计算实际重量
const handleCalculateWeight = (row: any) => {
  // 从 newChildData 对象中获取米重
  const meterWeight = Number(row.meterWeight) || 0;
  const actuallyLength = Number(row.actuallyLength);
 
  if (meterWeight > 0 && actuallyLength > 0) {
    const calculatedWeight = (meterWeight * actuallyLength) / 1000;
    row.actuallyWeight = Number(calculatedWeight.toFixed(3));
  }
  console.log("row", meterWeight, actuallyLength);
};
 
// 监听实际长度变化,自动计算重量
watch(
  () => newChildData.value.actuallyLength,
  (newValue, oldValue) => {
    console.log("实际长度变化:", { newValue, oldValue, newChildData: newChildData.value });
    if (newValue && String(newValue).trim() !== "") {
      // 使用 nextTick 确保 v-model 已经更新
      nextTick(() => {
        handleCalculateWeight(newChildData.value);
      });
    }
  },
  { immediate: false, deep: true }
);
 
onLoad(async (options: any) => {
  paramsId.value = options.wireId;
 
  // 从页面参数中获取父级数据
  parentData.value = {
    id: options.parentId,
    poleNumber: options.poleNumber,
    poleModel: options.poleModel,
    polePackageNumber: options.polePackageNumber,
    poleWeight: options.poleWeight,
    supplier: options.supplier,
  };
 
  await getDetailData(options.wireId);
  await getData();
});
</script>
 
<style lang="scss" scoped>
.report-manage-page {
  min-height: 100vh;
  background: #f3f9f8;
  padding: 0 4px 20px 4px;
}
 
.card_bg {
  box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.05);
  padding-bottom: 10px;
}
 
.fixed-header-card {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #f3f9f8;
  padding: 8px 0;
}
 
.header-card {
  border: none;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}
 
.icon_box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #e7f4ec99;
  border-radius: 50%;
}
 
:deep() {
  .add_btn {
    border-radius: 4px;
  }
}
 
.add-dialog {
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px 12px 0 0;
}
 
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #e6e6e6;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}
 
.dialog-title {
  font-size: 16px;
  color: #333;
  font-weight: 500;
}
 
.close-icon {
  font-size: 20px;
  color: #999;
  padding: 4px;
}
 
.dialog-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
 
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 16px;
  border-top: 1px solid #e6e6e6;
  gap: 8px;
}
 
.page-content {
  padding: 12px 4px;
  margin-top: 12px;
}
 
// 弹框 z-index 需要高于固定头部卡片
:deep(.yl-popup) {
  z-index: 400 !important;
}
 
// 弹框遮罩层 z-index 也需要高于固定头部卡片(使用更高的值确保在固定头部之上)
:deep(.wd-popup__mask),
:deep(.wd-popup-mask),
:deep([class*="popup"][class*="mask"]),
:deep(.wd-overlay),
:deep([class*="overlay"]) {
  z-index: 300 !important;
}
.wd-card {
  margin-left: 5px;
  margin-right: 5px;
  margin-top: 0px;
}
</style>
 
<style lang="scss">
// 全局样式:确保弹框遮罩层 z-index 高于固定头部卡片
.wd-popup__mask,
.wd-popup-mask,
[class*="popup"][class*="mask"],
.wd-overlay,
[class*="overlay"] {
  z-index: 300 !important;
}
</style>