invoice.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
  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: 'qingdongams/finance/invoice/index?type=0',
  23. add_url: 'qingdongams/finance/invoice/add',
  24. edit_url: 'qingdongams/finance/invoice/edit',
  25. del_url: 'qingdongams/finance/invoice/del',
  26. detail_url : 'qingdongams/finance/invoice/detail',
  27. customer_url : 'qingdongams/customer/customer/detail',
  28. contract_url:'qingdongams/customer/contract/detail',
  29. table: 'invoice'
  30. }
  31. });
  32. $(document).on('click', '.show-customer', function (data) {
  33. var area = ['95%', '95%'];
  34. var options = {
  35. shadeClose : false,
  36. shade : [0.3, '#393D49'],
  37. area : area,
  38. callback : function (value) {
  39. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  40. console.log(value);
  41. }
  42. };
  43. Fast.api.open($.fn.bootstrapTable.defaults.extend.customer_url + "?ids=" + $(this).data('id'), '客户详情', options);
  44. });
  45. $(document).on('click', '.show-contract', function (data) {
  46. var area = ['95%', '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. tableinfo:{
  60. url: '',
  61. pk: 'id',
  62. toolbar: '#toolbar',
  63. sortName: 'id',
  64. fixedRightNumber:1,
  65. fixedColumns:true,
  66. columns: [
  67. [
  68. {field: 'state', checkbox: true},
  69. {field: 'number', title: __('发票申请编号'), operate:false, formatter : function (value, row, index) {
  70. return "<a href='javascript:void(0);' class='btn-dialog' data-area=[\"95%\",\"95%\"] data-shade=\"0.3\"\n" +
  71. "data-url=\""+ $.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + row.id+
  72. "\" data-title=\"发票详情\" ' >" + value + "</a>";
  73. }},
  74. {field: 'customer', title: __('客户名称'), operate:false, formatter : function (value, row, index) {
  75. if(row.customer){
  76. return "<a href='javascript:void(0);' data-id='" + row.customer.id + "' class='show-customer'>" + row.customer.name + "</a>";
  77. }else{
  78. return '';
  79. }
  80. }},
  81. {field: 'contract', title: __('合同编号'), operate:false, formatter : function (value, row, index) {
  82. if(row.contract){
  83. return "<a href='javascript:void(0);' data-id='" + row.contract.id + "' class='show-contract'>" + row.contract.num + "</a>";
  84. }else{
  85. return '';
  86. }
  87. }},
  88. {field: 'money', title: __('开票金额')},
  89. {field: 'time', title: __('开票日期'), operate: '=', addclass: 'datetimepicker',data:"data-date-format=\" YYYY-MM-DD\""},
  90. {field: 'type', title: __('开票类型'), formatter: Table.api.formatter.status, searchList: {0: __('增值税专用发票'), 1: __('增值税普通发票'), 2: __('国税通用机打发票'), 3: __('地税通用机打发票'), 4: __('收据')}},
  91. {field: 'check_status', title: __('审批状态'), formatter: Table.api.formatter.status, searchList: {0: __('待审核'), 1: __('审核中'), 2: __('审核通过'), 3: __('审核拒绝'), 4: __('撤销'), 5: __('草稿')}},
  92. {field: 'owner_staff.name', title: __('创建人'),operate:false},
  93. {field: 'invoice_number', title: __('发票号码')},
  94. {field: 'invoice_time', title: __('实际开票时间'), operate: '=', addclass: 'datetimepicker',data:"data-date-format=\" YYYY-MM-DD\""},
  95. {field: 'logistics', title: __('物流单号')},
  96. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  97. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.buttons,
  98. buttons: [
  99. {
  100. name: 'detail',
  101. text: __('标记为开票'),
  102. title: __('标记为开票'),
  103. extend:'data-area=["80%","80%"]',
  104. classname: 'records btn-dialog',
  105. url: 'qingdongams/finance/invoice/batchstatus',
  106. visible: function (row) {
  107. if(row.invoice_time){
  108. return false;
  109. }
  110. return true;
  111. },
  112. },
  113. {
  114. name: 'detail',
  115. text: __('已开票'),
  116. title: __('已开票'),
  117. extend:'data-area=["80%","80%"]',
  118. classname: 'gray',
  119. disabled:true,
  120. visible: function (row) {
  121. //返回true时按钮显示,返回false隐藏
  122. if(row.invoice_time){
  123. return true;
  124. }
  125. return false;
  126. },
  127. },
  128. ]
  129. }
  130. ]
  131. ],
  132. //启用普通表单搜索
  133. search:false,
  134. commonSearch: true,
  135. searchFormVisible: true,
  136. onLoadSuccess:function(){
  137. // 这里就是数据渲染结束后的回调函数
  138. $(".btn-add").data("area",["90%","90%"]);
  139. $(".btn-edit").data("area",["90%","90%"]);
  140. }
  141. },
  142. table: {
  143. first: function () {
  144. var table = $("#table");
  145. Controller.tableinfo.url=location.href+'&type=0';
  146. Controller.tableinfo.toolbar='#toolbar';
  147. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  148. // 初始化表格
  149. table.bootstrapTable(Controller.tableinfo);
  150. // 为表格绑定事件
  151. Table.api.bindevent(table);
  152. },
  153. second: function () {
  154. // 初始化表格参数配置
  155. Table.api.init({});
  156. var table = $("#table1");
  157. Controller.tableinfo.url=location.href+'&type=1';
  158. Controller.tableinfo.toolbar='#toolbar1';
  159. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  160. // 初始化表格
  161. table.bootstrapTable(Controller.tableinfo);
  162. // 为表格绑定事件
  163. Table.api.bindevent(table);
  164. },
  165. third: function () {
  166. // 初始化表格参数配置
  167. Table.api.init({});
  168. var table = $("#table2");
  169. Controller.tableinfo.url=location.href+'&type=2';
  170. Controller.tableinfo.toolbar='#toolbar2';
  171. Controller.tableinfo.columns[0][Controller.tableinfo.columns[0].length-1].table=table;
  172. // 初始化表格
  173. table.bootstrapTable(Controller.tableinfo);
  174. // 为表格绑定事件
  175. Table.api.bindevent(table);
  176. },
  177. },
  178. add : function () {
  179. Controller.api.bindevent();
  180. },
  181. batchstatus : function () {
  182. Controller.api.bindevent();
  183. },
  184. edit : function () {
  185. Controller.api.bindevent();
  186. },
  187. detail : function () {
  188. $('.stafflist').popover({
  189. placement : 'bottom',
  190. trigger : 'hover'
  191. });
  192. Controller.api.bindevent();
  193. },
  194. api: {
  195. bindevent: function () {
  196. var num = 0;
  197. $(document).on("click", ".select-customer", function(){
  198. var $this=$(this);
  199. top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
  200. $this.html(data.name);
  201. $('[name="'+$this.data('name')+'"]').val(data.id);
  202. },area:["100%", "100%"]});
  203. }).on("click", ".select-contract", function(){
  204. var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
  205. if(!customer_id){
  206. Layer.msg('请先选择客户');
  207. return false;
  208. }
  209. top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id , __('Select'), {callback: function (data) {
  210. $this.html(data.name);
  211. $('#c-money').val(data.money);
  212. $('[name="'+$this.data('name')+'"]').val(data.id);
  213. },area:["100%", "100%"]});
  214. });
  215. Form.api.bindevent($("form[role=form]"));
  216. },
  217. formatter: {}
  218. },
  219. };
  220. return Controller;
  221. });