557 lines
16 KiB
Vue
557 lines
16 KiB
Vue
<!--
|
||
CheckFormDialog — 新建盘点单(stock.check.create)
|
||
|
||
字段说明(接口文档):
|
||
- title 盘点名称,非必填
|
||
- type 盘点范围:location 按库位(**缺省**;不选库位时后端自动拉取全仓启用库位)
|
||
/ store 按货主按商品 / goods 按商品
|
||
—— location 生成「库位明细行」,store/goods 生成「商品明细行」
|
||
⚠️ all 已下线(2026-10-27,传入返回 400),原「全盘」语义已并入 location
|
||
- mode 盘点方式:open 明盘 / blind 盲盘
|
||
—— 库位类(location)固定为 blind 盲盘且不可更改;商品类(store / goods)默认明盘
|
||
- store_id 货主ID(type=store 时必填)
|
||
- isStatic 是否静态盘点:0 关闭(缺省)/ 1 开启
|
||
—— **仅商品盘点(store / goods)有效**,库位盘点不显示选项且不传;
|
||
开启后审核通过会锁定移库 / 分配储位操作(拣货不受影响),盘点完成后自动解锁
|
||
- remark 备注
|
||
盘点时间不在本表单维护:主表已无 check_date,start_time(首个盘点明细写入时间)/
|
||
end_time(完成盘点时间)由盘点作业流程自动回填,前端不传。
|
||
warehouse_id 由服务端注入,前端不传。
|
||
-->
|
||
<template>
|
||
<el-dialog
|
||
:model-value="visible"
|
||
class="check-form-dialog"
|
||
width="min(560px, 92vw)"
|
||
align-center
|
||
append-to-body
|
||
:show-close="false"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@update:model-value="handleVisibleChange"
|
||
@closed="handleClosed"
|
||
>
|
||
<!-- 面板结构对齐「手工录入运单号」(TaskProgressPanel) -->
|
||
<div class="task-panel">
|
||
<header class="task-panel__head">
|
||
<div class="task-panel__titles">
|
||
<h2>新建盘点单</h2>
|
||
<p>创建后为「空盘点单」,需再添加盘点明细并提交审核</p>
|
||
</div>
|
||
<button
|
||
class="task-panel__close"
|
||
type="button"
|
||
aria-label="关闭"
|
||
@click="handleVisibleChange(false)"
|
||
>
|
||
<svg viewBox="0 0 12 12" fill="none">
|
||
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
|
||
</svg>
|
||
</button>
|
||
</header>
|
||
|
||
<div class="task-panel__body">
|
||
<el-form
|
||
ref="formRef"
|
||
:model="form"
|
||
:rules="rules"
|
||
class="task-panel__form"
|
||
>
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">盘点名称</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="title">
|
||
<el-input v-model="form.title" maxlength="50" show-word-limit placeholder="如:9月底全盘(可留空)" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">盘点范围</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="type">
|
||
<el-radio-group v-model="form.type">
|
||
<el-radio value="location">按库位</el-radio>
|
||
<el-radio value="store">按货主按商品</el-radio>
|
||
<el-radio value="goods">按商品</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<p class="task-panel__field-tip">
|
||
{{ isLocationType
|
||
? '库位盘点:明细行为「库位」(一行一个库位,行内按商品聚合),创建后添加盘点库位;不选库位时由后端自动拉取全仓库启用库位。'
|
||
: '商品盘点:明细行为「商品」(一行一个库存商品),创建后从库存中挑选商品。' }}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="form.type === 'store'" class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">货主</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="store_id">
|
||
<el-select
|
||
v-model="form.store_id"
|
||
placeholder="请选择货主"
|
||
filterable
|
||
clearable
|
||
style="width: 100%"
|
||
>
|
||
<el-option
|
||
v-for="opt in storeOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">盘点方式</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="mode">
|
||
<el-radio-group v-model="form.mode" :disabled="isLocationType">
|
||
<el-radio value="open">明盘</el-radio>
|
||
<el-radio value="blind">盲盘</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<p v-if="isLocationType" class="task-panel__field-tip">
|
||
库位盘点固定为盲盘(不可更改):盘点作业时前端不显示账面数量
|
||
</p>
|
||
<p v-else-if="form.mode === 'blind'" class="task-panel__field-tip">
|
||
盲盘:盘点作业时前端不显示账面数量
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="!isLocationType" class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">静态盘点</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="isStatic">
|
||
<el-radio-group v-model="form.isStatic">
|
||
<el-radio :value="0">关闭</el-radio>
|
||
<el-radio :value="1">开启</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<p v-if="form.isStatic === 1" class="task-panel__field-tip is-warning">
|
||
开启后:审核通过将锁定移库、分配储位操作(拣货不受影响),盘点完成后自动解锁
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input task-panel__field--textarea">
|
||
<span class="task-panel__field-label">备注</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="remark">
|
||
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="200" show-word-limit placeholder="可留空" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
</el-form>
|
||
|
||
<p class="task-panel__form-tip">
|
||
{{ createAlertText }}
|
||
</p>
|
||
</div>
|
||
|
||
<footer class="task-panel__foot">
|
||
<span class="task-panel__hint">提交前请确认盘点范围与盘点方式</span>
|
||
<div class="task-panel__actions">
|
||
<el-button size="small" @click="handleVisibleChange(false)">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||
确认创建
|
||
</el-button>
|
||
</div>
|
||
</footer>
|
||
</div>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, reactive, ref, watch } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import type { FormInstance, FormRules } from 'element-plus'
|
||
import {
|
||
isCheckApiSuccess,
|
||
isLocationScopeType,
|
||
loadStoreOptions,
|
||
storeOptions
|
||
} from '../config/template-config'
|
||
import {
|
||
stockCheckCreate,
|
||
type StockCheckMode,
|
||
type StockCheckType
|
||
} from '@/api/stock.check/stock.check'
|
||
|
||
defineOptions({ name: 'CheckFormDialog' })
|
||
|
||
const props = defineProps<{ visible: boolean }>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'update:visible', value: boolean): void
|
||
/**
|
||
* 创建成功(携创建出的盘点单关键信息)
|
||
* - type 用于决定后续添加「商品」还是「库位」
|
||
* - store_id/store_name 用于「添加盘点商品」时按货主限定可盘商品
|
||
*/
|
||
(
|
||
e: 'success',
|
||
task: {
|
||
id: number
|
||
check_no: string
|
||
title: string
|
||
type: string
|
||
store_id?: number
|
||
store_name?: string
|
||
}
|
||
): void
|
||
}>()
|
||
|
||
const formRef = ref<FormInstance>()
|
||
const submitting = ref(false)
|
||
|
||
const form = reactive<{
|
||
title: string
|
||
type: StockCheckType
|
||
store_id: number | undefined
|
||
mode: StockCheckMode
|
||
/** 是否静态盘点:0=关闭 / 1=开启(仅商品盘点可传,库位盘点不传) */
|
||
isStatic: 0 | 1
|
||
remark: string
|
||
}>({
|
||
title: '',
|
||
type: 'location',
|
||
store_id: undefined,
|
||
mode: 'blind',
|
||
isStatic: 0,
|
||
remark: ''
|
||
})
|
||
|
||
const rules: FormRules = {
|
||
store_id: [
|
||
{
|
||
validator: (_rule, value, callback) => {
|
||
if (form.type === 'store' && !value) callback(new Error('按货主盘点时必须选择货主'))
|
||
else callback()
|
||
},
|
||
trigger: 'change'
|
||
}
|
||
]
|
||
}
|
||
|
||
const isLocationType = computed(() => isLocationScopeType(form.type))
|
||
|
||
/** 库位类盘点(location)固定盲盘、不可更改;切回商品类恢复默认明盘 */
|
||
watch(
|
||
() => form.type,
|
||
(type) => {
|
||
form.mode = isLocationScopeType(type) ? 'blind' : 'open'
|
||
// 静态盘点仅商品盘点有效,库位盘点重置为关闭
|
||
if (isLocationScopeType(type)) form.isStatic = 0
|
||
}
|
||
)
|
||
|
||
/** 库位类任务创建后要添加的是「库位」而不是「商品」 */
|
||
const createAlertText = computed(() => {
|
||
if (!isLocationType.value) {
|
||
return '创建后为「空盘点单」,需再添加盘点商品并提交审核。'
|
||
}
|
||
// all 已下线:库位类只有 location,「不选库位=全仓」的兜底口径也并入 location
|
||
return '创建后为「空盘点单」,需再添加盘点库位并提交审核;不选库位时由后端自动拉取全仓库启用库位生成盘点范围。'
|
||
})
|
||
|
||
function handleVisibleChange(value: boolean) {
|
||
emit('update:visible', value)
|
||
}
|
||
|
||
function handleClosed() {
|
||
formRef.value?.clearValidate()
|
||
submitting.value = false
|
||
}
|
||
|
||
function resetForm() {
|
||
form.title = ''
|
||
form.type = 'location'
|
||
form.store_id = undefined
|
||
form.mode = 'blind'
|
||
form.isStatic = 0
|
||
form.remark = ''
|
||
}
|
||
|
||
watch(
|
||
() => props.visible,
|
||
(visible) => {
|
||
if (!visible) return
|
||
resetForm()
|
||
formRef.value?.clearValidate()
|
||
// 货主下拉(按货主盘点 / 后续筛选共用)
|
||
void loadStoreOptions()
|
||
}
|
||
)
|
||
|
||
async function handleSubmit() {
|
||
if (!formRef.value) return
|
||
try {
|
||
await formRef.value.validate()
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
submitting.value = true
|
||
try {
|
||
const res: any = await stockCheckCreate({
|
||
title: form.title.trim() || undefined,
|
||
type: form.type,
|
||
mode: form.mode,
|
||
store_id: form.type === 'store' ? form.store_id : undefined,
|
||
// 静态盘点仅商品盘点(store/goods)有效:库位盘点不显示选项、不传该字段
|
||
...(isLocationType.value ? {} : { isStatic: form.isStatic }),
|
||
remark: form.remark.trim() || undefined
|
||
})
|
||
if (!isCheckApiSuccess(res)) {
|
||
throw new Error(res?.message || '创建盘点单失败')
|
||
}
|
||
const payload: any =
|
||
res.data && (res.data.id || res.data.check_no) ? res.data : res
|
||
// 货主:创建响应(_formatCheckRow)带 store_id;兜底取表单所选,再用下拉选项补名称
|
||
const storeId = Number(payload.store_id ?? form.store_id) || 0
|
||
const storeName = storeId
|
||
? String(
|
||
payload.store_name ??
|
||
storeOptions.value.find((opt) => Number(opt.value) === storeId)?.label ??
|
||
''
|
||
).trim()
|
||
: ''
|
||
const task = {
|
||
id: Number(payload.id) || 0,
|
||
check_no: String(payload.check_no ?? ''),
|
||
title: String(payload.title ?? form.title ?? ''),
|
||
type: String(payload.type ?? form.type ?? ''),
|
||
store_id: storeId || undefined,
|
||
store_name: storeName || undefined
|
||
}
|
||
ElMessage.success(task.check_no ? `盘点单 ${task.check_no} 创建成功` : '盘点单创建成功')
|
||
emit('update:visible', false)
|
||
emit('success', task)
|
||
} catch (e: any) {
|
||
console.error('[stockcheck] 创建盘点单失败', e)
|
||
ElMessage.error(e?.message || '创建盘点单失败')
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
/* 面板结构 / 尺寸对齐手工录入运单号(TaskProgressPanel) */
|
||
.task-panel {
|
||
background: #fff;
|
||
color: #303133;
|
||
|
||
&__head {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 12px;
|
||
padding: 16px;
|
||
}
|
||
|
||
&__titles {
|
||
flex: 1;
|
||
min-width: 0;
|
||
|
||
h2 {
|
||
margin: 0;
|
||
font-size: 18px;
|
||
line-height: 24px;
|
||
font-weight: 400;
|
||
color: #303133;
|
||
}
|
||
|
||
p {
|
||
margin: 4px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
}
|
||
|
||
&__close {
|
||
width: 24px;
|
||
height: 24px;
|
||
flex: none;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: none;
|
||
border-radius: 4px;
|
||
background: transparent;
|
||
color: #909399;
|
||
cursor: pointer;
|
||
transition: color 0.2s;
|
||
|
||
svg {
|
||
width: 12px;
|
||
height: 12px;
|
||
}
|
||
|
||
&:hover {
|
||
color: #409eff;
|
||
}
|
||
}
|
||
|
||
&__body {
|
||
padding: 12px 16px 0;
|
||
}
|
||
|
||
&__form {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
&__field {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16px;
|
||
min-height: 40px;
|
||
padding: 8px 12px;
|
||
border: 1px solid #ebeef5;
|
||
border-radius: 4px;
|
||
background: #fafafa;
|
||
|
||
/* 输入行:不需要灰色容器,与静态信息行拉开层次 */
|
||
&--input {
|
||
align-items: flex-start;
|
||
min-height: 0;
|
||
padding: 4px 0 0 12px;
|
||
border: none;
|
||
border-radius: 0;
|
||
background: transparent;
|
||
|
||
.task-panel__field-label {
|
||
padding-top: 7px;
|
||
|
||
&.is-required::before {
|
||
top: 7px;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 多行文本行:标签与文本域顶部对齐 */
|
||
&--textarea {
|
||
.task-panel__field-label {
|
||
padding-top: 7px;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 标签列固定宽度(含必填星号占位):保证各输入框左边缘对齐、长度一致 */
|
||
&__field-label {
|
||
position: relative;
|
||
flex: none;
|
||
width: 88px;
|
||
padding-left: 10px;
|
||
box-sizing: border-box;
|
||
font-size: 12px;
|
||
line-height: 20px;
|
||
color: #606266;
|
||
text-align: left;
|
||
white-space: nowrap;
|
||
|
||
&.is-required::before {
|
||
content: '*';
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
line-height: 20px;
|
||
color: #f56c6c;
|
||
}
|
||
}
|
||
|
||
&__field-control {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
&__field-tip {
|
||
margin: 4px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
|
||
&.is-warning {
|
||
color: #e6a23c;
|
||
}
|
||
}
|
||
|
||
&__form-tip {
|
||
margin: 8px 0 0;
|
||
padding: 8px 12px;
|
||
border-radius: 4px;
|
||
background: #f4f4f5;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
|
||
&__foot {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
padding: 16px;
|
||
}
|
||
|
||
&__hint {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
&__actions {
|
||
display: flex;
|
||
align-items: center;
|
||
/* 与工具栏按钮组(OrderToolbarButtonGroup)保持一致:gap 6px */
|
||
gap: 6px;
|
||
|
||
:deep(.el-button) {
|
||
margin-left: 0;
|
||
margin-right: 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 面板内嵌 el-form-item:去掉默认间距,错误提示改回文档流内展示 */
|
||
.task-panel__form {
|
||
:deep(.el-form-item) {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
:deep(.el-form-item__content) {
|
||
margin-left: 0;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
:deep(.el-form-item__error) {
|
||
position: static;
|
||
padding-top: 4px;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style lang="scss">
|
||
/* el-dialog 会被 append 到 body:去掉默认头/内边距,统一交给面板(同手工录入运单号) */
|
||
.el-dialog.check-form-dialog {
|
||
padding: 0;
|
||
overflow: hidden;
|
||
|
||
.el-dialog__header {
|
||
display: none;
|
||
}
|
||
|
||
.el-dialog__body {
|
||
padding: 0;
|
||
}
|
||
}
|
||
</style>
|