spring
6 小时以前 d99cbed8146991dbaea2f50897ccde8ba40493e6
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<template>
  <view class="dispatch-page">
    <PageHeader title="出库台账" @back="goBack" />
 
    <!-- 搜索区域 -->
    <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>
 
    <!-- 列表 -->
    <view class="list-section">
      <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="outbound-date">{{ item.createTime }}</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.netWeight }}</text></view>
              <view class="row"><text class="l">采购员</text><text class="r">{{ item.purchaser || 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
              v-if="isQualifiedRow(item) && hasDispatchEdit"
              class="btn-edit"
              @click.stop="handleEdit(item)"
            >
              编辑
            </view>
            <view
              v-if="hasDispatchCancel"
              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>
 
    <!-- 编辑弹窗(参照 PC) -->
    <up-popup :show="showEditModal" mode="bottom" @close="showEditModal = false">
      <view class="edit-popup">
        <view class="popup-header">
          <text class="popup-title">编辑出库</text>
        </view>
        <scroll-view scroll-y class="popup-body">
          <view class="form-row">
            <text class="form-label required">车牌号</text>
            <up-input v-model="editForm.licensePlateNo" placeholder="请输入车牌号" />
          </view>
 
          <view class="form-row">
            <text class="form-label required">毛重(吨)</text>
            <up-input
              v-model="editForm.grossWeight"
              type="digit"
              placeholder="请输入毛重"
              @blur="computeNetWeightEdit"
            />
          </view>
 
          <view class="form-row">
            <text class="form-label required">皮重(吨)</text>
            <up-input
              v-model="editForm.tareWeight"
              type="digit"
              placeholder="请输入皮重"
              @blur="computeNetWeightEdit"
            />
          </view>
 
          <view class="form-row">
            <text class="form-label required">净重(吨)</text>
            <up-input v-model="editForm.netWeight" type="digit" placeholder="自动计算" disabled />
          </view>
 
          <view class="form-row">
            <text class="form-label required">过磅日期</text>
            <view class="selector-trigger" @click="openWeighingDatePicker">
              <text class="selector-text" :class="{ placeholder: !editForm.weighingDate }">
                {{ editForm.weighingDate || '请选择过磅日期' }}
              </text>
              <up-icon name="calendar" size="16" color="#999" />
            </view>
          </view>
 
          <view class="form-row">
            <text class="form-label required">过磅员</text>
            <up-input v-model="editForm.weighingOperator" placeholder="请输入过磅员" />
          </view>
 
          <view class="form-row">
            <text class="form-label">备注</text>
            <up-input v-model="editForm.remark" type="textarea" placeholder="选填" />
          </view>
        </scroll-view>
 
        <view class="popup-footer">
          <view class="btn-cancel" @click="showEditModal = false">取消</view>
          <view class="btn-ok" @click="handleEditSubmit">确认</view>
        </view>
 
        <up-popup :show="showWeighingDatePicker" mode="bottom" @close="showWeighingDatePicker = false">
          <up-datetime-picker
            :show="true"
            v-model="weighingDateValue"
            mode="datetime"
            @confirm="onWeighingDateConfirm"
            @cancel="showWeighingDatePicker = false"
          />
        </up-popup>
      </view>
    </up-popup>
  </view>
</template>
 
<script setup>
import { computed, ref, reactive, toRefs, watch } from 'vue'
import { onShow, onReachBottom } from '@dcloudio/uni-app'
import PageHeader from '@/components/PageHeader.vue'
import dayjs from 'dayjs'
import { checkPermi } from '@/utils/permission'
import { getStockOutPage, delStockOut, editStockOut } from '@/api/inventoryManagement/stockOutRecord.js'
import {
  findAllQualifiedStockOutRecordTypeOptions
} from '@/api/basicData/enum.js'
 
const stockRecordTypeOptions = ref([])
const currentType = () => '0'
const tableData = ref([])
const total = ref(0)
const loadStatus = ref('loadmore')
const page = reactive({ current: 1, size: 20 })
const data = reactive({
  searchForm: {
    productName: ''
  }
})
const { searchForm } = toRefs(data)
 
// 权限控制(参照 PC)
const hasDispatchEdit = computed(() => checkPermi(['dispatch_edit']))
const hasDispatchCancel = computed(() => checkPermi(['dispatch_cancel']))
 
function getRecordType(recordType) {
  if (recordType == null || recordType === '') return ''
  return stockRecordTypeOptions.value.find(item => item.value === recordType)?.label || ''
}
 
function fetchRecordTypeOptions() {
  findAllQualifiedStockOutRecordTypeOptions()
    .then(res => {
      const list = res.data != null ? res.data : res
      stockRecordTypeOptions.value = Array.isArray(list) ? list : []
    })
    .catch(() => {
      stockRecordTypeOptions.value = []
    })
}
 
function isQualifiedRow(row) {
  return row?.recordType === 0 || row?.recordType === '0'
}
 
const getList = () => {
  const isFirstPage = page.current === 1
  if (isFirstPage) {
    uni.showLoading({ title: '加载中...', mask: true })
  }
  getStockOutPage({
    ...page,
    type: currentType(),
    productName: searchForm.value.productName
  })
    .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()
}
 
const handleQuery = () => {
  page.current = 1
  loadStatus.value = 'loadmore'
  getList()
}
 
const goDetail = (item) => {
  if (!item.id) return
  try {
    uni.setStorageSync('dispatchDetailItem', JSON.stringify({
      item,
      type: '0'
    }))
  } catch (e) {}
  uni.navigateTo({
    url: '/pages/inventoryManagement/dispatchLog/view?id=' + item.id
  })
}
 
const handleDeleteSingle = (item) => {
  if (!hasDispatchCancel.value) return
  uni.showModal({
    title: '删除',
    content: '确认删除该条出库记录?',
    success: res => {
      if (res.confirm) {
        delStockOut([item.id])
          .then(() => {
            uni.showToast({ title: '删除成功', icon: 'success' })
            getList()
          })
          .catch(() => {
            uni.showToast({ title: '删除失败', icon: 'none' })
          })
      }
    }
  })
}
 
// ---------------- 编辑 ----------------
const showEditModal = ref(false)
const showWeighingDatePicker = ref(false)
const weighingDateValue = ref(Date.now())
 
const editForm = reactive({
  id: null,
  licensePlateNo: '',
  grossWeight: '',
  tareWeight: '',
  netWeight: '',
  weighingDate: '',
  weighingOperator: '',
  remark: ''
})
 
const computeNetWeightEdit = () => {
  const gross = Number(editForm.grossWeight)
  const tare = Number(editForm.tareWeight)
  if (Number.isFinite(gross) && Number.isFinite(tare)) {
    const net = gross - tare
    const safeNet = Number(net.toFixed(2))
    editForm.netWeight = safeNet > 0 ? safeNet : 0
  }
}
 
watch(
  () => [showEditModal.value, editForm.grossWeight, editForm.tareWeight],
  () => {
    if (showEditModal.value) computeNetWeightEdit()
  }
)
 
const openWeighingDatePicker = () => {
  weighingDateValue.value = editForm.weighingDate
    ? dayjs(editForm.weighingDate).valueOf()
    : Date.now()
  showWeighingDatePicker.value = true
}
 
const onWeighingDateConfirm = (e) => {
  editForm.weighingDate = dayjs(e.value).format('YYYY-MM-DD HH:mm:ss')
  showWeighingDatePicker.value = false
}
 
const handleEdit = (row) => {
  Object.assign(editForm, row || {})
  // 以当前毛重/皮重为准计算净重
  computeNetWeightEdit()
  showEditModal.value = true
}
 
const handleEditSubmit = () => {
  if (!hasDispatchEdit.value) return
  if (!editForm.licensePlateNo) return uni.showToast({ title: '请输入车牌号', icon: 'none' })
  if (!editForm.grossWeight && editForm.grossWeight !== 0) return uni.showToast({ title: '请输入毛重', icon: 'none' })
  if (!editForm.tareWeight && editForm.tareWeight !== 0) return uni.showToast({ title: '请输入皮重', icon: 'none' })
  if (!editForm.weighingDate) return uni.showToast({ title: '请选择过磅日期', icon: 'none' })
  if (!editForm.weighingOperator) return uni.showToast({ title: '请输入过磅员', icon: 'none' })
 
  uni.showLoading({ title: '保存中...', mask: true })
  const { stockOutNum, ...payload } = editForm
  editStockOut(payload)
    .then(() => {
      uni.showToast({ title: '编辑成功', icon: 'success' })
      showEditModal.value = false
      getList()
    })
    .catch(() => {
      uni.showToast({ title: '编辑失败', icon: 'none' })
    })
    .finally(() => {
      uni.hideLoading()
    })
}
 
const goBack = () => uni.navigateBack()
 
onShow(() => getList())
onReachBottom(() => loadMore())
</script>
 
<style lang="scss" scoped>
.dispatch-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 40rpx;
}
.search-section {
  background: #fff;
  margin: 24rpx;
  padding: 24rpx;
  border-radius: 16rpx;
}
.search-row {
  display: flex;
  align-items: center;
}
.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; }
.outbound-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;
  width: 100%;
  text-align: center;
}
.btn-delete {
  font-size: 28rpx;
  color: #f56c6c;
  padding: 12rpx 32rpx;
  margin: 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-edit {
  font-size: 28rpx;
  color: #2979ff;
  padding: 12rpx 32rpx;
  margin: 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.no-data {
  text-align: center;
  padding: 80rpx 0;
  color: #999;
  font-size: 28rpx;
}
.load-more-wrap { padding: 24rpx 0 40rpx; }
 
/* 编辑弹窗样式 */
.edit-popup {
  background: #fff;
  border-radius: 24rpx 24rpx 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.popup-header {
  padding: 24rpx;
  border-bottom: 1rpx solid #eee;
  text-align: center;
}
.popup-title {
  font-size: 30rpx;
  font-weight: 500;
  color: #333;
}
.popup-body {
  padding: 24rpx 24rpx 0;
  max-height: 60vh;
}
.popup-footer {
  display: flex;
  gap: 24rpx;
  padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
  border-top: 1rpx solid #eee;
}
.btn-cancel,
.btn-ok {
  flex: 1;
  height: 88rpx;
  border-radius: 999rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
}
.btn-cancel {
  background: #f0f0f0;
  color: #666;
}
.btn-ok {
  background: #2979ff;
  color: #fff;
}
.form-row {
  margin-bottom: 24rpx;
}
.form-label {
  display: block;
  font-size: 26rpx;
  color: #666;
  margin-bottom: 12rpx;
}
.form-label.required:before {
  content: '*';
  color: #f56c6c;
  margin-right: 6rpx;
}
.selector-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx 24rpx;
  background: #f5f5f5;
  border-radius: 12rpx;
}
.selector-text {
  font-size: 28rpx;
  color: #333;
}
.selector-text.placeholder {
  color: #999;
}
</style>