drill.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-add").data("area", ["1000px", "490px"]);
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'drill/index' + location.search,
  9. add_url: 'drill/add',
  10. edit_url: 'drill/edit',
  11. del_url: 'drill/del',
  12. multi_url: 'drill/multi',
  13. import_url: 'drill/import',
  14. table: 'drill',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'order_number', title: __('序号')},
  27. {field: 'unit_id_text', title: __('Unit_id')},
  28. {field: 'people_id_text', title: __('People_id')},
  29. {field: 'project', title: __('Project'), operate: 'LIKE'},
  30. {field: 'drill_time', title: __('Drill_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  31. {field: 'address', title: __('Address'), operate: 'LIKE'},
  32. {field: 'ought_to', title: __('Ought_to')},
  33. {field: 'actual', title: __('Actual')},
  34. {field: 'probability', title: __('Probability'), operate:'BETWEEN'},
  35. {field: 'result', title: __('Result'), operate: 'LIKE'},
  36. {field: 'expend', title: __('Expend'), operate: 'LIKE'},
  37. // {field: 'remark', title: __('Remark'), operate: 'LIKE'},
  38. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons: [
  39. {
  40. name: '查看',
  41. text: '查看',
  42. title: '查看',
  43. classname: 'btn btn-xs btn-info btn-view btn-dialog ',
  44. icon: 'fa fa-search',
  45. url: 'drill/details',
  46. extend: 'data-area=\'["900px","600px"]\'',
  47. refresh: true
  48. }
  49. ], formatter: Table.api.formatter.operate}
  50. ]
  51. ]
  52. });
  53. // 为表格绑定事件
  54. Table.api.bindevent(table);
  55. table.on('post-body.bs.table', function () {
  56. $(".btn-editone").data("area", ["1000px", "600px"]);
  57. })
  58. },
  59. add: function () {
  60. Controller.api.bindevent();
  61. Controller.api.events.getpeople();
  62. $("#J_unitselect").on('change',function(){
  63. Controller.api.events.getpeople();
  64. });
  65. $("#c-actual").on('change',function(){
  66. var max = $('#c-ought_to').data('max');
  67. if($(this).val()>max){
  68. Toastr.error("该数量不能大于单位总人数");
  69. $(this).val(max);
  70. }
  71. });
  72. $("#c-actual").on('keyup',function(){
  73. var max = $('#c-ought_to').data('max');
  74. if($(this).val()>max){
  75. Toastr.error("该数量不能大于单位总人数");
  76. $(this).val(max);
  77. }
  78. });
  79. $("#c-people_id").data("params", function (obj) {
  80. var unit_id = $('#J_unitselect').val();
  81. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  82. });
  83. },
  84. edit: function () {
  85. Controller.api.bindevent();
  86. Controller.api.events.getpeople();
  87. $("#J_unitselect").on('change',function(){
  88. Controller.api.events.getpeople();
  89. });
  90. $("#c-actual").on('change',function(){
  91. var max = $('#c-ought_to').data('max');
  92. if($(this).val()>max){
  93. Toastr.error("该数量不能大于单位总人数");
  94. $(this).val(max);
  95. }
  96. });
  97. $("#c-actual").on('keyup',function(){
  98. var max = $('#c-ought_to').data('max');
  99. if($(this).val()>max){
  100. Toastr.error("该数量不能大于单位总人数");
  101. $(this).val(max);
  102. }
  103. });
  104. },
  105. api: {
  106. bindevent: function () {
  107. Form.api.bindevent($("form[role=form]"));
  108. },
  109. events: {
  110. getpeople:function(){
  111. $.get('drill/huoq',{unit_id:$("#J_unitselect").val()},function(res){
  112. $('#c-ought_to').val(res.data);
  113. $('#c-ought_to').data('max',res.data);
  114. });
  115. }
  116. }
  117. }
  118. };
  119. return Controller;
  120. });