ZN
11 小时以前 2291b7406cdc184abfa1b1986baeb55499771343
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<template>
  <view class="receipt-page">
    <PageHeader title="入库管理" @back="goBack" />
 
    <!-- 标签:合格入库 / 不合格入库 -->
    <view class="tabs-wrap">
      <view
        v-for="tab in tabs"
        :key="tab.name"
        class="tab-item"
        :class="{ active: activeTab === tab.name }"
        @click="activeTab = tab.name"
      >
        <text>{{ tab.label }}</text>
      </view>
    </view>
 
    <!-- 搜索区域 -->
    <view class="search-section">
      <view class="search-row">
        <view class="search-input-wrap">
          <up-input
            v-model="searchForm.productName"
            placeholder="产品大类"
            clearable
          />
        </view>
        <view class="btn-search" @click="handleQuery">
          <view class="btn-search-inner">
            <up-icon name="search" size="22" color="#fff"></up-icon>
            <text>搜索</text>
          </view>
        </view>
      </view>
    </view>
 
    <!-- 列表(合格/不合格共用接口 type 区分) -->
    <view class="list-section" v-if="activeTab !== 'custom'">
      <view v-if="tableData.length > 0">
        <view
          v-for="(item, index) in tableData"
          :key="item.id || index"
          class="card-item"
        >
          <view class="card-click" @click="goDetail(item)">
            <view class="card-header">
              <view class="header-main">
                <text class="product-name">{{ item.productName }}</text>
                <text class="inbound-date">{{ item.createTime || item.inboundDate }}</text>
              </view>
            </view>
            <up-divider />
            <view class="card-body">
              <view class="row"><text class="l">规格型号</text><text class="r">{{ item.model }}</text></view>
              <view class="row"><text class="l">单位</text><text class="r">{{ item.unit }}</text></view>
              <view class="row"><text class="l">入库数量</text><text class="r highlight">{{ item.stockInNum }}</text></view>
              <view class="row"><text class="l">入库人</text><text class="r">{{ item.createBy }}</text></view>
              <view class="row" v-if="item.recordType !== undefined"><text class="l">来源</text><text class="r">{{ getRecordType(item.recordType) || item.recordType }}</text></view>
            </view>
          </view>
          <view class="card-actions">
            <view class="btn-delete" @click.stop="handleDeleteSingle(item)">删除</view>
          </view>
        </view>
      </view>
      <view v-else class="no-data">暂无数据</view>
    </view>
    <!-- 加载更多 -->
    <view class="load-more-wrap" v-if="tableData.length > 0">
      <u-loadmore :status="loadStatus" @loadmore="loadMore" />
    </view>
  </view>
</template>
 
<script setup>
import { ref, reactive, toRefs, watch } from 'vue'
import { onShow, onReachBottom } from '@dcloudio/uni-app'
import PageHeader from '@/components/PageHeader.vue'
import {
  getStockInRecordListPage,
  batchDeleteStockInRecords
} from '@/api/inventoryManagement/stockInRecord.js'
import {
  findAllQualifiedStockInRecordTypeOptions,
  findAllUnQualifiedStockInRecordTypeOptions
} from '@/api/basicData/enum.js'
 
const activeTab = ref('qualified')
const stockRecordTypeOptions = ref([])
const tabs = [
  { label: '合格入库', name: 'qualified', type: '0' },
  { label: '不合格入库', name: 'unqualified', type: '1' }
]
 
const tableData = ref([])
const total = ref(0)
const loadStatus = ref('loadmore') // loadmore | loading | nomore | error
 
const page = reactive({ current: 1, size: 4 })
const data = reactive({
  searchForm: {
    productName: ''
  }
})
const { searchForm } = toRefs(data)
 
const currentType = () => tabs.find(t => t.name === activeTab.value)?.type || '0'
 
function getRecordType(recordType) {
  if (recordType == null || recordType === '') return ''
  return stockRecordTypeOptions.value.find(item => item.value === recordType)?.label || ''
}
 
function fetchRecordTypeOptions() {
  const api = currentType() === '1'
    ? findAllUnQualifiedStockInRecordTypeOptions
    : findAllQualifiedStockInRecordTypeOptions
  api()
    .then(res => {
      const data = res.data != null ? res.data : res
      stockRecordTypeOptions.value = Array.isArray(data) ? data : []
    })
    .catch(() => {
      stockRecordTypeOptions.value = []
    })
}
 
const getList = () => {
  if (activeTab.value === 'custom') return
  const isFirstPage = page.current === 1
  if (isFirstPage) {
    uni.showLoading({ title: '加载中...', mask: true })
  }
  const params = {
    ...page,
    type: currentType(),
    productName: searchForm.value.productName
  }
  getStockInRecordListPage(params)
    .then(res => {
      uni.hideLoading()
      const records = res.data?.records || []
      const totalCount = res.data?.total || 0
      if (isFirstPage) {
        tableData.value = records
        fetchRecordTypeOptions()
      } else {
        tableData.value = [...tableData.value, ...records]
      }
      total.value = totalCount
      if (tableData.value.length >= totalCount || totalCount === 0) {
        loadStatus.value = 'nomore'
      } else {
        loadStatus.value = 'loadmore'
      }
    })
    .catch(() => {
      uni.hideLoading()
      loadStatus.value = 'error'
      if (isFirstPage) {
        uni.showToast({ title: '加载失败', icon: 'none' })
      }
    })
}
 
const loadMore = () => {
  if (loadStatus.value === 'nomore' || loadStatus.value === 'loading') return
  loadStatus.value = 'loading'
  page.current++
  getList()
}
 
watch(activeTab, () => {
  page.current = 1
  loadStatus.value = 'loadmore'
  stockRecordTypeOptions.value = []
  getList()
})
 
const handleQuery = () => {
  page.current = 1
  loadStatus.value = 'loadmore'
  getList()
}
 
const goDetail = (item) => {
  if (!item.id) return
  try {
    uni.setStorageSync('receiptDetailItem', JSON.stringify({
      item,
      type: currentType()
    }))
  } catch (e) {}
  uni.navigateTo({
    url: '/pages/inventoryManagement/receiptManagement/view?id=' + item.id
  })
}
 
const handleDeleteSingle = (item) => {
  uni.showModal({
    title: '删除',
    content: '确认删除该条入库记录?',
    success: res => {
      if (res.confirm) {
        batchDeleteStockInRecords([item.id])
          .then(() => {
            uni.showToast({ title: '删除成功', icon: 'success' })
            getList()
          })
          .catch(() => {
            uni.showToast({ title: '删除失败', icon: 'none' })
          })
      }
    }
  })
}
 
const goBack = () => uni.navigateBack()
 
onShow(() => {
  if (activeTab.value !== 'custom') getList()
})
 
onReachBottom(() => {
  loadMore()
})
</script>
 
<style lang="scss" scoped>
.receipt-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 40rpx;
}
.tabs-wrap {
  display: flex;
  background: #fff;
  padding: 24rpx;
  gap: 24rpx;
}
.tab-item {
  flex: 1;
  text-align: center;
  padding: 20rpx;
  border-radius: 12rpx;
  background: #f0f0f0;
  font-size: 28rpx;
  color: #666;
}
.tab-item.active {
  background: #2979ff;
  color: #fff;
}
.search-section {
  background: #fff;
  margin: 24rpx;
  padding: 24rpx;
  border-radius: 16rpx;
}
.search-row {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}
.search-input-wrap { flex: 1; margin-right: 20rpx; min-width: 0; }
.btn-search {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180rpx;
  min-height: 72rpx;
  flex-shrink: 0;
  padding: 20rpx 24rpx;
  background: #2979ff;
  color: #fff;
  border-radius: 12rpx;
  font-size: 28rpx;
  box-sizing: border-box;
  text-align: center;
}
.btn-search-inner {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
}
.btn-search text {
  line-height: 1;
  vertical-align: middle;
}
/* 按钮内图标与文字垂直水平都居中 */
:deep(.btn-search-inner > *),
:deep(.btn-search > *) {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.list-section {
  padding: 0 24rpx;
}
.card-item {
  background: #fff;
  border-radius: 16rpx;
  padding: 24rpx;
  margin-bottom: 24rpx;
  box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
}
.card-header {
  padding: 8rpx 0;
}
.header-main {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}
.product-name {
  font-size: 30rpx;
  font-weight: 500;
  color: #333;
}
.inbound-date {
  font-size: 24rpx;
  color: #999;
}
.card-body .row {
  display: flex;
  justify-content: space-between;
  padding: 12rpx 0;
  font-size: 26rpx;
}
.card-body .l { color: #666; }
.card-body .r { color: #333; }
.card-body .r.highlight { color: #2979ff; font-weight: 500; }
.card-actions {
  margin-top: 16rpx;
  padding-top: 16rpx;
  border-top: 1rpx solid #eee;
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn-delete {
  font-size: 28rpx;
  color: #f56c6c;
  padding: 12rpx 32rpx;
}
.no-data {
  text-align: center;
  padding: 80rpx 0;
  color: #999;
  font-size: 28rpx;
}
.load-more-wrap {
  padding: 24rpx 0 40rpx;
}
</style>