<template>
|
<view class="list_box">
|
<z-paging ref="pagingRef" v-model="cardList" :fixed="false" :auto-show-back-to-top="true">
|
<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" emitName="scanTime" />
|
<wd-toast />
|
</view>
|
</template>
|
|
<script setup lang="ts">
|
import CardTitle from "@/components/card-title/index.vue";
|
import zPaging from "@/components/z-paging/z-paging.vue";
|
import Scan from "@/components/scan/index.vue";
|
import MonofilCard from "../production/twist/components/MonofilCard.vue";
|
import TwistApi from "@/api/product/twist";
|
import { useToast } from "wot-design-uni";
|
|
const pagingRef = ref();
|
const scanRef = ref();
|
const toast = useToast();
|
const cardList = ref<any>([]);
|
|
const getScanCode = async (code: any) => {
|
console.log("时效扫码回调:", code);
|
console.log("json:", JSON.parse(code.code));
|
console.log("id:=============", JSON.parse(code.code).id);
|
const { data } = await TwistApi.getScarn({
|
outPutId: JSON.parse(code.code).id,
|
});
|
console.log("=======请求========", data);
|
const exists = cardList.value.some(
|
(item: any) => item.monofilamentNumber === data.monofilamentNumber
|
);
|
if (!exists) {
|
const { id, outPutId, wireId, oneLength, ...rest } = data;
|
console.log("sb", {
|
outputId: id,
|
amount: oneLength,
|
ongLength: oneLength,
|
...rest,
|
});
|
cardList.value.push({
|
outputId: id,
|
amount: oneLength,
|
ongLength: oneLength,
|
...rest,
|
});
|
pagingRef.value.complete(cardList.value);
|
} else {
|
toast.error("该单丝已领用,请勿重复扫码");
|
}
|
};
|
const save = async () => {
|
const { code } = await TwistApi.saveAge(cardList.value);
|
if (code == 200) {
|
toast.success("保存成功");
|
pagingRef.value.refresh();
|
} else {
|
toast.error("保存失败");
|
}
|
};
|
|
const openScan = () => {
|
scanRef.value.triggerScan();
|
};
|
|
// 确保先移除再添加监听
|
const setupScanListener = () => {
|
uni.$off("scanTime", getScanCode); // 先移除旧的
|
uni.$on("scanTime", getScanCode); // 再添加新的
|
};
|
|
onMounted(() => {
|
setupScanListener();
|
console.log("页面显示 - 扫码监听已设置");
|
});
|
|
onUnmounted(() => {
|
// 开启广播监听事件
|
uni.$off("scanTime", getScanCode);
|
console.log("页面卸载 - 扫码监听已移除");
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.list_box {
|
height: calc(100vh - 100px);
|
background: #f3f9f8;
|
}
|
:deep(.wd-button__content) {
|
color: #0d867f;
|
}
|
</style>
|