fix(stock): 清空商品后解锁仓库下拉,并新增创建页重置按钮
- 货主判定只统计仍持有商品的明细行,清空商品后仓库下拉/商品搜索范围立即解除 - 商品清空时同步清掉货主快照;自动带出的编码/名称/规格/单位一并清空, 手工改过的编码保留 - 提交前货主一致性校验只针对已选商品的行 - 入库/出库创建页新增「重置」按钮:清空单据头与明细、清除校验提示,不离开页面 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
9774ee1414
commit
6e1e7a0f19
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||||
import { inboundOrderApi } from '@/api/inboundOrder'
|
import { inboundOrderApi } from '@/api/inboundOrder'
|
||||||
@ -82,6 +82,8 @@ interface LineItem {
|
|||||||
product_id: number | null
|
product_id: number | null
|
||||||
/** 所选商品的所属货主(用于与仓库做同货主校验) */
|
/** 所选商品的所属货主(用于与仓库做同货主校验) */
|
||||||
product_subsidiary_id: number | null
|
product_subsidiary_id: number | null
|
||||||
|
/** 由商品自动带出的编码,用于清除商品时判断快照是否还需要保留 */
|
||||||
|
autofill_code?: string
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
spec: string
|
spec: string
|
||||||
@ -109,7 +111,8 @@ function removeLine(index: number) {
|
|||||||
const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, selectableWarehouses, canPickGoods } = useWarehouseGoodsScope({
|
const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, selectableWarehouses, canPickGoods } = useWarehouseGoodsScope({
|
||||||
warehouseId: computed(() => form.warehouse_id),
|
warehouseId: computed(() => form.warehouse_id),
|
||||||
warehouses,
|
warehouses,
|
||||||
lineOwners: () => lines.value.map(line => line.product_subsidiary_id),
|
// 只有仍持有商品的明细才参与货主判定,清空商品后立即解锁仓库下拉
|
||||||
|
lineOwners: () => lines.value.map(line => (line.product_id ? line.product_subsidiary_id : null)),
|
||||||
clearMismatchedGoods: ownerId => {
|
clearMismatchedGoods: ownerId => {
|
||||||
let cleared = 0
|
let cleared = 0
|
||||||
for (const line of lines.value) {
|
for (const line of lines.value) {
|
||||||
@ -126,11 +129,30 @@ const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, s
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 商品被清空后同步清掉货主快照与自动带出的商品信息,避免仓库下拉仍被锁定、或残留上次商品
|
||||||
|
watch(
|
||||||
|
() => lines.value.map(line => line.product_id).join(','),
|
||||||
|
() => {
|
||||||
|
for (const line of lines.value) {
|
||||||
|
if (line.product_id) continue
|
||||||
|
line.product_subsidiary_id = null
|
||||||
|
if (line.autofill_code && line.code === line.autofill_code) {
|
||||||
|
line.code = ''
|
||||||
|
line.name = ''
|
||||||
|
line.spec = ''
|
||||||
|
line.unit = ''
|
||||||
|
}
|
||||||
|
line.autofill_code = ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
function onLineProductSelect(index: number, p: ProductSearchItem) {
|
function onLineProductSelect(index: number, p: ProductSearchItem) {
|
||||||
const line = lines.value[index]
|
const line = lines.value[index]
|
||||||
if (!line) return
|
if (!line) return
|
||||||
line.product_id = p.id
|
line.product_id = p.id
|
||||||
line.product_subsidiary_id = p.subsidiary_id == null ? null : Number(p.subsidiary_id)
|
line.product_subsidiary_id = p.subsidiary_id == null ? null : Number(p.subsidiary_id)
|
||||||
|
line.autofill_code = p.item_code || ''
|
||||||
line.name = p.item_name || ''
|
line.name = p.item_name || ''
|
||||||
line.code = p.item_code || ''
|
line.code = p.item_code || ''
|
||||||
line.spec = p.sku_property || ''
|
line.spec = p.sku_property || ''
|
||||||
@ -168,7 +190,7 @@ async function submit() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (warehouseOwnerId.value !== null
|
if (warehouseOwnerId.value !== null
|
||||||
&& lines.value.some(line => line.product_subsidiary_id != null
|
&& lines.value.some(line => line.product_id && line.product_subsidiary_id != null
|
||||||
&& Number(line.product_subsidiary_id) !== warehouseOwnerId.value)) {
|
&& Number(line.product_subsidiary_id) !== warehouseOwnerId.value)) {
|
||||||
ElMessage.warning('存在与仓库货主(所属公司)不一致的商品,请重新选择')
|
ElMessage.warning('存在与仓库货主(所属公司)不一致的商品,请重新选择')
|
||||||
return
|
return
|
||||||
@ -216,6 +238,17 @@ function cancel() {
|
|||||||
router.push('/inbound-order')
|
router.push('/inbound-order')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 重置表单:清空单据头与明细,回到初始状态(不离开当前页面) */
|
||||||
|
async function handleReset() {
|
||||||
|
Object.assign(form, emptyForm())
|
||||||
|
lines.value = []
|
||||||
|
addLine()
|
||||||
|
// 清空字段会让下拉等控件回抛 change 校验,等它们处理完再统一清掉错误提示
|
||||||
|
await nextTick()
|
||||||
|
setTimeout(() => formRef.value?.clearValidate())
|
||||||
|
ElMessage.success('表单已重置')
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchOptions() {
|
async function fetchOptions() {
|
||||||
try {
|
try {
|
||||||
const [ warehouseRes, expressRes ] = await Promise.all([
|
const [ warehouseRes, expressRes ] = await Promise.all([
|
||||||
@ -241,6 +274,7 @@ onMounted(async () => {
|
|||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<span>创建入库单</span>
|
<span>创建入库单</span>
|
||||||
<div>
|
<div>
|
||||||
|
<el-button @click="handleReset">重置</el-button>
|
||||||
<el-button @click="cancel">取消</el-button>
|
<el-button @click="cancel">取消</el-button>
|
||||||
<el-button type="primary" :loading="submitting" @click="submit">保存</el-button>
|
<el-button type="primary" :loading="submitting" @click="submit">保存</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||||
import { outboundOrderApi } from '@/api/outboundOrder'
|
import { outboundOrderApi } from '@/api/outboundOrder'
|
||||||
@ -101,6 +101,8 @@ interface LineItem {
|
|||||||
product_id: number | null
|
product_id: number | null
|
||||||
/** 所选商品的所属货主(用于与仓库做同货主校验) */
|
/** 所选商品的所属货主(用于与仓库做同货主校验) */
|
||||||
product_subsidiary_id: number | null
|
product_subsidiary_id: number | null
|
||||||
|
/** 由商品自动带出的编码,用于清除商品时判断快照是否还需要保留 */
|
||||||
|
autofill_code?: string
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
spec: string
|
spec: string
|
||||||
@ -128,7 +130,8 @@ function removeLine(index: number) {
|
|||||||
const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, selectableWarehouses, canPickGoods } = useWarehouseGoodsScope({
|
const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, selectableWarehouses, canPickGoods } = useWarehouseGoodsScope({
|
||||||
warehouseId: computed(() => form.warehouse_id),
|
warehouseId: computed(() => form.warehouse_id),
|
||||||
warehouses,
|
warehouses,
|
||||||
lineOwners: () => lines.value.map(line => line.product_subsidiary_id),
|
// 只有仍持有商品的明细才参与货主判定,清空商品后立即解锁仓库下拉
|
||||||
|
lineOwners: () => lines.value.map(line => (line.product_id ? line.product_subsidiary_id : null)),
|
||||||
clearMismatchedGoods: ownerId => {
|
clearMismatchedGoods: ownerId => {
|
||||||
let cleared = 0
|
let cleared = 0
|
||||||
for (const line of lines.value) {
|
for (const line of lines.value) {
|
||||||
@ -145,11 +148,30 @@ const { warehouseOwnerId, goodsOwnerId, goodsOwnerConflict, scopeSubsidiaryId, s
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 商品被清空后同步清掉货主快照与自动带出的商品信息,避免仓库下拉仍被锁定、或残留上次商品
|
||||||
|
watch(
|
||||||
|
() => lines.value.map(line => line.product_id).join(','),
|
||||||
|
() => {
|
||||||
|
for (const line of lines.value) {
|
||||||
|
if (line.product_id) continue
|
||||||
|
line.product_subsidiary_id = null
|
||||||
|
if (line.autofill_code && line.code === line.autofill_code) {
|
||||||
|
line.code = ''
|
||||||
|
line.name = ''
|
||||||
|
line.spec = ''
|
||||||
|
line.unit = ''
|
||||||
|
}
|
||||||
|
line.autofill_code = ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
function onLineProductSelect(index: number, p: ProductSearchItem) {
|
function onLineProductSelect(index: number, p: ProductSearchItem) {
|
||||||
const line = lines.value[index]
|
const line = lines.value[index]
|
||||||
if (!line) return
|
if (!line) return
|
||||||
line.product_id = p.id
|
line.product_id = p.id
|
||||||
line.product_subsidiary_id = p.subsidiary_id == null ? null : Number(p.subsidiary_id)
|
line.product_subsidiary_id = p.subsidiary_id == null ? null : Number(p.subsidiary_id)
|
||||||
|
line.autofill_code = p.item_code || ''
|
||||||
line.name = p.item_name || ''
|
line.name = p.item_name || ''
|
||||||
line.code = p.item_code || ''
|
line.code = p.item_code || ''
|
||||||
line.spec = p.sku_property || ''
|
line.spec = p.sku_property || ''
|
||||||
@ -187,7 +209,7 @@ async function submit() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (warehouseOwnerId.value !== null
|
if (warehouseOwnerId.value !== null
|
||||||
&& lines.value.some(line => line.product_subsidiary_id != null
|
&& lines.value.some(line => line.product_id && line.product_subsidiary_id != null
|
||||||
&& Number(line.product_subsidiary_id) !== warehouseOwnerId.value)) {
|
&& Number(line.product_subsidiary_id) !== warehouseOwnerId.value)) {
|
||||||
ElMessage.warning('存在与仓库货主(所属公司)不一致的商品,请重新选择')
|
ElMessage.warning('存在与仓库货主(所属公司)不一致的商品,请重新选择')
|
||||||
return
|
return
|
||||||
@ -243,6 +265,17 @@ function cancel() {
|
|||||||
router.push('/outbound-order')
|
router.push('/outbound-order')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 重置表单:清空单据头与明细,回到初始状态(不离开当前页面) */
|
||||||
|
async function handleReset() {
|
||||||
|
Object.assign(form, emptyForm())
|
||||||
|
lines.value = []
|
||||||
|
addLine()
|
||||||
|
// 清空字段会让下拉等控件回抛 change 校验,等它们处理完再统一清掉错误提示
|
||||||
|
await nextTick()
|
||||||
|
setTimeout(() => formRef.value?.clearValidate())
|
||||||
|
ElMessage.success('表单已重置')
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchOptions() {
|
async function fetchOptions() {
|
||||||
try {
|
try {
|
||||||
const [ warehouseRes, shopRes, expressRes ] = await Promise.all([
|
const [ warehouseRes, shopRes, expressRes ] = await Promise.all([
|
||||||
@ -270,6 +303,7 @@ onMounted(async () => {
|
|||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<span>创建出库单</span>
|
<span>创建出库单</span>
|
||||||
<div>
|
<div>
|
||||||
|
<el-button @click="handleReset">重置</el-button>
|
||||||
<el-button @click="cancel">取消</el-button>
|
<el-button @click="cancel">取消</el-button>
|
||||||
<el-button type="primary" :loading="submitting" @click="submit">保存</el-button>
|
<el-button type="primary" :loading="submitting" @click="submit">保存</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user