procuremen.js 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. function maskProcuremenEmail(email) {
  3. email = (email == null ? '' : String(email)).trim();
  4. if (!email) {
  5. return '';
  6. }
  7. var at = email.indexOf('@');
  8. if (at < 0) {
  9. if (email.length <= 3) {
  10. return email;
  11. }
  12. var dotIdx = email.lastIndexOf('.');
  13. if (dotIdx < 0 || dotIdx < 3) {
  14. return email.slice(0, 3) + '***';
  15. }
  16. return email.slice(0, 3) + '***' + email.slice(dotIdx);
  17. }
  18. var local = email.slice(0, at);
  19. var domain = email.slice(at + 1);
  20. if (!domain) {
  21. return local.length <= 3 ? local : local.slice(0, 3) + '***';
  22. }
  23. var first3 = local.length <= 3 ? local : local.slice(0, 3);
  24. var domainDot = domain.lastIndexOf('.');
  25. if (domainDot < 0) {
  26. return first3 + '***@' + domain;
  27. }
  28. return first3 + '***' + domain.slice(domainDot);
  29. }
  30. function maskProcuremenPhone(phone) {
  31. phone = (phone == null ? '' : String(phone)).replace(/\s+/g, '').trim();
  32. if (!phone) {
  33. return '';
  34. }
  35. var len = phone.length;
  36. if (len <= 7) {
  37. return len <= 3 ? phone : phone.slice(0, 3) + new Array(len - 2).join('*');
  38. }
  39. return phone.slice(0, 3) + new Array(len - 6).join('*') + phone.slice(-4);
  40. }
  41. function procuremenReviewCompanyKey(c) {
  42. if (!c || typeof c !== 'object') {
  43. return '';
  44. }
  45. var id = String(c.id || '').trim();
  46. if (id) {
  47. return 'id:' + id;
  48. }
  49. return [String(c.name || c.company_name || ''), String(c.username || '')].join('\x01');
  50. }
  51. function procuremenReviewCompanyPayload(c) {
  52. if (!c || typeof c !== 'object') {
  53. return {};
  54. }
  55. return {
  56. id: c.id || '',
  57. name: c.name || c.company_name || '',
  58. company_name: c.company_name || c.name || '',
  59. username: c.username || '',
  60. company_type: c.company_type || c.category || '',
  61. category: c.category || c.company_type || ''
  62. };
  63. }
  64. function procuremenLayerTop() {
  65. try {
  66. if (typeof top !== 'undefined' && top.Layer) {
  67. return top.Layer;
  68. }
  69. } catch (e) {
  70. }
  71. try {
  72. if (typeof parent !== 'undefined' && parent.Layer) {
  73. return parent.Layer;
  74. }
  75. } catch (e) {
  76. }
  77. return typeof Layer !== 'undefined' ? Layer : null;
  78. }
  79. function procuremenLayoutFlag(key) {
  80. var $layout = $('#procuremen-layout');
  81. if (!$layout.length) {
  82. return null;
  83. }
  84. var raw = $layout.data(key);
  85. if (raw === undefined || raw === null || raw === '') {
  86. return null;
  87. }
  88. return parseInt(raw, 10) === 1;
  89. }
  90. /** 下发相关权限(弹窗 / 提交 / 确认页 任一即可见「下发」按钮) */
  91. function procuremenCanDispatch() {
  92. var fromLayout = procuremenLayoutFlag('canDispatch');
  93. if (fromLayout !== null) {
  94. return fromLayout;
  95. }
  96. return procuremenCan('pickreview') || procuremenCan('picksubmit') || procuremenCan('review');
  97. }
  98. function procuremenCanPickDelete() {
  99. var fromLayout = procuremenLayoutFlag('canPickDelete');
  100. if (fromLayout !== null) {
  101. return fromLayout;
  102. }
  103. return procuremenCan('pickdelete');
  104. }
  105. function procuremenCanComplete() {
  106. var fromLayout = procuremenLayoutFlag('canComplete');
  107. if (fromLayout !== null) {
  108. return fromLayout;
  109. }
  110. return procuremenCan('completedirectly');
  111. }
  112. function procuremenCanAuditAbandon() {
  113. var fromLayout = procuremenLayoutFlag('canAuditAbandon');
  114. if (fromLayout !== null) {
  115. return fromLayout;
  116. }
  117. return procuremenCan('auditabandon');
  118. }
  119. /** 是否拥有采购子权限(与菜单规则 name 一致,如 picksubmit → procuremen/picksubmit) */
  120. function procuremenCan(rule) {
  121. var map = (typeof Config !== 'undefined' && Config.procuremenAuth) ? Config.procuremenAuth : null;
  122. if (!map) {
  123. return false;
  124. }
  125. var key = String(rule || '').toLowerCase().replace(/^procuremen\//, '');
  126. var v = map[key];
  127. return v === true || v === 1 || v === '1';
  128. }
  129. function procuremenLayerNextZIndex() {
  130. var z = 19891014;
  131. var $doc;
  132. try {
  133. $doc = (typeof top !== 'undefined' && top.jQuery) ? top.jQuery(top.document) : null;
  134. } catch (e) {
  135. $doc = null;
  136. }
  137. if (!$doc || !$doc.length) {
  138. try {
  139. $doc = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery(parent.document) : null;
  140. } catch (e2) {
  141. $doc = null;
  142. }
  143. }
  144. if ($doc && $doc.length) {
  145. $doc.find('.layui-layer').each(function () {
  146. var zi = parseInt($(this).css('z-index'), 10) || 0;
  147. if (zi > z) {
  148. z = zi;
  149. }
  150. });
  151. }
  152. return z + 10;
  153. }
  154. /** 将 layer 弹层居中到顶层窗口可视区域(采购确认短信二次确认等) */
  155. function procuremenCenterLayer(layero) {
  156. var $win;
  157. try {
  158. $win = (typeof top !== 'undefined' && top.jQuery) ? top.jQuery : null;
  159. } catch (e) {
  160. $win = null;
  161. }
  162. if (!$win) {
  163. try {
  164. $win = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : null;
  165. } catch (e2) {
  166. $win = null;
  167. }
  168. }
  169. if (!$win) {
  170. $win = $;
  171. }
  172. var $layer = $win(layero);
  173. var place = function () {
  174. var w = $layer.outerWidth() || 480;
  175. var h = $layer.outerHeight() || 220;
  176. var $vw = $win(window);
  177. var vw = $vw.width() || 0;
  178. var vh = $vw.height() || 0;
  179. var topPx = Math.max(12, Math.round((vh - h) / 2));
  180. var leftPx = Math.max(12, Math.round((vw - w) / 2));
  181. $layer.css({
  182. position: 'fixed',
  183. top: topPx + 'px',
  184. left: leftPx + 'px',
  185. right: 'auto',
  186. bottom: 'auto',
  187. margin: 0,
  188. transform: 'none'
  189. });
  190. };
  191. setTimeout(place, 0);
  192. setTimeout(place, 80);
  193. }
  194. function procuremenPad2(n) {
  195. n = parseInt(n, 10) || 0;
  196. return (n < 10 ? '0' : '') + n;
  197. }
  198. function procuremenDefaultSysRqValue() {
  199. if (typeof moment === 'function') {
  200. return moment().format('YYYY-MM-DD HH:mm:ss');
  201. }
  202. var d = new Date();
  203. return d.getFullYear() + '-' + procuremenPad2(d.getMonth() + 1) + '-' + procuremenPad2(d.getDate())
  204. + ' ' + procuremenPad2(d.getHours()) + ':' + procuremenPad2(d.getMinutes()) + ':00';
  205. }
  206. function procuremenNormalizeSysRqValue(val) {
  207. val = (val || '').trim();
  208. if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}/.test(val)) {
  209. if (!/:\d{2}$/.test(val)) {
  210. val += ':00';
  211. }
  212. return val.replace(/^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2})(:\d{2})?$/, function (m, head, sec) {
  213. return head + (sec || ':00');
  214. });
  215. }
  216. return procuremenDefaultSysRqValue();
  217. }
  218. /** 截止时间:日期 + 时下拉 + 分下拉(options.readonly 时仅展示不可改) */
  219. function procuremenInitSysRqSplit($wrap, eventNs, options) {
  220. if (!$wrap || !$wrap.length) {
  221. return;
  222. }
  223. options = options || {};
  224. var readonly = !!options.readonly;
  225. var $hidden = $wrap.find('input[type="hidden"][id$="-sys-rq"]');
  226. var $date = $wrap.find('.procuremen-sys-rq-date');
  227. var $hour = $wrap.find('.procuremen-sys-rq-hour');
  228. var $minute = $wrap.find('.procuremen-sys-rq-minute');
  229. if (!$hidden.length || !$date.length || !$hour.length || !$minute.length) {
  230. return;
  231. }
  232. if (!$hour.children().length) {
  233. var h, m;
  234. for (h = 0; h < 24; h++) {
  235. $hour.append($('<option>').val(procuremenPad2(h)).text(procuremenPad2(h)));
  236. }
  237. for (m = 0; m < 60; m++) {
  238. $minute.append($('<option>').val(procuremenPad2(m)).text(procuremenPad2(m)));
  239. }
  240. }
  241. var syncToHidden = function () {
  242. var d = ($date.val() || '').trim();
  243. var hh = $hour.val();
  244. var mm = $minute.val();
  245. if (d && hh !== null && hh !== undefined && mm !== null && mm !== undefined) {
  246. $hidden.val(d + ' ' + hh + ':' + mm + ':00');
  247. } else {
  248. $hidden.val('');
  249. }
  250. };
  251. var syncFromHidden = function (val) {
  252. val = procuremenNormalizeSysRqValue(val);
  253. var parts = val.match(/^(\d{4}-\d{2}-\d{2})\s+(\d{2}):(\d{2})/);
  254. if (!parts) {
  255. return;
  256. }
  257. $date.val(parts[1]);
  258. $hour.val(parts[2]);
  259. $minute.val(parts[3]);
  260. };
  261. syncFromHidden($hidden.val());
  262. if (!$date.val() && !readonly) {
  263. syncFromHidden(procuremenDefaultSysRqValue());
  264. syncToHidden();
  265. }
  266. if (readonly) {
  267. $wrap.addClass('is-readonly');
  268. $date.prop({disabled: true, readonly: true}).attr('tabindex', '-1');
  269. $hour.prop('disabled', true).attr('tabindex', '-1');
  270. $minute.prop('disabled', true).attr('tabindex', '-1');
  271. return;
  272. }
  273. $date.add($hour).add($minute)
  274. .off('change.' + eventNs + ' input.' + eventNs)
  275. .on('change.' + eventNs + ' input.' + eventNs, syncToHidden);
  276. }
  277. function procuremenFocusSysRqSplit($wrap) {
  278. if (!$wrap || !$wrap.length) {
  279. return;
  280. }
  281. var $date = $wrap.find('.procuremen-sys-rq-date');
  282. if ($date.length) {
  283. $date.focus();
  284. }
  285. }
  286. var Controller = {
  287. currYm: '',
  288. index: function () {
  289. var $layout = $('#procuremen-layout');
  290. var table = $('#table');
  291. var issuedOnlyCols = ['purchase_order_id'];
  292. var pendingOnlyCols = ['po_detail_count', 'po_amount_fill_cnt', 'po_delivery_fill_cnt'];
  293. var pickedOnlyCols = ['picked_supplier_name'];
  294. var auditOnlyCols = ['notify_supplier_text'];
  295. var allOnlyCols = ['ID'];
  296. Controller.currYm = ($layout.data('defaultYm') || '').toString();
  297. Controller.wffTab = ($layout.data('procuremenStage') || 'pick').toString();
  298. if (['pick', 'audit', 'confirm'].indexOf(Controller.wffTab) < 0) {
  299. Controller.wffTab = 'pick';
  300. }
  301. var listAction = Controller.wffTab;
  302. /** 左侧年月栏为空时补默认月份,避免 Redis 未同步时整块空白 */
  303. function procuremenEnsureSidebarMonths() {
  304. var $sidebar = $('.procuremen-sidebar');
  305. if (!$sidebar.length || $sidebar.find('.procuremen-ym-item').length) {
  306. return;
  307. }
  308. var ym = (Controller.currYm || $layout.data('defaultYm') || '').toString();
  309. if (!/^\d{4}-\d{2}$/.test(ym)) {
  310. var d = new Date();
  311. ym = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0');
  312. }
  313. Controller.currYm = ym;
  314. var y = ym.substring(0, 4);
  315. var mo = parseInt(ym.substring(5, 7), 10) || 1;
  316. $sidebar.html(
  317. '<div class="procuremen-year-block">'
  318. + '<div class="year-title">' + y + '年</div>'
  319. + '<a href="javascript:;" class="procuremen-ym-item active" data-ym="' + ym + '">' + mo + '月</a>'
  320. + '</div>'
  321. );
  322. }
  323. /** 确认/审批页:默认选中服务端计算的有数据月份,避免沿用错误月份导致空表 */
  324. function procuremenApplyActiveYm(ym) {
  325. if (!/^\d{4}-\d{2}$/.test(ym)) {
  326. return;
  327. }
  328. Controller.currYm = ym;
  329. var y = ym.substring(0, 4);
  330. var mo = parseInt(ym.substring(5, 7), 10) || 1;
  331. var $item = $('.procuremen-ym-item[data-ym="' + ym + '"]');
  332. if (!$item.length) {
  333. var $block = $('.procuremen-sidebar .procuremen-year-block').filter(function () {
  334. return $(this).find('.year-title').text() === y + '年';
  335. }).first();
  336. if (!$block.length) {
  337. $block = $('<div class="procuremen-year-block"><div class="year-title">' + y + '年</div></div>');
  338. $('.procuremen-sidebar').prepend($block);
  339. }
  340. $item = $('<a href="javascript:;" class="procuremen-ym-item" data-ym="' + ym + '">' + mo + '月</a>');
  341. $block.append($item);
  342. $item.on('click', function () {
  343. var clickYm = $(this).data('ym');
  344. if (!clickYm || clickYm === Controller.currYm) {
  345. return;
  346. }
  347. Controller.currYm = clickYm;
  348. $('.procuremen-ym-item').removeClass('active');
  349. $(this).addClass('active');
  350. table.bootstrapTable('refresh');
  351. });
  352. }
  353. $('.procuremen-ym-item').removeClass('active');
  354. $item.addClass('active');
  355. }
  356. function procuremenSyncCurrYmFromSidebar() {
  357. var defYm = ($layout.data('defaultYm') || '').toString();
  358. if (/^\d{4}-\d{2}$/.test(defYm)) {
  359. procuremenApplyActiveYm(defYm);
  360. return;
  361. }
  362. var $first = $('.procuremen-sidebar .procuremen-ym-item').first();
  363. if ($first.length) {
  364. procuremenApplyActiveYm(($first.data('ym') || '').toString());
  365. }
  366. }
  367. procuremenEnsureSidebarMonths();
  368. if (Controller.wffTab === 'audit' || Controller.wffTab === 'confirm') {
  369. procuremenSyncCurrYmFromSidebar();
  370. }
  371. Table.api.init({
  372. extend: {
  373. index_url: 'procuremen/' + listAction,
  374. multi_url: 'procuremen/multi',
  375. import_url: 'procuremen/import',
  376. table: 'scydgy',
  377. }
  378. });
  379. $('.procuremen-ym-item').removeClass('active');
  380. $('.procuremen-ym-item[data-ym="' + Controller.currYm + '"]').addClass('active');
  381. var stagePick = Controller.wffTab === 'pick';
  382. var stageConfirm = Controller.wffTab === 'confirm';
  383. var stageAudit = Controller.wffTab === 'audit';
  384. issuedOnlyCols.forEach(function (field) {
  385. try {
  386. table.bootstrapTable((stageAudit || stageConfirm) ? 'showColumn' : 'hideColumn', field);
  387. } catch (ignore) {
  388. }
  389. });
  390. pendingOnlyCols.forEach(function (field) {
  391. try {
  392. table.bootstrapTable(stageConfirm ? 'showColumn' : 'hideColumn', field);
  393. } catch (ignore) {
  394. }
  395. });
  396. pickedOnlyCols.forEach(function (field) {
  397. try {
  398. table.bootstrapTable(stageConfirm ? 'showColumn' : 'hideColumn', field);
  399. } catch (ignore) {
  400. }
  401. });
  402. auditOnlyCols.forEach(function (field) {
  403. try {
  404. table.bootstrapTable(stageAudit ? 'showColumn' : 'hideColumn', field);
  405. } catch (ignore) {
  406. }
  407. });
  408. try {
  409. table.bootstrapTable((stagePick || stageAudit) ? 'showColumn' : 'hideColumn', 'state');
  410. } catch (ignore) {
  411. }
  412. // 用 class 显隐,避免被工具栏 CSS 的 display:!important 盖掉
  413. function procuremenToggleStageBtn(sel, show) {
  414. var $btn = $(sel);
  415. if (!$btn.length) {
  416. return;
  417. }
  418. $btn.toggleClass('procuremen-stage-hide', !show);
  419. $btn.toggleClass('hide', !show);
  420. if (show) {
  421. $btn.css('display', '');
  422. } else {
  423. $btn.css('display', 'none');
  424. }
  425. }
  426. function procuremenApplyStageButtons() {
  427. var pick = Controller.wffTab === 'pick';
  428. var audit = Controller.wffTab === 'audit';
  429. procuremenToggleStageBtn('#btn-procuremen-pick-review', pick && procuremenCanDispatch());
  430. procuremenToggleStageBtn('#btn-procuremen-pick-delete', pick && procuremenCanPickDelete());
  431. procuremenToggleStageBtn('#btn-procuremen-batch-finish', pick && procuremenCanComplete());
  432. procuremenToggleStageBtn('#btn-procuremen-audit-abandon', audit && procuremenCanAuditAbandon());
  433. }
  434. procuremenApplyStageButtons();
  435. Controller._procuremenApplyStageButtons = procuremenApplyStageButtons;
  436. $(document).off('click.procuremenYm', '.procuremen-ym-item').on('click.procuremenYm', '.procuremen-ym-item', function () {
  437. var ym = $(this).data('ym');
  438. if (!ym || ym === Controller.currYm) {
  439. return;
  440. }
  441. Controller.currYm = ym;
  442. $('.procuremen-ym-item').removeClass('active');
  443. $(this).addClass('active');
  444. try {
  445. table.bootstrapTable('removeAll');
  446. } catch (ignore) {
  447. }
  448. table.bootstrapTable('refresh', {pageNumber: 1});
  449. setTimeout(procuremenSyncTableHeight, 120);
  450. });
  451. function procuremenPlaceToolbar() {
  452. var $host = $('#procuremen-toolbar-host');
  453. var $bt = table.closest('.bootstrap-table');
  454. if (!$host.length || !$bt.length) {
  455. return;
  456. }
  457. $host.show().css({
  458. display: 'block',
  459. height: '',
  460. minHeight: '',
  461. padding: '',
  462. border: '',
  463. overflow: 'visible'
  464. });
  465. var $hostFt = $host.children('.fixed-table-toolbar').first();
  466. var $btFt = $bt.children('.fixed-table-toolbar').first();
  467. // 宿主已有完整工具栏:保留,隐藏表格内重复生成的空壳
  468. var hostOk = $hostFt.length && $hostFt.find('.btn-refresh, .toolbar .btn, .bs-bars .btn').length > 0;
  469. if (hostOk) {
  470. if ($btFt.length) {
  471. $btFt.hide().attr('data-procuremen-toolbar-dup', '1');
  472. }
  473. // 每次都校正右侧顺序,保证贴右且图标顺序与图二一致
  474. procuremenNormalizeToolbarRight($hostFt);
  475. procuremenBindToolbarDropdownFix();
  476. if (typeof Controller._procuremenApplyStageButtons === 'function') {
  477. Controller._procuremenApplyStageButtons();
  478. }
  479. return;
  480. }
  481. // 把表格内工具栏挪到宿主(脱离 overflow:hidden,避免上半截被裁切)
  482. var $ft = $btFt.length ? $btFt : $hostFt;
  483. if (!$ft.length) {
  484. return;
  485. }
  486. if ($ft.parent()[0] !== $host[0]) {
  487. $host.children('.fixed-table-toolbar').each(function () {
  488. var $old = $(this);
  489. if (!$old.find('.btn-refresh, .toolbar .btn, .search').length) {
  490. $old.remove();
  491. }
  492. });
  493. $host.append($ft.show().removeAttr('data-procuremen-toolbar-dup'));
  494. var $src = $bt.closest('.procuremen-table-area').find('#toolbar').first();
  495. if ($src.length && !$src.children().length) {
  496. $src.addClass('procuremen-toolbar-empty');
  497. }
  498. }
  499. procuremenNormalizeToolbarRight($ft);
  500. procuremenBindToolbarDropdownFix();
  501. if (typeof Controller._procuremenApplyStageButtons === 'function') {
  502. Controller._procuremenApplyStageButtons();
  503. }
  504. // 工具栏移出后重算表高,避免占位错乱
  505. setTimeout(function () {
  506. procuremenTableHeightCached = 0;
  507. procuremenSyncTableHeight();
  508. if (typeof Controller._procuremenApplyStageButtons === 'function') {
  509. Controller._procuremenApplyStageButtons();
  510. }
  511. }, 0);
  512. }
  513. function procuremenNormalizeToolbarRight($ft) {
  514. if (!$ft || !$ft.length) {
  515. return;
  516. }
  517. var $search = $ft.find('.search').first();
  518. if (!$search.length) {
  519. return;
  520. }
  521. // 专用右侧容器:不能把 .search 自身当 wrap(.search 的 display 会盖掉 flex,导致搜索与图标折成两行)
  522. var $right = $ft.children('.procuremen-toolbar-search-wrap').first();
  523. if (!$right.length) {
  524. $right = $('<div class="columns columns-right pull-right procuremen-toolbar-search-wrap"></div>');
  525. $ft.append($right);
  526. } else {
  527. $right.addClass('columns columns-right pull-right procuremen-toolbar-search-wrap');
  528. }
  529. // 若历史上把图标塞进了 .search 里,先拆出来
  530. if ($search.hasClass('procuremen-toolbar-search-wrap')) {
  531. $search.removeClass('procuremen-toolbar-search-wrap columns columns-right');
  532. }
  533. $search.children().not('input, .form-control').appendTo($right);
  534. $search.appendTo($right);
  535. $ft.children().each(function () {
  536. var $c = $(this);
  537. if ($c.is('.bars, .bs-bars') || $c[0] === $right[0] || $c.hasClass('search')) {
  538. return;
  539. }
  540. var mergeToolbarExtras = $c.hasClass('columns')
  541. || $c.hasClass('pull-right')
  542. || ($c.hasClass('btn-group') && $c.find('.search').length === 0)
  543. || $c.is('button[name="commonSearch"], button[name="toggle"]');
  544. if (!mergeToolbarExtras) {
  545. return;
  546. }
  547. if ($c.hasClass('btn-group') && !$c.hasClass('columns')) {
  548. $c.appendTo($right);
  549. } else if ($c.is('button')) {
  550. $c.appendTo($right);
  551. } else {
  552. $c.children().appendTo($right);
  553. if (!$c.children().length) {
  554. $c.remove();
  555. }
  556. }
  557. });
  558. // 顺序:搜索框 → 切换 → 列显隐 → 导出 → 通用搜索(放大镜)
  559. $right.addClass('procuremen-toolbar-search-wrap');
  560. var $toggle = $right.find('button[name="toggle"]').first();
  561. var $columns = $right.find('.keep-open').first();
  562. var $export = $right.find('.export').first();
  563. var $common = $right.find('button[name="commonSearch"]').first();
  564. $search = $right.find('.search').first();
  565. if ($search.length) {
  566. $search.prependTo($right);
  567. }
  568. if ($toggle.length) {
  569. $toggle.insertAfter($search);
  570. }
  571. if ($columns.length) {
  572. $columns.insertAfter($toggle.length ? $toggle : $search);
  573. }
  574. if ($export.length) {
  575. var $afterCols = $columns.length ? $columns : ($toggle.length ? $toggle : $search);
  576. $export.insertAfter($afterCols);
  577. }
  578. if ($common.length) {
  579. $common.appendTo($right);
  580. }
  581. }
  582. /** 列显隐下拉用 fixed,避免被表格区域 overflow 裁切 */
  583. function procuremenBindToolbarDropdownFix() {
  584. var $host = $('#procuremen-toolbar-host');
  585. if (!$host.length || $host.data('dropdownFixBound')) {
  586. return;
  587. }
  588. $host.data('dropdownFixBound', 1);
  589. $host.on('show.bs.dropdown shown.bs.dropdown', '.btn-group', function () {
  590. var $btnGroup = $(this);
  591. var $menu = $btnGroup.children('.dropdown-menu').first();
  592. if (!$menu.length) {
  593. return;
  594. }
  595. var place = function () {
  596. var btnTop = $btnGroup.offset().top;
  597. var btnHeight = $btnGroup.outerHeight();
  598. var scrollTop = $(window).scrollTop();
  599. var winH = $(window).height();
  600. var menuH = $menu.outerHeight() || 280;
  601. var maxH = Math.max(220, Math.min(520, winH - 24));
  602. var top = btnTop - scrollTop + btnHeight;
  603. if (top + Math.min(menuH, maxH) > winH - 8) {
  604. var up = btnTop - scrollTop - Math.min(menuH, maxH) - 4;
  605. if (up >= 8) {
  606. top = up;
  607. maxH = Math.min(maxH, Math.max(180, btnTop - scrollTop - 12));
  608. } else {
  609. maxH = Math.max(180, winH - top - 12);
  610. }
  611. }
  612. var left = $btnGroup.offset().left + $btnGroup.outerWidth() - ($menu.outerWidth() || 180);
  613. left = Math.max(8, Math.min(left, $(window).width() - ($menu.outerWidth() || 180) - 8));
  614. $menu.css({
  615. position: 'fixed',
  616. top: top,
  617. left: left,
  618. right: 'auto',
  619. bottom: 'auto',
  620. maxHeight: maxH + 'px',
  621. overflowY: 'auto',
  622. overflowX: 'hidden',
  623. zIndex: 2000
  624. });
  625. };
  626. place();
  627. setTimeout(place, 0);
  628. });
  629. }
  630. table.on('post-header.bs.table', function () {
  631. procuremenPlaceToolbar();
  632. procuremenScheduleAlign();
  633. });
  634. var indexInitWffTab = Controller.wffTab;
  635. var indexShowall = indexInitWffTab === 'pick' || indexInitWffTab === 'audit';
  636. var indexShowIssued = indexInitWffTab === 'audit' || indexInitWffTab === 'confirm';
  637. var indexShowPendingOnly = indexInitWffTab === 'confirm' || indexInitWffTab === 'audit';
  638. var indexShowPickedOnly = indexInitWffTab === 'confirm';
  639. var indexShowAuditSuppliers = indexInitWffTab === 'audit';
  640. function procuremenEscAttr(s) {
  641. return String(s == null ? '' : s)
  642. .replace(/&/g, '&amp;')
  643. .replace(/"/g, '&quot;')
  644. .replace(/'/g, '&#39;');
  645. }
  646. function procuremenEscHtml(s) {
  647. return String(s == null ? '' : s)
  648. .replace(/&/g, '&amp;')
  649. .replace(/</g, '&lt;')
  650. .replace(/>/g, '&gt;')
  651. .replace(/"/g, '&quot;');
  652. }
  653. function procuremenAutocontentCell(value, colWidth) {
  654. if (value == null || value === '') {
  655. return '';
  656. }
  657. var text = String(value).replace(/\r\n/g, '\n').replace(/\n+/g, ';').trim();
  658. if (text === '') {
  659. return '';
  660. }
  661. var width = colWidth != null && colWidth !== '' ? String(colWidth) : '250';
  662. if (/^\d+$/.test(width)) {
  663. width = width + 'px';
  664. }
  665. return "<div class='autocontent-item' style='white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:" + width + ";'>" + procuremenEscHtml(text) + '</div>';
  666. }
  667. /** 报价供应商:收起单行省略,展开后每家公司一行 */
  668. function procuremenParseSupplierLines(value) {
  669. if (value == null || value === '') {
  670. return [];
  671. }
  672. var raw = String(value).replace(/\r\n/g, '\n').trim();
  673. var lines = raw.split('\n').map(function (s) {
  674. return s.trim();
  675. }).filter(Boolean);
  676. if (lines.length === 1 && /[、;]/.test(lines[0])) {
  677. lines = lines[0].split(/[、;]+/).map(function (s) {
  678. return s.trim();
  679. }).filter(Boolean);
  680. }
  681. return lines;
  682. }
  683. function procuremenSupplierLinesCell(value, colWidth) {
  684. var lines = procuremenParseSupplierLines(value);
  685. if (lines.length === 0) {
  686. return '';
  687. }
  688. var preview = lines.join(';');
  689. var width = colWidth != null && colWidth !== '' ? String(colWidth) : '260';
  690. if (/^\d+$/.test(width)) {
  691. width = width + 'px';
  692. }
  693. 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 + ";'>"
  694. + "<span class='procuremen-supplier-preview'>" + procuremenEscHtml(preview) + '</span>'
  695. + '</div>';
  696. }
  697. function procuremenReadSupplierLinesFromCell($item) {
  698. if (!$item || !$item.length) {
  699. return [];
  700. }
  701. var raw = $item.attr('data-supplier-full');
  702. if (raw) {
  703. try {
  704. var parsed = JSON.parse(raw);
  705. if ($.isArray(parsed)) {
  706. return parsed.map(function (s) {
  707. return String(s == null ? '' : s).trim();
  708. }).filter(Boolean);
  709. }
  710. } catch (ignore) {
  711. }
  712. return procuremenParseSupplierLines(raw);
  713. }
  714. return [];
  715. }
  716. function procuremenSupplierLinesPopupHtml(lines) {
  717. return '<div class="procuremen-supplier-popup" style="padding:10px 12px;line-height:1.8;word-break:break-all;">'
  718. + lines.map(function (line) {
  719. return '<div>' + procuremenEscHtml(line) + '</div>';
  720. }).join('')
  721. + '</div>';
  722. }
  723. function procuremenSupplierCntText(v) {
  724. var n = parseInt(v, 10);
  725. if (isNaN(n) || n < 0) {
  726. n = 0;
  727. }
  728. return n + '家';
  729. }
  730. var indexTableColumns = [
  731. {checkbox: true, field: 'state', visible: indexShowall, align: 'center', width: 42, class: 'procuremen-col-checkbox'},
  732. // {field: 'ID', title: __('ID'), operate: 'LIKE', table: 'a', width: 100, align: 'center',
  733. // visible: indexShowall,
  734. // formatter: function (v) {
  735. // return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
  736. // }
  737. // },
  738. // {field: 'purchase_order_id',title: 'ID',operate: false,table: 'a',width: 88,align: 'center',
  739. // visible: indexShowIssued,
  740. // formatter: function (v) {
  741. // return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
  742. // }
  743. // },
  744. {field: 'CCYDH', title: __('订单号'), operate: 'LIKE', table: 'b', width: 108, align: 'center', sortable: true, class: 'procuremen-th-sort-tight'},
  745. {field: 'CYJMC', title: __('印件名称'), operate: 'LIKE', table: 'b', width: 270, align: 'left', class: 'procuremen-cell-wrap',
  746. formatter: function (v) {
  747. if (v == null || v === '') {
  748. return '';
  749. }
  750. return '<span title="' + procuremenEscAttr(v) + '">' + procuremenEscHtml(v) + '</span>';
  751. }
  752. },
  753. {field: 'CCLBMMC', title: '承揽部门', operate: 'LIKE', table: 'b', width: 140, align: 'center', class: 'procuremen-cell-wrap'},
  754. {field: 'CGYMC', title: __('工序名称'), operate: 'LIKE', table: 'a', width: 140, align: 'left', class: 'procuremen-cell-wrap',
  755. formatter: function (v) {
  756. return v != null && v !== '' ? String(v) : '';
  757. }
  758. },
  759. {field: 'CDW', title: __('单位'), operate: 'LIKE', table: 'a', width: 88, align: 'center'},
  760. {field: 'NGZL', title: __('工作量'), operate: 'LIKE', table: 'a', width: 88, align: 'center',
  761. formatter: function (v) {
  762. if (v == null || v === '') {
  763. return '';
  764. }
  765. var s = String(v).trim();
  766. if (s === '') {
  767. return '';
  768. }
  769. var n = parseFloat(s);
  770. if (!isNaN(n) && n === 0) {
  771. return '';
  772. }
  773. return s;
  774. }
  775. },
  776. {field: 'This_quantity', title: '本次数量', operate: 'LIKE', table: 'a', width: 96, align: 'center',
  777. visible: true,
  778. formatter: function (v, row, index) {
  779. var tab = Controller.wffTab || 'pick';
  780. if (tab === 'pick') {
  781. var val = (v != null && v !== '') ? String(v) : '';
  782. return '<input type="text" class="form-control input-sm procuremen-po-field procuremen-po-qty" '
  783. + 'style="min-width:72px;max-width:96px;height:28px;padding:2px 6px;" '
  784. + 'data-field="This_quantity" data-row-index="' + index + '" value="'
  785. + procuremenEscAttr(val) + '" placeholder="填写" autocomplete="off"/>';
  786. }
  787. return (v == null || v === '') ? '' : String(v);
  788. }
  789. },
  790. {field: 'ceilingPrice', title: '最高限价', operate: 'LIKE', table: 'a', width: 96, align: 'center',
  791. visible: true,
  792. formatter: function (value, row, index) {
  793. var tab = Controller.wffTab || 'pick';
  794. var v = value;
  795. if (v == null || v === '') {
  796. v = (row && row.ceilingPrice != null && row.ceilingPrice !== '') ? row.ceilingPrice
  797. : (row && row.ceiling_price != null ? row.ceiling_price : '');
  798. }
  799. if (tab === 'pick') {
  800. var val = (v != null && v !== '') ? String(v) : '';
  801. return '<input type="text" class="form-control input-sm procuremen-po-field procuremen-po-price" '
  802. + 'style="min-width:72px;max-width:96px;height:28px;padding:2px 6px;" '
  803. + 'data-field="ceilingPrice" data-row-index="' + index + '" value="'
  804. + procuremenEscAttr(val) + '" placeholder="填写" autocomplete="off"/>';
  805. }
  806. return (v == null || v === '') ? '' : String(v);
  807. }
  808. },
  809. {field: 'notify_supplier_text', title: '报价供应商', operate: false, table: 'a', width: 260, align: 'left',
  810. visible: indexShowAuditSuppliers,
  811. class: 'procuremen-supplier-lines-cell',
  812. formatter: function (v) {
  813. return procuremenSupplierLinesCell(v, this.width || 260);
  814. }
  815. },
  816. {field: 'picked_supplier_name', title: '报价供应商', operate: 'LIKE', table: 'a', width: 260, align: 'left',
  817. visible: indexShowPickedOnly,
  818. class: 'procuremen-supplier-lines-cell',
  819. formatter: function (v) {
  820. return procuremenSupplierLinesCell(v, this.width || 260);
  821. }
  822. },
  823. {field: 'po_detail_count', title: '已下发供应商', operate: false, table: 'a', width: 108, align: 'center',
  824. visible: indexShowPendingOnly,
  825. formatter: function (v) {
  826. return procuremenSupplierCntText(v);
  827. }
  828. },
  829. {field: 'po_amount_fill_cnt', title: '已填写单价', operate: false, table: 'a', width: 100, align: 'center',
  830. visible: indexShowPendingOnly,
  831. formatter: function (v) {
  832. return procuremenSupplierCntText(v);
  833. }
  834. },
  835. {field: 'po_delivery_fill_cnt', title: '已填写货期', operate: false, table: 'a', width: 100, align: 'center',
  836. visible: indexShowPendingOnly,
  837. formatter: function (v) {
  838. return procuremenSupplierCntText(v);
  839. }
  840. },
  841. {field: 'CDF', title: __('订法'), operate: 'LIKE', table: 'a', width: 100, align: 'center', class: 'procuremen-cell-wrap'},
  842. {field: 'cGzzxMc', title: __('外厂单位'), operate: 'LIKE', table: 'a', width: 220, align: 'center', class: 'procuremen-cell-wrap'},
  843. {field: 'MBZ', title: __('备注'), operate: 'LIKE', table: 'a', width: 150, align: 'center', class: 'procuremen-cell-wrap'},
  844. {field: 'cywyxm', title: __('业务员'), operate: 'LIKE', table: 'b', width: 80, align: 'center'},
  845. {field: 'dStamp', title: __('操作日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'a', width: 176, align: 'center', sortable: true, class: 'procuremen-th-sort-tight'},
  846. {field: 'dputrecord', title: __('提交日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'b', width: 176, align: 'center', sortable: true, class: 'procuremen-th-sort-tight'},
  847. {field: 'operate',title: '操作',width: 168,align: 'center',fixed: 'right', operate: false,
  848. visible: indexInitWffTab !== 'pick',
  849. table: table,
  850. formatter: function (value, row, index) {
  851. var tab = Controller.wffTab || 'pick';
  852. var pk = row && (row.ID != null ? row.ID : row.id);
  853. if (!row || pk == null || pk === '' || String(pk) === '0') {
  854. return '';
  855. }
  856. var areaDetails = ' data-area=\'["92%","88%"]\'';
  857. var areaAudit = ' data-area=\'["96%","88%"]\'';
  858. var areaConfirmOutward = ' data-area=\'["96%","88%"]\'';
  859. var parts = [];
  860. if (tab === 'pick') {
  861. return '';
  862. } else if (tab === 'audit') {
  863. if (procuremenCan('auditissue')) {
  864. 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>');
  865. }
  866. if (procuremenCan('details')) {
  867. 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>');
  868. }
  869. } else if (tab === 'confirm') {
  870. if (procuremenCan('outward_detail')) {
  871. 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>');
  872. }
  873. if (procuremenCan('details')) {
  874. 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>');
  875. }
  876. }
  877. return '<span class="procuremen-op-btns">' + parts.join('') + '</span>';
  878. },
  879. events: {}
  880. }
  881. ];
  882. // audit / confirm 右侧固定操作列,避免横向滚动才能点按钮
  883. var useFixedColumns = indexInitWffTab === 'audit' || indexInitWffTab === 'confirm';
  884. var procuremenTableHeightCached = 0;
  885. var procuremenHeightSyncTimer = null;
  886. function procuremenCalcTableHeight() {
  887. var $area = $layout.find('.procuremen-main .procuremen-table-area');
  888. if (!$area.length) {
  889. return 400;
  890. }
  891. var top = $area[0].getBoundingClientRect().top;
  892. return Math.max(280, Math.floor(window.innerHeight - top - 22));
  893. }
  894. function procuremenSyncTableHeight() {
  895. if (procuremenHeightSyncTimer) {
  896. clearTimeout(procuremenHeightSyncTimer);
  897. }
  898. procuremenHeightSyncTimer = setTimeout(function () {
  899. procuremenHeightSyncTimer = null;
  900. var h = procuremenCalcTableHeight();
  901. if (procuremenTableHeightCached > 0 && Math.abs(procuremenTableHeightCached - h) <= 3) {
  902. procuremenScheduleAlign();
  903. return;
  904. }
  905. procuremenTableHeightCached = h;
  906. try {
  907. table.bootstrapTable('resetView', {height: h});
  908. procuremenScheduleAlign();
  909. } catch (ignore) {
  910. }
  911. }, 100);
  912. }
  913. /** 按列配置生成统一宽度,表头/表体共用,杜绝内容撑开导致竖线错位 */
  914. function procuremenGetVisibleColWidths() {
  915. var widths = [];
  916. try {
  917. var opts = table.bootstrapTable('getOptions') || {};
  918. var cols = (opts.columns && opts.columns[0]) ? opts.columns[0] : indexTableColumns;
  919. $.each(cols, function (_, col) {
  920. if (!col || col.visible === false) {
  921. return;
  922. }
  923. var w = parseInt(col.width, 10);
  924. if (!w || isNaN(w)) {
  925. w = col.checkbox ? 42 : 120;
  926. }
  927. widths.push(w);
  928. });
  929. } catch (ignore) {
  930. }
  931. return widths;
  932. }
  933. function procuremenApplyColgroup($tbl, widths) {
  934. if (!$tbl || !$tbl.length || !widths.length) {
  935. return;
  936. }
  937. var total = 0;
  938. var i;
  939. for (i = 0; i < widths.length; i++) {
  940. total += widths[i];
  941. }
  942. $tbl.css({
  943. tableLayout: 'fixed',
  944. width: total + 'px',
  945. minWidth: total + 'px'
  946. });
  947. var $cg = $tbl.children('colgroup');
  948. if (!$cg.length) {
  949. $cg = $('<colgroup/>').prependTo($tbl);
  950. }
  951. $cg.empty();
  952. for (i = 0; i < widths.length; i++) {
  953. $cg.append($('<col/>').attr('style', 'width:' + widths[i] + 'px;min-width:' + widths[i] + 'px;'));
  954. }
  955. $tbl.find('thead tr:first > th').each(function (idx) {
  956. if (idx >= widths.length) {
  957. return;
  958. }
  959. var w = widths[idx];
  960. var $th = $(this);
  961. $th.css({width: w + 'px', minWidth: w + 'px', maxWidth: w + 'px'});
  962. $th.find('.fht-cell').css({width: w + 'px', minWidth: w + 'px', maxWidth: w + 'px'});
  963. });
  964. // 只锁首行即可带动 fixed 布局;避免给每一行都写 style 太重
  965. $tbl.find('tbody tr:first-child:not(.no-records-found) > *').each(function (idx) {
  966. if (idx >= widths.length) {
  967. return;
  968. }
  969. var w = widths[idx];
  970. $(this).css({width: w + 'px', minWidth: w + 'px', maxWidth: w + 'px'});
  971. });
  972. }
  973. /** 表头/表体列线对齐:统一 colgroup 宽度,不再用内容实测宽(内容会把表体撑偏) */
  974. function procuremenSyncHeaderBodyAlign() {
  975. if ($('body').hasClass('fa-sidebar-resizing')) {
  976. return;
  977. }
  978. var $bt = table.closest('.bootstrap-table');
  979. if (!$bt.length) {
  980. return;
  981. }
  982. var $headerWrap = $bt.find('> .fixed-table-container > .fixed-table-header').first();
  983. if (!$headerWrap.length) {
  984. $headerWrap = $bt.find('.fixed-table-header').not('.fixed-columns-right .fixed-table-header').first();
  985. }
  986. var $bodyWrap = $bt.find('> .fixed-table-container > .fixed-table-body').first();
  987. if (!$bodyWrap.length) {
  988. $bodyWrap = $bt.find('.fixed-table-body').not('.fixed-columns-right .fixed-table-body, .fixed-columns .fixed-table-body').first();
  989. }
  990. if (!$headerWrap.length || !$bodyWrap.length) {
  991. return;
  992. }
  993. var $headerTable = $headerWrap.children('table').first();
  994. var $bodyTable = $bodyWrap.children('table').first();
  995. if (!$headerTable.length || !$bodyTable.length) {
  996. return;
  997. }
  998. var widths = procuremenGetVisibleColWidths();
  999. if (!widths.length) {
  1000. // 兜底:按当前表头列数均分不可靠,改为按现有 th 数量取配置默认
  1001. var n = $headerTable.find('thead tr:first > th').length;
  1002. for (var k = 0; k < n; k++) {
  1003. widths.push(120);
  1004. }
  1005. }
  1006. // 列数不一致时以较少者为准,避免错位
  1007. var headCount = $headerTable.find('thead tr:first > th').length;
  1008. var bodyCount = $bodyTable.find('tbody tr:first-child:not(.no-records-found) > *').length;
  1009. if (!bodyCount) {
  1010. bodyCount = $bodyTable.find('thead tr:first > th').length;
  1011. }
  1012. var colCount = Math.min(widths.length, headCount || widths.length, bodyCount || widths.length);
  1013. if (colCount > 0 && colCount < widths.length) {
  1014. widths = widths.slice(0, colCount);
  1015. }
  1016. $headerWrap.css('padding-right', '');
  1017. var bodyEl = $bodyWrap[0];
  1018. var sb = Math.max(0, bodyEl.offsetWidth - bodyEl.clientWidth);
  1019. $headerWrap.css('margin-right', sb > 0 ? sb + 'px' : '');
  1020. procuremenApplyColgroup($headerTable, widths);
  1021. procuremenApplyColgroup($bodyTable, widths);
  1022. // 主表横向滚动与表头同步;避免异常 scrollLeft 把左侧复选框/订单号滚出可视区
  1023. var sl = $bodyWrap.scrollLeft() || 0;
  1024. if (sl < 0) {
  1025. sl = 0;
  1026. $bodyWrap.scrollLeft(0);
  1027. }
  1028. $headerWrap.scrollLeft(sl);
  1029. // 右侧固定操作列:插件克隆整表再 scrollLeft 到最右;切勿 scrollLeft(0) 或把 table 压成单列宽
  1030. var $fixedRight = $bt.find('.fixed-columns-right');
  1031. if ($fixedRight.length) {
  1032. var $fh = $fixedRight.find('.fixed-table-header').first();
  1033. var $fb = $fixedRight.find('.fixed-table-body').first();
  1034. var $fTable = $fh.find('table').first();
  1035. if (!$fTable.length) {
  1036. $fTable = $fb.find('table').first();
  1037. }
  1038. // 清掉历史错误内联样式,恢复整表宽度
  1039. $fixedRight.find('table').each(function () {
  1040. $(this).css({width: '', minWidth: '', maxWidth: '', tableLayout: ''});
  1041. });
  1042. $fixedRight.find('thead th, tbody td').css({
  1043. width: '',
  1044. minWidth: '',
  1045. maxWidth: '',
  1046. overflow: '',
  1047. whiteSpace: ''
  1048. });
  1049. $fixedRight.find('colgroup').remove();
  1050. var opW = 168;
  1051. var $opCell = $bt.find('.fixed-table-body table thead th[data-field="operate"]').first();
  1052. if (!$opCell.length) {
  1053. $opCell = $headerTable.find('th[data-field="operate"]').first();
  1054. }
  1055. if ($opCell.length) {
  1056. var measured = $opCell.outerWidth();
  1057. if (measured > 0) {
  1058. opW = Math.max(Math.round(measured), 156);
  1059. }
  1060. }
  1061. $fixedRight.css({
  1062. width: opW + 'px',
  1063. minWidth: opW + 'px',
  1064. maxWidth: opW + 'px',
  1065. display: 'block',
  1066. visibility: 'visible',
  1067. overflow: 'hidden'
  1068. });
  1069. var fullW = $fTable.outerWidth() || $fTable.width() || 0;
  1070. if (fullW > 0) {
  1071. $fh.scrollLeft(fullW);
  1072. $fb.scrollLeft(fullW);
  1073. }
  1074. }
  1075. }
  1076. function procuremenScheduleAlign() {
  1077. if ($('body').hasClass('fa-sidebar-resizing')) {
  1078. return;
  1079. }
  1080. setTimeout(procuremenSyncHeaderBodyAlign, 0);
  1081. setTimeout(procuremenSyncHeaderBodyAlign, 80);
  1082. }
  1083. var procuremenInitTableHeight = procuremenCalcTableHeight();
  1084. table.bootstrapTable({
  1085. url: $.fn.bootstrapTable.defaults.extend.index_url,
  1086. pk: 'ID',
  1087. sortName: indexInitWffTab === 'pick' ? 'CCYDH' : 'a.pick_time',
  1088. sortOrder: 'desc',
  1089. width: 'auto',
  1090. height: procuremenInitTableHeight,
  1091. fixedColumns: useFixedColumns,
  1092. fixedRightNumber: useFixedColumns ? 1 : 0,
  1093. clickToSelect: false,
  1094. dblClickToEdit: false,
  1095. dragCheckboxMultiselect: false,
  1096. maintainSelected: false,
  1097. commonSearch: true,
  1098. showToggle: true,
  1099. showColumns: true,
  1100. showExport: true,
  1101. search: true,
  1102. smartDisplay: false,
  1103. responseHandler: function (res) {
  1104. if (res && res.activeYm && (Controller.wffTab === 'audit' || Controller.wffTab === 'confirm')) {
  1105. procuremenApplyActiveYm(res.activeYm);
  1106. }
  1107. if (res && typeof res === 'object' && res.msg && (res.total === 0 || !res.rows || !res.rows.length)) {
  1108. delete res.msg;
  1109. }
  1110. return res;
  1111. },
  1112. queryParams: function (params) {
  1113. params.ym = Controller.currYm;
  1114. params.wff_tab = Controller.wffTab;
  1115. return params;
  1116. },
  1117. columns: [indexTableColumns]
  1118. });
  1119. Table.api.bindevent(table);
  1120. // 本页不需要「跨页选择模式」提示
  1121. table.closest('.bootstrap-table').find('.btn-selected-tips').remove();
  1122. $('#procuremen-toolbar-host .btn-selected-tips, #toolbar .btn-selected-tips').remove();
  1123. table.on('post-body.bs.table post-header.bs.table', function () {
  1124. $('#procuremen-toolbar-host .btn-selected-tips, .bootstrap-table .btn-selected-tips, #toolbar .btn-selected-tips').remove();
  1125. });
  1126. table.off('mouseenter.procuremenSupplierLines mouseleave.procuremenSupplierLines', '.procuremen-supplier-lines-cell')
  1127. .on('mouseenter.procuremenSupplierLines', '.procuremen-supplier-lines-cell', function () {
  1128. var $item = $(this).find('.procuremen-supplier-lines').first();
  1129. if (!$item.length) {
  1130. return;
  1131. }
  1132. var lines = procuremenReadSupplierLinesFromCell($item);
  1133. var target = $item.find('.procuremen-supplier-preview').get(0);
  1134. if (lines.length > 1 || (target && target.scrollWidth > target.offsetWidth)) {
  1135. if (!$(this).find('> .procuremen-supplier-caret').length) {
  1136. $(this).append("<div class='procuremen-supplier-caret'><i class='fa fa-chevron-down'></i></div>");
  1137. }
  1138. }
  1139. })
  1140. .on('mouseleave.procuremenSupplierLines', '.procuremen-supplier-lines-cell', function () {
  1141. $(this).find('> .procuremen-supplier-caret').remove();
  1142. });
  1143. table.off('click.procuremenSupplierLines', '.procuremen-supplier-lines-cell > .procuremen-supplier-caret')
  1144. .on('click.procuremenSupplierLines', '.procuremen-supplier-lines-cell > .procuremen-supplier-caret', function (e) {
  1145. e.preventDefault();
  1146. e.stopImmediatePropagation();
  1147. var $td = $(this).closest('.procuremen-supplier-lines-cell');
  1148. var $item = $td.find('.procuremen-supplier-lines').first();
  1149. var lines = procuremenReadSupplierLinesFromCell($item);
  1150. if (!lines.length) {
  1151. return;
  1152. }
  1153. var tdrect = $td.get(0).getBoundingClientRect();
  1154. var layerIndex = Layer.open({
  1155. id: 'procuremen-supplier-lines',
  1156. skin: 'layui-layer-fast layui-layer-autocontent',
  1157. title: false,
  1158. content: procuremenSupplierLinesPopupHtml(lines),
  1159. btn: false,
  1160. anim: false,
  1161. shade: 0,
  1162. isOutAnim: false,
  1163. area: 'auto',
  1164. maxWidth: 450,
  1165. maxHeight: 350,
  1166. offset: [tdrect.y, tdrect.x]
  1167. });
  1168. var mousedown = function (ev) {
  1169. if ($(ev.target).closest('.layui-layer').length === 0) {
  1170. Layer.close(layerIndex);
  1171. $(document).off('mousedown', mousedown);
  1172. }
  1173. };
  1174. $(document).off('mousedown', mousedown).on('mousedown', mousedown);
  1175. });
  1176. // 刷新/切换月份时旧请求被中断会误触 load-error;列表已有数据时不打扰用户
  1177. table.off('load-error.bs.table').on('load-error.bs.table', function (status, res, jqXHR) {
  1178. var xhr = jqXHR || res;
  1179. if (xhr && (!xhr.status || xhr.status === 0 || xhr.statusText === 'abort')) {
  1180. return;
  1181. }
  1182. try {
  1183. if ((table.bootstrapTable('getData') || []).length > 0) {
  1184. return;
  1185. }
  1186. } catch (ignore) {
  1187. }
  1188. });
  1189. table.on('load-success.bs.table', function () {
  1190. procuremenPlaceToolbar();
  1191. procuremenSyncTableHeight();
  1192. });
  1193. $(document).off('click.procuremenCommonSearch', 'button[name="commonSearch"]').on('click.procuremenCommonSearch', 'button[name="commonSearch"]', function () {
  1194. setTimeout(procuremenSyncTableHeight, 150);
  1195. });
  1196. $(window).off('resize.procuremenIndex').on('resize.procuremenIndex', function () {
  1197. if ($('body').hasClass('fa-sidebar-resizing')) {
  1198. return;
  1199. }
  1200. procuremenTableHeightCached = 0;
  1201. procuremenSyncTableHeight();
  1202. });
  1203. $(document).off('fa.sidebar.resized.procuremenIndex fa.table.relayout.procuremenIndex')
  1204. .on('fa.sidebar.resized.procuremenIndex fa.table.relayout.procuremenIndex', function () {
  1205. if ($('body').hasClass('fa-sidebar-resizing')) {
  1206. return;
  1207. }
  1208. procuremenTableHeightCached = 0;
  1209. var $bt = table.closest('.bootstrap-table');
  1210. $bt.find('.fixed-table-header').css({paddingRight: '', marginRight: ''});
  1211. $bt.find('.fixed-table-header thead th').css({width: '', minWidth: '', maxWidth: ''});
  1212. try {
  1213. table.bootstrapTable('resetView', {height: procuremenCalcTableHeight()});
  1214. } catch (ignore) {
  1215. }
  1216. procuremenScheduleAlign();
  1217. });
  1218. function procuremenEscHtml(s) {
  1219. return String(s == null ? '' : s)
  1220. .replace(/&/g, '&amp;')
  1221. .replace(/</g, '&lt;')
  1222. .replace(/>/g, '&gt;')
  1223. .replace(/"/g, '&quot;');
  1224. }
  1225. function procuremenBuildConfirmRowsTable(rows) {
  1226. var html = '<table class="table table-bordered table-condensed procuremen-confirm-table">'
  1227. + '<thead><tr><th>订单号</th><th>工序名称</th><th>印件名称</th></tr></thead><tbody>';
  1228. $.each(rows, function (i, rd) {
  1229. html += '<tr><td>' + procuremenEscHtml(String(rd.CCYDH || '').trim() || '—') + '</td>'
  1230. + '<td>' + procuremenEscHtml(String(rd.CGYMC || '').trim() || '—') + '</td>'
  1231. + '<td>' + procuremenEscHtml(String(rd.CYJMC || '').trim() || '—') + '</td></tr>';
  1232. });
  1233. html += '</tbody></table>';
  1234. return html;
  1235. }
  1236. function procuremenBuildConfirmMsg(introHtml, rowsTableHtml) {
  1237. return '<div class="procuremen-confirm-body">'
  1238. + '<p class="procuremen-confirm-intro">' + introHtml + '</p>'
  1239. + '<div class="procuremen-confirm-scroll">' + rowsTableHtml + '</div>'
  1240. + '</div>';
  1241. }
  1242. var procuremenConfirmLayerBase = {
  1243. area: ['680px', '400px'],
  1244. icon: -1,
  1245. skin: 'layui-layer-procuremen-finish',
  1246. success: function (layero) {
  1247. var $layer = $(layero);
  1248. $layer.css({
  1249. display: 'flex',
  1250. flexDirection: 'column',
  1251. height: '400px',
  1252. overflow: 'hidden'
  1253. });
  1254. $layer.find('.layui-layer-content').css({
  1255. flex: '1 1 auto',
  1256. minHeight: 0,
  1257. overflow: 'hidden',
  1258. height: 'auto'
  1259. });
  1260. $layer.find('.layui-layer-btn').css({flexShrink: 0});
  1261. }
  1262. };
  1263. function procuremenExpandOrderRows(row) {
  1264. if (!row) {
  1265. return [];
  1266. }
  1267. if ($.isArray(row._order_merge_rows) && row._order_merge_rows.length) {
  1268. return row._order_merge_rows;
  1269. }
  1270. return [row];
  1271. }
  1272. function procuremenRowsWithPoInputs(selRows) {
  1273. var $btPo = table.closest('.bootstrap-table');
  1274. var dataRows = table.bootstrapTable('getData');
  1275. var out = [];
  1276. $.each(selRows, function (i, r) {
  1277. if (!r) {
  1278. return;
  1279. }
  1280. var rowIdx = -1;
  1281. $.each(dataRows, function (di, dr) {
  1282. var pk = table.bootstrapTable('getOptions').pk || 'ID';
  1283. var a = dr && (dr[pk] != null ? dr[pk] : dr.id);
  1284. var b = r && (r[pk] != null ? r[pk] : r.id);
  1285. if (a != null && b != null && String(a) === String(b)) {
  1286. rowIdx = di;
  1287. return false;
  1288. }
  1289. });
  1290. var rowCopy = $.extend({}, r);
  1291. if (rowIdx >= 0 && $btPo.length) {
  1292. var $qty = $btPo.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]');
  1293. var $price = $btPo.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]');
  1294. if ($qty.length) {
  1295. rowCopy.This_quantity = String($qty.val()).trim();
  1296. }
  1297. if ($price.length) {
  1298. rowCopy.ceilingPrice = String($price.val()).trim();
  1299. }
  1300. }
  1301. out.push(rowCopy);
  1302. });
  1303. return out;
  1304. }
  1305. function procuremenOpenPickReview(selRows) {
  1306. if (!selRows || !selRows.length) {
  1307. Toastr.warning('请先勾选至少 1 条工序');
  1308. return;
  1309. }
  1310. var ccydh0 = String(selRows[0].CCYDH || '').trim();
  1311. if (!ccydh0) {
  1312. Toastr.warning('所选行缺少订单号,无法下发');
  1313. return;
  1314. }
  1315. if (selRows.length > 1) {
  1316. var j;
  1317. for (j = 1; j < selRows.length; j++) {
  1318. if (String(selRows[j].CCYDH || '').trim() !== ccydh0) {
  1319. Toastr.warning('合并下发须为同一订单号(当前混有:' + ccydh0 + ' 与其它订单)');
  1320. return;
  1321. }
  1322. }
  1323. }
  1324. var pk0 = table.bootstrapTable('getOptions').pk || 'ID';
  1325. var ids = [];
  1326. $.each(selRows, function (idx, r) {
  1327. var pkVal = r && (r[pk0] != null ? r[pk0] : r.id);
  1328. if (pkVal != null && String(pkVal) !== '' && String(pkVal) !== '0') {
  1329. ids.push(String(pkVal));
  1330. }
  1331. });
  1332. if (!ids.length) {
  1333. Toastr.warning('所选行无效,无法下发');
  1334. return;
  1335. }
  1336. try {
  1337. sessionStorage.setItem('procuremen_merge_rows', JSON.stringify(selRows));
  1338. } catch (ignoreStore) {
  1339. }
  1340. var titlePick = ' ';
  1341. var revUrl = Fast.api.fixurl('procuremen/pickreview?ids=' + encodeURIComponent(ids[0]) + '&merge=1');
  1342. var winPick = window;
  1343. if (!winPick.Backend || !winPick.Backend.api) {
  1344. Toastr.error('Backend 未就绪,请刷新页面');
  1345. return;
  1346. }
  1347. winPick.Backend.api.open(revUrl, titlePick, {area: ['76%', '100%']});
  1348. }
  1349. $(document).off('click.procuremenPickReview', '#btn-procuremen-pick-review').on('click.procuremenPickReview', '#btn-procuremen-pick-review', function (e) {
  1350. e.preventDefault();
  1351. if (Controller.wffTab !== 'pick') {
  1352. Toastr.warning('下发仅在协助下发列表可用');
  1353. return;
  1354. }
  1355. var selPick = procuremenRowsWithPoInputs(table.bootstrapTable('getSelections') || []);
  1356. procuremenOpenPickReview(selPick);
  1357. });
  1358. $(document).off('click.procuremenAuditAbandon', '#btn-procuremen-audit-abandon').on('click.procuremenAuditAbandon', '#btn-procuremen-audit-abandon', function (e) {
  1359. e.preventDefault();
  1360. if (Controller.wffTab !== 'audit') {
  1361. Toastr.warning('重新下发仅在协助审批下发列表可用');
  1362. return;
  1363. }
  1364. var selAb = table.bootstrapTable('getSelections') || [];
  1365. if (!selAb.length) {
  1366. Toastr.warning('请先勾选至少 1 条订单');
  1367. return;
  1368. }
  1369. var idSet = {};
  1370. $.each(selAb, function (ai, ra) {
  1371. var sid = ra && (ra.ID != null ? ra.ID : ra.id);
  1372. if (sid != null && sid !== '' && String(sid) !== '0') {
  1373. idSet[String(sid)] = true;
  1374. }
  1375. });
  1376. var idList = Object.keys(idSet);
  1377. if (!idList.length) {
  1378. Toastr.warning('所选行无效,请重新勾选');
  1379. return;
  1380. }
  1381. var abandonMsg = procuremenBuildConfirmMsg(
  1382. '退回初选并重新下发以下 <strong>' + idList.length + '</strong> 个订单:',
  1383. procuremenBuildConfirmRowsTable(selAb)
  1384. );
  1385. Layer.confirm(abandonMsg, $.extend({}, procuremenConfirmLayerBase, {
  1386. title: '重新下发确认',
  1387. btn: ['确认重新下发', '取消']
  1388. }), function (idxAb) {
  1389. Layer.close(idxAb);
  1390. Fast.api.ajax({
  1391. url: 'procuremen/auditabandon',
  1392. type: 'POST',
  1393. data: {
  1394. scydgy_ids_json: JSON.stringify(idList),
  1395. __token__: $('input[name=\'__token__\']').val() || Config.token
  1396. }
  1397. }, function (data, ret) {
  1398. table.bootstrapTable('refresh');
  1399. return false;
  1400. });
  1401. });
  1402. });
  1403. $(document).off('click.procuremenPickDelete', '#btn-procuremen-pick-delete').on('click.procuremenPickDelete', '#btn-procuremen-pick-delete', function (e) {
  1404. e.preventDefault();
  1405. if (Controller.wffTab !== 'pick') {
  1406. Toastr.warning('删除仅在协助初选列表可用');
  1407. return;
  1408. }
  1409. var selDel = procuremenRowsWithPoInputs(table.bootstrapTable('getSelections') || []);
  1410. if (!selDel.length) {
  1411. Toastr.warning('请先勾选至少 1 条工序');
  1412. return;
  1413. }
  1414. var deleteMsg = procuremenBuildConfirmMsg(
  1415. '删除以下 <strong>' + selDel.length + '</strong> 条工序,确认后将无法恢复:',
  1416. procuremenBuildConfirmRowsTable(selDel)
  1417. );
  1418. Layer.confirm(deleteMsg, $.extend({}, procuremenConfirmLayerBase, {
  1419. title: '删除',
  1420. btn: ['确定删除', '取消']
  1421. }), function (idxDel) {
  1422. Layer.close(idxDel);
  1423. Fast.api.ajax({
  1424. url: 'procuremen/pickdelete',
  1425. type: 'POST',
  1426. data: {
  1427. rows_json: JSON.stringify(selDel),
  1428. __token__: $('input[name=\'__token__\']').val() || ''
  1429. }
  1430. }, function () {
  1431. table.bootstrapTable('refresh');
  1432. return false;
  1433. });
  1434. });
  1435. });
  1436. $(document).off('click.procuremenBatchFinish', '#btn-procuremen-batch-finish').on('click.procuremenBatchFinish', '#btn-procuremen-batch-finish', function (e) {
  1437. e.preventDefault();
  1438. if (Controller.wffTab !== 'pick') {
  1439. Toastr.warning('完结仅在协助下发列表可用');
  1440. return;
  1441. }
  1442. var selFin = procuremenRowsWithPoInputs(table.bootstrapTable('getSelections') || []);
  1443. if (!selFin.length) {
  1444. Toastr.warning('请先勾选至少 1 条工序');
  1445. return;
  1446. }
  1447. var finishBatchMsg = procuremenBuildConfirmMsg(
  1448. '将对以下 <strong>' + selFin.length + '</strong> 条工序标记为<strong>已完结</strong>:',
  1449. procuremenBuildConfirmRowsTable(selFin)
  1450. );
  1451. Layer.confirm(finishBatchMsg, $.extend({}, procuremenConfirmLayerBase, {
  1452. title: '完结确认',
  1453. btn: ['确定', '取消']
  1454. }), function (idxFin) {
  1455. Layer.close(idxFin);
  1456. var tokenFin = $('input[name=\'__token__\']').val() || '';
  1457. var pending = selFin.length;
  1458. var failed = 0;
  1459. var nextFin = function (pos) {
  1460. if (pos >= selFin.length) {
  1461. table.bootstrapTable('refresh');
  1462. if (failed) {
  1463. Toastr.warning('部分工序完结失败(' + failed + '/' + selFin.length + ')');
  1464. } else {
  1465. Toastr.success('已完结 ' + pending + ' 条工序');
  1466. }
  1467. return;
  1468. }
  1469. Fast.api.ajax({
  1470. url: 'procuremen/completeDirectly',
  1471. type: 'POST',
  1472. data: {
  1473. row_json: JSON.stringify(selFin[pos]),
  1474. finish: '1',
  1475. __token__: tokenFin
  1476. }
  1477. }, function () {
  1478. nextFin(pos + 1);
  1479. return false;
  1480. }, function () {
  1481. failed++;
  1482. nextFin(pos + 1);
  1483. return false;
  1484. });
  1485. };
  1486. nextFin(0);
  1487. });
  1488. });
  1489. (function () {
  1490. var $wrap = table.closest('.bootstrap-table');
  1491. function procuremenSetFixedRightStaleLoading(hide) {
  1492. $wrap.find('.fixed-columns-right').toggleClass('procuremen-hide-fixed-right-loading', !!hide);
  1493. }
  1494. table.on('refresh.bs.table', function () {
  1495. if ($wrap.find('.fixed-table-loading').is(':visible')) {
  1496. procuremenSetFixedRightStaleLoading(true);
  1497. }
  1498. });
  1499. table.on('load-success.bs.table load-error.bs.table', function () {
  1500. procuremenSetFixedRightStaleLoading(false);
  1501. });
  1502. })();
  1503. var $bt = table.closest('.bootstrap-table');
  1504. var $poPopover = null;
  1505. var procuremenPoActiveRow = null;
  1506. var procuremenPoFocusSnapshot = null;
  1507. function procuremenNormPoCell(v) {
  1508. if (v == null || v === '') {
  1509. return '';
  1510. }
  1511. return String(v).trim();
  1512. }
  1513. function procuremenPoRowValues(rowIdx) {
  1514. if (!$bt.length) {
  1515. return null;
  1516. }
  1517. var dataRows = table.bootstrapTable('getData');
  1518. var baseRow = dataRows[rowIdx];
  1519. if (!baseRow) {
  1520. return null;
  1521. }
  1522. var $qty = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]');
  1523. var $price = $bt.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]');
  1524. var q = ($qty.length ? String($qty.val()) : '').trim();
  1525. var p = ($price.length ? String($price.val()) : '').trim();
  1526. var origQ = procuremenNormPoCell(baseRow.This_quantity);
  1527. var origP = procuremenNormPoCell(baseRow.ceilingPrice);
  1528. if (origP === '' && baseRow.ceiling_price != null && baseRow.ceiling_price !== '') {
  1529. origP = procuremenNormPoCell(baseRow.ceiling_price);
  1530. }
  1531. return {baseRow: baseRow, q: q, p: p, origQ: origQ, origP: origP};
  1532. }
  1533. function procuremenPoRowDirty(rowIdx) {
  1534. var v = procuremenPoRowValues(rowIdx);
  1535. if (!v) {
  1536. return false;
  1537. }
  1538. // 允许清空:只要与库中原值不同即视为已修改(两个都删空也能保存)
  1539. return v.q !== v.origQ || v.p !== v.origP;
  1540. }
  1541. function procuremenEnsurePoPopover() {
  1542. if ($poPopover && $poPopover.length) {
  1543. return $poPopover;
  1544. }
  1545. $poPopover = $('<div class="procuremen-po-popover" style="display:none;">'
  1546. + '<div class="procuremen-po-popover-inner">'
  1547. + '<button type="button" class="btn btn-xs btn-primary procuremen-po-pop-save">保存</button>'
  1548. + '<button type="button" class="btn btn-xs btn-default procuremen-po-pop-cancel">取消</button>'
  1549. + '</div></div>').appendTo('body');
  1550. $poPopover.on('mousedown', function (e) {
  1551. e.preventDefault();
  1552. });
  1553. return $poPopover;
  1554. }
  1555. function procuremenPoPopoverPosition($inp) {
  1556. if (!$inp || !$inp.length) {
  1557. return;
  1558. }
  1559. var rect = $inp[0].getBoundingClientRect();
  1560. var $pop = procuremenEnsurePoPopover();
  1561. var popW = $pop.outerWidth() || 120;
  1562. var left = rect.left;
  1563. var vw = window.innerWidth || document.documentElement.clientWidth || 0;
  1564. if (left + popW > vw - 8) {
  1565. left = Math.max(8, vw - popW - 8);
  1566. }
  1567. $pop.css({
  1568. display: 'block',
  1569. top: (rect.bottom + 4) + 'px',
  1570. left: left + 'px'
  1571. });
  1572. }
  1573. function procuremenPoPopoverSyncSaveBtn(rowIdx) {
  1574. if (!$bt.length || isNaN(rowIdx)) {
  1575. return;
  1576. }
  1577. var dirty = procuremenPoRowDirty(rowIdx);
  1578. procuremenEnsurePoPopover().find('.procuremen-po-pop-save').prop('disabled', !dirty);
  1579. $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"], .procuremen-po-price[data-row-index="' + rowIdx + '"]')
  1580. .toggleClass('procuremen-po-dirty', dirty);
  1581. }
  1582. function procuremenPoPopoverHide() {
  1583. if ($poPopover) {
  1584. $poPopover.hide();
  1585. }
  1586. procuremenPoActiveRow = null;
  1587. procuremenPoFocusSnapshot = null;
  1588. }
  1589. function procuremenPoPopoverCancel() {
  1590. if (procuremenPoActiveRow === null || !$bt.length) {
  1591. procuremenPoPopoverHide();
  1592. return;
  1593. }
  1594. var rowIdx = procuremenPoActiveRow;
  1595. var snap = procuremenPoFocusSnapshot;
  1596. if (snap) {
  1597. $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]').val(snap.q);
  1598. $bt.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]').val(snap.p);
  1599. }
  1600. $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"], .procuremen-po-price[data-row-index="' + rowIdx + '"]')
  1601. .removeClass('procuremen-po-dirty');
  1602. procuremenPoPopoverHide();
  1603. }
  1604. function procuremenPoPopoverShow($inp) {
  1605. if (Controller.wffTab !== 'pick' || !$inp.length) {
  1606. return;
  1607. }
  1608. var rowIdx = parseInt($inp.data('rowIndex'), 10);
  1609. if (isNaN(rowIdx)) {
  1610. return;
  1611. }
  1612. // 切到另一行时,上一行有未保存修改则先自动保存
  1613. if (procuremenPoActiveRow !== null && procuremenPoActiveRow !== rowIdx
  1614. && procuremenPoRowDirty(procuremenPoActiveRow)) {
  1615. procuremenSavePoRow(procuremenPoActiveRow);
  1616. }
  1617. var v = procuremenPoRowValues(rowIdx);
  1618. if (!v) {
  1619. return;
  1620. }
  1621. procuremenPoActiveRow = rowIdx;
  1622. procuremenPoFocusSnapshot = {q: v.origQ, p: v.origP};
  1623. procuremenPoPopoverSyncSaveBtn(rowIdx);
  1624. procuremenPoPopoverPosition($inp);
  1625. }
  1626. function procuremenSavePoRow(rowIdx) {
  1627. if (Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') {
  1628. return;
  1629. }
  1630. var v = procuremenPoRowValues(rowIdx);
  1631. if (!v) {
  1632. return;
  1633. }
  1634. if (!procuremenPoRowDirty(rowIdx)) {
  1635. Toastr.info('没有需要保存的修改');
  1636. return;
  1637. }
  1638. var row = $.extend({}, v.baseRow);
  1639. row.This_quantity = v.q;
  1640. row.ceilingPrice = v.p;
  1641. var $saveBtn = procuremenEnsurePoPopover().find('.procuremen-po-pop-save');
  1642. $saveBtn.prop('disabled', true);
  1643. Fast.api.ajax({
  1644. url: 'procuremen/completeDirectly',
  1645. type: 'POST',
  1646. data: {
  1647. row_json: JSON.stringify(row),
  1648. finish: '0',
  1649. __token__: $('input[name=\'__token__\']').val() || ''
  1650. }
  1651. }, function () {
  1652. try {
  1653. table.bootstrapTable('updateRow', {
  1654. index: rowIdx,
  1655. row: $.extend({}, v.baseRow, {This_quantity: v.q, ceilingPrice: v.p})
  1656. });
  1657. } catch (ignore) {
  1658. }
  1659. procuremenPoPopoverHide();
  1660. Toastr.success('保存成功');
  1661. return false;
  1662. }, function () {
  1663. procuremenPoPopoverSyncSaveBtn(rowIdx);
  1664. return false;
  1665. });
  1666. }
  1667. if ($bt.length) {
  1668. $bt.off('focusin.procuremenPoPop click.procuremenPoPop', '.procuremen-po-field')
  1669. .on('focusin.procuremenPoPop click.procuremenPoPop', '.procuremen-po-field', function () {
  1670. procuremenPoPopoverShow($(this));
  1671. });
  1672. $bt.off('input.procuremenPoPop change.procuremenPoPop', '.procuremen-po-field')
  1673. .on('input.procuremenPoPop change.procuremenPoPop', '.procuremen-po-field', function () {
  1674. if (Controller.wffTab !== 'pick') {
  1675. return;
  1676. }
  1677. var rowIdx = parseInt($(this).data('rowIndex'), 10);
  1678. if (procuremenPoActiveRow === rowIdx) {
  1679. procuremenPoPopoverSyncSaveBtn(rowIdx);
  1680. procuremenPoPopoverPosition($(this));
  1681. }
  1682. });
  1683. }
  1684. procuremenEnsurePoPopover()
  1685. .off('click.procuremenPoPopAct')
  1686. .on('click.procuremenPoPopAct', '.procuremen-po-pop-cancel', function (e) {
  1687. e.preventDefault();
  1688. procuremenPoPopoverCancel();
  1689. })
  1690. .on('click.procuremenPoPopAct', '.procuremen-po-pop-save', function (e) {
  1691. e.preventDefault();
  1692. if (procuremenPoActiveRow === null || $(this).prop('disabled')) {
  1693. return;
  1694. }
  1695. procuremenSavePoRow(procuremenPoActiveRow);
  1696. });
  1697. $(document).off('mousedown.procuremenPoPopClose').on('mousedown.procuremenPoPopClose', function (e) {
  1698. if (Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') {
  1699. return;
  1700. }
  1701. var $t = $(e.target);
  1702. if ($t.closest('.procuremen-po-field, .procuremen-po-popover').length) {
  1703. return;
  1704. }
  1705. // 点到别处时:有未保存修改则自动保存(避免删空后忘点保存)
  1706. var rowIdx = procuremenPoActiveRow;
  1707. if (rowIdx !== null && procuremenPoRowDirty(rowIdx)) {
  1708. procuremenSavePoRow(rowIdx);
  1709. return;
  1710. }
  1711. procuremenPoPopoverHide();
  1712. });
  1713. table.on('refresh.bs.table load-success.bs.table', function () {
  1714. procuremenPoPopoverHide();
  1715. });
  1716. $(window).off('resize.procuremenPoPop scroll.procuremenPoPop')
  1717. .on('resize.procuremenPoPop scroll.procuremenPoPop', function () {
  1718. if (procuremenPoActiveRow === null || !$bt.length) {
  1719. return;
  1720. }
  1721. var $active = $bt.find('.procuremen-po-field[data-row-index="' + procuremenPoActiveRow + '"]:focus');
  1722. if ($active.length) {
  1723. procuremenPoPopoverPosition($active);
  1724. } else {
  1725. procuremenPoPopoverHide();
  1726. }
  1727. });
  1728. if ($bt.length && $bt[0]) {
  1729. var tableRoot = $bt[0];
  1730. Controller._procuremenOpTableClick = function (e) {
  1731. var t = e.target;
  1732. if (!t || typeof t.closest !== 'function') {
  1733. return;
  1734. }
  1735. var details = t.closest('a.procuremen-btn-details');
  1736. if (details && tableRoot.contains(details) && !details.classList.contains('disabled')) {
  1737. e.preventDefault();
  1738. if (typeof e.stopImmediatePropagation === 'function') {
  1739. e.stopImmediatePropagation();
  1740. }
  1741. e.stopPropagation();
  1742. var $d = $(details);
  1743. var rowIdxD = parseInt($d.data('rowIndex'), 10);
  1744. var dataRowsD = table.bootstrapTable('getData');
  1745. var rowD = !isNaN(rowIdxD) && dataRowsD[rowIdxD] !== undefined ? dataRowsD[rowIdxD] : null;
  1746. var detUrl;
  1747. if (rowD) {
  1748. detUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/details', rowD, table));
  1749. } else {
  1750. detUrl = Backend.api.replaceids(details, $d.attr('href'));
  1751. }
  1752. var tabForDet = Controller.wffTab ? Controller.wffTab : 'done';
  1753. if (String(detUrl).indexOf('wff_tab=') === -1) {
  1754. detUrl += (detUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tabForDet);
  1755. }
  1756. var $ad = $(details);
  1757. var optsd = $.extend({}, $ad.data() || {});
  1758. var titled = $ad.attr('title') || $ad.data('title') || '详情';
  1759. var buttond = Backend.api.gettablecolumnbutton(optsd);
  1760. var layerOptsd = $.extend({}, optsd);
  1761. if (buttond && typeof buttond.callback === 'function') {
  1762. layerOptsd.callback = buttond.callback;
  1763. }
  1764. if (buttond && buttond.layerArea && buttond.layerArea.length) {
  1765. layerOptsd.area = buttond.layerArea;
  1766. }
  1767. var winNd = $ad.data('window') || 'self';
  1768. var winD = window[winNd] || window;
  1769. if (!winD.Backend || !winD.Backend.api) {
  1770. Toastr.error('Backend 未就绪,请刷新页面');
  1771. return;
  1772. }
  1773. winD.Backend.api.open(detUrl, titled, layerOptsd);
  1774. return;
  1775. }
  1776. var outward = t.closest('a.procuremen-btn-outward');
  1777. if (outward && !outward.classList.contains('disabled')) {
  1778. e.preventDefault();
  1779. if (typeof e.stopImmediatePropagation === 'function') {
  1780. e.stopImmediatePropagation();
  1781. }
  1782. e.stopPropagation();
  1783. var $o = $(outward);
  1784. var oOpts = $.extend({}, $o.data() || {});
  1785. var rowIdx = parseInt(oOpts.rowIndex, 10);
  1786. var dataRows = table.bootstrapTable('getData');
  1787. var row = !isNaN(rowIdx) && dataRows[rowIdx] !== undefined ? dataRows[rowIdx] : null;
  1788. var tab = Controller.wffTab ? Controller.wffTab : 'all';
  1789. var base = 'procuremen/outward_detail?wff_tab=' + encodeURIComponent(tab);
  1790. var outUrl;
  1791. if (row) {
  1792. outUrl = Fast.api.fixurl(Table.api.replaceurl(base, row, table));
  1793. } else {
  1794. outUrl = Backend.api.replaceids(outward, $o.attr('href'));
  1795. if (String(outUrl).indexOf('wff_tab=') === -1) {
  1796. outUrl += (outUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tab);
  1797. }
  1798. }
  1799. var $a = $(outward);
  1800. var opts = $.extend({}, $a.data() || {});
  1801. var title = $a.attr('title') || $a.data('title') || $a.data('original-title');
  1802. var button = Backend.api.gettablecolumnbutton(opts);
  1803. var layerOpts = $.extend({}, opts);
  1804. if (button && typeof button.callback === 'function') {
  1805. layerOpts.callback = button.callback;
  1806. }
  1807. if (button && button.layerArea && button.layerArea.length) {
  1808. layerOpts.area = button.layerArea;
  1809. }
  1810. var winName = $a.data('window') || 'self';
  1811. var win = window[winName] || window;
  1812. if (!win.Backend || !win.Backend.api) {
  1813. Toastr.error('Backend 未就绪,请刷新页面');
  1814. return;
  1815. }
  1816. if (typeof layerOpts.confirm !== 'undefined') {
  1817. Layer.confirm(layerOpts.confirm, function (index) {
  1818. win.Backend.api.open(outUrl, title, layerOpts);
  1819. Layer.close(index);
  1820. });
  1821. } else {
  1822. win.Backend.api.open(outUrl, title, layerOpts);
  1823. }
  1824. return;
  1825. }
  1826. var auditIssueBtn = t.closest('a.procuremen-btn-audit-issue');
  1827. if (auditIssueBtn && tableRoot.contains(auditIssueBtn) && !auditIssueBtn.classList.contains('disabled')) {
  1828. e.preventDefault();
  1829. if (typeof e.stopImmediatePropagation === 'function') {
  1830. e.stopImmediatePropagation();
  1831. }
  1832. e.stopPropagation();
  1833. var $aa = $(auditIssueBtn);
  1834. var rowIdxA = parseInt($aa.data('rowIndex'), 10);
  1835. var dataRowsA = table.bootstrapTable('getData');
  1836. var rowA = !isNaN(rowIdxA) && dataRowsA[rowIdxA] !== undefined ? dataRowsA[rowIdxA] : null;
  1837. var auditUrl;
  1838. if (rowA) {
  1839. auditUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/auditissue', rowA, table));
  1840. } else {
  1841. auditUrl = Backend.api.replaceids(auditIssueBtn, $aa.attr('href'));
  1842. }
  1843. var winA = window;
  1844. if (winA.Backend && winA.Backend.api) {
  1845. winA.Backend.api.open(auditUrl, '供应商报价明细', {area: ['96%', '88%']});
  1846. }
  1847. return;
  1848. }
  1849. };
  1850. tableRoot.addEventListener('click', Controller._procuremenOpTableClick, true);
  1851. }
  1852. $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) {
  1853. e.preventDefault();
  1854. var $spinFa = $('.bootstrap-table > .fixed-table-toolbar .btn-refresh .fa, #procuremen-toolbar-host .btn-refresh .fa, .procuremen-table-area #toolbar .btn-refresh .fa');
  1855. $spinFa.addClass('fa-spin');
  1856. var apiBase = ($layout.attr('data-procuremen-redis-api') || '').toString().trim();
  1857. if (apiBase) {
  1858. var sep = apiBase.indexOf('?') > -1 ? '&' : '?';
  1859. var refreshUrl = apiBase + sep + 'refresh=1';
  1860. $.ajax({
  1861. url: refreshUrl,
  1862. type: 'GET',
  1863. dataType: 'json',
  1864. timeout: 120000
  1865. }).done(function (ret) {
  1866. if (!(ret && (ret.code === 200 || ret.code === '200'))) {
  1867. console.warn('procuremen redis refresh:', ret);
  1868. }
  1869. }).fail(function () {
  1870. console.warn('procuremen redis refresh failed');
  1871. }).always(function () {
  1872. table.bootstrapTable('refresh');
  1873. });
  1874. } else {
  1875. table.bootstrapTable('refresh');
  1876. }
  1877. });
  1878. table.on('refresh.bs.table', function () {
  1879. setTimeout(function () {
  1880. procuremenPlaceToolbar();
  1881. }, 0);
  1882. });
  1883. table.on('post-body.bs.table', function () {
  1884. $('#procuremen-toolbar-host .btn-refresh .fa, .bootstrap-table > .fixed-table-toolbar .btn-refresh .fa').removeClass('fa-spin');
  1885. procuremenScheduleAlign();
  1886. if (Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') {
  1887. return;
  1888. }
  1889. /* FastAdmin 每次 post-body 会重复绑定复选框列拖拽,多次勾选后易错位/缺框 */
  1890. var $cbTd = table.closest('.bootstrap-table').find('tbody td.bs-checkbox');
  1891. $cbTd.off('mousedown mousemove').removeClass('overlaped');
  1892. $cbTd.each(function () {
  1893. var $td = $(this);
  1894. if (!$td.find('input[name="btSelectItem"]').length) {
  1895. var idx = $td.closest('tr').data('index');
  1896. if (idx !== undefined && idx !== '') {
  1897. $td.html('<input name="btSelectItem" type="checkbox" data-index="' + idx + '" />');
  1898. }
  1899. }
  1900. });
  1901. });
  1902. table.on('column-switch.bs.table reset-view.bs.table', function () {
  1903. procuremenScheduleAlign();
  1904. });
  1905. if ($bt.length) {
  1906. $bt.off('click.procuremenCbTd', 'tbody td.bs-checkbox').on('click.procuremenCbTd', 'tbody td.bs-checkbox', function (e) {
  1907. if ((Controller.wffTab !== 'pick' && Controller.wffTab !== 'audit') || $(e.target).is('input[type="checkbox"]')) {
  1908. return;
  1909. }
  1910. var $inp = $(this).find('input[name="btSelectItem"]:not(:disabled)').first();
  1911. if ($inp.length) {
  1912. e.preventDefault();
  1913. $inp.trigger('click');
  1914. }
  1915. });
  1916. }
  1917. },
  1918. pick: function () {
  1919. Controller.index();
  1920. },
  1921. audit: function () {
  1922. Controller.index();
  1923. },
  1924. confirm: function () {
  1925. Controller.index();
  1926. },
  1927. rfqlist: function () {
  1928. var isSuperAdmin = String($('.procuremen-rfqlist-wrap').data('super-admin') || '') === '1'
  1929. || String($('.procuremen-rfqlist-wrap').attr('data-super-admin') || '') === '1';
  1930. Table.api.init({
  1931. extend: {
  1932. index_url: 'procuremen/rfqlist' + location.search,
  1933. table: 'purchase_order',
  1934. }
  1935. });
  1936. var table = $('#table');
  1937. var rfqHeightCached = 0;
  1938. var rfqHeightTimer = null;
  1939. function rfqCalcTableHeight() {
  1940. var $bt = table.closest('.bootstrap-table');
  1941. var el = $bt.length ? $bt[0] : table[0];
  1942. if (!el || !el.getBoundingClientRect) {
  1943. return 400;
  1944. }
  1945. // 必须从 .bootstrap-table 顶部算(含工具栏),才是插件 height 的总高
  1946. var top = el.getBoundingClientRect().top;
  1947. return Math.max(280, Math.floor(window.innerHeight - top - 18));
  1948. }
  1949. function rfqSyncTableHeight() {
  1950. if (rfqHeightTimer) {
  1951. clearTimeout(rfqHeightTimer);
  1952. }
  1953. rfqHeightTimer = setTimeout(function () {
  1954. rfqHeightTimer = null;
  1955. var h = rfqCalcTableHeight();
  1956. if (rfqHeightCached > 0 && Math.abs(rfqHeightCached - h) <= 3) {
  1957. rfqFitEmptyState();
  1958. return;
  1959. }
  1960. rfqHeightCached = h;
  1961. try {
  1962. table.bootstrapTable('resetView', {height: h});
  1963. } catch (ignore) {
  1964. }
  1965. rfqFitEmptyState();
  1966. }, 100);
  1967. }
  1968. /** 无数据时占满表体高度,文案垂直居中到底部区域 */
  1969. function rfqFitEmptyState() {
  1970. var $bt = table.closest('.bootstrap-table');
  1971. var $body = $bt.find('.fixed-table-body').first();
  1972. var $tr = $body.find('tr.no-records-found');
  1973. if (!$tr.length || !$body.length) {
  1974. return;
  1975. }
  1976. var h = Math.max(160, Math.floor($body.innerHeight() || 0) - 4);
  1977. $tr.find('> td').css({
  1978. height: h + 'px',
  1979. verticalAlign: 'middle',
  1980. textAlign: 'center',
  1981. color: '#8c8c8c',
  1982. fontSize: '14px',
  1983. border: 'none'
  1984. });
  1985. }
  1986. var columns = [
  1987. {field: 'CCYDH', title: '订单号', operate: 'LIKE', width: 120},
  1988. {field: 'CYJMC', title: '印件名称', operate: 'LIKE', class: 'autocontent', formatter: Table.api.formatter.content},
  1989. {field: 'CCLBMMC', title: '承揽部门', operate: 'LIKE', width: 100},
  1990. {field: 'CGYMC', title: '工序名称', operate: 'LIKE', class: 'autocontent', formatter: Table.api.formatter.content},
  1991. {
  1992. field: 'progress_text',
  1993. title: '当前进度',
  1994. operate: false,
  1995. width: 130,
  1996. align: 'center',
  1997. formatter: function (value) {
  1998. var v = value == null ? '' : String(value);
  1999. if (v === '已完结') {
  2000. return '<span class="label label-success">' + v + '</span>';
  2001. }
  2002. if (v === '待采购确认' || v === '待确认供应商') {
  2003. return '<span class="label label-warning">' + v + '</span>';
  2004. }
  2005. if (v === '已下发待确认') {
  2006. return '<span class="label label-info">' + v + '</span>';
  2007. }
  2008. return v ? '<span class="label label-default">' + v + '</span>' : '';
  2009. }
  2010. },
  2011. {
  2012. field: 'createtime',
  2013. title: '新增时间',
  2014. operate: 'RANGE',
  2015. addclass: 'datetimerange',
  2016. autocomplete: false,
  2017. width: 165,
  2018. formatter: function (value, row) {
  2019. if (row.createtime_text) {
  2020. return row.createtime_text;
  2021. }
  2022. if (value == null || value === '') {
  2023. return '';
  2024. }
  2025. var n = parseInt(value, 10);
  2026. if (!isNaN(n) && n > 946684800) {
  2027. return Table.api.formatter.datetime.call(this, value, row);
  2028. }
  2029. return String(value);
  2030. }
  2031. },
  2032. {
  2033. field: 'operate',
  2034. title: '操作',
  2035. width: 100,
  2036. align: 'center',
  2037. operate: false,
  2038. table: table,
  2039. formatter: function (value, row) {
  2040. var sid = row && row.scydgy_id;
  2041. if (!sid) {
  2042. return '';
  2043. }
  2044. if (!procuremenCan('details')) {
  2045. return '';
  2046. }
  2047. 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>';
  2048. },
  2049. events: {}
  2050. }
  2051. ];
  2052. if (isSuperAdmin) {
  2053. columns.splice(4, 0, {field: 'cywyxm', title: '业务员', operate: 'LIKE', width: 90, align: 'center'});
  2054. }
  2055. table.bootstrapTable({
  2056. url: $.fn.bootstrapTable.defaults.extend.index_url,
  2057. pk: 'scydgy_id',
  2058. sortName: 'id',
  2059. sortOrder: 'desc',
  2060. height: rfqCalcTableHeight(),
  2061. commonSearch: true,
  2062. pagination: true,
  2063. smartDisplay: false,
  2064. pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
  2065. pageList: [10, 15, 20, 25, 50],
  2066. showJumpto: true,
  2067. formatNoMatches: function () {
  2068. return '暂无数据';
  2069. },
  2070. columns: [columns]
  2071. });
  2072. Table.api.bindevent(table);
  2073. table.on('post-body.bs.table load-success.bs.table', function () {
  2074. rfqSyncTableHeight();
  2075. setTimeout(rfqFitEmptyState, 0);
  2076. });
  2077. $(window).off('resize.procuremenRfqlist').on('resize.procuremenRfqlist', function () {
  2078. if ($('body').hasClass('fa-sidebar-resizing')) {
  2079. return;
  2080. }
  2081. rfqHeightCached = 0;
  2082. rfqSyncTableHeight();
  2083. });
  2084. $(document).off('fa.sidebar.resized.procuremenRfq fa.table.relayout.procuremenRfq')
  2085. .on('fa.sidebar.resized.procuremenRfq fa.table.relayout.procuremenRfq', function () {
  2086. if ($('body').hasClass('fa-sidebar-resizing')) {
  2087. return;
  2088. }
  2089. rfqHeightCached = 0;
  2090. rfqSyncTableHeight();
  2091. });
  2092. $(document).off('click.procuremenRfqCommonSearch', 'button[name="commonSearch"]').on('click.procuremenRfqCommonSearch', 'button[name="commonSearch"]', function () {
  2093. setTimeout(function () {
  2094. rfqSyncTableHeight();
  2095. rfqFitEmptyState();
  2096. }, 150);
  2097. });
  2098. $(document).off('click.procuremenRfqDetails', '.btn-rfq-details').on('click.procuremenRfqDetails', '.btn-rfq-details', function (e) {
  2099. e.preventDefault();
  2100. var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
  2101. if (!sid) {
  2102. return;
  2103. }
  2104. var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
  2105. Backend.api.open(url, '详情', {area: ['92%', '88%']});
  2106. });
  2107. },
  2108. add: function () {
  2109. Controller.api.bindevent();
  2110. },
  2111. edit: function () {
  2112. Controller.api.bindevent();
  2113. },
  2114. outward_detail: function () {
  2115. Controller.api.bindevent();
  2116. procuremenInitSysRqSplit($('#outward-confirm-sys-rq-wrap'), 'outwardConfirm', {readonly: true});
  2117. var $wrap = $('.outward-detail-wrap');
  2118. if (!$wrap.length || !$('#btn-pod-purchase-confirm').length) {
  2119. return;
  2120. }
  2121. var scydgyId = String($wrap.attr('data-scydgy-id') || '').trim();
  2122. if (!scydgyId) {
  2123. return;
  2124. }
  2125. var purchaseOrderId = String($wrap.attr('data-purchase-order-id') || '').trim();
  2126. var requiredSids = [];
  2127. var allDetailsBySid = {};
  2128. try {
  2129. requiredSids = JSON.parse($wrap.attr('data-required-sids') || '[]');
  2130. if (!Array.isArray(requiredSids)) {
  2131. requiredSids = [];
  2132. }
  2133. } catch (eReq) {
  2134. requiredSids = [];
  2135. }
  2136. try {
  2137. allDetailsBySid = JSON.parse($wrap.attr('data-all-details-by-sid') || '{}');
  2138. if (!allDetailsBySid || typeof allDetailsBySid !== 'object') {
  2139. allDetailsBySid = {};
  2140. }
  2141. } catch (eAll) {
  2142. allDetailsBySid = {};
  2143. }
  2144. if (requiredSids.length === 0) {
  2145. requiredSids = [parseInt(scydgyId, 10)];
  2146. }
  2147. function parseDetailPicks($cb) {
  2148. var raw = String($cb.attr('data-detail-picks') || '[]');
  2149. try {
  2150. var arr = JSON.parse(raw);
  2151. return Array.isArray(arr) ? arr : [];
  2152. } catch (e) {
  2153. return [];
  2154. }
  2155. }
  2156. function picksSidSet(picks) {
  2157. var set = {};
  2158. picks.forEach(function (p) {
  2159. if (p && p.scydgy_id) {
  2160. set[String(p.scydgy_id)] = true;
  2161. }
  2162. });
  2163. return set;
  2164. }
  2165. function sidSetsOverlap(a, b) {
  2166. var k;
  2167. for (k in a) {
  2168. if (a.hasOwnProperty(k) && b[k]) {
  2169. return true;
  2170. }
  2171. }
  2172. return false;
  2173. }
  2174. $wrap.off('.procuremenPurchaseConfirm');
  2175. $wrap.find('.pod-company-pick-cb').prop('disabled', true);
  2176. function procuremenOutwardFastRef() {
  2177. if (typeof Fast !== 'undefined' && Fast.api) {
  2178. return Fast;
  2179. }
  2180. if (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api) {
  2181. return parent.Fast;
  2182. }
  2183. return null;
  2184. }
  2185. function procuremenOutwardToast(msg, type) {
  2186. type = type || 'warning';
  2187. var T = null;
  2188. try {
  2189. if (typeof parent !== 'undefined' && parent.Toastr) {
  2190. T = parent.Toastr;
  2191. }
  2192. } catch (eP) {
  2193. }
  2194. if (!T && typeof Toastr !== 'undefined') {
  2195. T = Toastr;
  2196. }
  2197. if (T) {
  2198. if (type === 'error' && typeof T.error === 'function') {
  2199. T.error(msg);
  2200. } else if (typeof T.warning === 'function') {
  2201. T.warning(msg);
  2202. }
  2203. return;
  2204. }
  2205. var Lm = procuremenLayerTop();
  2206. if (Lm && typeof Lm.msg === 'function') {
  2207. Lm.msg(msg);
  2208. }
  2209. }
  2210. function onPurchaseConfirmClick(e) {
  2211. if (e && typeof e.preventDefault === 'function') {
  2212. e.preventDefault();
  2213. }
  2214. var FastRef = procuremenOutwardFastRef();
  2215. if (!FastRef || !FastRef.api) {
  2216. procuremenOutwardToast('页面未就绪,请刷新后重试', 'error');
  2217. return;
  2218. }
  2219. var $checked = $wrap.find('.pod-company-pick-cb:checked');
  2220. if (!$checked.length) {
  2221. procuremenOutwardToast('未指定中标供应商,无法审批通过');
  2222. return;
  2223. }
  2224. function escHtml(s) {
  2225. return String(s)
  2226. .replace(/&/g, '&amp;')
  2227. .replace(/</g, '&lt;')
  2228. .replace(/>/g, '&gt;')
  2229. .replace(/"/g, '&quot;');
  2230. }
  2231. function collectOrderPicks() {
  2232. var winnerBySid = {};
  2233. var conflict = false;
  2234. $checked.each(function () {
  2235. var picks = parseDetailPicks($(this));
  2236. picks.forEach(function (p) {
  2237. if (!p || !p.scydgy_id || !p.detail_id) {
  2238. return;
  2239. }
  2240. var sid = String(p.scydgy_id);
  2241. if (winnerBySid[sid]) {
  2242. conflict = true;
  2243. return;
  2244. }
  2245. winnerBySid[sid] = p;
  2246. });
  2247. });
  2248. if (conflict) {
  2249. return null;
  2250. }
  2251. var i;
  2252. for (i = 0; i < requiredSids.length; i++) {
  2253. if (!winnerBySid[String(requiredSids[i])]) {
  2254. return null;
  2255. }
  2256. }
  2257. var orderPicks = [];
  2258. requiredSids.forEach(function (sid) {
  2259. var win = winnerBySid[String(sid)];
  2260. if (!win) {
  2261. return;
  2262. }
  2263. var allIds = allDetailsBySid[String(sid)] || allDetailsBySid[sid] || [];
  2264. if (!Array.isArray(allIds)) {
  2265. allIds = [];
  2266. }
  2267. allIds = allIds.map(function (x) { return parseInt(String(x), 10); }).filter(function (x) { return x > 0; });
  2268. var selId = parseInt(String(win.detail_id), 10);
  2269. var unsel = allIds.filter(function (id) { return id !== selId; });
  2270. orderPicks.push({
  2271. scydgy_id: String(sid),
  2272. purchase_order_id: parseInt(String(win.purchase_order_id || purchaseOrderId), 10) || 0,
  2273. selected_ids: [selId],
  2274. unselected_ids: unsel
  2275. });
  2276. });
  2277. return orderPicks.length === requiredSids.length ? orderPicks : null;
  2278. }
  2279. var orderPicks = collectOrderPicks();
  2280. if (!orderPicks || orderPicks.length === 0) {
  2281. procuremenOutwardToast(requiredSids.length > 1
  2282. ? '所选供应商须覆盖本单全部工序,且同一工序不可重复选择'
  2283. : '请勾选一家供应商');
  2284. return;
  2285. }
  2286. var okNames = [];
  2287. var unNames = [];
  2288. $checked.each(function () {
  2289. var $tr = $(this).closest('tr');
  2290. var nm = $.trim($tr.children('td').eq(1).text());
  2291. if (nm) {
  2292. okNames.push(nm);
  2293. }
  2294. });
  2295. $wrap.find('.pod-company-pick-cb').not(':checked').each(function () {
  2296. var $tr = $(this).closest('tr');
  2297. var nm = $.trim($tr.children('td').eq(1).text());
  2298. if (nm) {
  2299. unNames.push(nm);
  2300. }
  2301. });
  2302. var nOk = okNames.length;
  2303. var nUn = unNames.length;
  2304. var okListText = nOk ? (nOk <= 4 ? okNames.join('、') : (okNames.slice(0, 3).join('、') + ' 等共' + nOk + '家')) : '—';
  2305. var unListText = nUn ? (nUn <= 4 ? unNames.join('、') : (unNames.slice(0, 3).join('、') + ' 等共' + nUn + '家')) : '—';
  2306. var tk = $('input[name=\'__token__\']').val() || $wrap.find('input[name=\'__token__\']').val() || '';
  2307. var confirmHtml = ''
  2308. + '<div style="text-align:left;line-height:1.75;font-size:13px;">'
  2309. + '<p style="margin:0 0 10px 0;">提交后将<strong>立即发送短信</strong>,且<strong>不可撤回或更改</strong>。请确认以下通知:</p>'
  2310. + '<ul style="margin:0;padding-left:1.2em;">'
  2311. + '<li style="margin-bottom:6px;"><strong>中标 ' + nOk + ' 家</strong>:将向 <strong>' + escHtml(okListText) + '</strong> 发送「已通过」短信;</li>'
  2312. + '<li><strong>未中标 ' + nUn + ' 家</strong>:将向 <strong>' + (nUn ? escHtml(unListText) : '对应供应商') + '</strong> 发送「未通过」短信。</li>'
  2313. + '</ul>'
  2314. + '<p style="margin:12px 0 0 0;"><strong>是否确认提交?</strong></p>'
  2315. + '</div>';
  2316. var Lr = procuremenLayerTop();
  2317. if (!Lr || typeof Lr.confirm !== 'function') {
  2318. procuremenOutwardToast('弹层组件未就绪,请刷新后重试', 'error');
  2319. return;
  2320. }
  2321. Lr.confirm(confirmHtml, {
  2322. icon: 3,
  2323. title: '采购终审 — 审批通过',
  2324. area: ['480px', 'auto'],
  2325. offset: 'auto',
  2326. btn: ['确定提交', '取消'],
  2327. fixed: true,
  2328. shade: 0.35,
  2329. zIndex: procuremenLayerNextZIndex(),
  2330. skin: 'layui-layer-fast procuremen-purchase-sms-confirm',
  2331. success: function (layero) {
  2332. procuremenCenterLayer(layero);
  2333. },
  2334. resizing: function (layero) {
  2335. procuremenCenterLayer(layero);
  2336. }
  2337. }, function (idx) {
  2338. Lr.close(idx);
  2339. FastRef.api.ajax({
  2340. url: FastRef.api.fixurl('procuremen/purchaseConfirmPick'),
  2341. type: 'POST',
  2342. data: {
  2343. __token__: tk,
  2344. order_picks_json: JSON.stringify(orderPicks)
  2345. }
  2346. }, function () {
  2347. if (typeof parent !== 'undefined' && parent.Layer) {
  2348. var ix = parent.Layer.getFrameIndex(window.name);
  2349. if (typeof ix !== 'undefined') {
  2350. parent.Layer.close(ix);
  2351. }
  2352. }
  2353. var p$ = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : (typeof parent !== 'undefined' ? parent.$ : null);
  2354. if (p$) {
  2355. var $doneTab = p$('.procuremen-wff-tabs a[data-wff="done"]');
  2356. if ($doneTab.length) {
  2357. $doneTab.trigger('click');
  2358. } else if (p$('#table').length) {
  2359. p$('#table').bootstrapTable('refresh');
  2360. }
  2361. }
  2362. });
  2363. });
  2364. }
  2365. function onPurchaseRejectClick(e) {
  2366. if (e && typeof e.preventDefault === 'function') {
  2367. e.preventDefault();
  2368. }
  2369. var FastRef = procuremenOutwardFastRef();
  2370. if (!FastRef || !FastRef.api) {
  2371. procuremenOutwardToast('页面未就绪,请刷新后重试', 'error');
  2372. return;
  2373. }
  2374. var rejectPicks = requiredSids.map(function (sid) {
  2375. return {scydgy_id: String(sid)};
  2376. });
  2377. if (!rejectPicks.length) {
  2378. rejectPicks = [{scydgy_id: scydgyId}];
  2379. }
  2380. var Lr = procuremenLayerTop();
  2381. if (!Lr || typeof Lr.confirm !== 'function') {
  2382. procuremenOutwardToast('弹层组件未就绪,请刷新后重试', 'error');
  2383. return;
  2384. }
  2385. Lr.confirm(
  2386. '是否确认驳回?',
  2387. {
  2388. icon: 0,
  2389. title: '采购终审 — 审批驳回',
  2390. area: ['460px', 'auto'],
  2391. btn: ['确认驳回', '取消'],
  2392. zIndex: procuremenLayerNextZIndex()
  2393. },
  2394. function (idx) {
  2395. Lr.close(idx);
  2396. FastRef.api.ajax({
  2397. url: FastRef.api.fixurl('procuremen/purchaseApprovalReject'),
  2398. type: 'POST',
  2399. data: {
  2400. __token__: $('input[name=\'__token__\']').val() || $wrap.find('input[name=\'__token__\']').val() || '',
  2401. order_picks_json: JSON.stringify(rejectPicks)
  2402. }
  2403. }, function () {
  2404. if (typeof parent !== 'undefined' && parent.Layer) {
  2405. var ix = parent.Layer.getFrameIndex(window.name);
  2406. if (typeof ix !== 'undefined') {
  2407. parent.Layer.close(ix);
  2408. }
  2409. }
  2410. var p$ = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : (typeof parent !== 'undefined' ? parent.$ : null);
  2411. if (p$ && p$('#table').length) {
  2412. p$('#table').bootstrapTable('refresh');
  2413. }
  2414. });
  2415. }
  2416. );
  2417. }
  2418. function onPurchaseCloseClick(e) {
  2419. if (e && typeof e.preventDefault === 'function') {
  2420. e.preventDefault();
  2421. }
  2422. if (typeof parent !== 'undefined' && parent.Layer) {
  2423. var ixClose = parent.Layer.getFrameIndex(window.name);
  2424. if (typeof ixClose !== 'undefined' && ixClose !== null) {
  2425. parent.Layer.close(ixClose);
  2426. return;
  2427. }
  2428. }
  2429. if (typeof Layer !== 'undefined' && typeof Layer.closeAll === 'function') {
  2430. Layer.closeAll();
  2431. }
  2432. }
  2433. function bindOutwardPurchaseFooterButtons() {
  2434. $(document)
  2435. .off('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm')
  2436. .on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm', onPurchaseConfirmClick)
  2437. .off('click.procuremenPurchaseConfirm', '#btn-pod-purchase-reject')
  2438. .on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-reject', onPurchaseRejectClick)
  2439. .off('click.procuremenPurchaseConfirm', '#btn-pod-purchase-close')
  2440. .on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-close', onPurchaseCloseClick);
  2441. $('#btn-pod-purchase-confirm').off('click.procuremenPurchaseConfirmDirect').on('click.procuremenPurchaseConfirmDirect', onPurchaseConfirmClick);
  2442. $('#btn-pod-purchase-reject').off('click.procuremenPurchaseConfirmDirect').on('click.procuremenPurchaseConfirmDirect', onPurchaseRejectClick);
  2443. $('#btn-pod-purchase-close').off('click.procuremenPurchaseConfirmDirect').on('click.procuremenPurchaseConfirmDirect', onPurchaseCloseClick);
  2444. }
  2445. bindOutwardPurchaseFooterButtons();
  2446. setTimeout(bindOutwardPurchaseFooterButtons, 350);
  2447. },
  2448. details: function () {
  2449. Controller.api.bindevent();
  2450. },
  2451. review: function () {
  2452. Controller.api.bindevent();
  2453. procuremenInitSysRqSplit($('#review-sys-rq-wrap'), 'reviewSysRq');
  2454. function procuremenReviewWarn(msg) {
  2455. var shown = false;
  2456. try {
  2457. if (typeof parent !== 'undefined' && parent.Toastr && typeof parent.Toastr.warning === 'function') {
  2458. parent.Toastr.warning(msg);
  2459. shown = true;
  2460. }
  2461. } catch (ignoreParentToast) {
  2462. }
  2463. if (!shown) {
  2464. if (typeof Toastr !== 'undefined') {
  2465. Toastr.warning(msg);
  2466. } else if (typeof Layer !== 'undefined') {
  2467. Layer.msg(msg);
  2468. }
  2469. }
  2470. }
  2471. function procuremenReviewFastRef() {
  2472. if (typeof Fast !== 'undefined' && Fast.api) {
  2473. return Fast;
  2474. }
  2475. if (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api) {
  2476. return parent.Fast;
  2477. }
  2478. return null;
  2479. }
  2480. function procuremenReviewIsPickMode() {
  2481. if (/pickreview/i.test((window.location.pathname || '') + (window.location.search || ''))) {
  2482. return true;
  2483. }
  2484. var $form = $('#review-form');
  2485. var pm = $form.attr('data-pick-mode');
  2486. if (pm === '1') {
  2487. return true;
  2488. }
  2489. pm = $form.data('pickMode');
  2490. if (pm === 1 || pm === '1') {
  2491. return true;
  2492. }
  2493. pm = $form.data('pick-mode');
  2494. return pm === 1 || pm === '1';
  2495. }
  2496. function procuremenReviewCollectSelected() {
  2497. var selected = [];
  2498. var seen = {};
  2499. $('#review-company-tbody .review-company-cb:checked').each(function () {
  2500. var c = $(this).data('company');
  2501. if (!c || typeof c !== 'object') {
  2502. return;
  2503. }
  2504. var k = procuremenReviewCompanyKey(c);
  2505. if (k && seen[k]) {
  2506. return;
  2507. }
  2508. if (k) {
  2509. seen[k] = true;
  2510. }
  2511. selected.push(procuremenReviewCompanyPayload(c));
  2512. });
  2513. return selected;
  2514. }
  2515. function onReviewSubmitClick(e) {
  2516. if (e && typeof e.preventDefault === 'function') {
  2517. e.preventDefault();
  2518. }
  2519. if (e && typeof e.stopPropagation === 'function') {
  2520. e.stopPropagation();
  2521. }
  2522. var $rqWrap = $('#review-sys-rq-wrap');
  2523. $rqWrap.find('.procuremen-sys-rq-date').trigger('change');
  2524. var $rq = $('#review-sys-rq');
  2525. var isPickMode = procuremenReviewIsPickMode();
  2526. var selected = procuremenReviewCollectSelected();
  2527. if (!selected.length) {
  2528. procuremenReviewWarn(isPickMode ? '请至少选择一家合作供应商' : '请至少选择一个下发单位');
  2529. return;
  2530. }
  2531. var sysRq = ($rq.val() || '').trim();
  2532. if (!sysRq) {
  2533. procuremenReviewWarn('请选择截止时间');
  2534. procuremenFocusSysRqSplit($rqWrap);
  2535. return;
  2536. }
  2537. var cons;
  2538. try {
  2539. cons = JSON.parse($('#c-row-json').val() || '{}');
  2540. } catch (ignoreParseRow) {
  2541. cons = {};
  2542. }
  2543. var mergePayload = ($('#c-merge-rows-json').val() || '').trim();
  2544. if (!mergePayload) {
  2545. mergePayload = JSON.stringify([cons]);
  2546. }
  2547. var $submitBtn = $('#btn-review-submit');
  2548. if ($submitBtn.prop('disabled')) {
  2549. return;
  2550. }
  2551. var FastRef = procuremenReviewFastRef();
  2552. if (!FastRef || !FastRef.api) {
  2553. procuremenReviewWarn('页面未就绪,请刷新后重试');
  2554. return;
  2555. }
  2556. var submitBtnHtml = $submitBtn.html();
  2557. $submitBtn.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> 提交中…');
  2558. FastRef.api.ajax({
  2559. url: FastRef.api.fixurl(isPickMode ? 'procuremen/picksubmit' : 'procuremen/review'),
  2560. type: 'POST',
  2561. data: {
  2562. __token__: $('input[name=\'__token__\']').val(),
  2563. row_json: JSON.stringify(cons),
  2564. merge_rows_json: mergePayload,
  2565. companies_json: JSON.stringify(selected),
  2566. sys_rq: sysRq
  2567. }
  2568. }, function (data, ret) {
  2569. var msg = (ret && ret.msg) ? ret.msg : '操作成功';
  2570. try {
  2571. sessionStorage.removeItem('procuremen_merge_rows');
  2572. } catch (ignoreClr) {
  2573. }
  2574. var index = parent.Layer.getFrameIndex(window.name);
  2575. if (typeof parent !== 'undefined' && parent.Layer && index) {
  2576. parent.Layer.close(index);
  2577. }
  2578. if (typeof parent !== 'undefined' && parent.Toastr) {
  2579. parent.Toastr.success(msg);
  2580. } else if (typeof Toastr !== 'undefined') {
  2581. Toastr.success(msg);
  2582. }
  2583. if (parent && parent.$ && parent.$('#table').length) {
  2584. parent.$('#table').bootstrapTable('refresh', {silent: true});
  2585. }
  2586. return false;
  2587. }, function (data, ret) {
  2588. $submitBtn.prop('disabled', false).html(submitBtnHtml);
  2589. var errMsg = (ret && ret.msg) ? ret.msg : '提交失败,请重试';
  2590. procuremenReviewWarn(errMsg);
  2591. return false;
  2592. });
  2593. }
  2594. function bindReviewFooterButtons() {
  2595. $(document)
  2596. .off('click.procuremenReviewSubmit', '#btn-review-submit')
  2597. .on('click.procuremenReviewSubmit', '#btn-review-submit', onReviewSubmitClick);
  2598. $('#btn-review-submit')
  2599. .off('click.procuremenReviewSubmitDirect')
  2600. .on('click.procuremenReviewSubmitDirect', onReviewSubmitClick);
  2601. }
  2602. bindReviewFooterButtons();
  2603. setTimeout(bindReviewFooterButtons, 350);
  2604. function procuremenReviewCloseLayer() {
  2605. try {
  2606. if (typeof parent !== 'undefined' && parent.Layer) {
  2607. var index = parent.Layer.getFrameIndex(window.name);
  2608. if (index) {
  2609. parent.Layer.close(index);
  2610. return;
  2611. }
  2612. }
  2613. } catch (ignoreClose) {
  2614. }
  2615. if (typeof Layer !== 'undefined' && typeof Layer.closeAll === 'function') {
  2616. Layer.closeAll();
  2617. }
  2618. }
  2619. $(document).off('keydown.procuremenReviewEsc').on('keydown.procuremenReviewEsc', function (e) {
  2620. if (e.keyCode !== 27 && e.key !== 'Escape') {
  2621. return;
  2622. }
  2623. procuremenReviewCloseLayer();
  2624. e.preventDefault();
  2625. });
  2626. $('.btn-close').off('click.procuremenReviewClose').on('click.procuremenReviewClose', function (e) {
  2627. e.preventDefault();
  2628. procuremenReviewCloseLayer();
  2629. });
  2630. var isPickReviewEntry = /pickreview/i.test((window.location.pathname || '') + (window.location.search || ''));
  2631. var ids = window.Fast && Fast.api ? Fast.api.query('ids') : null;
  2632. if (ids === null || ids === '') {
  2633. Toastr.error('请刷新页面后重试');
  2634. return;
  2635. }
  2636. var $ptable = $();
  2637. try {
  2638. if (typeof parent !== 'undefined' && parent.$) {
  2639. $ptable = parent.$('#table');
  2640. }
  2641. } catch (ignoreParentTable) {
  2642. $ptable = $();
  2643. }
  2644. if (!$ptable.length && !isPickReviewEntry) {
  2645. Toastr.error('请刷新页面后重试');
  2646. return;
  2647. }
  2648. var pk = 'ID';
  2649. var row = null;
  2650. if ($ptable.length) {
  2651. pk = $ptable.bootstrapTable('getOptions').pk || 'ID';
  2652. $.each($ptable.bootstrapTable('getData'), function (i, r) {
  2653. if (String(r[pk]) === String(ids)) {
  2654. row = r;
  2655. return false;
  2656. }
  2657. });
  2658. }
  2659. var mergeRows = [];
  2660. var mergeFlag = window.Fast && Fast.api ? String(Fast.api.query('merge') || '') : '';
  2661. if (mergeFlag === '1') {
  2662. try {
  2663. var rawMerge = sessionStorage.getItem('procuremen_merge_rows');
  2664. if (rawMerge) {
  2665. var parsed = JSON.parse(rawMerge);
  2666. if ($.isArray(parsed) && parsed.length) {
  2667. mergeRows = parsed;
  2668. }
  2669. }
  2670. } catch (ignoreMerge) {
  2671. }
  2672. }
  2673. if (mergeFlag === '1' && !mergeRows.length && row) {
  2674. mergeRows = [row];
  2675. }
  2676. if (mergeRows.length) {
  2677. row = mergeRows[0];
  2678. } else if (!row) {
  2679. Toastr.error('请刷新页面后重试');
  2680. return;
  2681. }
  2682. function procuremenReviewQtyDisp(r) {
  2683. if (!r) {
  2684. return '';
  2685. }
  2686. if (r.This_quantity != null && String(r.This_quantity).trim() !== '') {
  2687. return String(r.This_quantity).trim();
  2688. }
  2689. if (r.this_quantity != null && String(r.this_quantity).trim() !== '') {
  2690. return String(r.this_quantity).trim();
  2691. }
  2692. if (r.NGZL != null && String(r.NGZL).trim() !== '') {
  2693. return String(r.NGZL).trim();
  2694. }
  2695. if (r.ngzl != null && String(r.ngzl).trim() !== '') {
  2696. return String(r.ngzl).trim();
  2697. }
  2698. return '';
  2699. }
  2700. function procuremenReviewPriceDisp(r) {
  2701. if (!r) {
  2702. return '';
  2703. }
  2704. if (r.ceilingPrice != null && String(r.ceilingPrice).trim() !== '') {
  2705. return String(r.ceilingPrice).trim();
  2706. }
  2707. if (r.ceiling_price != null && String(r.ceiling_price).trim() !== '') {
  2708. return String(r.ceiling_price).trim();
  2709. }
  2710. return '';
  2711. }
  2712. function applyProcuremenMergeReviewUi(rows) {
  2713. var list = $.isArray(rows) && rows.length ? rows : (row ? [row] : []);
  2714. var $tb = $('#review-merge-tbody').empty();
  2715. var orderKey0 = list.length ? String(list[0].CCYDH || '').trim() : '';
  2716. var nameKey0 = list.length ? String(list[0].CYJMC || '').trim() : '';
  2717. var mergeSameOrder = list.length > 1 && orderKey0 !== '';
  2718. if (mergeSameOrder) {
  2719. $.each(list, function (i, rr) {
  2720. if (String(rr.CCYDH || '').trim() !== orderKey0
  2721. || String(rr.CYJMC || '').trim() !== nameKey0) {
  2722. mergeSameOrder = false;
  2723. return false;
  2724. }
  2725. });
  2726. }
  2727. $.each(list, function (idx, r) {
  2728. var qty = procuremenReviewQtyDisp(r);
  2729. var price = procuremenReviewPriceDisp(r);
  2730. var ccydh = String(r.CCYDH != null ? r.CCYDH : '').trim();
  2731. var cyjmc = String(r.CYJMC != null ? r.CYJMC : '').trim();
  2732. var $tr = $('<tr/>');
  2733. if (mergeSameOrder && idx === 0) {
  2734. $tr.append(
  2735. $('<td class="text-center"/>').attr('rowspan', list.length).text(ccydh),
  2736. $('<td/>').attr('rowspan', list.length).text(cyjmc)
  2737. );
  2738. } else if (!mergeSameOrder) {
  2739. $tr.append(
  2740. $('<td class="text-center"/>').text(ccydh),
  2741. $('<td/>').text(cyjmc)
  2742. );
  2743. }
  2744. $tr.append(
  2745. $('<td/>').text(r.CGYMC || ''),
  2746. $('<td class="text-center"/>').text(r.CDW != null && r.CDW !== '' ? r.CDW : ''),
  2747. $('<td class="text-center"/>').text(qty),
  2748. $('<td class="text-center"/>').text(price),
  2749. $('<td class="text-center"/>').text(r.CDF || ''),
  2750. $('<td/>').text(r.MBZ != null && r.MBZ !== '' ? String(r.MBZ) : '')
  2751. );
  2752. $tb.append($tr);
  2753. });
  2754. var isPickModeUi = procuremenReviewIsPickMode();
  2755. if (isPickModeUi && list.length > 1) {
  2756. $('.procuremen-review-submit-tip').html(
  2757. '<i class="fa fa-exclamation-triangle"></i> '
  2758. + '<strong>合并单:</strong>确认后将向所选供应商<strong>发送短信与邮件</strong>;'
  2759. + '本单含 <strong>' + list.length + ' 道工序</strong>,请核对后再确认。'
  2760. );
  2761. }
  2762. $('#c-merge-rows-json').val(JSON.stringify(list));
  2763. }
  2764. applyProcuremenMergeReviewUi(mergeRows.length ? mergeRows : (row ? [row] : []));
  2765. var isPickMode = procuremenReviewIsPickMode();
  2766. $('#c-row-json').val(JSON.stringify(row));
  2767. var reviewCompaniesAll = [];
  2768. var activeReviewCategory = null;
  2769. var reviewCompanySearchQ = '';
  2770. var reviewSelectedMap = {};
  2771. var reviewSearchTimer = null;
  2772. function syncReviewSelectedSummary() {
  2773. var entries = [];
  2774. $.each(reviewSelectedMap, function (k, c) {
  2775. if (!c) {
  2776. return;
  2777. }
  2778. var t = String(c.name || c.company_name || '').trim() || '(无名称)';
  2779. entries.push({ k: k, label: t });
  2780. });
  2781. entries.sort(function (a, b) {
  2782. return a.label.localeCompare(b.label, 'zh-CN');
  2783. });
  2784. var n = entries.length;
  2785. $('#review-selected-count').text(String(n));
  2786. $('#review-selected-tags').empty();
  2787. if (!n) {
  2788. $('#review-selected-empty').show();
  2789. return;
  2790. }
  2791. $('#review-selected-empty').hide();
  2792. $.each(entries, function (i, e) {
  2793. var $chip = $('<span class="review-selected-chip"/>').attr('title', e.label);
  2794. $chip.data('reviewSelKey', e.k);
  2795. $chip.append(
  2796. $('<span class="review-chip-text"/>').text(e.label),
  2797. $('<button type="button" class="review-chip-remove" title="取消选择" aria-label="取消选择"/>').text('\u00d7')
  2798. );
  2799. $('#review-selected-tags').append($chip);
  2800. });
  2801. }
  2802. syncReviewSelectedSummary();
  2803. $('#review-selected-tags').off('click.reviewChipRemove').on('click.reviewChipRemove', '.review-chip-remove', function (e) {
  2804. e.preventDefault();
  2805. e.stopPropagation();
  2806. var k = $(this).closest('.review-selected-chip').data('reviewSelKey');
  2807. if (k == null || k === '') {
  2808. return;
  2809. }
  2810. delete reviewSelectedMap[k];
  2811. $('#review-company-tbody .review-company-cb').each(function () {
  2812. var c = $(this).data('company');
  2813. var kk = procuremenReviewCompanyKey(c);
  2814. if (kk === k) {
  2815. $(this).prop('checked', false);
  2816. }
  2817. });
  2818. var $cbsR = $('#review-company-tbody .review-company-cb');
  2819. var $masterR = $('#review-check-all');
  2820. if (!$cbsR.length) {
  2821. $masterR.prop('checked', false).prop('indeterminate', false);
  2822. } else {
  2823. var nR = $cbsR.filter(':checked').length;
  2824. $masterR.prop('checked', nR === $cbsR.length);
  2825. $masterR.prop('indeterminate', nR > 0 && nR < $cbsR.length);
  2826. }
  2827. syncReviewSelectedSummary();
  2828. });
  2829. $('#review-category-sidebar').off('click.reviewCat').on('click.reviewCat', '.review-cat-item', function () {
  2830. var $t = $(this);
  2831. if ($t.hasClass('review-cat-all')) {
  2832. activeReviewCategory = null;
  2833. } else {
  2834. activeReviewCategory = $t.data('reviewCat');
  2835. }
  2836. $('#review-category-list .review-cat-item').removeClass('active');
  2837. $t.addClass('active');
  2838. var q = reviewCompanySearchQ;
  2839. var searchActive = q.length > 0;
  2840. var list = [];
  2841. $.each(reviewCompaniesAll, function (i, c) {
  2842. if (!c || typeof c !== 'object') {
  2843. return;
  2844. }
  2845. if (!searchActive && activeReviewCategory !== null) {
  2846. var segOk = activeReviewCategory == null || activeReviewCategory === '';
  2847. if (!segOk) {
  2848. var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
  2849. ? String(c.company_type).trim()
  2850. : String(c.category || '').trim();
  2851. var segs = [];
  2852. if (!rawCat) {
  2853. segs = ['未分类'];
  2854. } else {
  2855. var parts = rawCat.split('、');
  2856. var seen = {};
  2857. $.each(parts, function (idx, p) {
  2858. var tt = String(p).trim();
  2859. if (!tt || seen[tt]) {
  2860. return;
  2861. }
  2862. seen[tt] = true;
  2863. segs.push(tt);
  2864. });
  2865. if (!segs.length) {
  2866. segs = ['未分类'];
  2867. }
  2868. }
  2869. if ($.inArray(activeReviewCategory, segs) === -1) {
  2870. return;
  2871. }
  2872. }
  2873. }
  2874. if (q) {
  2875. var blob = [
  2876. c.name, c.company_name, c.username, c.email, c.phone,
  2877. c.company_type, c.category
  2878. ].map(function (x) {
  2879. return x == null ? '' : String(x);
  2880. }).join(' ').toLowerCase();
  2881. if (blob.indexOf(q) === -1) {
  2882. return;
  2883. }
  2884. }
  2885. list.push(c);
  2886. });
  2887. var $tbody = $('#review-company-tbody').empty();
  2888. if (!list.length) {
  2889. $tbody.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
  2890. var $cbs0 = $('#review-company-tbody .review-company-cb');
  2891. var $master0 = $('#review-check-all');
  2892. if (!$cbs0.length) {
  2893. $master0.prop('checked', false).prop('indeterminate', false);
  2894. } else {
  2895. var n0 = $cbs0.filter(':checked').length;
  2896. $master0.prop('checked', n0 === $cbs0.length);
  2897. $master0.prop('indeterminate', n0 > 0 && n0 < $cbs0.length);
  2898. }
  2899. syncReviewSelectedSummary();
  2900. return;
  2901. }
  2902. $.each(list, function (i, c) {
  2903. var $cb = $('<input type="checkbox" class="review-company-cb"/>');
  2904. $cb.data('company', c);
  2905. var k = procuremenReviewCompanyKey(c);
  2906. if (k && reviewSelectedMap[k]) {
  2907. $cb.prop('checked', true);
  2908. }
  2909. var $tr = $('<tr/>');
  2910. $tr.append($('<td class="review-td-cb"/>').append($cb));
  2911. $tr.append($('<td/>').text(c.name || c.company_name || ''));
  2912. $tr.append($('<td/>').text(c.username || ''));
  2913. $tr.append($('<td/>').text(c.email || ''));
  2914. $tr.append($('<td/>').text(c.phone || ''));
  2915. $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
  2916. $tbody.append($tr);
  2917. });
  2918. var $cbs = $('#review-company-tbody .review-company-cb');
  2919. var $master = $('#review-check-all');
  2920. var n = $cbs.filter(':checked').length;
  2921. $master.prop('checked', n === $cbs.length);
  2922. $master.prop('indeterminate', n > 0 && n < $cbs.length);
  2923. syncReviewSelectedSummary();
  2924. });
  2925. $('#review-company-search').off('input.reviewSearch').on('input.reviewSearch', function () {
  2926. var v = ($(this).val() || '').trim().toLowerCase();
  2927. if (reviewSearchTimer) {
  2928. clearTimeout(reviewSearchTimer);
  2929. }
  2930. reviewSearchTimer = setTimeout(function () {
  2931. reviewSearchTimer = null;
  2932. reviewCompanySearchQ = v;
  2933. var q = reviewCompanySearchQ;
  2934. var searchActive = q.length > 0;
  2935. var list = [];
  2936. $.each(reviewCompaniesAll, function (i, c) {
  2937. if (!c || typeof c !== 'object') {
  2938. return;
  2939. }
  2940. if (!searchActive && activeReviewCategory !== null) {
  2941. var segOk2 = activeReviewCategory == null || activeReviewCategory === '';
  2942. if (!segOk2) {
  2943. var rawCat2 = (c.company_type != null && String(c.company_type).trim() !== '')
  2944. ? String(c.company_type).trim()
  2945. : String(c.category || '').trim();
  2946. var segs2 = [];
  2947. if (!rawCat2) {
  2948. segs2 = ['未分类'];
  2949. } else {
  2950. var parts2 = rawCat2.split('、');
  2951. var seen2 = {};
  2952. $.each(parts2, function (idx, p) {
  2953. var tt2 = String(p).trim();
  2954. if (!tt2 || seen2[tt2]) {
  2955. return;
  2956. }
  2957. seen2[tt2] = true;
  2958. segs2.push(tt2);
  2959. });
  2960. if (!segs2.length) {
  2961. segs2 = ['未分类'];
  2962. }
  2963. }
  2964. if ($.inArray(activeReviewCategory, segs2) === -1) {
  2965. return;
  2966. }
  2967. }
  2968. }
  2969. if (q) {
  2970. var blob2 = [
  2971. c.name, c.company_name, c.username, c.email, c.phone,
  2972. c.company_type, c.category
  2973. ].map(function (x) {
  2974. return x == null ? '' : String(x);
  2975. }).join(' ').toLowerCase();
  2976. if (blob2.indexOf(q) === -1) {
  2977. return;
  2978. }
  2979. }
  2980. list.push(c);
  2981. });
  2982. var $tbody2 = $('#review-company-tbody').empty();
  2983. if (!list.length) {
  2984. $tbody2.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
  2985. } else {
  2986. $.each(list, function (i, c) {
  2987. var $cb = $('<input type="checkbox" class="review-company-cb"/>');
  2988. $cb.data('company', c);
  2989. var k2 = procuremenReviewCompanyKey(c);
  2990. if (k2 && reviewSelectedMap[k2]) {
  2991. $cb.prop('checked', true);
  2992. }
  2993. var $tr = $('<tr/>');
  2994. $tr.append($('<td class="review-td-cb"/>').append($cb));
  2995. $tr.append($('<td/>').text(c.name || c.company_name || ''));
  2996. $tr.append($('<td/>').text(c.username || ''));
  2997. $tr.append($('<td/>').text(c.email || ''));
  2998. $tr.append($('<td/>').text(c.phone || ''));
  2999. $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
  3000. $tbody2.append($tr);
  3001. });
  3002. }
  3003. var $cbsS = $('#review-company-tbody .review-company-cb');
  3004. var $masterS = $('#review-check-all');
  3005. if (!$cbsS.length) {
  3006. $masterS.prop('checked', false).prop('indeterminate', false);
  3007. } else {
  3008. var nS = $cbsS.filter(':checked').length;
  3009. $masterS.prop('checked', nS === $cbsS.length);
  3010. $masterS.prop('indeterminate', nS > 0 && nS < $cbsS.length);
  3011. }
  3012. syncReviewSelectedSummary();
  3013. }, 160);
  3014. });
  3015. $('#review-company-tbody').off('change.reviewCb').on('change.reviewCb', '.review-company-cb', function () {
  3016. var c = $(this).data('company');
  3017. var k = procuremenReviewCompanyKey(c);
  3018. var $cbsC = $('#review-company-tbody .review-company-cb');
  3019. var $masterC = $('#review-check-all');
  3020. if (!k) {
  3021. if (!$cbsC.length) {
  3022. $masterC.prop('checked', false).prop('indeterminate', false);
  3023. } else {
  3024. var nC = $cbsC.filter(':checked').length;
  3025. $masterC.prop('checked', nC === $cbsC.length);
  3026. $masterC.prop('indeterminate', nC > 0 && nC < $cbsC.length);
  3027. }
  3028. syncReviewSelectedSummary();
  3029. return;
  3030. }
  3031. if ($(this).prop('checked')) {
  3032. reviewSelectedMap[k] = c;
  3033. } else {
  3034. delete reviewSelectedMap[k];
  3035. }
  3036. var n2 = $cbsC.filter(':checked').length;
  3037. $masterC.prop('checked', n2 === $cbsC.length);
  3038. $masterC.prop('indeterminate', n2 > 0 && n2 < $cbsC.length);
  3039. syncReviewSelectedSummary();
  3040. });
  3041. $('#review-check-all').off('change.reviewAll').on('change.reviewAll', function () {
  3042. var on = $(this).prop('checked');
  3043. $('#review-company-tbody .review-company-cb').each(function () {
  3044. $(this).prop('checked', on).trigger('change');
  3045. });
  3046. });
  3047. /** 加载供应商列表(弹窗内勾选单位) */
  3048. function loadReviewCompaniesPanel() {
  3049. Fast.api.ajax({
  3050. url: 'procuremen/reviewCompanies',
  3051. type: 'GET',
  3052. loading: false
  3053. }, function (data) {
  3054. reviewCompaniesAll = Array.isArray(data) ? data : [];
  3055. reviewSelectedMap = {};
  3056. activeReviewCategory = null;
  3057. reviewCompanySearchQ = '';
  3058. $('#review-company-search').val('');
  3059. var counts = {};
  3060. var total = 0;
  3061. $.each(reviewCompaniesAll, function (i, c) {
  3062. if (!c || typeof c !== 'object') {
  3063. return;
  3064. }
  3065. total++;
  3066. var raw = (c.company_type != null && String(c.company_type).trim() !== '')
  3067. ? String(c.company_type).trim()
  3068. : String(c.category || '').trim();
  3069. var segs = [];
  3070. if (!raw) {
  3071. segs = ['未分类'];
  3072. } else {
  3073. var parts = raw.split('、');
  3074. var seen = {};
  3075. $.each(parts, function (idx, p) {
  3076. var tt = String(p).trim();
  3077. if (!tt || seen[tt]) {
  3078. return;
  3079. }
  3080. seen[tt] = true;
  3081. segs.push(tt);
  3082. });
  3083. if (!segs.length) {
  3084. segs = ['未分类'];
  3085. }
  3086. }
  3087. $.each(segs, function (j, seg) {
  3088. counts[seg] = (counts[seg] || 0) + 1;
  3089. });
  3090. });
  3091. var cats = Object.keys(counts);
  3092. cats.sort(function (a, b) {
  3093. return a.localeCompare(b, 'zh-CN');
  3094. });
  3095. var $list = $('#review-category-list').empty();
  3096. var $all = $('<div class="review-cat-item review-cat-all"/>').append(
  3097. $('<span/>').text('全部 '),
  3098. $('<span class="review-cat-count"/>').text('(' + total + ')')
  3099. );
  3100. $all.toggleClass('active', activeReviewCategory === null);
  3101. $list.append($all);
  3102. $.each(cats, function (i, cat) {
  3103. var $it = $('<div class="review-cat-item"/>').append(
  3104. $('<span/>').text(cat + ' '),
  3105. $('<span class="review-cat-count"/>').text('(' + counts[cat] + ')')
  3106. );
  3107. $it.data('reviewCat', cat);
  3108. $it.toggleClass('active', activeReviewCategory === cat);
  3109. $list.append($it);
  3110. });
  3111. var q = reviewCompanySearchQ;
  3112. var searchActive = q.length > 0;
  3113. var list = [];
  3114. $.each(reviewCompaniesAll, function (i, c) {
  3115. if (!c || typeof c !== 'object') {
  3116. return;
  3117. }
  3118. if (!searchActive && activeReviewCategory !== null) {
  3119. var segOk = activeReviewCategory == null || activeReviewCategory === '';
  3120. if (!segOk) {
  3121. var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
  3122. ? String(c.company_type).trim()
  3123. : String(c.category || '').trim();
  3124. var segsB = [];
  3125. if (!rawCat) {
  3126. segsB = ['未分类'];
  3127. } else {
  3128. var partsB = rawCat.split('、');
  3129. var seenB = {};
  3130. $.each(partsB, function (idx, p) {
  3131. var ttB = String(p).trim();
  3132. if (!ttB || seenB[ttB]) {
  3133. return;
  3134. }
  3135. seenB[ttB] = true;
  3136. segsB.push(ttB);
  3137. });
  3138. if (!segsB.length) {
  3139. segsB = ['未分类'];
  3140. }
  3141. }
  3142. if ($.inArray(activeReviewCategory, segsB) === -1) {
  3143. return;
  3144. }
  3145. }
  3146. }
  3147. if (q) {
  3148. var blob = [
  3149. c.name, c.company_name, c.username, c.email, c.phone,
  3150. c.company_type, c.category
  3151. ].map(function (x) {
  3152. return x == null ? '' : String(x);
  3153. }).join(' ').toLowerCase();
  3154. if (blob.indexOf(q) === -1) {
  3155. return;
  3156. }
  3157. }
  3158. list.push(c);
  3159. });
  3160. var $tbody = $('#review-company-tbody').empty();
  3161. if (!list.length) {
  3162. $tbody.append($('<tr/>').append($('<td colspan="6" class="review-company-empty"/>').text('暂无符合条件的单位')));
  3163. } else {
  3164. $.each(list, function (i, c) {
  3165. var $cb = $('<input type="checkbox" class="review-company-cb"/>');
  3166. $cb.data('company', c);
  3167. var k3 = procuremenReviewCompanyKey(c);
  3168. if (k3 && reviewSelectedMap[k3]) {
  3169. $cb.prop('checked', true);
  3170. }
  3171. var $tr = $('<tr/>');
  3172. $tr.append($('<td class="review-td-cb"/>').append($cb));
  3173. $tr.append($('<td/>').text(c.name || c.company_name || ''));
  3174. $tr.append($('<td/>').text(c.username || ''));
  3175. $tr.append($('<td/>').text(c.email || ''));
  3176. $tr.append($('<td/>').text(c.phone || ''));
  3177. $tr.append($('<td/>').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
  3178. $tbody.append($tr);
  3179. });
  3180. }
  3181. var $cbsF = $('#review-company-tbody .review-company-cb');
  3182. var $masterF = $('#review-check-all');
  3183. if (!$cbsF.length) {
  3184. $masterF.prop('checked', false).prop('indeterminate', false);
  3185. } else {
  3186. var nF = $cbsF.filter(':checked').length;
  3187. $masterF.prop('checked', nF === $cbsF.length);
  3188. $masterF.prop('indeterminate', nF > 0 && nF < $cbsF.length);
  3189. }
  3190. syncReviewSelectedSummary();
  3191. return false;
  3192. });
  3193. }
  3194. /*
  3195. * 协助下发:打开弹窗仅展示供应商,不写 purchase_order(确认下发走 picksubmit)。
  3196. * 非协助模式:仅当列表已填本次数量或最高限价时才 snapshot(草稿)。
  3197. */
  3198. if (isPickMode) {
  3199. loadReviewCompaniesPanel();
  3200. } else if (procuremenReviewQtyDisp(row) !== '' || procuremenReviewPriceDisp(row) !== '') {
  3201. Fast.api.ajax({
  3202. url: 'procuremen/snapshotToProcure',
  3203. type: 'POST',
  3204. data: {
  3205. __token__: $('input[name=\'__token__\']').val(),
  3206. row_json: JSON.stringify(row)
  3207. }
  3208. }, function () {
  3209. loadReviewCompaniesPanel();
  3210. return false;
  3211. });
  3212. } else {
  3213. loadReviewCompaniesPanel();
  3214. }
  3215. },
  3216. pickreview: function () {
  3217. Controller.review();
  3218. },
  3219. pickadd: function () {
  3220. Controller.api.bindevent();
  3221. $(document).off('click.procuremenPickAddClose', '.btn-procuremen-pick-add-close').on('click.procuremenPickAddClose', '.btn-procuremen-pick-add-close', function () {
  3222. var index = parent.Layer.getFrameIndex(window.name);
  3223. parent.Layer.close(index);
  3224. });
  3225. },
  3226. auditissue: function () {
  3227. function auditIssueClose() {
  3228. var index = parent.Layer.getFrameIndex(window.name);
  3229. parent.Layer.close(index);
  3230. }
  3231. function auditIssueSysRq() {
  3232. return ($('#audit-sys-rq').val() || '').trim();
  3233. }
  3234. /** 是否已过报价截止时间(无截止时间时按已到处理,与后端一致) */
  3235. function auditIssueQuoteDeadlineReached() {
  3236. var sysRq = auditIssueSysRq();
  3237. if (!sysRq) {
  3238. return true;
  3239. }
  3240. var normalized = String(sysRq).replace(/T/, ' ').replace(/-/g, '/');
  3241. var ts = Date.parse(normalized);
  3242. if (!ts || isNaN(ts)) {
  3243. return true;
  3244. }
  3245. return Date.now() >= ts;
  3246. }
  3247. function auditIssueValidateSysRq() {
  3248. $('#audit-sys-rq-wrap').find('.procuremen-sys-rq-date').trigger('change');
  3249. var sysRq = auditIssueSysRq();
  3250. if (!sysRq) {
  3251. Toastr.warning('请选择报价截止时间');
  3252. procuremenFocusSysRqSplit($('#audit-sys-rq-wrap'));
  3253. return false;
  3254. }
  3255. return true;
  3256. }
  3257. function auditIssueAjaxData(extra) {
  3258. var data = {
  3259. __token__: $('input[name=\'__token__\']').val(),
  3260. scydgy_id: $('input[name=\'scydgy_id\']').val(),
  3261. sys_rq: auditIssueSysRq()
  3262. };
  3263. if (extra) {
  3264. $.extend(data, extra);
  3265. }
  3266. return data;
  3267. }
  3268. procuremenInitSysRqSplit($('#audit-sys-rq-wrap'), 'auditIssue', {readonly: true});
  3269. function auditIssueBidOpenVerified() {
  3270. return parseInt($('#audit-bid-open-verified').val(), 10) === 1;
  3271. }
  3272. function auditIssueBidOpenSmsResendCd() {
  3273. var cd = 55;
  3274. if (typeof Config !== 'undefined' && Config.mprocSmsResendCd) {
  3275. cd = parseInt(Config.mprocSmsResendCd, 10) || cd;
  3276. }
  3277. return Math.max(30, Math.min(120, cd));
  3278. }
  3279. function auditIssueResetBidOpenSendBtn($btn) {
  3280. if (!$btn || !$btn.length) {
  3281. return;
  3282. }
  3283. var timer = $btn.data('cdTimer');
  3284. if (timer) {
  3285. clearInterval(timer);
  3286. $btn.removeData('cdTimer');
  3287. }
  3288. $btn.data('loading', 0);
  3289. $btn.prop('disabled', false).text('发送验证码');
  3290. }
  3291. function auditIssueStartBidOpenSendCountdown($btn) {
  3292. if (!$btn || !$btn.length) {
  3293. return;
  3294. }
  3295. var timer = $btn.data('cdTimer');
  3296. if (timer) {
  3297. clearInterval(timer);
  3298. $btn.removeData('cdTimer');
  3299. }
  3300. var left = auditIssueBidOpenSmsResendCd();
  3301. $btn.data('loading', 0).prop('disabled', true).text('已发送');
  3302. setTimeout(function () {
  3303. if (!$btn.closest('body').length) {
  3304. return;
  3305. }
  3306. $btn.text(left + '秒后重发');
  3307. timer = setInterval(function () {
  3308. left--;
  3309. if (!$btn.closest('body').length) {
  3310. clearInterval(timer);
  3311. return;
  3312. }
  3313. if (left <= 0) {
  3314. clearInterval(timer);
  3315. $btn.removeData('cdTimer');
  3316. $btn.prop('disabled', false).text('发送验证码');
  3317. return;
  3318. }
  3319. $btn.text(left + '秒后重发');
  3320. }, 1000);
  3321. $btn.data('cdTimer', timer);
  3322. }, 1000);
  3323. }
  3324. function auditIssueOpenBidModal() {
  3325. if (!procuremenCan('bidopenverify') && !procuremenCan('bidopen') && !procuremenCan('auditissue')) {
  3326. Toastr.warning('无开标权限');
  3327. return;
  3328. }
  3329. if (auditIssueBidOpenVerified()) {
  3330. Toastr.info('本单已完成开标验证');
  3331. return;
  3332. }
  3333. if (!auditIssueQuoteDeadlineReached()) {
  3334. Toastr.warning('未到截止时间');
  3335. return;
  3336. }
  3337. var users = [];
  3338. var BID_OPEN_LAST_USERS_KEY = 'xh_procuremen_bid_open_last_users';
  3339. function auditIssueLoadLastBidOpenUsers() {
  3340. try {
  3341. var raw = localStorage.getItem(BID_OPEN_LAST_USERS_KEY);
  3342. if (!raw) {
  3343. return {v1: 0, v2: 0};
  3344. }
  3345. var parsed = JSON.parse(raw);
  3346. return {
  3347. v1: parseInt(parsed && parsed.v1, 10) || 0,
  3348. v2: parseInt(parsed && parsed.v2, 10) || 0
  3349. };
  3350. } catch (e) {
  3351. return {v1: 0, v2: 0};
  3352. }
  3353. }
  3354. function auditIssueSaveLastBidOpenUsers(v1, v2) {
  3355. v1 = parseInt(v1, 10) || 0;
  3356. v2 = parseInt(v2, 10) || 0;
  3357. if (!v1 && !v2) {
  3358. return;
  3359. }
  3360. try {
  3361. localStorage.setItem(BID_OPEN_LAST_USERS_KEY, JSON.stringify({v1: v1, v2: v2}));
  3362. } catch (e) {
  3363. }
  3364. }
  3365. function auditIssueUserExists(uid) {
  3366. uid = parseInt(uid, 10) || 0;
  3367. if (!uid) {
  3368. return false;
  3369. }
  3370. var found = false;
  3371. $.each(users, function (i, u) {
  3372. if ((parseInt(u.id, 10) || 0) === uid) {
  3373. found = true;
  3374. return false;
  3375. }
  3376. });
  3377. return found;
  3378. }
  3379. function auditIssueRenderBidOpenUserOptions(excludeId, selectedId) {
  3380. var opts = '<option value="">请选择</option>';
  3381. $.each(users, function (i, u) {
  3382. var uid = parseInt(u.id, 10) || 0;
  3383. if (!uid) {
  3384. return;
  3385. }
  3386. if (excludeId && uid === parseInt(excludeId, 10)) {
  3387. return;
  3388. }
  3389. var label = (u.nickname || u.username || ('ID' + uid));
  3390. if (u.group_name || u.mobile) {
  3391. label += '(';
  3392. if (u.group_name) {
  3393. label += u.group_name;
  3394. }
  3395. if (u.group_name && u.mobile) {
  3396. label += ' · ';
  3397. }
  3398. if (u.mobile) {
  3399. label += u.mobile;
  3400. }
  3401. label += ')';
  3402. }
  3403. var selected = selectedId && uid === parseInt(selectedId, 10) ? ' selected="selected"' : '';
  3404. opts += '<option value="' + uid + '"' + selected + '>' + $('<div>').text(label).html() + '</option>';
  3405. });
  3406. return opts;
  3407. }
  3408. function auditIssueSyncBidOpenUserSelects(changedSlot) {
  3409. var v1 = parseInt($('#bid-open-user-1').val(), 10) || 0;
  3410. var v2 = parseInt($('#bid-open-user-2').val(), 10) || 0;
  3411. if (v1 && v2 && v1 === v2) {
  3412. if (changedSlot === 1) {
  3413. v2 = 0;
  3414. $('#bid-open-user-2').val('');
  3415. $('#bid-open-code-2').val('');
  3416. } else {
  3417. v1 = 0;
  3418. $('#bid-open-user-1').val('');
  3419. $('#bid-open-code-1').val('');
  3420. }
  3421. }
  3422. $('#bid-open-user-1').html(auditIssueRenderBidOpenUserOptions(v2, v1));
  3423. $('#bid-open-user-2').html(auditIssueRenderBidOpenUserOptions(v1, v2));
  3424. auditIssueSaveLastBidOpenUsers(v1, v2);
  3425. }
  3426. function auditIssueApplyLastBidOpenUsers() {
  3427. var last = auditIssueLoadLastBidOpenUsers();
  3428. var v1 = auditIssueUserExists(last.v1) ? last.v1 : 0;
  3429. var v2 = auditIssueUserExists(last.v2) ? last.v2 : 0;
  3430. if (v1 && v2 && v1 === v2) {
  3431. v2 = 0;
  3432. }
  3433. $('#bid-open-user-1').html(auditIssueRenderBidOpenUserOptions(v2, v1));
  3434. $('#bid-open-user-2').html(auditIssueRenderBidOpenUserOptions(v1, v2));
  3435. }
  3436. var html = [
  3437. '<div class="audit-bid-open-modal">',
  3438. '<p class="bid-open-tip"><i class="fa fa-info-circle"></i> 请选择两名用户,分别发送验证码并填写。验证通过后可查看供应商报价信息。</p>',
  3439. '<div class="bid-open-row bid-open-row-1">',
  3440. '<label>验证人1</label>',
  3441. '<select class="form-control bid-open-user" id="bid-open-user-1"><option value="">请选择</option></select>',
  3442. '<button type="button" class="btn btn-default btn-sm btn-send-code" data-slot="1">发送验证码</button>',
  3443. '<input type="text" class="form-control bid-open-code" id="bid-open-code-1" maxlength="6" placeholder="6位验证码"/>',
  3444. '</div>',
  3445. '<div class="bid-open-row bid-open-row-2">',
  3446. '<label>验证人2</label>',
  3447. '<select class="form-control bid-open-user" id="bid-open-user-2"><option value="">请选择</option></select>',
  3448. '<button type="button" class="btn btn-default btn-sm btn-send-code" data-slot="2">发送验证码</button>',
  3449. '<input type="text" class="form-control bid-open-code" id="bid-open-code-2" maxlength="6" placeholder="6位验证码"/>',
  3450. '</div>',
  3451. '</div>'
  3452. ].join('');
  3453. var layerIdx = Layer.open({
  3454. type: 1,
  3455. title: '开标验证',
  3456. area: ['560px', 'auto'],
  3457. content: html,
  3458. btn: ['提交验证', '取消'],
  3459. yes: function (idx) {
  3460. var v1 = parseInt($('#bid-open-user-1').val(), 10) || 0;
  3461. var v2 = parseInt($('#bid-open-user-2').val(), 10) || 0;
  3462. var c1 = $.trim($('#bid-open-code-1').val());
  3463. var c2 = $.trim($('#bid-open-code-2').val());
  3464. if (!v1 || !v2) {
  3465. Toastr.warning('请选择两位验证人');
  3466. return;
  3467. }
  3468. if (v1 === v2) {
  3469. Toastr.warning('两位验证人不能相同');
  3470. return;
  3471. }
  3472. if (!/^\d{6}$/.test(c1) || !/^\d{6}$/.test(c2)) {
  3473. Toastr.warning('请输入6位短信验证码');
  3474. return;
  3475. }
  3476. Fast.api.ajax({
  3477. url: 'procuremen/bidopenverify',
  3478. type: 'POST',
  3479. data: auditIssueAjaxData({
  3480. verifier1_id: v1,
  3481. verifier2_id: v2,
  3482. code1: c1,
  3483. code2: c2
  3484. })
  3485. }, function (data, ret) {
  3486. auditIssueSaveLastBidOpenUsers(v1, v2);
  3487. Layer.close(idx);
  3488. var msg = (ret && ret.msg) ? ret.msg : '开标验证成功';
  3489. Toastr.success(msg);
  3490. setTimeout(function () {
  3491. window.location.reload();
  3492. }, 400);
  3493. return false;
  3494. });
  3495. }
  3496. });
  3497. Fast.api.ajax({
  3498. url: 'procuremen/bidopenusers',
  3499. type: 'GET',
  3500. data: {scydgy_id: $('input[name=\'scydgy_id\']').val()}
  3501. }, function (data, ret) {
  3502. var payload = (ret && ret.data) ? ret.data : (data || {});
  3503. if (parseInt(payload.verified, 10) === 1) {
  3504. Layer.close(layerIdx);
  3505. Toastr.info('本单已完成开标验证');
  3506. setTimeout(function () {
  3507. window.location.reload();
  3508. }, 400);
  3509. return false;
  3510. }
  3511. users = payload.users || [];
  3512. auditIssueApplyLastBidOpenUsers();
  3513. $(document).off('change.bidOpenUser', '#bid-open-user-1, #bid-open-user-2')
  3514. .on('change.bidOpenUser', '#bid-open-user-1', function () {
  3515. auditIssueResetBidOpenSendBtn($('.btn-send-code[data-slot="1"]'));
  3516. auditIssueSyncBidOpenUserSelects(1);
  3517. })
  3518. .on('change.bidOpenUser', '#bid-open-user-2', function () {
  3519. auditIssueResetBidOpenSendBtn($('.btn-send-code[data-slot="2"]'));
  3520. auditIssueSyncBidOpenUserSelects(2);
  3521. });
  3522. return false;
  3523. });
  3524. $(document).off('click.bidOpenSend', '.btn-send-code').on('click.bidOpenSend', '.btn-send-code', function () {
  3525. var slot = $(this).attr('data-slot');
  3526. var adminId = parseInt($('#bid-open-user-' + slot).val(), 10) || 0;
  3527. if (!adminId) {
  3528. Toastr.warning('请先选择验证人' + slot);
  3529. return;
  3530. }
  3531. var $btn = $(this);
  3532. if ($btn.data('loading') || $btn.prop('disabled')) {
  3533. return;
  3534. }
  3535. $btn.data('loading', 1).prop('disabled', true).text('发送中…');
  3536. Fast.api.ajax({
  3537. url: 'procuremen/bidopensendcode',
  3538. type: 'POST',
  3539. data: auditIssueAjaxData({admin_id: adminId})
  3540. }, function (data, ret) {
  3541. Toastr.success((ret && ret.msg) ? ret.msg : '验证码已发送');
  3542. auditIssueStartBidOpenSendCountdown($btn);
  3543. return false;
  3544. }, function () {
  3545. auditIssueResetBidOpenSendBtn($btn);
  3546. });
  3547. });
  3548. }
  3549. $('#btn-audit-bid-open').off('click.auditBidOpen').on('click.auditBidOpen', function () {
  3550. auditIssueOpenBidModal();
  3551. });
  3552. function auditIssueSelectedCompany() {
  3553. var $checked = $('input[name="audit_quote_pick"]:checked');
  3554. if (!$checked.length) {
  3555. return '';
  3556. }
  3557. return $.trim($checked.val());
  3558. }
  3559. function auditIssuePostResendEmail(companies) {
  3560. if (!companies || !companies.length) {
  3561. Toastr.warning('请选择供应商');
  3562. return;
  3563. }
  3564. if (!auditIssueValidateSysRq()) {
  3565. return;
  3566. }
  3567. var company = companies[0];
  3568. Layer.confirm('向「' + company + '」发送邮件?', {icon: 3, title: '发邮件', btn: ['发送', '取消']}, function (layerIdx) {
  3569. Layer.close(layerIdx);
  3570. Fast.api.ajax({
  3571. url: 'procuremen/auditresendemail',
  3572. type: 'POST',
  3573. data: auditIssueAjaxData({
  3574. companies_json: JSON.stringify([company])
  3575. })
  3576. }, function (data, ret) {
  3577. var msg = (ret && ret.msg) ? ret.msg : '已发送';
  3578. if (typeof parent !== 'undefined' && parent.Toastr) {
  3579. parent.Toastr.success(msg);
  3580. }
  3581. return false;
  3582. });
  3583. });
  3584. }
  3585. function auditIssuePostResendSms(company) {
  3586. if (!company) {
  3587. Toastr.warning('请选择供应商');
  3588. return;
  3589. }
  3590. if (!auditIssueValidateSysRq()) {
  3591. return;
  3592. }
  3593. Layer.confirm('向「' + company + '」发送短信?', {icon: 3, title: '发短信', btn: ['发送', '取消']}, function (layerIdx) {
  3594. Layer.close(layerIdx);
  3595. Fast.api.ajax({
  3596. url: 'procuremen/auditresendsms',
  3597. type: 'POST',
  3598. data: auditIssueAjaxData({
  3599. selected_company: company
  3600. })
  3601. }, function (data, ret) {
  3602. var msg = (ret && ret.msg) ? ret.msg : '已发送';
  3603. if (typeof parent !== 'undefined' && parent.Toastr) {
  3604. parent.Toastr.success(msg);
  3605. }
  3606. return false;
  3607. });
  3608. });
  3609. }
  3610. $('#audit-quote-tbody').off('click.auditQuoteRow', 'tr').on('click.auditQuoteRow', 'tr', function (e) {
  3611. if ($(e.target).closest('input, label, a, button').length) {
  3612. return;
  3613. }
  3614. var $radio = $(this).find('.audit-quote-pick').first();
  3615. if ($radio.length) {
  3616. $radio.prop('checked', true);
  3617. }
  3618. });
  3619. $('#btn-audit-issue-close').off('click.auditClose').on('click.auditClose', function () {
  3620. auditIssueClose();
  3621. });
  3622. $('#btn-audit-issue-submit').off('click.auditIssue').on('click.auditIssue', function () {
  3623. var company = auditIssueSelectedCompany();
  3624. if (!company) {
  3625. Toastr.warning('请选择一家供应商');
  3626. return;
  3627. }
  3628. if (!auditIssueBidOpenVerified()) {
  3629. Toastr.warning('请先完成开标验证后再确认供应商');
  3630. return;
  3631. }
  3632. if (!auditIssueValidateSysRq()) {
  3633. return;
  3634. }
  3635. Layer.confirm(
  3636. '选定供应商「' + company + '」并进入审批<br/><span style="color:#666;">本步不发送短信。</span>',
  3637. {icon: 3, title: '选择供应商', btn: ['确认', '取消']},
  3638. function (layerIdx) {
  3639. Layer.close(layerIdx);
  3640. Fast.api.ajax({
  3641. url: 'procuremen/auditsubmit',
  3642. type: 'POST',
  3643. data: auditIssueAjaxData({
  3644. selected_company: company
  3645. })
  3646. }, function (data, ret) {
  3647. var msg = (ret && ret.msg) ? ret.msg : '操作成功';
  3648. if (typeof parent !== 'undefined' && parent.Toastr) {
  3649. parent.Toastr.success(msg);
  3650. }
  3651. if (parent && parent.$ && parent.$('#table').length) {
  3652. parent.$('#table').bootstrapTable('refresh');
  3653. }
  3654. auditIssueClose();
  3655. return false;
  3656. });
  3657. }
  3658. );
  3659. });
  3660. $('#audit-quote-tbody').off('click.auditRowEmail', '.audit-row-send-email').on('click.auditRowEmail', '.audit-row-send-email', function (e) {
  3661. e.preventDefault();
  3662. e.stopPropagation();
  3663. var company = $.trim($(this).attr('data-company') || '');
  3664. if (!company) {
  3665. return;
  3666. }
  3667. auditIssuePostResendEmail([company]);
  3668. });
  3669. $('#audit-quote-tbody').off('click.auditRowSms', '.audit-row-send-sms').on('click.auditRowSms', '.audit-row-send-sms', function (e) {
  3670. e.preventDefault();
  3671. e.stopPropagation();
  3672. var company = $.trim($(this).attr('data-company') || '');
  3673. if (!company) {
  3674. return;
  3675. }
  3676. auditIssuePostResendSms(company);
  3677. });
  3678. },
  3679. emaillog: function () {
  3680. Table.api.init({
  3681. extend: {
  3682. index_url: 'procuremen/emaillog' + location.search,
  3683. table: 'purchase_email_send_log',
  3684. }
  3685. });
  3686. var table = $("#table");
  3687. var colCenter = {align: 'center', valign: 'middle'};
  3688. table.bootstrapTable({
  3689. url: $.fn.bootstrapTable.defaults.extend.index_url,
  3690. pk: 'id',
  3691. sortName: 'id',
  3692. sortOrder: 'desc',
  3693. commonSearch: true,
  3694. columns: [
  3695. [
  3696. $.extend({field: 'id', title: __('Id'), width: 60, operate: false}, colCenter),
  3697. $.extend({field: 'ccydh', title: '订单号', operate: 'LIKE'}, colCenter),
  3698. $.extend({field: 'from_email', title: '发件邮箱', operate: 'LIKE', formatter: function (v, row) {
  3699. return row.from_email_masked || v || '';
  3700. }}, colCenter),
  3701. $.extend({field: 'to_email', title: '供应商邮箱', operate: 'LIKE', formatter: function (v, row) {
  3702. return row.to_email_masked || v || '';
  3703. }}, colCenter),
  3704. $.extend({field: 'company_name', title: '供应商', operate: 'LIKE'}, colCenter),
  3705. $.extend({field: 'scene', title: '场景', operate: '=', searchList: {'pick_issue': '初选下发', 'audit_resend': '确认页重发'}, formatter: function (v, row) {
  3706. return row.scene_text || v || '';
  3707. }}, colCenter),
  3708. $.extend({field: 'mail_subject', title: '邮件主题', operate: 'LIKE', class: 'autocontent', formatter: Table.api.formatter.content}, colCenter),
  3709. $.extend({field: 'status', title: '状态', operate: '=', searchList: {'1': '成功', '0': '失败'}, formatter: function (v, row) {
  3710. var t = row.status_text || (String(v) === '1' ? '成功' : '失败');
  3711. return String(v) === '1' || v === 1
  3712. ? '<span class="text-success">' + t + '</span>'
  3713. : '<span class="text-danger">' + t + '</span>';
  3714. }}, colCenter),
  3715. $.extend({field: 'admin_name', title: '操作人', operate: 'LIKE'}, colCenter),
  3716. $.extend({field: 'send_time', title: '操作时间', operate: 'RANGE', addclass: 'datetimerange', sortable: true}, colCenter),
  3717. $.extend({field: 'fail_reason', title: '失败原因', operate: false, class: 'autocontent', formatter: Table.api.formatter.content}, colCenter)
  3718. ]
  3719. ]
  3720. });
  3721. Table.api.bindevent(table);
  3722. },
  3723. api: {
  3724. bindevent: function () {
  3725. Form.api.bindevent($('form[role=form]'));
  3726. }
  3727. }
  3728. };
  3729. return Controller;
  3730. });