feat:样品库管理

This commit is contained in:
houjunxiang
2025-11-20 17:23:48 +08:00
parent 0494d224be
commit 7ee3df9ab9
32 changed files with 910 additions and 235 deletions

View File

@@ -1,19 +1,10 @@
<template>
<view class="p8">
<navbar-back title="库位变更"></navbar-back>
<uni-section type="line" title="库位信息修改"> </uni-section>
<up-input
v-model="locationCode"
placeholder="请扫描库位编码"
prefixIcon="scan"
fontSize="16"
prefixIconStyle="font-size: 30px;"
>
</up-input>
<up-radio-group v-model="changeType">
<uni-section type="line" title="库位信息修改" titleFontSize="15px"> </uni-section>
<up-radio-group v-model="changeType" size="20px" @change="handleChangeType">
<up-radio
:customStyle="{ marginBottom: '8px' }"
:customStyle="{ marginLeft: '8px' }"
v-for="(item, index) in changeTypeOptions"
:key="index"
:label="item.label"
@@ -22,30 +13,56 @@
</up-radio>
</up-radio-group>
<up-input
v-model="sampleCode"
:placeholder="`请扫描${changeType == 'sample' ? '样品编号' : '库位码'}`"
v-model="changeCode"
:placeholder="`请扫描${changeType == 'sample' ? '样品编号' : '(原)库位码'}`"
prefixIcon="scan"
fontSize="16"
prefixIconStyle="font-size: 30px;"
@confirm="getSampleList()"
>
</up-input>
<up-input
v-if="changeCode !== '' && sampleList.length > 0"
class="mt20"
v-model="targetLocation"
placeholder="请扫描变更后库位码"
prefixIcon="scan"
fontSize="16"
prefixIconStyle="font-size: 30px;"
>
</up-input>
<uni-section type="line" title="样品及当前归库信息">
<uni-card>
<view
>样品名称<text>{{ sampleData.sampleName }}</text></view
>
<view class="mt4"
>样品名称<text>{{ sampleData.sampleCode }}</text></view
>
<view class="mt4"
>归库编码<text>{{ sampleData.sampleCode }}</text></view
>
<view class="mt4"
>()库位编码<text>{{ sampleData.sampleCode }}</text></view
>
</uni-card>
<uni-section v-if="sampleList.length > 0" type="line" title="样品及当前归库信息" titleFontSize="15px">
<template #right> <up-text type="error" size="18" bold :text="sampleList.length"></up-text></template>
<scroll-view style="height: 43vh" scroll-y scroll-with-animation>
<uni-card v-for="item in sampleList">
<view
>样品名称<text>{{ item.sampleName }}</text></view
>
<view class="mt4"
>归库编码<text>{{ item.sampleReturnCode }}</text></view
>
<view class="mt4"
>归库时间<text>{{ nx.$dayjs(item.returnTime).format('YYYY-MM-DD HH:mm:ss') }}</text></view
>
<view class="mt4"
>样品库名称<text>{{ item.warehouseName }}</text></view
>
<view class="mt4"
>()库位码<text>{{ item.warehouseLocationCode }}</text></view
>
</uni-card>
</scroll-view>
</uni-section>
<up-button class="mt20" type="primary" style="width: 50%" text="提交" @click="handleReset"></up-button>
<up-button
v-if="targetLocation"
:loading="btnLoading"
class="mt20"
type="primary"
style="width: 50%"
text="提交"
@click="handleSubmit"
></up-button>
</view>
</template>
@@ -61,87 +78,122 @@ const changeTypeOptions = reactive([
label: '按样品变更'
},
{
name: 'location',
name: 'warehouseLocation',
label: '按库位变更'
}
])
function isJsonString(str) {
if (typeof str !== 'string') return false
let targetLocation = ref('')
let changeCode = ref('')
let sampleList = ref([])
try {
const parsed = JSON.parse(str)
return typeof parsed === 'object' && parsed !== null
} catch (e) {
return false
}
}
const { scanQRInfo } = toRefs(nx.$store('biz'))
watch(scanQRInfo, newVal => {
if (newVal && nx.$router.getCurrentPage().route == 'pages/sampleWarehouse/returnToStock/index') {
try {
if (!isJsonString(newVal)) {
if (!locationCode.value) {
uni.showToast({
title: '请先扫描库位码',
icon: 'none'
})
scanQRInfo.value = ''
return
} else {
if (changeType.value == 'sample') {
sampleCode.value = newVal
} else {
}
// 执行
// handleReturnToStock()
}
} else {
const codeObj = JSON.parse(newVal)
locationCode.value = codeObj.code
}
scanQRInfo.value = ''
} catch (error) {
scanQRInfo.value = ''
uni.showToast({
title: '请扫描样品编码',
icon: 'none'
})
}
watch(changeCode, newVal => {
if (newVal === '') {
sampleList.value = []
targetLocation.value = ''
isFirstInput.value = true
}
})
async function getSampleList() {
if (changeCode.value === '') return
let params = { pageSize: 999, pageNo: 1, returnStatus: 'completed' }
if (changeType.value === 'sample') {
params.sampleReturnCode = changeCode.value
} else {
params.warehouseLocationCode = changeCode.value
}
const { list } = await nx.$api.sampleWarehouse.queryReturnToStockSample(params)
sampleList.value = list
if (list.length === 0) {
uni.showToast({ title: '未查询到该样品信息', icon: 'none' })
isFirstInput.value = true
} else {
isFirstInput.value = false
}
}
const btnLoading = ref(false)
async function handleSubmit() {
let params = {
actionWay: changeType.value,
targetLocation: targetLocation.value
}
if (changeType.value === 'sample') {
params.sampleReturnCode = changeCode.value
} else {
params.warehouseLocationCode = changeCode.value
}
btnLoading.value = true
await nx.$api.sampleWarehouse.execChangeLocation(params).finally(() => {
btnLoading.value = false
})
uni.showToast({ title: '变更成功', icon: 'none' })
handleReset()
}
function handleChangeType(e) {
handleReset()
}
let isFirstInput = ref(true)
const { scanQRInfo } = toRefs(nx.$store('biz'))
watch(scanQRInfo, newVal => {
if (!newVal) return
scanQRInfo.value = ''
if (nx.$router.getCurrentPage().route !== 'pages/sampleWarehouse/execChangeLocation/index') return
try {
console.log(newVal)
const isJson = nx.$helper.isJsonString(newVal)
console.log(isJson)
if (isFirstInput.value) {
handleFirstScan(newVal, isJson)
} else {
handleSecondScan(newVal, isJson)
}
} catch (error) {
uni.showToast({ title: '扫码内容解析失败', icon: 'none' })
}
})
function handleFirstScan(rawValue, isJson) {
if (changeType.value === 'sample') {
// 按样品变更:首扫应为纯字符串(样品编号)
if (isJson) {
isFirstInput.value = true
uni.showToast({ title: '请先扫描样品编号', icon: 'none' })
return
} else {
changeCode.value = rawValue
}
} else {
// 按库位变更:首扫应为 JSON原库位码
if (!isJson) {
isFirstInput.value = true
uni.showToast({ title: '请先扫描(原)库位码', icon: 'none' })
return
} else {
const codeObj = JSON.parse(rawValue)
changeCode.value = codeObj.code
}
}
getSampleList()
}
function handleSecondScan(rawValue, isJson) {
// 第二次扫描必须是 JSON目标库位码
if (!isJson) {
uni.showToast({ title: '请扫描变更后库位码', icon: 'none' })
return
}
const codeObj = JSON.parse(rawValue)
targetLocation.value = codeObj.code
}
onShow(() => {
scanQRInfo.value = ''
})
let needPrint = ref(false)
let locationCode = ref('')
let sampleCode = ref('')
function handleReturnToStock() {
nx.$api.sampleWarehouse
.execReturnToStock({
warehouseLocationCode: locationCode.value,
sampleCode: sampleCode.value
})
.then(res => {
successCount.value++
if (res.print) {
uni.showToast({
title: `归库成功,归库码为【${res.code}`,
duration: 3000,
icon: 'none'
})
// 执行打印
}
})
}
const successCount = ref(2)
function handleReset() {
locationCode.value = ''
sampleCode.value = ''
successCount.value = 0
targetLocation.value = ''
changeCode.value = ''
sampleList.value = []
btnLoading.value = false
isFirstInput.value = true
}
</script>