product.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: 'height', title: __('Height'),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-time").val(res.create);
  56. $("#c-audit").val(res.examine_name);
  57. $("#c-pname").val(res.name);
  58. }
  59. });
  60. return false;
  61. }
  62. });
  63. $("#wuliao").keydown( function (e) {
  64. var key = e.which;
  65. if (key == 13) {
  66. var str = '';
  67. $.ajax({
  68. type: "POST",
  69. url: "product/get_formula",
  70. data: {
  71. formula: $("#wuliao").val(),
  72. },
  73. success(res) {
  74. str += "<tr><td><input class='form-control' type='text' name='row[material][]' readonly value='"+res.material+"'></td>";
  75. str += "<td><input class='form-control' type='number' name='row[height][]' data-rule='required' value=''></td>";
  76. str += "<td><input class='form-control' type='text' name='row[time][]' readonly value='"+res.time+"'></td>";
  77. str += '<td><button type="button" class="btn btn-danger del">删除</button></td></tr>';
  78. $("#table").append(str);
  79. $("#wuliao").val('');
  80. if(res.error === 1){
  81. Layer.confirm("此物料不在配方中,请确认!");
  82. //语音播报
  83. var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
  84. window.speechSynthesis.speak(msg);
  85. }
  86. }
  87. });
  88. return false;
  89. }
  90. });
  91. $(document).on('click','.del',function () {
  92. $(this).parent().parent().remove();
  93. });
  94. $('input').keydown( function (e) {
  95. let key = e.which;
  96. if (key == 13) {
  97. return false;
  98. }
  99. });
  100. /**
  101. * 播报
  102. * @param {Object} text 播放内容
  103. */
  104. startSpeech = (text)=>{
  105. const speech = new SpeechSynthesisUtterance()
  106. // 设置播放内容
  107. speech.text = text
  108. // 设置话语的音调(0-2 默认1,值越大越尖锐,越低越低沉)
  109. speech.pitch = 0.8
  110. // 设置说话的速度(0.1-10 默认1,值越大语速越快,越小语速越慢)
  111. speech.rate = 1
  112. // 设置说话的音量
  113. speech.volume = 10
  114. // 设置播放语言
  115. speech.lang = 'zh-CN'
  116. // 播放结束后调用
  117. speech.onend = (event)=>{
  118. }
  119. // 加入播放队列
  120. window.speechSynthesis.speak(speech);
  121. };
  122. /**
  123. * 停止播报,停止所有播报队列里面的语音
  124. */
  125. stopSpeech = () => {
  126. window.speechSynthesis.cancel();
  127. };
  128. Controller.api.bindevent();
  129. },
  130. edit: function () {
  131. Controller.api.bindevent();
  132. },
  133. api: {
  134. bindevent: function () {
  135. Form.api.bindevent($("form[role=form]"));
  136. }
  137. },
  138. };
  139. return Controller;
  140. });