1013 lines
31 KiB
Vue
1013 lines
31 KiB
Vue
<template>
|
||
<div class="pickcart-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="250px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFieldsRef"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
@submit="handleSubmit"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<el-button size="small" type="primary" :loading="loading" @click="loadList">刷新</el-button>
|
||
<el-button size="small" @click="openScanDialog">扫码查询</el-button>
|
||
<el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag>
|
||
</div>
|
||
<el-button-group>
|
||
<el-button type="success" size="small" @click="openCreate">新增拣货车</el-button>
|
||
<el-button type="success" size="small" plain @click="openBatchCreate">批量新增</el-button>
|
||
</el-button-group>
|
||
</div>
|
||
|
||
<div class="upper-wrapper">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="拣货车列表"
|
||
table-id="setting-pickcart"
|
||
:data="tableData"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-actions="true"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
row-key="cart_id"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadList"
|
||
>
|
||
<template #column-status="{ row }">
|
||
<el-tag :type="formatPickCartStatus(row.status).type" size="small">
|
||
{{ formatPickCartStatus(row.status).text }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-current_task_no="{ row }">
|
||
<template v-if="row.current_task_id">
|
||
<el-tag type="warning" size="small">{{ row.current_task_no || row.current_task_id }}</el-tag>
|
||
</template>
|
||
<el-text v-else type="info" size="small">未绑定</el-text>
|
||
</template>
|
||
|
||
<template #column-actions="{ row }">
|
||
<el-button link type="primary" size="small" @click.stop="openDetail(row)">详情</el-button>
|
||
<el-button link type="primary" size="small" @click.stop="openEdit(row)">编辑</el-button>
|
||
<el-button link type="success" size="small" @click.stop="openBind(row)">绑定任务</el-button>
|
||
<el-button link type="danger" size="small" @click.stop="handleDelete(row)">删除</el-button>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无拣货车数据,可调整左侧筛选条件或点击新增</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 新增/编辑 -->
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
:title="dialogMode === 'create' ? '新增拣货车' : '编辑拣货车'"
|
||
width="520px"
|
||
align-center
|
||
@close="resetForm"
|
||
>
|
||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="110px">
|
||
<el-form-item label="拣货车编码" prop="cart_code">
|
||
<el-input
|
||
v-model="formData.cart_code"
|
||
placeholder="当前仓库内唯一"
|
||
maxlength="64"
|
||
show-word-limit
|
||
@blur="handleCodeBlur"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="名称" prop="cart_name">
|
||
<el-input v-model="formData.cart_name" placeholder="可选" maxlength="100" show-word-limit />
|
||
</el-form-item>
|
||
<el-form-item label="状态" prop="status">
|
||
<el-radio-group v-model="formData.status">
|
||
<el-radio :label="1">启用</el-radio>
|
||
<el-radio :label="0">停用</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item v-if="codeCheckHint">
|
||
<el-text :type="codeCheckHint.type" size="small">{{ codeCheckHint.text }}</el-text>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="submitForm">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 详情 -->
|
||
<el-drawer v-model="detailVisible" title="拣货车详情" size="480px" @close="detailData = null">
|
||
<div v-loading="detailLoading" class="detail-body">
|
||
<template v-if="detailData">
|
||
<el-descriptions :column="1" border size="small">
|
||
<el-descriptions-item label="ID">{{ detailData.cart_id }}</el-descriptions-item>
|
||
<el-descriptions-item label="仓库ID">{{ detailData.warehouse_id }}</el-descriptions-item>
|
||
<el-descriptions-item label="编码">{{ detailData.cart_code }}</el-descriptions-item>
|
||
<el-descriptions-item label="名称">{{ detailData.cart_name || '--' }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag :type="formatPickCartStatus(detailData.status).type" size="small">
|
||
{{ formatPickCartStatus(detailData.status).text }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="绑定任务ID">
|
||
{{ detailData.current_task_id ?? '未绑定' }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="绑定任务编号">
|
||
{{ detailData.current_task_no || '--' }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
</template>
|
||
<el-empty v-else-if="!detailLoading" description="暂无详情" />
|
||
</div>
|
||
</el-drawer>
|
||
|
||
<!-- 扫码查询 -->
|
||
<el-dialog v-model="scanDialogVisible" title="扫码查询拣货车" width="520px" align-center @close="resetScan">
|
||
<el-form label-width="110px" @submit.prevent="submitScan">
|
||
<el-form-item label="拣货车编码">
|
||
<el-input
|
||
v-model="scanForm.cart_code"
|
||
placeholder="输入或扫描条码后回车"
|
||
clearable
|
||
@keyup.enter="submitScan"
|
||
/>
|
||
</el-form-item>
|
||
</el-form>
|
||
<div v-if="scanResult" class="scan-result">
|
||
<el-descriptions :column="1" border size="small">
|
||
<el-descriptions-item label="ID">{{ scanResult.cart_id }}</el-descriptions-item>
|
||
<el-descriptions-item label="编码">{{ scanResult.cart_code }}</el-descriptions-item>
|
||
<el-descriptions-item label="名称">{{ scanResult.cart_name || '--' }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag :type="formatPickCartStatus(scanResult.status).type" size="small">
|
||
{{ formatPickCartStatus(scanResult.status).text }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="绑定任务">
|
||
{{ scanResult.current_task_no || scanResult.current_task_id || '未绑定' }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
</div>
|
||
<template #footer>
|
||
<el-button @click="scanDialogVisible = false">关闭</el-button>
|
||
<el-button type="primary" :loading="scanLoading" @click="submitScan">查询</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 批量新增 -->
|
||
<el-dialog
|
||
v-model="batchDialogVisible"
|
||
title="批量新增拣货车"
|
||
width="760px"
|
||
align-center
|
||
@close="resetBatchForm"
|
||
>
|
||
<el-form ref="batchFormRef" :model="batchForm" :rules="batchRules" label-width="110px">
|
||
<div class="batch-section-title">拣货车编码</div>
|
||
<el-form-item label="编码前缀" prop="code.prefix">
|
||
<el-input v-model="batchForm.code.prefix" placeholder="如 CART-" maxlength="32" show-word-limit />
|
||
</el-form-item>
|
||
<el-form-item label="数字范围" required>
|
||
<div class="batch-range-row">
|
||
<el-form-item prop="code.start_num" class="batch-range-item">
|
||
<el-input-number v-model="batchForm.code.start_num" :min="0" :max="999999" controls-position="right" />
|
||
</el-form-item>
|
||
<span class="batch-range-sep">至</span>
|
||
<el-form-item prop="code.end_num" class="batch-range-item">
|
||
<el-input-number v-model="batchForm.code.end_num" :min="0" :max="999999" controls-position="right" />
|
||
</el-form-item>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item label="数字补零">
|
||
<el-switch v-model="batchForm.code.pad_zero" />
|
||
<el-input-number
|
||
v-if="batchForm.code.pad_zero"
|
||
v-model="batchForm.code.pad_width"
|
||
:min="1"
|
||
:max="8"
|
||
controls-position="right"
|
||
class="batch-pad-width"
|
||
/>
|
||
<el-text v-if="batchForm.code.pad_zero" type="info" size="small" class="batch-pad-hint">
|
||
位数 {{ batchForm.code.pad_width }},不足时左侧补 0
|
||
</el-text>
|
||
</el-form-item>
|
||
|
||
<el-divider />
|
||
|
||
<div class="batch-section-title">拣货车名称</div>
|
||
<el-form-item label="名称前缀" prop="name.prefix">
|
||
<el-input v-model="batchForm.name.prefix" placeholder="留空则不生成名称" maxlength="64" show-word-limit />
|
||
</el-form-item>
|
||
<template v-if="batchForm.name.prefix.trim()">
|
||
<el-form-item label="数字范围" required>
|
||
<div class="batch-range-row">
|
||
<el-form-item prop="name.start_num" class="batch-range-item">
|
||
<el-input-number v-model="batchForm.name.start_num" :min="0" :max="999999" controls-position="right" />
|
||
</el-form-item>
|
||
<span class="batch-range-sep">至</span>
|
||
<el-form-item prop="name.end_num" class="batch-range-item">
|
||
<el-input-number v-model="batchForm.name.end_num" :min="0" :max="999999" controls-position="right" />
|
||
</el-form-item>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item label="数字补零">
|
||
<el-switch v-model="batchForm.name.pad_zero" />
|
||
<el-input-number
|
||
v-if="batchForm.name.pad_zero"
|
||
v-model="batchForm.name.pad_width"
|
||
:min="1"
|
||
:max="8"
|
||
controls-position="right"
|
||
class="batch-pad-width"
|
||
/>
|
||
<el-text v-if="batchForm.name.pad_zero" type="info" size="small" class="batch-pad-hint">
|
||
位数 {{ batchForm.name.pad_width }},不足时左侧补 0
|
||
</el-text>
|
||
</el-form-item>
|
||
<el-form-item v-if="batchNameRangeMismatch">
|
||
<el-text type="danger" size="small">名称数量需与编码数量一致(当前编码 {{ codeBatchCount }} 条,名称 {{ nameBatchCount }} 条)</el-text>
|
||
</el-form-item>
|
||
</template>
|
||
|
||
<el-divider />
|
||
|
||
<el-form-item label="状态" prop="status">
|
||
<el-radio-group v-model="batchForm.status">
|
||
<el-radio :label="1">启用</el-radio>
|
||
<el-radio :label="0">停用</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item label="生成预览">
|
||
<div class="batch-preview">
|
||
<div>将生成 <strong>{{ batchPreviewCount }}</strong> 条拣货车</div>
|
||
<el-table
|
||
v-if="batchPreviewItems.length"
|
||
:data="batchPreviewTableRows"
|
||
size="small"
|
||
border
|
||
class="batch-preview-table"
|
||
>
|
||
<el-table-column prop="index" label="序号" width="70" align="center" />
|
||
<el-table-column prop="cart_code" label="拣货车编码" min-width="160" show-overflow-tooltip />
|
||
<el-table-column prop="cart_name" label="拣货车名称" min-width="160" show-overflow-tooltip />
|
||
</el-table>
|
||
<el-text v-else type="warning" size="small">请完善编码前缀与数字范围</el-text>
|
||
</div>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="batchDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="batchSaving" :disabled="batchPreviewCount <= 0" @click="submitBatchCreate">
|
||
确认新增
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 绑定任务 -->
|
||
<el-dialog
|
||
v-model="bindDialogVisible"
|
||
title="绑定拣货任务"
|
||
width="520px"
|
||
align-center
|
||
@close="resetBindForm"
|
||
>
|
||
<el-form ref="bindFormRef" :model="bindForm" :rules="bindRules" label-width="110px">
|
||
<el-form-item label="拣货车">
|
||
<el-input :model-value="bindForm.cartLabel" disabled />
|
||
</el-form-item>
|
||
<el-form-item label="任务ID" prop="task_id">
|
||
<el-input-number v-model="bindForm.task_id" :min="1" :controls="true" style="width: 100%" />
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-text type="info" size="small">
|
||
若任务已绑定其他拣货车将自动改绑;目标拣货车已绑定其他活动任务时将返回冲突。
|
||
</el-text>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="bindDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="bindLoading" @click="submitBind">确认绑定</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import type { FormInstance, FormRules } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import {
|
||
pickCartBindTaskCart,
|
||
pickCartCodeDuplicateCheck,
|
||
pickCartCreate,
|
||
pickCartDelete,
|
||
pickCartDetail,
|
||
pickCartList,
|
||
pickCartScan,
|
||
pickCartUpdate,
|
||
type PickCartDetailResponse
|
||
} from '@/api/pickcart/pickcart'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import {
|
||
buildPickCartBatchItems,
|
||
buildPickCartListPayload,
|
||
formatPickCartStatus,
|
||
getDefaultPickCartBatchPadWidth,
|
||
getPickCartBatchRangeCount,
|
||
normalizePickCartScanConditionToWhere,
|
||
PICK_CART_BATCH_CREATE_MAX,
|
||
pickCartColumns,
|
||
pickCartScanFields,
|
||
type PickCartRecord
|
||
} from './pickcart-config'
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(pickCartScanFields)))
|
||
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
const columns = pickCartColumns
|
||
const loading = ref(false)
|
||
const saving = ref(false)
|
||
const tableData = ref<PickCartRecord[]>([])
|
||
const queryTime = ref(0)
|
||
const tableSize = ref<'small' | 'default' | 'large'>('small')
|
||
const currentConditionRaw = ref<any>(null)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
|
||
const dialogVisible = ref(false)
|
||
const dialogMode = ref<'create' | 'edit'>('create')
|
||
const formRef = ref<FormInstance>()
|
||
const formData = reactive({
|
||
cart_id: undefined as number | undefined,
|
||
cart_code: '',
|
||
cart_name: '',
|
||
status: 1
|
||
})
|
||
|
||
const codeCheckHint = ref<{ text: string; type: 'success' | 'warning' | 'danger' | 'info' } | null>(null)
|
||
|
||
const rules: FormRules = {
|
||
cart_code: [{ required: true, message: '请输入拣货车编码', trigger: 'blur' }],
|
||
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
|
||
}
|
||
|
||
const detailVisible = ref(false)
|
||
const detailLoading = ref(false)
|
||
const detailData = ref<PickCartDetailResponse | null>(null)
|
||
|
||
const scanDialogVisible = ref(false)
|
||
const scanLoading = ref(false)
|
||
const scanForm = reactive({ cart_code: '' })
|
||
const scanResult = ref<PickCartDetailResponse | null>(null)
|
||
|
||
const bindDialogVisible = ref(false)
|
||
const bindLoading = ref(false)
|
||
const bindFormRef = ref<FormInstance>()
|
||
const bindForm = reactive({
|
||
cart_id: undefined as number | undefined,
|
||
cart_code: '',
|
||
cartLabel: '',
|
||
task_id: undefined as number | undefined
|
||
})
|
||
|
||
const bindRules: FormRules = {
|
||
task_id: [{ required: true, message: '请输入任务ID', trigger: 'blur' }]
|
||
}
|
||
|
||
const batchDialogVisible = ref(false)
|
||
const batchSaving = ref(false)
|
||
const batchFormRef = ref<FormInstance>()
|
||
|
||
function createDefaultBatchNumberRule(start = 1, end = 10) {
|
||
return {
|
||
prefix: '',
|
||
start_num: start,
|
||
end_num: end,
|
||
pad_zero: true,
|
||
pad_width: getDefaultPickCartBatchPadWidth(start, end)
|
||
}
|
||
}
|
||
|
||
const batchForm = reactive({
|
||
code: createDefaultBatchNumberRule(),
|
||
name: {
|
||
...createDefaultBatchNumberRule(),
|
||
prefix: '拣货车'
|
||
},
|
||
status: 1
|
||
})
|
||
|
||
function createBatchRangeValidator(section: 'code' | 'name') {
|
||
return (_rule: unknown, _value: unknown, callback: (error?: Error) => void) => {
|
||
const rule = batchForm[section]
|
||
const count = getPickCartBatchRangeCount(rule.start_num, rule.end_num)
|
||
if (count <= 0) {
|
||
callback(new Error('请输入有效的数字范围'))
|
||
return
|
||
}
|
||
if (section === 'code' && count > PICK_CART_BATCH_CREATE_MAX) {
|
||
callback(new Error(`单次最多新增 ${PICK_CART_BATCH_CREATE_MAX} 条`))
|
||
return
|
||
}
|
||
callback()
|
||
}
|
||
}
|
||
|
||
const validateBatchNameRange = (_rule: unknown, _value: unknown, callback: (error?: Error) => void) => {
|
||
if (!batchForm.name.prefix.trim()) {
|
||
callback()
|
||
return
|
||
}
|
||
const nameCount = getPickCartBatchRangeCount(batchForm.name.start_num, batchForm.name.end_num)
|
||
if (nameCount <= 0) {
|
||
callback(new Error('请输入有效的名称数字范围'))
|
||
return
|
||
}
|
||
if (nameCount !== codeBatchCount.value) {
|
||
callback(new Error('名称数量需与编码数量一致'))
|
||
return
|
||
}
|
||
callback()
|
||
}
|
||
|
||
const batchRules: FormRules = {
|
||
'code.prefix': [{ required: true, message: '请输入编码前缀', trigger: 'blur' }],
|
||
'code.start_num': [{ validator: createBatchRangeValidator('code'), trigger: 'change' }],
|
||
'code.end_num': [{ validator: createBatchRangeValidator('code'), trigger: 'change' }],
|
||
'name.start_num': [{ validator: validateBatchNameRange, trigger: 'change' }],
|
||
'name.end_num': [{ validator: validateBatchNameRange, trigger: 'change' }],
|
||
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
|
||
}
|
||
|
||
const codeBatchCount = computed(() =>
|
||
getPickCartBatchRangeCount(batchForm.code.start_num, batchForm.code.end_num)
|
||
)
|
||
|
||
const nameBatchCount = computed(() =>
|
||
batchForm.name.prefix.trim()
|
||
? getPickCartBatchRangeCount(batchForm.name.start_num, batchForm.name.end_num)
|
||
: 0
|
||
)
|
||
|
||
const batchNameRangeMismatch = computed(() => {
|
||
if (!batchForm.name.prefix.trim()) return false
|
||
return nameBatchCount.value > 0 && nameBatchCount.value !== codeBatchCount.value
|
||
})
|
||
|
||
const batchPreviewItems = computed(() => {
|
||
try {
|
||
if (!batchForm.code.prefix.trim() || codeBatchCount.value <= 0) return []
|
||
if (codeBatchCount.value > PICK_CART_BATCH_CREATE_MAX) return []
|
||
if (batchNameRangeMismatch.value) return []
|
||
return buildPickCartBatchItems(batchForm)
|
||
} catch {
|
||
return []
|
||
}
|
||
})
|
||
|
||
const batchPreviewCount = computed(() => batchPreviewItems.value.length)
|
||
|
||
const batchPreviewTableRows = computed(() =>
|
||
batchPreviewItems.value.slice(0, 5).map((item, index) => ({
|
||
index: index + 1,
|
||
cart_code: item.cart_code,
|
||
cart_name: item.cart_name || '--'
|
||
}))
|
||
)
|
||
|
||
watch(
|
||
() => [batchForm.code.start_num, batchForm.code.end_num, batchForm.code.pad_zero] as const,
|
||
() => {
|
||
if (!batchForm.code.pad_zero) return
|
||
batchForm.code.pad_width = getDefaultPickCartBatchPadWidth(
|
||
batchForm.code.start_num,
|
||
batchForm.code.end_num
|
||
)
|
||
}
|
||
)
|
||
|
||
watch(
|
||
() => [batchForm.name.start_num, batchForm.name.end_num, batchForm.name.pad_zero] as const,
|
||
() => {
|
||
if (!batchForm.name.pad_zero) return
|
||
batchForm.name.pad_width = getDefaultPickCartBatchPadWidth(
|
||
batchForm.name.start_num,
|
||
batchForm.name.end_num
|
||
)
|
||
}
|
||
)
|
||
|
||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||
|
||
async function loadList() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = normalizePickCartScanConditionToWhere(currentConditionRaw.value)
|
||
const res: any = await pickCartList(
|
||
buildPickCartListPayload({
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize,
|
||
where
|
||
})
|
||
)
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取拣货车列表失败')
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
return
|
||
}
|
||
const data = res?.data || {}
|
||
tableData.value = data.list || []
|
||
pagination.total = Number(data.pagination?.total ?? 0)
|
||
} catch {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('获取拣货车列表失败')
|
||
} finally {
|
||
queryTime.value = Date.now() - start
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
currentConditionRaw.value = condition
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleSubmit() {
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
if (scanBox.value?.reset) {
|
||
scanBox.value.reset()
|
||
} else if (scanBox.value?.clear) {
|
||
scanBox.value.clear()
|
||
}
|
||
loadList()
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadList()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function resetForm() {
|
||
formData.cart_id = undefined
|
||
formData.cart_code = ''
|
||
formData.cart_name = ''
|
||
formData.status = 1
|
||
codeCheckHint.value = null
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
function openCreate() {
|
||
dialogMode.value = 'create'
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
}
|
||
|
||
function resetBatchForm() {
|
||
batchForm.code = {
|
||
prefix: 'CART-',
|
||
start_num: 1,
|
||
end_num: 10,
|
||
pad_zero: true,
|
||
pad_width: 2
|
||
}
|
||
batchForm.name = {
|
||
prefix: '拣货车',
|
||
start_num: 1,
|
||
end_num: 10,
|
||
pad_zero: false,
|
||
pad_width: 1
|
||
}
|
||
batchForm.status = 1
|
||
batchFormRef.value?.clearValidate()
|
||
}
|
||
|
||
function openBatchCreate() {
|
||
batchDialogVisible.value = true
|
||
resetBatchForm()
|
||
}
|
||
|
||
async function submitBatchCreate() {
|
||
if (!batchFormRef.value || batchSaving.value) return
|
||
const valid = await batchFormRef.value.validate().catch(() => false)
|
||
if (!valid) return
|
||
|
||
const items = buildPickCartBatchItems(batchForm)
|
||
if (!items.length) {
|
||
ElMessage.warning('没有可新增的拣货车')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认批量新增 ${items.length} 辆拣货车吗?`,
|
||
'批量新增确认',
|
||
{ type: 'warning' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchSaving.value = true
|
||
let successCount = 0
|
||
let failCount = 0
|
||
let lastError = ''
|
||
|
||
try {
|
||
for (const item of items) {
|
||
try {
|
||
const payload: { cart_code: string; cart_name?: string; status: number } = {
|
||
cart_code: item.cart_code,
|
||
status: batchForm.status
|
||
}
|
||
if (item.cart_name) {
|
||
payload.cart_name = item.cart_name
|
||
}
|
||
const res: any = await pickCartCreate(payload)
|
||
if (isSuccess(res)) {
|
||
successCount += 1
|
||
} else {
|
||
failCount += 1
|
||
lastError = res?.message || '新增失败'
|
||
}
|
||
} catch {
|
||
failCount += 1
|
||
lastError = '新增失败'
|
||
}
|
||
}
|
||
|
||
if (failCount === 0) {
|
||
ElMessage.success(`批量新增成功,共 ${successCount} 条`)
|
||
batchDialogVisible.value = false
|
||
loadList()
|
||
} else if (successCount === 0) {
|
||
ElMessage.error(lastError || `批量新增失败,共 ${failCount} 条`)
|
||
} else {
|
||
ElMessage.warning(`批量新增完成:成功 ${successCount} 条,失败 ${failCount} 条`)
|
||
loadList()
|
||
}
|
||
} finally {
|
||
batchSaving.value = false
|
||
}
|
||
}
|
||
|
||
function openEdit(row: PickCartRecord) {
|
||
if (!row.cart_id) return
|
||
dialogMode.value = 'edit'
|
||
dialogVisible.value = true
|
||
formData.cart_id = row.cart_id
|
||
formData.cart_code = row.cart_code || ''
|
||
formData.cart_name = row.cart_name || ''
|
||
formData.status = Number(row.status ?? 1)
|
||
codeCheckHint.value = null
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
async function handleCodeBlur() {
|
||
const code = formData.cart_code.trim()
|
||
if (!code) {
|
||
codeCheckHint.value = null
|
||
return
|
||
}
|
||
try {
|
||
const payload: { cart_code: string; exclude_cart_id?: number } = { cart_code: code }
|
||
if (dialogMode.value === 'edit' && formData.cart_id) {
|
||
payload.exclude_cart_id = formData.cart_id
|
||
}
|
||
const res: any = await pickCartCodeDuplicateCheck(payload)
|
||
if (!isSuccess(res)) return
|
||
const data = res?.data || {}
|
||
if (data.duplicated) {
|
||
codeCheckHint.value = {
|
||
type: 'danger',
|
||
text: `编码已存在:${data.cart_name || data.cart_code || ''}(ID ${data.cart_id ?? '--'})`
|
||
}
|
||
} else {
|
||
codeCheckHint.value = { type: 'success', text: '编码可用' }
|
||
}
|
||
} catch {
|
||
codeCheckHint.value = null
|
||
}
|
||
}
|
||
|
||
async function submitForm() {
|
||
if (!formRef.value || saving.value) return
|
||
const valid = await formRef.value.validate().catch(() => false)
|
||
if (!valid) return
|
||
|
||
saving.value = true
|
||
try {
|
||
if (dialogMode.value === 'create') {
|
||
const res: any = await pickCartCreate({
|
||
cart_code: formData.cart_code.trim(),
|
||
cart_name: formData.cart_name.trim() || undefined,
|
||
status: formData.status
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '新增失败')
|
||
return
|
||
}
|
||
ElMessage.success('新增成功')
|
||
} else {
|
||
if (!formData.cart_id) return
|
||
const res: any = await pickCartUpdate({
|
||
cart_id: formData.cart_id,
|
||
cart_code: formData.cart_code.trim() || undefined,
|
||
cart_name: formData.cart_name.trim() || undefined,
|
||
status: formData.status
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '更新失败')
|
||
return
|
||
}
|
||
ElMessage.success('更新成功')
|
||
}
|
||
dialogVisible.value = false
|
||
loadList()
|
||
} catch {
|
||
ElMessage.error('保存失败')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
function handleDelete(row: PickCartRecord) {
|
||
if (!row.cart_id) return
|
||
const label = row.cart_name || row.cart_code || String(row.cart_id)
|
||
ElMessageBox.confirm(
|
||
`确认删除拣货车「${label}」吗?若已绑定任务则无法删除。`,
|
||
'提示',
|
||
{ type: 'warning' }
|
||
)
|
||
.then(async () => {
|
||
const res: any = await pickCartDelete({ cart_id: row.cart_id as number })
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
return
|
||
}
|
||
ElMessage.success('删除成功')
|
||
if (tableData.value.length === 1 && pagination.currentPage > 1) {
|
||
pagination.currentPage -= 1
|
||
}
|
||
loadList()
|
||
})
|
||
.catch(() => undefined)
|
||
}
|
||
|
||
async function openDetail(row: PickCartRecord) {
|
||
if (!row.cart_id) return
|
||
detailVisible.value = true
|
||
detailLoading.value = true
|
||
detailData.value = null
|
||
try {
|
||
const res: any = await pickCartDetail({ cart_id: row.cart_id })
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取详情失败')
|
||
return
|
||
}
|
||
detailData.value = res?.data || null
|
||
} catch {
|
||
ElMessage.error('获取详情失败')
|
||
} finally {
|
||
detailLoading.value = false
|
||
}
|
||
}
|
||
|
||
function openScanDialog() {
|
||
scanDialogVisible.value = true
|
||
resetScan()
|
||
}
|
||
|
||
function resetScan() {
|
||
scanForm.cart_code = ''
|
||
scanResult.value = null
|
||
}
|
||
|
||
async function submitScan() {
|
||
const code = scanForm.cart_code.trim()
|
||
if (!code) {
|
||
ElMessage.warning('请输入拣货车编码')
|
||
return
|
||
}
|
||
scanLoading.value = true
|
||
try {
|
||
const res: any = await pickCartScan({ cart_code: code })
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '查询失败')
|
||
scanResult.value = null
|
||
return
|
||
}
|
||
scanResult.value = res?.data || null
|
||
if (!scanResult.value) {
|
||
ElMessage.warning('未找到对应拣货车')
|
||
}
|
||
} catch {
|
||
ElMessage.error('查询失败')
|
||
scanResult.value = null
|
||
} finally {
|
||
scanLoading.value = false
|
||
}
|
||
}
|
||
|
||
function resetBindForm() {
|
||
bindForm.cart_id = undefined
|
||
bindForm.cart_code = ''
|
||
bindForm.cartLabel = ''
|
||
bindForm.task_id = undefined
|
||
bindFormRef.value?.clearValidate()
|
||
}
|
||
|
||
function openBind(row: PickCartRecord) {
|
||
if (!row.cart_id) return
|
||
bindForm.cart_id = row.cart_id
|
||
bindForm.cart_code = row.cart_code || ''
|
||
bindForm.cartLabel = `${row.cart_code}${row.cart_name ? `(${row.cart_name})` : ''}`
|
||
bindForm.task_id = undefined
|
||
bindDialogVisible.value = true
|
||
bindFormRef.value?.clearValidate()
|
||
}
|
||
|
||
async function submitBind() {
|
||
if (!bindFormRef.value || bindLoading.value || !bindForm.cart_id) return
|
||
const valid = await bindFormRef.value.validate().catch(() => false)
|
||
if (!valid || !bindForm.task_id) return
|
||
|
||
bindLoading.value = true
|
||
try {
|
||
const res: any = await pickCartBindTaskCart({
|
||
task_id: bindForm.task_id,
|
||
cart_id: bindForm.cart_id,
|
||
cart_code: bindForm.cart_code || undefined
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '绑定失败')
|
||
return
|
||
}
|
||
const data = res?.data || {}
|
||
ElMessage.success(`绑定成功:任务 ${data.task_no || bindForm.task_id}`)
|
||
bindDialogVisible.value = false
|
||
loadList()
|
||
} catch {
|
||
ElMessage.error('绑定失败')
|
||
} finally {
|
||
bindLoading.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadList()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.pickcart-container {
|
||
display: flex;
|
||
width: 100%;
|
||
background-color: #f0f2f5;
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 10px;
|
||
overflow: hidden;
|
||
min-width: 0;
|
||
}
|
||
|
||
.toolbar {
|
||
padding: 5px 8px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 12px;
|
||
flex-wrap: wrap;
|
||
background-color: #fff;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.toolbar-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
min-width: 0;
|
||
}
|
||
|
||
.upper-wrapper {
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.upper-wrapper :deep(.upper-table-container) {
|
||
height: 100%;
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: #909399;
|
||
padding: 16px;
|
||
}
|
||
}
|
||
|
||
.detail-body {
|
||
padding: 0 4px;
|
||
}
|
||
|
||
.scan-result {
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.batch-range-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.batch-range-item {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.batch-range-sep {
|
||
color: #606266;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.batch-pad-width {
|
||
margin-left: 12px;
|
||
width: 120px;
|
||
}
|
||
|
||
.batch-pad-hint {
|
||
margin-left: 8px;
|
||
}
|
||
|
||
.batch-section-title {
|
||
margin: 4px 0 10px;
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.batch-preview {
|
||
width: 100%;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.batch-preview-table {
|
||
margin-top: 8px;
|
||
}
|
||
</style>
|