|
|
|
|
@ -15,8 +15,8 @@
|
|
|
|
|
@confirm="onScanInputConfirm"
|
|
|
|
|
/>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="warehouse-box" @click="openWarehousePicker">
|
|
|
|
|
<text class="warehouse-box-text">{{ selectedWarehouseLabel || t('sparepartInventory.allWarehouse') }}</text>
|
|
|
|
|
<view class="area-box" @click="openAreaPicker">
|
|
|
|
|
<text class="area-box-text">{{ selectedAreaLabel || t('sparepartInventory.allArea') }}</text>
|
|
|
|
|
<uni-icons type="bottom" size="14" color="#9ca3af"></uni-icons>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="reset-filter-btn" @click="resetFilters">{{ t('functionCommon.reset') }}</view>
|
|
|
|
|
@ -86,23 +86,23 @@
|
|
|
|
|
|
|
|
|
|
<sv-focus-no-keyboard ref="focusNoKeyboardRef"></sv-focus-no-keyboard>
|
|
|
|
|
|
|
|
|
|
<uni-popup ref="warehousePickerRef" type="bottom" background-color="#fff">
|
|
|
|
|
<uni-popup ref="areaPickerRef" type="bottom" background-color="#fff">
|
|
|
|
|
<view class="picker-content">
|
|
|
|
|
<view class="picker-header">
|
|
|
|
|
<text class="picker-title">{{ t('sparepartInventory.warehousePlaceholder') }}</text>
|
|
|
|
|
<view class="picker-clear" @click="resetWarehouse">
|
|
|
|
|
<text class="picker-title">{{ t('sparepartInventory.areaPlaceholder') }}</text>
|
|
|
|
|
<view class="picker-clear" @click="resetArea">
|
|
|
|
|
<text class="picker-clear-text">{{ t('functionCommon.reset') }}</text>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<scroll-view scroll-y class="picker-list">
|
|
|
|
|
<view
|
|
|
|
|
v-for="item in warehouseOptions"
|
|
|
|
|
v-for="item in areaOptions"
|
|
|
|
|
:key="String(item.value)"
|
|
|
|
|
class="picker-item"
|
|
|
|
|
@click="selectWarehouse(item)"
|
|
|
|
|
@click="selectArea(item)"
|
|
|
|
|
>
|
|
|
|
|
<text class="picker-text">{{ item.label }}</text>
|
|
|
|
|
<text v-if="selectedWarehouse === item.value" class="picker-check">✓</text>
|
|
|
|
|
<text v-if="selectedArea === item.value" class="picker-check">✓</text>
|
|
|
|
|
</view>
|
|
|
|
|
</scroll-view>
|
|
|
|
|
</view>
|
|
|
|
|
@ -115,10 +115,11 @@ import { ref, computed, nextTick } from 'vue'
|
|
|
|
|
import { onLoad, onReady } from '@dcloudio/uni-app'
|
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
import NavBar from '@/components/common/NavBar.vue'
|
|
|
|
|
import { getSparepartInventoryPage, getWarehouseSimpleList } from '@/api/mes/sparepart'
|
|
|
|
|
import { getSparepartInventoryPage } from '@/api/mes/sparepart'
|
|
|
|
|
import { getWarehousePage, getWarehouseAreaSimpleList } from '@/api/mes/moldget'
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
const warehousePickerRef = ref(null)
|
|
|
|
|
const areaPickerRef = ref(null)
|
|
|
|
|
|
|
|
|
|
const list = ref([])
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
@ -128,9 +129,10 @@ const pageNo = ref(1)
|
|
|
|
|
const pageSize = ref(10)
|
|
|
|
|
const total = ref(0)
|
|
|
|
|
const searchKeyword = ref('')
|
|
|
|
|
const selectedWarehouse = ref('')
|
|
|
|
|
const selectedArea = ref('')
|
|
|
|
|
|
|
|
|
|
const warehouseOptions = ref([])
|
|
|
|
|
const areaOptions = ref([])
|
|
|
|
|
const sparepartWarehouseId = ref(null)
|
|
|
|
|
|
|
|
|
|
// 红外扫码不弹键盘
|
|
|
|
|
const focusNoKeyboardRef = ref(null)
|
|
|
|
|
@ -144,13 +146,13 @@ function focusKeywordNoKeyboard() {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const selectedWarehouseLabel = computed(() => {
|
|
|
|
|
const current = warehouseOptions.value.find((item) => item.value === selectedWarehouse.value)
|
|
|
|
|
const selectedAreaLabel = computed(() => {
|
|
|
|
|
const current = areaOptions.value.find((item) => item.value === selectedArea.value)
|
|
|
|
|
return current ? current.label : ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onLoad(async () => {
|
|
|
|
|
await loadWarehouseList()
|
|
|
|
|
await loadWarehouseThenAreas()
|
|
|
|
|
await fetchList(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@ -158,23 +160,30 @@ onReady(() => {
|
|
|
|
|
focusKeywordNoKeyboard()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
async function loadWarehouseList() {
|
|
|
|
|
async function loadWarehouseThenAreas() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await getWarehouseSimpleList()
|
|
|
|
|
const data = Array.isArray(res) ? res : (Array.isArray(res?.data) ? res.data : [])
|
|
|
|
|
warehouseOptions.value = data.map((w) => ({
|
|
|
|
|
value: String(w.id),
|
|
|
|
|
label: w.name || w.warehouseName || String(w.id)
|
|
|
|
|
}))
|
|
|
|
|
// 先获取备件仓(categoryType=3)
|
|
|
|
|
const whRes = await getWarehousePage({ pageNo: 1, pageSize: 1, categoryType: 3 })
|
|
|
|
|
const whData = Array.isArray(whRes) ? whRes : (Array.isArray(whRes?.data) ? whRes.data : (Array.isArray(whRes?.data?.list) ? whRes.data.list : []))
|
|
|
|
|
if (whData.length) {
|
|
|
|
|
sparepartWarehouseId.value = whData[0].id
|
|
|
|
|
// 再加载该仓库的库区列表
|
|
|
|
|
const areaRes = await getWarehouseAreaSimpleList(sparepartWarehouseId.value)
|
|
|
|
|
const areaData = Array.isArray(areaRes) ? areaRes : (Array.isArray(areaRes?.data) ? areaRes.data : [])
|
|
|
|
|
areaOptions.value = areaData.map((a) => ({
|
|
|
|
|
value: String(a.id),
|
|
|
|
|
label: a.name || a.areaName || String(a.id)
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('loadWarehouseList error', e)
|
|
|
|
|
console.error('loadWarehouseThenAreas error', e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 缓存全部数据用于前端搜索
|
|
|
|
|
const allList = ref([])
|
|
|
|
|
|
|
|
|
|
async function fetchAllForSearch(warehouseId) {
|
|
|
|
|
async function fetchAllForSearch(areaId) {
|
|
|
|
|
const all = []
|
|
|
|
|
let currentPage = 1
|
|
|
|
|
const maxPage = 10 // 最多拉10页,防止无限循环
|
|
|
|
|
@ -183,7 +192,7 @@ async function fetchAllForSearch(warehouseId) {
|
|
|
|
|
pageNo: currentPage,
|
|
|
|
|
pageSize: 100,
|
|
|
|
|
categoryType: 3,
|
|
|
|
|
warehouseId: warehouseId || undefined
|
|
|
|
|
areaId: areaId || undefined
|
|
|
|
|
})
|
|
|
|
|
const page = normalizePageData(res)
|
|
|
|
|
all.push(...page.list)
|
|
|
|
|
@ -208,7 +217,7 @@ async function fetchList(reset) {
|
|
|
|
|
|
|
|
|
|
if (keyword && reset) {
|
|
|
|
|
// 有搜索关键词:加载全部数据再前端过滤
|
|
|
|
|
const allData = await fetchAllForSearch(selectedWarehouse.value)
|
|
|
|
|
const allData = await fetchAllForSearch(selectedArea.value)
|
|
|
|
|
allList.value = allData
|
|
|
|
|
// 判断是否包含二维码ID格式(如 PRODUCTMATERIAL-330)
|
|
|
|
|
const scanMatch = keyword.match(/(?:productmaterial|spare|material|product)[-_](\d+)/i)
|
|
|
|
|
@ -232,7 +241,7 @@ async function fetchList(reset) {
|
|
|
|
|
pageNo: pageNo.value,
|
|
|
|
|
pageSize: pageSize.value,
|
|
|
|
|
categoryType: 3,
|
|
|
|
|
warehouseId: selectedWarehouse.value || undefined
|
|
|
|
|
areaId: selectedArea.value || undefined
|
|
|
|
|
})
|
|
|
|
|
const page = normalizePageData(res)
|
|
|
|
|
total.value = page.total
|
|
|
|
|
@ -270,7 +279,7 @@ async function onScanInputConfirm() {
|
|
|
|
|
|
|
|
|
|
async function resetFilters() {
|
|
|
|
|
searchKeyword.value = ''
|
|
|
|
|
selectedWarehouse.value = ''
|
|
|
|
|
selectedArea.value = ''
|
|
|
|
|
allList.value = []
|
|
|
|
|
// 重置后恢复正常分页
|
|
|
|
|
pageNo.value = 1
|
|
|
|
|
@ -278,22 +287,22 @@ async function resetFilters() {
|
|
|
|
|
await fetchList(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openWarehousePicker() {
|
|
|
|
|
warehousePickerRef.value?.open()
|
|
|
|
|
function openAreaPicker() {
|
|
|
|
|
areaPickerRef.value?.open()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function selectWarehouse(item) {
|
|
|
|
|
selectedWarehouse.value = item.value
|
|
|
|
|
warehousePickerRef.value?.close()
|
|
|
|
|
async function selectArea(item) {
|
|
|
|
|
selectedArea.value = item.value
|
|
|
|
|
areaPickerRef.value?.close()
|
|
|
|
|
allList.value = []
|
|
|
|
|
pageNo.value = 1
|
|
|
|
|
finished.value = false
|
|
|
|
|
await fetchList(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function resetWarehouse() {
|
|
|
|
|
selectedWarehouse.value = ''
|
|
|
|
|
warehousePickerRef.value?.close()
|
|
|
|
|
async function resetArea() {
|
|
|
|
|
selectedArea.value = ''
|
|
|
|
|
areaPickerRef.value?.close()
|
|
|
|
|
allList.value = []
|
|
|
|
|
pageNo.value = 1
|
|
|
|
|
finished.value = false
|
|
|
|
|
@ -385,7 +394,7 @@ function formatDateTime(value) {
|
|
|
|
|
color: #9ca3af;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.warehouse-box {
|
|
|
|
|
.area-box {
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
@ -399,7 +408,7 @@ function formatDateTime(value) {
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.warehouse-box-text {
|
|
|
|
|
.area-box-text {
|
|
|
|
|
color: #374151;
|
|
|
|
|
font-size: 26rpx;
|
|
|
|
|
max-width: 110rpx;
|
|
|
|
|
|