receivablesplan.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. Table.api.init();
  5. //绑定事件
  6. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  7. var panel = $($(this).attr("href"));
  8. if (panel.length > 0) {
  9. Controller.table[panel.attr("id")].call(this);
  10. $(this).on('click', function (e) {
  11. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  12. });
  13. }
  14. //移除绑定的事件
  15. $(this).unbind('shown.bs.tab');
  16. });
  17. //必须默认触发shown.bs.tab事件
  18. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  19. // 初始化表格参数配置
  20. Table.api.init({
  21. extend: {
  22. index_url: 'qingdong/customer/receivablesplan/index?type=0',
  23. add_url: 'qingdong/customer/receivablesplan/add',
  24. edit_url: 'qingdong/customer/receivablesplan/edit',
  25. del_url: 'qingdong/customer/receivablesplan/del',
  26. multi_url: 'qingdong/customer/receivablesplan/multi',
  27. import_url: 'qingdong/customer/receivablesplan/import',
  28. customer_url : 'qingdong/customer/customer/detail',
  29. contract_url : 'qingdong/customer/contract/detail',
  30. table: 'qingdong_receivables_plan',
  31. }
  32. });
  33. $(document).on('click', '.show-customer', function (data) {
  34. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  35. var options = {
  36. shadeClose : false,
  37. shade : [0.3, '#393D49'],
  38. area : area,
  39. callback : function (value) {
  40. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  41. console.log(value);
  42. }
  43. };
  44. Fast.api.open($.fn.bootstrapTable.defaults.extend.customer_url + "?ids=" + $(this).data('id'), '客户详情', options);
  45. }).on('click', '.show-contract', function (data) {
  46. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  47. var options = {
  48. shadeClose : false,
  49. shade : [0.3, '#393D49'],
  50. area : area,
  51. callback : function (value) {
  52. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  53. console.log(value);
  54. }
  55. };
  56. Fast.api.open($.fn.bootstrapTable.defaults.extend.contract_url + "?ids=" + $(this).data('id'), '合同详情', options);
  57. });
  58. // 为表格绑定事件
  59. Table.api.bindevent(table);
  60. },
  61. tableinfo:{
  62. url: '',
  63. pk: 'id',
  64. toolbar: '#toolbar',
  65. sortName: 'id',
  66. columns: [
  67. [
  68. {checkbox: true},
  69. {field: 'num', title: __('期数'), operate: 'LIKE'},
  70. {field: 'status', title: __('回款状态'),formatter: Table.api.formatter.status, searchList:{0: __('进行中'), 1: __('已完成'), 2: __('已逾期')}},
  71. {field: 'contract_id', title: __('合同'), operate:false, formatter : function (value, row, index) {
  72. if(row.contract){
  73. return "<a href='javascript:void(0);' data-id='" + row.contract.id + "' class='show-contract'>" + row.contract.name + "</a>";
  74. }
  75. return '';
  76. }},
  77. {field: 'customer_id', title: __('客户'), operate:false, formatter : function (value, row, index) {
  78. if(row.customer){
  79. return "<a href='javascript:void(0);' data-id='" + row.customer.id + "' class='show-customer'>" + row.customer.name + "</a>";
  80. }
  81. return '';
  82. }},
  83. {field: 'money', title: __('回款金额'), operate:'BETWEEN'},
  84. {field: 'return_date', title: __('回款日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  85. {field: 'return_type', title: __('回款方式'), operate: 'LIKE'},
  86. // {field: 'remind', title: __('提前几天提醒')},
  87. // {field: 'remind_date', title: __('提醒日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  88. {field: 'createtime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  89. {field: 'remarks', title: __('备注'), operate:false},
  90. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  91. ]
  92. ],
  93. //启用普通表单搜索
  94. search:false,
  95. commonSearch: true,
  96. searchFormVisible: true,
  97. onLoadSuccess:function(){
  98. // 这里就是数据渲染结束后的回调函数
  99. $('.btn-editone').html('编辑');
  100. $('.fa-pencil').remove();
  101. $('.btn-delone').html('删除');
  102. $('.fa-trash').remove();
  103. $('.btn-editone').removeClass('btn-success')
  104. $('.btn-editone').removeClass('btn')
  105. $('.btn-delone').removeClass('btn-danger')
  106. $('.btn-delone').removeClass('btn')
  107. }
  108. },
  109. table: {
  110. first: function () {
  111. // 初始化表格参数配置
  112. Table.api.init({});
  113. var table = $("#table");
  114. Controller.tableinfo.url=location.href+'&type=0';
  115. Controller.tableinfo.toolbar='#toolbar';
  116. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  117. // 初始化表格
  118. table.bootstrapTable(Controller.tableinfo);
  119. // 为表格绑定事件
  120. Table.api.bindevent(table);
  121. },
  122. second: function () {
  123. // 初始化表格参数配置
  124. Table.api.init({});
  125. var table = $("#table1");
  126. Controller.tableinfo.url=location.href+'&type=1';
  127. Controller.tableinfo.toolbar='#toolbar1';
  128. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  129. // 初始化表格
  130. table.bootstrapTable(Controller.tableinfo);
  131. // 为表格绑定事件
  132. Table.api.bindevent(table);
  133. },
  134. third: function () {
  135. // 初始化表格参数配置
  136. Table.api.init({});
  137. var table = $("#table2");
  138. Controller.tableinfo.url=location.href+'&type=2';
  139. Controller.tableinfo.toolbar='#toolbar2';
  140. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  141. // 初始化表格
  142. table.bootstrapTable(Controller.tableinfo);
  143. // 为表格绑定事件
  144. Table.api.bindevent(table);
  145. },
  146. },
  147. recyclebin: function () {
  148. // 初始化表格参数配置
  149. Table.api.init({
  150. extend: {
  151. 'dragsort_url': ''
  152. }
  153. });
  154. var table = $("#table");
  155. // 初始化表格
  156. table.bootstrapTable({
  157. url: 'qingdong/customer/receivablesplan/recyclebin' + location.search,
  158. pk: 'id',
  159. sortName: 'id',
  160. columns: [
  161. [
  162. {checkbox: true},
  163. {field: 'id', title: __('Id')},
  164. {
  165. field: 'deletetime',
  166. title: __('Deletetime'),
  167. operate: 'RANGE',
  168. addclass: 'datetimerange',
  169. formatter: Table.api.formatter.datetime
  170. },
  171. {
  172. field: 'operate',
  173. width: '130px',
  174. title: __('Operate'),
  175. table: table,
  176. events: Table.api.events.operate,
  177. buttons: [
  178. {
  179. name: 'Restore',
  180. text: __('Restore'),
  181. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  182. icon: 'fa fa-rotate-left',
  183. url: 'qingdong/customer/receivablesplan/restore',
  184. refresh: true
  185. },
  186. {
  187. name: 'Destroy',
  188. text: __('Destroy'),
  189. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  190. icon: 'fa fa-times',
  191. url: 'qingdong/customer/receivablesplan/destroy',
  192. refresh: true
  193. }
  194. ],
  195. formatter: Table.api.formatter.operate
  196. }
  197. ]
  198. ]
  199. });
  200. // 为表格绑定事件
  201. Table.api.bindevent(table);
  202. },
  203. add: function () {
  204. Controller.api.bindevent();
  205. },
  206. edit: function () {
  207. Controller.api.bindevent();
  208. },
  209. api: {
  210. bindevent: function () {
  211. $(document).on("click", ".select-customer", function(){
  212. var $this=$(this);
  213. top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
  214. $this.html(data.name);
  215. $('[name="'+$this.data('name')+'"]').val(data.id);
  216. },area:["100%", "100%"]});
  217. }).on("click", ".select-contract", function(){
  218. var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
  219. if(!customer_id){
  220. Layer.msg('请先选择客户');
  221. return false;
  222. }
  223. top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id+"&check_status=2" , __('Select'), {callback: function (data) {
  224. $this.html(data.name);
  225. $('[name="'+$this.data('name')+'"]').val(data.id);
  226. },area:["100%", "100%"]});
  227. });
  228. $("#c-contract_id").data("params", function (obj) {
  229. var customer_id=$('#c-customer_id').val();
  230. return {customer_id: customer_id};
  231. });
  232. Form.api.bindevent($("form[role=form]"));
  233. }
  234. }
  235. };
  236. return Controller;
  237. });