Browse Source

自动计算标签数,批量创建HU

master
han\hanst 3 months ago
parent
commit
029df4e18c
  1. 3
      src/api/warehouse/ifsInventoryInit.js
  2. 12
      src/views/modules/labelSetting/com_add_update_user_label_printer.vue
  3. 447
      src/views/modules/warehouse/ifsInventoryInit.vue

3
src/api/warehouse/ifsInventoryInit.js

@ -6,6 +6,9 @@ export const getInventoryStockList = data => createAPI(`ifsInventoryInit/getInve
// 创建HandlingUnit // 创建HandlingUnit
export const createHandlingUnits = data => createAPI(`ifsInventoryInit/createHandlingUnits`, 'POST', data) export const createHandlingUnits = data => createAPI(`ifsInventoryInit/createHandlingUnits`, 'POST', data)
// 批量创建HandlingUnit
export const batchCreateHandlingUnits = data => createAPI(`ifsInventoryInit/batchCreateHandlingUnits`, 'POST', data)
// 打印标签 // 打印标签
export const printLabel = data => createAPI('/label/setting/printLabel','post',data) export const printLabel = data => createAPI('/label/setting/printLabel','post',data)

12
src/views/modules/labelSetting/com_add_update_user_label_printer.vue

@ -31,7 +31,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row>
<!-- <el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item class="customer-item" :label=labels.printerName> <el-form-item class="customer-item" :label=labels.printerName>
<el-select v-model="pageData.printerName" style="width: 285px;" > <el-select v-model="pageData.printerName" style="width: 285px;" >
@ -41,7 +41,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row>
</el-row>-->
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button type="primary" @click="saveUserLabelPrinterMethod()">{{ buttons.saveButton }}</el-button> <el-button type="primary" @click="saveUserLabelPrinterMethod()">{{ buttons.saveButton }}</el-button>
@ -162,7 +162,7 @@ export default {
// //
//this.titleCon = this.labels.titleCon; //this.titleCon = this.labels.titleCon;
// //
this.getPrintName();
//this.getPrintName();
//admin //admin
if(this.userId.toUpperCase() == "ADMIN"){ if(this.userId.toUpperCase() == "ADMIN"){
// //
@ -242,7 +242,7 @@ export default {
// //
let labelNo = this.pageData.labelNo.trim(); let labelNo = this.pageData.labelNo.trim();
let userId = this.pageData.userId.trim(); let userId = this.pageData.userId.trim();
let printerName = this.pageData.printerName.trim();
let ipAddress = this.pageData.ipAddress.trim();
if(labelNo == null || labelNo === ''){ if(labelNo == null || labelNo === ''){
this.$message.success("标签编号不能为空!"); this.$message.success("标签编号不能为空!");
return false; return false;
@ -251,8 +251,8 @@ export default {
this.$message.success("用户ID不能为空!"); this.$message.success("用户ID不能为空!");
return false; return false;
} }
if(printerName == null || printerName === ''){
this.$message.success("打印机不能为空!");
if(ipAddress == null || ipAddress === ''){
this.$message.success("打印机ip不能为空!");
return false; return false;
} }
// //

447
src/views/modules/warehouse/ifsInventoryInit.vue

@ -19,6 +19,7 @@
<el-form-item> <el-form-item>
<el-button @click="getDataList()">查询</el-button> <el-button @click="getDataList()">查询</el-button>
<el-button @click="resetForm()">重置</el-button> <el-button @click="resetForm()">重置</el-button>
<el-button type="primary" @click="batchCreateHu()">批量创建HU</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -271,33 +272,63 @@
</el-row> </el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="8">
<el-form-item label="高度(mm)" prop="height" class="form-item-vertical">
<el-input v-model="createHuForm.height"></el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="包装数" prop="packageCount" class="form-item-vertical">
<el-input
v-model="createHuForm.packageCount"
:min="1"
placeholder="请输入包装数">
</el-input>
<el-col :span="24">
<el-form-item label="" prop="perPackageQty" class="form-item-vertical">
<el-checkbox
v-model="createHuForm.autoCalculate"
@change="onAutoCalculateChange"
style="margin-top: 5px;">
自动计算包装数和余数
</el-checkbox>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="8">
<el-col :span="12">
<el-form-item label="单包装数量" prop="perPackageQty" class="form-item-vertical"> <el-form-item label="单包装数量" prop="perPackageQty" class="form-item-vertical">
<el-input <el-input
v-model="createHuForm.perPackageQty" v-model="createHuForm.perPackageQty"
:min="0.01" :min="0.01"
:precision="2" :precision="2"
placeholder="请输入单包装数量">
placeholder="请输入单包装数量"
@input="onPerPackageQtyChange">
</el-input> </el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12">
<el-form-item label="高度(mm)" prop="height" class="form-item-vertical">
<el-input v-model="createHuForm.height"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="包装数" prop="packageCount" class="form-item-vertical">
<el-input
v-model="createHuForm.packageCount"
type="number"
:min="1"
:placeholder="createHuForm.autoCalculate ? '自动计算' : '手动输入'"
:readonly="createHuForm.autoCalculate"
@input="onPackageCountChange">
</el-input>
<span style="font-size: 12px; color: #999;">
{{ createHuForm.autoCalculate ? '自动计算' : '可手动输入' }}
</span>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="余数HU" prop="lastPackageQty" class="form-item-vertical">
<el-input
v-model="createHuForm.lastPackageQty"
:placeholder="createHuForm.autoCalculate ? '自动计算' : '手动输入'"
:readonly="createHuForm.autoCalculate"
@input="onLastPackageQtyChange">
</el-input>
<span style="font-size: 12px; color: #999;">
{{ createHuForm.autoCalculate ? '自动计算' : '可手动输入' }}
</span>
</el-form-item>
</el-col>
</el-row> </el-row>
</el-form> </el-form>
<div slot="footer" class="dialog-footer">
<div slot="footer" class="dialog-footer" style="margin-top: 20px">
<el-button @click="createHuVisible = false">取消</el-button> <el-button @click="createHuVisible = false">取消</el-button>
<el-button type="primary" @click="createHuSubmit()" :loading="createHuLoading">创建并打印</el-button> <el-button type="primary" @click="createHuSubmit()" :loading="createHuLoading">创建并打印</el-button>
</div> </div>
@ -306,7 +337,7 @@
</template> </template>
<script> <script>
import { getInventoryStockList, createHandlingUnits, printLabel, updatePrintQty } from '@/api/warehouse/ifsInventoryInit'
import { getInventoryStockList, createHandlingUnits, batchCreateHandlingUnits, printLabel, updatePrintQty } from '@/api/warehouse/ifsInventoryInit'
export default { export default {
data () { data () {
@ -351,9 +382,13 @@ export default {
wdr: '', wdr: '',
locationId: '', locationId: '',
umid: '', umid: '',
perPackageQty: 1,
packageCount: 1,
qtyOnHand: 0,
unPrintQty: 0,
perPackageQty: '',
packageCount: 0,
lastPackageQty: 0,
height: '', height: '',
autoCalculate: true //
}, },
createHuRules: { createHuRules: {
perPackageQty: [ perPackageQty: [
@ -490,42 +525,239 @@ export default {
unPrintQty: row.unPrintQty, unPrintQty: row.unPrintQty,
umid: row.umid, umid: row.umid,
perPackageQty: '', perPackageQty: '',
packageCount: 1
packageCount: 0,
lastPackageQty: 0,
height: '',
autoCalculate: true //
} }
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['createHuForm'].clearValidate() this.$refs['createHuForm'].clearValidate()
}) })
}, },
/**
* 单包装数量变化时的处理
* 如果开启自动计算基于未打印数量自动计算包装数和余数HU
* 如果手动输入不做自动计算
*
* 重要自动计算时使用未打印数量库存数量 - 已打印数量
* 例如库存44已打印0未打印44单包装10 -> 包装数4余数HU数量4
* 例如库存44已打印20未打印24单包装10 -> 包装数2余数HU数量4
*/
onPerPackageQtyChange() {
//
if (!this.createHuForm.autoCalculate) {
return
}
const perPackageQty = parseFloat(this.createHuForm.perPackageQty)
const unPrintQty = parseFloat(this.createHuForm.unPrintQty) // 使
//
if (!perPackageQty || perPackageQty <= 0 || isNaN(perPackageQty)) {
this.createHuForm.packageCount = 0
this.createHuForm.lastPackageQty = 0
return
}
// 0
if (!unPrintQty || unPrintQty <= 0 || isNaN(unPrintQty)) {
this.createHuForm.packageCount = 0
this.createHuForm.lastPackageQty = 0
this.$message.warning('未打印数量为0,无法创建HU')
return
}
// 1HU
if (perPackageQty >= unPrintQty) {
this.createHuForm.packageCount = 0
this.createHuForm.lastPackageQty = unPrintQty
return
}
// HU
const packageCount = Math.floor(unPrintQty / perPackageQty)
// HU
const lastPackageQty = unPrintQty - (perPackageQty * packageCount)
this.createHuForm.packageCount = packageCount
this.createHuForm.lastPackageQty = parseFloat(lastPackageQty.toFixed(2)) // 2
},
/**
* 包装数手动修改时的处理
* 只在手动输入模式下生效
* 根据用户输入的包装数重新计算余数HU数量
*
* 场景1库存44单包装10包装数5 -> 余数HU = 44 - 10×5 = -6提示包装数过大
* 场景2库存44单包装10包装数2 -> 余数HU = 44 - 10×2 = 24
* 场景3库存44单包装10包装数4 -> 余数HU = 44 - 10×4 = 4
*/
onPackageCountChange() {
//
if (this.createHuForm.autoCalculate) {
return
}
const perPackageQty = parseFloat(this.createHuForm.perPackageQty)
const packageCount = parseInt(this.createHuForm.packageCount)
const qtyOnHand = parseFloat(this.createHuForm.qtyOnHand)
//
if (!perPackageQty || perPackageQty <= 0 || isNaN(perPackageQty)) {
return
}
if (packageCount === null || packageCount === undefined || isNaN(packageCount)) {
return
}
if (!qtyOnHand || qtyOnHand <= 0 || isNaN(qtyOnHand)) {
return
}
// HU
const totalFullPackagesQty = perPackageQty * packageCount
//
const remainderQty = qtyOnHand - totalFullPackagesQty
//
if (remainderQty < 0) {
this.$message.warning(`包装数过大!${packageCount}个完整HU的总数量(${totalFullPackagesQty})超过库存数量(${qtyOnHand})`)
return
}
// HU0HU
this.createHuForm.lastPackageQty = parseFloat(remainderQty.toFixed(2)) // 2
},
/**
* 余数HU手动输入时的处理
* 只在手动输入模式下生效用于验证输入的合理性
*/
onLastPackageQtyChange() {
//
if (this.createHuForm.autoCalculate) {
return
}
const perPackageQty = parseFloat(this.createHuForm.perPackageQty)
const packageCount = parseInt(this.createHuForm.packageCount)
const lastPackageQty = parseFloat(this.createHuForm.lastPackageQty)
const qtyOnHand = parseFloat(this.createHuForm.qtyOnHand)
//
if (!perPackageQty || !qtyOnHand || packageCount === null || packageCount === undefined) {
return
}
//
const totalQty = (perPackageQty * packageCount) + lastPackageQty
if (totalQty > qtyOnHand) {
this.$message.warning(`总数量(${totalQty})超过库存数量(${qtyOnHand})!`)
}
},
/**
* 自动计算勾选框变化时的处理
* 切换自动计算/手动输入模式
*/
onAutoCalculateChange(checked) {
if (checked) {
//
this.$message.info('已切换到自动计算模式')
this.onPerPackageQtyChange()
} else {
//
this.$message.info('已切换到手动输入模式,您可以自由输入包装数和余数HU')
}
},
// HU // HU
createHuSubmit () { createHuSubmit () {
this.$refs['createHuForm'].validate((valid) => { this.$refs['createHuForm'].validate((valid) => {
if (valid) { if (valid) {
this.createHuLoading = true
createHandlingUnits(this.createHuForm).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: '创建HandlingUnit成功',
type: 'success',
duration: 1500
})
let printLabelType;
if (this.createHuForm.partNo && this.createHuForm.partNo.startsWith("80")) {
printLabelType = '库存成品标签';
} else {
printLabelType = 'BIL标签';
}
//
if (!this.createHuForm.packageCount || this.createHuForm.packageCount <= 0) {
this.$message.error('请输入单包装数量以自动计算包装数')
return
}
//
this.printHandlingUnits(data.unitIds,printLabelType)
//
const perQty = parseFloat(this.createHuForm.perPackageQty)
const lastQty = parseFloat(this.createHuForm.lastPackageQty)
const pkgCount = parseInt(this.createHuForm.packageCount)
const qtyOnHand = parseFloat(this.createHuForm.qtyOnHand)
const unPrintQty = parseFloat(this.createHuForm.unPrintQty)
this.createHuVisible = false
this.getDataList()
} else {
this.$message.error(data.msg || '创建HandlingUnit失败')
let confirmMsg = `即将创建 HU\n`
confirmMsg += `库存数量: ${qtyOnHand}\n`
confirmMsg += `未打印数量: ${unPrintQty}\n\n`
if (lastQty > 0) {
// HU
const totalRegular = perQty * pkgCount
const totalQty = totalRegular + lastQty
const actualHuCount = pkgCount + 1
confirmMsg += `创建 ${pkgCount} 个完整HU,每个数量: ${perQty}(小计: ${totalRegular}\n`
confirmMsg += `创建 1 个余数HU,数量: ${lastQty}\n\n`
confirmMsg += `总计: ${actualHuCount} 个HU,总数量: ${totalQty}\n`
if (totalQty < unPrintQty) {
const remaining = unPrintQty - totalQty
confirmMsg += `\n注意: 剩余未打印数量 ${remaining} 未创建HU`
}
} else {
// HU0
const total = perQty * pkgCount
confirmMsg += `创建 ${pkgCount} 个HU,每个数量: ${perQty}\n`
confirmMsg += `总计: ${pkgCount} 个HU,总数量: ${total}\n`
if (total < unPrintQty) {
const remaining = unPrintQty - total
confirmMsg += `\n注意: 剩余未打印数量 ${remaining} 未创建HU`
} }
this.createHuLoading = false
}
this.$confirm(confirmMsg, '确认创建', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
this.createHuLoading = true
createHandlingUnits(this.createHuForm).then(({ data }) => {
if (data && data.code === 0) {
const lastQty = parseFloat(this.createHuForm.lastPackageQty)
const actualHuCount = lastQty > 0 ? this.createHuForm.packageCount + 1 : this.createHuForm.packageCount
this.$message({
message: `创建HandlingUnit成功!共创建 ${actualHuCount} 个HU`,
type: 'success',
duration: 1500
})
let printLabelType;
if (this.createHuForm.partNo && this.createHuForm.partNo.startsWith("80")) {
printLabelType = '库存成品标签';
} else {
printLabelType = 'BIL标签';
}
//
this.printHandlingUnits(data.unitIds, printLabelType)
this.createHuVisible = false
this.getDataList()
} else {
this.$message.error(data.msg || '创建HandlingUnit失败')
}
this.createHuLoading = false
}).catch(() => {
this.createHuLoading = false
})
}).catch(() => { }).catch(() => {
this.createHuLoading = false
//
}) })
} }
}) })
@ -603,6 +835,139 @@ export default {
const month = String(d.getMonth() + 1).padStart(2, '0') const month = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0') const day = String(d.getDate()).padStart(2, '0')
return `${year}-${month}-${day}` return `${year}-${month}-${day}`
},
/**
* 批量创建HU
* 业务规则
* 1. 必须选中至少一条数据
* 2. 每行数据创建一条HU
* 3. 批次号使用每行自己的批次号
* 4. HU数量使用库存数量qtyOnHand
*/
batchCreateHu() {
//
if (!this.dataListSelections || this.dataListSelections.length === 0) {
this.$message.error('请至少选择一条数据进行批量创建HU!')
return
}
//
this.$confirm(`确定为选中的 ${this.dataListSelections.length} 条数据批量创建HU吗?`, '批量创建确认', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.executeBatchCreateHu()
}).catch(() => {
this.$message.info('已取消批量创建HU操作')
})
},
/**
* 执行批量创建HU
*/
executeBatchCreateHu() {
const loading = this.$loading({
lock: true,
text: '正在批量创建HU,请稍候...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
//
const items = this.dataListSelections.map(row => ({
site: row.site,
warehouseId: row.warehouseId,
partNo: row.partNo,
partDesc: row.description || '',
batchNo: row.batchNo, // 使
wdr: row.wdr,
locationId: row.locationId,
umid: row.umid,
qtyOnHand: row.qtyOnHand // HU使
}))
const requestData = {
items: items
}
batchCreateHandlingUnits(requestData).then(({ data }) => {
loading.close()
if (data && data.code === 0) {
const unitIds = data.unitIds || []
this.$message.success(`批量创建HU成功!共创建 ${unitIds.length} 个HU`)
//
if (unitIds.length > 0) {
this.$confirm(`是否打印 ${unitIds.length} 个HU标签?`, '打印确认', {
confirmButtonText: '打印',
cancelButtonText: '不打印',
type: 'info'
}).then(() => {
this.batchPrintLabels(unitIds)
}).catch(() => {
//
this.getDataList()
})
} else {
this.getDataList()
}
} else {
this.$message.error(data.msg || '批量创建HU失败')
}
}).catch(error => {
loading.close()
this.$message.error('批量创建HU异常: ' + (error.message || '未知错误'))
})
},
/**
* 批量打印标签
*/
async batchPrintLabels(unitIds) {
const loading = this.$loading({
lock: true,
text: '正在打印标签,请稍候...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
try {
let successCount = 0
let failCount = 0
//
for (let i = 0; i < unitIds.length; i++) {
const unitId = unitIds[i]
loading.text = `正在打印标签 (${i + 1}/${unitIds.length})...`
try {
// 使
const printLabelType = 'BIL标签'
await this.printViaServer(unitId, printLabelType)
successCount++
} catch (error) {
failCount++
}
}
loading.close()
if (successCount > 0) {
this.$message.success(`成功打印 ${successCount} 个标签` + (failCount > 0 ? `,失败 ${failCount}` : ''))
} else {
this.$message.error('所有标签打印失败')
}
//
this.getDataList()
} catch (error) {
loading.close()
this.$message.error('打印异常: ' + error.message)
this.getDataList()
}
} }
} }
} }

Loading…
Cancel
Save