leave.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. $(".btn-add").data("area",["800px","560px"]);
  6. Table.api.init({
  7. extend: {
  8. index_url: 'leave/index' + location.search,
  9. add_url: 'leave/add',
  10. edit_url: 'leave/edit',
  11. del_url: 'leave/del',
  12. multi_url: 'leave/multi',
  13. import_url: 'leave/import',
  14. table: 'leave',
  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: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  30. {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  31. {field: 'leave_type', title: __('Leave_type'), searchList: {"正课外出":__('正课外出'),"周末外出":__('周末外出'),"特殊类型":__('特殊类型')}, formatter: Table.api.formatter.normal},
  32. {field: 'departure_time', title: __('Departure_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  33. {field: 'return_time', title: __('Return_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  34. //{field: 'return_status', title: __('Return_status'), operate: 'LIKE', formatter: Table.api.formatter.status},
  35. {field: 'is_return', title: __('Is_return'), searchList: {"0":__('未归队'),"1":__('已归队')}, formatter: Table.api.formatter.normal},
  36. //{field: 'updatetime', title: __('Updatetime'), operate: 'LIKE'},
  37. //{field: 'admin_id_text', title: __('记录人')},
  38. {field: 'people_id1_text', title: __('People_id1')},
  39. {field: 'status1', title: __('一级审批状态'), formatter: Table.api.formatter.normal,formatter:function(index,row){
  40. if(row.status1 == 1){
  41. if(!row.contents1)return '<span class="text-success">已审批</span>'
  42. }else if(row.status1 == 2){
  43. return '<span class="text-danger">已驳回</span> <i class="fa fa-commenting-o" data-toggle="tooltip" data-original-title="'+row.contents+'"></i>'
  44. }else{
  45. return '未处理'
  46. }
  47. }},
  48. //{field: 'unit_id2_text', title: __('Unit_id2')},
  49. {field: 'people_id2_text', title: __('People_id2')},
  50. {field: 'status2', title: __('二级审批状态'), formatter: Table.api.formatter.normal,formatter:function(index,row){
  51. if(row.status2 == 1){
  52. if(!row.contents2)return '<span class="text-success">已审批</span>'
  53. }else if(row.status2 == 2){
  54. return '<span class="text-danger">已驳回</span> <i class="fa fa-commenting-o" data-toggle="tooltip" data-original-title="'+row.contents+'"></i>'
  55. }else{
  56. return '未处理'
  57. }
  58. }},
  59. //{field: 'unit_id3_text', title: __('Unit_id3')},
  60. {field: 'people_id3_text', title: __('People_id3')},
  61. {field: 'status3', title: __('三级审批状态'), formatter: Table.api.formatter.normal,formatter:function(index,row){
  62. if(row.status3 == 1){
  63. if(!row.contents3)return '<span class="text-success">已审批</span>'
  64. }else if(row.status3 == 2){
  65. return '<span class="text-danger">已驳回</span> <i class="fa fa-commenting-o" data-toggle="tooltip" data-original-title="'+row.contents+'"></i>'
  66. }else{
  67. return '未处理'
  68. }
  69. }},
  70. {field: 'people_id4_text', title: __('People_id4')},
  71. {field: 'status4', title: __('四级审批状态'), formatter: Table.api.formatter.normal,formatter:function(index,row){
  72. if(row.status4 == 1){
  73. if(!row.contents4)return '<span class="text-success">已审批</span>'
  74. }else if(row.status4 == 2){
  75. return '<span class="text-danger">已驳回</span> <i class="fa fa-commenting-o" data-toggle="tooltip" data-original-title="'+row.contents+'"></i>'
  76. }else{
  77. return '未处理'
  78. }
  79. }},
  80. {field: 'statusd', title: __('总审批状态'), searchList: {"0":__('未审批'),"1":__('审批已通过'),"2":__('审批不通过')}, formatter: Table.api.formatter.normal},
  81. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons: [
  82. {
  83. name: '审批',
  84. text: '审批',
  85. title: '审批',
  86. classname: 'btn btn-xs btn-info btn-view btn-dialog ',
  87. icon: 'fa fa-search',
  88. url: function(row){
  89. var url = 'leave/auth?ids='+row.id;
  90. if(row.status1==0){
  91. url+='&step=1';
  92. }else if(row.status2==0){
  93. url+='&step=2';
  94. }else if(row.status3==0){
  95. url+='&step=3';
  96. }else if(row.status4==0){
  97. url+='&step=4';
  98. }
  99. return url;
  100. },
  101. extend: 'data-area=\'["500px","80%"]\'',
  102. refresh: true,
  103. visible:function(row){
  104. if(row.status1==0 && Config.admin.id == row.people_id1){
  105. return true;
  106. }else if(row.status2==0 && Config.admin.id == row.people_id2 && row.status1==1){
  107. return true;
  108. }else if(row.status3==0 && Config.admin.id == row.people_id3 && row.status1==1 && row.status2==1){
  109. return true;
  110. }else if(row.status4==0 && Config.admin.id == row.people_id4 && row.status1==1 && row.status2==1 && row.status3==1){
  111. return true;
  112. }
  113. return false;
  114. }
  115. },
  116. {
  117. name: '归队',
  118. text: '归队',
  119. title: '归队',
  120. classname: 'btn btn-xs btn-info btn-ajax',
  121. confirm: '确定归队吗?',
  122. icon: 'fa fa-search',
  123. url: function(row){
  124. var url = 'leave/rejoin?ids='+row.id;
  125. return url;
  126. },
  127. refresh: true,
  128. visible:function(row){
  129. if(row.return_time != '' && row.statusd == 1 && row.is_return == 0){
  130. return true;
  131. }
  132. return false;
  133. }
  134. }
  135. ],formatter: function(value,row,index){
  136. var that = $.extend({},this);
  137. var table = $(that.table).clone(true);
  138. if(row.people_id1=="1" || row.people_id1=="2"){
  139. $(table).data("operate-edit",null);
  140. that.table = table;
  141. }
  142. return Table.api.formatter.operate.call(that,value,row,index)
  143. //console.log(value);
  144. //console.log(row);
  145. //console.log(index);
  146. }
  147. }
  148. ]
  149. ]
  150. });
  151. // 为表格绑定事件
  152. Table.api.bindevent(table);
  153. table.on('post-body.bs.table',function(){
  154. $(".btn-editone").data("area",["800px","420px"]);
  155. })
  156. },
  157. add: function () {
  158. Controller.api.bindevent();
  159. $("#c-people_id").data("params", function (obj) {
  160. var unit_id = $('#J_unitselect').val();
  161. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  162. });
  163. },
  164. edit: function () {
  165. Controller.api.bindevent();
  166. $("#c-people_id").data("params", function (obj) {
  167. var unit_id = $('#J_unitselect').val();
  168. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  169. });
  170. },
  171. auth: function () {
  172. Controller.api.bindevent();
  173. $('#J_ok').click(function(){
  174. var id = $('#id').val();
  175. Layer.confirm('确定要通过吗?',{shade:false},function(index){
  176. $.get('leave/auth_status',{ids:id,status:1},function(res){
  177. parent.Layer.closeAll();
  178. parent.$("a.btn-refresh").trigger("click");
  179. parent.Layer.msg(res.msg);
  180. });
  181. });
  182. });
  183. $('#J_no').click(function(){
  184. var id = $('#id').val();
  185. Layer.prompt({
  186. title:'驳回原因'
  187. },function(val,index){
  188. if(val){
  189. $.get('leave/auth_status',{ids:id,status:2,contents:val},function(res){
  190. parent.Layer.closeAll();
  191. parent.$("a.btn-refresh").trigger("click");
  192. parent.Layer.msg(res.msg);
  193. });
  194. }else{
  195. Layer.msg('请输入原因');
  196. }
  197. })
  198. });
  199. },
  200. api: {
  201. bindevent: function () {
  202. Form.api.bindevent($("form[role=form]"));
  203. }
  204. }
  205. };
  206. return Controller;
  207. });