agreement.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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: 'agreement/index',
  8. add_url: 'agreement/add',
  9. edit_url: 'agreement/edit',
  10. del_url: 'agreement/del',
  11. multi_url: 'agreement/multi',
  12. import_url: 'agreement/import',
  13. down_url: 'agreement/downpdf',
  14. multidownpdf_url: 'agreement/multidownpdf',
  15. table: 'agreement',
  16. }
  17. });
  18. var table = $("#table");
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'id',
  24. commonSearch: true,
  25. searchFormVisible: true,
  26. columns: [
  27. [
  28. {checkbox: true},
  29. {field: 'id', title: __('Id')},
  30. {field: 'admin_id', title: __('Admin_id'), operate: false, visible: false},
  31. {field: 'username_a', title: __('Username_a'), operate: false},
  32. {field: 'username_b', title: __('Username_b'), operate:"LIKE %...%"},
  33. {field: 'cardid_b', title: __('Cardid_b'), operate: false, visible: false},
  34. {field: 'mobile_b', title: __('Mobile_b'), operate: false, visible: false},
  35. //{field: 'sign_status', title: __('Sign_status'), visible:false, searchList: {"sign_status 1":__('Sign_status 1'),"sign_status 2":__('Sign_status 2')}},
  36. {field: 'sign_status_text', title: __('Sign_status'), operate:false},
  37. {
  38. field: 'template_type',
  39. title: __('template_type'),
  40. operate: false,
  41. formatter: function (value, row, index) {
  42. if (value == '2') {
  43. return '模板二';
  44. } else if (value == '1') {
  45. return '模板一';
  46. }
  47. }
  48. },
  49. /* {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
  50. {field: 'status_text', title: __('Status'), operate:false, visible: false},
  51. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},
  52. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible: false},*/
  53. {
  54. field: 'operate',
  55. title: __('Operate'),
  56. table: table,
  57. events: Controller.api.events.operate,
  58. buttons: [
  59. {
  60. name: 'operate',
  61. text: __('查看'),
  62. title: __('查看'),
  63. classname: 'btn btn-xs btn-success btn-editone',
  64. icon: 'fa fa-eye',
  65. },
  66. {
  67. name: 'operate',
  68. text: __('删除'),
  69. title: __('删除'),
  70. classname: 'btn btn-xs btn-danger btn-delone',
  71. icon: 'fa fa-trash',
  72. },
  73. {
  74. name: 'operate',
  75. text: __('下载合同'),
  76. title: __('下载合同'),
  77. classname: 'btn btn-xs btn-success btn-downone',
  78. icon: 'fa fa-eye',
  79. }
  80. ],
  81. formatter: Table.api.formatter.buttons
  82. },
  83. ]
  84. ]
  85. });
  86. $(".btn-mpdfdown").click(function(){
  87. var options = table.bootstrapTable('getOptions');
  88. var url = options.extend.down_url;
  89. var data= table.bootstrapTable('getSelections');
  90. var ids= '';
  91. if(data.length > 0 ){
  92. $.each(data, function (i, item) {
  93. //ids += item.id + ',';
  94. url = url+'/ids/'+item.id;
  95. var aLink = document.createElement('a');
  96. aLink.download = "cps";
  97. aLink.href = url;
  98. document.body.appendChild(aLink);
  99. aLink.click();
  100. document.body.removeChild(aLink);
  101. url = options.extend.down_url;
  102. });
  103. }
  104. });
  105. // 为表格绑定事件
  106. Table.api.bindevent(table);
  107. },
  108. add: function () {
  109. Controller.api.bindevent();
  110. },
  111. edit: function () {
  112. Controller.api.bindevent();
  113. },
  114. api: {
  115. bindevent: function () {
  116. Form.api.bindevent($("form[role=form]"));
  117. },
  118. events: {
  119. operate: {
  120. 'click .btn-editone': function (e, value, row, index) {
  121. e.stopPropagation();
  122. e.preventDefault();
  123. var table = $(this).closest('table');
  124. var options = table.bootstrapTable('getOptions');
  125. var ids = row[options.pk];
  126. row = $.extend({}, row ? row : {}, {ids: ids});
  127. var url = options.extend.edit_url;
  128. Fast.api.open(Table.api.replaceurl(url, row, table), '查看', $(this).data() || {});
  129. },
  130. 'click .btn-delone': function (e, value, row, index) {
  131. e.stopPropagation();
  132. e.preventDefault();
  133. var that = this;
  134. var top = $(that).offset().top - $(window).scrollTop();
  135. var left = $(that).offset().left - $(window).scrollLeft() - 260;
  136. if (top + 154 > $(window).height()) {
  137. top = top - 154;
  138. }
  139. if ($(window).width() < 480) {
  140. top = left = undefined;
  141. }
  142. Layer.confirm(
  143. __('Are you sure you want to delete this item?'),
  144. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
  145. function (index) {
  146. var table = $(that).closest('table');
  147. var options = table.bootstrapTable('getOptions');
  148. Table.api.multi("del", row[options.pk], table, that);
  149. Layer.close(index);
  150. }
  151. );
  152. },
  153. 'click .btn-downone': function (e, value, row, index) {
  154. e.stopPropagation();
  155. e.preventDefault();
  156. var table = $(this).closest('table');
  157. var options = table.bootstrapTable('getOptions');
  158. var ids = row[options.pk];
  159. row = $.extend({}, row ? row : {}, {ids: ids});
  160. var url = options.extend.down_url;
  161. url = Table.api.replaceurl(url, row, table);
  162. $(location).prop('href', url);
  163. },
  164. }
  165. },
  166. }
  167. };
  168. return Controller;
  169. });