曹睿
2025-05-21 fe6dbaaefef6dd9bb4a1ee26df8ad8b451500a10
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
<template>
  <view class="list_box">
    <z-paging
      ref="pagingRef"
      v-model="cardList"
      :fixed="false"
      :auto-show-back-to-top="true"
      @query="getList"
    >
      <template #top>
        <CardTitle title="单丝领用" :hideAction="false">
          <template #action>
            <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
          </template>
        </CardTitle>
      </template>
      <MonofilCard v-for="(item, index) in cardList" :key="index" :data="item" />
      <template #bottom>
        <view class="flex justify-center items-center">
          <wd-button block @click="save">
            <text class="text-[#fff]">保存</text>
          </wd-button>
        </view>
      </template>
    </z-paging>
    <Scan ref="scanRef" />
    <wd-toast />
  </view>
</template>
 
<script setup lang="ts">
import CardTitle from "@/components/card-title/index.vue";
import MonofilCard from "../components/MonofilCard.vue";
import { useToast } from "wot-design-uni";
import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
import Scan from "@/components/scan/index.vue";
import ManageApi from "@/api/product/manage";
import TwistApi from "@/api/product/twist";
import zPaging from "@/components/z-paging/z-paging.vue";
// import { useZebraScan } from "@/hooks/useZebraScan";
// const { init, start, stop, triggerScan } = useZebraScan();
 
const paramsId = ref();
const pagingRef = ref();
const scanRef = ref();
const cardList = ref<any[]>([]);
const toast = useToast();
 
const getScanCode = async (code: any) => {
  // console.log("自定义扫描的结果回调函数:", code);
  // let parseData = code.trim();
  console.log("code:===========", JSON.parse(code.code));
  console.log("id:=============", JSON.parse(code.code).id);
  const { data } = await TwistApi.getScarn({
    outPutId: JSON.parse(code.code).id,
  });
  const exists = cardList.value.some((item) => item.monofilamentNumber === data.monofilamentNumber);
  if (!exists) {
    const { id, outPutId, wireId, oneLength, ...rest } = data;
    console.log("sb", {
      wireId: paramsId.value,
      outputId: id,
      amount: oneLength,
      ongLength: oneLength,
      ...rest,
    });
    cardList.value.push({
      wireId: paramsId.value,
      outputId: id,
      amount: oneLength,
      ongLength: oneLength,
      ...rest,
    });
    pagingRef.value.complete(cardList.value);
  } else {
    toast.error("该单丝已领用,请勿重复扫码");
  }
};
 
const openScan = () => {
  scanRef.value.triggerScan();
};
 
const getList = async () => {
  const { code, data } = await ManageApi.getStrandedWireDish({
    wireId: paramsId.value,
    type: "单丝",
  });
  if (code == 200) {
    pagingRef.value.complete(data);
  }
};
 
const save = async () => {
  const { code } = await TwistApi.addStrandedWireDish(cardList.value);
  if (code == 200) {
    toast.success("保存成功");
    pagingRef.value.refresh();
  } else {
    toast.error("保存失败");
  }
};
 
onLoad((options: any) => {
  // 开启广播监听事件
  uni.$on("scan", getScanCode);
  paramsId.value = options.id;
});
onUnload(() => {
  // 开启广播监听事件
  uni.$off("scan", getScanCode);
});
 
onShow(() => {});
 
onHide(() => {});
</script>
 
<style lang="scss" scoped>
.list_box {
  height: calc(100vh - 100px);
  background: #f3f9f8;
}
:deep(.wd-button__content) {
  color: #0d867f;
}
</style>