| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- /* 列表:Controller.index 内顺序执行。审核:Controller.review 内顺序执行。无其它本文件自定义函数。 */
- function procuremenLayerTop() {
- try {
- if (typeof top !== 'undefined' && top.Layer) {
- return top.Layer;
- }
- } catch (e) {
- }
- try {
- if (typeof parent !== 'undefined' && parent.Layer) {
- return parent.Layer;
- }
- } catch (e) {
- }
- return typeof Layer !== 'undefined' ? Layer : null;
- }
- function procuremenLayerNextZIndex() {
- var z = 19891014;
- var $doc;
- try {
- $doc = (typeof top !== 'undefined' && top.jQuery) ? top.jQuery(top.document) : null;
- } catch (e) {
- $doc = null;
- }
- if (!$doc || !$doc.length) {
- try {
- $doc = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery(parent.document) : null;
- } catch (e2) {
- $doc = null;
- }
- }
- if ($doc && $doc.length) {
- $doc.find('.layui-layer').each(function () {
- var zi = parseInt($(this).css('z-index'), 10) || 0;
- if (zi > z) {
- z = zi;
- }
- });
- }
- return z + 10;
- }
- /** 将 layer 弹层居中到顶层窗口可视区域(采购确认短信二次确认等) */
- function procuremenCenterLayer(layero) {
- var $win;
- try {
- $win = (typeof top !== 'undefined' && top.jQuery) ? top.jQuery : null;
- } catch (e) {
- $win = null;
- }
- if (!$win) {
- try {
- $win = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : null;
- } catch (e2) {
- $win = null;
- }
- }
- if (!$win) {
- $win = $;
- }
- var $layer = $win(layero);
- var place = function () {
- var w = $layer.outerWidth() || 480;
- var h = $layer.outerHeight() || 220;
- var $vw = $win(window);
- var vw = $vw.width() || 0;
- var vh = $vw.height() || 0;
- var topPx = Math.max(12, Math.round((vh - h) / 2));
- var leftPx = Math.max(12, Math.round((vw - w) / 2));
- $layer.css({
- position: 'fixed',
- top: topPx + 'px',
- left: leftPx + 'px',
- right: 'auto',
- bottom: 'auto',
- margin: 0,
- transform: 'none'
- });
- };
- setTimeout(place, 0);
- setTimeout(place, 80);
- }
- var Controller = {
- currYm: '',
- index: function () {
- var $layout = $('#procuremen-layout');
- var table = $('#table');
- var issuedOnlyCols = ['purchase_order_id'];
- var pendingOnlyCols = ['po_detail_count', 'po_amount_fill_cnt', 'po_delivery_fill_cnt'];
- var pickedOnlyCols = ['picked_supplier_name'];
- var allOnlyCols = ['ID'];
- Controller.currYm = ($layout.data('defaultYm') || '').toString();
- Controller.wffTab = 'all';
- Table.api.init({
- extend: {
- index_url: 'procuremen/index' + location.search,
- multi_url: 'procuremen/multi',
- import_url: 'procuremen/import',
- table: 'scydgy',
- }
- });
- $('.procuremen-ym-item').removeClass('active');
- $('.procuremen-ym-item[data-ym="' + Controller.currYm + '"]').addClass('active');
- $('.procuremen-wff-tabs').find('li').removeClass('active');
- $('.procuremen-wff-tabs').find('a[data-wff="' + Controller.wffTab + '"]').parent().addClass('active');
- $(document).off('click.procuremenWff', '.procuremen-wff-tabs a').on('click.procuremenWff', '.procuremen-wff-tabs a', function (e) {
- e.preventDefault();
- var t = $(this).data('wff');
- if (!t || t === Controller.wffTab) {
- return;
- }
- Controller.wffTab = t;
- $('.procuremen-wff-tabs').find('li').removeClass('active');
- $('.procuremen-wff-tabs').find('a[data-wff="' + Controller.wffTab + '"]').parent().addClass('active');
- /* 先清空:否则 show/hideColumn 会立刻用上一状态的 data 重绘一行/多行,直到 refresh 返回才消失 */
- try {
- table.bootstrapTable('removeAll');
- } catch (ignore) {
- }
- var issuedNow = Controller.wffTab === 'pending' || Controller.wffTab === 'done' || Controller.wffTab === 'picked';
- issuedOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(issuedNow ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- pendingOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(Controller.wffTab === 'pending' ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- pickedOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(Controller.wffTab === 'picked' ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- allOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(issuedNow ? 'hideColumn' : 'showColumn', field);
- } catch (ignore) {
- }
- });
- table.bootstrapTable('refresh', {pageNumber: 1});
- });
- $(document).off('click.procuremenYm', '.procuremen-ym-item').on('click.procuremenYm', '.procuremen-ym-item', function () {
- var ym = $(this).data('ym');
- if (!ym || ym === Controller.currYm) {
- return;
- }
- Controller.currYm = ym;
- $('.procuremen-ym-item').removeClass('active');
- $(this).addClass('active');
- try {
- table.bootstrapTable('removeAll');
- } catch (ignore) {
- }
- table.bootstrapTable('refresh', {pageNumber: 1});
- });
- $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
- var ymDefault = (Controller.currYm || '').toString();
- if (!/^\d{4}-\d{2}$/.test(ymDefault)) {
- ymDefault = ($layout.data('defaultYm') || '').toString();
- }
- if (!/^\d{4}-\d{2}$/.test(ymDefault)) {
- ymDefault = '';
- }
- if (!ymDefault) {
- var d = new Date();
- ymDefault = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
- }
- var escYm = String(ymDefault == null ? '' : ymDefault).replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
- var html = ''
- + '<div style="padding:14px 18px 6px;">'
- + '<div class="form-group" style="margin-bottom:0;">'
- + '<input type="month" id="export-outward-ym-input" class="form-control" value="' + escYm + '" style="max-width:220px;" />'
- + '</div>'
- + '</div>';
- Layer.open({
- type: 1,
- title: '月份外发明细导出',
- area: ['370px', 'auto'],
- shadeClose: true,
- content: html,
- btn: ['导出 Excel'],
- yes: function (index, layero) {
- var v = (layero.find('#export-outward-ym-input').val() || '').trim();
- if (!/^\d{4}-\d{2}$/.test(v)) {
- Toastr.warning('请选择有效月份');
- return;
- }
- Layer.close(index);
- var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(v));
- setTimeout(function () {
- window.open(url, '_blank');
- }, 100);
- }
- });
- });
- table.on('post-header.bs.table', function () {
- var $host = $('#procuremen-toolbar-host');
- var $bt = table.closest('.bootstrap-table');
- if (!$host.length || !$bt.length) {
- return;
- }
- var $ft = $bt.children('.fixed-table-toolbar').first();
- if (!$ft.length) {
- $ft = $host.find('.fixed-table-toolbar').first();
- }
- if (!$ft.length) {
- return;
- }
- if ($ft.parent()[0] !== $host[0]) {
- $host.children('.fixed-table-toolbar').remove();
- $host.append($ft);
- var $src = $bt.closest('.procuremen-table-area').find('#toolbar').first();
- if ($src.length && !$src.children().length) {
- $src.addClass('procuremen-toolbar-empty');
- }
- }
- $ft.find('.procuremen-toolbar-search-wrap').removeClass('procuremen-toolbar-search-wrap');
- var $search = $ft.find('.search').first();
- if (!$search.length) {
- return;
- }
- var $right = $search.closest('.columns, .pull-right').first();
- if (!$right.length || ($ft[0] && !$.contains($ft[0], $right[0]))) {
- return;
- }
- $ft.children().each(function () {
- var $c = $(this);
- if ($c.is('.bars, .bs-bars') || $c[0] === $right[0]) {
- return;
- }
- var mergeToolbarExtras = $c.hasClass('columns')
- || $c.hasClass('pull-right')
- || ($c.hasClass('btn-group') && $c.find('.search').length === 0);
- if (!mergeToolbarExtras || $c.find('.search').length) {
- return;
- }
- if ($c.hasClass('btn-group') && !$c.hasClass('columns')) {
- $c.appendTo($right);
- } else {
- $c.children().appendTo($right);
- if (!$c.children().length) {
- $c.remove();
- }
- }
- });
- $ft.find('.search').first().prependTo($right);
- $right.addClass('procuremen-toolbar-search-wrap');
- });
- var indexInitWffTab = Controller.wffTab;
- var indexShowall = indexInitWffTab === 'all';
- var indexShowIssued = indexInitWffTab === 'pending' || indexInitWffTab === 'done' || indexInitWffTab === 'picked';
- var indexShowPendingOnly = indexInitWffTab === 'pending';
- var indexShowPickedOnly = indexInitWffTab === 'picked';
- function procuremenEscAttr(s) {
- return String(s == null ? '' : s)
- .replace(/&/g, '&')
- .replace(/"/g, '"')
- .replace(/'/g, ''');
- }
- var indexTableColumns = [
- // {field: 'ID', title: __('ID'), operate: 'LIKE', table: 'a', width: 100, align: 'center',
- // visible: indexShowall,
- // formatter: function (v) {
- // return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
- // }
- // },
- // {field: 'purchase_order_id',title: 'ID',operate: false,table: 'a',width: 88,align: 'center',
- // visible: indexShowIssued,
- // formatter: function (v) {
- // return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
- // }
- // },
- {field: 'CCYDH', title: __('订单号'), operate: 'LIKE', table: 'b', width: 100, align: 'center'},
- {field: 'CYJMC', title: __('印件名称'), operate: 'LIKE', table: 'b', width: 270, align: 'left'},
- {field: 'CGYMC', title: __('工序名称'), operate: 'LIKE', table: 'a', width: 100, align: 'center'},
- {field: 'CDW', title: __('单位'), operate: 'LIKE', table: 'a', width: 50, align: 'center'},
- {field: 'NGZL', title: __('工作量'), operate: false, table: 'a', width: 80, align: 'center'},
- {field: 'This_quantity', title: '本次数量', operate: false, table: 'a', width: 96, align: 'center',
- visible: true,
- formatter: function (v, row, index) {
- var tab = Controller.wffTab || 'all';
- if (tab === 'all') {
- var val = (v != null && v !== '') ? String(v) : '';
- return '<input type="text" class="form-control input-sm procuremen-po-field procuremen-po-qty" '
- + 'style="min-width:72px;max-width:96px;height:28px;padding:2px 6px;" '
- + 'data-field="This_quantity" data-row-index="' + index + '" value="'
- + procuremenEscAttr(val) + '" placeholder="填写" autocomplete="off"/>';
- }
- return (v == null || v === '') ? '' : String(v);
- }
- },
- {field: 'ceilingPrice', title: '最高限价', operate: false, table: 'a', width: 96, align: 'center',
- visible: true,
- formatter: function (value, row, index) {
- var tab = Controller.wffTab || 'all';
- var v = value;
- if (v == null || v === '') {
- v = (row && row.ceilingPrice != null && row.ceilingPrice !== '') ? row.ceilingPrice
- : (row && row.ceiling_price != null ? row.ceiling_price : '');
- }
- if (tab === 'all') {
- var val = (v != null && v !== '') ? String(v) : '';
- return '<input type="text" class="form-control input-sm procuremen-po-field procuremen-po-price" '
- + 'style="min-width:72px;max-width:96px;height:28px;padding:2px 6px;" '
- + 'data-field="ceilingPrice" data-row-index="' + index + '" value="'
- + procuremenEscAttr(val) + '" placeholder="填写" autocomplete="off"/>';
- }
- return (v == null || v === '') ? '' : String(v);
- }
- },
- {field: 'po_detail_count',title: '已下发数量',operate: false,table: 'a',width: 96,align: 'center',
- visible: indexShowPendingOnly,
- formatter: function (v) {
- return v != null && v !== '' ? String(v) : '0';
- }
- },
- {field: 'po_amount_fill_cnt',title: '已上报金额',operate: false,table: 'a',width: 96,align: 'center',
- visible: indexShowPendingOnly,
- formatter: function (v) {
- return v != null && v !== '' ? String(v) : '0';
- }
- },
- {field: 'po_delivery_fill_cnt',title: '已上报货期',operate: false,table: 'a',width: 96,align: 'center',
- visible: indexShowPendingOnly,
- formatter: function (v) {
- return v != null && v !== '' ? String(v) : '0';
- }
- },
- {field: 'picked_supplier_name', title: '已选供应商', operate: false, table: 'a', width: 200, align: 'left',
- visible: indexShowPickedOnly,
- formatter: function (v) {
- return v != null && v !== '' ? String(v) : '';
- }
- },
- {field: 'CDF', title: __('订法'), operate: false, table: 'a', width: 100, align: 'center'},
- {field: 'cGzzxMc', title: __('外厂单位'), operate: 'LIKE', table: 'a', width: 220, align: 'center'},
- {field: 'MBZ', title: __('备注'), operate: 'LIKE', table: 'a', width: 150, align: 'center'},
- {field: 'dStamp', title: __('操作日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'a', width: 165, align: 'center'},
- {field: 'dputrecord', title: __('提交日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'b', width: 170, align: 'center'},
- {field: 'cywyxm', title: __('业务员'), operate: 'LIKE', table: 'b', width: 80, align: 'center'},
- {field: 'operate',title: '操作',width: 170,align: 'center',fixed: 'right',
- table: table,
- formatter: function (value, row, index) {
- var tab = Controller.wffTab || 'all';
- var pk = row && (row.ID != null ? row.ID : row.id);
- if (!row || pk == null || pk === '' || String(pk) === '0') {
- return '';
- }
- var area = ' data-area=\'["76%","100%"]\'';
- var parts = [];
- if (tab === 'all') {
- //未发
- 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>');
- 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>');
- } else if (tab === 'pending') {
- //已下发
- 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>');
- 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>');
- } else if (tab === 'picked') {
- 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>');
- } else {
- //已完结
- 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>');
- }
- return '<div class="btn-group">' + parts.join(' ') + '</div>';
- },
- events: {}
- }
- ];
- var $wbh = $layout.find('.procuremen-main .widget-body');
- var tableHeight = !$wbh.length ? 400 : Math.max(168, $(window).height() - $wbh.offset().top - 56);
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'ID',
- sortName: 'a.ID',
- width: 'auto',
- height: tableHeight,
- fixedColumns: true,
- fixedRightNumber: 1,
- clickToSelect: false,
- dblClickToEdit: false,
- commonSearch: false,
- showToggle: false,
- showExport: false,
- smartDisplay: false,
- queryParams: function (params) {
- params.ym = Controller.currYm;
- params.wff_tab = Controller.wffTab;
- return params;
- },
- columns: [indexTableColumns]
- });
- Table.api.bindevent(table);
- (function () {
- var $wrap = table.closest('.bootstrap-table');
- function procuremenSetFixedRightStaleLoading(hide) {
- $wrap.find('.fixed-columns-right').toggleClass('procuremen-hide-fixed-right-loading', !!hide);
- }
- table.on('refresh.bs.table', function () {
- if ($wrap.find('.fixed-table-loading').is(':visible')) {
- procuremenSetFixedRightStaleLoading(true);
- }
- });
- table.on('load-success.bs.table load-error.bs.table', function () {
- procuremenSetFixedRightStaleLoading(false);
- });
- })();
- var $bt = table.closest('.bootstrap-table');
- var procuremenPoBlurTimer = null;
- function procuremenNormPoCell(v) {
- if (v == null || v === '') {
- return '';
- }
- return String(v).trim();
- }
- if ($bt.length) {
- $bt.off('blur.procuremenPoSave', '.procuremen-po-field').on('blur.procuremenPoSave', '.procuremen-po-field', function () {
- if (Controller.wffTab !== 'all') {
- return;
- }
- var $inp = $(this);
- clearTimeout(procuremenPoBlurTimer);
- procuremenPoBlurTimer = setTimeout(function () {
- procuremenPoBlurTimer = null;
- var rowIdx = parseInt($inp.data('rowIndex'), 10);
- if (isNaN(rowIdx)) {
- return;
- }
- var dataRows = table.bootstrapTable('getData');
- if (!dataRows[rowIdx]) {
- return;
- }
- var $qty = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]');
- var $price = $bt.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]');
- var q = ($qty.length ? String($qty.val()) : '').trim();
- var p = ($price.length ? String($price.val()) : '').trim();
- var baseRow = dataRows[rowIdx];
- var origQ = procuremenNormPoCell(baseRow.This_quantity);
- var origP = procuremenNormPoCell(baseRow.ceilingPrice);
- if (origP === '' && baseRow.ceiling_price != null && baseRow.ceiling_price !== '') {
- origP = procuremenNormPoCell(baseRow.ceiling_price);
- }
- /* 与当前行数据一致则不调接口、不弹*/
- if (q === origQ && p === origP) {
- return;
- }
- var row = $.extend({}, baseRow);
- row.This_quantity = q;
- row.ceilingPrice = p;
- Fast.api.ajax({
- url: 'procuremen/completeDirectly',
- type: 'POST',
- data: {
- row_json: JSON.stringify(row),
- finish: '0',
- __token__: $('input[name=\'__token__\']').val() || ''
- }
- }, function () {
- try {
- table.bootstrapTable('updateRow', {
- index: rowIdx,
- row: $.extend({}, baseRow, {This_quantity: q, ceilingPrice: p})
- });
- } catch (ignore) {
- }
- Toastr.success('操作成功');
- return false;
- });
- }, 220);
- });
- }
- if ($bt.length && $bt[0]) {
- var tableRoot = $bt[0];
- Controller._procuremenOpTableClick = function (e) {
- var t = e.target;
- if (!t || typeof t.closest !== 'function') {
- return;
- }
- var finish = t.closest('a.procuremen-btn-finish');
- if (finish && tableRoot.contains(finish) && !finish.classList.contains('disabled')) {
- e.preventDefault();
- if (typeof e.stopImmediatePropagation === 'function') {
- e.stopImmediatePropagation();
- }
- e.stopPropagation();
- var $f = $(finish);
- var rowIdxF = parseInt($f.data('rowIndex'), 10);
- var dataRowsF = table.bootstrapTable('getData');
- var rowF = !isNaN(rowIdxF) && dataRowsF[rowIdxF] !== undefined ? dataRowsF[rowIdxF] : null;
- if (!rowF) {
- Toastr.error('无法取得行数据');
- return;
- }
- var $qtyF = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdxF + '"]');
- var $priceF = $bt.find('.procuremen-po-price[data-row-index="' + rowIdxF + '"]');
- if ($qtyF.length) {
- rowF = $.extend({}, rowF, {This_quantity: String($qtyF.val()).trim()});
- }
- if ($priceF.length) {
- rowF = $.extend({}, rowF, {ceilingPrice: String($priceF.val()).trim()});
- }
- var escHtmlFinish = function (s) {
- return String(s == null ? '' : s)
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"');
- };
- var ccydhF = String(rowF.CCYDH != null ? rowF.CCYDH : '').trim();
- var cyjmcF = String(rowF.CYJMC != null ? rowF.CYJMC : '').trim();
- var finishMsg = '<div style="text-align:left;line-height:1.65;font-size:13px;padding:2px 0;">'
- + '<p style="margin:0 0 10px 0;">即将对以下<strong>订单</strong>标记为<strong>已完结</strong>:</p>'
- + '<div style="margin-bottom:12px;padding:8px 10px;background:#f9f9f9;border:1px solid #e5e5e5;border-radius:3px;">'
- + '<div><span style="color:#888;">订单号:</span><strong>' + (ccydhF !== '' ? escHtmlFinish(ccydhF) : '—') + '</strong></div>'
- + '<div style="margin-top:6px;"><span style="color:#888;">印件名称:</span>' + (cyjmcF !== '' ? escHtmlFinish(cyjmcF) : '—') + '</div>'
- + '</div>'
- + '<p style="margin:0;color:#a94442;"><strong>提示:</strong>请确认核对后、。<strong>点击「确定」后不可撤回或更改。</strong></p>'
- + '</div>';
- Layer.confirm(finishMsg, {
- title: '完结确认',
- area: ['520px', 'auto'],
- icon: 3,
- btn: ['确定', '取消'],
- skin: 'layui-layer-procuremen-finish'
- }, function (idx) {
- Layer.close(idx);
- Fast.api.ajax({
- url: 'procuremen/completeDirectly',
- type: 'POST',
- data: {
- row_json: JSON.stringify(rowF),
- finish: '1',
- __token__: $('input[name=\'__token__\']').val() || ''
- }
- }, function () {
- table.bootstrapTable('refresh');
- Toastr.success('操作成功');
- return false;
- });
- });
- return;
- }
- var details = t.closest('a.procuremen-btn-details');
- if (details && tableRoot.contains(details) && !details.classList.contains('disabled')) {
- e.preventDefault();
- if (typeof e.stopImmediatePropagation === 'function') {
- e.stopImmediatePropagation();
- }
- e.stopPropagation();
- var $d = $(details);
- var rowIdxD = parseInt($d.data('rowIndex'), 10);
- var dataRowsD = table.bootstrapTable('getData');
- var rowD = !isNaN(rowIdxD) && dataRowsD[rowIdxD] !== undefined ? dataRowsD[rowIdxD] : null;
- var detUrl;
- if (rowD) {
- detUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/details', rowD, table));
- } else {
- detUrl = Backend.api.replaceids(details, $d.attr('href'));
- }
- var tabForDet = Controller.wffTab ? Controller.wffTab : 'done';
- if (String(detUrl).indexOf('wff_tab=') === -1) {
- detUrl += (detUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tabForDet);
- }
- var $ad = $(details);
- var optsd = $.extend({}, $ad.data() || {});
- var titled = $ad.attr('title') || $ad.data('title') || '详情';
- var buttond = Backend.api.gettablecolumnbutton(optsd);
- var layerOptsd = $.extend({}, optsd);
- if (buttond && typeof buttond.callback === 'function') {
- layerOptsd.callback = buttond.callback;
- }
- if (buttond && buttond.layerArea && buttond.layerArea.length) {
- layerOptsd.area = buttond.layerArea;
- }
- var winNd = $ad.data('window') || 'self';
- var winD = window[winNd] || window;
- if (!winD.Backend || !winD.Backend.api) {
- Toastr.error('Backend 未就绪,请刷新页面');
- return;
- }
- winD.Backend.api.open(detUrl, titled, layerOptsd);
- return;
- }
- var outward = t.closest('a.procuremen-btn-outward');
- if (outward && !outward.classList.contains('disabled')) {
- e.preventDefault();
- if (typeof e.stopImmediatePropagation === 'function') {
- e.stopImmediatePropagation();
- }
- e.stopPropagation();
- var $o = $(outward);
- var oOpts = $.extend({}, $o.data() || {});
- var rowIdx = parseInt(oOpts.rowIndex, 10);
- var dataRows = table.bootstrapTable('getData');
- var row = !isNaN(rowIdx) && dataRows[rowIdx] !== undefined ? dataRows[rowIdx] : null;
- var tab = Controller.wffTab ? Controller.wffTab : 'all';
- var base = 'procuremen/outward_detail?wff_tab=' + encodeURIComponent(tab);
- var outUrl;
- if (row) {
- outUrl = Fast.api.fixurl(Table.api.replaceurl(base, row, table));
- } else {
- outUrl = Backend.api.replaceids(outward, $o.attr('href'));
- if (String(outUrl).indexOf('wff_tab=') === -1) {
- outUrl += (outUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tab);
- }
- }
- var $a = $(outward);
- var opts = $.extend({}, $a.data() || {});
- var title = $a.attr('title') || $a.data('title') || $a.data('original-title');
- var button = Backend.api.gettablecolumnbutton(opts);
- var layerOpts = $.extend({}, opts);
- if (button && typeof button.callback === 'function') {
- layerOpts.callback = button.callback;
- }
- if (button && button.layerArea && button.layerArea.length) {
- layerOpts.area = button.layerArea;
- }
- var winName = $a.data('window') || 'self';
- var win = window[winName] || window;
- if (!win.Backend || !win.Backend.api) {
- Toastr.error('Backend 未就绪,请刷新页面');
- return;
- }
- if (typeof layerOpts.confirm !== 'undefined') {
- Layer.confirm(layerOpts.confirm, function (index) {
- win.Backend.api.open(outUrl, title, layerOpts);
- Layer.close(index);
- });
- } else {
- win.Backend.api.open(outUrl, title, layerOpts);
- }
- return;
- }
- var review = t.closest('a.procuremen-btn-review');
- if (!review || !tableRoot.contains(review) || review.classList.contains('disabled')) {
- return;
- }
- e.preventDefault();
- if (typeof e.stopImmediatePropagation === 'function') {
- e.stopImmediatePropagation();
- }
- e.stopPropagation();
- var $a2 = $(review);
- var rowIdx2 = parseInt($a2.data('rowIndex'), 10);
- var dataRows2 = table.bootstrapTable('getData');
- var row2 = !isNaN(rowIdx2) && dataRows2[rowIdx2] !== undefined ? dataRows2[rowIdx2] : null;
- var revUrl;
- if (row2) {
- revUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/review', row2, table));
- } else {
- revUrl = Backend.api.replaceids(review, $a2.attr('href'));
- }
- var opts2 = $.extend({}, $a2.data() || {});
- var title2 = $a2.attr('title') || $a2.data('title') || $a2.data('original-title');
- var button2 = Backend.api.gettablecolumnbutton(opts2);
- var layerOpts2 = $.extend({}, opts2);
- if (button2 && typeof button2.callback === 'function') {
- layerOpts2.callback = button2.callback;
- }
- if (button2 && button2.layerArea && button2.layerArea.length) {
- layerOpts2.area = button2.layerArea;
- }
- var winName2 = $a2.data('window') || 'self';
- var win2 = window[winName2] || window;
- if (!win2.Backend || !win2.Backend.api) {
- Toastr.error('Backend 未就绪,请刷新页面');
- return;
- }
- if (typeof layerOpts2.confirm !== 'undefined') {
- Layer.confirm(layerOpts2.confirm, function (index) {
- win2.Backend.api.open(revUrl, title2, layerOpts2);
- Layer.close(index);
- });
- } else {
- win2.Backend.api.open(revUrl, title2, layerOpts2);
- }
- };
- tableRoot.addEventListener('click', Controller._procuremenOpTableClick, true);
- }
- $layout.find('.procuremen-main').off('click.procuremenTbRefresh').on('click.procuremenTbRefresh', '#procuremen-toolbar-host .btn-refresh, .procuremen-table-area #toolbar .btn-refresh', function (e) {
- e.preventDefault();
- var $spinFa = $('#procuremen-toolbar-host .btn-refresh .fa, .procuremen-table-area #toolbar .btn-refresh .fa');
- $spinFa.addClass('fa-spin');
- var apiBase = ($layout.attr('data-procuremen-redis-api') || '').toString().trim();
- if (apiBase) {
- var sep = apiBase.indexOf('?') > -1 ? '&' : '?';
- var refreshUrl = apiBase + sep + 'refresh=1';
- $.ajax({
- url: refreshUrl,
- type: 'GET',
- dataType: 'json',
- timeout: 120000
- }).done(function (ret) {
-
- if (ret && (ret.code === 200 || ret.code === '200')) {
- if (typeof Toastr !== 'undefined') {
- console.log('已刷新');
- // console.log(ret);
- // Toastr.success('已刷新');
- }
- } else if (typeof Toastr !== 'undefined') {
- Toastr.warning((ret && ret.msg) ? String(ret.msg) : '刷新接口返回异常');
- }
- }).fail(function (xhr) {
- if (typeof Toastr !== 'undefined') {
- Toastr.error(xhr && xhr.statusText ? ('刷新失败:' + xhr.statusText) : '刷新缓存请求失败');
- }
- }).always(function () {
- table.bootstrapTable('refresh');
- });
- } else {
- table.bootstrapTable('refresh');
- }
- });
- table.on('refresh.bs.table', function () {
- setTimeout(function () {
- var $host2 = $('#procuremen-toolbar-host');
- var $bt2 = table.closest('.bootstrap-table');
- if (!$host2.length || !$bt2.length) {
- return;
- }
- var $ft2 = $bt2.children('.fixed-table-toolbar').first();
- if (!$ft2.length) {
- $ft2 = $host2.find('.fixed-table-toolbar').first();
- }
- if (!$ft2.length) {
- return;
- }
- if ($ft2.parent()[0] !== $host2[0]) {
- $host2.children('.fixed-table-toolbar').remove();
- $host2.append($ft2);
- var $src2 = $bt2.closest('.procuremen-table-area').find('#toolbar').first();
- if ($src2.length && !$src2.children().length) {
- $src2.addClass('procuremen-toolbar-empty');
- }
- }
- $ft2.find('.procuremen-toolbar-search-wrap').removeClass('procuremen-toolbar-search-wrap');
- var $search2 = $ft2.find('.search').first();
- if (!$search2.length) {
- return;
- }
- var $right2 = $search2.closest('.columns, .pull-right').first();
- if (!$right2.length || ($ft2[0] && !$.contains($ft2[0], $right2[0]))) {
- return;
- }
- $ft2.children().each(function () {
- var $c2 = $(this);
- if ($c2.is('.bars, .bs-bars') || $c2[0] === $right2[0]) {
- return;
- }
- var merge2 = $c2.hasClass('columns')
- || $c2.hasClass('pull-right')
- || ($c2.hasClass('btn-group') && $c2.find('.search').length === 0);
- if (!merge2 || $c2.find('.search').length) {
- return;
- }
- if ($c2.hasClass('btn-group') && !$c2.hasClass('columns')) {
- $c2.appendTo($right2);
- } else {
- $c2.children().appendTo($right2);
- if (!$c2.children().length) {
- $c2.remove();
- }
- }
- });
- $ft2.find('.search').first().prependTo($right2);
- $right2.addClass('procuremen-toolbar-search-wrap');
- }, 0);
- });
- table.on('post-body.bs.table', function () {
- $('#procuremen-toolbar-host .btn-refresh .fa').removeClass('fa-spin');
- });
- $(window).off('resize.procuremenIndex').on('resize.procuremenIndex', function () {
- try {
- var $wbr = $layout.find('.procuremen-main .widget-body');
- var h = !$wbr.length ? 400 : Math.max(168, $(window).height() - $wbr.offset().top - 56);
- table.bootstrapTable('resetView', {height: h});
- } catch (ignore) {
- }
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- outward_detail: function () {
- Controller.api.bindevent();
- var $wrap = $('.outward-detail-wrap');
- if (!$wrap.length || !$('#btn-pod-purchase-confirm').length) {
- return;
- }
- var scydgyId = String($wrap.attr('data-scydgy-id') || '').trim();
- if (!scydgyId) {
- return;
- }
- var purchaseOrderId = String($wrap.attr('data-purchase-order-id') || '').trim();
- $wrap.off('.procuremenPurchaseConfirm');
- $wrap.on('change.procuremenPurchaseConfirm', '.pod-pick-cb', function () {
- if (this.checked) {
- $wrap.find('.pod-pick-cb').not(this).prop('checked', false);
- }
- });
- $wrap.on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm', function () {
- var FastRef = (typeof Fast !== 'undefined' && Fast.api) ? Fast
- : (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api ? parent.Fast : null);
- if (!FastRef || !FastRef.api) {
- if (typeof parent !== 'undefined' && parent.Toastr) {
- parent.Toastr.error('页面未就绪,请刷新后重试');
- }
- return;
- }
- var $cbs = $wrap.find('.pod-pick-cb');
- var all = $cbs.map(function () { return String($(this).val()); }).get();
- var sel = $cbs.filter(':checked').val();
- if (!sel) {
- var L = (typeof parent !== 'undefined' && parent.Layer) ? parent.Layer : (typeof Layer !== 'undefined' ? Layer : null);
- if (L && typeof L.msg === 'function') {
- L.msg('请勾选一条明细');
- } else if (typeof Toastr !== 'undefined') {
- Toastr.warning('请勾选一条明细');
- }
- return;
- }
- var unsel = $.grep(all, function (id) { return String(id) !== String(sel); });
- var selArr = [String(sel)];
- var tk = $('input[name=\'__token__\']').val() || '';
- function podRowCompany($tr) {
- if (!$tr || !$tr.length) {
- return '(无名称)';
- }
- var $tds = $tr.children('td');
- if ($tds.length < 8) {
- return '(无名称)';
- }
- var t = $.trim($tds.eq(6).text());
- return t !== '' ? t : '(无名称)';
- }
- function escHtml(s) {
- return String(s)
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"');
- }
- var $trOk = $cbs.filter(':checked').closest('tr');
- var okName = podRowCompany($trOk);
- var unNames = [];
- $cbs.not(':checked').each(function () {
- unNames.push(podRowCompany($(this).closest('tr')));
- });
- var nUn = unNames.length;
- var unListText = nUn ? (nUn <= 4 ? unNames.join('、') : (unNames.slice(0, 3).join('、') + ' 等共' + nUn + '家')) : '—';
- var confirmHtml = ''
- + '<div style="text-align:left;line-height:1.75;font-size:13px;">'
- + '<p style="margin:0 0 10px 0;">提交后将<strong>立即发送短信</strong>,且<strong>不可撤回或更改</strong>。请确认以下通知:</p>'
- + '<ul style="margin:0;padding-left:1.2em;">'
- + '<li style="margin-bottom:6px;"><strong>已选中 1 条</strong>:将向 <strong>' + escHtml(okName) + '</strong> 发送「已通过」短信;</li>'
- + '<li><strong>未选中 ' + nUn + ' 条</strong>:将向 <strong>' + (nUn ? escHtml(unListText) : '对应供应商') + '</strong> 发送「未通过」短信。</li>'
- + '</ul>'
- + '<p style="margin:12px 0 0 0;"><strong>是否确认提交?</strong></p>'
- + '</div>';
- var Lr = procuremenLayerTop();
- if (!Lr || typeof Lr.confirm !== 'function') {
- if (typeof Toastr !== 'undefined') {
- Toastr.error('弹层组件未就绪,请刷新后重试');
- }
- return;
- }
- Lr.confirm(confirmHtml, {
- icon: 3,
- title: '采购确认 — 短信通知',
- area: ['480px', 'auto'],
- offset: 'auto',
- btn: ['确定提交', '取消'],
- fixed: true,
- shade: 0.35,
- zIndex: procuremenLayerNextZIndex(),
- skin: 'layui-layer-fast procuremen-purchase-sms-confirm',
- success: function (layero) {
- procuremenCenterLayer(layero);
- },
- resizing: function (layero) {
- procuremenCenterLayer(layero);
- }
- }, function (idx) {
- Lr.close(idx);
- FastRef.api.ajax({
- url: FastRef.api.fixurl('procuremen/purchaseConfirmPick'),
- type: 'POST',
- data: {
- scydgy_id: scydgyId,
- purchase_order_id: purchaseOrderId,
- selected_id: sel,
- selected_ids: JSON.stringify(selArr),
- unselected_ids: JSON.stringify(unsel),
- all_detail_ids: JSON.stringify(all),
- __token__: tk
- }
- }, function () {
- if (typeof parent !== 'undefined' && parent.Layer) {
- var ix = parent.Layer.getFrameIndex(window.name);
- if (typeof ix !== 'undefined') {
- parent.Layer.close(ix);
- }
- }
- var p$ = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : (typeof parent !== 'undefined' ? parent.$ : null);
- if (p$) {
- var $doneTab = p$('.procuremen-wff-tabs a[data-wff="done"]');
- if ($doneTab.length) {
- $doneTab.trigger('click');
- } else if (p$('#table').length) {
- p$('#table').bootstrapTable('refresh');
- }
- }
- });
- });
- });
- $wrap.on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-close', function () {
- if (typeof parent !== 'undefined' && parent.Layer) {
- var ixClose = parent.Layer.getFrameIndex(window.name);
- if (typeof ixClose !== 'undefined' && ixClose !== null) {
- parent.Layer.close(ixClose);
- return;
- }
- }
- if (typeof Layer !== 'undefined' && typeof Layer.closeAll === 'function') {
- Layer.closeAll();
- }
- });
- },
- details: function () {
- Controller.api.bindevent();
- },
- review: function () {
- Controller.api.bindevent();
- require(['bootstrap-datetimepicker'], function () {
- var $el = $('#review-sys-rq');
- if (!$el.length) {
- return;
- }
- var placePickerBesideInput = function () {
- var picker = $el.data('DateTimePicker');
- if (!picker || !picker.widget) {
- return;
- }
- var $w = picker.widget;
- var rect = $el[0].getBoundingClientRect();
- var gap = 12;
- var top = rect.top;
- var left = rect.right + gap;
- var widgetW = $w.outerWidth() || 300;
- var widgetH = $w.outerHeight() || 320;
- var vw = window.innerWidth || document.documentElement.clientWidth;
- var vh = window.innerHeight || document.documentElement.clientHeight;
- if (left + widgetW > vw - 8) {
- left = Math.max(8, rect.left);
- top = rect.bottom + 6;
- }
- if (top + widgetH > vh - 8) {
- top = Math.max(8, rect.top - widgetH - 6);
- }
- $w.appendTo(document.body).css({
- position: 'fixed',
- top: top + 'px',
- left: left + 'px',
- right: 'auto',
- bottom: 'auto',
- display: 'block',
- margin: 0
- });
- };
- var bindPickerFloat = function (attempt) {
- if ($el.data('DateTimePicker')) {
- $el.off('dp.show.reviewSysRq dp.update.reviewSysRq focus.reviewSysRq click.reviewSysRq')
- .on('dp.show.reviewSysRq dp.update.reviewSysRq', function () {
- setTimeout(placePickerBesideInput, 0);
- })
- .on('focus.reviewSysRq click.reviewSysRq', function () {
- var picker = $el.data('DateTimePicker');
- if (picker) {
- picker.show();
- }
- });
- return;
- }
- if (attempt < 30) {
- setTimeout(function () {
- bindPickerFloat(attempt + 1);
- }, 50);
- }
- };
- bindPickerFloat(0);
- });
- var ids = window.Fast && Fast.api ? Fast.api.query('ids') : null;
- if (ids === null || ids === '') {
- Toastr.error('请刷新页面后重试');
- return;
- }
- var $ptable = parent.$('#table');
- if (!$ptable.length) {
- Toastr.error('请刷新页面后重试');
- return;
- }
- var pk = $ptable.bootstrapTable('getOptions').pk || 'ID';
- var row = null;
- $.each($ptable.bootstrapTable('getData'), function (i, r) {
- if (String(r[pk]) === String(ids)) {
- row = r;
- return false;
- }
- });
- if (!row) {
- Toastr.error('请刷新页面后重试');
- return;
- }
- $('#review-ccydh').text(row.CCYDH || '');
- $('#review-cyjmc').text(row.CYJMC || '');
- $('#review-CGYMC').text(row.CGYMC || '');
- $('#review-CDW').text(row.CDW != null && row.CDW !== '' ? row.CDW : '');
- $('#review-NGZL').text(row.NGZL != null && row.NGZL !== '' ? row.NGZL : '');
- $('#review-CDF').text(row.CDF || '');
- $('#review-cGzzxMc').text(row.cGzzxMc || '');
- var qDisp = row.This_quantity != null && String(row.This_quantity).trim() !== '' ? String(row.This_quantity).trim()
- : (row.this_quantity != null && String(row.this_quantity).trim() !== '' ? String(row.this_quantity).trim() : '');
- var pDisp = row.ceilingPrice != null && String(row.ceilingPrice).trim() !== '' ? String(row.ceilingPrice).trim()
- : (row.ceiling_price != null && String(row.ceiling_price).trim() !== '' ? String(row.ceiling_price).trim() : '');
- $('#review-qty-display').text(qDisp !== '' ? qDisp : '—');
- $('#review-price-display').text(pDisp !== '' ? pDisp : '—');
- $('#c-row-json').val(JSON.stringify(row));
- var reviewCompaniesAll = [];
- var activeReviewCategory = null;
- var reviewCompanySearchQ = '';
- var reviewSelectedMap = {};
- var reviewSearchTimer = null;
- function syncReviewSelectedSummary() {
- var entries = [];
- $.each(reviewSelectedMap, function (k, c) {
- if (!c) {
- return;
- }
- var t = String(c.name || c.company_name || '').trim() || '(无名称)';
- entries.push({ k: k, label: t });
- });
- entries.sort(function (a, b) {
- return a.label.localeCompare(b.label, 'zh-CN');
- });
- var n = entries.length;
- $('#review-selected-count').text(String(n));
- $('#review-selected-tags').empty();
- if (!n) {
- $('#review-selected-empty').show();
- return;
- }
- $('#review-selected-empty').hide();
- $.each(entries, function (i, e) {
- var $chip = $('<span class="review-selected-chip"/>').attr('title', e.label);
- $chip.data('reviewSelKey', e.k);
- $chip.append(
- $('<span class="review-chip-text"/>').text(e.label),
- $('<button type="button" class="review-chip-remove" title="取消选择" aria-label="取消选择"/>').text('\u00d7')
- );
- $('#review-selected-tags').append($chip);
- });
- }
- syncReviewSelectedSummary();
- $('#review-selected-tags').off('click.reviewChipRemove').on('click.reviewChipRemove', '.review-chip-remove', function (e) {
- e.preventDefault();
- e.stopPropagation();
- var k = $(this).closest('.review-selected-chip').data('reviewSelKey');
- if (k == null || k === '') {
- return;
- }
- delete reviewSelectedMap[k];
- $('#review-company-tbody .review-company-cb').each(function () {
- var c = $(this).data('company');
- var kk = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
- if (kk === k) {
- $(this).prop('checked', false);
- }
- });
- var $cbsR = $('#review-company-tbody .review-company-cb');
- var $masterR = $('#review-check-all');
- if (!$cbsR.length) {
- $masterR.prop('checked', false).prop('indeterminate', false);
- } else {
- var nR = $cbsR.filter(':checked').length;
- $masterR.prop('checked', nR === $cbsR.length);
- $masterR.prop('indeterminate', nR > 0 && nR < $cbsR.length);
- }
- syncReviewSelectedSummary();
- });
- $('#review-category-sidebar').off('click.reviewCat').on('click.reviewCat', '.review-cat-item', function () {
- var $t = $(this);
- if ($t.hasClass('review-cat-all')) {
- activeReviewCategory = null;
- } else {
- activeReviewCategory = $t.data('reviewCat');
- }
- $('#review-category-list .review-cat-item').removeClass('active');
- $t.addClass('active');
- var q = reviewCompanySearchQ;
- var searchActive = q.length > 0;
- var list = [];
- $.each(reviewCompaniesAll, function (i, c) {
- if (!c || typeof c !== 'object') {
- return;
- }
- if (!searchActive && activeReviewCategory !== null) {
- var segOk = activeReviewCategory == null || activeReviewCategory === '';
- if (!segOk) {
- var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
- ? String(c.company_type).trim()
- : String(c.category || '').trim();
- var segs = [];
- if (!rawCat) {
- segs = ['未分类'];
- } else {
- var parts = rawCat.split('、');
- var seen = {};
- $.each(parts, function (idx, p) {
- var tt = String(p).trim();
- if (!tt || seen[tt]) {
- return;
- }
- seen[tt] = true;
- segs.push(tt);
- });
- if (!segs.length) {
- segs = ['未分类'];
- }
- }
- if ($.inArray(activeReviewCategory, segs) === -1) {
- return;
- }
- }
- }
- if (q) {
- var blob = [
- c.name, c.company_name, c.username, c.email, c.phone,
- c.company_type, c.category
- ].map(function (x) {
- return x == null ? '' : String(x);
- }).join(' ').toLowerCase();
- if (blob.indexOf(q) === -1) {
- return;
- }
- }
- list.push(c);
- });
- var $tbody = $('#review-company-tbody').empty();
- if (!list.length) {
- $tbody.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
- var $cbs0 = $('#review-company-tbody .review-company-cb');
- var $master0 = $('#review-check-all');
- if (!$cbs0.length) {
- $master0.prop('checked', false).prop('indeterminate', false);
- } else {
- var n0 = $cbs0.filter(':checked').length;
- $master0.prop('checked', n0 === $cbs0.length);
- $master0.prop('indeterminate', n0 > 0 && n0 < $cbs0.length);
- }
- syncReviewSelectedSummary();
- return;
- }
- $.each(list, function (i, c) {
- var $cb = $('<input type="checkbox" class="review-company-cb"/>');
- $cb.data('company', c);
- var k = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
- if (k && reviewSelectedMap[k]) {
- $cb.prop('checked', true);
- }
- var $tr = $('<tr/>');
- $tr.append($('<td class="review-td-cb"/>').append($cb));
- $tr.append($('<td/>').text(c.name || c.company_name || ''));
- $tr.append($('<td/>').text(c.username || ''));
- $tr.append($('<td/>').text(c.email || ''));
- $tr.append($('<td/>').text(c.phone || ''));
- $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
- $tbody.append($tr);
- });
- var $cbs = $('#review-company-tbody .review-company-cb');
- var $master = $('#review-check-all');
- var n = $cbs.filter(':checked').length;
- $master.prop('checked', n === $cbs.length);
- $master.prop('indeterminate', n > 0 && n < $cbs.length);
- syncReviewSelectedSummary();
- });
- $('#review-company-search').off('input.reviewSearch').on('input.reviewSearch', function () {
- var v = ($(this).val() || '').trim().toLowerCase();
- if (reviewSearchTimer) {
- clearTimeout(reviewSearchTimer);
- }
- reviewSearchTimer = setTimeout(function () {
- reviewSearchTimer = null;
- reviewCompanySearchQ = v;
- var q = reviewCompanySearchQ;
- var searchActive = q.length > 0;
- var list = [];
- $.each(reviewCompaniesAll, function (i, c) {
- if (!c || typeof c !== 'object') {
- return;
- }
- if (!searchActive && activeReviewCategory !== null) {
- var segOk2 = activeReviewCategory == null || activeReviewCategory === '';
- if (!segOk2) {
- var rawCat2 = (c.company_type != null && String(c.company_type).trim() !== '')
- ? String(c.company_type).trim()
- : String(c.category || '').trim();
- var segs2 = [];
- if (!rawCat2) {
- segs2 = ['未分类'];
- } else {
- var parts2 = rawCat2.split('、');
- var seen2 = {};
- $.each(parts2, function (idx, p) {
- var tt2 = String(p).trim();
- if (!tt2 || seen2[tt2]) {
- return;
- }
- seen2[tt2] = true;
- segs2.push(tt2);
- });
- if (!segs2.length) {
- segs2 = ['未分类'];
- }
- }
- if ($.inArray(activeReviewCategory, segs2) === -1) {
- return;
- }
- }
- }
- if (q) {
- var blob2 = [
- c.name, c.company_name, c.username, c.email, c.phone,
- c.company_type, c.category
- ].map(function (x) {
- return x == null ? '' : String(x);
- }).join(' ').toLowerCase();
- if (blob2.indexOf(q) === -1) {
- return;
- }
- }
- list.push(c);
- });
- var $tbody2 = $('#review-company-tbody').empty();
- if (!list.length) {
- $tbody2.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
- } else {
- $.each(list, function (i, c) {
- var $cb = $('<input type="checkbox" class="review-company-cb"/>');
- $cb.data('company', c);
- var k2 = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
- if (k2 && reviewSelectedMap[k2]) {
- $cb.prop('checked', true);
- }
- var $tr = $('<tr/>');
- $tr.append($('<td class="review-td-cb"/>').append($cb));
- $tr.append($('<td/>').text(c.name || c.company_name || ''));
- $tr.append($('<td/>').text(c.username || ''));
- $tr.append($('<td/>').text(c.email || ''));
- $tr.append($('<td/>').text(c.phone || ''));
- $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
- $tbody2.append($tr);
- });
- }
- var $cbsS = $('#review-company-tbody .review-company-cb');
- var $masterS = $('#review-check-all');
- if (!$cbsS.length) {
- $masterS.prop('checked', false).prop('indeterminate', false);
- } else {
- var nS = $cbsS.filter(':checked').length;
- $masterS.prop('checked', nS === $cbsS.length);
- $masterS.prop('indeterminate', nS > 0 && nS < $cbsS.length);
- }
- syncReviewSelectedSummary();
- }, 160);
- });
- $('#review-company-tbody').off('change.reviewCb').on('change.reviewCb', '.review-company-cb', function () {
- var c = $(this).data('company');
- var k = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
- var $cbsC = $('#review-company-tbody .review-company-cb');
- var $masterC = $('#review-check-all');
- if (!k) {
- if (!$cbsC.length) {
- $masterC.prop('checked', false).prop('indeterminate', false);
- } else {
- var nC = $cbsC.filter(':checked').length;
- $masterC.prop('checked', nC === $cbsC.length);
- $masterC.prop('indeterminate', nC > 0 && nC < $cbsC.length);
- }
- syncReviewSelectedSummary();
- return;
- }
- if ($(this).prop('checked')) {
- reviewSelectedMap[k] = c;
- } else {
- delete reviewSelectedMap[k];
- }
- var n2 = $cbsC.filter(':checked').length;
- $masterC.prop('checked', n2 === $cbsC.length);
- $masterC.prop('indeterminate', n2 > 0 && n2 < $cbsC.length);
- syncReviewSelectedSummary();
- });
- $('#review-check-all').off('change.reviewAll').on('change.reviewAll', function () {
- var on = $(this).prop('checked');
- $('#review-company-tbody .review-company-cb').each(function () {
- $(this).prop('checked', on).trigger('change');
- });
- });
- $('#btn-review-submit').off('click.reviewSubmit').on('click.reviewSubmit', function () {
- var selected = [];
- $.each(reviewSelectedMap, function (k, c) {
- if (c) {
- selected.push(c);
- }
- });
- if (!selected.length) {
- Toastr.warning('请至少选择一个下发单位');
- return;
- }
- var sysRq = ($('#review-sys-rq').val() || '').trim();
- if (!sysRq) {
- Toastr.warning('请选择截止时间');
- $('#review-sys-rq').focus();
- return;
- }
- var cons;
- try {
- cons = JSON.parse($('#c-row-json').val() || '{}');
- } catch (e) {
- cons = {};
- }
- Fast.api.ajax({
- url: 'procuremen/review',
- type: 'POST',
- data: {
- __token__: $('input[name=\'__token__\']').val(),
- row_json: JSON.stringify(cons),
- companies_json: JSON.stringify(selected),
- sys_rq: sysRq
- }
- }, function (data, ret) {
- var msg = (ret && ret.msg) ? ret.msg : '操作成功';
- if (typeof parent !== 'undefined' && parent.Toastr) {
- parent.Toastr.success(msg);
- }
- if (parent && parent.$ && parent.$('#table').length) {
- parent.$('#table').bootstrapTable('refresh');
- }
- var index = parent.Layer.getFrameIndex(window.name);
- parent.Layer.close(index);
- return false;
- });
- });
- Fast.api.ajax({
- url: 'procuremen/snapshotToProcure',
- type: 'POST',
- data: {
- __token__: $('input[name=\'__token__\']').val(),
- row_json: JSON.stringify(row)
- }
- }, function () {
- Fast.api.ajax({
- url: 'procuremen/reviewCompanies',
- type: 'GET',
- loading: false
- }, function (data) {
- reviewCompaniesAll = Array.isArray(data) ? data : [];
- reviewSelectedMap = {};
- activeReviewCategory = null;
- reviewCompanySearchQ = '';
- $('#review-company-search').val('');
- var counts = {};
- var total = 0;
- $.each(reviewCompaniesAll, function (i, c) {
- if (!c || typeof c !== 'object') {
- return;
- }
- total++;
- var raw = (c.company_type != null && String(c.company_type).trim() !== '')
- ? String(c.company_type).trim()
- : String(c.category || '').trim();
- var segs = [];
- if (!raw) {
- segs = ['未分类'];
- } else {
- var parts = raw.split('、');
- var seen = {};
- $.each(parts, function (idx, p) {
- var tt = String(p).trim();
- if (!tt || seen[tt]) {
- return;
- }
- seen[tt] = true;
- segs.push(tt);
- });
- if (!segs.length) {
- segs = ['未分类'];
- }
- }
- $.each(segs, function (j, seg) {
- counts[seg] = (counts[seg] || 0) + 1;
- });
- });
- var cats = Object.keys(counts);
- cats.sort(function (a, b) {
- return a.localeCompare(b, 'zh-CN');
- });
- var $list = $('#review-category-list').empty();
- var $all = $('<div class="review-cat-item review-cat-all"/>').append(
- $('<span/>').text('全部 '),
- $('<span class="review-cat-count"/>').text('(' + total + ')')
- );
- $all.toggleClass('active', activeReviewCategory === null);
- $list.append($all);
- $.each(cats, function (i, cat) {
- var $it = $('<div class="review-cat-item"/>').append(
- $('<span/>').text(cat + ' '),
- $('<span class="review-cat-count"/>').text('(' + counts[cat] + ')')
- );
- $it.data('reviewCat', cat);
- $it.toggleClass('active', activeReviewCategory === cat);
- $list.append($it);
- });
- var q = reviewCompanySearchQ;
- var searchActive = q.length > 0;
- var list = [];
- $.each(reviewCompaniesAll, function (i, c) {
- if (!c || typeof c !== 'object') {
- return;
- }
- if (!searchActive && activeReviewCategory !== null) {
- var segOk = activeReviewCategory == null || activeReviewCategory === '';
- if (!segOk) {
- var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
- ? String(c.company_type).trim()
- : String(c.category || '').trim();
- var segsB = [];
- if (!rawCat) {
- segsB = ['未分类'];
- } else {
- var partsB = rawCat.split('、');
- var seenB = {};
- $.each(partsB, function (idx, p) {
- var ttB = String(p).trim();
- if (!ttB || seenB[ttB]) {
- return;
- }
- seenB[ttB] = true;
- segsB.push(ttB);
- });
- if (!segsB.length) {
- segsB = ['未分类'];
- }
- }
- if ($.inArray(activeReviewCategory, segsB) === -1) {
- return;
- }
- }
- }
- if (q) {
- var blob = [
- c.name, c.company_name, c.username, c.email, c.phone,
- c.company_type, c.category
- ].map(function (x) {
- return x == null ? '' : String(x);
- }).join(' ').toLowerCase();
- if (blob.indexOf(q) === -1) {
- return;
- }
- }
- list.push(c);
- });
- var $tbody = $('#review-company-tbody').empty();
- if (!list.length) {
- $tbody.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
- } else {
- $.each(list, function (i, c) {
- var $cb = $('<input type="checkbox" class="review-company-cb"/>');
- $cb.data('company', c);
- var k3 = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
- if (k3 && reviewSelectedMap[k3]) {
- $cb.prop('checked', true);
- }
- var $tr = $('<tr/>');
- $tr.append($('<td class="review-td-cb"/>').append($cb));
- $tr.append($('<td/>').text(c.name || c.company_name || ''));
- $tr.append($('<td/>').text(c.username || ''));
- $tr.append($('<td/>').text(c.email || ''));
- $tr.append($('<td/>').text(c.phone || ''));
- $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
- $tbody.append($tr);
- });
- }
- var $cbsF = $('#review-company-tbody .review-company-cb');
- var $masterF = $('#review-check-all');
- if (!$cbsF.length) {
- $masterF.prop('checked', false).prop('indeterminate', false);
- } else {
- var nF = $cbsF.filter(':checked').length;
- $masterF.prop('checked', nF === $cbsF.length);
- $masterF.prop('indeterminate', nF > 0 && nF < $cbsF.length);
- }
- syncReviewSelectedSummary();
- return false;
- });
- return false;
- });
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($('form[role=form]'));
- }
- }
- };
- return Controller;
- });
|