feeding.js 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jQuery.print', 'jquery.qrcode.min'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'feeding/index' + location.search,
  8. add_url: 'feeding/add',
  9. edit_url: 'feeding/edit',
  10. del_url: 'feeding/del',
  11. multi_url: 'feeding/multi',
  12. import_url: 'feeding/import',
  13. table: 'feeding',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. { checkbox: true },
  27. // { field: 'id', title: __('Id') },
  28. { field: 'bach', title: __('Bach'), operate: 'LIKE' },
  29. { field: 'material', title: __('Material'), operate: 'LIKE' },
  30. { field: 'no', title: __('No'), operate: 'LIKE' },
  31. { field: 'nweight', title: __('Nweight'), operate: 'LIKE' },
  32. { field: 'weight', title: __('Weight'), operate: 'LIKE' },
  33. { field: 'gy_num', title: __('Gy_num') },
  34. { field: 'date', title: __('Date'), operate: 'LIKE' },
  35. { field: 'operator', title: __('Operator'), operate: 'LIKE' },
  36. // {field: 'tid', title: __('Tid')},
  37. { field: 'inspector', title: __('Inspector'), operate: 'LIKE' },
  38. { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
  39. ]
  40. ]
  41. });
  42. table.on('post-body.bs.table', function () {
  43. $(".btn-add").data("area", ["100%", "100%"]);
  44. });
  45. // 进入页面全屏
  46. // if (document.documentElement) {
  47. // document.documentElement.webkitRequestFullScreen();
  48. // document.body.onkeyup = function (e) {
  49. // e = e || window.event;
  50. // console.log(e.keyCode);
  51. // if (e.keyCode == 27) {//Esc全屏或退出全屏
  52. // document.documentElement.webkitRequestFullScreen();
  53. // }
  54. // if (e.keyCode == 116) {//F5
  55. // document.documentElement.webkitRequestFullScreen();
  56. // }
  57. // if (e.keyCode == 82 && e.ctrlKey) {//Ctrl+R
  58. // document.documentElement.webkitRequestFullScreen();
  59. // }
  60. // if (e.keyCode === 13) {
  61. // document.querySelector('.btn-refresh').click();
  62. // document.querySelector('.btn-add').click();
  63. // }
  64. //
  65. // };
  66. // }
  67. $(document).ready(function() {
  68. // 尝试进入全屏模式
  69. function enterFullScreen() {
  70. if (document.documentElement.requestFullscreen) {
  71. document.documentElement.requestFullscreen();
  72. } else if (document.documentElement.webkitRequestFullScreen) {
  73. document.documentElement.webkitRequestFullScreen();
  74. }
  75. }
  76. // 页面加载时尝试进入全屏
  77. enterFullScreen();
  78. // 监听键盘事件
  79. document.body.addEventListener('keyup', function(e) {
  80. e = e || window.event;
  81. console.log(e.keyCode);
  82. if (e.keyCode === 27) { // Esc键退出全屏后,不需要再次请求全屏
  83. // 一般情况下,浏览器会自动处理 Esc 键退出全屏
  84. }
  85. if (e.keyCode === 116) { // F5刷新页面,通常不需要特别处理
  86. // 浏览器默认行为会刷新页面
  87. }
  88. if (e.keyCode === 82 && e.ctrlKey) { // Ctrl+R,通常不需要特别处理
  89. // 浏览器默认行为会刷新页面
  90. }
  91. if (e.keyCode === 13) { // 回车键
  92. document.querySelector('.btn-refresh').click(); // 模拟点击刷新按钮
  93. document.querySelector('.btn-add').click(); // 模拟点击添加按钮
  94. }
  95. });
  96. });
  97. $(".form-control").focus();
  98. // 为表格绑定事件
  99. Table.api.bindevent(table);
  100. },
  101. //添加
  102. add: function () {
  103. $(document).ready(function(){
  104. // 设置边框颜色并清除其他输入框的边框颜色
  105. function setBorderColor(input) {
  106. $('input').not(input).css('border-color', ''); // 清除其他输入框的边框颜色
  107. input.css('border-color', 'red'); // 设置当前点击输入框的边框颜色
  108. }
  109. function setBorderColors(input) {
  110. $('input').not(input).css('border-color', '');
  111. input.css('border-color', 'red');
  112. $('#c-inspector').css('border-color', '');
  113. $('#c-operator').css('border-color', '');
  114. }
  115. $('#c-bach').focus(function(){
  116. setBorderColors($(this));
  117. });
  118. $('#wuliao').focus(function(){
  119. setBorderColors($(this));
  120. });
  121. $('#dzcshuju').focus(function(){
  122. setBorderColors($(this));
  123. });
  124. $('#c-operator').focus(function(){
  125. setBorderColor($(this));
  126. $('#c-inspector').css('border-color', '');
  127. });
  128. $('#c-inspector').focus(function(){
  129. setBorderColor($(this));
  130. $('#c-operator').css('border-color', '');
  131. });
  132. });
  133. const BAUD_RATE = 9600;
  134. const READ_TIMEOUT = 50;
  135. let serialPort;
  136. let reader;
  137. let readFlag = true;
  138. let conectFlag = false;
  139. let serialData = [];
  140. let asciidecoder = new TextDecoder();
  141. let serialTimer = null;
  142. let input = null;
  143. let oldVal = 0;
  144. // 连接串口设备
  145. const connectSerial = async () => {
  146. try {
  147. const ports = await navigator.serial.getPorts();
  148. if (ports.length > 0) {
  149. // 关闭已连接的串口
  150. if (serialPort) {
  151. await serialPort.close();
  152. serialPort = null;
  153. }
  154. // 选择第一个串口进行连接
  155. serialPort = ports[0];
  156. await serialPort.open({ baudRate: BAUD_RATE });
  157. if (serialPort.readable) {
  158. console.log("已连接设备");
  159. conectFlag = true;
  160. readData(); // 开始读取数据
  161. } else {
  162. console.log("未能连接到设备");
  163. }
  164. } else {
  165. var duankou_msg = new SpeechSynthesisUtterance("请选择 U S B 串口并点击连接");
  166. window.speechSynthesis.speak(duankou_msg);
  167. const port = await navigator.serial.requestPort();
  168. serialPort = port;
  169. await serialPort.open({ baudRate: BAUD_RATE });
  170. if (serialPort.readable) {
  171. var duankou_msg = new SpeechSynthesisUtterance("已连接设备");
  172. window.speechSynthesis.speak(duankou_msg);
  173. conectFlag = true;
  174. readData(); // 开始读取数据
  175. }
  176. }
  177. } catch (error) {
  178. // 处理连接错误
  179. }
  180. };
  181. // 读取串口数据
  182. const readData = async () => {
  183. try {
  184. while (readFlag && conectFlag && serialPort.readable) {
  185. reader = serialPort.readable.getReader();
  186. while (true) {
  187. const { value, done } = await reader.read();
  188. if (done) break;
  189. dataReceived(value);
  190. }
  191. }
  192. } catch (error) {
  193. // 处理读取数据错误
  194. } finally {
  195. reader.releaseLock();
  196. }
  197. };
  198. // 处理接收到的数据
  199. const dataReceived = (data) => {
  200. serialData.push(...data);
  201. clearTimeout(serialTimer);
  202. serialTimer = setTimeout(() => {
  203. // const dataNum = parseFloat(asciidecoder.decode(Uint8Array.from(data)));
  204. const dataNum = parseFloat(asciidecoder.decode(Uint8Array.from(serialData)));
  205. console.log('电子秤获取的数据是'+ dataNum);
  206. if (!isNaN(parseFloat(dataNum))) {
  207. $('#dzcshuju').text(dataNum);
  208. } else {
  209. // 字符串不是数字的处理逻辑
  210. console.log("串口接触异常,未获取到数据");
  211. }
  212. serialData = [];
  213. }, READ_TIMEOUT);
  214. };
  215. // const BAUD_RATE = 9600;
  216. // const READ_TIMEOUT = 20;
  217. // let serialPort;
  218. // let reader;
  219. // let readFlag = true;
  220. // let conectFlag = false;
  221. // let serialData = [];
  222. // let asciidecoder = new TextDecoder();
  223. // let serialTimer = null;
  224. // let input = null;
  225. // let oldVal = 0;
  226. //
  227. // // 连接串口设备
  228. // const connectSerial = async () => {
  229. // try {
  230. // const ports = await navigator.serial.getPorts();
  231. // if (ports.length > 0) {
  232. // // 关闭已连接的串口
  233. // if (serialPort) {
  234. // await serialPort.close();
  235. // serialPort = null;
  236. // }
  237. // // 选择第一个串口进行连接
  238. // serialPort = ports[0];
  239. // await serialPort.open({ baudRate: BAUD_RATE });
  240. // if (serialPort.readable) {
  241. // console.log("已连接设备");
  242. // conectFlag = true;
  243. // readData(); // 开始读取数据
  244. // } else {
  245. // console.log("未能连接到设备");
  246. // }
  247. // } else {
  248. // var duankou_msg = new SpeechSynthesisUtterance("请选择 U S B 串口并点击连接");
  249. // window.speechSynthesis.speak(duankou_msg);
  250. // const port = await navigator.serial.requestPort();
  251. // serialPort = port;
  252. // await serialPort.open({ baudRate: BAUD_RATE });
  253. // if (serialPort.readable) {
  254. // var duankou_msg = new SpeechSynthesisUtterance("已连接设备");
  255. // window.speechSynthesis.speak(duankou_msg);
  256. // conectFlag = true;
  257. // readData(); // 开始读取数据
  258. // }
  259. // }
  260. // } catch (error) {
  261. // // 处理连接错误
  262. // }
  263. // };
  264. //
  265. // // 读取串口数据
  266. // const readData = async () => {
  267. // try {
  268. // while (readFlag && conectFlag && serialPort.readable) {
  269. // reader = serialPort.readable.getReader();
  270. // while (true) {
  271. // const { value, done } = await reader.read();
  272. // if (done) break;
  273. // dataReceived(value);
  274. // }
  275. // }
  276. // } catch (error) {
  277. // // 处理读取数据错误
  278. // } finally {
  279. // reader.releaseLock();
  280. // }
  281. // };
  282. //
  283. // // 处理接收到的数据
  284. // const dataReceived = (data) => {
  285. // serialData.push(...data);
  286. // clearTimeout(serialTimer);
  287. // serialTimer = setTimeout(() => {
  288. // const dataNums = asciidecoder.decode(Uint8Array.from(serialData));
  289. // const dataNum = parseFloat(dataNums.split('').reverse().join('').split('=')[0]);
  290. // console.log('电子秤获取的数据是'+ dataNum);
  291. //
  292. // if (!isNaN(parseFloat(dataNum))) {
  293. // $('#dzcshuju').text(dataNum);
  294. // } else {
  295. // // 字符串不是数字的处理逻辑
  296. // console.log("串口接触异常,未获取到数据");
  297. // }
  298. // serialData = [];
  299. // }, READ_TIMEOUT);
  300. // };
  301. //进入投料添加页面 光标自动跳到批次号输入框
  302. $('#c-bach').focus();
  303. var num = 0;
  304. $('#c-bach').keydown((e) => {
  305. let key = e.which;
  306. if (key == 13) {
  307. $('#dzcshuju').text('');
  308. connectSerial();
  309. $("#wuliao").focus();
  310. if (num === 0) {
  311. var bach = $("#c-bach").val();//批次号
  312. if (bach == '') {
  313. layer.confirm('批次号不能为空', { title: '操作提示',btn: [],closeBtn: 0,time: 2000});
  314. return false;
  315. }
  316. //批次号语音播报
  317. var bach_msg = new SpeechSynthesisUtterance("当前批次号是" + bach);
  318. window.speechSynthesis.speak(bach_msg);
  319. $.ajax({
  320. method: "POST",
  321. data: { bach: bach },
  322. url: "feeding/get_task",
  323. success(res) {
  324. $("#table").append("<input id='name' type='hidden' value='" + res.data[0].name + "'>");
  325. //批次号重复/做下拉选择
  326. if (res.data.length > 1) {
  327. // let str = '';
  328. // str+='<select class="selectpicker form-control" id="bach"><option>请选择对应的生产量</option>';
  329. // for(var i=0;i<res.data.length;i++){
  330. // str+='<option value="'+i+'">'+res.data[i].create+'&nbsp;&nbsp;&nbsp;&nbsp;生产量:'+res.data[i].number+'</option>';
  331. // }
  332. // str+='</select><a href="javascript:;" id="btn" class="btn btn-success">确认</a>';
  333. // $('#c-bach').parent('#c_bach').append(str);
  334. // $("#bach").change(()=>{
  335. // $("#c-name").val(res.data[$("#bach").val()].name);
  336. // $("#c-specifications").val(res.data[$("#bach").val()].drawer_name);
  337. // $("#c-unit").val(res.data[$("#bach").val()].examine_name);
  338. // });
  339. // $("#btn").click(()=>{
  340. // //只读->已扫描过批次号
  341. // if($("#c-bach").attr('readonly')==='readonly'){
  342. // return false;
  343. // }
  344. // $("#bach").css('cssText','display:none! important');//隐藏按钮,下拉菜单
  345. // $("#btn").css('display','none');
  346. //
  347. // $.ajax({
  348. // method:"POST",
  349. // url:"feeding/get_formula",
  350. // data:{
  351. // bach:$("#c-bach").val(),
  352. // num:res.data[$("#bach").val()].number// 选定批次号的生产量,精确查找
  353. // },
  354. // success(result){
  355. // var str = '';//页面table
  356. // var html = '';// html:需打印的表格
  357. // for(var i=0;i<result.data.length;i++){
  358. // str += "<tr class='tablestr"+i+" tablestr'><td><input class='form-control material' type='text' name='row[material][]' readonly value='"+result.data[i].material+"'></td>";
  359. // str += "<td><input class='form-control' type='text' name='row[nweight][]' readonly value='"+result.data[i].nweight+"'></td>";
  360. // str += "<td><input class='form-control' type='number' name='row[weight][]' value='";
  361. // if (result.data[i].weight) {
  362. // //已操作的工序变为只读,附带实加重量
  363. // str += parseFloat(result.data[i].weight) + "' readonly ";
  364. // }
  365. // str += "'></td>";
  366. // str += "<input class='form-control' type='hidden' name='row[gy_num][]' value='"+result.data[i].gy_num+"'>";
  367. // str += "<td><input class='form-control' type='text' name='row[gy_name][]' readonly value='"+result.data[i].gy_name+"'></td>";
  368. // str += "</tr>";
  369. // html += `<tr class="print${i} print"><td>${result.data[i].material}</td>
  370. // <td>${result.data[i].nweight}</td><td>`;
  371. // if (result.data[i].weight) {
  372. // html += parseFloat(result.data[i].weight);
  373. // }
  374. // html += `</td><td style="text-align: left">${result.data[i].gy_name}</td></tr>`;
  375. //
  376. // }
  377. // html+= `<tr>
  378. // <td style="width: 100px;text-align: center">总计</td>
  379. // <td class="total" style="width: 100px;text-align: center"></td>
  380. // <td id="total"></td>
  381. // <td></td>
  382. // </tr>`;//${res.data.number}
  383. // $("#print_gy").append(html);
  384. // $("#table").append(str);
  385. // $("#c-bach").attr('readonly','readonly');//批次号输入框变为只读
  386. //
  387. // $("#wuliao").keydown((e)=>{
  388. // let key = e.which;
  389. // var error = 0;
  390. // if(key === 13){
  391. // var wuliao = $("#wuliao").val();
  392. // for(var i=0;i<result.data.length;i++) {
  393. // //扫描的物料=table中的物料,,,变红,否则语音提示
  394. // if(result.data[i].material===wuliao && result.data[i].gy_num == result.process){
  395. // $(".material")[i].setAttribute('style','color:red');
  396. // error++;
  397. // }else if(result.data[i].material===wuliao){
  398. // Layer.confirm("此物料不在当前工序,请确认!");
  399. // //语音播报
  400. // var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
  401. // window.speechSynthesis.speak(msg);
  402. // error++;
  403. // }
  404. // //替代料变扫描的物料
  405. // if(result.data[i].material.indexOf('/')!==-1){
  406. // var arr = result.data[i].material.split('/');
  407. // if(arr.indexOf($("#wuliao").val()) !== -1 && result.data[i].gy_num == result.process){
  408. // $(".material")[i].value = wuliao;
  409. // $(".material")[i].setAttribute('style','color:red');
  410. // error++;
  411. // }else if(arr.indexOf($("#wuliao").val()) !== -1 ){
  412. // Layer.confirm("此物料不在当前工序,请确认!");
  413. // //语音播报
  414. // var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
  415. // window.speechSynthesis.speak(msg);
  416. // error++;
  417. // }
  418. // }
  419. // }
  420. // if(error===0){
  421. // Layer.confirm("此物料不在配方中,请确认!");
  422. // //语音播报
  423. // var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
  424. // window.speechSynthesis.speak(msg);
  425. // }
  426. // //清空物料扫描后的值,下次直接重新扫描即可
  427. // $("#wuliao").val('');
  428. // }
  429. // });
  430. // }
  431. // });
  432. // });
  433. } else {//批次号不重复直接赋值
  434. $("#btn").css('display', 'none');
  435. $("#c-name").val(res.data[0].name);
  436. $("#c-specifications").val(res.data[0].drawer_name);
  437. $("#c-unit").val(res.data[0].examine_name);
  438. if (res.operator != '' && res.inspector != '') {
  439. $("#c-operator").val(res.operator);
  440. $("#c-inspector").val(res.inspector);
  441. }
  442. $.ajax({
  443. method: "POST",
  444. url: "feeding/get_formula",
  445. data: {
  446. bach: $("#c-bach").val(),
  447. },
  448. success(result) {
  449. var str = '';//页面table
  450. var html = '';//打印的table
  451. for (var i = 0; i < result.data.length; i++) {
  452. str += "<tr class='tablestr" + i + " tablestr'><td style='padding: 0px 0px 0px 10px;'><input class='form-control material' type='text' name='row[material][]' readonly value='" + result.data[i].material + "'></td>";
  453. str += "<td style='padding: 0px 0px 0px 0px;'><input class='form-control nweight' type='text' name='row[nweight][]' readonly value='" + result.data[i].nweight + "'></td>";
  454. // str += "<td><input class='form-control nweight' type='text' name='row[nweight][]' readonly value='" + result.data[i].nweight + "' style='color: " + (result.data[i].weight ? "##000000" : "") + ";'></td>";
  455. str += "<td style='display: none'><input class='form-control gy_num' type='hidden' name='row[gy_num][]' value='" + result.data[i].gy_num + "'></td>";
  456. //投料重量
  457. str += "<td style='padding: 0px 0px 0px 0px;'><input class='form-control number' type='number' name='row[weight][]' value='";
  458. // if (result.data[i].weight || result.data[i].material === '*****') {
  459. if (result.data[i].weight || result.data[i].material === '*****' || result.data[i].material === ' ') {
  460. //已操作的工序变为只读,附带实加重量
  461. str += result.data[i].weight + "' readonly ";
  462. // str += `${result.data[i].weight}' style="color: ##000000;`;
  463. }
  464. str += "'></td>";
  465. if (result.data[i].weight == 0) {
  466. str += "<td style='display:none'><button type=\"button\" class=\"btn btn-primary btn-embossed submit \">保存</button></td>";
  467. str += "<td style='padding: 0px 0px 0px 0px;'><input class='form-control bach' readonly type='text' name='row[bach][]' value=''></td>";
  468. } else {
  469. str += "<td style='display:none' ><button type=\"button\" class=\"btn btn-primary btn-embossed submit \" disabled>已保存</button></td>";
  470. str += "<td style='padding: 0px 0px 0px 0px;'><input class='form-control bach' type='text' name='row[bach][]' readonly value='" + result.data[i].material_bach + "'></td>";
  471. }
  472. str += "<td style='padding: 0px 0px 0px 0px;'><input class='form-control' readonly type='text' name='row[gy_name][]' value='" + result.data[i].gy_name + "'></td>";
  473. str += "</tr>";
  474. html += `<tr class="print${i} print"><td>${result.data[i].material}</td>
  475. <td>${result.data[i].nweight}</td><td>`;
  476. if (result.data[i].weight) {
  477. html += parseFloat(result.data[i].weight);
  478. }
  479. html += `</td><td style="text-align: left">${result.data[i].gy_name}</td></tr>`;
  480. }
  481. html += `<tr>
  482. <td style="width: 100px;text-align: center">总计</td>
  483. <td class="total" id="stotal" style="width: 100px;text-align: center"></td>
  484. <td id="total"></td>
  485. <td></td>
  486. </tr>`;
  487. $("#print_gy").append(html);
  488. $("#table").append(str);
  489. $("#c-bach").attr('readonly', 'readonly');//批次号输入框变为只读
  490. //判断是否链接电子秤串口conectFlag === true 连接正常
  491. if(conectFlag === true){
  492. $("#dzcshuju").on({
  493. focus: function () {
  494. readFlag = true;
  495. input = $(this);
  496. readData();
  497. },
  498. blur: function () {
  499. readFlag = false;
  500. reader.releaseLock();
  501. input = null;
  502. },
  503. });
  504. $(".number").on({
  505. focus: function () {
  506. readFlag = true;
  507. input = $(this);
  508. readData();
  509. },
  510. blur: function () {
  511. readFlag = false;
  512. reader.releaseLock();
  513. input = null;
  514. },
  515. keydown:function(e){
  516. //通过回车自动保存数据
  517. if(e.keyCode == 13){
  518. $(this).parent().next().children().click();
  519. }
  520. }
  521. });
  522. }else{
  523. //连接电子秤异常,可手动在表格回车保存
  524. $(".number").on({
  525. keydown:function(e){
  526. //通过回车自动保存数据
  527. if(e.keyCode == 13){
  528. $(this).parent().next().children().click();
  529. }
  530. }
  531. });
  532. }
  533. //扫描物料回车
  534. $("#wuliao").keydown((e) => {
  535. let key = e.which;
  536. var error = 0;
  537. if (key === 13) {
  538. var string = $("#wuliao").val().trim();//获取扫描物料的值
  539. console.log("wulaio----"+string);
  540. if ($("#wuliao").val() === '') {
  541. layer.confirm('扫描物料不能为空', { title: '操作提示',btn: [],closeBtn: 0,time: 2000});
  542. return false;
  543. }
  544. //判断扫描物料 是否纯数字五位数
  545. var regex = /^[0-9]{5}$/;
  546. if (regex.test(string)) {
  547. Fast.api.close();//关闭窗口
  548. return false;
  549. }
  550. //物料码(string):M-501_年月日【M-501_230325】 = 原材料_原材料批次号
  551. if (string.substr(0, string.indexOf('_'))) {
  552. var wuliao = string.substr(0, string.indexOf('_'));//原材料_
  553. var bach = string.substr(string.indexOf('_') + 1);//_原材料批次号
  554. } else {
  555. var wuliao = string;
  556. var bach = '';
  557. }
  558. //判断是否扫描公斤码【20GJ\50GJ\60GJ】
  559. if(wuliao.includes('GJ')) {
  560. var numberOnly = wuliao.replace(/GJ$/, ""); // 只替换字符串末尾的'GJ'
  561. $('#dzcshuju').text(numberOnly);
  562. $("#wuliao").val('');
  563. $("#wuliao").focus();
  564. return false;
  565. }
  566. if(wuliao.includes('gj')) {
  567. var numberOnly = wuliao.replace(/gj$/, ""); // 只替换字符串末尾的'GJ'
  568. $('#dzcshuju').text(numberOnly);
  569. $("#wuliao").val('');
  570. $("#wuliao").focus();
  571. return false;
  572. }
  573. if(wuliao.includes('KG')) {
  574. var numberOnly = wuliao.replace(/KG$/, ""); // 只替换字符串末尾的'GJ'
  575. $('#dzcshuju').text(numberOnly);
  576. $("#wuliao").val('');
  577. $("#wuliao").focus();
  578. return false;
  579. }
  580. if(wuliao.includes('kg')) {
  581. var numberOnly = wuliao.replace(/kg$/, ""); // 只替换字符串末尾的'GJ'
  582. $('#dzcshuju').text(numberOnly);
  583. $("#wuliao").val('');
  584. $("#wuliao").focus();
  585. return false;
  586. }
  587. //定时获取投入重量的值,将值复制到对应物料列表中投料重量
  588. setInterval(() => {
  589. let dzcshuju = $("#dzcshuju").text();
  590. for (let i = 0; i < $('.tablestr').length; i++) {
  591. const dom = $('.tablestr')[i];
  592. const val = $(dom).children().eq(0).children().eq(0).val();
  593. const table_tlzl = $(dom).children().eq(2).children().eq(0).val();
  594. const status = $(dom).children().eq(4).children().eq(0).text();
  595. //按钮状态是未保存(是保存按钮的时候)并且 表格物料 == 扫描的物料
  596. if (status === '保存' && val == wuliao) {
  597. $(dom).children().eq(3).children().eq(0).val(dzcshuju);
  598. break;
  599. }
  600. }
  601. }, 1000); // 每秒检查一次
  602. // if (trzl === '') {
  603. // console.log("投料重量为空");
  604. // var wuliao_msg = new SpeechSynthesisUtterance(wuliao + "投入重量为空");
  605. // window.speechSynthesis.speak(wuliao_msg);
  606. // // 这里不应该有 return false; 因为它会导致函数退出
  607. // }
  608. $('#input').html();
  609. $.ajax({
  610. method: "POST",
  611. url: "feeding/get_material",
  612. data: {
  613. bach: $("#c-bach").val(),
  614. material: wuliao
  615. },
  616. success(data) {
  617. console.log(data)
  618. if (data.total > 0) {
  619. if (wuliao.length < 7) {
  620. $('#input').css('font-size', '60px');
  621. } else {
  622. $('#input').css('font-size', '25px');
  623. }
  624. console.log(11111)
  625. wuliao = data.string;
  626. $('#input').html(wuliao);
  627. for (var i = 0; i < result.data.length; i++) {
  628. for (var j = 0; j < data.data.length; j++) {
  629. //扫描的物料=table中的物料,,,变红,否则语音提示
  630. if (result.data[i].material === data.data[j].m_name && (result.data[i].weight === 0 || result.data[i].weight == '')) {
  631. if (result.data[i].gy_num <= result.process) {
  632. console.log(wuliao+"中文文字变红")
  633. //投料重量为空时 扫描物料文字为红
  634. if (result.data[i].weight == 0 || result.data[i].weight == '') {
  635. $(".material")[i].setAttribute('style', 'color:red');
  636. $(".nweight")[i].setAttribute('style', 'color:red');
  637. }
  638. // 扫描物料保存
  639. let ytzl = $("#ytzl").text().trim(); // 应投重量
  640. let trzl = $("#dzcshuju").text().trim(); // 投入重量
  641. // 遍历表格行
  642. const dom = $('.tablestr')[i];
  643. console.log(dom)
  644. //原材料
  645. const val = $(dom).find('td:eq(0) input').val();
  646. //应投重量
  647. const table_ytzl = $(dom).find('td:eq(1) input').val();
  648. //投料重量
  649. const table_tlzl = $(dom).find('td:eq(2) input').val();
  650. //按钮
  651. const status_button = $(dom).find('td:eq(4) button').text();
  652. console.log(wuliao)
  653. console.log(data.data[j].m_name)
  654. //扫描物料等于表格中物料 并且 未保存
  655. if (status_button === '保存' && (val === wuliao || data.data[j].m_name === wuliao)) {
  656. console.log(9999)
  657. if (ytzl === '' && trzl === '' || ytzl && trzl === '') {
  658. console.log(9898)
  659. $("#input").text(wuliao);
  660. $("#ytzl").text(table_ytzl);
  661. $("#wuliao").val('');
  662. $("#wuliao").focus();
  663. var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + wuliao + "应投入重量" + table_ytzl + "千克");
  664. window.speechSynthesis.speak(wuliao_msg);
  665. } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === wuliao) {
  666. console.log("保存了");
  667. $(dom).find('td:eq(4) button').click();
  668. $("#dzcshuju").text('');
  669. $("#ytzl").text('');
  670. $("#wuliao").val('');
  671. $("#wuliao").focus();
  672. //扫描物料语音播报
  673. var wuliao_msg = new SpeechSynthesisUtterance("已保存");
  674. window.speechSynthesis.speak(wuliao_msg);
  675. }
  676. break; // 退出循环
  677. } else if (status_button === '已保存' && val === wuliao) {
  678. // 扫描的物料保存过了,清空【应投重量,投入重量】
  679. $("#ytzl").text('');
  680. $("#dzcshuju").text('');
  681. var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + wuliao + "已投料");
  682. window.speechSynthesis.speak(wuliao_msg);
  683. $("#wuliao").val('');
  684. $("#wuliao").focus();
  685. break; // 退出循环
  686. }
  687. // var the_bach = document.getElementsByClassName('bach')[i];
  688. // if (the_bach.readOnly == false) {
  689. // the_bach.value = bach;
  690. // //语音播报
  691. // var msg = new SpeechSynthesisUtterance("应投入物料" + result.data[i].material + "应投入重量" + result.data[i].nweight + "千克");
  692. // window.speechSynthesis.speak(msg);
  693. // }
  694. // error++;
  695. } else if (result.data[i].gy_num > result.process) {
  696. Layer.confirm("此物料不在当前工序,请确认!", {
  697. area: ['60%', '60%'],
  698. });
  699. //语音播报
  700. var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
  701. window.speechSynthesis.speak(msg);
  702. error++;
  703. }
  704. }
  705. //替代料变扫描的物料
  706. if (result.data[i].material.indexOf('/') !== -1) {
  707. var arr = result.data[i].material.split('/');
  708. if (arr.indexOf($("#wuliao").val()) !== -1 && result.data[i].gy_num == result.process) {
  709. $(".material")[i].value = wuliao;
  710. if (result.data[i].weight == 0) {
  711. $(".material")[i].setAttribute('style', 'color:red');
  712. $(".nweight")[i].setAttribute('style', 'color:red');
  713. }
  714. var the_bach = document.getElementsByClassName('bach')[i];
  715. the_bach.value = bach;
  716. $(".number")[i].focus();
  717. error++;
  718. } else if (arr.indexOf($("#wuliao").val()) !== -1) {
  719. Layer.confirm("此物料不在当前工序,请确认!", {
  720. area: ['60%', '60%'],
  721. });
  722. //语音播报
  723. var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
  724. window.speechSynthesis.speak(msg);
  725. error++;
  726. }
  727. }
  728. }
  729. }
  730. // if (error === 0) {
  731. // layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息
  732. // title: ['信息'],
  733. // btn: ['确认'],
  734. // area: ['60%', '60%'],
  735. // });
  736. // var synth = window.speechSynthesis;
  737. // var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!');
  738. // window.speechSynthesis.cancel();
  739. // synth.speak(msg);
  740. // }
  741. } else {
  742. console.log(222)
  743. //没有在数据库查到,直接去比较物料与配方
  744. if (wuliao.length < 7) {
  745. $('#input').css('font-size', '52px');
  746. } else {
  747. $('#input').css('font-size', '25px');
  748. }
  749. $('#input').html(wuliao);
  750. console.log(result)
  751. for (var i = 0; i < result.data.length; i++) {
  752. //扫描的物料=table中的物料,,,变红,否则语音提示
  753. if (result.data[i].material === wuliao && (result.data[i].weight === 0 || result.data[i].weight == '')) {
  754. if (result.data[i].gy_num <= result.process) {
  755. if (result.data[i].weight == 0 || result.data[i].weight == '') {
  756. console.log('扫描的物料 : '+wuliao+ '红色')
  757. //原材料、应投重量文字颜色
  758. $(".material")[i].setAttribute('style', 'color:red');
  759. $(".nweight")[i].setAttribute('style', 'color:red');
  760. }
  761. // 扫描物料保存
  762. let ytzl = $("#ytzl").text().trim(); // 应投重量
  763. let trzl = $("#dzcshuju").text().trim(); // 投入重量
  764. // 遍历表格行
  765. const dom = $('.tablestr')[i];
  766. console.log(dom)
  767. //原材料
  768. const val = $(dom).find('td:eq(0) input').val();
  769. //应投重量
  770. const table_ytzl = $(dom).find('td:eq(1) input').val();
  771. //投料重量
  772. const table_tlzl = $(dom).find('td:eq(2) input').val();
  773. //按钮
  774. const status_button = $(dom).find('td:eq(4) button').text();
  775. //扫描物料等于表格中物料 并且 未保存
  776. if (status_button === '保存' && val === wuliao) {
  777. if (ytzl === '' && trzl === '' || ytzl && trzl === '') {
  778. $("#input").text(wuliao);
  779. $("#ytzl").text(table_ytzl);
  780. $("#wuliao").val('');
  781. $("#wuliao").focus();
  782. var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + wuliao + "应投入重量" + table_ytzl + "千克");
  783. window.speechSynthesis.speak(wuliao_msg);
  784. } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === wuliao) {
  785. console.log("保存了");
  786. $(dom).find('td:eq(4) button').click();
  787. $("#dzcshuju").text('');
  788. $("#ytzl").text('');
  789. $("#wuliao").val('');
  790. $("#wuliao").focus();
  791. //扫描物料语音播报
  792. var wuliao_msg = new SpeechSynthesisUtterance("已保存");
  793. window.speechSynthesis.speak(wuliao_msg);
  794. }
  795. break; // 退出循环
  796. } else if (status_button === '已保存' && val === wuliao) {
  797. // 扫描的物料保存过了,清空【应投重量,投入重量】
  798. $("#ytzl").text('');
  799. $("#dzcshuju").text('');
  800. var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + wuliao + "已投料");
  801. window.speechSynthesis.speak(wuliao_msg);
  802. $("#wuliao").val('');
  803. $("#wuliao").focus();
  804. break; // 退出循环
  805. }
  806. // var the_bach = document.getElementsByClassName('bach')[i];
  807. // if (the_bach.readOnly == false) {
  808. // the_bach.value = bach;
  809. // //语音播报
  810. // if($("#ytzl").text() !== ''){
  811. // var ytzl_msg = new SpeechSynthesisUtterance("应投入重量" + result.data[i].nweight + "千克");
  812. // window.speechSynthesis.speak(ytzl_msg);
  813. // }
  814. // }
  815. error++;
  816. break;
  817. } else if (result.data[i].gy_num > result.process) {
  818. Layer.confirm( wuliao + "此物料不在当前工序,请确认!", {
  819. area: ['70%', '60%'],
  820. });
  821. $("#ytzl").text('');
  822. $("#wuliao").val('');
  823. $("#wuliao").focus();
  824. //语音播报
  825. var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
  826. window.speechSynthesis.speak(msg);
  827. error++;
  828. break;
  829. }
  830. }
  831. //替代料变扫描的物料
  832. if (result.data[i].material.indexOf('/') !== -1) {
  833. var arr = result.data[i].material.split('/');
  834. var spanValue = document.getElementById("input").innerHTML;
  835. if (arr.indexOf(spanValue) !== -1 && result.data[i].gy_num <= result.process) {
  836. $(".material")[i].value = wuliao;
  837. if (result.data[i].weight == 0) {
  838. $(".material")[i].setAttribute('style', 'color:red');
  839. $(".nweight")[i].setAttribute('style', 'color:red');
  840. }
  841. // 扫描物料保存
  842. let ytzl = $("#ytzl").text().trim(); // 应投重量
  843. let trzl = $("#dzcshuju").text().trim(); // 投入重量
  844. // 遍历表格行
  845. // for (let i = 0; i < $('.tablestr').length; i++) {
  846. const dom = $('.tablestr')[i];
  847. //原材料
  848. const val = $(dom).find('td:eq(0) input').val();
  849. //应投重量
  850. const table_ytzl = $(dom).find('td:eq(1) input').val();
  851. //投料重量
  852. const table_tlzl = $(dom).find('td:eq(2) input').val();
  853. //按钮
  854. const status_button = $(dom).find('td:eq(4) button').text();
  855. //扫描物料等于表格中物料 并且 未保存
  856. if (status_button === '保存' && val === wuliao) {
  857. if (ytzl === '' && trzl === '' || ytzl && trzl === '') {
  858. $("#input").text(wuliao);
  859. $("#ytzl").text(table_ytzl);
  860. $("#wuliao").val('');
  861. $("#wuliao").focus();
  862. var wuliao_msg = new SpeechSynthesisUtterance("当前扫描物料" + wuliao + "应投入重量" + table_ytzl + "千克");
  863. window.speechSynthesis.speak(wuliao_msg);
  864. } else if (table_tlzl !== '' && trzl !== '' && status_button === '保存' && val === wuliao) {
  865. console.log("保存了");
  866. $(dom).find('td:eq(4) button').click();
  867. $("#dzcshuju").text('');
  868. $("#ytzl").text('');
  869. $("#wuliao").val('');
  870. $("#wuliao").focus();
  871. //扫描物料语音播报
  872. var wuliao_msg = new SpeechSynthesisUtterance("已保存");
  873. window.speechSynthesis.speak(wuliao_msg);
  874. }
  875. break; // 退出循环
  876. } else if (status_button === '已保存' && val === wuliao) {
  877. // 扫描的物料保存过了,清空【应投重量,投入重量】
  878. $("#ytzl").text('');
  879. $("#dzcshuju").text('');
  880. var wuliao_msg = new SpeechSynthesisUtterance("当前扫描" + wuliao + "已投料");
  881. window.speechSynthesis.speak(wuliao_msg);
  882. $("#wuliao").val('');
  883. $("#wuliao").focus();
  884. break; // 退出循环
  885. }
  886. // }
  887. // var the_bach = document.getElementsByClassName('bach')[i];
  888. // if (the_bach.readOnly == false) {
  889. // the_bach.value = bach;
  890. // // $(".number")[i].focus();
  891. // console.log("替代料")
  892. // var msg = new SpeechSynthesisUtterance("应投入物料" + result.data[i].material + "应投入重量" + result.data[i].nweight + "千克");
  893. // window.speechSynthesis.speak(msg);
  894. // }
  895. // error++;
  896. // break;
  897. } else if (arr.indexOf($("#wuliao").val()) !== -1) {
  898. Layer.confirm("此物料不在当前工序,请确认!", {
  899. area: ['60%', '60%'],
  900. });
  901. //语音播报
  902. var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
  903. window.speechSynthesis.speak(msg);
  904. error++;
  905. break;
  906. }
  907. }
  908. }
  909. // if (error === 0) {
  910. // layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息
  911. // title: ['信息'],
  912. // btn: ['确认'],
  913. // area: ['60%', '60%'],
  914. // });
  915. // var synth = window.speechSynthesis;
  916. // //没有物料,清空应投重量
  917. // $("#ytzl").text('');
  918. // var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!');
  919. // window.speechSynthesis.cancel();
  920. // synth.speak(msg);
  921. // }
  922. }
  923. }
  924. });
  925. //清空物料扫描后的值,下次直接重新扫描即可
  926. $("#wuliao").val('');
  927. }
  928. });
  929. }
  930. });
  931. }
  932. }
  933. });
  934. num++;
  935. } else {
  936. // return false;
  937. }
  938. }
  939. });
  940. $(document).on('click', '.submit', function () {
  941. if ($("#c-operator").val() == "" || $("#c-inspector").val() == "") {
  942. layer.confirm('请选择 操作人员 或 检验人员', {title: '操作提示',btn: [],area: ['60%', '60%'],closeBtn: 0,time: 2000});
  943. //语音播报
  944. var msg = new SpeechSynthesisUtterance("请选择 操作人员 或 检验人员");
  945. window.speechSynthesis.speak(msg);
  946. } else {
  947. //批次号
  948. var bach = $("#c-bach").val();
  949. //日期
  950. var date = $("#c-date").val();
  951. //操作人员
  952. var operator = $("#c-operator").val();
  953. //检验人员
  954. var inspector = $("#c-inspector").val();
  955. //原材料
  956. var material = $(this).parent().siblings().eq(0).children('input').val();
  957. //应投重量
  958. var nweight = $(this).parent().siblings().eq(1).children('input').val();
  959. //工艺序号
  960. var gy_num = $(this).parent().siblings().eq(2).children('input').val();
  961. //投料重量
  962. var weight = $(this).parent().siblings().eq(3).children('input').val();
  963. //原材料批次号
  964. var material_bach = $(this).parent().siblings().eq(4).children('input').val();
  965. //操作记录
  966. var gy_name = $(this).parent().siblings().eq(5).children('input').val();
  967. // if(nweight != weight){
  968. // var num_weight = parseFloat((nweight - weight).toFixed(3));
  969. // console.log(num_weight)
  970. // var num_weight_msg = new SpeechSynthesisUtterance("投料重量与应投入重量相差" + num_weight + "请确认" );
  971. // window.speechSynthesis.speak(num_weight_msg);
  972. // return false;
  973. // }
  974. if (weight == "") {
  975. layer.confirm('投料重量不能为空', {
  976. title: '操作提示',
  977. btn: [],
  978. area: ['60%', '60%'],
  979. closeBtn: 0,
  980. time: 2000
  981. });
  982. //语音播报
  983. var msg = new SpeechSynthesisUtterance("投料重量不能为空");
  984. window.speechSynthesis.speak(msg);
  985. } else {
  986. $(this).text('已保存');
  987. $("#wuliao").focus();
  988. // $(this).text('修改');
  989. //禁用投料重量
  990. $(this).parent().siblings().eq(3).children('input').attr('readonly', true);
  991. // 禁用原材料批次号
  992. $(this).parent().siblings().eq(4).children('input').attr('readonly', true);
  993. $(this).attr('disabled', true);
  994. }
  995. // console.log(bach);
  996. // console.log(date);
  997. // console.log(operator);
  998. // console.log(inspector);
  999. // console.log(material);
  1000. // console.log(nweight);
  1001. // console.log(gy_num);
  1002. // console.log(weight);
  1003. // console.log(material_bach);
  1004. // console.log(gy_name);return false;
  1005. $.ajax({
  1006. type: "POST",
  1007. url: "feeding/add",
  1008. data: {
  1009. bach: bach,
  1010. date: date,
  1011. operator: operator,
  1012. inspector: inspector,
  1013. material: material,
  1014. nweight: nweight,
  1015. gy_num: gy_num,
  1016. weight: weight,
  1017. material_bach: material_bach,
  1018. gy_name: gy_name,
  1019. },
  1020. success: function (data) {
  1021. // console.log("ajax"+data);
  1022. if(data == '添加失败'){
  1023. //语音播报
  1024. var msg = new SpeechSynthesisUtterance("网络连接异常 请检查后重新添加");
  1025. window.speechSynthesis.speak(msg);
  1026. }
  1027. }
  1028. });
  1029. }
  1030. });
  1031. document.addEventListener('keydown', function(event) {
  1032. // console.log(event.key);
  1033. // 检查按下的键是否是回车键
  1034. if (event.key === 'Escape') {
  1035. //关闭弹窗
  1036. Fast.api.close();
  1037. }
  1038. });
  1039. $('input').keydown(function (e) {
  1040. let key = e.which;
  1041. if (key == 13) {
  1042. return false;
  1043. }
  1044. });
  1045. //打印预览
  1046. $(document).ready(function ($) {
  1047. 'use strict';
  1048. $(".print-link").on('click', function () {
  1049. var status = 1;
  1050. var total = 0;
  1051. var stotal = 0;
  1052. //开票人
  1053. $("#specifications").html($('#c-specifications').val());
  1054. //审核
  1055. $("#unit").html($('#c-unit').val());
  1056. //批次号
  1057. var bach = $('#c-bach').val();
  1058. //写入到add页面
  1059. $("#bach").html(bach);
  1060. $("#formula").val($("#name").val());
  1061. //添加重量,包装规格,机组到表格内
  1062. for (var i = 0; i < $(".tablestr").length; i++) {
  1063. var weight = parseFloat($(".tablestr:eq(" + i + ")").children("tr td:eq(3)").children().val());
  1064. if (weight) {
  1065. $(".print:eq(" + i + ")").children("tr td:eq(2)").html(weight);
  1066. total += weight;
  1067. }
  1068. var weight2 = parseFloat($(".tablestr:eq(" + i + ")").children("tr td:eq(1)").children().val());
  1069. if (weight2) {
  1070. $(".print:eq(" + i + ")").children("tr td:eq(1)").html(weight2);
  1071. stotal += weight2;
  1072. }
  1073. }
  1074. $("#stotal").html(stotal.toFixed(2));
  1075. if (total > 0) {
  1076. $("#total").html(total.toFixed(2));
  1077. }
  1078. if (!$("#c-pickor").val()) {
  1079. status = 2;
  1080. }
  1081. if (!$("#c-warehouseor").val()) {
  1082. status = 2;
  1083. }
  1084. /*if (status == 2){
  1085. layer.confirm('领料人或仓管人为空,请检查!');return false;
  1086. }*/
  1087. createQrcode(bach, 80, 80);
  1088. var img = document.getElementById("myImage"); /// get image element
  1089. var canvas = document.getElementsByTagName('canvas')[0];
  1090. img.src = canvas.toDataURL(); /// update image
  1091. $.print('#print_area');
  1092. return false;
  1093. });
  1094. function createQrcode(txt, width, height) {
  1095. $(".qrcode").qrcode({
  1096. render: "canvas",//canvas和table两种渲染方式
  1097. width: width,
  1098. height: height,
  1099. correctLevel: 3,//二维码纠错级别
  1100. background: "#ffffff",//背景颜色
  1101. foreground: "#000000", //二维码颜色
  1102. text: txt
  1103. });
  1104. }
  1105. });
  1106. Controller.api.bindevent();
  1107. },
  1108. edit: function () {
  1109. Controller.api.bindevent();
  1110. },
  1111. api: {
  1112. bindevent: function () {
  1113. Form.api.bindevent($("form[role=form]"));
  1114. }
  1115. }
  1116. };
  1117. return Controller;
  1118. });