|
|
<template> <div class="mod-config"> <el-form :inline="true" label-position="top"> <!-- 栈板只归属主工厂,查询显式传当前工厂,不提供工厂选择或子site拆分 - rqrq --> <el-form-item label="托盘ID"> <el-input v-model="queryData.palletId" placeholder="请输入托盘ID" style="width: 150px;" clearable @keyup.enter.native="getDataList" /> </el-form-item> <el-form-item label="托盘大分类"> <el-select v-model="queryData.palletFamily" placeholder="请选择" style="width: 140px;" clearable @change="onQueryFamilyChange"> <el-option v-for="item in palletFamilyOptions" :key="item.palletFamily" :label="item.palletFamilyDesc || item.palletFamily" :value="item.palletFamily" /> </el-select> </el-form-item> <el-form-item label="托盘类型"> <el-select v-model="queryData.palletType" placeholder="请选择" style="width: 150px;" clearable> <el-option v-for="item in palletTypeOptions" :key="item.palletType" :label="item.typeDesc || item.palletType" :value="item.palletType" /> </el-select> </el-form-item><!-- <el-form-item label="托盘状态">--><!-- <el-select v-model="queryData.status" placeholder="请选择" style="width: 120px;" clearable>--><!-- <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />--><!-- </el-select>--><!-- </el-form-item>--> <el-form-item label="站点"> <el-input v-model="queryData.locationCode" placeholder="请输入站点编码" style="width: 140px;" clearable @keyup.enter.native="getDataList" /> </el-form-item> <el-form-item label="区域"> <el-input v-model="queryData.area" placeholder="请输入区域编码" style="width: 130px;" clearable @keyup.enter.native="getDataList" /> </el-form-item> <!-- 是否在立库按wcs_location是否有值筛选,清空表示不限制 - rqrq --> <el-form-item label="是否在立库"> <el-select v-model="queryData.inStockFlag" placeholder="请选择" style="width: 110px;" clearable> <el-option label="是" value="Y" /> <el-option label="否" value="N" /> </el-select> </el-form-item>
<el-form-item style="margin-top: 20px;"> <el-button type="primary" :loading="queryLoading" :disabled="queryLoading" @click="getDataList">查询</el-button> <el-button :disabled="queryLoading" @click="resetQuery">重置</el-button> <!-- 导出字段与页面字段保持同口径,避免口径不一致 - rqrq --> <download-excel :fields="fields()" :data="exportData" type="xls" :name="exportName" :header="exportHeader" :footer="exportFooter" :fetch="createExportData" :before-generate="startDownload" :before-finish="finishDownload" :disabled="exportLoading" :class="{ 'is-disabled': exportLoading }" :style="{ pointerEvents: exportLoading ? 'none' : 'auto' }" worksheet="托盘" class="el-button el-button--primary el-button--medium" > 导出 </download-excel> </el-form-item> <el-form-item style="margin-top: 20px;"><!-- <el-button type="primary" @click="openCreateDialog">新增托盘</el-button>--> <el-button type="success" @click="openBatchGenerateDialog">批量新增托盘</el-button> </el-form-item> </el-form>
<el-table :height="height" :data="dataList" border stripe v-loading="tableLoading" @selection-change="selectionChangeHandle" style="width: 100%;" > <el-table-column type="selection" width="55" align="center" header-align="center" /> <el-table-column v-for="(item, index) in columnList" :key="index" :prop="item.columnProp" :label="item.columnLabel" :min-width="item.columnWidth" :align="item.align" :header-align="item.headerAlign" :show-overflow-tooltip="item.showOverflowTooltip !== false" > <template slot-scope="scope"> <span>{{ formatColumnValue(scope.row, item) }}</span> </template> </el-table-column><!-- <el-table-column fixed="right" label="操作" width="140" align="center" header-align="center">--><!-- <template slot-scope="scope">--><!-- <a style="margin-right: 10px;" @click="openEditDialog(scope.row)">编辑</a>--><!-- <a style="color: #f56c6c;" @click="deleteOne(scope.row)">删除</a>--><!-- </template>--><!-- </el-table-column>--> </el-table>
<el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper" />
<!-- 托盘编辑弹窗:统一维护主表字段并防重复提交 - rqrq --> <el-dialog :title="editDialog.title" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="editDialog.visible" width="980px" > <el-form ref="editForm" :model="editFormData" :rules="formRules" label-position="top"> <el-row :gutter="20"> <el-col :span="6"> <el-form-item label="工厂" prop="site"> <el-select v-model="editFormData.site" :disabled="editDialog.readonlySite" style="width: 100%;" @change="onEditSiteChange"> <el-option v-for="item in siteOptions" :key="item.site" :label="item.siteName || item.site" :value="item.site" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="托盘ID" prop="palletId"> <el-input v-model="editFormData.palletId" :readonly="!!editFormData.id" placeholder="为空时后端自动生成" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="托盘大分类" prop="palletFamily"> <el-select v-model="editFormData.palletFamily" style="width: 100%;" @change="onEditFamilyChange"> <el-option v-for="item in editDialog.palletFamilyOptions" :key="item.palletFamily" :label="item.palletFamilyDesc || item.palletFamily" :value="item.palletFamily" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="托盘类型" prop="palletType"> <el-select v-model="editFormData.palletType" style="width: 100%;"> <el-option v-for="item in editDialog.palletTypeOptions" :key="item.palletType" :label="item.typeDesc || item.palletType" :value="item.palletType" /> </el-select> </el-form-item> </el-col> </el-row>
<el-row :gutter="20"> <el-col :span="6"> <el-form-item label="托盘状态" prop="status"> <el-select v-model="editFormData.status" style="width: 100%;"> <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="区域编码"> <el-input v-model="editFormData.area" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="站点编码"> <el-input v-model="editFormData.locationCode" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="货架编码"> <el-input v-model="editFormData.wcsLocation" /> </el-form-item> </el-col> </el-row>
<el-row :gutter="20"> <el-col :span="6"> <el-form-item label="托盘尺寸"> <el-input v-model="editFormData.palletSize" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="最大承重(kg)"> <el-input v-model="editFormData.maxLoad" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="自动分拣"> <el-select v-model="editFormData.autoSort" style="width: 100%;"> <el-option label="是" value="Y" /> <el-option label="否" value="N" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="分拣方式"> <el-select v-model="editFormData.soreType" style="width: 100%;"> <el-option label="人工/混装" :value="0" /> <el-option label="气胀轴自动分拣" :value="1" /> <el-option label="抱箱自动分拣" :value="2" /> <el-option label="直接出库" :value="3" /> </el-select> </el-form-item> </el-col> </el-row>
<el-row :gutter="20"> <el-col :span="6"> <el-form-item label="空托盘标记"> <el-select v-model="editFormData.emptyFlag" style="width: 100%;"> <el-option label="是" value="Y" /> <el-option label="否" value="N" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="调用标记"> <el-select v-model="editFormData.callingFlag" style="width: 100%;"> <el-option label="是" value="Y" /> <el-option label="否" value="N" /> </el-select> </el-form-item> </el-col> </el-row>
<el-row> <el-col :span="24"> <el-form-item label="备注"> <el-input v-model="editFormData.remark" type="textarea" :rows="3" /> </el-form-item> </el-col> </el-row> </el-form>
<div slot="footer" class="dialog-footer" style="margin-top: 52px"> <el-button type="primary" :loading="editDialog.saveLoading" :disabled="editDialog.saveLoading" @click="saveEditForm"> {{ editDialog.saveLoading ? '保存中...' : '保存' }} </el-button> <el-button :disabled="editDialog.saveLoading" @click="editDialog.visible = false">取消</el-button> </div> </el-dialog>
<!-- 批量新增弹窗:按大分类前缀生成连续托盘号,单类单次<=1000 - rqrq --> <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :title="'批量新增托盘 - 工厂: ' + batchGenerateDialog.site" :visible.sync="batchGenerateDialog.visible" width="520px" > <div v-loading="batchGenerateDialog.loading"> <div class="batch-header"> <span class="batch-col-name">托盘大分类</span> <span class="batch-col-count">当前数量</span> <span class="batch-col-input">新增数量</span> </div> <div v-for="(item, index) in batchGenerateDialog.palletNoList" :key="index" class="batch-row"> <span class="batch-col-name">{{ item.palletFamilyDesc }} ({{ item.prefix }})</span> <span class="batch-col-count">{{ item.totalCount || 0 }}</span> <span class="batch-col-input"> <el-input v-model.number="item.generateCount" placeholder="0" size="small" style="width: 100px;" @input="validateCount(item)" /> </span> </div> <div class="batch-tip"> <i class="el-icon-info" /> 每种托盘单次最多新增1000个 </div> </div> <div slot="footer" class="dialog-footer"> <el-button type="primary" :disabled="batchGenerateDialog.saving" :loading="batchGenerateDialog.saving" @click="doBatchGenerate"> {{ batchGenerateDialog.saving ? '生成中...' : '确认生成' }} </el-button> <el-button :disabled="batchGenerateDialog.saving" @click="batchGenerateDialog.visible = false">取消</el-button> </div> </el-dialog> </div></template>
<script>import { haiAnBatchGeneratePallet, haiAnDeletePallet, haiAnGetMaxPalletNoByFamily, haiAnGetPalletFamilyList, haiAnGetPalletList, haiAnGetPalletStatusOptions, haiAnGetPalletTypeList, haiAnGetUserAuthorizedSites, haiAnSavePallet, haiAnUpdatePallet} from '@/api/haianWarehouse/warehousePallet.js'
export default { name: 'WarehousePallet54', data() { return { queryLoading: false, // 查询序号隔离切换主工厂前的旧响应,导出加载标记阻止重复请求 - rqrq
querySequence: 0, exportLoading: false, tableLoading: false, height: 450, queryData: { site: this.$store.state.user.site || '', palletId: '', palletType: '', palletFamily: '', status: '', locationCode: '', area: '', inStockFlag: '', partNo: '', batchNo: '', page: 1, limit: 20 }, statusOptions: [], siteOptions: [], palletFamilyOptions: [], palletTypeOptions: [], dataList: [], pageIndex: 1, pageSize: 20, totalPage: 0, selectedRows: [], exportData: [], exportName: '托盘信息' + this.dayjs().format('YYYYMMDDHHmmss'), exportHeader: ['托盘信息'], exportFooter: [], columnList: [ // { columnProp: 'site', columnLabel: '工厂', columnWidth: 90, align: 'center', headerAlign: 'center' },
{ columnProp: 'palletId', columnLabel: '托盘ID', columnWidth: 120, align: 'center', headerAlign: 'center' }, { columnProp: 'palletFamilyDesc', columnLabel: '托盘大分类', columnWidth: 120, align: 'center', headerAlign: 'center' }, { columnProp: 'typeDesc', columnLabel: '托盘类型', columnWidth: 160, align: 'center', headerAlign: 'center' }, { columnProp: 'height', columnLabel: '高度', columnWidth: 120, align: 'center', headerAlign: 'center', formatter: 'height' }, // { columnProp: 'status', columnLabel: '托盘状态', columnWidth: 100, align: 'center', headerAlign: 'center', formatter: 'status' },
{ columnProp: 'area', columnLabel: '区域', columnWidth: 90, align: 'center', headerAlign: 'center' }, { columnProp: 'locationCode', columnLabel: '所在位置', columnWidth: 120, align: 'center', headerAlign: 'center' }, { columnProp: 'wcsLocation', columnLabel: '立库货架', columnWidth: 120, align: 'center', headerAlign: 'center' }, { columnProp: 'emptyFlag', columnLabel: '空托盘', columnWidth: 90, align: 'center', headerAlign: 'center', formatter: 'yn' }, { columnProp: 'callingFlag', columnLabel: '调用标记', columnWidth: 90, align: 'center', headerAlign: 'center', formatter: 'yn' }, { columnProp: 'remark', columnLabel: '备注', columnWidth: 220, align: 'left', headerAlign: 'center' }, { columnProp: 'manualRemark', columnLabel: '手工备注', columnWidth: 220, align: 'left', headerAlign: 'center' }, { columnProp: 'createdBy', columnLabel: '创建人', columnWidth: 100, align: 'center', headerAlign: 'center' }, { columnProp: 'createdTime', columnLabel: '创建时间', columnWidth: 160, align: 'center', headerAlign: 'center' }, { columnProp: 'updatedBy', columnLabel: '修改人', columnWidth: 100, align: 'center', headerAlign: 'center' }, { columnProp: 'updatedTime', columnLabel: '修改时间', columnWidth: 160, align: 'center', headerAlign: 'center' } ], editDialog: { visible: false, title: '新增托盘', saveLoading: false, readonlySite: false, palletFamilyOptions: [], palletTypeOptions: [] }, editFormData: this.createEmptyForm(), formRules: { site: [{ required: true, message: '工厂不能为空', trigger: 'change' }], palletFamily: [{ required: true, message: '托盘大分类不能为空', trigger: 'change' }], palletType: [{ required: true, message: '托盘类型不能为空', trigger: 'change' }], status: [{ required: true, message: '托盘状态不能为空', trigger: 'change' }] }, batchGenerateDialog: { visible: false, loading: false, saving: false, site: '', palletNoList: [] } } }, computed: { // 栈板查询使用当前主工厂;空值由查询入口拦截,不能退回旧工厂或扩展为全部工厂 - rqrq
currentSite () { return String(this.$store.state.user.site || '').trim() } }, watch: { // 当前主工厂变化后重新初始化,清除原工厂筛选和结果,防止缓存页串厂 - rqrq
currentSite () { this.initializePage() } }, mounted() { this.$nextTick(() => { this.height = window.innerHeight - 240 }) }, activated() { this.initializePage() }, created() { this.initializePage() }, methods: { // 页面初始化先同步当前主工厂,再加载分类、类型及列表;查询不读取工厂或子site下拉 - rqrq
initializePage() { this.syncQuerySite() this.getStatusOptions() this.getPalletFamilyOptions(this.queryData.site) this.getPalletTypeOptions(this.queryData.site, this.queryData.palletFamily) this.getDataList() }, // 主工厂变化时清空旧分类和结果并使旧请求失效;site始终显式写入查询参数,不拆分子工厂 - rqrq
syncQuerySite () { if (this.queryData.site !== this.currentSite) { this.queryData.site = this.currentSite this.queryData.palletFamily = '' this.queryData.palletType = '' this.palletFamilyOptions = [] this.palletTypeOptions = [] this.pageIndex = 1 this.dataList = [] this.totalPage = 0 this.selectedRows = [] this.querySequence++ this.queryLoading = false this.tableLoading = false } }, // 构造表单默认值,确保新增场景字段初始化一致 - rqrq
createEmptyForm() { return { id: null, site: this.$store.state.user.site || '', palletId: '', palletType: '', palletFamily: '', palletSize: '', maxLoad: '', status: 'AVAILABLE', locationCode: '', wcsLocation: '', area: '', callingFlag: 'N', autoSort: 'N', soreType: 0, emptyFlag: 'N', remark: '', createdBy: this.$store.state.user.name, updatedBy: this.$store.state.user.name } }, // 状态字典查询 - rqrq
getStatusOptions() { haiAnGetPalletStatusOptions({}).then(({ data }) => { if (data && data.code === 0) { this.statusOptions = data.options || [] } else { this.statusOptions = [] } }).catch(() => { this.statusOptions = [] }) }, // 工厂下拉查询:仅展示当前用户授权工厂 - rqrq
getSiteOptions() { const inData = { userName: this.$store.state.user.name } haiAnGetUserAuthorizedSites(inData).then(({ data }) => { if (data && data.code === 0) { this.siteOptions = data.rows || [] } else { this.siteOptions = [] } }).catch(() => { this.siteOptions = [] }) }, // 托盘大分类下拉查询(按site) - rqrq
getPalletFamilyOptions(site) { if (!site) { this.palletFamilyOptions = [] return } haiAnGetPalletFamilyList({ site }).then(({ data }) => { // 切换主工厂后的旧分类响应不再回填当前筛选 - rqrq
if (site !== this.currentSite) return if (data && data.code === 0) { this.palletFamilyOptions = data.rows || [] } else { this.palletFamilyOptions = [] } }).catch(() => { if (site !== this.currentSite) return this.palletFamilyOptions = [] }) }, // 托盘类型下拉查询(按site+family) - rqrq
getPalletTypeOptions(site, palletFamily) { if (!site) { this.palletTypeOptions = [] return } const inData = { site, palletFamily: palletFamily || '' } haiAnGetPalletTypeList(inData).then(({ data }) => { // 工厂或大分类已变化时忽略旧类型响应,避免跨厂或跨分类回填 - rqrq
if (site !== this.currentSite || inData.palletFamily !== this.queryData.palletFamily) return if (data && data.code === 0) { this.palletTypeOptions = data.rows || [] } else { this.palletTypeOptions = [] } }).catch(() => { if (site !== this.currentSite || inData.palletFamily !== this.queryData.palletFamily) return this.palletTypeOptions = [] }) }, // 查询工厂变化后重置分类/类型,避免跨site脏筛选条件 - rqrq
onQuerySiteChange(val) { this.queryData.palletFamily = '' this.queryData.palletType = '' this.getPalletFamilyOptions(val) this.getPalletTypeOptions(val, '') }, // 查询分类变化后联动托盘类型列表 - rqrq
onQueryFamilyChange(val) { this.queryData.palletType = '' this.getPalletTypeOptions(this.queryData.site, val) }, // 列表与分页只按当前主工厂查询,缺失工厂拒绝请求;重复查询拦截,旧响应不覆盖切厂后的结果 - rqrq
getDataList() { this.syncQuerySite() if (this.queryLoading) return if (!this.currentSite) { this.$alert('当前工厂不能为空,请先选择当前工厂', '提示', { confirmButtonText: '确定' }) return } this.queryLoading = true this.tableLoading = true this.queryData.page = this.pageIndex this.queryData.limit = this.pageSize const sequence = ++this.querySequence const query = { ...this.queryData, site: this.currentSite } haiAnGetPalletList(query).then(({ data }) => { if (sequence !== this.querySequence || query.site !== this.currentSite) return if (data && data.code === 0) { this.dataList = (data.page && data.page.list) || [] this.totalPage = (data.page && data.page.totalCount) || 0 } else { this.dataList = [] this.totalPage = 0 this.$alert((data && data.msg) || '查询失败', '提示', { confirmButtonText: '确定' }) } }).catch(() => { if (sequence !== this.querySequence || query.site !== this.currentSite) return this.dataList = [] this.totalPage = 0 this.$message.error('查询失败') }).finally(() => { if (sequence === this.querySequence) { this.queryLoading = false this.tableLoading = false } }) }, // 查询重置:保留当前登录site作为默认工厂 - rqrq
resetQuery() { this.pageIndex = 1 this.queryData = { site: this.$store.state.user.site || '', palletId: '', palletType: '', palletFamily: '', status: '', locationCode: '', area: '', inStockFlag: '', partNo: '', batchNo: '', page: 1, limit: this.pageSize } this.getPalletFamilyOptions(this.queryData.site) this.getPalletTypeOptions(this.queryData.site, '') this.getDataList() }, // 表格多选回调(预留批量删除能力) - rqrq
selectionChangeHandle(val) { this.selectedRows = val || [] }, // 分页大小变化回调 - rqrq
sizeChangeHandle(val) { this.pageSize = val this.pageIndex = 1 this.getDataList() }, // 当前页变化回调 - rqrq
currentChangeHandle(val) { this.pageIndex = val this.getDataList() }, // 打开新增弹窗:清空表单并按site加载下拉 - rqrq
openCreateDialog() { // 既有新增表单仍使用授权工厂选项,仅打开新增时加载,不影响主工厂查询口径 - rqrq
this.getSiteOptions() this.editDialog.title = '新增托盘' this.editDialog.visible = true this.editDialog.readonlySite = false this.editDialog.saveLoading = false this.editDialog.palletFamilyOptions = [...this.palletFamilyOptions] this.editDialog.palletTypeOptions = [...this.palletTypeOptions] this.editFormData = this.createEmptyForm() this.$nextTick(() => { if (this.$refs.editForm) { this.$refs.editForm.clearValidate() } }) }, // 打开编辑弹窗:保持独立页面逻辑,不复用旧页面主流程 - rqrq
openEditDialog(row) { this.editDialog.title = '编辑托盘' this.editDialog.visible = true this.editDialog.readonlySite = true this.editDialog.saveLoading = false this.editDialog.palletFamilyOptions = [...this.palletFamilyOptions] this.editDialog.palletTypeOptions = [] this.editFormData = { id: row.id, site: row.site, palletId: row.palletId, palletType: row.palletType, palletFamily: row.palletFamily, palletSize: row.palletSize, maxLoad: row.maxLoad, status: row.status, locationCode: row.locationCode, wcsLocation: row.wcsLocation, area: row.area, callingFlag: row.callingFlag || 'N', autoSort: row.autoSort || 'N', soreType: row.soreType == null ? 0 : row.soreType, emptyFlag: row.emptyFlag || 'N', remark: row.remark, updatedBy: this.$store.state.user.name } this.getEditPalletTypeOptions(row.site, row.palletFamily) this.$nextTick(() => { if (this.$refs.editForm) { this.$refs.editForm.clearValidate() } }) }, // 编辑弹窗site变化后联动分类和类型,防止跨site遗留值 - rqrq
onEditSiteChange(val) { this.editFormData.palletFamily = '' this.editFormData.palletType = '' this.getEditFamilyOptions(val) this.getEditPalletTypeOptions(val, '') }, // 编辑弹窗大分类变化后联动托盘类型 - rqrq
onEditFamilyChange(val) { this.editFormData.palletType = '' this.getEditPalletTypeOptions(this.editFormData.site, val) }, // 编辑弹窗分类选项查询 - rqrq
getEditFamilyOptions(site) { if (!site) { this.editDialog.palletFamilyOptions = [] return } haiAnGetPalletFamilyList({ site }).then(({ data }) => { if (data && data.code === 0) { this.editDialog.palletFamilyOptions = data.rows || [] } else { this.editDialog.palletFamilyOptions = [] } }).catch(() => { this.editDialog.palletFamilyOptions = [] }) }, // 编辑弹窗类型选项查询 - rqrq
getEditPalletTypeOptions(site, palletFamily) { if (!site) { this.editDialog.palletTypeOptions = [] return } haiAnGetPalletTypeList({ site, palletFamily: palletFamily || '' }).then(({ data }) => { if (data && data.code === 0) { this.editDialog.palletTypeOptions = data.rows || [] } else { this.editDialog.palletTypeOptions = [] } }).catch(() => { this.editDialog.palletTypeOptions = [] }) }, // 保存弹窗:统一使用loading+disabled防重复提交,失败时按业务/系统错误区分 - rqrq
saveEditForm() { this.$refs.editForm.validate(valid => { if (!valid) { return } this.editDialog.saveLoading = true const submitData = { ...this.editFormData } const request = submitData.id ? haiAnUpdatePallet(submitData) : haiAnSavePallet(submitData) request.then(({ data }) => { if (data && data.code === 0) { this.$message.success(data.msg || '保存成功') this.editDialog.visible = false this.getDataList() } else { this.$alert((data && data.msg) || '保存失败', '提示', { confirmButtonText: '确定' }) } }).catch(() => { this.$message.error('系统异常,请稍后重试') }).finally(() => { this.editDialog.saveLoading = false }) }) }, // 单条删除:后端执行软删除,保留追溯数据 - rqrq
deleteOne(row) { this.$confirm(`确定删除托盘 [${row.palletId}] 吗?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { const payload = { ids: [row.id], operator: this.$store.state.user.name } haiAnDeletePallet(payload).then(({ data }) => { if (data && data.code === 0) { this.$message.success(data.msg || '删除成功') this.getDataList() } else { this.$alert((data && data.msg) || '删除失败', '提示', { confirmButtonText: '确定' }) } }).catch(() => { this.$message.error('系统异常,请稍后重试') }) }).catch(() => {}) }, // 批量新增弹窗打开:固定按当前登录site生成,避免跨工厂误生成 - rqrq
openBatchGenerateDialog() { this.batchGenerateDialog.site = this.$store.state.user.site || this.queryData.site if (!this.batchGenerateDialog.site) { this.$message.warning('请先选择工厂') return } this.batchGenerateDialog.visible = true this.batchGenerateDialog.saving = false this.batchGenerateDialog.palletNoList = [] this.loadPalletMaxNos() }, // 加载当前号段统计:用于提示每类托盘现有数量与新增起点 - rqrq
loadPalletMaxNos() { this.batchGenerateDialog.loading = true haiAnGetMaxPalletNoByFamily({ site: this.batchGenerateDialog.site }).then(({ data }) => { if (data && data.code === 0) { this.batchGenerateDialog.palletNoList = (data.rows || []).map(item => ({ ...item, generateCount: null })) } else { this.batchGenerateDialog.palletNoList = [] this.$alert((data && data.msg) || '查询号段失败', '提示', { confirmButtonText: '确定' }) } }).catch(() => { this.batchGenerateDialog.palletNoList = [] this.$message.error('系统异常,请稍后重试') }).finally(() => { this.batchGenerateDialog.loading = false }) }, // 输入校验:限制0~1000并转整型,避免无效请求 - rqrq
validateCount(item) { if (item.generateCount === '' || item.generateCount == null) { item.generateCount = null return } const intVal = parseInt(item.generateCount, 10) if (Number.isNaN(intVal) || intVal < 0) { item.generateCount = null return } if (intVal > 1000) { item.generateCount = 1000 this.$message.warning('单次最多新增1000个') return } item.generateCount = intVal }, // 批量生成入口:逐类调用后端并汇总结果,保证失败可感知 - rqrq
doBatchGenerate() { const items = this.batchGenerateDialog.palletNoList.filter(item => item.generateCount && item.generateCount > 0) if (items.length === 0) { this.$message.warning('请至少输入一种托盘的新增数量') return } let confirmMsg = '确定生成以下托盘吗?\n\n' items.forEach(item => { confirmMsg += `${item.palletFamilyDesc} (${item.prefix}):${item.generateCount}个\n` }) this.$confirm(confirmMsg, '批量生成确认', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.executeBatchGenerate(items) }).catch(() => {}) }, // 执行批量生成:按分类串行提交,便于精确定位失败分类 - rqrq
async executeBatchGenerate(items) { this.batchGenerateDialog.saving = true let successCount = 0 let failedCount = 0 let resultMsg = ''
for (const item of items) { try { const { data } = await haiAnBatchGeneratePallet({ site: this.batchGenerateDialog.site, palletFamily: item.palletFamily, count: item.generateCount, username: this.$store.state.user.name }) if (data && data.code === 0) { successCount += 1 resultMsg += `✓ ${item.palletFamilyDesc}: 生成${data.count}个 (${data.startPalletId} ~ ${data.endPalletId})\n` } else { failedCount += 1 resultMsg += `✗ ${item.palletFamilyDesc}: ${(data && data.msg) || '生成失败'}\n` } } catch (e) { failedCount += 1 resultMsg += `✗ ${item.palletFamilyDesc}: 请求异常\n` } }
this.batchGenerateDialog.saving = false const title = failedCount === 0 ? '生成成功' : `生成结果(成功${successCount},失败${failedCount})` this.$alert(resultMsg, title, { confirmButtonText: '确定', type: failedCount === 0 ? 'success' : (failedCount === items.length ? 'error' : 'warning'), callback: () => { if (failedCount === 0) { this.batchGenerateDialog.visible = false } else { this.loadPalletMaxNos() } this.getDataList() } }) }, // 导出显式使用当前主工厂且不拆子site;切厂时丢弃旧导出,失败提示并在finally复位加载状态 - rqrq
async createExportData() { if (this.exportLoading) return [] this.syncQuerySite() if (!this.currentSite) { this.$alert('当前工厂不能为空,请先选择当前工厂', '提示', { confirmButtonText: '确定' }) return [] } const exportQuery = { ...this.queryData, site: this.currentSite, page: 1, limit: 999999 } this.exportLoading = true try { const { data } = await haiAnGetPalletList(exportQuery) if (exportQuery.site !== this.currentSite) return [] if (data && data.code === 0 && data.page && data.page.list) { return data.page.list } this.$alert((data && data.msg) || '导出失败', '提示', { confirmButtonText: '确定' }) return [] } catch (error) { this.$message.error('导出失败,请稍后重试') return [] } finally { this.exportLoading = false } }, // 导出开始钩子预留 - rqrq
startDownload() {}, // 导出结束钩子预留 - rqrq
finishDownload() {}, // 导出字段映射:严格与页面columnList同源,避免口径偏差 - rqrq
fields() { const result = {} this.columnList.forEach(item => { result[item.columnLabel] = item.columnProp }) return result }, // 表格值格式化:统一处理状态与是/否文本 - rqrq
formatColumnValue(row, column) { const value = row[column.columnProp] if (column.formatter === 'yn') { if (value === 'Y') return '是' if (value === 'N') return '否' return value || '' } if (column.formatter === 'height') { // 海安托盘高度的旧第三、第四档在历史数据迁移后统一回显为新第三档。- rqrq
const map = { HEIGHT_LT_600: '低于600', HEIGHT_600_1100: '600-1100', HEIGHT_1100_1650: '1100-1650' } return map[value] || value || '' } if (column.formatter === 'status') { const map = { AVAILABLE: '可用', OCCUPIED: '使用中', DAMAGED: '损坏', DISABLED: '禁用' } return map[value] || value || '' } return value == null ? '' : value } }}</script>
<style scoped>.batch-header { display: flex; align-items: center; padding: 10px 0; margin-bottom: 6px; border-bottom: 1px solid #ebeef5; color: #606266; font-weight: bold;}
.batch-row { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px dashed #ebeef5;}
.batch-col-name { flex: 1;}
.batch-col-count { width: 100px; text-align: center; color: #409eff; font-weight: bold;}
.batch-col-input { width: 140px; text-align: center;}
.batch-tip { margin-top: 12px; color: #909399; font-size: 12px;}</style>
|