<template>
|
<view class="subtract-page">
|
<PageHeader title="库存出库" @back="goBack" />
|
|
<scroll-view scroll-y class="content-scroll">
|
<view class="form-section">
|
<view class="form-row">
|
<text class="form-label">产品名称</text>
|
<up-input v-model="form.productName" disabled />
|
</view>
|
<view class="form-row">
|
<text class="form-label">规格</text>
|
<up-input v-model="form.model" disabled />
|
</view>
|
<view class="form-row">
|
<text class="form-label">单位</text>
|
<up-input v-model="form.unit" disabled />
|
</view>
|
</view>
|
|
<view class="form-section">
|
<view class="section-title">出库/过磅信息</view>
|
<view class="form-row">
|
<text class="form-label">车牌号</text>
|
<up-input v-model="form.licensePlateNo" placeholder="请输入车牌号" />
|
</view>
|
<view class="form-row">
|
<text class="form-label">毛重(吨)</text>
|
<up-input
|
v-model="form.grossWeight"
|
type="number"
|
placeholder="请输入毛重"
|
/>
|
</view>
|
<view class="form-row">
|
<text class="form-label">皮重(吨)</text>
|
<up-input
|
v-model="form.tareWeight"
|
type="number"
|
placeholder="请输入皮重"
|
/>
|
</view>
|
<view class="form-row">
|
<text class="form-label">净重(吨)</text>
|
<up-input
|
v-model="form.netWeight"
|
type="number"
|
disabled
|
placeholder="自动计算"
|
/>
|
</view>
|
<view class="form-row">
|
<text class="form-label">过磅日期</text>
|
<view class="selector-trigger" @click="openWeighingDatePicker">
|
<text class="selector-text" :class="{ placeholder: !form.weighingDate }">
|
{{ form.weighingDate || '请选择过磅日期' }}
|
</text>
|
<up-icon name="calendar" size="16" color="#999"></up-icon>
|
</view>
|
</view>
|
<view class="form-row">
|
<text class="form-label">过磅员</text>
|
<up-input v-model="form.weighingOperator" placeholder="请输入过磅员" />
|
</view>
|
<view class="form-row">
|
<text class="form-label">备注</text>
|
<up-input v-model="form.remark" type="textarea" placeholder="选填" />
|
</view>
|
</view>
|
</scroll-view>
|
|
<view class="bottom-bar">
|
<view class="btn-submit" @click="handleSubmit">出库</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>
|
</template>
|
|
<script setup>
|
import { ref, reactive, watch } from 'vue'
|
import { onLoad } from '@dcloudio/uni-app'
|
import dayjs from 'dayjs'
|
import PageHeader from '@/components/PageHeader.vue'
|
import { subtractStockInventory } from '@/api/inventoryManagement/stockInventory.js'
|
import { subtractStockUnInventory } from '@/api/inventoryManagement/stockUninventory.js'
|
|
const form = reactive({
|
id: undefined,
|
// 产品及库存基础信息(来自列表记录)
|
productId: undefined,
|
productModelId: undefined,
|
parentId: undefined,
|
parentName: '',
|
productName: '',
|
model: '',
|
unit: '',
|
qualitity: undefined,
|
lockedQuantity: undefined,
|
unLockedQuantity: undefined,
|
warnNum: undefined,
|
currentStock: undefined,
|
totalStockIn: undefined,
|
totalStockOut: undefined,
|
createTime: '',
|
updateTime: '',
|
version: undefined,
|
// 出库/过磅信息
|
licensePlateNo: '',
|
grossWeight: '',
|
tareWeight: '',
|
netWeight: '',
|
weighingDate: '',
|
weighingOperator: '',
|
remark: ''
|
})
|
|
const type = ref('0') // 0 合格库存,1 不合格库存
|
const showWeighingDatePicker = ref(false)
|
const weighingDateValue = ref(Date.now())
|
|
onLoad((options) => {
|
if (options && options.type != null) {
|
type.value = options.type
|
}
|
const cached = uni.getStorageSync('stockSubtractRecord')
|
if (cached) {
|
try {
|
const payload = typeof cached === 'string' ? JSON.parse(cached) : cached
|
const item = payload && payload.item ? payload.item : payload
|
// 将列表记录的完整字段拷贝到表单中,保持与 PC 端 Subtract.vue 一致
|
Object.assign(form, item)
|
uni.removeStorageSync('stockSubtractRecord')
|
} catch (e) {
|
uni.removeStorageSync('stockSubtractRecord')
|
}
|
}
|
})
|
|
// 净重 = 毛重 - 皮重
|
const computeNetWeight = () => {
|
const gross = Number(form.grossWeight)
|
const tare = Number(form.tareWeight)
|
if (!isNaN(gross) && !isNaN(tare)) {
|
const net = Number((gross - tare).toFixed(2))
|
form.netWeight = net > 0 ? net : 0
|
} else {
|
form.netWeight = ''
|
}
|
}
|
|
watch(
|
() => [form.grossWeight, form.tareWeight],
|
() => {
|
computeNetWeight()
|
}
|
)
|
|
const openWeighingDatePicker = () => {
|
weighingDateValue.value = form.weighingDate
|
? dayjs(form.weighingDate, 'YYYY-MM-DD HH:mm:ss').valueOf()
|
: Date.now()
|
showWeighingDatePicker.value = true
|
}
|
|
const onWeighingDateConfirm = (e) => {
|
const ts = e?.value ?? weighingDateValue.value
|
form.weighingDate = dayjs(ts).format('YYYY-MM-DD HH:mm:ss')
|
showWeighingDatePicker.value = false
|
}
|
|
const handleSubmit = () => {
|
if (!form.id) {
|
uni.showToast({ title: '记录信息缺失,无法出库', icon: 'none' })
|
return
|
}
|
const payload = { ...form }
|
const api = type.value === '0' ? subtractStockInventory : subtractStockUnInventory
|
api(payload)
|
.then(() => {
|
uni.showToast({ title: '出库成功', icon: 'success' })
|
setTimeout(() => {
|
uni.navigateBack()
|
}, 400)
|
})
|
.catch(() => {
|
uni.showToast({ title: '出库失败', icon: 'none' })
|
})
|
}
|
|
const goBack = () => uni.navigateBack()
|
</script>
|
|
<style lang="scss" scoped>
|
.subtract-page {
|
min-height: 100vh;
|
background: #f5f5f5;
|
padding-bottom: 100rpx;
|
}
|
.content-scroll {
|
height: calc(100vh - 100rpx);
|
}
|
.form-section {
|
background: #fff;
|
margin: 24rpx;
|
padding: 24rpx;
|
border-radius: 16rpx;
|
}
|
.section-title {
|
font-size: 28rpx;
|
font-weight: 500;
|
color: #333;
|
margin-bottom: 12rpx;
|
}
|
.form-row {
|
margin-bottom: 24rpx;
|
}
|
.form-label {
|
display: block;
|
font-size: 26rpx;
|
color: #666;
|
margin-bottom: 12rpx;
|
}
|
.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;
|
}
|
.bottom-bar {
|
position: fixed;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
padding: 16rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
|
background: #fff;
|
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04);
|
}
|
.btn-submit {
|
height: 88rpx;
|
border-radius: 999rpx;
|
background: #2979ff;
|
color: #fff;
|
font-size: 30rpx;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
}
|
</style>
|