stock.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. table.on('post-body.bs.table',function(){
  40. $(".btn-editone").data("area",["100%","100%"]);
  41. });
  42. // 为表格绑定事件
  43. Table.api.bindevent(table);
  44. var ref = setInterval(function(){ //定时刷新
  45. $.ajax({
  46. type: "POST",
  47. url: "order/stockad",
  48. success(res) {//根据订单管理返回的值为1代表有新增数据订单
  49. if (res == 1) {
  50. window.clearInterval(ref);//停止刷新
  51. layer.confirm("您好,来新订单了!", {
  52. title: ['信息'],
  53. btn: ['确认'],
  54. area: ['60%', '60%'],
  55. },function(index) { //点击处理停止语音播报
  56. setInterval(fn,3000);
  57. jQuery.ajax({
  58. type: "post",
  59. url: "stock/orderstu",
  60. data: {orderstu:2},
  61. success: function(data){//成功回调函数
  62. if(data='处理成功'){
  63. location.reload();//刷新本页面
  64. }
  65. layer.close(index);//点击确定关闭弹窗
  66. },
  67. error: function(){ //失败返回调用
  68. alert("网络异常!");
  69. }
  70. });
  71. });
  72. var fn = function(){//有订单弹出提示框并且语音播报
  73. var synth = window.speechSynthesis;
  74. var msg = new window.SpeechSynthesisUtterance('您好,来新订单了!');
  75. window.speechSynthesis.cancel();
  76. synth.speak(msg);
  77. };
  78. setInterval(fn,5000);//多久播一次
  79. }
  80. }
  81. });
  82. },10000);//10000 十秒
  83. },
  84. add: function () {
  85. Controller.api.bindevent();
  86. },
  87. edit: function () {
  88. Controller.api.bindevent();
  89. },
  90. print: function () {
  91. Controller.api.bindevent();
  92. },
  93. api: {
  94. bindevent: function () {
  95. Form.api.bindevent($("form[role=form]"));
  96. },
  97. rowStyle:function(row,index){
  98. var style = {};
  99. if(row.warning){
  100. style={css:{'color':'#ff0000'}};
  101. }
  102. return style;
  103. }
  104. }
  105. };
  106. return Controller;
  107. });