stock.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'stock/index' + location.search,
  8. add_url: 'stock/add',
  9. edit_url: 'stock/edit',
  10. del_url: 'stock/del',
  11. multi_url: 'stock/multi',
  12. import_url: 'stock/import',
  13. table: 'stock',
  14. }
  15. });
  16. var table = $("#table");//index.html table的id
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. rowStyle:Controller.api.rowStyle,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id')},
  27. {field: 'name', title: __('Name'), operate: 'LIKE'},
  28. {field: 'unit', title: __('Unit'), operate: 'LIKE'},
  29. {field: 'number', title: __('Number'), operate: 'LIKE'},
  30. {field: 'l_number', title: __('L_number'), operate: 'LIKE'},
  31. {field: 'specs', title: __('Specs'), operate: 'LIKE'},
  32. // {field: 'company_id', title: __('Company_id')},
  33. {field: 'create', title: __('Create'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  34. {field: 'update', title: __('Update'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  35. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. var ref = setInterval(function(){ //定时刷新
  42. $.ajax({
  43. type: "POST",
  44. url: "order/stockad",
  45. success(res) {//根据订单管理返回的值为1代表有新增数据订单
  46. if (res == 1) {
  47. window.clearInterval(ref);//停止刷新
  48. layer.confirm("您好,来新订单了!", {
  49. title: ['信息'],
  50. btn: ['确认'],
  51. area: ['60%', '60%'],
  52. },function(index) { //点击处理停止语音播报
  53. setInterval(fn,3000);
  54. jQuery.ajax({
  55. type: "post",
  56. url: "stock/orderstu",
  57. data: {orderstu:2},
  58. success: function(data){//成功回调函数
  59. if(data='处理成功'){
  60. location.reload();//刷新本页面
  61. }
  62. layer.close(index);//点击确定关闭弹窗
  63. },
  64. error: function(){ //失败返回调用
  65. alert("网络异常!");
  66. }
  67. });
  68. });
  69. var fn = function(){//有订单弹出提示框并且语音播报
  70. var synth = window.speechSynthesis;
  71. var msg = new window.SpeechSynthesisUtterance('您好,来新订单了!');
  72. window.speechSynthesis.cancel();
  73. synth.speak(msg);
  74. };
  75. setInterval(fn,5000);//多久播一次
  76. }
  77. }
  78. });
  79. },10000);//10000 十秒
  80. },
  81. add: function () {
  82. Controller.api.bindevent();
  83. },
  84. edit: function () {
  85. Controller.api.bindevent();
  86. },
  87. api: {
  88. bindevent: function () {
  89. Form.api.bindevent($("form[role=form]"));
  90. },
  91. rowStyle:function(row,index){
  92. var style = {};
  93. if(row.warning){
  94. style={css:{'color':'#ff0000'}};
  95. }
  96. return style;
  97. }
  98. }
  99. };
  100. return Controller;
  101. });