product.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','jQuery.print'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-add").data("area",["100%","100%"]);
  5. $(".btn-edit").data("area",["100%","100%"]);
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'product/index' + location.search,
  10. add_url: 'product/add',
  11. edit_url: 'product/edit',
  12. del_url: 'product/del',
  13. multi_url: 'product/multi',
  14. import_url: 'product/import',
  15. table: 'product',
  16. }
  17. });
  18. var table = $("#table");
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'id',
  24. fixedColumns: true,
  25. fixedRightNumber: 1,
  26. columns: [
  27. [
  28. {checkbox: true},
  29. // {field: 'id', title: __('Id')},
  30. {field: 'batch', title: __('Batch'), operate: 'LIKE'},
  31. {field: 'pname', title: __('Pname'),operate: 'LIKE'},
  32. {field: 'specifications', title: __('Specifications'),operate: 'LIKE'},
  33. {field: 'audit', title: __('Audit'),operate: 'LIKE'},
  34. {field: 'unit', title: __('Unit'),operate: 'LIKE'},
  35. {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.normal},
  36. // {field: 'time', title: __('Time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  37. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
  38. {field: 'operate', title: '操作', buttons:[{
  39. name:'task',
  40. text:'查看',
  41. title:'查看',
  42. icon:'fa fa-add',
  43. extend: 'data-area=["100%","100%"]',
  44. classname:'btn btn-xs btn-info btn-fields btn-dialog ',
  45. url:'product/show',
  46. }],
  47. table: table,
  48. events: Table.api.events.operate, formatter: Table.api.formatter.operate
  49. },
  50. ]
  51. ]
  52. });
  53. table.on('post-body.bs.table',function(){
  54. $(".btn-editone").data("area",["100%","100%"]);
  55. });
  56. // 为表格绑定事件
  57. Table.api.bindevent(table);
  58. },
  59. add: function () {
  60. //扫描批次号
  61. $("#c-batch").keydown(function(e){
  62. var key = e.which;
  63. if (key == 13) {
  64. $.ajax({
  65. type:"POST",
  66. url:"product/ajax",
  67. data:{
  68. bach:$("#c-batch").val()
  69. },
  70. //获取头部信息
  71. success(res){
  72. $("#c-batch").val($("#c-batch").val()+';');
  73. $("#c-time").val(res.create);
  74. $("#c-audit").val(res.examine_name);
  75. $("#c-pname").val(res.name);
  76. var str = '';
  77. str += "<input class='form-control' type='hidden' name='row[audit][]' value='"+$("#c-audit").val()+"'>";
  78. str += "<input class='form-control' type='hidden' name='row[proname][]' value='"+$("#c-pname").val()+"'>";
  79. str += "<input class='form-control' type='hidden' name='row[unit][]' value='"+$("#c-unit").val()+"'>";
  80. $("#table").append(str);
  81. }
  82. });
  83. return false;
  84. }
  85. });
  86. var i=0;
  87. //扫描物料
  88. $("#wuliao").keydown( function (e) {
  89. var key = e.which;
  90. if (key == 13) {
  91. var str = '';
  92. var html = '';
  93. $.ajax({
  94. type: "POST",
  95. url: "product/get_formula",
  96. data: {
  97. formula: $("#wuliao").val(),
  98. },
  99. //扫描一个物料添加一行表格
  100. success(res) {
  101. str += "<tr class='tablestr"+i+" tablestr'><td><input class='form-control' type='text' name='row[batch][]' readonly value='"+res.bach+"'></td>";
  102. str += "<td><input class='form-control' type='text' name='row[pname][]' readonly value='"+res.pname+"'></td>";
  103. str += "<td><input class='form-control' type='text' name='row[material][]' readonly value='"+res.material+"'></td>";
  104. str += "<td><input class='form-control' type='number' name='row[weight][]' data-rule='required' value=''></td>";
  105. str += "<td><input class='form-control' type='text' name='row[specifications][]' value='"+ (res.specifications?res.specifications:'')+"'></td>";
  106. str += "<td><input class='form-control' type='text' name='row[unit][]' value=''></td>";
  107. str += "<td><input class='form-control' type='text' name='row[time][]' readonly value='"+res.time+"'></td>";
  108. str += "<input type='hidden' value='"+i+"'>";
  109. str += '<td><button type="button" class="btn btn-danger del">删除</button></td></tr>';
  110. //添加打印表格
  111. html += ` <tr class="print${i} print">
  112. <td>${res.bach}</td>
  113. <td>${res.pname}</td>
  114. <td>${res.material}</td>
  115. <td></td>
  116. <td>${res.specifications}</td>
  117. <td></td>
  118. </tr>`;
  119. //写入页面
  120. $("#table").append(str);
  121. $("#print_gy").append(html);
  122. //清空物料扫描后的值,下次直接重新扫描即可
  123. $("#wuliao").val('');
  124. if($("#status").val()==1){
  125. if(res.error === 1){
  126. // Layer.confirm("此物料不在配方中,请确认!");
  127. layer.confirm("此物料不在配方中,请确认!", {//物料不存在提示错误信息
  128. title: ['信息'],
  129. btn: ['确认', '取消'],
  130. area: ['60%', '60%'],
  131. },function(index) {//点击确定正常执行
  132. layer.close(index);
  133. },function(){//点击取消删除添加的最后一个元素
  134. $("#table tr:last").remove();
  135. });
  136. var synth = window.speechSynthesis;
  137. var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,请确认!');
  138. window.speechSynthesis.cancel();
  139. synth.speak(msg);
  140. //语音播报
  141. // var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
  142. // window.speechSynthesis.speak(msg);
  143. }
  144. }
  145. i++;
  146. }
  147. });
  148. return false;
  149. }
  150. });
  151. //删除当前行内容及打印表格当前行内容
  152. $(document).on('click','.del',function () {
  153. $(this).parent().parent().remove();
  154. var i = $(this).parent().prev().val();
  155. $(".print"+i).remove();
  156. });
  157. //阻止回车事件
  158. $('input').keydown( function (e) {
  159. let key = e.which;
  160. if (key == 13) {
  161. return false;
  162. }
  163. });
  164. Controller.api.bindevent();
  165. //打印
  166. $(document).ready(function($) { 'use strict';
  167. $(".print-link").on('click', function() {
  168. var status = 1;
  169. //领料人
  170. $("#pickor").html($('#c-pickor').val());
  171. //仓管人
  172. $("#warehouseor").html($('#c-warehouseor').val());
  173. //批次
  174. var bach = $('#c-batch').val();
  175. //写入到add页面
  176. $("#formula").html(bach);
  177. //添加重量,包装规格,机组到表格内
  178. for(var i=0;i<$(".tablestr").length;i++){
  179. var weight = $(".tablestr:eq("+i+")").children("tr td:eq(3)").children().val();
  180. var specifications = $(".tablestr:eq("+i+")").children("tr td:eq(4)").children().val();
  181. var unit = $(".tablestr:eq("+i+")").children("tr td:eq(5)").children().val();
  182. $(".print:eq("+i+")").children("tr td:eq(3)").html(weight);
  183. $(".print:eq("+i+")").children("tr td:eq(4)").html(specifications);
  184. $(".print:eq("+i+")").children("tr td:eq(5)").html(unit);
  185. }
  186. if(!$("#c-pickor").val()){
  187. status = 2;
  188. }
  189. if(!$("#c-warehouseor").val()){
  190. status = 2;
  191. }
  192. if (status == 2){
  193. // layer.confirm('领料人或仓管人为空,请检查!');
  194. layer.confirm("领料人或仓管人为空,请检查!",{//物料不存在提示错误信息
  195. title:['信息'],
  196. area:['60%','60%'],
  197. });
  198. return false;
  199. }
  200. // createQrcode(bach,80,80);
  201. var img = document.getElementById("myImage"); /// get image element
  202. var canvas = document.getElementsByTagName('canvas')[0];
  203. // img.src = canvas.toDataURL(); /// update image
  204. $.print('#print_area');
  205. return false;
  206. });
  207. function createQrcode(txt,width,height) {
  208. $("#qrcode").qrcode({
  209. render: "canvas",//canvas和table两种渲染方式
  210. width: width,
  211. height: height,
  212. correctLevel:3,//二维码纠错级别
  213. background:"#ffffff",//背景颜色
  214. foreground:"#000000", //二维码颜色
  215. text:txt
  216. });
  217. }
  218. });
  219. },
  220. edit: function () {
  221. Controller.api.bindevent();
  222. },
  223. api: {
  224. bindevent: function () {
  225. Form.api.bindevent($("form[role=form]"));
  226. }
  227. },
  228. };
  229. return Controller;
  230. });