<script>
|
export default {
|
components: {},
|
props: {},
|
data() {
|
return {
|
// 当前正在扫描的数据
|
currentRow: null,
|
// 已经找到的数据
|
existRows: []
|
};
|
},
|
methods: {
|
// 播放正确声音
|
play() {
|
this.$refs.sound_correct.currentTime = 0;
|
this.$refs.sound_correct.play();
|
},
|
// 播放失败声音
|
playError() {
|
this.$refs.sound_error.currentTime = 0;
|
this.$refs.sound_error.play();
|
},
|
// 获得焦点
|
focus(refName) {
|
if (this.$refs[refName]) {
|
this.$refs[refName].focus();
|
this.$refs[refName].select();
|
} else {
|
this.$message.error("焦点不存在:" + refName);
|
}
|
},
|
/**
|
* 判断扫描包装条码
|
* @param {dataRows} 筛选数据
|
* @param {successCallback} 扫描成功后,回调函数
|
* @param {noExistCallback} 扫描不存在后,回调函数
|
*/
|
checkPackingProductModel(dataRows, successCallback, noExistCallback) {
|
if (!dataRows || !Array.isArray(dataRows)) {
|
if (typeof dataRows === "function") {
|
successCallback = dataRows;
|
}
|
dataRows = this.tableData;
|
}
|
if (!this.formData.extendField06) return;
|
|
var code = this.formData.extendField06.trim();
|
if (!code) return;
|
if (this.currentRow) {
|
const exists = this.checkProductModelExist(code, this.currentRow);
|
if (!exists || !this.currentRow.unFinishedQuantity) {
|
this.currentRow = null;
|
} else {
|
this.currentRow.sortIndex = 1;
|
}
|
}
|
|
if (!this.currentRow) {
|
// 判断是否存在一码多品
|
this.existRows = dataRows.filter(item => {
|
const exist = this.checkProductModelExist(code, item);
|
// UnFinishedQuantity不存在或者大于0
|
return exist && (item.unFinishedQuantity === undefined || item.unFinishedQuantity > 0);
|
});
|
this.focus("extendField06");
|
|
if (this.existRows.length > 1) {
|
this.$message.error(`【${code}】存在一码多品,需要手动选择需要扫描的明细,双击一下明细即可选择哦。`);
|
this.existRows.forEach(item => {
|
item.sortIndex = 1;
|
});
|
// 置顶排序
|
dataRows.sort(function(a, b) {
|
return b.sortIndex - a.sortIndex;
|
});
|
|
dataRows.forEach(element => {
|
element.sortIndex = 0;
|
});
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
if (!this.existRows.length) {
|
// 执行回调函数
|
if (typeof noExistCallback === "function") {
|
noExistCallback(code);
|
} else {
|
this.$message.error(`【${code}】没有可扫描的数据`);
|
this.playError();
|
}
|
return;
|
}
|
|
// 设置当前行
|
this.currentRow = this.existRows[0];
|
this.currentRow.sortIndex = 1;
|
}
|
this.currentRow.scanWeight = Math.Round(this.currentRow.weight * this.currentRow.finishedQuantity, 2);
|
this.setRowQty(dataRows);
|
|
// 执行回调函数
|
if (typeof successCallback === "function") {
|
successCallback();
|
}
|
},
|
// 扫描数量处理
|
setRowQty(dataRows) {
|
if (!dataRows || !Array.isArray(dataRows)) {
|
dataRows = this.tableData;
|
}
|
var code = this.formData.extendField06.trim();
|
|
// 获得扫描数量
|
let scanQty = 1; // 默认扫描数量为1
|
if (this.currentRow.middleBarcode === code) {
|
// 中包装条码
|
scanQty = this.currentRow.middleUnitConvert;
|
if (!scanQty || scanQty < 0) {
|
this.$message.error(`条码【${this.currentRow.middleBarcode}】没有设置中单位换算关系数据!`);
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
} else if (this.currentRow.bigBarcode === code) {
|
// 中包装条码
|
scanQty = this.currentRow.unitConvert;
|
if (!scanQty || scanQty < 0) {
|
this.$message.error(`条码【${this.currentRow.bigBarcode}】没有设置大单位换算关系数据!`);
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
}
|
|
// 判断是否有足够扫描数量
|
if (this.currentRow.unFinishedQuantity !== undefined && this.currentRow.unFinishedQuantity < scanQty) {
|
this.$message.error(`物料扫描数量不足!`);
|
this.focus("scanQty");
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
|
// 设置已扫描的数量
|
this.currentRow.finishedQuantity += scanQty;
|
if (this.currentRow.unFinishedQuantity !== undefined) {
|
this.currentRow.unFinishedQuantity -= scanQty;
|
this.currentRow.scanWeight = Math.Round(this.currentRow.finishedQuantity * this.currentRow.weight, 4);
|
} else {
|
this.currentRow.scanWeight = Math.Round(this.currentRow.finishedQuantity * this.currentRow.weight, 4);
|
}
|
this.formData.scanQty = this.currentRow.finishedQuantity;
|
this.play();
|
|
// 置顶排序
|
dataRows.sort(function(a, b) {
|
return b.sortIndex - a.sortIndex;
|
});
|
|
dataRows.forEach(element => {
|
element.sortIndex = 0;
|
});
|
this.focus("extendField06");
|
},
|
/**
|
* 获得扫描数量,根据大中小进率
|
*/
|
getScanQty() {
|
var code = this.formData.extendField06.trim();
|
// 获得扫描数量
|
let scanQty = 1; // 默认扫描数量为1
|
if (this.currentRow.middleBarcode === code) {
|
// 中包装条码
|
scanQty = this.currentRow.middleUnitConvert;
|
if (!scanQty || scanQty < 0) {
|
this.$message.error(`条码【${this.currentRow.middleBarcode}】没有设置中单位换算关系数据!`);
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
} else if (this.currentRow.bigBarcode === code) {
|
// 中包装条码
|
scanQty = this.currentRow.unitConvert;
|
if (!scanQty || scanQty < 0) {
|
this.$message.error(`条码【${this.currentRow.bigBarcode}】没有设置大单位换算关系数据!`);
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
}
|
|
return scanQty;
|
},
|
// 判断所有条码是否存在
|
checkProductModelExist(extendField06, rowData) {
|
var isExists = false;
|
if (!extendField06 || !rowData) {
|
return false;
|
}
|
|
isExists =
|
extendField06 === rowData.extendField06 ||
|
extendField06 === rowData.relationCode ||
|
extendField06 === rowData.relationCode2 ||
|
extendField06 === rowData.relationCode3 ||
|
extendField06 === rowData.relationCode4 ||
|
extendField06 === rowData.relationCode5 ||
|
extendField06 === rowData.middleBarcode ||
|
extendField06 === rowData.bigBarcode;
|
|
return isExists;
|
},
|
// 手动设置数量
|
setScanQty(callback) {
|
debugger;
|
this.currentRow = null;
|
|
if (!this.existRows.length) {
|
this.$message.error("请扫描物料条码!");
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return false;
|
}
|
if (this.existRows.length > 1) {
|
this.$message.error(`【${this.existRows[0].extendField06}】存在一码多品,需要手动选择需要扫描的明细,双击一下明细即可选择哦。`);
|
this.$refs.sound_error.currentTime = 0;
|
this.playError();
|
return;
|
}
|
|
// 设置当前行
|
this.currentRow = this.existRows[0];
|
const scanQty = this.formData.scanQty;
|
if (this.currentRow.unFinishedQuantity !== undefined) {
|
// 判断是否有足够扫描数量
|
const totalQty = this.currentRow.unFinishedQuantity + this.currentRow.finishedQuantity;
|
if (totalQty < scanQty) {
|
this.$message.error("物料扫描数量不足!");
|
this.playError();
|
this.focus("scanQty");
|
return false;
|
}
|
const total = totalQty - scanQty;
|
// 设置未扫描的数量
|
this.currentRow.unFinishedQuantity = Math.Round(total, 4);
|
}
|
// 设置已扫描的数量
|
this.$set(this.currentRow, "finishedQuantity", scanQty);
|
this.currentRow.scanWeight = this.currentRow.finishedQuantity * this.currentRow.weight;
|
|
this.play();
|
if (typeof callback === "function") {
|
const re = callback();
|
if (re === false) {
|
this.play();
|
return;
|
}
|
}
|
this.play();
|
|
return true;
|
},
|
// 行样式
|
rowClass({ row, rowIndex }) {
|
if (this.existRows.find(f => f === row)) {
|
if (this.existRows.length === 1) {
|
return "row-active";
|
} else {
|
return "multi-row-active";
|
}
|
}
|
},
|
// 双击事件
|
setCurrent(row, event, column) {
|
if (this.checkProductModelExist(this.formData.extendField06, row)) {
|
this.currentRow = row;
|
this.existRows = [row];
|
this.tableData.forEach(element => {
|
element.sortIndex = 0;
|
});
|
this.currentRow.sortIndex = 1;
|
this.tableData = this.tableData.sort(function(a, b) {
|
return b.sortIndex - a.sortIndex;
|
});
|
this.tableData.forEach(element => {
|
element.sortIndex = 0;
|
});
|
this.focus("extendField06");
|
}
|
},
|
// 是否已完成
|
isFinished() {
|
var isAllFinished = this.tableData.every(rowData => {
|
return rowData.unFinishedQuantity <= 0;
|
});
|
|
return isAllFinished;
|
},
|
// 行数据改变
|
rowChangeQty(prop, row, qtyFeild) {
|
if (!qtyFeild) {
|
qtyFeild = "quantityOrder";
|
}
|
if (prop === "finishedQuantity") {
|
row.unFinishedQuantity = row[qtyFeild] - row.finishedQuantity;
|
} else if (prop === "unFinishedQuantity") {
|
row.finishedQuantity = row[qtyFeild] - row.unFinishedQuantity;
|
}
|
row.scanWeight = Math.Round(row.weight * row.finishedQuantity, 2);
|
}
|
}
|
};
|
</script>
|