| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- function maskProcuremenEmail(email) {
- email = (email == null ? '' : String(email)).trim();
- if (!email) {
- return '';
- }
- var at = email.indexOf('@');
- if (at < 0) {
- if (email.length <= 3) {
- return email;
- }
- var dotIdx = email.lastIndexOf('.');
- if (dotIdx < 0 || dotIdx < 3) {
- return email.slice(0, 3) + '***';
- }
- return email.slice(0, 3) + '***' + email.slice(dotIdx);
- }
- var local = email.slice(0, at);
- var domain = email.slice(at + 1);
- if (!domain) {
- return local.length <= 3 ? local : local.slice(0, 3) + '***';
- }
- var first3 = local.length <= 3 ? local : local.slice(0, 3);
- var domainDot = domain.lastIndexOf('.');
- if (domainDot < 0) {
- return first3 + '***@' + domain;
- }
- return first3 + '***' + domain.slice(domainDot);
- }
- function maskProcuremenPhone(phone) {
- phone = (phone == null ? '' : String(phone)).replace(/\s+/g, '').trim();
- if (!phone) {
- return '';
- }
- var len = phone.length;
- if (len <= 7) {
- return len <= 3 ? phone : phone.slice(0, 3) + new Array(len - 2).join('*');
- }
- return phone.slice(0, 3) + new Array(len - 6).join('*') + phone.slice(-4);
- }
- function procuremenReviewCompanyKey(c) {
- if (!c || typeof c !== 'object') {
- return '';
- }
- var id = String(c.id || '').trim();
- if (id) {
- return 'id:' + id;
- }
- return [String(c.name || c.company_name || ''), String(c.username || '')].join('\x01');
- }
- function procuremenReviewCompanyPayload(c) {
- if (!c || typeof c !== 'object') {
- return {};
- }
- return {
- id: c.id || '',
- name: c.name || c.company_name || '',
- company_name: c.company_name || c.name || '',
- username: c.username || '',
- company_type: c.company_type || c.category || '',
- category: c.category || c.company_type || ''
- };
- }
- 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 procuremenLayoutFlag(key) {
- var $layout = $('#procuremen-layout');
- if (!$layout.length) {
- return null;
- }
- var raw = $layout.data(key);
- if (raw === undefined || raw === null || raw === '') {
- return null;
- }
- return parseInt(raw, 10) === 1;
- }
- /** 下发相关权限(弹窗 / 提交 / 确认页 任一即可见「下发」按钮) */
- function procuremenCanDispatch() {
- var fromLayout = procuremenLayoutFlag('canDispatch');
- if (fromLayout !== null) {
- return fromLayout;
- }
- return procuremenCan('pickreview') || procuremenCan('picksubmit') || procuremenCan('review');
- }
- function procuremenCanPickDelete() {
- var fromLayout = procuremenLayoutFlag('canPickDelete');
- if (fromLayout !== null) {
- return fromLayout;
- }
- return procuremenCan('pickdelete');
- }
- function procuremenCanComplete() {
- var fromLayout = procuremenLayoutFlag('canComplete');
- if (fromLayout !== null) {
- return fromLayout;
- }
- return procuremenCan('completedirectly');
- }
- function procuremenCanAuditAbandon() {
- var fromLayout = procuremenLayoutFlag('canAuditAbandon');
- if (fromLayout !== null) {
- return fromLayout;
- }
- return procuremenCan('auditabandon');
- }
- /** 是否拥有采购子权限(与菜单规则 name 一致,如 picksubmit → procuremen/picksubmit) */
- function procuremenCan(rule) {
- var map = (typeof Config !== 'undefined' && Config.procuremenAuth) ? Config.procuremenAuth : null;
- if (!map) {
- return false;
- }
- var key = String(rule || '').toLowerCase().replace(/^procuremen\//, '');
- var v = map[key];
- return v === true || v === 1 || v === '1';
- }
- 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);
- }
- function procuremenPad2(n) {
- n = parseInt(n, 10) || 0;
- return (n < 10 ? '0' : '') + n;
- }
- function procuremenDefaultSysRqValue() {
- if (typeof moment === 'function') {
- return moment().format('YYYY-MM-DD HH:mm:ss');
- }
- var d = new Date();
- return d.getFullYear() + '-' + procuremenPad2(d.getMonth() + 1) + '-' + procuremenPad2(d.getDate())
- + ' ' + procuremenPad2(d.getHours()) + ':' + procuremenPad2(d.getMinutes()) + ':00';
- }
- function procuremenNormalizeSysRqValue(val) {
- val = (val || '').trim();
- if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}/.test(val)) {
- if (!/:\d{2}$/.test(val)) {
- val += ':00';
- }
- return val.replace(/^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2})(:\d{2})?$/, function (m, head, sec) {
- return head + (sec || ':00');
- });
- }
- return procuremenDefaultSysRqValue();
- }
- /** 截止时间:日期 + 时下拉 + 分下拉(options.readonly 时仅展示不可改) */
- function procuremenInitSysRqSplit($wrap, eventNs, options) {
- if (!$wrap || !$wrap.length) {
- return;
- }
- options = options || {};
- var readonly = !!options.readonly;
- var $hidden = $wrap.find('input[type="hidden"][id$="-sys-rq"]');
- var $date = $wrap.find('.procuremen-sys-rq-date');
- var $hour = $wrap.find('.procuremen-sys-rq-hour');
- var $minute = $wrap.find('.procuremen-sys-rq-minute');
- if (!$hidden.length || !$date.length || !$hour.length || !$minute.length) {
- return;
- }
- if (!$hour.children().length) {
- var h, m;
- for (h = 0; h < 24; h++) {
- $hour.append($('<option>').val(procuremenPad2(h)).text(procuremenPad2(h)));
- }
- for (m = 0; m < 60; m++) {
- $minute.append($('<option>').val(procuremenPad2(m)).text(procuremenPad2(m)));
- }
- }
- var syncToHidden = function () {
- var d = ($date.val() || '').trim();
- var hh = $hour.val();
- var mm = $minute.val();
- if (d && hh !== null && hh !== undefined && mm !== null && mm !== undefined) {
- $hidden.val(d + ' ' + hh + ':' + mm + ':00');
- } else {
- $hidden.val('');
- }
- };
- var syncFromHidden = function (val) {
- val = procuremenNormalizeSysRqValue(val);
- var parts = val.match(/^(\d{4}-\d{2}-\d{2})\s+(\d{2}):(\d{2})/);
- if (!parts) {
- return;
- }
- $date.val(parts[1]);
- $hour.val(parts[2]);
- $minute.val(parts[3]);
- };
- syncFromHidden($hidden.val());
- if (!$date.val() && !readonly) {
- syncFromHidden(procuremenDefaultSysRqValue());
- syncToHidden();
- }
- if (readonly) {
- $wrap.addClass('is-readonly');
- $date.prop({disabled: true, readonly: true}).attr('tabindex', '-1');
- $hour.prop('disabled', true).attr('tabindex', '-1');
- $minute.prop('disabled', true).attr('tabindex', '-1');
- return;
- }
- $date.add($hour).add($minute)
- .off('change.' + eventNs + ' input.' + eventNs)
- .on('change.' + eventNs + ' input.' + eventNs, syncToHidden);
- }
- function procuremenFocusSysRqSplit($wrap) {
- if (!$wrap || !$wrap.length) {
- return;
- }
- var $date = $wrap.find('.procuremen-sys-rq-date');
- if ($date.length) {
- $date.focus();
- }
- }
- 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 auditOnlyCols = ['notify_supplier_text'];
- var allOnlyCols = ['ID'];
- Controller.currYm = ($layout.data('defaultYm') || '').toString();
- Controller.wffTab = ($layout.data('procuremenStage') || 'pick').toString();
- if (['pick', 'audit', 'confirm'].indexOf(Controller.wffTab) < 0) {
- Controller.wffTab = 'pick';
- }
- var listAction = Controller.wffTab;
- /** 左侧年月栏为空时补默认月份,避免 Redis 未同步时整块空白 */
- function procuremenEnsureSidebarMonths() {
- var $sidebar = $('.procuremen-sidebar');
- if (!$sidebar.length || $sidebar.find('.procuremen-ym-item').length) {
- return;
- }
- var ym = (Controller.currYm || $layout.data('defaultYm') || '').toString();
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- var d = new Date();
- ym = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0');
- }
- Controller.currYm = ym;
- var y = ym.substring(0, 4);
- var mo = parseInt(ym.substring(5, 7), 10) || 1;
- $sidebar.html(
- '<div class="procuremen-year-block">'
- + '<div class="year-title">' + y + '年</div>'
- + '<a href="javascript:;" class="procuremen-ym-item active" data-ym="' + ym + '">' + mo + '月</a>'
- + '</div>'
- );
- }
- /** 确认/审批页:默认选中服务端计算的有数据月份,避免沿用错误月份导致空表 */
- function procuremenApplyActiveYm(ym) {
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- return;
- }
- Controller.currYm = ym;
- var y = ym.substring(0, 4);
- var mo = parseInt(ym.substring(5, 7), 10) || 1;
- var $item = $('.procuremen-ym-item[data-ym="' + ym + '"]');
- if (!$item.length) {
- var $block = $('.procuremen-sidebar .procuremen-year-block').filter(function () {
- return $(this).find('.year-title').text() === y + '年';
- }).first();
- if (!$block.length) {
- $block = $('<div class="procuremen-year-block"><div class="year-title">' + y + '年</div></div>');
- $('.procuremen-sidebar').prepend($block);
- }
- $item = $('<a href="javascript:;" class="procuremen-ym-item" data-ym="' + ym + '">' + mo + '月</a>');
- $block.append($item);
- $item.on('click', function () {
- var clickYm = $(this).data('ym');
- if (!clickYm || clickYm === Controller.currYm) {
- return;
- }
- Controller.currYm = clickYm;
- $('.procuremen-ym-item').removeClass('active');
- $(this).addClass('active');
- table.bootstrapTable('refresh');
- });
- }
- $('.procuremen-ym-item').removeClass('active');
- $item.addClass('active');
- }
- function procuremenSyncCurrYmFromSidebar() {
- var defYm = ($layout.data('defaultYm') || '').toString();
- if (/^\d{4}-\d{2}$/.test(defYm)) {
- procuremenApplyActiveYm(defYm);
- return;
- }
- var $first = $('.procuremen-sidebar .procuremen-ym-item').first();
- if ($first.length) {
- procuremenApplyActiveYm(($first.data('ym') || '').toString());
- }
- }
- procuremenEnsureSidebarMonths();
- if (Controller.wffTab === 'audit' || Controller.wffTab === 'confirm') {
- procuremenSyncCurrYmFromSidebar();
- }
- Table.api.init({
- extend: {
- index_url: 'procuremen/' + listAction,
- multi_url: 'procuremen/multi',
- import_url: 'procuremen/import',
- table: 'scydgy',
- }
- });
- $('.procuremen-ym-item').removeClass('active');
- $('.procuremen-ym-item[data-ym="' + Controller.currYm + '"]').addClass('active');
- var stagePick = Controller.wffTab === 'pick';
- var stageConfirm = Controller.wffTab === 'confirm';
- var stageAudit = Controller.wffTab === 'audit';
- issuedOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable((stageAudit || stageConfirm) ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- pendingOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(stageConfirm ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- pickedOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(stageConfirm ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- auditOnlyCols.forEach(function (field) {
- try {
- table.bootstrapTable(stageAudit ? 'showColumn' : 'hideColumn', field);
- } catch (ignore) {
- }
- });
- try {
- table.bootstrapTable((stagePick || stageAudit) ? 'showColumn' : 'hideColumn', 'state');
- } catch (ignore) {
- }
- // 用 class 显隐,避免被工具栏 CSS 的 display:!important 盖掉
- function procuremenToggleStageBtn(sel, show) {
- var $btn = $(sel);
- if (!$btn.length) {
- return;
- }
- $btn.toggleClass('procuremen-stage-hide', !show);
- $btn.toggleClass('hide', !show);
- if (show) {
- $btn.css('display', '');
- } else {
- $btn.css('display', 'none');
- }
- }
- function procuremenApplyStageButtons() {
- var pick = Controller.wffTab === 'pick';
- var audit = Controller.wffTab === 'audit';
- procuremenToggleStageBtn('#btn-procuremen-pick-review', pick && procuremenCanDispatch());
- procuremenToggleStageBtn('#btn-procuremen-pick-delete', pick && procuremenCanPickDelete());
- procuremenToggleStageBtn('#btn-procuremen-batch-finish', pick && procuremenCanComplete());
- procuremenToggleStageBtn('#btn-procuremen-audit-abandon', audit && procuremenCanAuditAbandon());
- }
- procuremenApplyStageButtons();
- Controller._procuremenApplyStageButtons = procuremenApplyStageButtons;
- $(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});
- setTimeout(procuremenSyncTableHeight, 120);
- });
- function procuremenPlaceToolbar() {
- var $host = $('#procuremen-toolbar-host');
- var $bt = table.closest('.bootstrap-table');
- if (!$host.length || !$bt.length) {
- return;
- }
- $host.show().css({
- display: 'block',
- height: '',
- minHeight: '',
- padding: '',
- border: '',
- overflow: 'visible'
- });
- var $hostFt = $host.children('.fixed-table-toolbar').first();
- var $btFt = $bt.children('.fixed-table-toolbar').first();
- // 宿主已有完整工具栏:保留,隐藏表格内重复生成的空壳
- var hostOk = $hostFt.length && $hostFt.find('.btn-refresh, .toolbar .btn, .bs-bars .btn').length > 0;
- if (hostOk) {
- if ($btFt.length) {
- $btFt.hide().attr('data-procuremen-toolbar-dup', '1');
- }
- // 每次都校正右侧顺序,保证贴右且图标顺序与图二一致
- procuremenNormalizeToolbarRight($hostFt);
- procuremenBindToolbarDropdownFix();
- if (typeof Controller._procuremenApplyStageButtons === 'function') {
- Controller._procuremenApplyStageButtons();
- }
- return;
- }
- // 把表格内工具栏挪到宿主(脱离 overflow:hidden,避免上半截被裁切)
- var $ft = $btFt.length ? $btFt : $hostFt;
- if (!$ft.length) {
- return;
- }
- if ($ft.parent()[0] !== $host[0]) {
- $host.children('.fixed-table-toolbar').each(function () {
- var $old = $(this);
- if (!$old.find('.btn-refresh, .toolbar .btn, .search').length) {
- $old.remove();
- }
- });
- $host.append($ft.show().removeAttr('data-procuremen-toolbar-dup'));
- var $src = $bt.closest('.procuremen-table-area').find('#toolbar').first();
- if ($src.length && !$src.children().length) {
- $src.addClass('procuremen-toolbar-empty');
- }
- }
- procuremenNormalizeToolbarRight($ft);
- procuremenBindToolbarDropdownFix();
- if (typeof Controller._procuremenApplyStageButtons === 'function') {
- Controller._procuremenApplyStageButtons();
- }
- // 工具栏移出后重算表高,避免占位错乱
- setTimeout(function () {
- procuremenTableHeightCached = 0;
- procuremenSyncTableHeight();
- if (typeof Controller._procuremenApplyStageButtons === 'function') {
- Controller._procuremenApplyStageButtons();
- }
- }, 0);
- }
- function procuremenNormalizeToolbarRight($ft) {
- if (!$ft || !$ft.length) {
- return;
- }
- var $search = $ft.find('.search').first();
- if (!$search.length) {
- return;
- }
- // 专用右侧容器:不能把 .search 自身当 wrap(.search 的 display 会盖掉 flex,导致搜索与图标折成两行)
- var $right = $ft.children('.procuremen-toolbar-search-wrap').first();
- if (!$right.length) {
- $right = $('<div class="columns columns-right pull-right procuremen-toolbar-search-wrap"></div>');
- $ft.append($right);
- } else {
- $right.addClass('columns columns-right pull-right procuremen-toolbar-search-wrap');
- }
- // 若历史上把图标塞进了 .search 里,先拆出来
- if ($search.hasClass('procuremen-toolbar-search-wrap')) {
- $search.removeClass('procuremen-toolbar-search-wrap columns columns-right');
- }
- $search.children().not('input, .form-control').appendTo($right);
- $search.appendTo($right);
- $ft.children().each(function () {
- var $c = $(this);
- if ($c.is('.bars, .bs-bars') || $c[0] === $right[0] || $c.hasClass('search')) {
- return;
- }
- var mergeToolbarExtras = $c.hasClass('columns')
- || $c.hasClass('pull-right')
- || ($c.hasClass('btn-group') && $c.find('.search').length === 0)
- || $c.is('button[name="commonSearch"], button[name="toggle"]');
- if (!mergeToolbarExtras) {
- return;
- }
- if ($c.hasClass('btn-group') && !$c.hasClass('columns')) {
- $c.appendTo($right);
- } else if ($c.is('button')) {
- $c.appendTo($right);
- } else {
- $c.children().appendTo($right);
- if (!$c.children().length) {
- $c.remove();
- }
- }
- });
- // 顺序:搜索框 → 切换 → 列显隐 → 导出 → 通用搜索(放大镜)
- $right.addClass('procuremen-toolbar-search-wrap');
- var $toggle = $right.find('button[name="toggle"]').first();
- var $columns = $right.find('.keep-open').first();
- var $export = $right.find('.export').first();
- var $common = $right.find('button[name="commonSearch"]').first();
- $search = $right.find('.search').first();
- if ($search.length) {
- $search.prependTo($right);
- }
- if ($toggle.length) {
- $toggle.insertAfter($search);
- }
- if ($columns.length) {
- $columns.insertAfter($toggle.length ? $toggle : $search);
- }
- if ($export.length) {
- var $afterCols = $columns.length ? $columns : ($toggle.length ? $toggle : $search);
- $export.insertAfter($afterCols);
- }
- if ($common.length) {
- $common.appendTo($right);
- }
- }
- /** 列显隐下拉用 fixed,避免被表格区域 overflow 裁切 */
- function procuremenBindToolbarDropdownFix() {
- var $host = $('#procuremen-toolbar-host');
- if (!$host.length || $host.data('dropdownFixBound')) {
- return;
- }
- $host.data('dropdownFixBound', 1);
- $host.on('show.bs.dropdown shown.bs.dropdown', '.btn-group', function () {
- var $btnGroup = $(this);
- var $menu = $btnGroup.children('.dropdown-menu').first();
- if (!$menu.length) {
- return;
- }
- var place = function () {
- var btnTop = $btnGroup.offset().top;
- var btnHeight = $btnGroup.outerHeight();
- var scrollTop = $(window).scrollTop();
- var winH = $(window).height();
- var menuH = $menu.outerHeight() || 280;
- var maxH = Math.max(220, Math.min(520, winH - 24));
- var top = btnTop - scrollTop + btnHeight;
- if (top + Math.min(menuH, maxH) > winH - 8) {
- var up = btnTop - scrollTop - Math.min(menuH, maxH) - 4;
- if (up >= 8) {
- top = up;
- maxH = Math.min(maxH, Math.max(180, btnTop - scrollTop - 12));
- } else {
- maxH = Math.max(180, winH - top - 12);
- }
- }
- var left = $btnGroup.offset().left + $btnGroup.outerWidth() - ($menu.outerWidth() || 180);
- left = Math.max(8, Math.min(left, $(window).width() - ($menu.outerWidth() || 180) - 8));
- $menu.css({
- position: 'fixed',
- top: top,
- left: left,
- right: 'auto',
- bottom: 'auto',
- maxHeight: maxH + 'px',
- overflowY: 'auto',
- overflowX: 'hidden',
- zIndex: 2000
- });
- };
- place();
- setTimeout(place, 0);
- });
- }
- table.on('post-header.bs.table', function () {
- procuremenPlaceToolbar();
- procuremenScheduleAlign();
- });
- var indexInitWffTab = Controller.wffTab;
- var indexShowall = indexInitWffTab === 'pick' || indexInitWffTab === 'audit';
- var indexShowIssued = indexInitWffTab === 'audit' || indexInitWffTab === 'confirm';
- var indexShowPendingOnly = indexInitWffTab === 'confirm' || indexInitWffTab === 'audit';
- var indexShowPickedOnly = indexInitWffTab === 'confirm';
- var indexShowAuditSuppliers = indexInitWffTab === 'audit';
- function procuremenEscAttr(s) {
- return String(s == null ? '' : s)
- .replace(/&/g, '&')
- .replace(/"/g, '"')
- .replace(/'/g, ''');
- }
- function procuremenEscHtml(s) {
- return String(s == null ? '' : s)
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"');
- }
- function procuremenAutocontentCell(value, colWidth) {
- if (value == null || value === '') {
- return '';
- }
- var text = String(value).replace(/\r\n/g, '\n').replace(/\n+/g, ';').trim();
- if (text === '') {
- return '';
- }
- var width = colWidth != null && colWidth !== '' ? String(colWidth) : '250';
- if (/^\d+$/.test(width)) {
- width = width + 'px';
- }
- return "<div class='autocontent-item' style='white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:" + width + ";'>" + procuremenEscHtml(text) + '</div>';
- }
- /** 报价供应商:收起单行省略,展开后每家公司一行 */
- function procuremenParseSupplierLines(value) {
- if (value == null || value === '') {
- return [];
- }
- var raw = String(value).replace(/\r\n/g, '\n').trim();
- var lines = raw.split('\n').map(function (s) {
- return s.trim();
- }).filter(Boolean);
- if (lines.length === 1 && /[、;]/.test(lines[0])) {
- lines = lines[0].split(/[、;]+/).map(function (s) {
- return s.trim();
- }).filter(Boolean);
- }
- return lines;
- }
- function procuremenSupplierLinesCell(value, colWidth) {
- var lines = procuremenParseSupplierLines(value);
- if (lines.length === 0) {
- return '';
- }
- var preview = lines.join(';');
- var width = colWidth != null && colWidth !== '' ? String(colWidth) : '260';
- if (/^\d+$/.test(width)) {
- width = width + 'px';
- }
- return "<div class='procuremen-supplier-lines' data-supplier-full='" + procuremenEscAttr(JSON.stringify(lines)) + "' style='white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:" + width + ";'>"
- + "<span class='procuremen-supplier-preview'>" + procuremenEscHtml(preview) + '</span>'
- + '</div>';
- }
- function procuremenReadSupplierLinesFromCell($item) {
- if (!$item || !$item.length) {
- return [];
- }
- var raw = $item.attr('data-supplier-full');
- if (raw) {
- try {
- var parsed = JSON.parse(raw);
- if ($.isArray(parsed)) {
- return parsed.map(function (s) {
- return String(s == null ? '' : s).trim();
- }).filter(Boolean);
- }
- } catch (ignore) {
- }
- return procuremenParseSupplierLines(raw);
- }
- return [];
- }
- function procuremenSupplierLinesPopupHtml(lines) {
- return '<div class="procuremen-supplier-popup" style="padding:10px 12px;line-height:1.8;word-break:break-all;">'
- + lines.map(function (line) {
- return '<div>' + procuremenEscHtml(line) + '</div>';
- }).join('')
- + '</div>';
- }
- function procuremenSupplierCntText(v) {
- var n = parseInt(v, 10);
- if (isNaN(n) || n < 0) {
- n = 0;
- }
- return n + '家';
- }
- var indexTableColumns = [
- {checkbox: true, field: 'state', visible: indexShowall, align: 'center', width: 42, class: 'procuremen-col-checkbox'},
- // {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: 108, align: 'center', sortable: true, class: 'procuremen-th-sort-tight'},
- {field: 'CYJMC', title: __('印件名称'), operate: 'LIKE', table: 'b', width: 270, align: 'left', class: 'procuremen-cell-wrap',
- formatter: function (v) {
- if (v == null || v === '') {
- return '';
- }
- return '<span title="' + procuremenEscAttr(v) + '">' + procuremenEscHtml(v) + '</span>';
- }
- },
- {field: 'CCLBMMC', title: '承揽部门', operate: 'LIKE', table: 'b', width: 140, align: 'center', class: 'procuremen-cell-wrap'},
- {field: 'CGYMC', title: __('工序名称'), operate: 'LIKE', table: 'a', width: 140, align: 'left', class: 'procuremen-cell-wrap',
- formatter: function (v) {
- return v != null && v !== '' ? String(v) : '';
- }
- },
- {field: 'CDW', title: __('单位'), operate: 'LIKE', table: 'a', width: 88, align: 'center'},
- {field: 'NGZL', title: __('工作量'), operate: 'LIKE', table: 'a', width: 88, align: 'center',
- formatter: function (v) {
- if (v == null || v === '') {
- return '';
- }
- var s = String(v).trim();
- if (s === '') {
- return '';
- }
- var n = parseFloat(s);
- if (!isNaN(n) && n === 0) {
- return '';
- }
- return s;
- }
- },
- {field: 'This_quantity', title: '本次数量', operate: 'LIKE', table: 'a', width: 96, align: 'center',
- visible: true,
- formatter: function (v, row, index) {
- var tab = Controller.wffTab || 'pick';
- if (tab === 'pick') {
- 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: 'LIKE', table: 'a', width: 96, align: 'center',
- visible: true,
- formatter: function (value, row, index) {
- var tab = Controller.wffTab || 'pick';
- 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 === 'pick') {
- 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: 'notify_supplier_text', title: '报价供应商', operate: false, table: 'a', width: 260, align: 'left',
- visible: indexShowAuditSuppliers,
- class: 'procuremen-supplier-lines-cell',
- formatter: function (v) {
- return procuremenSupplierLinesCell(v, this.width || 260);
- }
- },
- {field: 'picked_supplier_name', title: '报价供应商', operate: 'LIKE', table: 'a', width: 260, align: 'left',
- visible: indexShowPickedOnly,
- class: 'procuremen-supplier-lines-cell',
- formatter: function (v) {
- return procuremenSupplierLinesCell(v, this.width || 260);
- }
- },
- {field: 'po_detail_count', title: '已下发供应商', operate: false, table: 'a', width: 108, align: 'center',
- visible: indexShowPendingOnly,
- formatter: function (v) {
- return procuremenSupplierCntText(v);
- }
- },
- {field: 'po_amount_fill_cnt', title: '已填写单价', operate: false, table: 'a', width: 100, align: 'center',
- visible: indexShowPendingOnly,
- formatter: function (v) {
- return procuremenSupplierCntText(v);
- }
- },
- {field: 'po_delivery_fill_cnt', title: '已填写货期', operate: false, table: 'a', width: 100, align: 'center',
- visible: indexShowPendingOnly,
- formatter: function (v) {
- return procuremenSupplierCntText(v);
- }
- },
- {field: 'CDF', title: __('订法'), operate: 'LIKE', table: 'a', width: 100, align: 'center', class: 'procuremen-cell-wrap'},
- {field: 'cGzzxMc', title: __('外厂单位'), operate: 'LIKE', table: 'a', width: 220, align: 'center', class: 'procuremen-cell-wrap'},
- {field: 'MBZ', title: __('备注'), operate: 'LIKE', table: 'a', width: 150, align: 'center', class: 'procuremen-cell-wrap'},
- {field: 'cywyxm', title: __('业务员'), operate: 'LIKE', table: 'b', width: 80, align: 'center'},
- {field: 'dStamp', title: __('操作日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'a', width: 176, align: 'center', sortable: true, class: 'procuremen-th-sort-tight'},
- {field: 'dputrecord', title: __('提交日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'b', width: 176, align: 'center', sortable: true, class: 'procuremen-th-sort-tight'},
- {field: 'operate',title: '操作',width: 168,align: 'center',fixed: 'right', operate: false,
- visible: indexInitWffTab !== 'pick',
- table: table,
- formatter: function (value, row, index) {
- var tab = Controller.wffTab || 'pick';
- var pk = row && (row.ID != null ? row.ID : row.id);
- if (!row || pk == null || pk === '' || String(pk) === '0') {
- return '';
- }
- var areaDetails = ' data-area=\'["92%","88%"]\'';
- var areaAudit = ' data-area=\'["96%","88%"]\'';
- var areaConfirmOutward = ' data-area=\'["96%","88%"]\'';
- var parts = [];
- if (tab === 'pick') {
- return '';
- } else if (tab === 'audit') {
- if (procuremenCan('auditissue')) {
- parts.push('<a class="btn btn-xs btn-primary procuremen-op-open procuremen-btn-audit-issue"' + areaAudit + ' href="procuremen/auditissue" data-row-index="' + index + '" title=""><i class="fa fa-check"></i> 选择供应商</a>');
- }
- if (procuremenCan('details')) {
- parts.push('<a class="btn btn-xs btn-info procuremen-op-open procuremen-btn-details"' + areaDetails + ' href="procuremen/details" data-row-index="' + index + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>');
- }
- } else if (tab === 'confirm') {
- if (procuremenCan('outward_detail')) {
- parts.push('<a class="btn btn-xs btn-success procuremen-op-open procuremen-btn-outward"' + areaConfirmOutward + ' href="procuremen/outward_detail?wff_tab=confirm" data-row-index="' + index + '" title="审批"><i class="fa fa-gavel"></i> 审批</a>');
- }
- if (procuremenCan('details')) {
- parts.push('<a class="btn btn-xs btn-info procuremen-op-open procuremen-btn-details"' + areaDetails + ' href="procuremen/details" data-row-index="' + index + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>');
- }
- }
- return '<span class="procuremen-op-btns">' + parts.join('') + '</span>';
- },
- events: {}
- }
- ];
- // audit / confirm 右侧固定操作列,避免横向滚动才能点按钮
- var useFixedColumns = indexInitWffTab === 'audit' || indexInitWffTab === 'confirm';
- var procuremenTableHeightCached = 0;
- var procuremenHeightSyncTimer = null;
- function procuremenCalcTableHeight() {
- var $area = $layout.find('.procuremen-main .procuremen-table-area');
- if (!$area.length) {
- return 400;
- }
- var top = $area[0].getBoundingClientRect().top;
- return Math.max(280, Math.floor(window.innerHeight - top - 22));
- }
- function procuremenSyncTableHeight() {
- if (procuremenHeightSyncTimer) {
- clearTimeout(procuremenHeightSyncTimer);
- }
- procuremenHeightSyncTimer = setTimeout(function () {
- procuremenHeightSyncTimer = null;
- var h = procuremenCalcTableHeight();
- if (procuremenTableHeightCached > 0 && Math.abs(procuremenTableHeightCached - h) <= 3) {
- procuremenScheduleAlign();
- return;
- }
- procuremenTableHeightCached = h;
- try {
- table.bootstrapTable('resetView', {height: h});
- procuremenScheduleAlign();
- } catch (ignore) {
- }
- }, 100);
- }
- /** 按列配置生成统一宽度,表头/表体共用,杜绝内容撑开导致竖线错位 */
- function procuremenGetVisibleColWidths() {
- var widths = [];
- try {
- var opts = table.bootstrapTable('getOptions') || {};
- var cols = (opts.columns && opts.columns[0]) ? opts.columns[0] : indexTableColumns;
- $.each(cols, function (_, col) {
- if (!col || col.visible === false) {
- return;
- }
- var w = parseInt(col.width, 10);
- if (!w || isNaN(w)) {
- w = col.checkbox ? 42 : 120;
- }
- widths.push(w);
- });
- } catch (ignore) {
- }
- return widths;
- }
- function procuremenApplyColgroup($tbl, widths) {
- if (!$tbl || !$tbl.length || !widths.length) {
- return;
- }
- var total = 0;
- var i;
- for (i = 0; i < widths.length; i++) {
- total += widths[i];
- }
- $tbl.css({
- tableLayout: 'fixed',
- width: total + 'px',
- minWidth: total + 'px'
- });
- var $cg = $tbl.children('colgroup');
- if (!$cg.length) {
- $cg = $('<colgroup/>').prependTo($tbl);
- }
- $cg.empty();
- for (i = 0; i < widths.length; i++) {
- $cg.append($('<col/>').attr('style', 'width:' + widths[i] + 'px;min-width:' + widths[i] + 'px;'));
- }
- $tbl.find('thead tr:first > th').each(function (idx) {
- if (idx >= widths.length) {
- return;
- }
- var w = widths[idx];
- var $th = $(this);
- $th.css({width: w + 'px', minWidth: w + 'px', maxWidth: w + 'px'});
- $th.find('.fht-cell').css({width: w + 'px', minWidth: w + 'px', maxWidth: w + 'px'});
- });
- // 只锁首行即可带动 fixed 布局;避免给每一行都写 style 太重
- $tbl.find('tbody tr:first-child:not(.no-records-found) > *').each(function (idx) {
- if (idx >= widths.length) {
- return;
- }
- var w = widths[idx];
- $(this).css({width: w + 'px', minWidth: w + 'px', maxWidth: w + 'px'});
- });
- }
- /** 表头/表体列线对齐:统一 colgroup 宽度,不再用内容实测宽(内容会把表体撑偏) */
- function procuremenSyncHeaderBodyAlign() {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- var $bt = table.closest('.bootstrap-table');
- if (!$bt.length) {
- return;
- }
- var $headerWrap = $bt.find('> .fixed-table-container > .fixed-table-header').first();
- if (!$headerWrap.length) {
- $headerWrap = $bt.find('.fixed-table-header').not('.fixed-columns-right .fixed-table-header').first();
- }
- var $bodyWrap = $bt.find('> .fixed-table-container > .fixed-table-body').first();
- if (!$bodyWrap.length) {
- $bodyWrap = $bt.find('.fixed-table-body').not('.fixed-columns-right .fixed-table-body, .fixed-columns .fixed-table-body').first();
- }
- if (!$headerWrap.length || !$bodyWrap.length) {
- return;
- }
- var $headerTable = $headerWrap.children('table').first();
- var $bodyTable = $bodyWrap.children('table').first();
- if (!$headerTable.length || !$bodyTable.length) {
- return;
- }
- var widths = procuremenGetVisibleColWidths();
- if (!widths.length) {
- // 兜底:按当前表头列数均分不可靠,改为按现有 th 数量取配置默认
- var n = $headerTable.find('thead tr:first > th').length;
- for (var k = 0; k < n; k++) {
- widths.push(120);
- }
- }
- // 列数不一致时以较少者为准,避免错位
- var headCount = $headerTable.find('thead tr:first > th').length;
- var bodyCount = $bodyTable.find('tbody tr:first-child:not(.no-records-found) > *').length;
- if (!bodyCount) {
- bodyCount = $bodyTable.find('thead tr:first > th').length;
- }
- var colCount = Math.min(widths.length, headCount || widths.length, bodyCount || widths.length);
- if (colCount > 0 && colCount < widths.length) {
- widths = widths.slice(0, colCount);
- }
- $headerWrap.css('padding-right', '');
- var bodyEl = $bodyWrap[0];
- var sb = Math.max(0, bodyEl.offsetWidth - bodyEl.clientWidth);
- $headerWrap.css('margin-right', sb > 0 ? sb + 'px' : '');
- procuremenApplyColgroup($headerTable, widths);
- procuremenApplyColgroup($bodyTable, widths);
- // 主表横向滚动与表头同步;避免异常 scrollLeft 把左侧复选框/订单号滚出可视区
- var sl = $bodyWrap.scrollLeft() || 0;
- if (sl < 0) {
- sl = 0;
- $bodyWrap.scrollLeft(0);
- }
- $headerWrap.scrollLeft(sl);
- // 右侧固定操作列:插件克隆整表再 scrollLeft 到最右;切勿 scrollLeft(0) 或把 table 压成单列宽
- var $fixedRight = $bt.find('.fixed-columns-right');
- if ($fixedRight.length) {
- var $fh = $fixedRight.find('.fixed-table-header').first();
- var $fb = $fixedRight.find('.fixed-table-body').first();
- var $fTable = $fh.find('table').first();
- if (!$fTable.length) {
- $fTable = $fb.find('table').first();
- }
- // 清掉历史错误内联样式,恢复整表宽度
- $fixedRight.find('table').each(function () {
- $(this).css({width: '', minWidth: '', maxWidth: '', tableLayout: ''});
- });
- $fixedRight.find('thead th, tbody td').css({
- width: '',
- minWidth: '',
- maxWidth: '',
- overflow: '',
- whiteSpace: ''
- });
- $fixedRight.find('colgroup').remove();
- var opW = 168;
- var $opCell = $bt.find('.fixed-table-body table thead th[data-field="operate"]').first();
- if (!$opCell.length) {
- $opCell = $headerTable.find('th[data-field="operate"]').first();
- }
- if ($opCell.length) {
- var measured = $opCell.outerWidth();
- if (measured > 0) {
- opW = Math.max(Math.round(measured), 156);
- }
- }
- $fixedRight.css({
- width: opW + 'px',
- minWidth: opW + 'px',
- maxWidth: opW + 'px',
- display: 'block',
- visibility: 'visible',
- overflow: 'hidden'
- });
- var fullW = $fTable.outerWidth() || $fTable.width() || 0;
- if (fullW > 0) {
- $fh.scrollLeft(fullW);
- $fb.scrollLeft(fullW);
- }
- }
- }
- function procuremenScheduleAlign() {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- setTimeout(procuremenSyncHeaderBodyAlign, 0);
- setTimeout(procuremenSyncHeaderBodyAlign, 80);
- }
- var procuremenInitTableHeight = procuremenCalcTableHeight();
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'ID',
- sortName: indexInitWffTab === 'pick' ? 'CCYDH' : 'a.pick_time',
- sortOrder: 'desc',
- width: 'auto',
- height: procuremenInitTableHeight,
- fixedColumns: useFixedColumns,
- fixedRightNumber: useFixedColumns ? 1 : 0,
- clickToSelect: false,
- dblClickToEdit: false,
- dragCheckboxMultiselect: false,
- maintainSelected: false,
- commonSearch: true,
- showToggle: true,
- showColumns: true,
- showExport: true,
- search: true,
- smartDisplay: false,
- responseHandler: function (res) {
- if (res && res.activeYm && (Controller.wffTab === 'audit' || Controller.wffTab === 'confirm')) {
- procuremenApplyActiveYm(res.activeYm);
- }
- if (res && typeof res === 'object' && res.msg && (res.total === 0 || !res.rows || !res.rows.length)) {
- delete res.msg;
- }
- return res;
- },
- queryParams: function (params) {
- params.ym = Controller.currYm;
- params.wff_tab = Controller.wffTab;
- return params;
- },
- columns: [indexTableColumns]
- });
- Table.api.bindevent(table);
- // 本页不需要「跨页选择模式」提示
- table.closest('.bootstrap-table').find('.btn-selected-tips').remove();
- $('#procuremen-toolbar-host .btn-selected-tips, #toolbar .btn-selected-tips').remove();
- table.on('post-body.bs.table post-header.bs.table', function () {
- $('#procuremen-toolbar-host .btn-selected-tips, .bootstrap-table .btn-selected-tips, #toolbar .btn-selected-tips').remove();
- });
- table.off('mouseenter.procuremenSupplierLines mouseleave.procuremenSupplierLines', '.procuremen-supplier-lines-cell')
- .on('mouseenter.procuremenSupplierLines', '.procuremen-supplier-lines-cell', function () {
- var $item = $(this).find('.procuremen-supplier-lines').first();
- if (!$item.length) {
- return;
- }
- var lines = procuremenReadSupplierLinesFromCell($item);
- var target = $item.find('.procuremen-supplier-preview').get(0);
- if (lines.length > 1 || (target && target.scrollWidth > target.offsetWidth)) {
- if (!$(this).find('> .procuremen-supplier-caret').length) {
- $(this).append("<div class='procuremen-supplier-caret'><i class='fa fa-chevron-down'></i></div>");
- }
- }
- })
- .on('mouseleave.procuremenSupplierLines', '.procuremen-supplier-lines-cell', function () {
- $(this).find('> .procuremen-supplier-caret').remove();
- });
- table.off('click.procuremenSupplierLines', '.procuremen-supplier-lines-cell > .procuremen-supplier-caret')
- .on('click.procuremenSupplierLines', '.procuremen-supplier-lines-cell > .procuremen-supplier-caret', function (e) {
- e.preventDefault();
- e.stopImmediatePropagation();
- var $td = $(this).closest('.procuremen-supplier-lines-cell');
- var $item = $td.find('.procuremen-supplier-lines').first();
- var lines = procuremenReadSupplierLinesFromCell($item);
- if (!lines.length) {
- return;
- }
- var tdrect = $td.get(0).getBoundingClientRect();
- var layerIndex = Layer.open({
- id: 'procuremen-supplier-lines',
- skin: 'layui-layer-fast layui-layer-autocontent',
- title: false,
- content: procuremenSupplierLinesPopupHtml(lines),
- btn: false,
- anim: false,
- shade: 0,
- isOutAnim: false,
- area: 'auto',
- maxWidth: 450,
- maxHeight: 350,
- offset: [tdrect.y, tdrect.x]
- });
- var mousedown = function (ev) {
- if ($(ev.target).closest('.layui-layer').length === 0) {
- Layer.close(layerIndex);
- $(document).off('mousedown', mousedown);
- }
- };
- $(document).off('mousedown', mousedown).on('mousedown', mousedown);
- });
- // 刷新/切换月份时旧请求被中断会误触 load-error;列表已有数据时不打扰用户
- table.off('load-error.bs.table').on('load-error.bs.table', function (status, res, jqXHR) {
- var xhr = jqXHR || res;
- if (xhr && (!xhr.status || xhr.status === 0 || xhr.statusText === 'abort')) {
- return;
- }
- try {
- if ((table.bootstrapTable('getData') || []).length > 0) {
- return;
- }
- } catch (ignore) {
- }
- });
- table.on('load-success.bs.table', function () {
- procuremenPlaceToolbar();
- procuremenSyncTableHeight();
- });
- $(document).off('click.procuremenCommonSearch', 'button[name="commonSearch"]').on('click.procuremenCommonSearch', 'button[name="commonSearch"]', function () {
- setTimeout(procuremenSyncTableHeight, 150);
- });
- $(window).off('resize.procuremenIndex').on('resize.procuremenIndex', function () {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- procuremenTableHeightCached = 0;
- procuremenSyncTableHeight();
- });
- $(document).off('fa.sidebar.resized.procuremenIndex fa.table.relayout.procuremenIndex')
- .on('fa.sidebar.resized.procuremenIndex fa.table.relayout.procuremenIndex', function () {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- procuremenTableHeightCached = 0;
- var $bt = table.closest('.bootstrap-table');
- $bt.find('.fixed-table-header').css({paddingRight: '', marginRight: ''});
- $bt.find('.fixed-table-header thead th').css({width: '', minWidth: '', maxWidth: ''});
- try {
- table.bootstrapTable('resetView', {height: procuremenCalcTableHeight()});
- } catch (ignore) {
- }
- procuremenScheduleAlign();
- });
- function procuremenEscHtml(s) {
- return String(s == null ? '' : s)
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"');
- }
- function procuremenBuildConfirmRowsTable(rows) {
- var html = '<table class="table table-bordered table-condensed procuremen-confirm-table">'
- + '<thead><tr><th>订单号</th><th>工序名称</th><th>印件名称</th></tr></thead><tbody>';
- $.each(rows, function (i, rd) {
- html += '<tr><td>' + procuremenEscHtml(String(rd.CCYDH || '').trim() || '—') + '</td>'
- + '<td>' + procuremenEscHtml(String(rd.CGYMC || '').trim() || '—') + '</td>'
- + '<td>' + procuremenEscHtml(String(rd.CYJMC || '').trim() || '—') + '</td></tr>';
- });
- html += '</tbody></table>';
- return html;
- }
- function procuremenBuildConfirmMsg(introHtml, rowsTableHtml) {
- return '<div class="procuremen-confirm-body">'
- + '<p class="procuremen-confirm-intro">' + introHtml + '</p>'
- + '<div class="procuremen-confirm-scroll">' + rowsTableHtml + '</div>'
- + '</div>';
- }
- var procuremenConfirmLayerBase = {
- area: ['680px', '400px'],
- icon: -1,
- skin: 'layui-layer-procuremen-finish',
- success: function (layero) {
- var $layer = $(layero);
- $layer.css({
- display: 'flex',
- flexDirection: 'column',
- height: '400px',
- overflow: 'hidden'
- });
- $layer.find('.layui-layer-content').css({
- flex: '1 1 auto',
- minHeight: 0,
- overflow: 'hidden',
- height: 'auto'
- });
- $layer.find('.layui-layer-btn').css({flexShrink: 0});
- }
- };
- function procuremenExpandOrderRows(row) {
- if (!row) {
- return [];
- }
- if ($.isArray(row._order_merge_rows) && row._order_merge_rows.length) {
- return row._order_merge_rows;
- }
- return [row];
- }
- function procuremenRowsWithPoInputs(selRows) {
- var $btPo = table.closest('.bootstrap-table');
- var dataRows = table.bootstrapTable('getData');
- var out = [];
- $.each(selRows, function (i, r) {
- if (!r) {
- return;
- }
- var rowIdx = -1;
- $.each(dataRows, function (di, dr) {
- var pk = table.bootstrapTable('getOptions').pk || 'ID';
- var a = dr && (dr[pk] != null ? dr[pk] : dr.id);
- var b = r && (r[pk] != null ? r[pk] : r.id);
- if (a != null && b != null && String(a) === String(b)) {
- rowIdx = di;
- return false;
- }
- });
- var rowCopy = $.extend({}, r);
- if (rowIdx >= 0 && $btPo.length) {
- var $qty = $btPo.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]');
- var $price = $btPo.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]');
- if ($qty.length) {
- rowCopy.This_quantity = String($qty.val()).trim();
- }
- if ($price.length) {
- rowCopy.ceilingPrice = String($price.val()).trim();
- }
- }
- out.push(rowCopy);
- });
- return out;
- }
- function procuremenOpenPickReview(selRows) {
- if (!selRows || !selRows.length) {
- Toastr.warning('请先勾选至少 1 条工序');
- return;
- }
- var ccydh0 = String(selRows[0].CCYDH || '').trim();
- if (!ccydh0) {
- Toastr.warning('所选行缺少订单号,无法下发');
- return;
- }
- if (selRows.length > 1) {
- var j;
- for (j = 1; j < selRows.length; j++) {
- if (String(selRows[j].CCYDH || '').trim() !== ccydh0) {
- Toastr.warning('合并下发须为同一订单号(当前混有:' + ccydh0 + ' 与其它订单)');
- return;
- }
- }
- }
- var pk0 = table.bootstrapTable('getOptions').pk || 'ID';
- var ids = [];
- $.each(selRows, function (idx, r) {
- var pkVal = r && (r[pk0] != null ? r[pk0] : r.id);
- if (pkVal != null && String(pkVal) !== '' && String(pkVal) !== '0') {
- ids.push(String(pkVal));
- }
- });
- if (!ids.length) {
- Toastr.warning('所选行无效,无法下发');
- return;
- }
- try {
- sessionStorage.setItem('procuremen_merge_rows', JSON.stringify(selRows));
- } catch (ignoreStore) {
- }
- var titlePick = ' ';
- var revUrl = Fast.api.fixurl('procuremen/pickreview?ids=' + encodeURIComponent(ids[0]) + '&merge=1');
- var winPick = window;
- if (!winPick.Backend || !winPick.Backend.api) {
- Toastr.error('Backend 未就绪,请刷新页面');
- return;
- }
- winPick.Backend.api.open(revUrl, titlePick, {area: ['76%', '100%']});
- }
- $(document).off('click.procuremenPickReview', '#btn-procuremen-pick-review').on('click.procuremenPickReview', '#btn-procuremen-pick-review', function (e) {
- e.preventDefault();
- if (Controller.wffTab !== 'pick') {
- Toastr.warning('下发仅在协助下发列表可用');
- return;
- }
- var selPick = procuremenRowsWithPoInputs(table.bootstrapTable('getSelections') || []);
- procuremenOpenPickReview(selPick);
- });
- $(document).off('click.procuremenAuditAbandon', '#btn-procuremen-audit-abandon').on('click.procuremenAuditAbandon', '#btn-procuremen-audit-abandon', function (e) {
- e.preventDefault();
- if (Controller.wffTab !== 'audit') {
- Toastr.warning('重新下发仅在协助审批下发列表可用');
- return;
- }
- var selAb = table.bootstrapTable('getSelections') || [];
- if (!selAb.length) {
- Toastr.warning('请先勾选至少 1 条订单');
- return;
- }
- var idSet = {};
- $.each(selAb, function (ai, ra) {
- var sid = ra && (ra.ID != null ? ra.ID : ra.id);
- if (sid != null && sid !== '' && String(sid) !== '0') {
- idSet[String(sid)] = true;
- }
- });
- var idList = Object.keys(idSet);
- if (!idList.length) {
- Toastr.warning('所选行无效,请重新勾选');
- return;
- }
- var abandonMsg = procuremenBuildConfirmMsg(
- '退回初选并重新下发以下 <strong>' + idList.length + '</strong> 个订单:',
- procuremenBuildConfirmRowsTable(selAb)
- );
- Layer.confirm(abandonMsg, $.extend({}, procuremenConfirmLayerBase, {
- title: '重新下发确认',
- btn: ['确认重新下发', '取消']
- }), function (idxAb) {
- Layer.close(idxAb);
- Fast.api.ajax({
- url: 'procuremen/auditabandon',
- type: 'POST',
- data: {
- scydgy_ids_json: JSON.stringify(idList),
- __token__: $('input[name=\'__token__\']').val() || Config.token
- }
- }, function (data, ret) {
- table.bootstrapTable('refresh');
- return false;
- });
- });
- });
- $(document).off('click.procuremenPickDelete', '#btn-procuremen-pick-delete').on('click.procuremenPickDelete', '#btn-procuremen-pick-delete', function (e) {
- e.preventDefault();
- if (Controller.wffTab !== 'pick') {
- Toastr.warning('删除仅在协助初选列表可用');
- return;
- }
- var selDel = procuremenRowsWithPoInputs(table.bootstrapTable('getSelections') || []);
- if (!selDel.length) {
- Toastr.warning('请先勾选至少 1 条工序');
- return;
- }
- var deleteMsg = procuremenBuildConfirmMsg(
- '删除以下 <strong>' + selDel.length + '</strong> 条工序,确认后将无法恢复:',
- procuremenBuildConfirmRowsTable(selDel)
- );
- Layer.confirm(deleteMsg, $.extend({}, procuremenConfirmLayerBase, {
- title: '删除',
- btn: ['确定删除', '取消']
- }), function (idxDel) {
- Layer.close(idxDel);
- Fast.api.ajax({
- url: 'procuremen/pickdelete',
- type: 'POST',
- data: {
- rows_json: JSON.stringify(selDel),
- __token__: $('input[name=\'__token__\']').val() || ''
- }
- }, function () {
- table.bootstrapTable('refresh');
- return false;
- });
- });
- });
- $(document).off('click.procuremenBatchFinish', '#btn-procuremen-batch-finish').on('click.procuremenBatchFinish', '#btn-procuremen-batch-finish', function (e) {
- e.preventDefault();
- if (Controller.wffTab !== 'pick') {
- Toastr.warning('完结仅在协助下发列表可用');
- return;
- }
- var selFin = procuremenRowsWithPoInputs(table.bootstrapTable('getSelections') || []);
- if (!selFin.length) {
- Toastr.warning('请先勾选至少 1 条工序');
- return;
- }
- var finishBatchMsg = procuremenBuildConfirmMsg(
- '将对以下 <strong>' + selFin.length + '</strong> 条工序标记为<strong>已完结</strong>:',
- procuremenBuildConfirmRowsTable(selFin)
- );
- Layer.confirm(finishBatchMsg, $.extend({}, procuremenConfirmLayerBase, {
- title: '完结确认',
- btn: ['确定', '取消']
- }), function (idxFin) {
- Layer.close(idxFin);
- var tokenFin = $('input[name=\'__token__\']').val() || '';
- var pending = selFin.length;
- var failed = 0;
- var nextFin = function (pos) {
- if (pos >= selFin.length) {
- table.bootstrapTable('refresh');
- if (failed) {
- Toastr.warning('部分工序完结失败(' + failed + '/' + selFin.length + ')');
- } else {
- Toastr.success('已完结 ' + pending + ' 条工序');
- }
- return;
- }
- Fast.api.ajax({
- url: 'procuremen/completeDirectly',
- type: 'POST',
- data: {
- row_json: JSON.stringify(selFin[pos]),
- finish: '1',
- __token__: tokenFin
- }
- }, function () {
- nextFin(pos + 1);
- return false;
- }, function () {
- failed++;
- nextFin(pos + 1);
- return false;
- });
- };
- nextFin(0);
- });
- });
- (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 $poPopover = null;
- var procuremenPoActiveRow = null;
- var procuremenPoFocusSnapshot = null;
- function procuremenNormPoCell(v) {
- if (v == null || v === '') {
- return '';
- }
- return String(v).trim();
- }
- function procuremenPoRowValues(rowIdx) {
- if (!$bt.length) {
- return null;
- }
- var dataRows = table.bootstrapTable('getData');
- var baseRow = dataRows[rowIdx];
- if (!baseRow) {
- return null;
- }
- 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 origQ = procuremenNormPoCell(baseRow.This_quantity);
- var origP = procuremenNormPoCell(baseRow.ceilingPrice);
- if (origP === '' && baseRow.ceiling_price != null && baseRow.ceiling_price !== '') {
- origP = procuremenNormPoCell(baseRow.ceiling_price);
- }
- return {baseRow: baseRow, q: q, p: p, origQ: origQ, origP: origP};
- }
- function procuremenPoRowDirty(rowIdx) {
- var v = procuremenPoRowValues(rowIdx);
- if (!v) {
- return false;
- }
- // 允许清空:只要与库中原值不同即视为已修改(两个都删空也能保存)
- return v.q !== v.origQ || v.p !== v.origP;
- }
- function procuremenEnsurePoPopover() {
- if ($poPopover && $poPopover.length) {
- return $poPopover;
- }
- $poPopover = $('<div class="procuremen-po-popover" style="display:none;">'
- + '<div class="procuremen-po-popover-inner">'
- + '<button type="button" class="btn btn-xs btn-primary procuremen-po-pop-save">保存</button>'
- + '<button type="button" class="btn btn-xs btn-default procuremen-po-pop-cancel">取消</button>'
- + '</div></div>').appendTo('body');
- $poPopover.on('mousedown', function (e) {
- e.preventDefault();
- });
- return $poPopover;
- }
- function procuremenPoPopoverPosition($inp) {
- if (!$inp || !$inp.length) {
- return;
- }
- var rect = $inp[0].getBoundingClientRect();
- var $pop = procuremenEnsurePoPopover();
- var popW = $pop.outerWidth() || 120;
- var left = rect.left;
- var vw = window.innerWidth || document.documentElement.clientWidth || 0;
- if (left + popW > vw - 8) {
- left = Math.max(8, vw - popW - 8);
- }
- $pop.css({
- display: 'block',
- top: (rect.bottom + 4) + 'px',
- left: left + 'px'
- });
- }
- function procuremenPoPopoverSyncSaveBtn(rowIdx) {
- if (!$bt.length || isNaN(rowIdx)) {
- return;
- }
- var dirty = procuremenPoRowDirty(rowIdx);
- procuremenEnsurePoPopover().find('.procuremen-po-pop-save').prop('disabled', !dirty);
- $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"], .procuremen-po-price[data-row-index="' + rowIdx + '"]')
- .toggleClass('procuremen-po-dirty', dirty);
- }
- function procuremenPoPopoverHide() {
- if ($poPopover) {
- $poPopover.hide();
- }
- procuremenPoActiveRow = null;
- procuremenPoFocusSnapshot = null;
- }
- function procuremenPoPopoverCancel() {
- if (procuremenPoActiveRow === null || !$bt.length) {
- procuremenPoPopoverHide();
- return;
- }
- var rowIdx = procuremenPoActiveRow;
- var snap = procuremenPoFocusSnapshot;
- if (snap) {
- $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]').val(snap.q);
- $bt.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]').val(snap.p);
- }
- $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"], .procuremen-po-price[data-row-index="' + rowIdx + '"]')
- .removeClass('procuremen-po-dirty');
- procuremenPoPopoverHide();
- }
- function procuremenPoPopoverShow($inp) {
- if (Controller.wffTab !== 'pick' || !$inp.length) {
- return;
- }
- var rowIdx = parseInt($inp.data('rowIndex'), 10);
- if (isNaN(rowIdx)) {
- return;
- }
- // 切到另一行时,上一行有未保存修改则先自动保存
- if (procuremenPoActiveRow !== null && procuremenPoActiveRow !== rowIdx
- && procuremenPoRowDirty(procuremenPoActiveRow)) {
- procuremenSavePoRow(procuremenPoActiveRow);
- }
- var v = procuremenPoRowValues(rowIdx);
- if (!v) {
- return;
- }
- procuremenPoActiveRow = rowIdx;
- procuremenPoFocusSnapshot = {q: v.origQ, p: v.origP};
- procuremenPoPopoverSyncSaveBtn(rowIdx);
- procuremenPoPopoverPosition($inp);
- }
- function procuremenSavePoRow(rowIdx) {
- if (Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') {
- return;
- }
- var v = procuremenPoRowValues(rowIdx);
- if (!v) {
- return;
- }
- if (!procuremenPoRowDirty(rowIdx)) {
- Toastr.info('没有需要保存的修改');
- return;
- }
- var row = $.extend({}, v.baseRow);
- row.This_quantity = v.q;
- row.ceilingPrice = v.p;
- var $saveBtn = procuremenEnsurePoPopover().find('.procuremen-po-pop-save');
- $saveBtn.prop('disabled', true);
- 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({}, v.baseRow, {This_quantity: v.q, ceilingPrice: v.p})
- });
- } catch (ignore) {
- }
- procuremenPoPopoverHide();
- Toastr.success('保存成功');
- return false;
- }, function () {
- procuremenPoPopoverSyncSaveBtn(rowIdx);
- return false;
- });
- }
- if ($bt.length) {
- $bt.off('focusin.procuremenPoPop click.procuremenPoPop', '.procuremen-po-field')
- .on('focusin.procuremenPoPop click.procuremenPoPop', '.procuremen-po-field', function () {
- procuremenPoPopoverShow($(this));
- });
- $bt.off('input.procuremenPoPop change.procuremenPoPop', '.procuremen-po-field')
- .on('input.procuremenPoPop change.procuremenPoPop', '.procuremen-po-field', function () {
- if (Controller.wffTab !== 'pick') {
- return;
- }
- var rowIdx = parseInt($(this).data('rowIndex'), 10);
- if (procuremenPoActiveRow === rowIdx) {
- procuremenPoPopoverSyncSaveBtn(rowIdx);
- procuremenPoPopoverPosition($(this));
- }
- });
- }
- procuremenEnsurePoPopover()
- .off('click.procuremenPoPopAct')
- .on('click.procuremenPoPopAct', '.procuremen-po-pop-cancel', function (e) {
- e.preventDefault();
- procuremenPoPopoverCancel();
- })
- .on('click.procuremenPoPopAct', '.procuremen-po-pop-save', function (e) {
- e.preventDefault();
- if (procuremenPoActiveRow === null || $(this).prop('disabled')) {
- return;
- }
- procuremenSavePoRow(procuremenPoActiveRow);
- });
- $(document).off('mousedown.procuremenPoPopClose').on('mousedown.procuremenPoPopClose', function (e) {
- if (Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') {
- return;
- }
- var $t = $(e.target);
- if ($t.closest('.procuremen-po-field, .procuremen-po-popover').length) {
- return;
- }
- // 点到别处时:有未保存修改则自动保存(避免删空后忘点保存)
- var rowIdx = procuremenPoActiveRow;
- if (rowIdx !== null && procuremenPoRowDirty(rowIdx)) {
- procuremenSavePoRow(rowIdx);
- return;
- }
- procuremenPoPopoverHide();
- });
- table.on('refresh.bs.table load-success.bs.table', function () {
- procuremenPoPopoverHide();
- });
- $(window).off('resize.procuremenPoPop scroll.procuremenPoPop')
- .on('resize.procuremenPoPop scroll.procuremenPoPop', function () {
- if (procuremenPoActiveRow === null || !$bt.length) {
- return;
- }
- var $active = $bt.find('.procuremen-po-field[data-row-index="' + procuremenPoActiveRow + '"]:focus');
- if ($active.length) {
- procuremenPoPopoverPosition($active);
- } else {
- procuremenPoPopoverHide();
- }
- });
- 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 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 auditIssueBtn = t.closest('a.procuremen-btn-audit-issue');
- if (auditIssueBtn && tableRoot.contains(auditIssueBtn) && !auditIssueBtn.classList.contains('disabled')) {
- e.preventDefault();
- if (typeof e.stopImmediatePropagation === 'function') {
- e.stopImmediatePropagation();
- }
- e.stopPropagation();
- var $aa = $(auditIssueBtn);
- var rowIdxA = parseInt($aa.data('rowIndex'), 10);
- var dataRowsA = table.bootstrapTable('getData');
- var rowA = !isNaN(rowIdxA) && dataRowsA[rowIdxA] !== undefined ? dataRowsA[rowIdxA] : null;
- var auditUrl;
- if (rowA) {
- auditUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/auditissue', rowA, table));
- } else {
- auditUrl = Backend.api.replaceids(auditIssueBtn, $aa.attr('href'));
- }
- var winA = window;
- if (winA.Backend && winA.Backend.api) {
- winA.Backend.api.open(auditUrl, '供应商报价明细', {area: ['96%', '88%']});
- }
- return;
- }
- };
- tableRoot.addEventListener('click', Controller._procuremenOpTableClick, true);
- }
- $layout.find('.procuremen-main').off('click.procuremenTbRefresh').on('click.procuremenTbRefresh', '.bootstrap-table > .fixed-table-toolbar .btn-refresh, #procuremen-toolbar-host .btn-refresh, .procuremen-table-area #toolbar .btn-refresh', function (e) {
- e.preventDefault();
- var $spinFa = $('.bootstrap-table > .fixed-table-toolbar .btn-refresh .fa, #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'))) {
- console.warn('procuremen redis refresh:', ret);
- }
- }).fail(function () {
- console.warn('procuremen redis refresh failed');
- }).always(function () {
- table.bootstrapTable('refresh');
- });
- } else {
- table.bootstrapTable('refresh');
- }
- });
- table.on('refresh.bs.table', function () {
- setTimeout(function () {
- procuremenPlaceToolbar();
- }, 0);
- });
- table.on('post-body.bs.table', function () {
- $('#procuremen-toolbar-host .btn-refresh .fa, .bootstrap-table > .fixed-table-toolbar .btn-refresh .fa').removeClass('fa-spin');
- procuremenScheduleAlign();
- if (Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') {
- return;
- }
- /* FastAdmin 每次 post-body 会重复绑定复选框列拖拽,多次勾选后易错位/缺框 */
- var $cbTd = table.closest('.bootstrap-table').find('tbody td.bs-checkbox');
- $cbTd.off('mousedown mousemove').removeClass('overlaped');
- $cbTd.each(function () {
- var $td = $(this);
- if (!$td.find('input[name="btSelectItem"]').length) {
- var idx = $td.closest('tr').data('index');
- if (idx !== undefined && idx !== '') {
- $td.html('<input name="btSelectItem" type="checkbox" data-index="' + idx + '" />');
- }
- }
- });
- });
- table.on('column-switch.bs.table reset-view.bs.table', function () {
- procuremenScheduleAlign();
- });
- if ($bt.length) {
- $bt.off('click.procuremenCbTd', 'tbody td.bs-checkbox').on('click.procuremenCbTd', 'tbody td.bs-checkbox', function (e) {
- if ((Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') || $(e.target).is('input[type="checkbox"]')) {
- return;
- }
- var $inp = $(this).find('input[name="btSelectItem"]:not(:disabled)').first();
- if ($inp.length) {
- e.preventDefault();
- $inp.trigger('click');
- }
- });
- }
- },
- pick: function () {
- Controller.index();
- },
- audit: function () {
- Controller.index();
- },
- confirm: function () {
- Controller.index();
- },
- rfqlist: function () {
- var isSuperAdmin = String($('.procuremen-rfqlist-wrap').data('super-admin') || '') === '1'
- || String($('.procuremen-rfqlist-wrap').attr('data-super-admin') || '') === '1';
- Table.api.init({
- extend: {
- index_url: 'procuremen/rfqlist' + location.search,
- table: 'purchase_order',
- }
- });
- var table = $('#table');
- var rfqHeightCached = 0;
- var rfqHeightTimer = null;
- function rfqCalcTableHeight() {
- var $bt = table.closest('.bootstrap-table');
- var el = $bt.length ? $bt[0] : table[0];
- if (!el || !el.getBoundingClientRect) {
- return 400;
- }
- // 必须从 .bootstrap-table 顶部算(含工具栏),才是插件 height 的总高
- var top = el.getBoundingClientRect().top;
- return Math.max(280, Math.floor(window.innerHeight - top - 18));
- }
- function rfqSyncTableHeight() {
- if (rfqHeightTimer) {
- clearTimeout(rfqHeightTimer);
- }
- rfqHeightTimer = setTimeout(function () {
- rfqHeightTimer = null;
- var h = rfqCalcTableHeight();
- if (rfqHeightCached > 0 && Math.abs(rfqHeightCached - h) <= 3) {
- rfqFitEmptyState();
- return;
- }
- rfqHeightCached = h;
- try {
- table.bootstrapTable('resetView', {height: h});
- } catch (ignore) {
- }
- rfqFitEmptyState();
- }, 100);
- }
- /** 无数据时占满表体高度,文案垂直居中到底部区域 */
- function rfqFitEmptyState() {
- var $bt = table.closest('.bootstrap-table');
- var $body = $bt.find('.fixed-table-body').first();
- var $tr = $body.find('tr.no-records-found');
- if (!$tr.length || !$body.length) {
- return;
- }
- var h = Math.max(160, Math.floor($body.innerHeight() || 0) - 4);
- $tr.find('> td').css({
- height: h + 'px',
- verticalAlign: 'middle',
- textAlign: 'center',
- color: '#8c8c8c',
- fontSize: '14px',
- border: 'none'
- });
- }
- var columns = [
- {field: 'CCYDH', title: '订单号', operate: 'LIKE', width: 120},
- {field: 'CYJMC', title: '印件名称', operate: 'LIKE', class: 'autocontent', formatter: Table.api.formatter.content},
- {field: 'CCLBMMC', title: '承揽部门', operate: 'LIKE', width: 100},
- {field: 'CGYMC', title: '工序名称', operate: 'LIKE', class: 'autocontent', formatter: Table.api.formatter.content},
- {
- field: 'progress_text',
- title: '当前进度',
- operate: false,
- width: 130,
- align: 'center',
- formatter: function (value) {
- var v = value == null ? '' : String(value);
- if (v === '已完结') {
- return '<span class="label label-success">' + v + '</span>';
- }
- if (v === '待采购确认' || v === '待确认供应商') {
- return '<span class="label label-warning">' + v + '</span>';
- }
- if (v === '已下发待确认') {
- return '<span class="label label-info">' + v + '</span>';
- }
- return v ? '<span class="label label-default">' + v + '</span>' : '';
- }
- },
- {
- field: 'createtime',
- title: '新增时间',
- operate: 'RANGE',
- addclass: 'datetimerange',
- autocomplete: false,
- width: 165,
- formatter: function (value, row) {
- if (row.createtime_text) {
- return row.createtime_text;
- }
- if (value == null || value === '') {
- return '';
- }
- var n = parseInt(value, 10);
- if (!isNaN(n) && n > 946684800) {
- return Table.api.formatter.datetime.call(this, value, row);
- }
- return String(value);
- }
- },
- {
- field: 'operate',
- title: '操作',
- width: 100,
- align: 'center',
- operate: false,
- table: table,
- formatter: function (value, row) {
- var sid = row && row.scydgy_id;
- if (!sid) {
- return '';
- }
- if (!procuremenCan('details')) {
- return '';
- }
- return '<a href="javascript:;" class="btn btn-xs btn-info btn-rfq-details" data-scydgy-id="' + sid + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>';
- },
- events: {}
- }
- ];
- if (isSuperAdmin) {
- columns.splice(4, 0, {field: 'cywyxm', title: '业务员', operate: 'LIKE', width: 90, align: 'center'});
- }
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'scydgy_id',
- sortName: 'id',
- sortOrder: 'desc',
- height: rfqCalcTableHeight(),
- commonSearch: true,
- pagination: true,
- smartDisplay: false,
- pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
- pageList: [10, 15, 20, 25, 50],
- showJumpto: true,
- formatNoMatches: function () {
- return '暂无数据';
- },
- columns: [columns]
- });
- Table.api.bindevent(table);
- table.on('post-body.bs.table load-success.bs.table', function () {
- rfqSyncTableHeight();
- setTimeout(rfqFitEmptyState, 0);
- });
- $(window).off('resize.procuremenRfqlist').on('resize.procuremenRfqlist', function () {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- rfqHeightCached = 0;
- rfqSyncTableHeight();
- });
- $(document).off('fa.sidebar.resized.procuremenRfq fa.table.relayout.procuremenRfq')
- .on('fa.sidebar.resized.procuremenRfq fa.table.relayout.procuremenRfq', function () {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- rfqHeightCached = 0;
- rfqSyncTableHeight();
- });
- $(document).off('click.procuremenRfqCommonSearch', 'button[name="commonSearch"]').on('click.procuremenRfqCommonSearch', 'button[name="commonSearch"]', function () {
- setTimeout(function () {
- rfqSyncTableHeight();
- rfqFitEmptyState();
- }, 150);
- });
- $(document).off('click.procuremenRfqDetails', '.btn-rfq-details').on('click.procuremenRfqDetails', '.btn-rfq-details', function (e) {
- e.preventDefault();
- var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
- if (!sid) {
- return;
- }
- var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
- Backend.api.open(url, '详情', {area: ['92%', '88%']});
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- outward_detail: function () {
- Controller.api.bindevent();
- procuremenInitSysRqSplit($('#outward-confirm-sys-rq-wrap'), 'outwardConfirm', {readonly: true});
- 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();
- var requiredSids = [];
- var allDetailsBySid = {};
- try {
- requiredSids = JSON.parse($wrap.attr('data-required-sids') || '[]');
- if (!Array.isArray(requiredSids)) {
- requiredSids = [];
- }
- } catch (eReq) {
- requiredSids = [];
- }
- try {
- allDetailsBySid = JSON.parse($wrap.attr('data-all-details-by-sid') || '{}');
- if (!allDetailsBySid || typeof allDetailsBySid !== 'object') {
- allDetailsBySid = {};
- }
- } catch (eAll) {
- allDetailsBySid = {};
- }
- if (requiredSids.length === 0) {
- requiredSids = [parseInt(scydgyId, 10)];
- }
- function parseDetailPicks($cb) {
- var raw = String($cb.attr('data-detail-picks') || '[]');
- try {
- var arr = JSON.parse(raw);
- return Array.isArray(arr) ? arr : [];
- } catch (e) {
- return [];
- }
- }
- function picksSidSet(picks) {
- var set = {};
- picks.forEach(function (p) {
- if (p && p.scydgy_id) {
- set[String(p.scydgy_id)] = true;
- }
- });
- return set;
- }
- function sidSetsOverlap(a, b) {
- var k;
- for (k in a) {
- if (a.hasOwnProperty(k) && b[k]) {
- return true;
- }
- }
- return false;
- }
- $wrap.off('.procuremenPurchaseConfirm');
- $wrap.find('.pod-company-pick-cb').prop('disabled', true);
- function procuremenOutwardFastRef() {
- if (typeof Fast !== 'undefined' && Fast.api) {
- return Fast;
- }
- if (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api) {
- return parent.Fast;
- }
- return null;
- }
- function procuremenOutwardToast(msg, type) {
- type = type || 'warning';
- var T = null;
- try {
- if (typeof parent !== 'undefined' && parent.Toastr) {
- T = parent.Toastr;
- }
- } catch (eP) {
- }
- if (!T && typeof Toastr !== 'undefined') {
- T = Toastr;
- }
- if (T) {
- if (type === 'error' && typeof T.error === 'function') {
- T.error(msg);
- } else if (typeof T.warning === 'function') {
- T.warning(msg);
- }
- return;
- }
- var Lm = procuremenLayerTop();
- if (Lm && typeof Lm.msg === 'function') {
- Lm.msg(msg);
- }
- }
- function onPurchaseConfirmClick(e) {
- if (e && typeof e.preventDefault === 'function') {
- e.preventDefault();
- }
- var FastRef = procuremenOutwardFastRef();
- if (!FastRef || !FastRef.api) {
- procuremenOutwardToast('页面未就绪,请刷新后重试', 'error');
- return;
- }
- var $checked = $wrap.find('.pod-company-pick-cb:checked');
- if (!$checked.length) {
- procuremenOutwardToast('未指定中标供应商,无法审批通过');
- return;
- }
- function escHtml(s) {
- return String(s)
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"');
- }
- function collectOrderPicks() {
- var winnerBySid = {};
- var conflict = false;
- $checked.each(function () {
- var picks = parseDetailPicks($(this));
- picks.forEach(function (p) {
- if (!p || !p.scydgy_id || !p.detail_id) {
- return;
- }
- var sid = String(p.scydgy_id);
- if (winnerBySid[sid]) {
- conflict = true;
- return;
- }
- winnerBySid[sid] = p;
- });
- });
- if (conflict) {
- return null;
- }
- var i;
- for (i = 0; i < requiredSids.length; i++) {
- if (!winnerBySid[String(requiredSids[i])]) {
- return null;
- }
- }
- var orderPicks = [];
- requiredSids.forEach(function (sid) {
- var win = winnerBySid[String(sid)];
- if (!win) {
- return;
- }
- var allIds = allDetailsBySid[String(sid)] || allDetailsBySid[sid] || [];
- if (!Array.isArray(allIds)) {
- allIds = [];
- }
- allIds = allIds.map(function (x) { return parseInt(String(x), 10); }).filter(function (x) { return x > 0; });
- var selId = parseInt(String(win.detail_id), 10);
- var unsel = allIds.filter(function (id) { return id !== selId; });
- orderPicks.push({
- scydgy_id: String(sid),
- purchase_order_id: parseInt(String(win.purchase_order_id || purchaseOrderId), 10) || 0,
- selected_ids: [selId],
- unselected_ids: unsel
- });
- });
- return orderPicks.length === requiredSids.length ? orderPicks : null;
- }
- var orderPicks = collectOrderPicks();
- if (!orderPicks || orderPicks.length === 0) {
- procuremenOutwardToast(requiredSids.length > 1
- ? '所选供应商须覆盖本单全部工序,且同一工序不可重复选择'
- : '请勾选一家供应商');
- return;
- }
- var okNames = [];
- var unNames = [];
- $checked.each(function () {
- var $tr = $(this).closest('tr');
- var nm = $.trim($tr.children('td').eq(1).text());
- if (nm) {
- okNames.push(nm);
- }
- });
- $wrap.find('.pod-company-pick-cb').not(':checked').each(function () {
- var $tr = $(this).closest('tr');
- var nm = $.trim($tr.children('td').eq(1).text());
- if (nm) {
- unNames.push(nm);
- }
- });
- var nOk = okNames.length;
- var nUn = unNames.length;
- var okListText = nOk ? (nOk <= 4 ? okNames.join('、') : (okNames.slice(0, 3).join('、') + ' 等共' + nOk + '家')) : '—';
- var unListText = nUn ? (nUn <= 4 ? unNames.join('、') : (unNames.slice(0, 3).join('、') + ' 等共' + nUn + '家')) : '—';
- var tk = $('input[name=\'__token__\']').val() || $wrap.find('input[name=\'__token__\']').val() || '';
- 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>中标 ' + nOk + ' 家</strong>:将向 <strong>' + escHtml(okListText) + '</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') {
- procuremenOutwardToast('弹层组件未就绪,请刷新后重试', '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: {
- __token__: tk,
- order_picks_json: JSON.stringify(orderPicks)
- }
- }, 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');
- }
- }
- });
- });
- }
- function onPurchaseRejectClick(e) {
- if (e && typeof e.preventDefault === 'function') {
- e.preventDefault();
- }
- var FastRef = procuremenOutwardFastRef();
- if (!FastRef || !FastRef.api) {
- procuremenOutwardToast('页面未就绪,请刷新后重试', 'error');
- return;
- }
- var rejectPicks = requiredSids.map(function (sid) {
- return {scydgy_id: String(sid)};
- });
- if (!rejectPicks.length) {
- rejectPicks = [{scydgy_id: scydgyId}];
- }
- var Lr = procuremenLayerTop();
- if (!Lr || typeof Lr.confirm !== 'function') {
- procuremenOutwardToast('弹层组件未就绪,请刷新后重试', 'error');
- return;
- }
- Lr.confirm(
- '是否确认驳回?',
- {
- icon: 0,
- title: '采购终审 — 审批驳回',
- area: ['460px', 'auto'],
- btn: ['确认驳回', '取消'],
- zIndex: procuremenLayerNextZIndex()
- },
- function (idx) {
- Lr.close(idx);
- FastRef.api.ajax({
- url: FastRef.api.fixurl('procuremen/purchaseApprovalReject'),
- type: 'POST',
- data: {
- __token__: $('input[name=\'__token__\']').val() || $wrap.find('input[name=\'__token__\']').val() || '',
- order_picks_json: JSON.stringify(rejectPicks)
- }
- }, 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$ && p$('#table').length) {
- p$('#table').bootstrapTable('refresh');
- }
- });
- }
- );
- }
- function onPurchaseCloseClick(e) {
- if (e && typeof e.preventDefault === 'function') {
- e.preventDefault();
- }
- 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();
- }
- }
- function bindOutwardPurchaseFooterButtons() {
- $(document)
- .off('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm')
- .on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm', onPurchaseConfirmClick)
- .off('click.procuremenPurchaseConfirm', '#btn-pod-purchase-reject')
- .on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-reject', onPurchaseRejectClick)
- .off('click.procuremenPurchaseConfirm', '#btn-pod-purchase-close')
- .on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-close', onPurchaseCloseClick);
- $('#btn-pod-purchase-confirm').off('click.procuremenPurchaseConfirmDirect').on('click.procuremenPurchaseConfirmDirect', onPurchaseConfirmClick);
- $('#btn-pod-purchase-reject').off('click.procuremenPurchaseConfirmDirect').on('click.procuremenPurchaseConfirmDirect', onPurchaseRejectClick);
- $('#btn-pod-purchase-close').off('click.procuremenPurchaseConfirmDirect').on('click.procuremenPurchaseConfirmDirect', onPurchaseCloseClick);
- }
- bindOutwardPurchaseFooterButtons();
- setTimeout(bindOutwardPurchaseFooterButtons, 350);
- },
- details: function () {
- Controller.api.bindevent();
- },
- review: function () {
- Controller.api.bindevent();
- procuremenInitSysRqSplit($('#review-sys-rq-wrap'), 'reviewSysRq');
- function procuremenReviewWarn(msg) {
- var shown = false;
- try {
- if (typeof parent !== 'undefined' && parent.Toastr && typeof parent.Toastr.warning === 'function') {
- parent.Toastr.warning(msg);
- shown = true;
- }
- } catch (ignoreParentToast) {
- }
- if (!shown) {
- if (typeof Toastr !== 'undefined') {
- Toastr.warning(msg);
- } else if (typeof Layer !== 'undefined') {
- Layer.msg(msg);
- }
- }
- }
- function procuremenReviewFastRef() {
- if (typeof Fast !== 'undefined' && Fast.api) {
- return Fast;
- }
- if (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api) {
- return parent.Fast;
- }
- return null;
- }
- function procuremenReviewIsPickMode() {
- if (/pickreview/i.test((window.location.pathname || '') + (window.location.search || ''))) {
- return true;
- }
- var $form = $('#review-form');
- var pm = $form.attr('data-pick-mode');
- if (pm === '1') {
- return true;
- }
- pm = $form.data('pickMode');
- if (pm === 1 || pm === '1') {
- return true;
- }
- pm = $form.data('pick-mode');
- return pm === 1 || pm === '1';
- }
- function procuremenReviewCollectSelected() {
- var selected = [];
- var seen = {};
- $('#review-company-tbody .review-company-cb:checked').each(function () {
- var c = $(this).data('company');
- if (!c || typeof c !== 'object') {
- return;
- }
- var k = procuremenReviewCompanyKey(c);
- if (k && seen[k]) {
- return;
- }
- if (k) {
- seen[k] = true;
- }
- selected.push(procuremenReviewCompanyPayload(c));
- });
- return selected;
- }
- function onReviewSubmitClick(e) {
- if (e && typeof e.preventDefault === 'function') {
- e.preventDefault();
- }
- if (e && typeof e.stopPropagation === 'function') {
- e.stopPropagation();
- }
- var $rqWrap = $('#review-sys-rq-wrap');
- $rqWrap.find('.procuremen-sys-rq-date').trigger('change');
- var $rq = $('#review-sys-rq');
- var isPickMode = procuremenReviewIsPickMode();
- var selected = procuremenReviewCollectSelected();
- if (!selected.length) {
- procuremenReviewWarn(isPickMode ? '请至少选择一家合作供应商' : '请至少选择一个下发单位');
- return;
- }
- var sysRq = ($rq.val() || '').trim();
- if (!sysRq) {
- procuremenReviewWarn('请选择截止时间');
- procuremenFocusSysRqSplit($rqWrap);
- return;
- }
- var cons;
- try {
- cons = JSON.parse($('#c-row-json').val() || '{}');
- } catch (ignoreParseRow) {
- cons = {};
- }
- var mergePayload = ($('#c-merge-rows-json').val() || '').trim();
- if (!mergePayload) {
- mergePayload = JSON.stringify([cons]);
- }
- var $submitBtn = $('#btn-review-submit');
- if ($submitBtn.prop('disabled')) {
- return;
- }
- var FastRef = procuremenReviewFastRef();
- if (!FastRef || !FastRef.api) {
- procuremenReviewWarn('页面未就绪,请刷新后重试');
- return;
- }
- var submitBtnHtml = $submitBtn.html();
- $submitBtn.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> 提交中…');
- FastRef.api.ajax({
- url: FastRef.api.fixurl(isPickMode ? 'procuremen/picksubmit' : 'procuremen/review'),
- type: 'POST',
- data: {
- __token__: $('input[name=\'__token__\']').val(),
- row_json: JSON.stringify(cons),
- merge_rows_json: mergePayload,
- companies_json: JSON.stringify(selected),
- sys_rq: sysRq
- }
- }, function (data, ret) {
- var msg = (ret && ret.msg) ? ret.msg : '操作成功';
- try {
- sessionStorage.removeItem('procuremen_merge_rows');
- } catch (ignoreClr) {
- }
- var index = parent.Layer.getFrameIndex(window.name);
- if (typeof parent !== 'undefined' && parent.Layer && index) {
- parent.Layer.close(index);
- }
- if (typeof parent !== 'undefined' && parent.Toastr) {
- parent.Toastr.success(msg);
- } else if (typeof Toastr !== 'undefined') {
- Toastr.success(msg);
- }
- if (parent && parent.$ && parent.$('#table').length) {
- parent.$('#table').bootstrapTable('refresh', {silent: true});
- }
- return false;
- }, function (data, ret) {
- $submitBtn.prop('disabled', false).html(submitBtnHtml);
- var errMsg = (ret && ret.msg) ? ret.msg : '提交失败,请重试';
- procuremenReviewWarn(errMsg);
- return false;
- });
- }
- function bindReviewFooterButtons() {
- $(document)
- .off('click.procuremenReviewSubmit', '#btn-review-submit')
- .on('click.procuremenReviewSubmit', '#btn-review-submit', onReviewSubmitClick);
- $('#btn-review-submit')
- .off('click.procuremenReviewSubmitDirect')
- .on('click.procuremenReviewSubmitDirect', onReviewSubmitClick);
- }
- bindReviewFooterButtons();
- setTimeout(bindReviewFooterButtons, 350);
- function procuremenReviewCloseLayer() {
- try {
- if (typeof parent !== 'undefined' && parent.Layer) {
- var index = parent.Layer.getFrameIndex(window.name);
- if (index) {
- parent.Layer.close(index);
- return;
- }
- }
- } catch (ignoreClose) {
- }
- if (typeof Layer !== 'undefined' && typeof Layer.closeAll === 'function') {
- Layer.closeAll();
- }
- }
- $(document).off('keydown.procuremenReviewEsc').on('keydown.procuremenReviewEsc', function (e) {
- if (e.keyCode !== 27 && e.key !== 'Escape') {
- return;
- }
- procuremenReviewCloseLayer();
- e.preventDefault();
- });
- $('.btn-close').off('click.procuremenReviewClose').on('click.procuremenReviewClose', function (e) {
- e.preventDefault();
- procuremenReviewCloseLayer();
- });
- var isPickReviewEntry = /pickreview/i.test((window.location.pathname || '') + (window.location.search || ''));
- var ids = window.Fast && Fast.api ? Fast.api.query('ids') : null;
- if (ids === null || ids === '') {
- Toastr.error('请刷新页面后重试');
- return;
- }
- var $ptable = $();
- try {
- if (typeof parent !== 'undefined' && parent.$) {
- $ptable = parent.$('#table');
- }
- } catch (ignoreParentTable) {
- $ptable = $();
- }
- if (!$ptable.length && !isPickReviewEntry) {
- Toastr.error('请刷新页面后重试');
- return;
- }
- var pk = 'ID';
- var row = null;
- if ($ptable.length) {
- pk = $ptable.bootstrapTable('getOptions').pk || 'ID';
- $.each($ptable.bootstrapTable('getData'), function (i, r) {
- if (String(r[pk]) === String(ids)) {
- row = r;
- return false;
- }
- });
- }
- var mergeRows = [];
- var mergeFlag = window.Fast && Fast.api ? String(Fast.api.query('merge') || '') : '';
- if (mergeFlag === '1') {
- try {
- var rawMerge = sessionStorage.getItem('procuremen_merge_rows');
- if (rawMerge) {
- var parsed = JSON.parse(rawMerge);
- if ($.isArray(parsed) && parsed.length) {
- mergeRows = parsed;
- }
- }
- } catch (ignoreMerge) {
- }
- }
- if (mergeFlag === '1' && !mergeRows.length && row) {
- mergeRows = [row];
- }
- if (mergeRows.length) {
- row = mergeRows[0];
- } else if (!row) {
- Toastr.error('请刷新页面后重试');
- return;
- }
- function procuremenReviewQtyDisp(r) {
- if (!r) {
- return '';
- }
- if (r.This_quantity != null && String(r.This_quantity).trim() !== '') {
- return String(r.This_quantity).trim();
- }
- if (r.this_quantity != null && String(r.this_quantity).trim() !== '') {
- return String(r.this_quantity).trim();
- }
- if (r.NGZL != null && String(r.NGZL).trim() !== '') {
- return String(r.NGZL).trim();
- }
- if (r.ngzl != null && String(r.ngzl).trim() !== '') {
- return String(r.ngzl).trim();
- }
- return '';
- }
- function procuremenReviewPriceDisp(r) {
- if (!r) {
- return '';
- }
- if (r.ceilingPrice != null && String(r.ceilingPrice).trim() !== '') {
- return String(r.ceilingPrice).trim();
- }
- if (r.ceiling_price != null && String(r.ceiling_price).trim() !== '') {
- return String(r.ceiling_price).trim();
- }
- return '';
- }
- function applyProcuremenMergeReviewUi(rows) {
- var list = $.isArray(rows) && rows.length ? rows : (row ? [row] : []);
- var $tb = $('#review-merge-tbody').empty();
- var orderKey0 = list.length ? String(list[0].CCYDH || '').trim() : '';
- var nameKey0 = list.length ? String(list[0].CYJMC || '').trim() : '';
- var mergeSameOrder = list.length > 1 && orderKey0 !== '';
- if (mergeSameOrder) {
- $.each(list, function (i, rr) {
- if (String(rr.CCYDH || '').trim() !== orderKey0
- || String(rr.CYJMC || '').trim() !== nameKey0) {
- mergeSameOrder = false;
- return false;
- }
- });
- }
- $.each(list, function (idx, r) {
- var qty = procuremenReviewQtyDisp(r);
- var price = procuremenReviewPriceDisp(r);
- var ccydh = String(r.CCYDH != null ? r.CCYDH : '').trim();
- var cyjmc = String(r.CYJMC != null ? r.CYJMC : '').trim();
- var $tr = $('<tr/>');
- if (mergeSameOrder && idx === 0) {
- $tr.append(
- $('<td class="text-center"/>').attr('rowspan', list.length).text(ccydh),
- $('<td/>').attr('rowspan', list.length).text(cyjmc)
- );
- } else if (!mergeSameOrder) {
- $tr.append(
- $('<td class="text-center"/>').text(ccydh),
- $('<td/>').text(cyjmc)
- );
- }
- $tr.append(
- $('<td/>').text(r.CGYMC || ''),
- $('<td class="text-center"/>').text(r.CDW != null && r.CDW !== '' ? r.CDW : ''),
- $('<td class="text-center"/>').text(qty),
- $('<td class="text-center"/>').text(price),
- $('<td class="text-center"/>').text(r.CDF || ''),
- $('<td/>').text(r.MBZ != null && r.MBZ !== '' ? String(r.MBZ) : '')
- );
- $tb.append($tr);
- });
- var isPickModeUi = procuremenReviewIsPickMode();
- if (isPickModeUi && list.length > 1) {
- $('.procuremen-review-submit-tip').html(
- '<i class="fa fa-exclamation-triangle"></i> '
- + '<strong>合并单:</strong>确认后将向所选供应商<strong>发送短信与邮件</strong>;'
- + '本单含 <strong>' + list.length + ' 道工序</strong>,请核对后再确认。'
- );
- }
- $('#c-merge-rows-json').val(JSON.stringify(list));
- }
- applyProcuremenMergeReviewUi(mergeRows.length ? mergeRows : (row ? [row] : []));
- var isPickMode = procuremenReviewIsPickMode();
- $('#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 = procuremenReviewCompanyKey(c);
- 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 = procuremenReviewCompanyKey(c);
- 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 = procuremenReviewCompanyKey(c);
- 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 = procuremenReviewCompanyKey(c);
- 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');
- });
- });
- /** 加载供应商列表(弹窗内勾选单位) */
- function loadReviewCompaniesPanel() {
- 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 = procuremenReviewCompanyKey(c);
- 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;
- });
- }
- /*
- * 协助下发:打开弹窗仅展示供应商,不写 purchase_order(确认下发走 picksubmit)。
- * 非协助模式:仅当列表已填本次数量或最高限价时才 snapshot(草稿)。
- */
- if (isPickMode) {
- loadReviewCompaniesPanel();
- } else if (procuremenReviewQtyDisp(row) !== '' || procuremenReviewPriceDisp(row) !== '') {
- Fast.api.ajax({
- url: 'procuremen/snapshotToProcure',
- type: 'POST',
- data: {
- __token__: $('input[name=\'__token__\']').val(),
- row_json: JSON.stringify(row)
- }
- }, function () {
- loadReviewCompaniesPanel();
- return false;
- });
- } else {
- loadReviewCompaniesPanel();
- }
- },
- pickreview: function () {
- Controller.review();
- },
- pickadd: function () {
- Controller.api.bindevent();
- $(document).off('click.procuremenPickAddClose', '.btn-procuremen-pick-add-close').on('click.procuremenPickAddClose', '.btn-procuremen-pick-add-close', function () {
- var index = parent.Layer.getFrameIndex(window.name);
- parent.Layer.close(index);
- });
- },
- auditissue: function () {
- function auditIssueClose() {
- var index = parent.Layer.getFrameIndex(window.name);
- parent.Layer.close(index);
- }
- function auditIssueSysRq() {
- return ($('#audit-sys-rq').val() || '').trim();
- }
- /** 是否已过报价截止时间(无截止时间时按已到处理,与后端一致) */
- function auditIssueQuoteDeadlineReached() {
- var sysRq = auditIssueSysRq();
- if (!sysRq) {
- return true;
- }
- var normalized = String(sysRq).replace(/T/, ' ').replace(/-/g, '/');
- var ts = Date.parse(normalized);
- if (!ts || isNaN(ts)) {
- return true;
- }
- return Date.now() >= ts;
- }
- function auditIssueValidateSysRq() {
- $('#audit-sys-rq-wrap').find('.procuremen-sys-rq-date').trigger('change');
- var sysRq = auditIssueSysRq();
- if (!sysRq) {
- Toastr.warning('请选择报价截止时间');
- procuremenFocusSysRqSplit($('#audit-sys-rq-wrap'));
- return false;
- }
- return true;
- }
- function auditIssueAjaxData(extra) {
- var data = {
- __token__: $('input[name=\'__token__\']').val(),
- scydgy_id: $('input[name=\'scydgy_id\']').val(),
- sys_rq: auditIssueSysRq()
- };
- if (extra) {
- $.extend(data, extra);
- }
- return data;
- }
- procuremenInitSysRqSplit($('#audit-sys-rq-wrap'), 'auditIssue', {readonly: true});
- function auditIssueBidOpenVerified() {
- return parseInt($('#audit-bid-open-verified').val(), 10) === 1;
- }
- function auditIssueBidOpenSmsResendCd() {
- var cd = 55;
- if (typeof Config !== 'undefined' && Config.mprocSmsResendCd) {
- cd = parseInt(Config.mprocSmsResendCd, 10) || cd;
- }
- return Math.max(30, Math.min(120, cd));
- }
- function auditIssueResetBidOpenSendBtn($btn) {
- if (!$btn || !$btn.length) {
- return;
- }
- var timer = $btn.data('cdTimer');
- if (timer) {
- clearInterval(timer);
- $btn.removeData('cdTimer');
- }
- $btn.data('loading', 0);
- $btn.prop('disabled', false).text('发送验证码');
- }
- function auditIssueStartBidOpenSendCountdown($btn) {
- if (!$btn || !$btn.length) {
- return;
- }
- var timer = $btn.data('cdTimer');
- if (timer) {
- clearInterval(timer);
- $btn.removeData('cdTimer');
- }
- var left = auditIssueBidOpenSmsResendCd();
- $btn.data('loading', 0).prop('disabled', true).text('已发送');
- setTimeout(function () {
- if (!$btn.closest('body').length) {
- return;
- }
- $btn.text(left + '秒后重发');
- timer = setInterval(function () {
- left--;
- if (!$btn.closest('body').length) {
- clearInterval(timer);
- return;
- }
- if (left <= 0) {
- clearInterval(timer);
- $btn.removeData('cdTimer');
- $btn.prop('disabled', false).text('发送验证码');
- return;
- }
- $btn.text(left + '秒后重发');
- }, 1000);
- $btn.data('cdTimer', timer);
- }, 1000);
- }
- function auditIssueOpenBidModal() {
- if (!procuremenCan('bidopenverify') && !procuremenCan('bidopen') && !procuremenCan('auditissue')) {
- Toastr.warning('无开标权限');
- return;
- }
- if (auditIssueBidOpenVerified()) {
- Toastr.info('本单已完成开标验证');
- return;
- }
- if (!auditIssueQuoteDeadlineReached()) {
- Toastr.warning('未到截止时间');
- return;
- }
- var users = [];
- var BID_OPEN_LAST_USERS_KEY = 'xh_procuremen_bid_open_last_users';
- function auditIssueLoadLastBidOpenUsers() {
- try {
- var raw = localStorage.getItem(BID_OPEN_LAST_USERS_KEY);
- if (!raw) {
- return {v1: 0, v2: 0};
- }
- var parsed = JSON.parse(raw);
- return {
- v1: parseInt(parsed && parsed.v1, 10) || 0,
- v2: parseInt(parsed && parsed.v2, 10) || 0
- };
- } catch (e) {
- return {v1: 0, v2: 0};
- }
- }
- function auditIssueSaveLastBidOpenUsers(v1, v2) {
- v1 = parseInt(v1, 10) || 0;
- v2 = parseInt(v2, 10) || 0;
- if (!v1 && !v2) {
- return;
- }
- try {
- localStorage.setItem(BID_OPEN_LAST_USERS_KEY, JSON.stringify({v1: v1, v2: v2}));
- } catch (e) {
- }
- }
- function auditIssueUserExists(uid) {
- uid = parseInt(uid, 10) || 0;
- if (!uid) {
- return false;
- }
- var found = false;
- $.each(users, function (i, u) {
- if ((parseInt(u.id, 10) || 0) === uid) {
- found = true;
- return false;
- }
- });
- return found;
- }
- function auditIssueRenderBidOpenUserOptions(excludeId, selectedId) {
- var opts = '<option value="">请选择</option>';
- $.each(users, function (i, u) {
- var uid = parseInt(u.id, 10) || 0;
- if (!uid) {
- return;
- }
- if (excludeId && uid === parseInt(excludeId, 10)) {
- return;
- }
- var label = (u.nickname || u.username || ('ID' + uid));
- if (u.group_name || u.mobile) {
- label += '(';
- if (u.group_name) {
- label += u.group_name;
- }
- if (u.group_name && u.mobile) {
- label += ' · ';
- }
- if (u.mobile) {
- label += u.mobile;
- }
- label += ')';
- }
- var selected = selectedId && uid === parseInt(selectedId, 10) ? ' selected="selected"' : '';
- opts += '<option value="' + uid + '"' + selected + '>' + $('<div>').text(label).html() + '</option>';
- });
- return opts;
- }
- function auditIssueSyncBidOpenUserSelects(changedSlot) {
- var v1 = parseInt($('#bid-open-user-1').val(), 10) || 0;
- var v2 = parseInt($('#bid-open-user-2').val(), 10) || 0;
- if (v1 && v2 && v1 === v2) {
- if (changedSlot === 1) {
- v2 = 0;
- $('#bid-open-user-2').val('');
- $('#bid-open-code-2').val('');
- } else {
- v1 = 0;
- $('#bid-open-user-1').val('');
- $('#bid-open-code-1').val('');
- }
- }
- $('#bid-open-user-1').html(auditIssueRenderBidOpenUserOptions(v2, v1));
- $('#bid-open-user-2').html(auditIssueRenderBidOpenUserOptions(v1, v2));
- auditIssueSaveLastBidOpenUsers(v1, v2);
- }
- function auditIssueApplyLastBidOpenUsers() {
- var last = auditIssueLoadLastBidOpenUsers();
- var v1 = auditIssueUserExists(last.v1) ? last.v1 : 0;
- var v2 = auditIssueUserExists(last.v2) ? last.v2 : 0;
- if (v1 && v2 && v1 === v2) {
- v2 = 0;
- }
- $('#bid-open-user-1').html(auditIssueRenderBidOpenUserOptions(v2, v1));
- $('#bid-open-user-2').html(auditIssueRenderBidOpenUserOptions(v1, v2));
- }
- var html = [
- '<div class="audit-bid-open-modal">',
- '<p class="bid-open-tip"><i class="fa fa-info-circle"></i> 请选择两名用户,分别发送验证码并填写。验证通过后可查看供应商报价信息。</p>',
- '<div class="bid-open-row bid-open-row-1">',
- '<label>验证人1</label>',
- '<select class="form-control bid-open-user" id="bid-open-user-1"><option value="">请选择</option></select>',
- '<button type="button" class="btn btn-default btn-sm btn-send-code" data-slot="1">发送验证码</button>',
- '<input type="text" class="form-control bid-open-code" id="bid-open-code-1" maxlength="6" placeholder="6位验证码"/>',
- '</div>',
- '<div class="bid-open-row bid-open-row-2">',
- '<label>验证人2</label>',
- '<select class="form-control bid-open-user" id="bid-open-user-2"><option value="">请选择</option></select>',
- '<button type="button" class="btn btn-default btn-sm btn-send-code" data-slot="2">发送验证码</button>',
- '<input type="text" class="form-control bid-open-code" id="bid-open-code-2" maxlength="6" placeholder="6位验证码"/>',
- '</div>',
- '</div>'
- ].join('');
- var layerIdx = Layer.open({
- type: 1,
- title: '开标验证',
- area: ['560px', 'auto'],
- content: html,
- btn: ['提交验证', '取消'],
- yes: function (idx) {
- var v1 = parseInt($('#bid-open-user-1').val(), 10) || 0;
- var v2 = parseInt($('#bid-open-user-2').val(), 10) || 0;
- var c1 = $.trim($('#bid-open-code-1').val());
- var c2 = $.trim($('#bid-open-code-2').val());
- if (!v1 || !v2) {
- Toastr.warning('请选择两位验证人');
- return;
- }
- if (v1 === v2) {
- Toastr.warning('两位验证人不能相同');
- return;
- }
- if (!/^\d{6}$/.test(c1) || !/^\d{6}$/.test(c2)) {
- Toastr.warning('请输入6位短信验证码');
- return;
- }
- Fast.api.ajax({
- url: 'procuremen/bidopenverify',
- type: 'POST',
- data: auditIssueAjaxData({
- verifier1_id: v1,
- verifier2_id: v2,
- code1: c1,
- code2: c2
- })
- }, function (data, ret) {
- auditIssueSaveLastBidOpenUsers(v1, v2);
- Layer.close(idx);
- var msg = (ret && ret.msg) ? ret.msg : '开标验证成功';
- Toastr.success(msg);
- setTimeout(function () {
- window.location.reload();
- }, 400);
- return false;
- });
- }
- });
- Fast.api.ajax({
- url: 'procuremen/bidopenusers',
- type: 'GET',
- data: {scydgy_id: $('input[name=\'scydgy_id\']').val()}
- }, function (data, ret) {
- var payload = (ret && ret.data) ? ret.data : (data || {});
- if (parseInt(payload.verified, 10) === 1) {
- Layer.close(layerIdx);
- Toastr.info('本单已完成开标验证');
- setTimeout(function () {
- window.location.reload();
- }, 400);
- return false;
- }
- users = payload.users || [];
- auditIssueApplyLastBidOpenUsers();
- $(document).off('change.bidOpenUser', '#bid-open-user-1, #bid-open-user-2')
- .on('change.bidOpenUser', '#bid-open-user-1', function () {
- auditIssueResetBidOpenSendBtn($('.btn-send-code[data-slot="1"]'));
- auditIssueSyncBidOpenUserSelects(1);
- })
- .on('change.bidOpenUser', '#bid-open-user-2', function () {
- auditIssueResetBidOpenSendBtn($('.btn-send-code[data-slot="2"]'));
- auditIssueSyncBidOpenUserSelects(2);
- });
- return false;
- });
- $(document).off('click.bidOpenSend', '.btn-send-code').on('click.bidOpenSend', '.btn-send-code', function () {
- var slot = $(this).attr('data-slot');
- var adminId = parseInt($('#bid-open-user-' + slot).val(), 10) || 0;
- if (!adminId) {
- Toastr.warning('请先选择验证人' + slot);
- return;
- }
- var $btn = $(this);
- if ($btn.data('loading') || $btn.prop('disabled')) {
- return;
- }
- $btn.data('loading', 1).prop('disabled', true).text('发送中…');
- Fast.api.ajax({
- url: 'procuremen/bidopensendcode',
- type: 'POST',
- data: auditIssueAjaxData({admin_id: adminId})
- }, function (data, ret) {
- Toastr.success((ret && ret.msg) ? ret.msg : '验证码已发送');
- auditIssueStartBidOpenSendCountdown($btn);
- return false;
- }, function () {
- auditIssueResetBidOpenSendBtn($btn);
- });
- });
- }
- $('#btn-audit-bid-open').off('click.auditBidOpen').on('click.auditBidOpen', function () {
- auditIssueOpenBidModal();
- });
- function auditIssueSelectedCompany() {
- var $checked = $('input[name="audit_quote_pick"]:checked');
- if (!$checked.length) {
- return '';
- }
- return $.trim($checked.val());
- }
- function auditIssuePostResendEmail(companies) {
- if (!companies || !companies.length) {
- Toastr.warning('请选择供应商');
- return;
- }
- if (!auditIssueValidateSysRq()) {
- return;
- }
- var company = companies[0];
- Layer.confirm('向「' + company + '」发送邮件?', {icon: 3, title: '发邮件', btn: ['发送', '取消']}, function (layerIdx) {
- Layer.close(layerIdx);
- Fast.api.ajax({
- url: 'procuremen/auditresendemail',
- type: 'POST',
- data: auditIssueAjaxData({
- companies_json: JSON.stringify([company])
- })
- }, function (data, ret) {
- var msg = (ret && ret.msg) ? ret.msg : '已发送';
- if (typeof parent !== 'undefined' && parent.Toastr) {
- parent.Toastr.success(msg);
- }
- return false;
- });
- });
- }
- function auditIssuePostResendSms(company) {
- if (!company) {
- Toastr.warning('请选择供应商');
- return;
- }
- if (!auditIssueValidateSysRq()) {
- return;
- }
- Layer.confirm('向「' + company + '」发送短信?', {icon: 3, title: '发短信', btn: ['发送', '取消']}, function (layerIdx) {
- Layer.close(layerIdx);
- Fast.api.ajax({
- url: 'procuremen/auditresendsms',
- type: 'POST',
- data: auditIssueAjaxData({
- selected_company: company
- })
- }, function (data, ret) {
- var msg = (ret && ret.msg) ? ret.msg : '已发送';
- if (typeof parent !== 'undefined' && parent.Toastr) {
- parent.Toastr.success(msg);
- }
- return false;
- });
- });
- }
- $('#audit-quote-tbody').off('click.auditQuoteRow', 'tr').on('click.auditQuoteRow', 'tr', function (e) {
- if ($(e.target).closest('input, label, a, button').length) {
- return;
- }
- var $radio = $(this).find('.audit-quote-pick').first();
- if ($radio.length) {
- $radio.prop('checked', true);
- }
- });
- $('#btn-audit-issue-close').off('click.auditClose').on('click.auditClose', function () {
- auditIssueClose();
- });
- $('#btn-audit-issue-submit').off('click.auditIssue').on('click.auditIssue', function () {
- var company = auditIssueSelectedCompany();
- if (!company) {
- Toastr.warning('请选择一家供应商');
- return;
- }
- if (!auditIssueBidOpenVerified()) {
- Toastr.warning('请先完成开标验证后再确认供应商');
- return;
- }
- if (!auditIssueValidateSysRq()) {
- return;
- }
- Layer.confirm(
- '选定供应商「' + company + '」并进入审批<br/><span style="color:#666;">本步不发送短信。</span>',
- {icon: 3, title: '选择供应商', btn: ['确认', '取消']},
- function (layerIdx) {
- Layer.close(layerIdx);
- Fast.api.ajax({
- url: 'procuremen/auditsubmit',
- type: 'POST',
- data: auditIssueAjaxData({
- selected_company: company
- })
- }, 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');
- }
- auditIssueClose();
- return false;
- });
- }
- );
- });
- $('#audit-quote-tbody').off('click.auditRowEmail', '.audit-row-send-email').on('click.auditRowEmail', '.audit-row-send-email', function (e) {
- e.preventDefault();
- e.stopPropagation();
- var company = $.trim($(this).attr('data-company') || '');
- if (!company) {
- return;
- }
- auditIssuePostResendEmail([company]);
- });
- $('#audit-quote-tbody').off('click.auditRowSms', '.audit-row-send-sms').on('click.auditRowSms', '.audit-row-send-sms', function (e) {
- e.preventDefault();
- e.stopPropagation();
- var company = $.trim($(this).attr('data-company') || '');
- if (!company) {
- return;
- }
- auditIssuePostResendSms(company);
- });
- },
- emaillog: function () {
- Table.api.init({
- extend: {
- index_url: 'procuremen/emaillog' + location.search,
- table: 'purchase_email_send_log',
- }
- });
- var table = $("#table");
- var colCenter = {align: 'center', valign: 'middle'};
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- sortOrder: 'desc',
- commonSearch: true,
- columns: [
- [
- $.extend({field: 'id', title: __('Id'), width: 60, operate: false}, colCenter),
- $.extend({field: 'ccydh', title: '订单号', operate: 'LIKE'}, colCenter),
- $.extend({field: 'from_email', title: '发件邮箱', operate: 'LIKE', formatter: function (v, row) {
- return row.from_email_masked || v || '';
- }}, colCenter),
- $.extend({field: 'to_email', title: '供应商邮箱', operate: 'LIKE', formatter: function (v, row) {
- return row.to_email_masked || v || '';
- }}, colCenter),
- $.extend({field: 'company_name', title: '供应商', operate: 'LIKE'}, colCenter),
- $.extend({field: 'scene', title: '场景', operate: '=', searchList: {'pick_issue': '初选下发', 'audit_resend': '确认页重发'}, formatter: function (v, row) {
- return row.scene_text || v || '';
- }}, colCenter),
- $.extend({field: 'mail_subject', title: '邮件主题', operate: 'LIKE', class: 'autocontent', formatter: Table.api.formatter.content}, colCenter),
- $.extend({field: 'status', title: '状态', operate: '=', searchList: {'1': '成功', '0': '失败'}, formatter: function (v, row) {
- var t = row.status_text || (String(v) === '1' ? '成功' : '失败');
- return String(v) === '1' || v === 1
- ? '<span class="text-success">' + t + '</span>'
- : '<span class="text-danger">' + t + '</span>';
- }}, colCenter),
- $.extend({field: 'admin_name', title: '操作人', operate: 'LIKE'}, colCenter),
- $.extend({field: 'send_time', title: '操作时间', operate: 'RANGE', addclass: 'datetimerange', sortable: true}, colCenter),
- $.extend({field: 'fail_reason', title: '失败原因', operate: false, class: 'autocontent', formatter: Table.api.formatter.content}, colCenter)
- ]
- ]
- });
- Table.api.bindevent(table);
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($('form[role=form]'));
- }
- }
- };
- return Controller;
- });
|