procuremenarchive.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. function archiveEscHtml(s) {
  3. return String(s == null ? '' : s)
  4. .replace(/&/g, '&')
  5. .replace(/</g, '&lt;')
  6. .replace(/>/g, '&gt;')
  7. .replace(/"/g, '&quot;');
  8. }
  9. function archiveCan(rule) {
  10. var map = (typeof Config !== 'undefined' && Config.procuremenAuth) ? Config.procuremenAuth : null;
  11. if (!map) {
  12. return false;
  13. }
  14. var key = String(rule || '').toLowerCase().replace(/^procuremen\//, '');
  15. var v = map[key];
  16. return v === true || v === 1 || v === '1';
  17. }
  18. var Controller = {
  19. index: function () {
  20. Table.api.init({
  21. extend: {
  22. index_url: 'procuremenarchive/index' + location.search,
  23. table: 'purchase_order',
  24. }
  25. });
  26. var table = $("#table");
  27. function archiveCellText(value) {
  28. var text = archiveEscHtml(value == null ? '' : value);
  29. return "<div class='autocontent-item' style='white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:100%;width:100%;box-sizing:border-box;'>" + text + "</div>";
  30. }
  31. /** 让省略宽度跟单元格实际宽度一致,避免列很宽却只显示 250px */
  32. function archiveFitAutocontent() {
  33. if ($('body').hasClass('fa-sidebar-resizing')) {
  34. return;
  35. }
  36. table.closest('.bootstrap-table').find('td.autocontent').each(function () {
  37. var td = this;
  38. var $item = $(td).children('.autocontent-item').first();
  39. if (!$item.length) {
  40. return;
  41. }
  42. var cs = window.getComputedStyle(td);
  43. var pad = (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
  44. var w = Math.floor(td.clientWidth - pad);
  45. if (w > 0) {
  46. $item.css({maxWidth: w + 'px', width: w + 'px'});
  47. }
  48. });
  49. }
  50. table.bootstrapTable({
  51. url: $.fn.bootstrapTable.defaults.extend.index_url,
  52. pk: 'scydgy_id',
  53. sortName: 'id',
  54. sortOrder: 'desc',
  55. commonSearch: true,
  56. search: true,
  57. pagination: true,
  58. smartDisplay: false,
  59. pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
  60. pageList: [10, 15, 20, 25, 50],
  61. showJumpto: true,
  62. columns: [
  63. [
  64. {checkbox: true, width: 36},
  65. {field: 'CCYDH', title: '订单号', operate: 'LIKE', width: 140, align: 'left'},
  66. {
  67. field: 'CYJMC',
  68. title: '印件名称',
  69. operate: 'LIKE',
  70. class: 'autocontent',
  71. formatter: function (value) {
  72. return archiveCellText(value);
  73. }
  74. },
  75. {
  76. field: 'CGYMC',
  77. title: '工序名称',
  78. operate: 'LIKE',
  79. width: 140,
  80. class: 'autocontent',
  81. formatter: function (value) {
  82. return archiveCellText(value);
  83. }
  84. },
  85. {
  86. field: 'pick_company_name',
  87. title: '已选供应商',
  88. operate: 'LIKE',
  89. width: 180,
  90. class: 'autocontent',
  91. formatter: function (value) {
  92. return archiveCellText(value);
  93. }
  94. },
  95. {
  96. field: 'createtime',
  97. title: '完结时间',
  98. operate: 'RANGE',
  99. addclass: 'datetimerange',
  100. autocomplete: false,
  101. width: 165,
  102. formatter: function (value, row) {
  103. if (row.createtime_text) {
  104. return row.createtime_text;
  105. }
  106. if (value == null || value === '') {
  107. return '';
  108. }
  109. var n = parseInt(value, 10);
  110. if (!isNaN(n) && n > 946684800) {
  111. return Table.api.formatter.datetime.call(this, value, row);
  112. }
  113. return String(value);
  114. }
  115. },
  116. {
  117. field: 'operate',
  118. title: '操作',
  119. width: 100,
  120. align: 'center',
  121. operate: false,
  122. table: table,
  123. formatter: function (value, row) {
  124. var sid = row && row.scydgy_id;
  125. if (!sid) {
  126. return '';
  127. }
  128. if (!archiveCan('details')) {
  129. return '';
  130. }
  131. return '<a href="javascript:;" class="btn btn-xs btn-info btn-archive-details" data-scydgy-id="' + sid + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>';
  132. },
  133. events: {}
  134. }
  135. ]
  136. ]
  137. });
  138. Table.api.bindevent(table);
  139. table.on('post-body.bs.table load-success.bs.table', function () {
  140. setTimeout(archiveFitAutocontent, 0);
  141. });
  142. $(window).off('resize.procuremenArchive').on('resize.procuremenArchive', function () {
  143. if ($('body').hasClass('fa-sidebar-resizing')) {
  144. return;
  145. }
  146. setTimeout(archiveFitAutocontent, 40);
  147. });
  148. $(document).off('fa.sidebar.resized.procuremenArchive fa.table.relayout.procuremenArchive')
  149. .on('fa.sidebar.resized.procuremenArchive fa.table.relayout.procuremenArchive', function () {
  150. setTimeout(archiveFitAutocontent, 40);
  151. });
  152. $(document).off('click.procuremenArchiveCommonSearch', 'button[name="commonSearch"]').on('click.procuremenArchiveCommonSearch', 'button[name="commonSearch"]', function () {
  153. setTimeout(archiveFitAutocontent, 150);
  154. });
  155. $(document).off('click.procuremenArchiveDetails', '.btn-archive-details').on('click.procuremenArchiveDetails', '.btn-archive-details', function (e) {
  156. e.preventDefault();
  157. var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
  158. if (!sid) {
  159. return;
  160. }
  161. var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
  162. Backend.api.open(url, '详情', {area: ['92%', '88%']});
  163. });
  164. $(document).off('click.procuremenArchiveAbandon', '#btn-archive-abandon').on('click.procuremenArchiveAbandon', '#btn-archive-abandon', function (e) {
  165. e.preventDefault();
  166. if (!archiveCan('archiveabandon')) {
  167. Toastr.error('无重新下发权限');
  168. return;
  169. }
  170. var sel = table.bootstrapTable('getSelections') || [];
  171. if (!sel.length) {
  172. Toastr.warning('请先勾选至少 1 条订单');
  173. return;
  174. }
  175. var idSet = {};
  176. var rowsHtml = '<table class="table table-bordered table-condensed" style="margin:8px 0 0;font-size:12px;">'
  177. + '<thead><tr><th>订单号</th><th>工序名称</th><th>印件名称</th></tr></thead><tbody>';
  178. $.each(sel, function (i, row) {
  179. var sid = row && row.scydgy_id;
  180. if (sid != null && sid !== '' && String(sid) !== '0') {
  181. idSet[String(sid)] = true;
  182. }
  183. rowsHtml += '<tr><td>' + archiveEscHtml(String(row.CCYDH || '').trim() || '—') + '</td>'
  184. + '<td>' + archiveEscHtml(String(row.CGYMC || '').trim() || '—') + '</td>'
  185. + '<td>' + archiveEscHtml(String(row.CYJMC || '').trim() || '—') + '</td></tr>';
  186. });
  187. rowsHtml += '</tbody></table>';
  188. var idList = Object.keys(idSet);
  189. if (!idList.length) {
  190. Toastr.warning('所选行无效,请重新勾选');
  191. return;
  192. }
  193. var abandonMsg = '<div style="text-align:left;line-height:1.65;font-size:13px;">'
  194. + '<p style="margin:0 0 8px 0;">即将从历史存证退回协助初选并重新下发以下 <strong>' + idList.length + '</strong> 个订单(历史记录会保留):</p>'
  195. + rowsHtml
  196. + '<p style="margin:10px 0 0;color:#a94442;"><strong>提示:</strong>退回后需重新选择供应商下发。</p></div>';
  197. Layer.confirm(abandonMsg, {
  198. title: '重新下发确认',
  199. area: ['560px', 'auto'],
  200. icon: 3,
  201. btn: ['确认重新下发', '取消']
  202. }, function (idx) {
  203. Layer.close(idx);
  204. Fast.api.ajax({
  205. url: 'procuremen/archiveabandon',
  206. type: 'POST',
  207. data: {
  208. scydgy_ids_json: JSON.stringify(idList),
  209. __token__: $('input[name=\'__token__\']').val() || Config.token
  210. }
  211. }, function () {
  212. table.bootstrapTable('refresh');
  213. return false;
  214. });
  215. });
  216. });
  217. },
  218. api: {
  219. bindevent: function () {
  220. Form.api.bindevent($("form[role=form]"));
  221. }
  222. }
  223. };
  224. return Controller;
  225. });