procuremen.js 80 KB

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