procuremenexport.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. sidePagination: 'server',
  43. pagination: true,
  44. pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
  45. pageList: [10, 15, 20, 25, 50],
  46. showJumpto: true,
  47. commonSearch: true,
  48. search: true,
  49. queryParams: function (params) {
  50. var ym = ($('#export-preview-ym').val() || '').trim();
  51. if (!/^\d{4}-\d{2}$/.test(ym)) {
  52. ym = Controller.api.currentYm();
  53. }
  54. params.ym = ym;
  55. return params;
  56. },
  57. columns: [
  58. [
  59. {field: 'ym', title: '月份', width: 88, operate: false},
  60. {field: 'CCYDH', title: '订单号', operate: 'LIKE'},
  61. {field: 'CYJMC', title: '印件名称', class: 'autocontent', operate: 'LIKE', formatter: Table.api.formatter.content},
  62. {field: 'CGYMC', title: '工序名称', class: 'autocontent', operate: 'LIKE', formatter: Table.api.formatter.content},
  63. {
  64. field: 'picked_supplier',
  65. title: '已选供应商',
  66. class: 'autocontent',
  67. operate: 'LIKE',
  68. formatter: Table.api.formatter.content
  69. },
  70. {field: 'createtime_text', title: '完结时间', width: 165, operate: 'LIKE'},
  71. {
  72. field: 'operate',
  73. title: '操作',
  74. width: 88,
  75. align: 'center',
  76. operate: false,
  77. formatter: function (value, row) {
  78. var sid = row && row.scydgy_id;
  79. if (!sid) {
  80. return '';
  81. }
  82. if (!exportCan('details')) {
  83. return '';
  84. }
  85. 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>';
  86. }
  87. }
  88. ]
  89. ]
  90. });
  91. Table.api.bindevent(table);
  92. $('.btn-refresh').off('click.procuremenExportRefresh').on('click.procuremenExportRefresh', function () {
  93. refreshTable();
  94. });
  95. $('#export-preview-ym').off('change.procuremenExportYm').on('change.procuremenExportYm', function () {
  96. refreshTable();
  97. });
  98. function buildMonthExportUrl(action) {
  99. var ym = ($('#export-preview-ym').val() || '').trim();
  100. if (!/^\d{4}-\d{2}$/.test(ym)) {
  101. Toastr.warning('请选择有效月份');
  102. return '';
  103. }
  104. var opts = table.bootstrapTable('getOptions') || {};
  105. var search = $.trim(opts.searchText || '');
  106. if (!search) {
  107. search = $.trim(table.closest('.bootstrap-table').find('.fixed-table-toolbar .search input').val() || '');
  108. }
  109. var filter = '';
  110. var op = '';
  111. try {
  112. var $cs = table.closest('.panel-intro').find('form.form-commonsearch');
  113. if ($cs.length) {
  114. var filterObj = {};
  115. var opObj = {};
  116. $cs.find('input[name], select[name]').each(function () {
  117. var $el = $(this);
  118. var name = ($el.attr('name') || '').trim();
  119. if (!name || name === 'search' || name.indexOf('[') >= 0) {
  120. return;
  121. }
  122. var val = $.trim($el.val() || '');
  123. if (val === '') {
  124. return;
  125. }
  126. filterObj[name] = val;
  127. var operate = $el.data('operate') || $el.attr('data-operate') || 'LIKE';
  128. opObj[name] = operate;
  129. });
  130. if (Object.keys(filterObj).length) {
  131. filter = JSON.stringify(filterObj);
  132. op = JSON.stringify(opObj);
  133. }
  134. }
  135. } catch (eFilter) {
  136. }
  137. var url = Fast.api.fixurl('procuremen/' + action + '?ym=' + encodeURIComponent(ym));
  138. if (search) {
  139. url += '&search=' + encodeURIComponent(search);
  140. }
  141. if (filter) {
  142. url += '&filter=' + encodeURIComponent(filter);
  143. }
  144. if (op) {
  145. url += '&op=' + encodeURIComponent(op);
  146. }
  147. return url;
  148. }
  149. $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
  150. if (!exportCan('export_month_outward')) {
  151. Toastr.error('无导出权限');
  152. return;
  153. }
  154. var url = buildMonthExportUrl('export_month_outward');
  155. if (url) {
  156. window.open(url, '_blank');
  157. }
  158. });
  159. $(document).off('click.procuremenExportQuote', '#btn-export-month-quote').on('click.procuremenExportQuote', '#btn-export-month-quote', function () {
  160. if (!exportCan('export_month_quote') && !exportCan('export_month_outward')) {
  161. Toastr.error('无导出权限');
  162. return;
  163. }
  164. var url = buildMonthExportUrl('export_month_quote');
  165. if (url) {
  166. window.open(url, '_blank');
  167. }
  168. });
  169. $(document).off('click.procuremenExportDetails', '.btn-export-details').on('click.procuremenExportDetails', '.btn-export-details', function (e) {
  170. e.preventDefault();
  171. var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
  172. if (!sid) {
  173. return;
  174. }
  175. var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
  176. Backend.api.open(url, '详情', {area: ['100%', '100%']});
  177. });
  178. },
  179. api: {
  180. currentYm: function () {
  181. var d = new Date();
  182. return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
  183. },
  184. bindevent: function () {
  185. Form.api.bindevent($('form[role=form]'));
  186. }
  187. }
  188. };
  189. return Controller;
  190. });