diff --git a/src/views/wpm_bx/wprList.vue b/src/views/wpm_bx/wprList.vue
index 237b7e90..a43fd34f 100644
--- a/src/views/wpm_bx/wprList.vue
+++ b/src/views/wpm_bx/wprList.vue
@@ -12,6 +12,7 @@
批量喷码
{
that.$message.warning("请先设置打印机");
}
},
- //喷码: 通过名为'喷码模板'的标签模板向喷码机下发产品编号
+ //把 wpr 行转成模板渲染数据
+ rowToTdata(row){
+ return {
+ number: row.number,
+ name: (row.material_name||'').split('|')[0],
+ ofrom_name: this.ofromName,
+ ofrom_batch: this.ofromBatch,
+ };
+ },
+ //下发喷码: 单行入队 1 条
sendToCoder(row){
let that = this;
if (that.coderLoadingIds[row.id]) return;
- let coder_ip = localStorage.getItem('coder_ip') || '';
- let coder_port = localStorage.getItem('coder_port') || '';
- let coder_field = localStorage.getItem('coder_field') || '';
- if (!coder_ip) {
- that.$message.error('请先在右上角"喷码设置"配置喷码IP');
- return;
- }
- that.coderLoadingIds = { ...that.coderLoadingIds, [row.id]: true };
- let templateName = '喷码模板';
- let tdata = {
- number: row.number,
- name: (row.material_name||'').split('|')[0],
- ofrom_name: that.ofromName,
- ofrom_batch: that.ofromBatch,
- };
let release = () => {
let map = { ...that.coderLoadingIds };
delete map[row.id];
that.coderLoadingIds = map;
};
- that.$API.cm.labeltemplate.list.req({name: templateName, page: 0}).then((res) => {
- let list = Array.isArray(res) ? res : (res && res.results) || [];
- let template = list.find(t => t.name === templateName);
- if (!template) {
- that.$message.error(`未找到标签模板: ${templateName}`);
- release();
- return;
- }
- let body = {tdata, coder_ip};
- if (coder_port) body.coder_port = Number(coder_port);
- if (coder_field) body.coder_field = coder_field;
- that.$API.cm.labeltemplate.sendToCoder.req(template.id, body).then(() => {
- that.$message.success("喷码下发成功");
- }).finally(release);
- }).catch(release);
+ that.coderLoadingIds = { ...that.coderLoadingIds, [row.id]: true };
+ that._postCoder([that.rowToTdata(row)])
+ .then(() => that.$message.success("喷码下发成功"))
+ .finally(release);
},
handleSelectionChange(rows){
this.selectedRows = rows;
},
+ //批量喷码: 一次请求入队 N 条
batchSendToCoder(){
let that = this;
- that.selectedRows.forEach(row => {
- that.sendToCoder(row);
+ if (!that.selectedRows.length || that.batchCoderLoading) return;
+ let tdataList = that.selectedRows.map(r => that.rowToTdata(r));
+ that.batchCoderLoading = true;
+ that._postCoder(tdataList)
+ .then(() => that.$message.success(`已入队 ${tdataList.length} 条`))
+ .finally(() => { that.batchCoderLoading = false; });
+ },
+ //公共: 查模板 + 拼 body + 调接口
+ _postCoder(tdataList){
+ let that = this;
+ let coder_ip = localStorage.getItem('coder_ip') || '';
+ let coder_port = localStorage.getItem('coder_port') || '';
+ let coder_field = localStorage.getItem('coder_field') || '';
+ if (!coder_ip) {
+ that.$message.error('请先在右上角"喷码设置"配置喷码IP');
+ return Promise.reject(new Error('no coder_ip'));
+ }
+ let templateName = '喷码模板';
+ return that.$API.cm.labeltemplate.list.req({name: templateName, page: 0}).then((res) => {
+ let list = Array.isArray(res) ? res : (res && res.results) || [];
+ let template = list.find(t => t.name === templateName);
+ if (!template) {
+ that.$message.error(`未找到标签模板: ${templateName}`);
+ return Promise.reject(new Error('no template'));
+ }
+ let body = {tdata_list: tdataList, coder_ip};
+ if (coder_port) body.coder_port = Number(coder_port);
+ if (coder_field) body.coder_field = coder_field;
+ return that.$API.cm.labeltemplate.sendToCoder.req(template.id, body);
});
},
//本地更新数据