receivables.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index : function () {
  4. // 初始化表格参数配置
  5. Table.api.init();
  6. //绑定事件
  7. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  8. var panel = $($(this).attr("href"));
  9. if (panel.length > 0) {
  10. Controller.table[panel.attr("id")].call(this);
  11. $(this).on('click', function (e) {
  12. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  13. });
  14. }
  15. //移除绑定的事件
  16. $(this).unbind('shown.bs.tab');
  17. });
  18. //必须默认触发shown.bs.tab事件
  19. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  20. // 初始化表格参数配置
  21. Table.api.init({
  22. extend : {
  23. add_url : 'qingdong/customer/receivables/add',
  24. detail_url : 'qingdong/customer/receivables/detail',
  25. customer_url : 'qingdong/customer/customer/detail',
  26. contract_url : 'qingdong/customer/contract/detail',
  27. table : 'customer',
  28. }
  29. });
  30. $(document).on('click', '.show-detail', function (data) {
  31. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  32. var options = {
  33. shadeClose : false,
  34. shade : [0.3, '#393D49'],
  35. area : area,
  36. callback : function (value) {
  37. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  38. console.log(value);
  39. }
  40. };
  41. Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url+"?ids="+$(this).data('id'), '回款详情', options);
  42. }).on('click', '.show-customer', function (data) {
  43. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  44. var options = {
  45. shadeClose : false,
  46. shade : [0.3, '#393D49'],
  47. area : area,
  48. callback : function (value) {
  49. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  50. console.log(value);
  51. }
  52. };
  53. Fast.api.open($.fn.bootstrapTable.defaults.extend.customer_url + "?ids=" + $(this).data('id'), '客户详情', options);
  54. }).on('click', '.show-contract', function (data) {
  55. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  56. var options = {
  57. shadeClose : false,
  58. shade : [0.3, '#393D49'],
  59. area : area,
  60. callback : function (value) {
  61. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  62. console.log(value);
  63. }
  64. };
  65. Fast.api.open($.fn.bootstrapTable.defaults.extend.contract_url + "?ids=" + $(this).data('id'), '合同详情', options);
  66. }).on('click','.btn-imports',function () {
  67. Fast.api.open("qingdong/customer/receivables/import", "回款导入",{
  68. shadeClose: false,
  69. shade: false,
  70. maxmin: false,
  71. moveOut: false,
  72. scrollbars:false,
  73. 'area':[
  74. $(window).width() > 800 ? '600px' : '400px',
  75. $(window).height() > 600 ? '500px' : '400px'
  76. ],
  77. callback:function(value){
  78. Form.events.plupload("#plupload-local");
  79. // 在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
  80. },
  81. });
  82. }).on("click", ".btn-export", function () {
  83. var tab_id=$('.active.in').attr('id');
  84. var table,type;
  85. switch (tab_id){
  86. case 'first'://全部
  87. table=$('#table');
  88. type=0;
  89. break;
  90. case 'second'://我负责的
  91. table=$('#table1');
  92. type=1;
  93. break;
  94. case 'third'://下属负责的
  95. table=$('#table2');
  96. type=2;
  97. break;
  98. }
  99. var ids = Table.api.selectedids(table);
  100. var page = table.bootstrapTable('getData');
  101. var options = table.bootstrapTable('getOptions');
  102. var params=options.queryParams({});
  103. var all = options.totalRows;
  104. var sort = options.sortName+' '+options.sortOrder;
  105. var filter = params.filter;
  106. var op = params.op;
  107. Layer.confirm("请选择导出的选项", {
  108. title : '导出数据',
  109. btn : ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
  110. success : function (layero, index) {
  111. $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
  112. }, yes : function (index, layero) {
  113. if (ids.length == 0) {
  114. Layer.alert('数据为空');
  115. return true;
  116. }
  117. $.post('qingdong/customer/receivables/export', {sort:sort,ids : ids.join(","), isall : 1}, function (res) {
  118. Layer.alert(res.msg);
  119. if(res.code == 1){
  120. window.location.href = res.data.filePath;
  121. Layer.close(index);
  122. }
  123. table.bootstrapTable('refresh');
  124. }, 'json');
  125. return false;
  126. },
  127. btn2 : function (index, layero) {
  128. if (page.length == 0) {
  129. Layer.alert('数据为空');
  130. return true;
  131. }
  132. var ids = [];
  133. $.each(page, function (i, j) {
  134. ids.push(j.id);
  135. });
  136. $.post('qingdong/customer/receivables/export', {sort:sort,ids : ids.join(","), isall : 2}, function (res) {
  137. Layer.alert(res.msg);
  138. if(res.code == 1){
  139. window.location.href = res.data.filePath;
  140. Layer.close(index);
  141. }
  142. table.bootstrapTable('refresh');
  143. }, 'json');
  144. return false;
  145. },
  146. btn3 : function (index, layero) {
  147. if (page.length == 0) {
  148. Layer.alert('数据为空');
  149. return true;
  150. }
  151. $.post('qingdong/customer/receivables/export?filter='+filter+'&op='+op, {sort:sort,ids : ids.join(","), isall : 3,type:type}, function (res) {
  152. Layer.alert(res.msg);
  153. if(res.code == 1){
  154. window.location.href = res.data.filePath;
  155. Layer.close(index);
  156. }
  157. table.bootstrapTable('refresh');
  158. }, 'json');
  159. return false;
  160. }
  161. })
  162. });
  163. },
  164. table: {
  165. first: function () {
  166. // 初始化表格参数配置
  167. Table.api.init({
  168. extend : {
  169. add_url : 'qingdong/customer/receivables/add',
  170. detail_url : 'qingdong/customer/receivables/detail',
  171. customer_url : 'qingdong/customer/customer/detail',
  172. contract_url : 'qingdong/customer/contract/detail',
  173. table : 'customer',
  174. }
  175. });
  176. if(Config.fields !='[]'){
  177. if (Config.fields && Object.keys(Config.fields).length > 0) {
  178. var fields = JSON.parse(Config.fields);
  179. var start = Controller.tableinfo.columns[0].length-2;
  180. for (var i = 0; i < fields.length; i++) {
  181. if (fields[i].hasOwnProperty('formatter'))
  182. fields[i].formatter = eval(fields[i].formatter);
  183. if (fields[i].hasOwnProperty('events'))
  184. fields[i].events = eval(fields[i].events);
  185. if (fields[i].hasOwnProperty('searchList'))
  186. fields[i].searchList = JSON.parse(fields[i].searchList);
  187. Controller.tableinfo.columns[0].splice(start + i, 0, fields[i]);
  188. }
  189. }
  190. }
  191. var table = $("#table");
  192. Controller.tableinfo.url=location.href+'&type=0';
  193. Controller.tableinfo.toolbar='#toolbar';
  194. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  195. // 初始化表格
  196. table.bootstrapTable(Controller.tableinfo);
  197. // 为表格绑定事件
  198. Table.api.bindevent(table);
  199. },
  200. second: function () {
  201. // 初始化表格参数配置
  202. Table.api.init({
  203. extend : {
  204. add_url : 'qingdong/customer/receivables/add',
  205. detail_url : 'qingdong/customer/receivables/detail',
  206. customer_url : 'qingdong/customer/customer/detail',
  207. contract_url : 'qingdong/customer/contract/detail',
  208. table : 'customer',
  209. }
  210. });
  211. var table = $("#table1");
  212. Controller.tableinfo.url=location.href+'&type=1';
  213. Controller.tableinfo.toolbar='#toolbar1';
  214. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  215. // 初始化表格
  216. table.bootstrapTable(Controller.tableinfo);
  217. // 为表格绑定事件
  218. Table.api.bindevent(table);
  219. },
  220. third: function () {
  221. // 初始化表格参数配置
  222. Table.api.init({
  223. extend : {
  224. add_url : 'qingdong/customer/receivables/add',
  225. detail_url : 'qingdong/customer/receivables/detail',
  226. customer_url : 'qingdong/customer/customer/detail',
  227. contract_url : 'qingdong/customer/contract/detail',
  228. table : 'customer',
  229. }
  230. });
  231. var table = $("#table2");
  232. Controller.tableinfo.url=location.href+'&type=2';
  233. Controller.tableinfo.toolbar='#toolbar2';
  234. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  235. // 初始化表格
  236. table.bootstrapTable(Controller.tableinfo);
  237. // 为表格绑定事件
  238. Table.api.bindevent(table);
  239. },
  240. },
  241. tableinfo:{
  242. url : '',
  243. toolbar: '#toolbar',
  244. pk : 'id',
  245. sortName : 'id',
  246. fixedColumns : true,
  247. fixedNumber : 2,
  248. search:false,
  249. searchFormVisible:true,
  250. columns : [
  251. [
  252. {checkbox : true},
  253. {
  254. field : 'number', title : '回款编号', fixedColumns : true, formatter : function (value, row, index) {
  255. return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-detail'>" + value + "</a>";
  256. },operate: 'LIKE'
  257. },
  258. {field : 'customer', title : '客户', fixedColumns : true, formatter : function (value, row, index) {
  259. if(row.customer){
  260. return "<a href='javascript:void(0);' data-id='" + row.customer_id + "' class='show-customer'>" + row.customer.name + "</a>";
  261. }
  262. return '';
  263. },operate:false},
  264. {field : 'customer_id', title : '客户名称', visible: false, addClass: "selectpage", extend: "data-source='qingdong/customer/customer/index' data-field='name'"},
  265. {field : 'contract_id', title : '合同', formatter : function (value, row, index) {
  266. if(row.contract){
  267. return "<a href='javascript:void(0);' data-id='" + row.contract_id + "' class='show-contract'>" + row.contract.name + "</a>";
  268. }
  269. return '';
  270. },operate:false},
  271. {field : 'return_time', title : '回款日期',operate: 'RANGE', addclass: 'datetimerange'},
  272. {field : 'return_type', title : '回款方式',operate:'like'},
  273. {field : 'money', title : '回款金额',operate:'like'},
  274. {field : 'owner_staff.name', title : '负责人',operate:false},
  275. {field : 'owner_staff_id', title : '负责人', visible: false, addClass: "selectpage", extend: "data-source='qingdong/department/staff/index' data-field='name'"},
  276. {field : 'check_status', title : '审核状态',formatter:Table.api.formatter.status, searchList: {0:'待审核', 2:'审核通过',3:"审核未通过",1: '审核中'},custom: {0: 'gray', 1: 'gray',2: 'success', 3: 'danger'}},
  277. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  278. ]
  279. ],
  280. onLoadSuccess:function(){
  281. // 这里就是数据渲染结束后的回调函数
  282. $(".btn-add").data("area",["80%","80%"]);
  283. $(".btn-edit").data("area",["80%","80%"]);
  284. }
  285. },
  286. add : function () {
  287. Controller.api.bindevent();
  288. },
  289. import : function () {
  290. Controller.api.bindevent();
  291. },
  292. detail : function () {
  293. // 初始化表格参数配置
  294. Table.api.init({});
  295. $('.stafflist').popover({
  296. placement : 'bottom',
  297. trigger : 'hover'
  298. });
  299. //操作日志
  300. var table2 = $("#operation_log");
  301. // 初始化表格
  302. table2.bootstrapTable({
  303. url : 'qingdong/examine/examine/receivables?receivables_id='+Config.idinfo.id,
  304. pk : 'id',
  305. sortName : 'id',
  306. operate : false,
  307. commonSearch : false,
  308. search : false,
  309. visible : false,
  310. showColumns : false,
  311. showExport : false,
  312. showToggle : false,
  313. columns : [
  314. [
  315. {field: 'check_staff.name', title: __('审批人')},
  316. {field: 'status', title: __('审批状态'), operate: false, formatter: Table.api.formatter.status, searchList: {0: __('待审批'), 1: __('审批通过'), 2: __('审批拒绝'), 3: __('撤销')}},
  317. {field: 'check_time', title: __('审批时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  318. {field: 'content', title: __('内容'),cellStyle:function (value,row,index,field) {
  319. return {
  320. css: {
  321. "min-width": "150px",
  322. "white-space": "nowrap",
  323. "text-overflow": "ellipsis",
  324. "overflow": "hidden",
  325. "max-width":"300px",
  326. 'cursor':"pointer"
  327. }
  328. };
  329. },formatter:function (value,row,index,field) {
  330. var span=document.createElement('span');
  331. span.setAttribute('title',value);
  332. span.innerHTML = value;
  333. return span.outerHTML;
  334. }
  335. },
  336. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  337. ]
  338. ]
  339. });
  340. Controller.api.bindevent();
  341. },
  342. api : {
  343. bindevent : function () {
  344. $(document).on("click", ".select-customer", function(){
  345. var $this=$(this);
  346. top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
  347. $this.html(data.name);
  348. $('[name="'+$this.data('name')+'"]').val(data.id);
  349. },area:["100%", "100%"]});
  350. }).on("click", ".select-contract", function(){
  351. var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
  352. if(!customer_id){
  353. Layer.msg('请先选择客户');
  354. return false;
  355. }
  356. top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id , __('Select'), {callback: function (data) {
  357. $this.html(data.name);
  358. $('[name="'+$this.data('name')+'"]').val(data.id);
  359. $.post('qingdong/customer/receivables/plan', {customer_id:customer_id,contract_id : data.id}, function (res) {
  360. $('#plan_id').html('');
  361. var data = res.data;
  362. var length = data.length;
  363. var html='';
  364. for (var i = 0; i < length; i++) {
  365. html += '<option value="' + data[i].id + '">' + data[i].num + '</option>';
  366. }
  367. $('#plan_id').html(html);
  368. $('#plan_id').selectpicker('refresh');
  369. }, 'json');
  370. },area:["100%", "100%"]});
  371. });
  372. $("#c-contract_id").data("params", function (obj) {
  373. var customer_id=$('#c-customer_id').val();
  374. return {customer_id: customer_id};
  375. });
  376. Form.api.bindevent($("form[role=form]"));
  377. }
  378. }
  379. };
  380. return Controller;
  381. });