procuremen.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. /* 列表:Controller.index 内顺序执行。审核:Controller.review 内顺序执行。无其它本文件自定义函数。 */
  3. var Controller = {
  4. currYm: '',
  5. index: function () {
  6. var $layout = $('#procuremen-layout');
  7. var table = $('#table');
  8. var issuedOnlyCols = ['purchase_order_id'];
  9. var pendingOnlyCols = ['po_detail_count', 'po_amount_fill_cnt', 'po_delivery_fill_cnt'];
  10. var pickedOnlyCols = ['picked_supplier_name'];
  11. var allOnlyCols = ['ID'];
  12. Controller.currYm = ($layout.data('defaultYm') || '').toString();
  13. Controller.wffTab = 'all';
  14. Table.api.init({
  15. extend: {
  16. index_url: 'procuremen/index' + location.search,
  17. multi_url: 'procuremen/multi',
  18. import_url: 'procuremen/import',
  19. table: 'scydgy',
  20. }
  21. });
  22. $('.procuremen-ym-item').removeClass('active');
  23. $('.procuremen-ym-item[data-ym="' + Controller.currYm + '"]').addClass('active');
  24. $('.procuremen-wff-tabs').find('li').removeClass('active');
  25. $('.procuremen-wff-tabs').find('a[data-wff="' + Controller.wffTab + '"]').parent().addClass('active');
  26. $(document).off('click.procuremenWff', '.procuremen-wff-tabs a').on('click.procuremenWff', '.procuremen-wff-tabs a', function (e) {
  27. e.preventDefault();
  28. var t = $(this).data('wff');
  29. if (!t || t === Controller.wffTab) {
  30. return;
  31. }
  32. Controller.wffTab = t;
  33. $('.procuremen-wff-tabs').find('li').removeClass('active');
  34. $('.procuremen-wff-tabs').find('a[data-wff="' + Controller.wffTab + '"]').parent().addClass('active');
  35. /* 先清空:否则 show/hideColumn 会立刻用上一状态的 data 重绘一行/多行,直到 refresh 返回才消失 */
  36. try {
  37. table.bootstrapTable('removeAll');
  38. } catch (ignore) {
  39. }
  40. var issuedNow = Controller.wffTab === 'pending' || Controller.wffTab === 'done' || Controller.wffTab === 'picked';
  41. issuedOnlyCols.forEach(function (field) {
  42. try {
  43. table.bootstrapTable(issuedNow ? 'showColumn' : 'hideColumn', field);
  44. } catch (ignore) {
  45. }
  46. });
  47. pendingOnlyCols.forEach(function (field) {
  48. try {
  49. table.bootstrapTable(Controller.wffTab === 'pending' ? 'showColumn' : 'hideColumn', field);
  50. } catch (ignore) {
  51. }
  52. });
  53. pickedOnlyCols.forEach(function (field) {
  54. try {
  55. table.bootstrapTable(Controller.wffTab === 'picked' ? 'showColumn' : 'hideColumn', field);
  56. } catch (ignore) {
  57. }
  58. });
  59. allOnlyCols.forEach(function (field) {
  60. try {
  61. table.bootstrapTable(issuedNow ? 'hideColumn' : 'showColumn', field);
  62. } catch (ignore) {
  63. }
  64. });
  65. table.bootstrapTable('refresh', {pageNumber: 1});
  66. });
  67. $(document).off('click.procuremenYm', '.procuremen-ym-item').on('click.procuremenYm', '.procuremen-ym-item', function () {
  68. var ym = $(this).data('ym');
  69. if (!ym || ym === Controller.currYm) {
  70. return;
  71. }
  72. Controller.currYm = ym;
  73. $('.procuremen-ym-item').removeClass('active');
  74. $(this).addClass('active');
  75. try {
  76. table.bootstrapTable('removeAll');
  77. } catch (ignore) {
  78. }
  79. table.bootstrapTable('refresh', {pageNumber: 1});
  80. });
  81. $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
  82. var ymDefault = (Controller.currYm || '').toString();
  83. if (!/^\d{4}-\d{2}$/.test(ymDefault)) {
  84. ymDefault = ($layout.data('defaultYm') || '').toString();
  85. }
  86. if (!/^\d{4}-\d{2}$/.test(ymDefault)) {
  87. ymDefault = '';
  88. }
  89. if (!ymDefault) {
  90. var d = new Date();
  91. ymDefault = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
  92. }
  93. var escYm = String(ymDefault == null ? '' : ymDefault).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  94. var html = ''
  95. + '<div style="padding:14px 18px 6px;">'
  96. + '<p class="text-muted" style="margin:0 0 12px;font-size:13px;line-height:1.55;">'
  97. + '默认与左侧当前月份一致,可选择导出其它月份的下发明细。'
  98. + '</p>'
  99. + '<div class="form-group" style="margin-bottom:0;">'
  100. + '<input type="month" id="export-outward-ym-input" class="form-control" value="' + escYm + '" style="max-width:220px;" />'
  101. + '</div>'
  102. + '</div>';
  103. Layer.open({
  104. type: 1,
  105. title: '月份下发明细导出',
  106. area: ['440px', 'auto'],
  107. shadeClose: true,
  108. content: html,
  109. btn: ['导出明细'],
  110. yes: function (index, layero) {
  111. var v = (layero.find('#export-outward-ym-input').val() || '').trim();
  112. if (!/^\d{4}-\d{2}$/.test(v)) {
  113. Toastr.warning('请选择有效月份');
  114. return;
  115. }
  116. Layer.close(index);
  117. var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(v));
  118. setTimeout(function () {
  119. window.open(url, '_blank');
  120. }, 100);
  121. }
  122. });
  123. });
  124. table.on('post-header.bs.table', function () {
  125. var $host = $('#procuremen-toolbar-host');
  126. var $bt = table.closest('.bootstrap-table');
  127. if (!$host.length || !$bt.length) {
  128. return;
  129. }
  130. var $ft = $bt.children('.fixed-table-toolbar').first();
  131. if (!$ft.length) {
  132. $ft = $host.find('.fixed-table-toolbar').first();
  133. }
  134. if (!$ft.length) {
  135. return;
  136. }
  137. if ($ft.parent()[0] !== $host[0]) {
  138. $host.children('.fixed-table-toolbar').remove();
  139. $host.append($ft);
  140. var $src = $bt.closest('.procuremen-table-area').find('#toolbar').first();
  141. if ($src.length && !$src.children().length) {
  142. $src.addClass('procuremen-toolbar-empty');
  143. }
  144. }
  145. $ft.find('.procuremen-toolbar-search-wrap').removeClass('procuremen-toolbar-search-wrap');
  146. var $search = $ft.find('.search').first();
  147. if (!$search.length) {
  148. return;
  149. }
  150. var $right = $search.closest('.columns, .pull-right').first();
  151. if (!$right.length || ($ft[0] && !$.contains($ft[0], $right[0]))) {
  152. return;
  153. }
  154. $ft.children().each(function () {
  155. var $c = $(this);
  156. if ($c.is('.bars, .bs-bars') || $c[0] === $right[0]) {
  157. return;
  158. }
  159. var mergeToolbarExtras = $c.hasClass('columns')
  160. || $c.hasClass('pull-right')
  161. || ($c.hasClass('btn-group') && $c.find('.search').length === 0);
  162. if (!mergeToolbarExtras || $c.find('.search').length) {
  163. return;
  164. }
  165. if ($c.hasClass('btn-group') && !$c.hasClass('columns')) {
  166. $c.appendTo($right);
  167. } else {
  168. $c.children().appendTo($right);
  169. if (!$c.children().length) {
  170. $c.remove();
  171. }
  172. }
  173. });
  174. $ft.find('.search').first().prependTo($right);
  175. $right.addClass('procuremen-toolbar-search-wrap');
  176. });
  177. var indexInitWffTab = Controller.wffTab;
  178. var indexShowall = indexInitWffTab === 'all';
  179. var indexShowIssued = indexInitWffTab === 'pending' || indexInitWffTab === 'done' || indexInitWffTab === 'picked';
  180. var indexShowPendingOnly = indexInitWffTab === 'pending';
  181. var indexShowPickedOnly = indexInitWffTab === 'picked';
  182. function procuremenEscAttr(s) {
  183. return String(s == null ? '' : s)
  184. .replace(/&/g, '&amp;')
  185. .replace(/"/g, '&quot;')
  186. .replace(/'/g, '&#39;');
  187. }
  188. var indexTableColumns = [
  189. // {field: 'ID', title: __('ID'), operate: 'LIKE', table: 'a', width: 100, align: 'center',
  190. // visible: indexShowall,
  191. // formatter: function (v) {
  192. // return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
  193. // }
  194. // },
  195. // {field: 'purchase_order_id',title: 'ID',operate: false,table: 'a',width: 88,align: 'center',
  196. // visible: indexShowIssued,
  197. // formatter: function (v) {
  198. // return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
  199. // }
  200. // },
  201. {field: 'CCYDH', title: __('订单号'), operate: 'LIKE', table: 'b', width: 100, align: 'center'},
  202. {field: 'CYJMC', title: __('印件名称'), operate: 'LIKE', table: 'b', width: 270, align: 'left'},
  203. {field: 'CGYMC', title: __('工序名称'), operate: 'LIKE', table: 'a', width: 100, align: 'center'},
  204. {field: 'CDW', title: __('单位'), operate: 'LIKE', table: 'a', width: 50, align: 'center'},
  205. {field: 'NGZL', title: __('工作量'), operate: false, table: 'a', width: 80, align: 'center'},
  206. {field: 'This_quantity', title: '本次数量', operate: false, table: 'a', width: 96, align: 'center',
  207. visible: true,
  208. formatter: function (v, row, index) {
  209. var tab = Controller.wffTab || 'all';
  210. if (tab === 'all') {
  211. var val = (v != null && v !== '') ? String(v) : '';
  212. return '<input type="text" class="form-control input-sm procuremen-po-field procuremen-po-qty" '
  213. + 'style="min-width:72px;max-width:96px;height:28px;padding:2px 6px;" '
  214. + 'data-field="This_quantity" data-row-index="' + index + '" value="'
  215. + procuremenEscAttr(val) + '" placeholder="填写" autocomplete="off"/>';
  216. }
  217. return (v == null || v === '') ? '' : String(v);
  218. }
  219. },
  220. {field: 'ceilingPrice', title: '最高限价', operate: false, table: 'a', width: 96, align: 'center',
  221. visible: true,
  222. formatter: function (value, row, index) {
  223. var tab = Controller.wffTab || 'all';
  224. var v = value;
  225. if (v == null || v === '') {
  226. v = (row && row.ceilingPrice != null && row.ceilingPrice !== '') ? row.ceilingPrice
  227. : (row && row.ceiling_price != null ? row.ceiling_price : '');
  228. }
  229. if (tab === 'all') {
  230. var val = (v != null && v !== '') ? String(v) : '';
  231. return '<input type="text" class="form-control input-sm procuremen-po-field procuremen-po-price" '
  232. + 'style="min-width:72px;max-width:96px;height:28px;padding:2px 6px;" '
  233. + 'data-field="ceilingPrice" data-row-index="' + index + '" value="'
  234. + procuremenEscAttr(val) + '" placeholder="填写" autocomplete="off"/>';
  235. }
  236. return (v == null || v === '') ? '' : String(v);
  237. }
  238. },
  239. {field: 'po_detail_count',title: '已下发数量',operate: false,table: 'a',width: 96,align: 'center',
  240. visible: indexShowPendingOnly,
  241. formatter: function (v) {
  242. return v != null && v !== '' ? String(v) : '0';
  243. }
  244. },
  245. {field: 'po_amount_fill_cnt',title: '已上报金额',operate: false,table: 'a',width: 96,align: 'center',
  246. visible: indexShowPendingOnly,
  247. formatter: function (v) {
  248. return v != null && v !== '' ? String(v) : '0';
  249. }
  250. },
  251. {field: 'po_delivery_fill_cnt',title: '已上报货期',operate: false,table: 'a',width: 96,align: 'center',
  252. visible: indexShowPendingOnly,
  253. formatter: function (v) {
  254. return v != null && v !== '' ? String(v) : '0';
  255. }
  256. },
  257. {field: 'picked_supplier_name', title: '已选供应商', operate: false, table: 'a', width: 200, align: 'left',
  258. visible: indexShowPickedOnly,
  259. formatter: function (v) {
  260. return v != null && v !== '' ? String(v) : '';
  261. }
  262. },
  263. {field: 'CDF', title: __('订法'), operate: false, table: 'a', width: 100, align: 'center'},
  264. {field: 'cGzzxMc', title: __('外厂单位'), operate: 'LIKE', table: 'a', width: 220, align: 'center'},
  265. {field: 'MBZ', title: __('备注'), operate: 'LIKE', table: 'a', width: 150, align: 'center'},
  266. {field: 'dStamp', title: __('操作日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'a', width: 165, align: 'center'},
  267. {field: 'dputrecord', title: __('提交日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'b', width: 170, align: 'center'},
  268. {field: 'cywyxm', title: __('业务员'), operate: 'LIKE', table: 'b', width: 80, align: 'center'},
  269. {field: 'operate',title: '操作',width: 260,align: 'center',fixed: 'right',
  270. table: table,
  271. formatter: function (value, row, index) {
  272. var tab = Controller.wffTab || 'all';
  273. var pk = row && (row.ID != null ? row.ID : row.id);
  274. if (!row || pk == null || pk === '' || String(pk) === '0') {
  275. return '';
  276. }
  277. var area = ' data-area=\'["76%","100%"]\'';
  278. var parts = [];
  279. if (tab === 'all') {
  280. //未发
  281. parts.push('<a class="btn btn-xs btn-info procuremen-op-open procuremen-btn-review"' + area + ' href="procuremen/review" data-row-index="' + index + '" title="审核"><i class="fa fa-check"></i> 审核</a>');
  282. parts.push('<a class="btn btn-xs btn-warning procuremen-btn-finish" href="javascript:;" data-row-index="' + index + '" title="完结"><i class="fa fa-flag-checkered"></i> 完结</a>');
  283. } else if (tab === 'pending') {
  284. //已下发
  285. parts.push('<a class="btn btn-xs btn-success procuremen-op-open procuremen-btn-outward"' + area + ' href="procuremen/outward_detail" data-row-index="' + index + '" title="采购确认"><i class="fa fa-shopping-cart"></i> 采购确认</a>');
  286. parts.push('<a class="btn btn-xs btn-default procuremen-op-open procuremen-btn-details"' + area + ' href="procuremen/details" data-row-index="' + index + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>');
  287. } else if (tab === 'picked') {
  288. parts.push('<a class="btn btn-xs btn-default procuremen-op-open procuremen-btn-details"' + area + ' href="procuremen/details" data-row-index="' + index + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>');
  289. } else {
  290. //已完结
  291. parts.push('<a class="btn btn-xs btn-default procuremen-op-open procuremen-btn-details"' + area + ' href="procuremen/details" data-row-index="' + index + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>');
  292. }
  293. return '<div class="btn-group">' + parts.join(' ') + '</div>';
  294. },
  295. events: {}
  296. }
  297. ];
  298. var $wbh = $layout.find('.procuremen-main .widget-body');
  299. var tableHeight = !$wbh.length ? 400 : Math.max(168, $(window).height() - $wbh.offset().top - 56);
  300. table.bootstrapTable({
  301. url: $.fn.bootstrapTable.defaults.extend.index_url,
  302. pk: 'ID',
  303. sortName: 'a.ID',
  304. width: 'auto',
  305. height: tableHeight,
  306. fixedColumns: true,
  307. fixedRightNumber: 1,
  308. clickToSelect: false,
  309. dblClickToEdit: false,
  310. commonSearch: false,
  311. showToggle: false,
  312. showExport: false,
  313. smartDisplay: false,
  314. queryParams: function (params) {
  315. params.ym = Controller.currYm;
  316. params.wff_tab = Controller.wffTab;
  317. return params;
  318. },
  319. columns: [indexTableColumns]
  320. });
  321. Table.api.bindevent(table);
  322. (function () {
  323. var $wrap = table.closest('.bootstrap-table');
  324. function procuremenSetFixedRightStaleLoading(hide) {
  325. $wrap.find('.fixed-columns-right').toggleClass('procuremen-hide-fixed-right-loading', !!hide);
  326. }
  327. table.on('refresh.bs.table', function () {
  328. if ($wrap.find('.fixed-table-loading').is(':visible')) {
  329. procuremenSetFixedRightStaleLoading(true);
  330. }
  331. });
  332. table.on('load-success.bs.table load-error.bs.table', function () {
  333. procuremenSetFixedRightStaleLoading(false);
  334. });
  335. })();
  336. var $bt = table.closest('.bootstrap-table');
  337. var procuremenPoBlurTimer = null;
  338. function procuremenNormPoCell(v) {
  339. if (v == null || v === '') {
  340. return '';
  341. }
  342. return String(v).trim();
  343. }
  344. if ($bt.length) {
  345. $bt.off('blur.procuremenPoSave', '.procuremen-po-field').on('blur.procuremenPoSave', '.procuremen-po-field', function () {
  346. if (Controller.wffTab !== 'all') {
  347. return;
  348. }
  349. var $inp = $(this);
  350. clearTimeout(procuremenPoBlurTimer);
  351. procuremenPoBlurTimer = setTimeout(function () {
  352. procuremenPoBlurTimer = null;
  353. var rowIdx = parseInt($inp.data('rowIndex'), 10);
  354. if (isNaN(rowIdx)) {
  355. return;
  356. }
  357. var dataRows = table.bootstrapTable('getData');
  358. if (!dataRows[rowIdx]) {
  359. return;
  360. }
  361. var $qty = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]');
  362. var $price = $bt.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]');
  363. var q = ($qty.length ? String($qty.val()) : '').trim();
  364. var p = ($price.length ? String($price.val()) : '').trim();
  365. var baseRow = dataRows[rowIdx];
  366. var origQ = procuremenNormPoCell(baseRow.This_quantity);
  367. var origP = procuremenNormPoCell(baseRow.ceilingPrice);
  368. if (origP === '' && baseRow.ceiling_price != null && baseRow.ceiling_price !== '') {
  369. origP = procuremenNormPoCell(baseRow.ceiling_price);
  370. }
  371. /* 与当前行数据一致则不调接口、不弹*/
  372. if (q === origQ && p === origP) {
  373. return;
  374. }
  375. var row = $.extend({}, baseRow);
  376. row.This_quantity = q;
  377. row.ceilingPrice = p;
  378. Fast.api.ajax({
  379. url: 'procuremen/completeDirectly',
  380. type: 'POST',
  381. data: {
  382. row_json: JSON.stringify(row),
  383. finish: '0',
  384. __token__: $('input[name=\'__token__\']').val() || ''
  385. }
  386. }, function () {
  387. try {
  388. table.bootstrapTable('updateRow', {
  389. index: rowIdx,
  390. row: $.extend({}, baseRow, {This_quantity: q, ceilingPrice: p})
  391. });
  392. } catch (ignore) {
  393. }
  394. Toastr.success('操作成功');
  395. return false;
  396. });
  397. }, 220);
  398. });
  399. }
  400. if ($bt.length && $bt[0]) {
  401. var tableRoot = $bt[0];
  402. Controller._procuremenOpTableClick = function (e) {
  403. var t = e.target;
  404. if (!t || typeof t.closest !== 'function') {
  405. return;
  406. }
  407. var finish = t.closest('a.procuremen-btn-finish');
  408. if (finish && tableRoot.contains(finish) && !finish.classList.contains('disabled')) {
  409. e.preventDefault();
  410. if (typeof e.stopImmediatePropagation === 'function') {
  411. e.stopImmediatePropagation();
  412. }
  413. e.stopPropagation();
  414. var $f = $(finish);
  415. var rowIdxF = parseInt($f.data('rowIndex'), 10);
  416. var dataRowsF = table.bootstrapTable('getData');
  417. var rowF = !isNaN(rowIdxF) && dataRowsF[rowIdxF] !== undefined ? dataRowsF[rowIdxF] : null;
  418. if (!rowF) {
  419. Toastr.error('无法取得行数据');
  420. return;
  421. }
  422. var $qtyF = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdxF + '"]');
  423. var $priceF = $bt.find('.procuremen-po-price[data-row-index="' + rowIdxF + '"]');
  424. if ($qtyF.length) {
  425. rowF = $.extend({}, rowF, {This_quantity: String($qtyF.val()).trim()});
  426. }
  427. if ($priceF.length) {
  428. rowF = $.extend({}, rowF, {ceilingPrice: String($priceF.val()).trim()});
  429. }
  430. Layer.confirm('确认后仅将本单标记为已完结。', function (idx) {
  431. Layer.close(idx);
  432. Fast.api.ajax({
  433. url: 'procuremen/completeDirectly',
  434. type: 'POST',
  435. data: {
  436. row_json: JSON.stringify(rowF),
  437. finish: '1',
  438. __token__: $('input[name=\'__token__\']').val() || ''
  439. }
  440. }, function () {
  441. table.bootstrapTable('refresh');
  442. Toastr.success('操作成功');
  443. return false;
  444. });
  445. });
  446. return;
  447. }
  448. var details = t.closest('a.procuremen-btn-details');
  449. if (details && tableRoot.contains(details) && !details.classList.contains('disabled')) {
  450. e.preventDefault();
  451. if (typeof e.stopImmediatePropagation === 'function') {
  452. e.stopImmediatePropagation();
  453. }
  454. e.stopPropagation();
  455. var $d = $(details);
  456. var rowIdxD = parseInt($d.data('rowIndex'), 10);
  457. var dataRowsD = table.bootstrapTable('getData');
  458. var rowD = !isNaN(rowIdxD) && dataRowsD[rowIdxD] !== undefined ? dataRowsD[rowIdxD] : null;
  459. var detUrl;
  460. if (rowD) {
  461. detUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/details', rowD, table));
  462. } else {
  463. detUrl = Backend.api.replaceids(details, $d.attr('href'));
  464. }
  465. var tabForDet = Controller.wffTab ? Controller.wffTab : 'done';
  466. if (String(detUrl).indexOf('wff_tab=') === -1) {
  467. detUrl += (detUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tabForDet);
  468. }
  469. var $ad = $(details);
  470. var optsd = $.extend({}, $ad.data() || {});
  471. var titled = $ad.attr('title') || $ad.data('title') || '详情';
  472. var buttond = Backend.api.gettablecolumnbutton(optsd);
  473. var layerOptsd = $.extend({}, optsd);
  474. if (buttond && typeof buttond.callback === 'function') {
  475. layerOptsd.callback = buttond.callback;
  476. }
  477. if (buttond && buttond.layerArea && buttond.layerArea.length) {
  478. layerOptsd.area = buttond.layerArea;
  479. }
  480. var winNd = $ad.data('window') || 'self';
  481. var winD = window[winNd] || window;
  482. if (!winD.Backend || !winD.Backend.api) {
  483. Toastr.error('Backend 未就绪,请刷新页面');
  484. return;
  485. }
  486. winD.Backend.api.open(detUrl, titled, layerOptsd);
  487. return;
  488. }
  489. var outward = t.closest('a.procuremen-btn-outward');
  490. if (outward && !outward.classList.contains('disabled')) {
  491. e.preventDefault();
  492. if (typeof e.stopImmediatePropagation === 'function') {
  493. e.stopImmediatePropagation();
  494. }
  495. e.stopPropagation();
  496. var $o = $(outward);
  497. var oOpts = $.extend({}, $o.data() || {});
  498. var rowIdx = parseInt(oOpts.rowIndex, 10);
  499. var dataRows = table.bootstrapTable('getData');
  500. var row = !isNaN(rowIdx) && dataRows[rowIdx] !== undefined ? dataRows[rowIdx] : null;
  501. var tab = Controller.wffTab ? Controller.wffTab : 'all';
  502. var base = 'procuremen/outward_detail?wff_tab=' + encodeURIComponent(tab);
  503. var outUrl;
  504. if (row) {
  505. outUrl = Fast.api.fixurl(Table.api.replaceurl(base, row, table));
  506. } else {
  507. outUrl = Backend.api.replaceids(outward, $o.attr('href'));
  508. if (String(outUrl).indexOf('wff_tab=') === -1) {
  509. outUrl += (outUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tab);
  510. }
  511. }
  512. var $a = $(outward);
  513. var opts = $.extend({}, $a.data() || {});
  514. var title = $a.attr('title') || $a.data('title') || $a.data('original-title');
  515. var button = Backend.api.gettablecolumnbutton(opts);
  516. var layerOpts = $.extend({}, opts);
  517. if (button && typeof button.callback === 'function') {
  518. layerOpts.callback = button.callback;
  519. }
  520. if (button && button.layerArea && button.layerArea.length) {
  521. layerOpts.area = button.layerArea;
  522. }
  523. var winName = $a.data('window') || 'self';
  524. var win = window[winName] || window;
  525. if (!win.Backend || !win.Backend.api) {
  526. Toastr.error('Backend 未就绪,请刷新页面');
  527. return;
  528. }
  529. if (typeof layerOpts.confirm !== 'undefined') {
  530. Layer.confirm(layerOpts.confirm, function (index) {
  531. win.Backend.api.open(outUrl, title, layerOpts);
  532. Layer.close(index);
  533. });
  534. } else {
  535. win.Backend.api.open(outUrl, title, layerOpts);
  536. }
  537. return;
  538. }
  539. var review = t.closest('a.procuremen-btn-review');
  540. if (!review || !tableRoot.contains(review) || review.classList.contains('disabled')) {
  541. return;
  542. }
  543. e.preventDefault();
  544. if (typeof e.stopImmediatePropagation === 'function') {
  545. e.stopImmediatePropagation();
  546. }
  547. e.stopPropagation();
  548. var $a2 = $(review);
  549. var rowIdx2 = parseInt($a2.data('rowIndex'), 10);
  550. var dataRows2 = table.bootstrapTable('getData');
  551. var row2 = !isNaN(rowIdx2) && dataRows2[rowIdx2] !== undefined ? dataRows2[rowIdx2] : null;
  552. var revUrl;
  553. if (row2) {
  554. revUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/review', row2, table));
  555. } else {
  556. revUrl = Backend.api.replaceids(review, $a2.attr('href'));
  557. }
  558. var opts2 = $.extend({}, $a2.data() || {});
  559. var title2 = $a2.attr('title') || $a2.data('title') || $a2.data('original-title');
  560. var button2 = Backend.api.gettablecolumnbutton(opts2);
  561. var layerOpts2 = $.extend({}, opts2);
  562. if (button2 && typeof button2.callback === 'function') {
  563. layerOpts2.callback = button2.callback;
  564. }
  565. if (button2 && button2.layerArea && button2.layerArea.length) {
  566. layerOpts2.area = button2.layerArea;
  567. }
  568. var winName2 = $a2.data('window') || 'self';
  569. var win2 = window[winName2] || window;
  570. if (!win2.Backend || !win2.Backend.api) {
  571. Toastr.error('Backend 未就绪,请刷新页面');
  572. return;
  573. }
  574. if (typeof layerOpts2.confirm !== 'undefined') {
  575. Layer.confirm(layerOpts2.confirm, function (index) {
  576. win2.Backend.api.open(revUrl, title2, layerOpts2);
  577. Layer.close(index);
  578. });
  579. } else {
  580. win2.Backend.api.open(revUrl, title2, layerOpts2);
  581. }
  582. };
  583. tableRoot.addEventListener('click', Controller._procuremenOpTableClick, true);
  584. }
  585. $layout.find('.procuremen-main').off('click.procuremenTbRefresh').on('click.procuremenTbRefresh', '#procuremen-toolbar-host .btn-refresh', function (e) {
  586. e.preventDefault();
  587. table.bootstrapTable('refresh');
  588. });
  589. table.on('refresh.bs.table', function () {
  590. $('#procuremen-toolbar-host .btn-refresh .fa').addClass('fa-spin');
  591. setTimeout(function () {
  592. var $host2 = $('#procuremen-toolbar-host');
  593. var $bt2 = table.closest('.bootstrap-table');
  594. if (!$host2.length || !$bt2.length) {
  595. return;
  596. }
  597. var $ft2 = $bt2.children('.fixed-table-toolbar').first();
  598. if (!$ft2.length) {
  599. $ft2 = $host2.find('.fixed-table-toolbar').first();
  600. }
  601. if (!$ft2.length) {
  602. return;
  603. }
  604. if ($ft2.parent()[0] !== $host2[0]) {
  605. $host2.children('.fixed-table-toolbar').remove();
  606. $host2.append($ft2);
  607. var $src2 = $bt2.closest('.procuremen-table-area').find('#toolbar').first();
  608. if ($src2.length && !$src2.children().length) {
  609. $src2.addClass('procuremen-toolbar-empty');
  610. }
  611. }
  612. $ft2.find('.procuremen-toolbar-search-wrap').removeClass('procuremen-toolbar-search-wrap');
  613. var $search2 = $ft2.find('.search').first();
  614. if (!$search2.length) {
  615. return;
  616. }
  617. var $right2 = $search2.closest('.columns, .pull-right').first();
  618. if (!$right2.length || ($ft2[0] && !$.contains($ft2[0], $right2[0]))) {
  619. return;
  620. }
  621. $ft2.children().each(function () {
  622. var $c2 = $(this);
  623. if ($c2.is('.bars, .bs-bars') || $c2[0] === $right2[0]) {
  624. return;
  625. }
  626. var merge2 = $c2.hasClass('columns')
  627. || $c2.hasClass('pull-right')
  628. || ($c2.hasClass('btn-group') && $c2.find('.search').length === 0);
  629. if (!merge2 || $c2.find('.search').length) {
  630. return;
  631. }
  632. if ($c2.hasClass('btn-group') && !$c2.hasClass('columns')) {
  633. $c2.appendTo($right2);
  634. } else {
  635. $c2.children().appendTo($right2);
  636. if (!$c2.children().length) {
  637. $c2.remove();
  638. }
  639. }
  640. });
  641. $ft2.find('.search').first().prependTo($right2);
  642. $right2.addClass('procuremen-toolbar-search-wrap');
  643. }, 0);
  644. });
  645. table.on('post-body.bs.table', function () {
  646. $('#procuremen-toolbar-host .btn-refresh .fa').removeClass('fa-spin');
  647. });
  648. $(window).off('resize.procuremenIndex').on('resize.procuremenIndex', function () {
  649. try {
  650. var $wbr = $layout.find('.procuremen-main .widget-body');
  651. var h = !$wbr.length ? 400 : Math.max(168, $(window).height() - $wbr.offset().top - 56);
  652. table.bootstrapTable('resetView', {height: h});
  653. } catch (ignore) {
  654. }
  655. });
  656. },
  657. add: function () {
  658. Controller.api.bindevent();
  659. },
  660. edit: function () {
  661. Controller.api.bindevent();
  662. },
  663. outward_detail: function () {
  664. Controller.api.bindevent();
  665. var $wrap = $('.outward-detail-wrap');
  666. if (!$wrap.length || !$('#btn-pod-purchase-confirm').length) {
  667. return;
  668. }
  669. var scydgyId = String($wrap.attr('data-scydgy-id') || '').trim();
  670. if (!scydgyId) {
  671. return;
  672. }
  673. var purchaseOrderId = String($wrap.attr('data-purchase-order-id') || '').trim();
  674. $wrap.off('.procuremenPurchaseConfirm');
  675. $wrap.on('change.procuremenPurchaseConfirm', '.pod-pick-cb', function () {
  676. if (this.checked) {
  677. $wrap.find('.pod-pick-cb').not(this).prop('checked', false);
  678. }
  679. });
  680. $wrap.on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm', function () {
  681. var FastRef = (typeof Fast !== 'undefined' && Fast.api) ? Fast
  682. : (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api ? parent.Fast : null);
  683. if (!FastRef || !FastRef.api) {
  684. if (typeof parent !== 'undefined' && parent.Toastr) {
  685. parent.Toastr.error('页面未就绪,请刷新后重试');
  686. }
  687. return;
  688. }
  689. var $cbs = $wrap.find('.pod-pick-cb');
  690. var all = $cbs.map(function () { return String($(this).val()); }).get();
  691. var sel = $cbs.filter(':checked').val();
  692. if (!sel) {
  693. var L = (typeof parent !== 'undefined' && parent.Layer) ? parent.Layer : (typeof Layer !== 'undefined' ? Layer : null);
  694. if (L && typeof L.msg === 'function') {
  695. L.msg('请勾选一条明细');
  696. } else if (typeof Toastr !== 'undefined') {
  697. Toastr.warning('请勾选一条明细');
  698. }
  699. return;
  700. }
  701. var unsel = $.grep(all, function (id) { return String(id) !== String(sel); });
  702. var selArr = [String(sel)];
  703. var tk = $('input[name=\'__token__\']').val() || '';
  704. function podRowCompany($tr) {
  705. if (!$tr || !$tr.length) {
  706. return '(无名称)';
  707. }
  708. var $tds = $tr.children('td');
  709. if ($tds.length < 8) {
  710. return '(无名称)';
  711. }
  712. var t = $.trim($tds.eq(6).text());
  713. return t !== '' ? t : '(无名称)';
  714. }
  715. function escHtml(s) {
  716. return String(s)
  717. .replace(/&/g, '&amp;')
  718. .replace(/</g, '&lt;')
  719. .replace(/>/g, '&gt;')
  720. .replace(/"/g, '&quot;');
  721. }
  722. var $trOk = $cbs.filter(':checked').closest('tr');
  723. var okName = podRowCompany($trOk);
  724. var unNames = [];
  725. $cbs.not(':checked').each(function () {
  726. unNames.push(podRowCompany($(this).closest('tr')));
  727. });
  728. var nUn = unNames.length;
  729. var unListText = nUn ? (nUn <= 4 ? unNames.join('、') : (unNames.slice(0, 3).join('、') + ' 等共' + nUn + '家')) : '—';
  730. var confirmHtml = ''
  731. + '<div style="text-align:left;line-height:1.75;font-size:13px;">'
  732. + '<p style="margin:0 0 10px 0;">提交后将<strong>立即发送短信</strong>,且<strong>不可撤回或更改</strong>。请确认以下通知:</p>'
  733. + '<ul style="margin:0;padding-left:1.2em;">'
  734. + '<li style="margin-bottom:6px;"><strong>已选中 1 条</strong>:采购确认结果视为「<strong>通过</strong>」,将向 <strong>' + escHtml(okName) + '</strong> 发送「已通过」短信;</li>'
  735. + '<li><strong>未选中 ' + nUn + ' 条</strong>:视为「<strong>未通过</strong>」,将向对应供应商发送「未通过」短信。</li>'
  736. + '</ul>'
  737. + (nUn ? ('<p style="margin:8px 0 0 0;color:#888;font-size:12px;">未选中涉及:' + escHtml(unListText) + '</p>') : '')
  738. + '<p style="margin:12px 0 0 0;"><strong>是否确认提交?</strong></p>'
  739. + '</div>';
  740. var Lr = (typeof parent !== 'undefined' && parent.Layer) ? parent.Layer : (typeof Layer !== 'undefined' ? Layer : null);
  741. if (!Lr || typeof Lr.confirm !== 'function') {
  742. if (typeof Toastr !== 'undefined') {
  743. Toastr.error('弹层组件未就绪,请刷新后重试');
  744. }
  745. return;
  746. }
  747. Lr.confirm(confirmHtml, {
  748. icon: 3,
  749. title: '采购确认 — 短信通知',
  750. area: ['480px', 'auto'],
  751. btn: ['确定提交', '取消']
  752. }, function (idx) {
  753. Lr.close(idx);
  754. FastRef.api.ajax({
  755. url: FastRef.api.fixurl('procuremen/purchaseConfirmPick'),
  756. type: 'POST',
  757. data: {
  758. scydgy_id: scydgyId,
  759. purchase_order_id: purchaseOrderId,
  760. selected_id: sel,
  761. selected_ids: JSON.stringify(selArr),
  762. unselected_ids: JSON.stringify(unsel),
  763. all_detail_ids: JSON.stringify(all),
  764. __token__: tk
  765. }
  766. }, function () {
  767. if (typeof parent !== 'undefined' && parent.Layer) {
  768. var ix = parent.Layer.getFrameIndex(window.name);
  769. if (typeof ix !== 'undefined') {
  770. parent.Layer.close(ix);
  771. }
  772. }
  773. var p$ = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : (typeof parent !== 'undefined' ? parent.$ : null);
  774. if (p$) {
  775. var $doneTab = p$('.procuremen-wff-tabs a[data-wff="done"]');
  776. if ($doneTab.length) {
  777. $doneTab.trigger('click');
  778. } else if (p$('#table').length) {
  779. p$('#table').bootstrapTable('refresh');
  780. }
  781. }
  782. });
  783. });
  784. });
  785. },
  786. details: function () {
  787. Controller.api.bindevent();
  788. },
  789. review: function () {
  790. var ids = window.Fast && Fast.api ? Fast.api.query('ids') : null;
  791. if (ids === null || ids === '') {
  792. Toastr.error('请刷新页面后重试');
  793. return;
  794. }
  795. var $ptable = parent.$('#table');
  796. if (!$ptable.length) {
  797. Toastr.error('请刷新页面后重试');
  798. return;
  799. }
  800. var pk = $ptable.bootstrapTable('getOptions').pk || 'ID';
  801. var row = null;
  802. $.each($ptable.bootstrapTable('getData'), function (i, r) {
  803. if (String(r[pk]) === String(ids)) {
  804. row = r;
  805. return false;
  806. }
  807. });
  808. if (!row) {
  809. Toastr.error('请刷新页面后重试');
  810. return;
  811. }
  812. $('#review-ccydh').text(row.CCYDH || '');
  813. $('#review-cyjmc').text(row.CYJMC || '');
  814. $('#review-CGYMC').text(row.CGYMC || '');
  815. $('#review-CDW').text(row.CDW != null && row.CDW !== '' ? row.CDW : '');
  816. $('#review-NGZL').text(row.NGZL != null && row.NGZL !== '' ? row.NGZL : '');
  817. $('#review-CDF').text(row.CDF || '');
  818. $('#review-cGzzxMc').text(row.cGzzxMc || '');
  819. var qDisp = row.This_quantity != null && String(row.This_quantity).trim() !== '' ? String(row.This_quantity).trim()
  820. : (row.this_quantity != null && String(row.this_quantity).trim() !== '' ? String(row.this_quantity).trim() : '');
  821. var pDisp = row.ceilingPrice != null && String(row.ceilingPrice).trim() !== '' ? String(row.ceilingPrice).trim()
  822. : (row.ceiling_price != null && String(row.ceiling_price).trim() !== '' ? String(row.ceiling_price).trim() : '');
  823. $('#review-qty-display').text(qDisp !== '' ? qDisp : '—');
  824. $('#review-price-display').text(pDisp !== '' ? pDisp : '—');
  825. $('#c-row-json').val(JSON.stringify(row));
  826. var reviewCompaniesAll = [];
  827. var activeReviewCategory = null;
  828. var reviewCompanySearchQ = '';
  829. var reviewSelectedMap = {};
  830. var reviewSearchTimer = null;
  831. function syncReviewSelectedSummary() {
  832. var entries = [];
  833. $.each(reviewSelectedMap, function (k, c) {
  834. if (!c) {
  835. return;
  836. }
  837. var t = String(c.name || c.company_name || '').trim() || '(无名称)';
  838. entries.push({ k: k, label: t });
  839. });
  840. entries.sort(function (a, b) {
  841. return a.label.localeCompare(b.label, 'zh-CN');
  842. });
  843. var n = entries.length;
  844. $('#review-selected-count').text(String(n));
  845. $('#review-selected-tags').empty();
  846. if (!n) {
  847. $('#review-selected-empty').show();
  848. return;
  849. }
  850. $('#review-selected-empty').hide();
  851. $.each(entries, function (i, e) {
  852. var $chip = $('<span class="review-selected-chip"/>').attr('title', e.label);
  853. $chip.data('reviewSelKey', e.k);
  854. $chip.append(
  855. $('<span class="review-chip-text"/>').text(e.label),
  856. $('<button type="button" class="review-chip-remove" title="取消选择" aria-label="取消选择"/>').text('\u00d7')
  857. );
  858. $('#review-selected-tags').append($chip);
  859. });
  860. }
  861. syncReviewSelectedSummary();
  862. $('#review-selected-tags').off('click.reviewChipRemove').on('click.reviewChipRemove', '.review-chip-remove', function (e) {
  863. e.preventDefault();
  864. e.stopPropagation();
  865. var k = $(this).closest('.review-selected-chip').data('reviewSelKey');
  866. if (k == null || k === '') {
  867. return;
  868. }
  869. delete reviewSelectedMap[k];
  870. $('#review-company-tbody .review-company-cb').each(function () {
  871. var c = $(this).data('company');
  872. var kk = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
  873. if (kk === k) {
  874. $(this).prop('checked', false);
  875. }
  876. });
  877. var $cbsR = $('#review-company-tbody .review-company-cb');
  878. var $masterR = $('#review-check-all');
  879. if (!$cbsR.length) {
  880. $masterR.prop('checked', false).prop('indeterminate', false);
  881. } else {
  882. var nR = $cbsR.filter(':checked').length;
  883. $masterR.prop('checked', nR === $cbsR.length);
  884. $masterR.prop('indeterminate', nR > 0 && nR < $cbsR.length);
  885. }
  886. syncReviewSelectedSummary();
  887. });
  888. $('#review-category-sidebar').off('click.reviewCat').on('click.reviewCat', '.review-cat-item', function () {
  889. var $t = $(this);
  890. if ($t.hasClass('review-cat-all')) {
  891. activeReviewCategory = null;
  892. } else {
  893. activeReviewCategory = $t.data('reviewCat');
  894. }
  895. $('#review-category-list .review-cat-item').removeClass('active');
  896. $t.addClass('active');
  897. var q = reviewCompanySearchQ;
  898. var searchActive = q.length > 0;
  899. var list = [];
  900. $.each(reviewCompaniesAll, function (i, c) {
  901. if (!c || typeof c !== 'object') {
  902. return;
  903. }
  904. if (!searchActive && activeReviewCategory !== null) {
  905. var segOk = activeReviewCategory == null || activeReviewCategory === '';
  906. if (!segOk) {
  907. var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
  908. ? String(c.company_type).trim()
  909. : String(c.category || '').trim();
  910. var segs = [];
  911. if (!rawCat) {
  912. segs = ['未分类'];
  913. } else {
  914. var parts = rawCat.split('、');
  915. var seen = {};
  916. $.each(parts, function (idx, p) {
  917. var tt = String(p).trim();
  918. if (!tt || seen[tt]) {
  919. return;
  920. }
  921. seen[tt] = true;
  922. segs.push(tt);
  923. });
  924. if (!segs.length) {
  925. segs = ['未分类'];
  926. }
  927. }
  928. if ($.inArray(activeReviewCategory, segs) === -1) {
  929. return;
  930. }
  931. }
  932. }
  933. if (q) {
  934. var blob = [
  935. c.name, c.company_name, c.username, c.email, c.phone,
  936. c.company_type, c.category
  937. ].map(function (x) {
  938. return x == null ? '' : String(x);
  939. }).join(' ').toLowerCase();
  940. if (blob.indexOf(q) === -1) {
  941. return;
  942. }
  943. }
  944. list.push(c);
  945. });
  946. var $tbody = $('#review-company-tbody').empty();
  947. if (!list.length) {
  948. $tbody.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
  949. var $cbs0 = $('#review-company-tbody .review-company-cb');
  950. var $master0 = $('#review-check-all');
  951. if (!$cbs0.length) {
  952. $master0.prop('checked', false).prop('indeterminate', false);
  953. } else {
  954. var n0 = $cbs0.filter(':checked').length;
  955. $master0.prop('checked', n0 === $cbs0.length);
  956. $master0.prop('indeterminate', n0 > 0 && n0 < $cbs0.length);
  957. }
  958. syncReviewSelectedSummary();
  959. return;
  960. }
  961. $.each(list, function (i, c) {
  962. var $cb = $('<input type="checkbox" class="review-company-cb"/>');
  963. $cb.data('company', c);
  964. var k = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
  965. if (k && reviewSelectedMap[k]) {
  966. $cb.prop('checked', true);
  967. }
  968. var $tr = $('<tr/>');
  969. $tr.append($('<td class="review-td-cb"/>').append($cb));
  970. $tr.append($('<td/>').text(c.name || c.company_name || ''));
  971. $tr.append($('<td/>').text(c.username || ''));
  972. $tr.append($('<td/>').text(c.email || ''));
  973. $tr.append($('<td/>').text(c.phone || ''));
  974. $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
  975. $tbody.append($tr);
  976. });
  977. var $cbs = $('#review-company-tbody .review-company-cb');
  978. var $master = $('#review-check-all');
  979. var n = $cbs.filter(':checked').length;
  980. $master.prop('checked', n === $cbs.length);
  981. $master.prop('indeterminate', n > 0 && n < $cbs.length);
  982. syncReviewSelectedSummary();
  983. });
  984. $('#review-company-search').off('input.reviewSearch').on('input.reviewSearch', function () {
  985. var v = ($(this).val() || '').trim().toLowerCase();
  986. if (reviewSearchTimer) {
  987. clearTimeout(reviewSearchTimer);
  988. }
  989. reviewSearchTimer = setTimeout(function () {
  990. reviewSearchTimer = null;
  991. reviewCompanySearchQ = v;
  992. var q = reviewCompanySearchQ;
  993. var searchActive = q.length > 0;
  994. var list = [];
  995. $.each(reviewCompaniesAll, function (i, c) {
  996. if (!c || typeof c !== 'object') {
  997. return;
  998. }
  999. if (!searchActive && activeReviewCategory !== null) {
  1000. var segOk2 = activeReviewCategory == null || activeReviewCategory === '';
  1001. if (!segOk2) {
  1002. var rawCat2 = (c.company_type != null && String(c.company_type).trim() !== '')
  1003. ? String(c.company_type).trim()
  1004. : String(c.category || '').trim();
  1005. var segs2 = [];
  1006. if (!rawCat2) {
  1007. segs2 = ['未分类'];
  1008. } else {
  1009. var parts2 = rawCat2.split('、');
  1010. var seen2 = {};
  1011. $.each(parts2, function (idx, p) {
  1012. var tt2 = String(p).trim();
  1013. if (!tt2 || seen2[tt2]) {
  1014. return;
  1015. }
  1016. seen2[tt2] = true;
  1017. segs2.push(tt2);
  1018. });
  1019. if (!segs2.length) {
  1020. segs2 = ['未分类'];
  1021. }
  1022. }
  1023. if ($.inArray(activeReviewCategory, segs2) === -1) {
  1024. return;
  1025. }
  1026. }
  1027. }
  1028. if (q) {
  1029. var blob2 = [
  1030. c.name, c.company_name, c.username, c.email, c.phone,
  1031. c.company_type, c.category
  1032. ].map(function (x) {
  1033. return x == null ? '' : String(x);
  1034. }).join(' ').toLowerCase();
  1035. if (blob2.indexOf(q) === -1) {
  1036. return;
  1037. }
  1038. }
  1039. list.push(c);
  1040. });
  1041. var $tbody2 = $('#review-company-tbody').empty();
  1042. if (!list.length) {
  1043. $tbody2.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
  1044. } else {
  1045. $.each(list, function (i, c) {
  1046. var $cb = $('<input type="checkbox" class="review-company-cb"/>');
  1047. $cb.data('company', c);
  1048. var k2 = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
  1049. if (k2 && reviewSelectedMap[k2]) {
  1050. $cb.prop('checked', true);
  1051. }
  1052. var $tr = $('<tr/>');
  1053. $tr.append($('<td class="review-td-cb"/>').append($cb));
  1054. $tr.append($('<td/>').text(c.name || c.company_name || ''));
  1055. $tr.append($('<td/>').text(c.username || ''));
  1056. $tr.append($('<td/>').text(c.email || ''));
  1057. $tr.append($('<td/>').text(c.phone || ''));
  1058. $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
  1059. $tbody2.append($tr);
  1060. });
  1061. }
  1062. var $cbsS = $('#review-company-tbody .review-company-cb');
  1063. var $masterS = $('#review-check-all');
  1064. if (!$cbsS.length) {
  1065. $masterS.prop('checked', false).prop('indeterminate', false);
  1066. } else {
  1067. var nS = $cbsS.filter(':checked').length;
  1068. $masterS.prop('checked', nS === $cbsS.length);
  1069. $masterS.prop('indeterminate', nS > 0 && nS < $cbsS.length);
  1070. }
  1071. syncReviewSelectedSummary();
  1072. }, 160);
  1073. });
  1074. $('#review-company-tbody').off('change.reviewCb').on('change.reviewCb', '.review-company-cb', function () {
  1075. var c = $(this).data('company');
  1076. var k = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
  1077. var $cbsC = $('#review-company-tbody .review-company-cb');
  1078. var $masterC = $('#review-check-all');
  1079. if (!k) {
  1080. if (!$cbsC.length) {
  1081. $masterC.prop('checked', false).prop('indeterminate', false);
  1082. } else {
  1083. var nC = $cbsC.filter(':checked').length;
  1084. $masterC.prop('checked', nC === $cbsC.length);
  1085. $masterC.prop('indeterminate', nC > 0 && nC < $cbsC.length);
  1086. }
  1087. syncReviewSelectedSummary();
  1088. return;
  1089. }
  1090. if ($(this).prop('checked')) {
  1091. reviewSelectedMap[k] = c;
  1092. } else {
  1093. delete reviewSelectedMap[k];
  1094. }
  1095. var n2 = $cbsC.filter(':checked').length;
  1096. $masterC.prop('checked', n2 === $cbsC.length);
  1097. $masterC.prop('indeterminate', n2 > 0 && n2 < $cbsC.length);
  1098. syncReviewSelectedSummary();
  1099. });
  1100. $('#review-check-all').off('change.reviewAll').on('change.reviewAll', function () {
  1101. var on = $(this).prop('checked');
  1102. $('#review-company-tbody .review-company-cb').each(function () {
  1103. $(this).prop('checked', on).trigger('change');
  1104. });
  1105. });
  1106. $('#btn-review-submit').off('click.reviewSubmit').on('click.reviewSubmit', function () {
  1107. var selected = [];
  1108. $.each(reviewSelectedMap, function (k, c) {
  1109. if (c) {
  1110. selected.push(c);
  1111. }
  1112. });
  1113. if (!selected.length) {
  1114. Toastr.warning('请至少选择一个下发单位');
  1115. return;
  1116. }
  1117. var cons;
  1118. try {
  1119. cons = JSON.parse($('#c-row-json').val() || '{}');
  1120. } catch (e) {
  1121. cons = {};
  1122. }
  1123. Fast.api.ajax({
  1124. url: 'procuremen/review',
  1125. type: 'POST',
  1126. data: {
  1127. __token__: $('input[name=\'__token__\']').val(),
  1128. row_json: JSON.stringify(cons),
  1129. companies_json: JSON.stringify(selected),
  1130. }
  1131. }, function (data, ret) {
  1132. var msg = (ret && ret.msg) ? ret.msg : '操作成功';
  1133. if (typeof parent !== 'undefined' && parent.Toastr) {
  1134. parent.Toastr.success(msg);
  1135. }
  1136. if (parent && parent.$ && parent.$('#table').length) {
  1137. parent.$('#table').bootstrapTable('refresh');
  1138. }
  1139. var index = parent.Layer.getFrameIndex(window.name);
  1140. parent.Layer.close(index);
  1141. return false;
  1142. });
  1143. });
  1144. Fast.api.ajax({
  1145. url: 'procuremen/snapshotToProcure',
  1146. type: 'POST',
  1147. data: {
  1148. __token__: $('input[name=\'__token__\']').val(),
  1149. row_json: JSON.stringify(row)
  1150. }
  1151. }, function () {
  1152. Fast.api.ajax({
  1153. url: 'procuremen/reviewCompanies',
  1154. type: 'GET',
  1155. loading: false
  1156. }, function (data) {
  1157. reviewCompaniesAll = Array.isArray(data) ? data : [];
  1158. reviewSelectedMap = {};
  1159. activeReviewCategory = null;
  1160. reviewCompanySearchQ = '';
  1161. $('#review-company-search').val('');
  1162. var counts = {};
  1163. var total = 0;
  1164. $.each(reviewCompaniesAll, function (i, c) {
  1165. if (!c || typeof c !== 'object') {
  1166. return;
  1167. }
  1168. total++;
  1169. var raw = (c.company_type != null && String(c.company_type).trim() !== '')
  1170. ? String(c.company_type).trim()
  1171. : String(c.category || '').trim();
  1172. var segs = [];
  1173. if (!raw) {
  1174. segs = ['未分类'];
  1175. } else {
  1176. var parts = raw.split('、');
  1177. var seen = {};
  1178. $.each(parts, function (idx, p) {
  1179. var tt = String(p).trim();
  1180. if (!tt || seen[tt]) {
  1181. return;
  1182. }
  1183. seen[tt] = true;
  1184. segs.push(tt);
  1185. });
  1186. if (!segs.length) {
  1187. segs = ['未分类'];
  1188. }
  1189. }
  1190. $.each(segs, function (j, seg) {
  1191. counts[seg] = (counts[seg] || 0) + 1;
  1192. });
  1193. });
  1194. var cats = Object.keys(counts);
  1195. cats.sort(function (a, b) {
  1196. return a.localeCompare(b, 'zh-CN');
  1197. });
  1198. var $list = $('#review-category-list').empty();
  1199. var $all = $('<div class="review-cat-item review-cat-all"/>').append(
  1200. $('<span/>').text('全部 '),
  1201. $('<span class="review-cat-count"/>').text('(' + total + ')')
  1202. );
  1203. $all.toggleClass('active', activeReviewCategory === null);
  1204. $list.append($all);
  1205. $.each(cats, function (i, cat) {
  1206. var $it = $('<div class="review-cat-item"/>').append(
  1207. $('<span/>').text(cat + ' '),
  1208. $('<span class="review-cat-count"/>').text('(' + counts[cat] + ')')
  1209. );
  1210. $it.data('reviewCat', cat);
  1211. $it.toggleClass('active', activeReviewCategory === cat);
  1212. $list.append($it);
  1213. });
  1214. var q = reviewCompanySearchQ;
  1215. var searchActive = q.length > 0;
  1216. var list = [];
  1217. $.each(reviewCompaniesAll, function (i, c) {
  1218. if (!c || typeof c !== 'object') {
  1219. return;
  1220. }
  1221. if (!searchActive && activeReviewCategory !== null) {
  1222. var segOk = activeReviewCategory == null || activeReviewCategory === '';
  1223. if (!segOk) {
  1224. var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
  1225. ? String(c.company_type).trim()
  1226. : String(c.category || '').trim();
  1227. var segsB = [];
  1228. if (!rawCat) {
  1229. segsB = ['未分类'];
  1230. } else {
  1231. var partsB = rawCat.split('、');
  1232. var seenB = {};
  1233. $.each(partsB, function (idx, p) {
  1234. var ttB = String(p).trim();
  1235. if (!ttB || seenB[ttB]) {
  1236. return;
  1237. }
  1238. seenB[ttB] = true;
  1239. segsB.push(ttB);
  1240. });
  1241. if (!segsB.length) {
  1242. segsB = ['未分类'];
  1243. }
  1244. }
  1245. if ($.inArray(activeReviewCategory, segsB) === -1) {
  1246. return;
  1247. }
  1248. }
  1249. }
  1250. if (q) {
  1251. var blob = [
  1252. c.name, c.company_name, c.username, c.email, c.phone,
  1253. c.company_type, c.category
  1254. ].map(function (x) {
  1255. return x == null ? '' : String(x);
  1256. }).join(' ').toLowerCase();
  1257. if (blob.indexOf(q) === -1) {
  1258. return;
  1259. }
  1260. }
  1261. list.push(c);
  1262. });
  1263. var $tbody = $('#review-company-tbody').empty();
  1264. if (!list.length) {
  1265. $tbody.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
  1266. } else {
  1267. $.each(list, function (i, c) {
  1268. var $cb = $('<input type="checkbox" class="review-company-cb"/>');
  1269. $cb.data('company', c);
  1270. var k3 = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
  1271. if (k3 && reviewSelectedMap[k3]) {
  1272. $cb.prop('checked', true);
  1273. }
  1274. var $tr = $('<tr/>');
  1275. $tr.append($('<td class="review-td-cb"/>').append($cb));
  1276. $tr.append($('<td/>').text(c.name || c.company_name || ''));
  1277. $tr.append($('<td/>').text(c.username || ''));
  1278. $tr.append($('<td/>').text(c.email || ''));
  1279. $tr.append($('<td/>').text(c.phone || ''));
  1280. $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
  1281. $tbody.append($tr);
  1282. });
  1283. }
  1284. var $cbsF = $('#review-company-tbody .review-company-cb');
  1285. var $masterF = $('#review-check-all');
  1286. if (!$cbsF.length) {
  1287. $masterF.prop('checked', false).prop('indeterminate', false);
  1288. } else {
  1289. var nF = $cbsF.filter(':checked').length;
  1290. $masterF.prop('checked', nF === $cbsF.length);
  1291. $masterF.prop('indeterminate', nF > 0 && nF < $cbsF.length);
  1292. }
  1293. syncReviewSelectedSummary();
  1294. return false;
  1295. });
  1296. return false;
  1297. });
  1298. },
  1299. api: {
  1300. bindevent: function () {
  1301. Form.api.bindevent($('form[role=form]'));
  1302. }
  1303. }
  1304. };
  1305. return Controller;
  1306. });