| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <template>
- <uni-navbar-lite :show-right=false title="库存查询"></uni-navbar-lite>
- <view class="list-page">
- <view class="search-block">
- <view class="search-bar">
- <view class="search-box">
- <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
- <input class="search-input" type="text" placeholder="请输入物料名称查询" v-model="keyword" @input="handleSearch" />
- <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
- <text class="clear-btn-text">×</text>
- </view>
- <view class="search-btn" @tap="handleSearch">
- <text class="search-btn-text">搜索</text>
- </view>
- </view>
- </view>
- </view>
- <view class="status-tabs">
- <view
- class="status-tab"
- :class="{ 'active': currentStatus === '' }"
- @tap="handleStatusChange('')"
- >
- <text class="status-tab-text" :class="{ 'active-text': currentStatus === '' }">全部</text>
- </view>
- <view
- class="status-tab"
- :class="{ 'active': currentStatus === '1' }"
- @tap="handleStatusChange('1')"
- >
- <text class="status-tab-text" :class="{ 'active-text': currentStatus === '1' }">有库存</text>
- </view>
- <view
- class="status-tab"
- :class="{ 'active': currentStatus === '0' }"
- @tap="handleStatusChange('0')"
- >
- <text class="status-tab-text" :class="{ 'active-text': currentStatus === '0' }">无库存</text>
- </view>
- </view>
- <common-list
- :dataList="dataList"
- :loading="loading"
- :refreshing="refreshing"
- :hasMore="hasMore"
- @refresh="handleRefresh"
- @loadMore="loadMore"
- >
- <template #default="{ item, index }">
- <view class="list-item">
- <view class="item-container">
- <view class="item-header">
- <view class="item-main-info">
- <view class="item-name-row">
- <text class="item-name">{{ getItemName(item) }}</text>
- <text class="item-measure">{{ getMeasureName(item) }}</text>
- </view>
- <view class="item-details">
- <text class="item-code">编码: {{ getItemCode(item) }}</text>
- </view>
- </view>
- <view class="item-qty-row">
- <text class="item-qty-label">在库</text>
- <text class="item-qty-value">{{ getQuantityOnhand(item) }}</text>
- </view>
- </view>
- <view class="item-info">
- <view class="info-row">
- <text class="info-label">规格型号</text>
- <text class="info-value">{{ getSpecification(item) }}</text>
- </view>
- <view class="info-row">
- <text class="info-label">入库批次</text>
- <text class="info-value">{{ getBatchCode(item) }}</text>
- </view>
- <view class="info-row">
- <text class="info-label">仓库位置</text>
- <text class="info-value">{{ getWarehouseFull(item) }}</text>
- </view>
- <view class="info-row">
- <text class="info-label">供应商</text>
- <text class="info-value">{{ getVendorName(item) }}</text>
- </view>
- <view class="info-row">
- <text class="info-label">入库日期</text>
- <text class="info-value">{{ getRecptDate(item) }}</text>
- </view>
- <view class="info-row" v-if="getExpireDate(item).length > 0">
- <text class="info-label">有效期至</text>
- <text class="info-value">{{ getExpireDate(item) }}</text>
- </view>
- </view>
- </view>
- </view>
- </template>
- </common-list>
- </view>
- </template>
- <script setup lang="uts">
- import { ref, onMounted } from 'vue'
- import { onShow } from '@dcloudio/uni-app';
- import { listWmstock } from '../../api/wmstock/index'
- let searchTimer: number | null = null
- const dataList = ref<any[]>([])
- const keyword = ref<string>("")
- const currentStatus = ref<string>('1')
- const page = ref<number>(1)
- const pageSize: number = 10
- const hasMore = ref<boolean>(true)
- const loading = ref<boolean>(false)
- const refreshing = ref<boolean>(false)
- const getItemName = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['itemName']
- return val != null ? val.toString() : ''
- }
- const getItemCode = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['itemCode']
- return val != null ? val.toString() : ''
- }
- const getMeasureName = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['measureName']
- return val != null ? val.toString() : ''
- }
- const getSpecification = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['specification']
- return val != null ? val.toString() : ''
- }
- const getQuantityOnhand = (item: any | null): string => {
- if (item == null) return '0'
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['quantityOnhand']
- return val != null ? val.toString() : '0'
- }
- const getBatchCode = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['batchCode']
- return val != null ? val.toString() : ''
- }
- const getWarehouseFull = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const wh = jsonItem['warehouseName']
- const loc = jsonItem['locationName']
- const area = jsonItem['areaCode']
- let result = wh != null ? wh.toString() : ''
- if (loc != null && loc.toString().length > 0) result += '->' + loc.toString()
- if (area != null && area.toString().length > 0) result += '->' + area.toString()
- return result
- }
- const getVendorName = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['vendorName']
- return val != null ? val.toString() : ''
- }
- const getRecptDate = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['recptDate']
- if (val == null) return ''
- const dateStr = val.toString()
- return dateStr.length >= 10 ? dateStr.substring(0, 10) : dateStr
- }
- const getExpireDate = (item: any | null): string => {
- if (item == null) return ''
- const jsonItem = item as UTSJSONObject
- const val = jsonItem['expireDate']
- if (val == null) return ''
- const dateStr = val.toString()
- return dateStr.length >= 10 ? dateStr.substring(0, 10) : dateStr
- }
- const loadData = async (isRefresh: boolean): Promise<void> => {
- if (loading.value) return
-
- try {
- loading.value = true
-
- if (isRefresh) {
- page.value = 1
- }
-
- const result = await listWmstock(page.value, pageSize, keyword.value, currentStatus.value)
- const resultObj = result as UTSJSONObject
- const rows = resultObj['rows']
- const total = resultObj['total'] as number
-
- if (rows != null) {
- const newData = rows as any[]
- if (isRefresh) {
- dataList.value = newData
- } else {
- dataList.value = [...dataList.value, ...newData]
- }
- hasMore.value = dataList.value.length < total
- } else {
- if (isRefresh) {
- dataList.value = []
- }
- hasMore.value = false
- }
-
- } catch (e) {
- console.error('加载失败:', e)
- } finally {
- loading.value = false
- refreshing.value = false
- }
- }
- const handleSearch = (): void => {
- const timer = searchTimer
- if (timer != null) {
- clearTimeout(timer)
- }
- searchTimer = setTimeout(() => {
- loadData(true)
- }, 300)
- }
- const handleStatusChange = (status: string): void => {
- currentStatus.value = status
- page.value = 1
- loadData(true)
- }
- const clearKeyword = (): void => {
- keyword.value = ''
- loadData(true)
- }
- const handleRefresh = (): void => {
- refreshing.value = true
- loadData(true)
- }
- const loadMore = (): void => {
- if (!hasMore.value || loading.value) return
- page.value++
- loadData(false)
- }
- onMounted(() => {
- loadData(true)
- })
- onShow(() => {
- loadData(true)
- })
- </script>
- <style lang="scss">
- .list-page {
- flex: 1;
- background-color: #e8f0f9;
- }
- .search-block {
- background-color: #ffffff;
- border-radius: 15rpx;
- }
- .search-bar {
- padding: 20rpx 30rpx;
- }
- .search-box {
- flex-direction: row;
- align-items: center;
- height: 72rpx;
- padding: 0 24rpx;
- background-color: #f5f5f5;
- border-radius: 36rpx;
- .search-icon {
- width: 32rpx;
- height: 32rpx;
- margin-right: 12rpx;
- }
- .search-input {
- flex: 1;
- font-size: 28rpx;
- color: #333333;
- }
- .search-btn {
- padding: 10rpx 20rpx;
- background-color: #007aff;
- border-radius: 8rpx;
- margin-left: 10rpx;
- }
- .search-btn-text {
- color: #ffffff;
- font-size: 24rpx;
- }
- .clear-btn {
- width: 36rpx;
- height: 36rpx;
- border-radius: 18rpx;
- background-color: #cccccc;
- align-items: center;
- justify-content: center;
- margin-left: 10rpx;
- }
- .clear-btn-text {
- color: #ffffff;
- font-size: 24rpx;
- font-weight: bold;
- }
- }
- .status-tabs {
- display: flex;
- flex-direction: row;
- padding: 0rpx 30rpx 20rpx;
- background-color: #ffffff;
- }
- .status-tab {
- flex: 1;
- padding: 16rpx 0;
- text-align: center;
- margin-right: 16rpx;
- border-radius: 8rpx;
- background-color: #f5f5f5;
- justify-content: center;
- align-items: center;
- &:last-child {
- margin-right: 0;
- }
- &.active {
- background-color: #007aff;
- }
- .status-tab-text {
- font-size: 26rpx;
- color: #666666;
- &.active-text {
- color: #ffffff;
- font-weight: bold;
- }
- }
- }
- .list-item {
- margin: 8rpx 10rpx;
- background-color: #ffffff;
- border-radius: 12rpx;
- }
- .item-container {
- padding: 20rpx;
- }
- .item-header {
- flex-direction: row;
- align-items: flex-start;
- justify-content: space-between;
- margin-bottom: 12rpx;
- width: 100%;
- .item-main-info {
- flex: 1;
- margin-right: 20rpx;
- }
- .item-name-row {
- flex-direction: row;
- align-items: center;
- margin-bottom: 8rpx;
- }
- .item-name {
- font-size: 28rpx;
- color: #1d2129;
- font-weight: bold;
- }
- .item-measure {
- font-size: 24rpx;
- color: #86909c;
- margin-left: 10rpx;
- }
- .item-details {
- flex-direction: row;
- width: 100%;
- }
- .item-code {
- font-size: 23rpx;
- color: #797979;
- flex: 1;
- }
- .item-qty-row {
- flex-direction: column;
- align-items: center;
- justify-content: center;
- background-color: #f0f5ff;
- padding: 10rpx 16rpx;
- border-radius: 8rpx;
- min-width: 100rpx;
- }
- .item-qty-label {
- font-size: 20rpx;
- color: #165dff;
- }
- .item-qty-value {
- font-size: 32rpx;
- color: #165dff;
- font-weight: 700;
- }
- }
- .item-info {
- .info-row {
- flex-direction: row;
- padding: 4rpx 0;
- }
- .info-label {
- font-size: 24rpx;
- color: #86909c;
- width: 120rpx;
- flex-shrink: 0;
- }
- .info-value {
- font-size: 24rpx;
- color: #1d2129;
- flex: 1;
- }
- }
- </style>
|