roster.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-add").data("area",["1000px","1200px"]);
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'roster/index' + location.search,
  9. // add_url: 'roster/add',
  10. // edit_url: 'roster/edit',
  11. // del_url: 'roster/del',
  12. multi_url: 'roster/multi',
  13. import_url: 'roster/import',
  14. table: 'roster',
  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: __('Id')},
  27. {field: 'name', title: __('姓名')},
  28. {field: 'unit_id_text', title: __('单位')},
  29. {field: 'post_id_text', title: __('职务')},
  30. {field: 'rank_id_text', title: __('军衔'), operate: 'LIKE'},
  31. {field: 'nation_id_text', title: __('民族'), operate: 'LIKE'},
  32. {field: 'origin', title: __('籍贯'), operate:'RANGE'},
  33. {field: 'birth_date', title: __('出生年月'), operate: 'LIKE'},
  34. {field: 'enlist_date', title: __('入伍时间'), operate: 'LIKE'},
  35. {field: 'party_date', title: __('党团时间'), operate: 'LIKE'},
  36. {field: 'education_id_text', title: __('文化程度'), operate: 'LIKE'},
  37. {field: 'marry_list', title: __('婚姻状况'), operate: 'LIKE'},
  38. {field: 'phone', title: __('家庭住址及联系方式'), operate: 'LIKE'},
  39. //{field: 'lead_text', title: __('备注'), operate: 'LIKE'},
  40. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons: [
  41. {
  42. name: '查看',
  43. text: '查看',
  44. title: '查看',
  45. classname: 'btn btn-xs btn-info btn-view btn-dialog ',
  46. icon: 'fa fa-search',
  47. url: 'roster/details',
  48. extend: 'data-area=\'["1000px","80%"]\'',
  49. refresh: true
  50. }
  51. ], formatter: Table.api.formatter.operate}
  52. ]
  53. ]
  54. });
  55. // 为表格绑定事件
  56. Table.api.bindevent(table);
  57. table.on('post-body.bs.table',function(){
  58. $(".btn-editone").data("area",["1000px","1200px"]);
  59. })
  60. },
  61. add: function () {
  62. Controller.api.bindevent();
  63. $(document).on("change", "#J_unitselect", function(){
  64. $.get('diary/huoq',{id:$("#J_unitselect").val()},function(res){
  65. $('#c-orgcadre').val(res.data.orgcadre);
  66. $('#c-orgsoldier').val(res.data.orgsoldier);
  67. $('#c-orgcivilian').val(res.data.orgcivilian);
  68. $('#c-nowcadre').val(res.data.nowcadre);
  69. $('#c-nowsoldier').val(res.data.nowsoldier);
  70. $('#c-nowcivilian').val(res.data.nowcivilian);
  71. });
  72. });
  73. $("#c-people_id,#c-dutylead,#c-dutyA,#c-dutyB,#c-dutyC,#c-dutyD,#c-dutyE,#c-dutyF,#c-lead,.people_id1").data("params", function (obj) {
  74. //console.log($(this).attr('id'))
  75. var unit_id = $('#J_unitselect').val();
  76. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  77. });
  78. //因为日期选择框不会触发change事件,导致无法刷新textarea,所以加上判断
  79. $(document).on("dp.change", "#add-form .datetimepicker", function () {
  80. $(this).parent().prev().find("input").trigger("change");
  81. });
  82. $(document).on("fa.event.appendfieldlist", "#add-form .btn-append", function (e, obj) {
  83. Form.events.selectpage(obj);
  84. Form.events.datetimepicker(obj);
  85. });
  86. $(document).on('click','.btn-append',function(){
  87. var form = $("#add-form");
  88. require(['bootstrap-datetimepicker'], function () {
  89. var options = {
  90. format: 'LT',
  91. icons: {
  92. time: 'fa fa-clock-o',
  93. date: 'fa fa-calendar',
  94. up: 'fa fa-chevron-up',
  95. down: 'fa fa-chevron-down',
  96. previous: 'fa fa-chevron-left',
  97. next: 'fa fa-chevron-right',
  98. today: 'fa fa-history',
  99. clear: 'fa fa-trash',
  100. close: 'fa fa-remove'
  101. },
  102. showTodayButton: true,
  103. showClose: true
  104. };
  105. $('.datetimepicker3', form).parent().css('position', 'relative');
  106. $('.datetimepicker3', form).datetimepicker(options).on('dp.change', "#add-form .datetimepicker3", function (e) {
  107. $(this, document).trigger("changed");
  108. });
  109. });
  110. $(".people_id1,.people_id2,.people_id3,.people_id4,.people_id6,.people_id5").data("params", function (obj) {
  111. var unit_id = $('#J_unitselect').val();
  112. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  113. });
  114. });
  115. },
  116. edit: function () {
  117. Controller.api.bindevent();
  118. $(document).on("change", "#J_unitselect", function(){
  119. $.get('diary/huoq',{id:$("#J_unitselect").val()},function(res){
  120. $('#c-orgcadre').val(res.data.orgcadre);
  121. $('#c-orgsoldier').val(res.data.orgsoldier);
  122. $('#c-orgcivilian').val(res.data.orgcivilian);
  123. $('#c-nowcadre').val(res.data.nowcadre);
  124. $('#c-nowsoldier').val(res.data.nowsoldier);
  125. $('#c-nowcivilian').val(res.data.nowcivilian);
  126. });
  127. });
  128. $("#c-people_id,#c-dutylead,#c-dutyA,#c-dutyB,#c-dutyC,#c-dutyD,#c-dutyE,#c-dutyF,#c-lead,.people_id1").data("params", function (obj) {
  129. console.log($(this).attr('id'))
  130. var unit_id = $('#J_unitselect').val();
  131. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  132. });
  133. //因为日期选择框不会触发change事件,导致无法刷新textarea,所以加上判断
  134. $(document).on("dp.change", "#edit-form .datetimepicker", function () {
  135. $(this).parent().prev().find("input").trigger("change");
  136. });
  137. $(document).on("fa.event.appendfieldlist", "#edit-form .btn-append", function (e, obj) {
  138. Form.events.selectpage(obj);
  139. Form.events.datetimepicker(obj);
  140. });
  141. $(document).on('click','.btn-append',function(){
  142. var form = $("#edit-form");
  143. require(['bootstrap-datetimepicker'], function () {
  144. var options = {
  145. format: 'LT',
  146. icons: {
  147. time: 'fa fa-clock-o',
  148. date: 'fa fa-calendar',
  149. up: 'fa fa-chevron-up',
  150. down: 'fa fa-chevron-down',
  151. previous: 'fa fa-chevron-left',
  152. next: 'fa fa-chevron-right',
  153. today: 'fa fa-history',
  154. clear: 'fa fa-trash',
  155. close: 'fa fa-remove'
  156. },
  157. showTodayButton: true,
  158. showClose: true
  159. };
  160. $('.datetimepicker3', form).parent().css('position', 'relative');
  161. $('.datetimepicker3', form).datetimepicker(options).on('dp.change', "#edit-form .datetimepicker3", function (e) {
  162. $(this, document).trigger("changed");
  163. });
  164. });
  165. $(".people_id1,.people_id2,.people_id3,.people_id4,.people_id6,.people_id5").data("params", function (obj) {
  166. var unit_id = $('#J_unitselect').val();
  167. return {"custom[unit_id][0]":"in","custom[unit_id][1]":unit_id};
  168. });
  169. });
  170. },
  171. api: {
  172. bindevent: function () {
  173. Form.api.bindevent($("form[role=form]"));
  174. }
  175. }
  176. };
  177. return Controller;
  178. });