procuremenexport.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. var currYm = Controller.api.currentYm();
  5. $('#export-preview-ym').val(currYm);
  6. function listUrl(ym) {
  7. ym = (ym || '').trim();
  8. if (!/^\d{4}-\d{2}$/.test(ym)) {
  9. ym = Controller.api.currentYm();
  10. }
  11. return Fast.api.fixurl('procuremenexport/index?ym=' + encodeURIComponent(ym));
  12. }
  13. function refreshTable() {
  14. var ym = ($('#export-preview-ym').val() || '').trim();
  15. if (!/^\d{4}-\d{2}$/.test(ym)) {
  16. ym = Controller.api.currentYm();
  17. $('#export-preview-ym').val(ym);
  18. }
  19. $('#table').bootstrapTable('refresh', {url: listUrl(ym)});
  20. }
  21. Table.api.init({
  22. extend: {
  23. index_url: listUrl(currYm),
  24. table: 'purchase_order',
  25. }
  26. });
  27. var table = $('#table');
  28. table.bootstrapTable({
  29. url: listUrl(currYm),
  30. pk: 'id',
  31. sortName: 'id',
  32. sortOrder: 'desc',
  33. pagination: true,
  34. pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
  35. pageList: [10, 15, 20, 25, 50],
  36. showJumpto: true,
  37. commonSearch: false,
  38. search: false,
  39. columns: [
  40. [
  41. {field: 'ym', title: '月份', width: 88},
  42. {field: 'CCYDH', title: '订单号'},
  43. {field: 'CYJMC', title: '印件名称', class: 'autocontent', formatter: Table.api.formatter.content},
  44. {field: 'CGYMC', title: '工序名称', class: 'autocontent', formatter: Table.api.formatter.content},
  45. {field: 'createtime_text', title: '完结时间', width: 165},
  46. {field: 'row_count', title: '工序数', width: 72, align: 'center'},
  47. {field: 'total_amount', title: '金额合计', formatter: function (value, row) {
  48. return row.total_amount_text != null && row.total_amount_text !== ''
  49. ? row.total_amount_text
  50. : (value != null ? String(value) : '');
  51. }},
  52. {
  53. field: 'operate',
  54. title: '操作',
  55. width: 88,
  56. align: 'center',
  57. formatter: function (value, row) {
  58. var sid = row && row.scydgy_id;
  59. if (!sid) {
  60. return '';
  61. }
  62. return '<a href="javascript:;" class="btn btn-xs btn-info btn-export-details" data-scydgy-id="' + sid + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>';
  63. }
  64. }
  65. ]
  66. ]
  67. });
  68. Table.api.bindevent(table);
  69. $('.btn-refresh').off('click.procuremenExportRefresh').on('click.procuremenExportRefresh', function () {
  70. refreshTable();
  71. });
  72. $('#export-preview-ym').off('change.procuremenExportYm').on('change.procuremenExportYm', function () {
  73. refreshTable();
  74. });
  75. $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
  76. var ym = ($('#export-preview-ym').val() || '').trim();
  77. if (!/^\d{4}-\d{2}$/.test(ym)) {
  78. Toastr.warning('请选择有效月份');
  79. return;
  80. }
  81. var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(ym));
  82. window.open(url, '_blank');
  83. });
  84. $(document).off('click.procuremenExportDetails', '.btn-export-details').on('click.procuremenExportDetails', '.btn-export-details', function (e) {
  85. e.preventDefault();
  86. var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
  87. if (!sid) {
  88. return;
  89. }
  90. var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
  91. Backend.api.open(url, '详情', {area: ['76%', '100%']});
  92. });
  93. },
  94. api: {
  95. currentYm: function () {
  96. var d = new Date();
  97. return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
  98. },
  99. bindevent: function () {
  100. Form.api.bindevent($('form[role=form]'));
  101. }
  102. }
  103. };
  104. return Controller;
  105. });