product.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: '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. $("#c-batch").keydown(function(e){
  61. var key = e.which;
  62. if (key == 13) {
  63. $.ajax({
  64. type:"POST",
  65. url:"product/ajax",
  66. data:{
  67. bach:$("#c-batch").val()
  68. },
  69. success(res){
  70. $("#c-batch").val($("#c-batch").val()+';');
  71. $("#c-time").val(res.create);
  72. $("#c-audit").val(res.examine_name);
  73. $("#c-pname").val(res.name);
  74. var str = '';
  75. str += "<input class='form-control' type='hidden' name='row[audit][]' value='"+$("#c-audit").val()+"'>";
  76. str += "<input class='form-control' type='hidden' name='row[proname][]' value='"+$("#c-pname").val()+"'>";
  77. str += "<input class='form-control' type='hidden' name='row[unit][]' value='"+$("#c-unit").val()+"'>";
  78. $("#table").append(str);
  79. }
  80. });
  81. return false;
  82. }
  83. });
  84. $("#wuliao").keydown( function (e) {
  85. var key = e.which;
  86. if (key == 13) {
  87. var str = '';
  88. $.ajax({
  89. type: "POST",
  90. url: "product/get_formula",
  91. data: {
  92. formula: $("#wuliao").val(),
  93. },
  94. success(res) {
  95. str += "<tr><td><input class='form-control' type='text' name='row[batch][]' readonly value='"+res.bach+"'></td>";
  96. str += "<td><input class='form-control' type='text' name='row[pname][]' readonly value='"+res.pname+"'></td>";
  97. str += "<td><input class='form-control' type='text' name='row[material][]' readonly value='"+res.material+"'></td>";
  98. str += "<td><input class='form-control' type='text' name='row[specifications][]' value='"+ (res.specifications?res.specifications:'')+"'></td>";
  99. str += "<td><input class='form-control' type='number' name='row[weight][]' data-rule='required' value=''></td>";
  100. str += "<td><input class='form-control' type='text' name='row[unit][]' value=''></td>";
  101. str += "<td><input class='form-control' type='text' name='row[time][]' readonly value='"+res.time+"'></td>";
  102. str += '<td><button type="button" class="btn btn-danger del">删除</button></td></tr>';
  103. $("#table").append(str);
  104. $("#wuliao").val('');
  105. if($("#status").val()==1){
  106. if(res.error === 1){
  107. Layer.confirm("此物料不在配方中,请确认!");
  108. //语音播报
  109. var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
  110. window.speechSynthesis.speak(msg);
  111. }
  112. }
  113. }
  114. });
  115. return false;
  116. }
  117. });
  118. $(document).on('click','.del',function () {
  119. $(this).parent().parent().remove();
  120. });
  121. $('input').keydown( function (e) {
  122. let key = e.which;
  123. if (key == 13) {
  124. return false;
  125. }
  126. });
  127. Controller.api.bindevent();
  128. },
  129. edit: function () {
  130. Controller.api.bindevent();
  131. },
  132. api: {
  133. bindevent: function () {
  134. Form.api.bindevent($("form[role=form]"));
  135. }
  136. },
  137. };
  138. return Controller;
  139. });