ckgl/pages/whiteEmbryo/w-scanCode.vue
2025-01-18 17:29:34 +08:00

161 lines
4.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<van-nav-bar
title="扫码入库"
left-text="返回"
left-arrow
right-text="扫一扫"
@click-left="onClickLeft"
@click-right="onClickRight"
/>
<view style="text-align: center;margin-top: 20px;">请扫描库位码</view>
<cshaptx4869-scancode
v-if="h5ScanCode"
@success="handleSuccess"
@fail="handleFail"
@close="handleClose"
></cshaptx4869-scancode>
</view>
</template>
<script setup lang="ts">
import { showConfirmDialog, showToast } from 'vant';
import { onMounted, ref } from 'vue';
import { putAction } from '../../common/http';
onMounted(()=>{
})
const onClickLeft = () =>{
window.history.back()
}
const onClickRight=()=>{
scanCode()
}
const h5ScanCode = ref(false);
function scanCode() {
// #ifdef H5
h5ScanCode.value = true;
// #endif
// #ifndef H5
uni.scanCode({
success: (res) => {
uni.showToast({
icon: "none",
title: res.result,
});
},
faile: (err) => {
console.log("err", err);
location.value=''
barcode.value=''
},
});
// #endif
}
const barcode = ref()
const location = ref()
function handleSuccess(res:any) {
h5ScanCode.value = false;
if(location.value){
barcode.value=res
putAction('/rawFabric/sign',{barcode:barcode.value,location:location.value},{'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}).then((res1:any)=>{
if(res1.code===7778){//已经入库
let data=JSON.parse(res1.msg)
let html=`
<p>面料编号为<span style="color:red;font-size:18px">${barcode.value}</span>的<span style="color:red;font-size:18px">${data.category}</span>已放置在<span style="color:red;font-size:18px">${data.location}</span>,是否将面料移动到<span style="color:red;font-size:18px">${location.value}</span></p>
`
showConfirmDialog({
message: html,
allowHtml:true,
confirmButtonText:'确认',
})
.then(() => {
putAction('/rawFabric/sign',{barcode:barcode.value,location:location.value,force:true},{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'}).then((res2:any)=>{
if(res2.code===200){
showToast('入货架成功!')
}else{
showToast(res2.msg)
}
})
})
.catch(() => {
location.value=''
barcode.value=''
});
}else if(res1.code===7777){
//暂存
let data=JSON.parse(res1.msg)
let html=`
<p>面料编号为<span style="color:red;font-size:18px">${barcode.value}</span>的<span style="color:red;font-size:18px">${data.category}</span>被暂存在检验室,是否确认移动到<span style="color:red;font-size:18px">${location.value}</span></p>
`
showConfirmDialog({
message: html,
allowHtml:true,
confirmButtonText:'确认',
})
.then(() => {
putAction('/rawFabric/sign',{barcode:barcode.value,location:location.value,force:true},{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'}).then((res2:any)=>{
if(res2.code===200){
showToast('入货架成功!')
}else{
showToast(res2.msg)
}
})
})
.catch(() => {
location.value=''
barcode.value=''
});
}else if(res1.code===200) {
showConfirmDialog({
title: '扫码成功,请扫描面料编号',
message:'货架号:'+location.value,
confirmButtonText:'扫一扫',
})
.then(() => {
scanCode()
})
.catch(() => {
location.value=''
barcode.value=''
});
}else{
showToast(res1.msg)
}
})
}else{
location.value=res
showConfirmDialog({
title: '扫码成功,请扫描面料编号',
message:'货架号:'+location.value,
confirmButtonText:'扫一扫',
})
.then(() => {
scanCode()
})
.catch(() => {
location.value=''
barcode.value=''
});
}
}
function handleFail(err) {
uni.showModal({
title: err.errName,
content: err.errMsg,
complete: () => {
h5ScanCode.value = false;
},
});
}
function handleClose() {
h5ScanCode.value = false;
}
</script>
<style lang="scss" scoped>
</style>