feat:样品库管理

This commit is contained in:
houjunxiang
2025-11-21 17:56:33 +08:00
parent 7ee3df9ab9
commit 753766893b
24 changed files with 818 additions and 218 deletions

View File

@@ -1,7 +1,159 @@
<template>
<view> </view>
<navbar-back title="调拨归还"></navbar-back>
<view class="pl8 pr8 pt8">
<view class="x-f">
<text class="pl6">归还人</text>
<uni-data-select v-model="givebackUserId" :localdata="range" placeholder="请选择样品归还人"></uni-data-select>
</view>
<view class="border-b p6 x-f"
><view class="pr16">库管员</view><text>{{ userInfo.nickname }}</text></view
>
<up-input
style="padding-top: 20px"
border="bottom"
v-model="sampleCode"
placeholder="请扫描需要归还的样品编号"
prefixIcon="scan"
fontSize="16"
prefixIconStyle="font-size: 30px;"
@confirm="getSampleList"
>
</up-input>
<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: 49vh" scroll-y scroll-with-animation>
<uni-card margin="5px" v-for="item in sampleList" class="sample-item">
<view class="x-bc">
<view
>样品名称<text class="black">{{ item.sampleName }}</text></view
>
<view>调拨人<text class="black">{{}}</text></view>
</view>
<view class="x-bc">
<view
>样品编号<text class="black">{{ item.sampleReturnCode }}</text></view
>
<view>调拨时间<text class="black">{{}}</text></view>
</view>
<view class="mt4"
>归库编码<text class="black">{{ item.sampleReturnCode }}</text></view
>
<view class="mt4"
>样品库名称<text class="black">{{ item.warehouseName }}</text></view
>
<view class="mt4"
>库位码<text class="black">{{ item.warehouseLocationCode }}</text></view
>
</uni-card>
</scroll-view>
<up-button type="primary" :loading="btnLoading" style="width: 50%" text="提交" @click="handleSubmit"></up-button>
</uni-section>
</view>
</template>
<script setup></script>
<script setup>
import { computed, ref, toRefs, watch, onMounted } from 'vue'
import { debounce } from 'lodash'
import nx from '@/nx'
import { onLoad, onShow } from '@dcloudio/uni-app'
<style lang="scss" scoped></style>
const btnLoading = ref(false)
let sampleCode = ref('')
let sampleList = ref([])
const range = ref([])
const userInfo = computed(() => nx.$store('user').userInfo)
const givebackUserId = ref('')
const { scanQRInfo } = toRefs(nx.$store('biz'))
watch(scanQRInfo, newVal => {
debouncedHandleScan(newVal)
})
const debouncedHandleScan = debounce(val => {
if (!val) return
scanQRInfo.value = ''
if (nx.$router.getCurrentPage().route !== 'pages/sampleWarehouse/dispatchGiveBack/index') return
try {
sampleCode.value = val
getSampleList()
} catch (error) {
uni.showToast({
title: '请扫描正确的样品编码',
icon: 'none'
})
}
}, 300)
onShow(() => {
scanQRInfo.value = ''
})
async function getSampleList() {
if (sampleCode.value === '') return
let params = {
pageSize: 999,
pageNo: 1,
returnStatus: 'completed',
dispatchStatus: '1',
sampleReturnCode: sampleCode.value
}
const { list } = await nx.$api.sampleWarehouse.queryReturnToStockSample(params)
if (list.length === 0) {
return uni.showToast({ title: '未查询到该样品信息', icon: 'none' })
}
const existingCodes = new Set(sampleList.value.map(item => item.id)) // 假设唯一标识是 `code`
const newItems = list.filter(item => !existingCodes.has(item.id))
if (newItems.length === 0) {
return uni.showToast({ title: '该样品已存在,无需重复添加', icon: 'none' })
}
sampleList.value.push(...newItems)
}
async function handleSubmit() {
if (givebackUserId.value === '') {
return uni.showToast({
title: '请选择样品归还人',
icon: 'none'
})
}
btnLoading.value = true
const givebackUser = range.value.find(item => item.value === givebackUserId.value)?.nickname
await nx.$api.sampleWarehouse
.execSampleDispatch({
detailIds: sampleList.value.map(item => item.id),
givebackUserId: givebackUserId.value,
givebackUser
})
.finally(() => {
btnLoading.value = false
})
uni.showToast({
title: '归还成功',
icon: 'none'
})
handleReset()
}
function handleReset() {
sampleCode.value = ''
sampleList.value = []
}
onMounted(async () => {
const data = await nx.$api.user.getAssignUserList()
range.value = data.map(item => ({ text: item.nickname, value: item.id }))
})
</script>
<style lang="scss" scoped>
.sample-item {
position: relative;
pointer-events: none;
.item-checkbox {
position: absolute;
right: 5px;
top: 5px;
}
}
:deep(.uni-select__input-placeholder) {
font-size: 16px;
}
</style>