product.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], 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: 'material', title: __('Material'), operate: 'LIKE'},
  31. {field: 'weight', title: __('Weight'),operate: 'LIKE'},
  32. {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.normal},
  33. {field: 'time', title: __('Time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  34. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  35. ]
  36. ]
  37. });
  38. table.on('post-body.bs.table',function(){
  39. $(".btn-editone").data("area",["100%","100%"]);
  40. });
  41. // 为表格绑定事件
  42. Table.api.bindevent(table);
  43. },
  44. add: function () {
  45. $("#c-batch").keydown(function(e){
  46. var key = e.which;
  47. if (key == 13) {
  48. $.ajax({
  49. type:"POST",
  50. url:"product/ajax",
  51. data:{
  52. bach:$("#c-batch").val()
  53. },
  54. success(res){
  55. $("#c-batch").val($("#c-batch").val()+';');
  56. $("#c-time").val(res.create);
  57. $("#c-audit").val(res.examine_name);
  58. $("#c-pname").val(res.name);
  59. }
  60. });
  61. return false;
  62. }
  63. });
  64. $("#wuliao").keydown( function (e) {
  65. var key = e.which;
  66. if (key == 13) {
  67. var str = '';
  68. $.ajax({
  69. type: "POST",
  70. url: "product/get_formula",
  71. data: {
  72. formula: $("#wuliao").val(),
  73. },
  74. success(res) {
  75. str += "<tr><td><input class='form-control' type='text' name='row[batch][]' readonly value='"+res.bach+"'></td>";
  76. str += "<td><input class='form-control' type='text' name='row[pname][]' readonly value='"+res.pname+"'></td>";
  77. str += "<td><input class='form-control' type='text' name='row[material][]' readonly value='"+res.material+"'></td>";
  78. str += "<td><input class='form-control' type='text' name='row[specifications][]' value='"+ (res.specifications?res.specifications:'')+"'></td>";
  79. str += "<td><input class='form-control' type='number' name='row[weight][]' data-rule='required' value=''></td>";
  80. str += "<td><input class='form-control' type='text' name='row[unit][]' value=''></td>";
  81. str += "<td><input class='form-control' type='text' name='row[time][]' readonly value='"+res.time+"'></td>";
  82. str += '<td><button type="button" class="btn btn-danger del">删除</button></td></tr>';
  83. $("#table").append(str);
  84. $("#wuliao").val('');
  85. if($("#status").val()==1){
  86. if(res.error === 1){
  87. Layer.confirm("此物料不在配方中,请确认!");
  88. //语音播报
  89. var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
  90. window.speechSynthesis.speak(msg);
  91. }
  92. }
  93. }
  94. });
  95. return false;
  96. }
  97. });
  98. $(document).on('click','.del',function () {
  99. $(this).parent().parent().remove();
  100. });
  101. $('input').keydown( function (e) {
  102. let key = e.which;
  103. if (key == 13) {
  104. return false;
  105. }
  106. });
  107. Controller.api.bindevent();
  108. },
  109. edit: function () {
  110. Controller.api.bindevent();
  111. },
  112. api: {
  113. bindevent: function () {
  114. Form.api.bindevent($("form[role=form]"));
  115. }
  116. },
  117. };
  118. return Controller;
  119. });