product.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. window.i=0;
  87. var i=0;
  88. //扫描物料
  89. $("#wuliao").keydown( function (e) {
  90. var key = e.which;
  91. if (key == 13) {
  92. var str = '';
  93. var html = '';
  94. $.ajax({
  95. type: "POST",
  96. url: "product/get_formula",
  97. data: {
  98. formula: $("#wuliao").val(),
  99. bach:$("#c-batch").val()
  100. },
  101. //扫描一个物料添加一行表格
  102. success(res) {
  103. str += "<tr class='tablestr"+i+" tablestr'><td><input class='form-control' type='text' name='row[batch][]' readonly value='"+res.bach+"'></td>";
  104. str += "<td><input class='form-control' type='text' name='row[pname][]' readonly value='"+res.pname+"'></td>";
  105. str += "<td><input class='form-control' type='text' name='row[material][]' readonly value='"+res.material+"'></td>";
  106. // str += "<td><input class='form-control' type='number' name='row[weight][]' data-rule='required' value=''></td>";
  107. // str += "<td><input class='form-control' type='text' name='row[specifications][]' value='"+ (res.specifications?res.specifications:'')+"'></td>";
  108. str += "<td><input class='form-control' type='text' name='row[unit][]' value=''></td>";
  109. str += "<td><input class='form-control' type='text' name='row[time][]' readonly value='"+res.time+"'></td>";
  110. str += "<input type='hidden' value='"+i+"'>";
  111. str += '<td><button type="button" class="btn btn-danger del">删除</button></td></tr>';
  112. //添加打印表格
  113. html += ` <tr class="print${i} print">
  114. <td>${res.bach}</td>
  115. <td>${res.pname}</td>
  116. <td>${res.material}</td>
  117. <td></td>
  118. <!--<td>${res.specifications}</td>-->
  119. <!--<td></td>-->
  120. </tr>`;
  121. //写入页面
  122. $("#print_gy").append(html);
  123. $("#table").append(str);
  124. // $("#print_gy").append(html);
  125. //清空物料扫描后的值,下次直接重新扫描即可
  126. $("#wuliao").val('');
  127. if($("#status").val()==1){
  128. if(res.error === 1){
  129. // Layer.confirm("此物料不在配方中,请确认!");
  130. layer.confirm("此物料不在配方中,请确认!", { //物料不存在提示错误信息
  131. title: ['信息'],
  132. btn: ['确认', '取消'],
  133. area: ['60%', '60%'],
  134. },function(index) { //点击确定写入打印页面
  135. layer.close(index);
  136. },function(){ //点击取消删除添加的最后一个元素
  137. $("#table tr:last").remove();
  138. $("#print_gy tr:last").remove();
  139. });
  140. //语音播报
  141. var synth = window.speechSynthesis;
  142. var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,请确认!');
  143. window.speechSynthesis.cancel();
  144. synth.speak(msg);
  145. }
  146. }
  147. i++;
  148. }
  149. });
  150. return false;
  151. }
  152. });
  153. //删除当前行内容及打印表格当前行内容
  154. $(document).on('click','.del',function () {
  155. $(this).parent().parent().remove();
  156. var i = $(this).parent().prev().val();
  157. $(".print"+i).remove();
  158. });
  159. //阻止回车事件
  160. $('input').keydown( function (e) {
  161. let key = e.which;
  162. if (key == 13) {
  163. return false;
  164. }
  165. });
  166. Controller.api.bindevent();
  167. //打印
  168. $(document).ready(function($) { 'use strict';
  169. $(".print-link").on('click', function() {
  170. var status = 1;
  171. //领料人
  172. $("#pickor").html($('#c-pickor').val());
  173. //仓管人
  174. $("#warehouseor").html($('#c-warehouseor').val());
  175. //批次
  176. var bach = $('#c-batch').val();
  177. //写入到add页面
  178. $("#formula").html(bach);
  179. //添加重量,包装规格,机组到表格内
  180. for(var i=0;i<$(".tablestr").length;i++){
  181. var weight = $(".tablestr:eq("+i+")").children("tr td:eq(3)").children().val();
  182. var specifications = $(".tablestr:eq("+i+")").children("tr td:eq(4)").children().val();
  183. var unit = $(".tablestr:eq("+i+")").children("tr td:eq(5)").children().val();
  184. // $(".print:eq("+i+")").children("tr td:eq(3)").html(weight);
  185. // $(".print:eq("+i+")").children("tr td:eq(4)").html(specifications);
  186. $(".print:eq("+i+")").children("tr td:eq(5)").html(unit);
  187. }
  188. if(!$("#c-pickor").val()){
  189. status = 2;
  190. }
  191. if(!$("#c-warehouseor").val()){
  192. status = 2;
  193. }
  194. if (status == 2){
  195. // layer.confirm('领料人或仓管人为空,请检查!');
  196. layer.confirm("领料人或仓管人为空,请检查!",{//物料不存在提示错误信息
  197. title:['信息'],
  198. area:['60%','60%'],
  199. });
  200. return false;
  201. }
  202. // createQrcode(bach,80,80);
  203. var img = document.getElementById("myImage"); /// get image element
  204. var canvas = document.getElementsByTagName('canvas')[0];
  205. // img.src = canvas.toDataURL(); /// update image
  206. $.print('#print_area');
  207. return false;
  208. });
  209. function createQrcode(txt,width,height) {
  210. $("#qrcode").qrcode({
  211. render: "canvas",//canvas和table两种渲染方式
  212. width: width,
  213. height: height,
  214. correctLevel:3,//二维码纠错级别
  215. background:"#ffffff",//背景颜色
  216. foreground:"#000000", //二维码颜色
  217. text:txt
  218. });
  219. }
  220. });
  221. },
  222. edit: function () {
  223. Controller.api.bindevent();
  224. },
  225. api: {
  226. bindevent: function () {
  227. Form.api.bindevent($("form[role=form]"));
  228. }
  229. },
  230. };
  231. return Controller;
  232. });