procuremenexport.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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: true,
  47. search: true,
  48. columns: [
  49. [
  50. {field: 'ym', title: '月份', width: 88, operate: false},
  51. {field: 'CCYDH', title: '订单号', operate: 'LIKE'},
  52. {field: 'CYJMC', title: '印件名称', class: 'autocontent', operate: 'LIKE', formatter: Table.api.formatter.content},
  53. {field: 'CGYMC', title: '工序名称', class: 'autocontent', operate: 'LIKE', formatter: Table.api.formatter.content},
  54. {field: 'createtime_text', title: '完结时间', width: 165, operate: 'LIKE'},
  55. {field: 'row_count', title: '工序数', width: 72, align: 'center', operate: false},
  56. {field: 'total_amount', title: '金额合计', operate: false, 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. operate: false,
  67. formatter: function (value, row) {
  68. var sid = row && row.scydgy_id;
  69. if (!sid) {
  70. return '';
  71. }
  72. if (!exportCan('details')) {
  73. return '';
  74. }
  75. 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>';
  76. }
  77. }
  78. ]
  79. ]
  80. });
  81. Table.api.bindevent(table);
  82. $('.btn-refresh').off('click.procuremenExportRefresh').on('click.procuremenExportRefresh', function () {
  83. refreshTable();
  84. });
  85. $('#export-preview-ym').off('change.procuremenExportYm').on('change.procuremenExportYm', function () {
  86. refreshTable();
  87. });
  88. $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
  89. if (!exportCan('export_month_outward')) {
  90. Toastr.error('无导出权限');
  91. return;
  92. }
  93. var ym = ($('#export-preview-ym').val() || '').trim();
  94. if (!/^\d{4}-\d{2}$/.test(ym)) {
  95. Toastr.warning('请选择有效月份');
  96. return;
  97. }
  98. var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(ym));
  99. window.open(url, '_blank');
  100. });
  101. $(document).off('click.procuremenExportDetails', '.btn-export-details').on('click.procuremenExportDetails', '.btn-export-details', function (e) {
  102. e.preventDefault();
  103. var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
  104. if (!sid) {
  105. return;
  106. }
  107. var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
  108. Backend.api.open(url, '详情', {area: ['92%', '88%']});
  109. });
  110. },
  111. api: {
  112. currentYm: function () {
  113. var d = new Date();
  114. return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
  115. },
  116. bindevent: function () {
  117. Form.api.bindevent($('form[role=form]'));
  118. }
  119. }
  120. };
  121. return Controller;
  122. });