procuremenexport.js 5.7 KB

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