define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jQuery.print', 'jquery.qrcode.min'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'feeding/index' + location.search, add_url: 'feeding/add', edit_url: 'feeding/edit', del_url: 'feeding/del', multi_url: 'feeding/multi', import_url: 'feeding/import', table: 'feeding', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ { checkbox: true }, // { field: 'id', title: __('Id') }, { field: 'bach', title: __('Bach'), operate: 'LIKE' }, { field: 'material', title: __('Material'), operate: 'LIKE' }, { field: 'no', title: __('No'), operate: 'LIKE' }, { field: 'nweight', title: __('Nweight'), operate: 'LIKE' }, { field: 'weight', title: __('Weight'), operate: 'LIKE' }, { field: 'gy_num', title: __('Gy_num') }, { field: 'date', title: __('Date'), operate: 'LIKE' }, { field: 'operator', title: __('Operator'), operate: 'LIKE' }, // {field: 'tid', title: __('Tid')}, { field: 'inspector', title: __('Inspector'), operate: 'LIKE' }, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate } ] ], showToggle:false, }); table.on('post-body.bs.table', function () { $(".btn-add").data("area", ["100%", "100%"]); }); // 进入页面全屏 // if (document.documentElement) { // document.documentElement.webkitRequestFullScreen(); // document.body.onkeyup = function (e) { // e = e || window.event; // console.log(e.keyCode); // if (e.keyCode == 27) {//Esc全屏或退出全屏 // document.documentElement.webkitRequestFullScreen(); // } // if (e.keyCode == 116) {//F5 // document.documentElement.webkitRequestFullScreen(); // } // if (e.keyCode == 82 && e.ctrlKey) {//Ctrl+R // document.documentElement.webkitRequestFullScreen(); // } // if (e.keyCode === 13) { // document.querySelector('.btn-refresh').click(); // document.querySelector('.btn-add').click(); // } // // }; // } // $(document).ready(function() { // // 尝试进入全屏模式 // // function enterFullScreen() { // // if (document.documentElement.requestFullscreen) { // // document.documentElement.requestFullscreen(); // // } else if (document.documentElement.webkitRequestFullScreen) { // // document.documentElement.webkitRequestFullScreen(); // // } // // } // // // 页面加载时尝试进入全屏 // enterFullScreen(); // // // 监听键盘事件 // document.body.addEventListener('keyup', function(e) { // e = e || window.event; // console.log(e.keyCode); // if (e.keyCode === 27) { // Esc键退出全屏后,不需要再次请求全屏 // // 一般情况下,浏览器会自动处理 Esc 键退出全屏 // } // if (e.keyCode === 116) { // F5刷新页面,通常不需要特别处理 // // 浏览器默认行为会刷新页面 // } // if (e.keyCode === 82 && e.ctrlKey) { // Ctrl+R,通常不需要特别处理 // // 浏览器默认行为会刷新页面 // } // if (e.keyCode === 13) { // 回车键 // document.querySelector('.btn-refresh').click(); // 模拟点击刷新按钮 // document.querySelector('.btn-add').click(); // 模拟点击添加按钮 // } // }); // }); $(".form-control").focus(); // 为表格绑定事件 Table.api.bindevent(table); }, //添加 add: function () { $(document).ready(function(){ // 设置边框颜色并清除其他输入框的边框颜色 function setBorderColor(input) { $('input').not(input).css('border-color', ''); // 清除其他输入框的边框颜色 input.css('border-color', 'red'); // 设置当前点击输入框的边框颜色 } function setBorderColors(input) { $('input').not(input).css('border-color', ''); input.css('border-color', 'red'); $('#c-inspector').css('border-color', ''); $('#c-operator').css('border-color', ''); } $('#c-bach').focus(function(){ setBorderColors($(this)); }); $('#wuliao').focus(function(){ setBorderColors($(this)); }); $('#dzcshuju').focus(function(){ setBorderColors($(this)); }); $('#c-operator').focus(function(){ setBorderColor($(this)); $('#c-inspector').css('border-color', ''); }); $('#c-inspector').focus(function(){ setBorderColor($(this)); $('#c-operator').css('border-color', ''); }); }); const BAUD_RATE = 9600; const READ_TIMEOUT = 50; let serialPort; let reader; let readFlag = true; let conectFlag = false; let serialData = []; let asciidecoder = new TextDecoder(); let serialTimer = null; let input = null; let oldVal = 0; // 连接串口设备 const connectSerial = async () => { try { const ports = await navigator.serial.getPorts(); if (ports.length > 0) { // 关闭已连接的串口 if (serialPort) { await serialPort.close(); serialPort = null; } // 选择第一个串口进行连接 serialPort = ports[0]; await serialPort.open({ baudRate: BAUD_RATE }); if (serialPort.readable) { console.log("已连接设备"); conectFlag = true; readData(); // 开始读取数据 } else { console.log("未能连接到设备"); } } else { var duankou_msg = new SpeechSynthesisUtterance("请选择 U S B 串口并点击连接"); window.speechSynthesis.speak(duankou_msg); const port = await navigator.serial.requestPort(); serialPort = port; await serialPort.open({ baudRate: BAUD_RATE }); if (serialPort.readable) { var duankou_msg = new SpeechSynthesisUtterance("已连接设备"); window.speechSynthesis.speak(duankou_msg); conectFlag = true; readData(); // 开始读取数据 } } } catch (error) { // 处理连接错误 } }; // 读取串口数据 const readData = async () => { try { while (readFlag && conectFlag && serialPort.readable) { reader = serialPort.readable.getReader(); while (true) { const { value, done } = await reader.read(); if (done) break; dataReceived(value); } } } catch (error) { // 处理读取数据错误 } finally { reader.releaseLock(); } }; // 处理接收到的数据 const dataReceived = (data) => { serialData.push(...data); clearTimeout(serialTimer); serialTimer = setTimeout(() => { const dataNum = parseFloat(asciidecoder.decode(Uint8Array.from(serialData))); console.log(dataNum); if (!isNaN(parseFloat(dataNum))) { console.log('蓝牙电子秤数据是'+ dataNum); if (dataNum === 0) { // 如果数据是0,设置显示为空 $('#dzcshuju').text(''); } else { // 数据不是0,正常显示数据 $('#dzcshuju').text(dataNum); } } else { const dataNums = asciidecoder.decode(Uint8Array.from(serialData)); const dataNum = parseFloat(dataNums.split('').reverse().join('').split('=')[0]); console.log(dataNum); if (dataNum === 0) { // 如果数据是0,设置显示为空 $('#dzcshuju').text(''); } else { // 数据不是0,正常显示数据 $('#dzcshuju').text(dataNum); } // 字符串不是数字的处理逻辑 // console.log("串口接触异常,未获取到数据"); } serialData = []; }, READ_TIMEOUT); }; // const BAUD_RATE = 9600; // const READ_TIMEOUT = 20; // let serialPort; // let reader; // let readFlag = true; // let conectFlag = false; // let serialData = []; // let asciidecoder = new TextDecoder(); // let serialTimer = null; // let input = null; // let oldVal = 0; // // // 连接串口设备 // const connectSerial = async () => { // try { // const ports = await navigator.serial.getPorts(); // console.log(ports); // // if (ports.length > 0) { // // 关闭已连接的串口 // if (serialPort) { // await serialPort.close(); // serialPort = null; // } // // 选择第一个串口进行连接 // serialPort = ports[0]; // await serialPort.open({ baudRate: BAUD_RATE }); // if (serialPort.readable) { // console.log("已连接设备"); // conectFlag = true; // readData(); // 开始读取数据 // } else { // console.log("未能连接到设备"); // } // } else { // var duankou_msg = new SpeechSynthesisUtterance("请选择 U S B 串口并点击连接"); // window.speechSynthesis.speak(duankou_msg); // const port = await navigator.serial.requestPort(); // serialPort = port; // await serialPort.open({ baudRate: BAUD_RATE }); // if (serialPort.readable) { // var duankou_msg = new SpeechSynthesisUtterance("已连接设备"); // window.speechSynthesis.speak(duankou_msg); // conectFlag = true; // readData(); // 开始读取数据 // } // } // } catch (error) { // // 处理连接错误 // } // }; // // // 读取串口数据 // const readData = async () => { // try { // while (readFlag && conectFlag && serialPort.readable) { // reader = serialPort.readable.getReader(); // while (true) { // const { value, done } = await reader.read(); // if (done) break; // dataReceived(value); // } // } // } catch (error) { // // 处理读取数据错误 // } finally { // reader.releaseLock(); // } // }; // // // 处理接收到的数据 // const dataReceived = (data) => { // serialData.push(...data); // clearTimeout(serialTimer); // serialTimer = setTimeout(() => { // const dataNums = asciidecoder.decode(Uint8Array.from(serialData)); // const dataNum = parseFloat(dataNums.split('').reverse().join('').split('=')[0]); // console.log('电子秤获取的数据是'+ dataNum); // if (!isNaN(parseFloat(dataNum))) { // $('#dzcshuju').text(dataNum); // } else { // // 字符串不是数字的处理逻辑 // console.log("串口接触异常,未获取到数据"); // } // serialData = []; // }, READ_TIMEOUT); // }; //进入投料添加页面 光标自动跳到批次号输入框 $('#c-bach').focus(); var num = 0; $('#c-bach').keydown((e) => { let key = e.which; if (key == 13) { $('#dzcshuju').text(''); $.ajax({ method: "get", url: "feeding/cheng", success(data) { if(data.admin.username === '333' || data.admin.username === 'admin'){ // if(data.admin.username === '333'){ console.log('登录了带有电子秤的账号'); connectSerial(); }else{ console.log('登录了没有电子秤的账号'); } } }); $("#wuliao").focus(); if (num === 0) { var bach = $("#c-bach").val();//批次号 if (bach == '') { layer.confirm('批次号不能为空', { title: '操作提示',btn: [],closeBtn: 0,time: 2000}); return false; } //批次号语音播报 var bach_msg = new SpeechSynthesisUtterance("当前批次号是" + bach); window.speechSynthesis.speak(bach_msg); $.ajax({ method: "POST", data: { bach: bach }, url: "feeding/get_task", success(res) { $("#table").append(""); //批次号重复/做下拉选择 if (res.data.length > 1) { // let str = ''; // str+='请选择对应的生产量'; // for(var i=0;i'+res.data[i].create+' 生产量:'+res.data[i].number+''; // } // str+='确认'; // $('#c-bach').parent('#c_bach').append(str); // $("#bach").change(()=>{ // $("#c-name").val(res.data[$("#bach").val()].name); // $("#c-specifications").val(res.data[$("#bach").val()].drawer_name); // $("#c-unit").val(res.data[$("#bach").val()].examine_name); // }); // $("#btn").click(()=>{ // //只读->已扫描过批次号 // if($("#c-bach").attr('readonly')==='readonly'){ // return false; // } // $("#bach").css('cssText','display:none! important');//隐藏按钮,下拉菜单 // $("#btn").css('display','none'); // // $.ajax({ // method:"POST", // url:"feeding/get_formula", // data:{ // bach:$("#c-bach").val(), // num:res.data[$("#bach").val()].number// 选定批次号的生产量,精确查找 // }, // success(result){ // var str = '';//页面table // var html = '';// html:需打印的表格 // for(var i=0;i"; // str += ""; // str += ""; // str += ""; // str += ""; // str += ""; // html += `${result.data[i].material} // ${result.data[i].nweight}`; // if (result.data[i].weight) { // html += parseFloat(result.data[i].weight); // } // html += `${result.data[i].gy_name}`; // // } // html+= ` // 总计 // // // // `;//${res.data.number} // $("#print_gy").append(html); // $("#table").append(str); // $("#c-bach").attr('readonly','readonly');//批次号输入框变为只读 // // $("#wuliao").keydown((e)=>{ // let key = e.which; // var error = 0; // if(key === 13){ // var wuliao = $("#wuliao").val(); // for(var i=0;i"; str += ""; // str += ""; str += ""; //投料重量 str += ""; if (result.data[i].weight == 0) { str += "保存"; str += ""; } else { str += "已保存"; str += ""; } str += ""; str += ""; str += ""; html += `${result.data[i].material} ${result.data[i].nweight}`; if (result.data[i].weight) { html += parseFloat(result.data[i].weight); } html += `${result.data[i].gy_name}`; } html += ` 总计 `; $("#print_gy").append(html); $("#table").append(str); $("#c-bach").attr('readonly', 'readonly');//批次号输入框变为只读 //判断是否链接电子秤串口conectFlag === true 连接正常 if(conectFlag === true){ $("#dzcshuju").on({ focus: function () { readFlag = true; input = $(this); readData(); }, blur: function () { readFlag = false; reader.releaseLock(); input = null; }, }); $(".number").on({ focus: function () { readFlag = true; input = $(this); readData(); }, blur: function () { readFlag = false; reader.releaseLock(); input = null; }, keydown:function(e){ //通过回车自动保存数据 if(e.keyCode == 13){ $(this).parent().next().children().click(); } } }); }else{ //连接电子秤异常,可手动在表格回车保存 $(".number").on({ keydown:function(e){ //通过回车自动保存数据 if(e.keyCode == 13){ $(this).parent().next().children().click(); } } }); } //扫描物料回车 $("#wuliao").keydown((e) => { let key = e.which; var error = 0; if (key === 13) { var string = $("#wuliao").val().trim();//获取扫描物料的值 // if ($("#wuliao").val() === '') { // // layer.confirm('扫描物料不能为空', { title: '操作提示',btn: [],closeBtn: 0,time: 2000}); // return false; // } var ytzl = $("#ytzl").text().trim(); var trzl = $("#dzcshuju").text().trim(); var input = $("#input").text().trim(); if (string === '') { for (let i = 0; i < $('.tablestr').length; i++) { const dom = $('.tablestr').eq(i); // 使用 jQuery 对象 const val = dom.find('td:eq(0) input').val(); // 获取第一个单元格中的input的值 const table_tlzl = dom.find('td:eq(1) input').val(); // 获取第二个单元格中的input的值 const table_ytzl = dom.find('td:eq(3) input').val(); // 获取第二个单元格中的input的值 const status_button = dom.find('td:eq(4) button').text(); // 获取第五个单元格中的button的文本 if (ytzl !== '' && trzl !== '') { if (status_button === '保存' && trzl === table_ytzl && val === input) { dom.find('td:eq(4) button').click(); // 触发按钮点击事件 $("#dzcshuju").text(''); // 清空对应的文本 $("#ytzl").text(''); $("#wuliao").val(''); $("#wuliao").focus(); // 让物料输入框获得焦点 // 扫描物料语音播报 var wuliao_msg = new SpeechSynthesisUtterance("已保存"); window.speechSynthesis.speak(wuliao_msg); } } } return false; } console.log("扫描物料"+string); //扫描批次号关闭 判断扫描物料 是否纯数字五位数 var regex = /^[0-9]{5}$/; if (regex.test(string)) { Fast.api.close();//关闭窗口 return false; } // 扫描重量 var regexs = /^\d+(\.\d+)?$/; if (regexs.test(string)) { var zhongliang = string + 'kg'; //判断是否扫描公斤码【20GJ\50GJ\60GJ】 if(zhongliang.includes('kg')) { var numberOnly = zhongliang.replace(/kg$/, ""); // 只替换字符串末尾的'GJ' $('#dzcshuju').text(numberOnly); $("#wuliao").val(''); $("#wuliao").focus(); return false; } } //物料码(string):M-501_年月日【M-501_230325】 = 原材料_原材料批次号 if (string.substr(0, string.indexOf('_'))) { var wuliao = string.substr(0, string.indexOf('_'));//原材料_ var bach = string.substr(string.indexOf('_') + 1);//_原材料批次号 } else { var wuliao = string; var bach = ''; } //定时获取投入重量的值,将值复制到对应物料列表中投料重量 setInterval(() => { let dzcshuju = $("#dzcshuju").text(); for (let i = 0; i < $('.tablestr').length; i++) { const dom = $('.tablestr')[i]; const val = $(dom).children().eq(0).children().eq(0).val(); const status = $(dom).children().eq(4).children().eq(0).text(); //按钮状态是未保存(是保存按钮的时候)并且 表格物料 == 扫描的物料 if (status === '保存' && val == wuliao) { $(dom).children().eq(3).children().eq(0).val(dzcshuju); break; } } }, 1000); // 每秒检查一次 // $('#input').html(); $.ajax({ method: "POST", url: "feeding/get_material", data: { bach: $("#c-bach").val(), material: wuliao }, success(data) { if (data.total > 0) { if (wuliao.length < 7) { $('#input').css('font-size', '60px'); } else { $('#input').css('font-size', '25px'); } console.log(11111) wuliao = data.string; $('#input').html(wuliao); for (var i = 0; i < result.data.length; i++) { for (var j = 0; j < data.data.length; j++) { //扫描的物料=table中的物料,,,变红,否则语音提示 if (result.data[i].material === data.data[j].m_name && (result.data[i].weight === 0 || result.data[i].weight == '')) { if (result.data[i].gy_num <= result.process) { console.log(wuliao+"中文文字变红") //投料重量为空时 扫描物料文字为红 if (result.data[i].weight == 0 || result.data[i].weight == '') { $(".material")[i].setAttribute('style', 'color:red'); $(".nweight")[i].setAttribute('style', 'color:red'); } // 扫描物料保存 let ytzl = $("#ytzl").text().trim(); // 应投重量 let trzl = $("#dzcshuju").text().trim(); // 投入重量 let input = $("#input").text();//扫描的物料 // 遍历表格行 const dom = $('.tablestr')[i]; //原材料 const val = $(dom).find('td:eq(0) input').val(); //应投重量 const table_ytzl = $(dom).find('td:eq(1) input').val(); //投料重量 const table_tlzl = $(dom).find('td:eq(2) input').val(); //按钮 const status_button = $(dom).find('td:eq(4) button').text(); //扫描物料等于表格中物料 并且 未保存 if (status_button === '保存' && (val === wuliao || data.data[j].m_name === wuliao)) { if (ytzl === '' && trzl === '' || ytzl && trzl === '') { $("#input").text(wuliao); $("#ytzl").text(table_ytzl); $("#wuliao").val(''); $("#wuliao").focus(); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + wuliao + "应投入重量" + table_ytzl + "千克"); window.speechSynthesis.speak(wuliao_msg); } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === wuliao) { console.log("保存了"); $(dom).find('td:eq(4) button').click(); $("#dzcshuju").text(''); $("#ytzl").text(''); $("#wuliao").val(''); $("#wuliao").focus(); //扫描物料语音播报 var wuliao_msg = new SpeechSynthesisUtterance("已保存"); window.speechSynthesis.speak(wuliao_msg); } break; // 退出循环 } else if (status_button === '已保存' && val === wuliao) { // 扫描的物料保存过了,清空【应投重量,投入重量】 $("#ytzl").text(''); $("#dzcshuju").text(''); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + wuliao + "已投料"); window.speechSynthesis.speak(wuliao_msg); $("#wuliao").val(''); $("#wuliao").focus(); break; // 退出循环 } // var the_bach = document.getElementsByClassName('bach')[i]; // if (the_bach.readOnly == false) { // the_bach.value = bach; // //语音播报 // var msg = new SpeechSynthesisUtterance("应投入物料" + result.data[i].material + "应投入重量" + result.data[i].nweight + "千克"); // window.speechSynthesis.speak(msg); // } // error++; } else if (result.data[i].gy_num > result.process) { Layer.confirm("此物料不在当前工序,请确认!", { area: ['60%', '60%'], }); //语音播报 var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!"); window.speechSynthesis.speak(msg); error++; } } //替代料变扫描的物料 if (result.data[i].material.indexOf('/') !== -1) { var arr = result.data[i].material.split('/'); if (arr.indexOf($("#wuliao").val()) !== -1 && result.data[i].gy_num == result.process) { $(".material")[i].value = wuliao; if (result.data[i].weight == 0) { $(".material")[i].setAttribute('style', 'color:red'); $(".nweight")[i].setAttribute('style', 'color:red'); } var the_bach = document.getElementsByClassName('bach')[i]; the_bach.value = bach; $(".number")[i].focus(); error++; } else if (arr.indexOf($("#wuliao").val()) !== -1) { Layer.confirm("此物料不在当前工序,请确认!", { area: ['60%', '60%'], }); //语音播报 var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!"); window.speechSynthesis.speak(msg); error++; } } } } // if (error === 0) { // layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息 // title: ['信息'], // btn: ['确认'], // area: ['60%', '60%'], // }); // var synth = window.speechSynthesis; // var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!'); // window.speechSynthesis.cancel(); // synth.speak(msg); // } } else { console.log(2) //没有在数据库查到,直接去比较物料与配方 if (wuliao.length < 7) { $('#input').css('font-size', '52px'); } else { $('#input').css('font-size', '25px'); } $('#input').html(wuliao); var isHas = false for (var i = 0; i < result.data.length; i++) { //扫描的物料=table中的物料,,,变红,否则语音提示 if (result.data[i].material === wuliao && (result.data[i].weight === 0 || result.data[i].weight == '')) { if (result.data[i].gy_num <= result.process) { isHas = true if (result.data[i].weight == 0 || result.data[i].weight == '') { console.log('扫描的物料 : '+wuliao+ '红色') //原材料、应投重量文字颜色 $(".material")[i].setAttribute('style', 'color:red'); $(".nweight")[i].setAttribute('style', 'color:red'); } var the_bach = document.getElementsByClassName('bach')[i]; the_bach.value = bach; let ytzl = $("#ytzl").text().trim(); // 应投重量 let trzl = $("#dzcshuju").text().trim(); // 投入重量 // 遍历表格行 const dom = $('.tablestr')[i]; //原材料 const val = $(dom).find('td:eq(0) input').val(); //应投重量 const table_ytzl = $(dom).find('td:eq(1) input').val(); //投料重量 const table_tlzl = $(dom).find('td:eq(2) input').val(); //按钮 const status_button = $(dom).find('td:eq(4) button').text(); //扫描物料等于表格中物料 并且 未保存 if (status_button === '保存' && val === wuliao) { if (ytzl === '' && trzl === '' || ytzl && trzl === '') { console.log("当前扫描物料应投入重量") $("#input").text(wuliao); $("#ytzl").text(table_ytzl); $("#wuliao").val(''); $("#wuliao").focus(); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + wuliao + "应投入重量" + table_ytzl + "千克"); window.speechSynthesis.speak(wuliao_msg); } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === wuliao) { console.log("保存了"); $(dom).find('td:eq(4) button').click(); $("#dzcshuju").text(''); $("#ytzl").text(''); $("#wuliao").val(''); $("#wuliao").focus(); //扫描物料语音播报 var wuliao_msg = new SpeechSynthesisUtterance("已保存"); window.speechSynthesis.speak(wuliao_msg); } break; // 退出循环 } else if (status_button === '已保存' && val === wuliao) { console.log(wuliao+"已投料") // 扫描的物料保存过了,清空【应投重量,投入重量】 $("#ytzl").text(''); $("#dzcshuju").text(''); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + wuliao + "已投料"); window.speechSynthesis.speak(wuliao_msg); $("#wuliao").val(''); $("#wuliao").focus(); break; // 退出循环 } error++; break; } else if (result.data[i].gy_num > result.process) { isHas = true Layer.confirm( wuliao + "此物料不在当前工序,请确认!", { area: ['70%', '60%'], }); $("#ytzl").text(''); $("#wuliao").val(''); $("#wuliao").focus(); //语音播报 var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!"); window.speechSynthesis.speak(msg); error++; break; } } //替代料变扫描的物料 if (result.data[i].material.indexOf('/') !== -1) { var arr = result.data[i].material.split('/'); var spanValue = document.getElementById("input").innerHTML; if (arr.indexOf(spanValue) !== -1 && result.data[i].gy_num <= result.process) { $(".material")[i].value = wuliao; if (result.data[i].weight == 0) { $(".material")[i].setAttribute('style', 'color:red'); $(".nweight")[i].setAttribute('style', 'color:red'); } // 扫描物料保存 let ytzl = $("#ytzl").text().trim(); // 应投重量 let trzl = $("#dzcshuju").text().trim(); // 投入重量 // 遍历表格行 // for (let i = 0; i < $('.tablestr').length; i++) { const dom = $('.tablestr')[i]; //原材料 const val = $(dom).find('td:eq(0) input').val(); //应投重量 const table_ytzl = $(dom).find('td:eq(1) input').val(); //投料重量 const table_tlzl = $(dom).find('td:eq(2) input').val(); //按钮 const status_button = $(dom).find('td:eq(4) button').text(); //扫描物料等于表格中物料 并且 未保存 if (status_button === '保存' && val === wuliao) { if (ytzl === '' && trzl === '' || ytzl && trzl === '') { $("#input").text(wuliao); $("#ytzl").text(table_ytzl); $("#wuliao").val(''); $("#wuliao").focus(); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + wuliao + "应投入重量" + table_ytzl + "千克"); window.speechSynthesis.speak(wuliao_msg); } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === wuliao) { console.log("保存了"); $(dom).find('td:eq(4) button').click(); $("#dzcshuju").text(''); $("#ytzl").text(''); $("#wuliao").val(''); $("#wuliao").focus(); //扫描物料语音播报 var wuliao_msg = new SpeechSynthesisUtterance("已保存"); window.speechSynthesis.speak(wuliao_msg); } break; // 退出循环 } else if (status_button === '已保存' && val === wuliao) { // 扫描的物料保存过了,清空【应投重量,投入重量】 $("#ytzl").text(''); $("#dzcshuju").text(''); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + wuliao + "已投料"); window.speechSynthesis.speak(wuliao_msg); $("#wuliao").val(''); $("#wuliao").focus(); break; // 退出循环 } // } // var the_bach = document.getElementsByClassName('bach')[i]; // if (the_bach.readOnly == false) { // the_bach.value = bach; // // $(".number")[i].focus(); // console.log("替代料") // var msg = new SpeechSynthesisUtterance("应投入物料" + result.data[i].material + "应投入重量" + result.data[i].nweight + "千克"); // window.speechSynthesis.speak(msg); // } // error++; // break; } else if (arr.indexOf($("#wuliao").val()) !== -1) { Layer.confirm("此物料不在当前工序,请确认!", { area: ['60%', '60%'], }); //语音播报 var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!"); window.speechSynthesis.speak(msg); error++; break; } } } if (! isHas) { $.post({ url: 'feeding/matchCode', data: {code: wuliao}, success(data) { console.log(data) var str= '' if (data.length > 0) { // data.forEach(function(item, index) { // str +=` // // // ${item.name} // // ` // }) data.forEach(function(item, index) { str += ` ${item} `; }); } Layer.open({ type: 1, title: '选择物料', content: ` ${ str } `, area: ['90%', '100%'], btn: ['确定', '取消'], btnAlign: 'right', // yes: function() { // var form = layer.form; // console.log(form) // return false; // }, yes: function(index, layero) { // 点击确定按钮时触发的回调函数 var code = $('input[type="radio"]:checked').val(); var matchCode = code.match(/^(M-\d{2,3})/)[1] for (var i = 0; i < result.data.length; i++) { var item = result.data[i] var itemCode = item.material.match(/^(M-\d{2,3})/) console.log(itemCode) if (itemCode != null && itemCode[0] == matchCode) { item.material = code if (result.data[i].weight == 0 || result.data[i].weight == '') { //原材料、应投重量文字颜色 $(".material")[i].setAttribute('style', 'color:red'); $(".material")[i].setAttribute('value', code) $(".nweight")[i].setAttribute('style', 'color:red'); } var the_bach = document.getElementsByClassName('bach')[i]; the_bach.value = bach; let ytzl = $("#ytzl").text().trim(); // 应投重量 let trzl = $("#dzcshuju").text().trim(); // 投入重量 // 遍历表格行 const dom = $('.tablestr')[i]; //原材料 const val = $(dom).find('td:eq(0) input').val(); //应投重量 const table_ytzl = $(dom).find('td:eq(1) input').val(); //投料重量 const table_tlzl = $(dom).find('td:eq(2) input').val(); //按钮 const status_button = $(dom).find('td:eq(4) button').text(); break; //扫描物料等于表格中物料 并且 未保存 if (status_button === '保存' && val === code) { if (ytzl === '' && trzl === '' || ytzl && trzl === '') { $("#input").text(code); $("#ytzl").text(table_ytzl); $("#wuliao").val(''); $("#wuliao").focus(); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + code + "应投入重量" + table_ytzl + "千克"); window.speechSynthesis.speak(wuliao_msg); } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === code) { console.log("保存了"); $(dom).find('td:eq(4) button').click(); $("#dzcshuju").text(''); $("#ytzl").text(''); $("#wuliao").val(''); $("#wuliao").focus(); //扫描物料语音播报 var wuliao_msg = new SpeechSynthesisUtterance("已保存"); window.speechSynthesis.speak(wuliao_msg); } break; // 退出循环 } else if (status_button === '已保存' && val === code) { // 扫描的物料保存过了,清空【应投重量,投入重量】 $("#ytzl").text(''); $("#dzcshuju").text(''); var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + code + "已投料"); window.speechSynthesis.speak(wuliao_msg); $("#wuliao").val(''); $("#wuliao").focus(); break; // 退出循环 } } } // 关闭弹出框 Layer.close(index); $("#wuliao").focus(); }, btn2: function(index, layero) { // 点击取消按钮时触发的回调函数 // 直接关闭弹出框 Layer.close(index); // 返回 false 阻止弹出框关闭 return false; } }); } }) } // if (error === 0) { // layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息 // title: ['信息'], // btn: ['确认'], // area: ['60%', '60%'], // }); // var synth = window.speechSynthesis; // //没有物料,清空应投重量 // $("#ytzl").text(''); // var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!'); // window.speechSynthesis.cancel(); // synth.speak(msg); // } } } }); //清空物料扫描后的值,下次直接重新扫描即可 $("#wuliao").val(''); } }); } }); } } }); num++; } else { // return false; } } }); $(document).on('click', '.submit', function () { if ($("#c-operator").val() == "" || $("#c-inspector").val() == "") { layer.confirm('请选择 操作人员 或 检验人员', {title: '操作提示',btn: [],area: ['60%', '60%'],closeBtn: 0,time: 2000}); //语音播报 var msg = new SpeechSynthesisUtterance("请选择 操作人员 或 检验人员"); window.speechSynthesis.speak(msg); } else { //批次号 var bach = $("#c-bach").val(); //日期 var date = $("#c-date").val(); //操作人员 var operator = $("#c-operator").val(); //检验人员 var inspector = $("#c-inspector").val(); //原材料 var material = $(this).parent().siblings().eq(0).children('input').val(); //应投重量 var nweight = $(this).parent().siblings().eq(1).children('input').val(); //工艺序号 var gy_num = $(this).parent().siblings().eq(2).children('input').val(); //投料重量 var weight = $(this).parent().siblings().eq(3).children('input').val(); //原材料批次号 var material_bach = $(this).parent().siblings().eq(4).children('input').val(); //操作记录 var gy_name = $(this).parent().siblings().eq(5).children('input').val(); var fid = $(this).parent().siblings().eq(6).children('input').val(); // if(nweight != weight){ // var num_weight = parseFloat((nweight - weight).toFixed(3)); // console.log(num_weight) // var num_weight_msg = new SpeechSynthesisUtterance("投料重量与应投入重量相差" + num_weight + "请确认" ); // window.speechSynthesis.speak(num_weight_msg); // return false; // } // if (weight == "") { // layer.confirm('投料重量不能为空', { // title: '操作提示', // btn: [], // area: ['60%', '60%'], // closeBtn: 0, // time: 2000 // }); // //语音播报 // var msg = new SpeechSynthesisUtterance("投料重量不能为空"); // window.speechSynthesis.speak(msg); // } else { $(this).text('已保存'); $("#wuliao").focus(); // $(this).text('修改'); //禁用投料重量 $(this).parent().siblings().eq(3).children('input').attr('readonly', true); // 禁用原材料批次号 $(this).parent().siblings().eq(4).children('input').attr('readonly', true); $(this).attr('disabled', true); // } // console.log(bach); // console.log(date); // console.log(operator); // console.log(inspector); // console.log(material); // console.log(nweight); // console.log(gy_num); // console.log(weight); // console.log(material_bach); // console.log(gy_name);return false; $.ajax({ type: "POST", url: "feeding/add", data: { fid: fid, bach: bach, date: date, operator: operator, inspector: inspector, material: material, nweight: nweight, gy_num: gy_num, weight: weight, material_bach: material_bach, gy_name: gy_name, }, success: function (data) { console.log(data) } }); } }); document.addEventListener('keydown', function(event) { // console.log(event.key); // 检查按下的键是否是回车键 if (event.key === 'Escape') { //关闭弹窗 Fast.api.close(); } }); $('input').keydown(function (e) { let key = e.which; if (key == 13) { return false; } }); //打印预览 $(document).ready(function ($) { 'use strict'; $(".print-link").on('click', function () { var status = 1; var total = 0; var stotal = 0; //开票人 $("#specifications").html($('#c-specifications').val()); //审核 $("#unit").html($('#c-unit').val()); //批次号 var bach = $('#c-bach').val(); //写入到add页面 $("#bach").html(bach); $("#formula").val($("#name").val()); //添加重量,包装规格,机组到表格内 for (var i = 0; i < $(".tablestr").length; i++) { var weight = parseFloat($(".tablestr:eq(" + i + ")").children("tr td:eq(3)").children().val()); if (weight) { $(".print:eq(" + i + ")").children("tr td:eq(2)").html(weight); total += weight; } var weight2 = parseFloat($(".tablestr:eq(" + i + ")").children("tr td:eq(1)").children().val()); if (weight2) { $(".print:eq(" + i + ")").children("tr td:eq(1)").html(weight2); stotal += weight2; } } $("#stotal").html(stotal.toFixed(2)); if (total > 0) { $("#total").html(total.toFixed(2)); } if (!$("#c-pickor").val()) { status = 2; } if (!$("#c-warehouseor").val()) { status = 2; } /*if (status == 2){ layer.confirm('领料人或仓管人为空,请检查!');return false; }*/ createQrcode(bach, 80, 80); var img = document.getElementById("myImage"); /// get image element var canvas = document.getElementsByTagName('canvas')[0]; img.src = canvas.toDataURL(); /// update image $.print('#print_area'); return false; }); function createQrcode(txt, width, height) { $(".qrcode").qrcode({ render: "canvas",//canvas和table两种渲染方式 width: width, height: height, correctLevel: 3,//二维码纠错级别 background: "#ffffff",//背景颜色 foreground: "#000000", //二维码颜色 text: txt }); } }); Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });