stage.js 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  32. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  33. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  34. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  35. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  36. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  37. { title: '本期批注', fields: ['postil'], visible: true },
  38. { title: '图册号', fields: ['drawing_code'], visible: true },
  39. { title: '备注', fields: ['memo'], visible: true },
  40. { title: '总额计量', fields: ['is_tp'], visible: true},
  41. ];
  42. if (!checkTzMeasureType()) {
  43. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  44. }
  45. const settingStr = Cookies.get(ckColSetting);
  46. if (settingStr) {
  47. const customSetting = JSON.parse(settingStr);
  48. for (const ds of defaultSetting) {
  49. const cs = customSetting.find(x => {return x.title === ds.title});
  50. if (cs) ds.visible = cs.visible;
  51. }
  52. }
  53. return defaultSetting;
  54. }
  55. /**
  56. * 根据列显示设置,调整setting中的列是否显示
  57. * @param setting
  58. * @param customDisplay
  59. */
  60. function customizeStageTreeSetting(setting, customDisplay) {
  61. for (const cd of customDisplay) {
  62. for (const c of setting.cols) {
  63. if (cd.fields.indexOf(c.field) !== -1) {
  64. c.visible = cd.visible;
  65. }
  66. }
  67. }
  68. }
  69. /**
  70. * 初始化 树结构 列事件
  71. * @param setting
  72. */
  73. function initTreeColSettingEvents(setting) {
  74. const Events = {
  75. readOnly: {
  76. measureData: function (node) {
  77. return node.children && node.children.length > 0;
  78. },
  79. },
  80. };
  81. const getEvent = function (eventName) {
  82. const names = eventName.split('.');
  83. let event = Events;
  84. for (let name of names) {
  85. if (event[name]) {
  86. event = event[name];
  87. } else {
  88. return null;
  89. }
  90. }
  91. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  92. return null;
  93. } else {
  94. return event;
  95. }
  96. };
  97. for (const col of setting.cols) {
  98. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  99. col.readOnly = getEvent(col.readOnly);
  100. }
  101. }
  102. }
  103. // 生成所有附件列表
  104. function getAllList(currPageNum = 1) {
  105. // 每页最多几个附件
  106. const pageCount = 15;
  107. // 附件总数
  108. const total = attData.length;
  109. // 总页数
  110. const pageNum = Math.ceil(total/pageCount);
  111. $('#totalPage').text(pageNum);
  112. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  113. // 当前页附件内容
  114. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  115. let html = '';
  116. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  117. for(const att of currPageAttData) {
  118. html += `<tr>
  119. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  120. <td>
  121. <div class="d-flex">
  122. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  123. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  124. </div>
  125. </td><td>${att.username}</td></tr>`
  126. }
  127. $('#alllist-table').html(html);
  128. $('#alllist-table').on('click', 'tr', function() {
  129. $('#alllist-table tr').removeClass('bg-light')
  130. $(this).addClass('bg-light')
  131. })
  132. }
  133. // 生成当前节点列表
  134. function getNodeList(node) {
  135. let html = '';
  136. for(const att of attData) {
  137. if (node === att.lid) {
  138. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  139. html += `<tr>
  140. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  141. <td>
  142. <div class="d-flex">
  143. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  144. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  145. </div>
  146. </td><td>${att.username}</td></tr>`
  147. }
  148. }
  149. $('#nodelist-table').html(html);
  150. $('#nodelist-table').on('click', 'tr', function() {
  151. $('#nodelist-table tr').removeClass('bg-light')
  152. $(this).addClass('bg-light')
  153. })
  154. }
  155. function getGxbyText(data) {
  156. const def = thirdParty.gxby.find(function (x) {
  157. return x.value === data.gxby_status;
  158. });
  159. return def ? def.name : '';
  160. }
  161. function getDaglText(data) {
  162. const def = thirdParty.dagl.find(function (x) {
  163. return x.value === data.dagl_status;
  164. });
  165. return def ? def.name : '';
  166. }
  167. function getHintMsg () {
  168. return {
  169. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  170. disableChange: {type: 'error', msg: '不可修改此数据'},
  171. }
  172. }
  173. $(document).ready(() => {
  174. const exportExcelSetting = {
  175. cols: [
  176. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  177. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  178. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  179. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  180. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  181. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  182. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  183. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  184. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  185. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  186. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  187. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  188. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  189. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  190. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  191. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  192. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  193. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  194. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  196. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, type: 'Number'},
  197. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  198. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  199. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  200. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  201. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  202. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  203. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  204. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  205. ],
  206. headRows: 2,
  207. headRowHeight: [25, 25],
  208. defaultRowHeight: 21,
  209. headerFont: 'bold 10px 微软雅黑',
  210. font: '10px 微软雅黑'
  211. };
  212. let detail, searchLedger, checkedChanges;
  213. const checkOption = {
  214. sibling: { enable: 0 },
  215. empty_code: { enable: 0 },
  216. calc: {
  217. enable: 1,
  218. fields: ['contract_qty', 'qc_qty'],
  219. },
  220. zero: { enable: 0 },
  221. tp: {
  222. enable: 1,
  223. fields: [
  224. {qty: 'contract_qty', tp: 'contract_tp'},
  225. {qty: 'qc_qty', tp: 'qc_tp'},
  226. ],
  227. filter: function (node) {
  228. return node.is_tp;
  229. }
  230. },
  231. over: {
  232. enable: 1, isTz: checkTzMeasureType(),
  233. },
  234. limit3f: {
  235. enable: 1, checkType: [],
  236. }
  237. };
  238. if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
  239. if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
  240. // 界面布局
  241. autoFlashHeight();
  242. // 初始化 台账树结构 数据结构
  243. removeLocalCache('bills-fold');
  244. const stageTreeSetting = {
  245. id: 'ledger_id',
  246. pid: 'ledger_pid',
  247. order: 'order',
  248. level: 'level',
  249. rootId: -1,
  250. keys: ['id', 'tender_id', 'ledger_id'],
  251. stageId: 'id',
  252. autoExpand: 3,
  253. // markFoldKey: 'bills-fold',
  254. // markFoldSubKey: window.location.pathname.split('/')[2],
  255. markExpandKey: 'stage-bills-expand',
  256. markExpandSubKey: window.location.pathname.split('/')[2],
  257. };
  258. // 台账树结构计算相关设置
  259. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
  260. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  261. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'];
  262. stageTreeSetting.calcFun = function (node) {
  263. if (!node.children || node.children.length === 0) {
  264. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  265. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  266. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  267. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  268. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  269. }
  270. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  271. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  272. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  273. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  274. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  275. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  276. if (!node.children || node.children.length === 0) {
  277. if (node.end_contract_qty) {
  278. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  279. } else {
  280. node.end_correct_tp = node.end_gather_tp;
  281. }
  282. }
  283. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  284. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  285. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  286. };
  287. const stageTree = createNewPathTree('stage', stageTreeSetting);
  288. // 初始化 计量单元 数据结构
  289. const stagePosSetting = {
  290. id: 'id', ledgerId: 'lid',
  291. updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr'],
  292. };
  293. stagePosSetting.calcFun = function (pos) {
  294. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  295. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  296. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  297. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  298. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  299. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  300. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  301. pos.estimate_qty = !checkZero(pos.real_qty)
  302. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  303. : null;
  304. };
  305. const stagePos = new StagePosData(stagePosSetting);
  306. const setCooperationSelectHtml = function () {
  307. const selectHtml = [];
  308. selectHtml.push('<option>全部</option>');
  309. const cooName = _.uniqWith(_.map(stageTree.pwd, 'company'));
  310. for (const i of cooName) {
  311. selectHtml.push('<option>', i, '</option>');
  312. }
  313. $('#cooperationSelect').html(selectHtml.join(''));
  314. };
  315. const reloadCooperationHtml = function () {
  316. const html = [];
  317. const select = $('#cooperationSelect').val();
  318. const list = select !== '全部' ? _.filter(stageTree.pwd, { company: select }) : stageTree.pwd;
  319. for (const p of list) {
  320. if (!p.node) continue;
  321. if (p.confirm) {
  322. html.push(`<tr class="text-success">`);
  323. } else {
  324. html.push(`<tr>`);
  325. }
  326. html.push(`<td>${p.node.code}</td>`, `<td>${p.node.name}</td>`);
  327. if(coopwd) {
  328. html.push('<td>', p.check ? `已解锁:${p.pwd}` : `<a name="ledger-unlock" lid="${p.ledger_id}" href="javascript: void(0);">解锁</a>`, '</td>');
  329. }
  330. html.push('<td>', p.company, '</td>');
  331. html.push('<td>', p.check ? (p.confirm ? (moment(p.confirm_time).format('YYYY-MM-DD HH:mm') + ' ' + (coopwd ? `<a name="ledger-unconfirm" href="javascript: void(0);" lid="${p.ledger_id}">重新审批</a>` : '')) : `<a name="ledger-confirm" href="javascript: void(0);" lid="${p.ledger_id}" class="btn btn-sm btn-success">确认</a>`) : '' ,'</td>');
  332. html.push('</tr>');
  333. }
  334. $('#cooperationList').html(html.join(''));
  335. };
  336. class Changes {
  337. constructor(obj) {
  338. const self = this;
  339. this.obj = obj;
  340. // 初始化 清单编号窗口 参数
  341. this.spreadSetting = {
  342. cols: [
  343. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  344. if (data.uamount && !checkZero(data.uamount)) {
  345. return $('#icon-ok')[0];
  346. } else {
  347. return null;
  348. }
  349. }},
  350. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  351. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  352. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  353. //{title: '总数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  354. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  355. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  356. ],
  357. emptyRows: 0,
  358. headRows: 1,
  359. headRowHeight: [32],
  360. headerFont: '12px 微软雅黑',
  361. font: '12px 微软雅黑',
  362. getColor: function (sheet, data, row, col, defaultColor) {
  363. if (col.field === 'uamount') {
  364. if (data.bamount > 0) {
  365. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  366. return usedAmount < 0 || usedAmount > data.bamount ? '#ff6f5c' : defaultColor;
  367. } else if (data.bamount < 0) {
  368. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  369. return usedAmount > 0 || usedAmount < data.bamount ? '#ff6f5c' : defaultColor;
  370. } else {
  371. return data.uamount ? '#ff6f5c' : defaultColor;
  372. }
  373. } else {
  374. return defaultColor;
  375. }
  376. }
  377. };
  378. this.curChangeId = '';
  379. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  380. this.firstView = true;
  381. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  382. // 初次显示,需刷新spread界面,保证界面绘制正确
  383. this.obj.bind('shown.bs.modal', function () {
  384. if (self.firstView) {
  385. self.firstView = false;
  386. self.spread.refresh();
  387. }
  388. });
  389. // 切换变更令,加载右侧明细数据
  390. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  391. const change = SpreadJsObj.getSelectObject(info.sheet);
  392. if(change) {
  393. self._loadChangeDetail(change);
  394. }
  395. });
  396. // 填写本期计量
  397. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  398. if (info.sheet.zh_setting) {
  399. const col = info.sheet.zh_setting.cols[info.col];
  400. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  401. const node = sortData[info.row];
  402. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  403. // 刷新界面
  404. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  405. }
  406. });
  407. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  408. if (info.sheet.zh_setting) {
  409. const sortData = SpreadJsObj.getSortData(info.sheet);
  410. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  411. const curRow = iRow + info.cellRange.row;
  412. const curCol = info.cellRange.col;
  413. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  414. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  415. }
  416. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  417. }
  418. });
  419. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  420. if (sheet.zh_setting) {
  421. const sel = sheet.getSelections()[0];
  422. const sortData = SpreadJsObj.getSortData(sheet);
  423. // 仅本期计量可删除
  424. if (sel.col === 5 && sel.colCount === 1) {
  425. const col = sheet.zh_setting.cols[sel.col];
  426. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  427. const data = sortData[iRow];
  428. data[col.field] = null;
  429. }
  430. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  431. }
  432. }
  433. });
  434. // 过滤可变更数量为0
  435. $('#filterEmpty').click(function () {
  436. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  437. });
  438. // 匹配编号
  439. $('#matchPos').click(function () {
  440. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  441. });
  442. // 展开收起 变更令详细信息
  443. $('#show-bgl-detail').bind('click', function () {
  444. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  445. if (detail.hasClass('col-4')) {
  446. detail.attr('class', 'col').hide();
  447. bgl.attr('class', 'col-12');
  448. $('a', obj).attr('title', '展开侧栏');
  449. $('i', obj).attr('class', 'fa fa-chevron-left');
  450. self.spread.refresh();
  451. } else {
  452. detail.attr('class', 'col-4').show();
  453. bgl.attr('class', 'col-8');
  454. $('a', obj).attr('title', '收起侧栏');
  455. $('i', obj).attr('class', 'fa fa-chevron-right');
  456. self.spread.refresh();
  457. }
  458. });
  459. // 添加调用变更令
  460. $('#usg-bg-ok').click(function () {
  461. const data = { target: self.callData, change: [] };
  462. for (const c of self.displayChanges) {
  463. if (c.uamount) {
  464. if (c.bamount > 0) {
  465. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  466. if (usedAmount < 0 || usedAmount > c.bamount) {
  467. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  468. return;
  469. }
  470. } else if (c.bamount < 0) {
  471. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  472. if (usedAmount > 0 || usedAmount < c.bamount) {
  473. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  474. return;
  475. }
  476. } else {
  477. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  478. return;
  479. }
  480. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  481. }
  482. }
  483. // 提交数据到后端
  484. postData(window.location.pathname + '/use-change', data, function(result) {
  485. if (result.pos) {
  486. stagePos.loadCurStageData(result.pos.curStageData);
  487. }
  488. const nodes = stageTree.loadPostStageData(result.bills);
  489. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  490. stagePosSpreadObj.loadCurPosData();
  491. if (detail) {
  492. detail.loadStageChangeUpdateData(result, nodes);
  493. } else {
  494. stageIm.loadUpdateChangeData(result, nodes)
  495. }
  496. self.obj.modal('hide');
  497. });
  498. })
  499. }
  500. _calculateAmount() {
  501. for (const c of this.changes) {
  502. c.bamount = _.toNumber(c.b_amount);
  503. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  504. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  505. if (uc) {
  506. c.org_uamount = uc.qty;
  507. c.uamount = uc.qty;
  508. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  509. }
  510. c.pre_amount = ZhCalc.sub(c.used_amount, c.uamount);
  511. }
  512. }
  513. _loadChangeDetail(change) {
  514. if (change) {
  515. if (change.cid === this.curChangeId) { return; }
  516. this.curChangeId = change.cid;
  517. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  518. for (const i of inputs) {
  519. const field = $(i).attr('name');
  520. const text = (field && change[field]) ? change[field] : '';
  521. $(i).val(text);
  522. }
  523. const textareas = $('textarea', this.obj);
  524. for (const ta of textareas) {
  525. const field = $(ta).attr('name');
  526. const text = (field && change[field]) ? change[field].replace(/<br><br>/g, '\r\n') : '';
  527. ta.textContent = text;
  528. }
  529. const html = [];
  530. for (const a of change.attachments) {
  531. html.push('<tr>');
  532. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  533. html.push('<td>', a.u_name, '</td>');
  534. html.push('</tr>');
  535. }
  536. // 变更类型
  537. if (change.type) {
  538. const cType = change.type.split(',');
  539. $('input[name="type"]').prop("checked", false);
  540. for (const c of cType) {
  541. $('input[name="type"][value='+ c +']').prop("checked", true);
  542. }
  543. }
  544. // 变更类别
  545. $('select[name=class]').val(change.class);
  546. // 变更性质
  547. $('select[name=quality]').val(change.quality);
  548. // 变更单位
  549. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  550. // 费用承担方
  551. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  552. // 附件
  553. $('#attachment').html(html.join(''));
  554. } else {
  555. const inputs = $('input', this.obj);
  556. for (const i of inputs) {
  557. $(i).val('');
  558. }
  559. const textareas = $('textarea', this.obj);
  560. for (const ta of textareas) {
  561. ta.innerText = '';
  562. }
  563. $('#attachment').html('');
  564. }
  565. }
  566. _viewChanges() {
  567. const sheet = this.spread.getActiveSheet();
  568. if (this.changes) {
  569. sheet.setSelection(0, 0, 1, 1);
  570. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  571. this._loadChangeDetail(this.changes[0]);
  572. } else {
  573. toastr.error('查询变更令有误,请刷新页面后重试');
  574. }
  575. }
  576. _filterChange(filterEmpty, matchPosName) {
  577. this.displayChanges = [];
  578. for (const c of this.changes) {
  579. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  580. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  581. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  582. this.displayChanges.push(c);
  583. }
  584. }
  585. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  586. }
  587. loadChanges(data) {
  588. this.callData = data;
  589. if (this.callData.pos) {
  590. $('#matchPos').parent().show();
  591. } else {
  592. $('#matchPos').parent().hide();
  593. }
  594. const self = this;
  595. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  596. postData(window.location.pathname + '/valid-change', data, function (result) {
  597. self.changes = result.changes;
  598. self.useChanges = result.useChanges;
  599. self._calculateAmount();
  600. self._viewChanges();
  601. self.obj.modal('show');
  602. });
  603. }
  604. }
  605. const changesObj = new Changes($('#use-bg'));
  606. // 初始化 台账 spread
  607. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  608. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  609. // 数量变更列,添加按钮
  610. const qcCol = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  611. qcCol.readOnly = true;
  612. qcCol.cellType = 'activeImageBtn';
  613. qcCol.normalImg = '#ellipsis-icon';
  614. qcCol.indent = 5;
  615. qcCol.showImage = function (data) {
  616. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  617. return false;
  618. } else {
  619. const nodePos = stagePos.getLedgerPos(data.id);
  620. return !(nodePos && nodePos.length > 0);
  621. }
  622. };
  623. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  624. ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  625. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  626. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  627. if (col.field === 'dagl') {
  628. data.dagl_url && window.open(data.dagl_url);
  629. } else if (col.field === 'qc_qty') {
  630. if (data.children && data.children.length > 0 || data.lock) return;
  631. const nodePos = stagePos.getLedgerPos(data.id);
  632. if (nodePos && nodePos.length > 0) return;
  633. changesObj.loadChanges({bills: data});
  634. }
  635. };
  636. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  637. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  638. if (data) {
  639. if (col.field === 'gxby') {
  640. const def = thirdParty.gxby.find(function (x) {
  641. return x.value === data.gxby_status;
  642. });
  643. if (def && def.color) return def.color;
  644. } else if (col.field === 'dagl') {
  645. const def = thirdParty.dagl.find(function (x) {
  646. return x.value === data.dagl_status;
  647. });
  648. if (def && def.color) return def.color;
  649. }
  650. return checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? '#f8d7da' : defaultColor;
  651. } else {
  652. return defaultColor;
  653. }
  654. };
  655. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  656. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  657. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['dagl'], 'getValue', getDaglText);
  658. const lDaglCol = _.find(ledgerSpreadSetting.cols, {field: 'dagl'});
  659. if (lDaglCol) {
  660. lDaglCol.getValue = getDaglText;
  661. lDaglCol.cellType = 'activeImageBtn';
  662. lDaglCol.normalImg = '#rela-file-icon';
  663. lDaglCol.indent = 5;
  664. lDaglCol.imgAlign = 2;
  665. lDaglCol.showImage = function (data) { return data && data.dagl_url; }
  666. }
  667. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  668. ledgerSpreadSetting.headColWidth = [50];
  669. ledgerSpreadSetting.rowHeader = [
  670. {
  671. rowHeaderType: 'tag',
  672. setting: {
  673. indent: 14,
  674. tagSize: 0.8,
  675. tagFont: '8px 微软雅黑',
  676. getColor: function (index, data) {
  677. if (!data) return;
  678. return billsTag.getBillsTagsColor(data.id);
  679. },
  680. getTagHtml: function (index, data) {
  681. if (!data) return;
  682. const getHtml = function (list) {
  683. if (!list || list.length === 0) return '';
  684. const html = [];
  685. for (const l of list) {
  686. html.push('<div class="row mr-1">');
  687. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  688. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  689. html.push('</div>');
  690. }
  691. return html.join('');
  692. };
  693. return getHtml(billsTag.getBillsTagsInfo(data.id));
  694. }
  695. },
  696. },
  697. ];
  698. ledgerSpreadSetting.readOnly = function (data) {
  699. if (!data) return false;
  700. return data.lock || false;
  701. };
  702. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  703. slSpread.getActiveSheet().frozenColumnCount(5);
  704. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  705. //初始化所有附件列表
  706. getAllList();
  707. // 初始化 计量单元 Spread
  708. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  709. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  710. spCol.readOnly = true;
  711. spCol.cellType = 'activeImageBtn';
  712. spCol.normalImg = '#ellipsis-icon';
  713. spCol.indent = 5;
  714. spCol.showImage = function (data) {
  715. return data !== undefined && data !== null;
  716. };
  717. posSpreadSetting.imageClick = function (data, hitinfo) {
  718. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  719. if (col.field === 'dagl') {
  720. data.dagl_url && window.open(data.dagl_url);
  721. } else if (col.field === 'qc_qty') {
  722. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  723. if (node.lock) return;
  724. changesObj.loadChanges({bills: node, pos: data});
  725. }
  726. };
  727. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  728. if (data) {
  729. if (col.field === 'gxby') {
  730. const def = thirdParty.gxby.find(function (x) {
  731. return x.value === data.gxby_status;
  732. });
  733. if (def && def.color) return def.color;
  734. } else if (col.field === 'dagl') {
  735. const def = thirdParty.dagl.find(function (x) {
  736. return x.value === data.dagl_status;
  737. });
  738. if (def && def.color) return def.color;
  739. }
  740. }
  741. if (checkTzMeasureType()) {
  742. return checkUtils.posOver(data) ? '#f8d7da' : defaultColor;
  743. }
  744. };
  745. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  746. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  747. sjsSettingObj.setPropValue(posSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  748. sjsSettingObj.setPropValue(posSpreadSetting, ['dagl'], 'getValue', getDaglText);
  749. const pDaglCol = _.find(posSpreadSetting.cols, {field: 'dagl'});
  750. if (pDaglCol) {
  751. pDaglCol.getValue = getDaglText;
  752. pDaglCol.cellType = 'activeImageBtn';
  753. pDaglCol.normalImg = '#rela-file-icon';
  754. pDaglCol.indent = 5;
  755. pDaglCol.imgAlign = 2;
  756. pDaglCol.showImage = function (data) { return data && data.dagl_url; }
  757. }
  758. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  759. const billsTag = $.billsTag({
  760. selector: '#bills-tag',
  761. relaSpread: slSpread,
  762. updateUrl: window.location.pathname + '/tag',
  763. afterModify: function (nodes) {
  764. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  765. },
  766. afterLocated: function () {
  767. stagePosSpreadObj.loadCurPosData();
  768. },
  769. afterShow: function () {
  770. slSpread.refresh();
  771. if (spSpread) spSpread.refresh();
  772. },
  773. });
  774. const errorList = $.cs_errorList({
  775. tabSelector: '#error-list-tab',
  776. selector: '#error-list',
  777. relaSpread: slSpread,
  778. storeKey: 'stage-error-' + stage.id,
  779. afterLocated: function () {
  780. stagePosSpreadObj.loadCurPosData();
  781. },
  782. afterShow: function () {
  783. slSpread.refresh();
  784. if (spSpread) spSpread.refresh();
  785. },
  786. });
  787. const checkList = $.ledger_checkList({
  788. id: 'check-list',
  789. tabSelector: '#check-list-tab',
  790. selector: '#check-list',
  791. relaSpread: slSpread,
  792. storeKey: 'stage-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  793. checkType: getCheckType(checkOption),
  794. afterLocated: function () {
  795. stagePosSpreadObj.loadCurPosData();
  796. },
  797. afterShow: function () {
  798. slSpread.refresh();
  799. if (spSpread) spSpread.refresh();
  800. },
  801. });
  802. const stageTreeSpreadObj = {
  803. loadExprToInput(sheet) {
  804. const sel = sheet.getSelections()[0];
  805. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  806. if (col.type === 'Number') {
  807. const data = SpreadJsObj.getSelectObject(sheet);
  808. if (!data) {
  809. $('#bills-expr').val('').attr('readOnly', true);
  810. $('#bills-expr').removeAttr('data-row');
  811. return;
  812. }
  813. const nodePos = stagePos.getLedgerPos(data.id);
  814. if (nodePos && nodePos.length > 0) {
  815. $('#bills-expr').val('').attr('readOnly', true);
  816. } else {
  817. const exprInfo = getExprInfo(col.field);
  818. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  819. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  820. if (col.field.indexOf('tp') >= 0) {
  821. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  822. } else {
  823. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  824. }
  825. }
  826. $('#bills-expr').attr('data-row', sel.row);
  827. } else {
  828. $('#bills-expr').val('').attr('readOnly', true);
  829. $('#bills-expr').removeAttr('data-row');
  830. }
  831. },
  832. refreshTreeNodes: function (sheet, nodes) {
  833. const tree = sheet.zh_tree;
  834. if (!tree) { return }
  835. const rows = [];
  836. for (const node of nodes) {
  837. rows.push(tree.nodes.indexOf(node));
  838. }
  839. SpreadJsObj.reLoadRowsData(sheet, rows);
  840. },
  841. editEnded: function (e, info) {
  842. if (info.sheet.zh_setting) {
  843. const col = info.sheet.zh_setting.cols[info.col];
  844. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  845. const node = sortData[info.row], updateData = {};
  846. const orgValue = node[col.field];
  847. let newValue = trimInvalidChar(info.editingText);
  848. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  849. return;
  850. }
  851. if (col.type === 'Number' && newValue && newValue !== '') {
  852. const num = _.toNumber(newValue);
  853. if (_.isFinite(num)) {
  854. newValue = num;
  855. } else {
  856. try {
  857. newValue = math.evaluate(transExpr(newValue));
  858. } catch(err) {
  859. toastr.error('输入的表达式非法');
  860. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  861. return;
  862. }
  863. }
  864. }
  865. if (col.field.indexOf('_dgn_') > 0) {
  866. if (node.b_code && node.b_code !== '') {
  867. toastr.error('仅项目节可输入项目节数量');
  868. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  869. return;
  870. }
  871. } else if (col.field !== 'postil' && col.field !== 'memo') {
  872. if (node.children && node.children.length > 0) {
  873. toastr.error('清单父项不可计量');
  874. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  875. return;
  876. } else {
  877. const nodePos = stagePos.getLedgerPos(node.id);
  878. if (nodePos && nodePos.length > 0) {
  879. toastr.error('该清单有计量单元,请在计量单元处计量');
  880. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  881. return;
  882. }
  883. }
  884. }
  885. if (col.field === 'memo') {
  886. updateData.main = {
  887. id: node.id
  888. };
  889. updateData.main[col.field] = newValue;
  890. } else if (col.field.indexOf('_dgn_') > 0) {
  891. updateData.dgn = {
  892. id: node.id
  893. };
  894. updateData.dgn[col.field] = newValue;
  895. } else if (col.field !== 'is_tp') {
  896. updateData.stage = {
  897. lid: node.id
  898. };
  899. updateData.stage[col.field] = newValue;
  900. const exprInfo = getExprInfo(col.field);
  901. if (exprInfo) {
  902. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  903. }
  904. }
  905. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  906. // tag update
  907. const nodes = stageTree.loadPostStageData(data);
  908. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  909. if (detail) {
  910. detail.loadStageLedgerUpdateData(data, nodes);
  911. } else {
  912. stageIm.loadUpdateLedgerData(data, nodes);
  913. }
  914. }, function () {
  915. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  916. });
  917. }
  918. },
  919. selectionChanged: function (e, info) {
  920. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  921. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  922. stagePosSpreadObj.loadCurPosData();
  923. if (posSearch) {
  924. posSearch.search();
  925. }
  926. }
  927. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  928. stageTreeSpreadObj.loadExprToInput(info.sheet);
  929. },
  930. deletePress(sheet) {
  931. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  932. const tree = sheet.zh_tree;
  933. if (!tree) { return; }
  934. const sel = sheet.getSelections()[0];
  935. const validCols = [];
  936. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  937. const colSetting = sheet.zh_setting.cols[iCol];
  938. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  939. validCols.push(iCol);
  940. }
  941. }
  942. if (validCols.length === 0) { return; }
  943. const sortData = sheet.zh_tree.nodes;
  944. const datas = [], dgnDatas = [], mainDatas = [];
  945. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  946. const node = sortData[iRow];
  947. if (node && !node.lock) {
  948. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  949. let filter = true, filterDgn = true, filterMain = true;
  950. for (const iCol of validCols) {
  951. const colSetting = sheet.zh_setting.cols[iCol];
  952. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  953. if (node.b_code && node.b_code !== '') continue;
  954. } else if (colSetting.field !== 'postil') {
  955. if (colSetting.field === 'contract_qty') {
  956. if (node.is_tp) continue;
  957. } else if (colSetting.field === 'contract_tp') {
  958. if (!node.is_tp) continue;
  959. }
  960. if (node.children && node.children.length > 0) {
  961. continue;
  962. }
  963. const nodePos = stagePos.getLedgerPos(node.id);
  964. if (nodePos && nodePos.length > 0) {
  965. continue;
  966. }
  967. }
  968. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  969. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  970. dgnData[colSetting.field] = 0;
  971. filterDgn = false;
  972. }
  973. } else if (colSetting.field === 'memo') {
  974. mainData[colSetting.field] = null;
  975. filterMain = false;
  976. } else {
  977. data[colSetting.field] = null;
  978. const exprInfo = getExprInfo(colSetting.field);
  979. if (exprInfo) {
  980. data[exprInfo.expr] = '';
  981. }
  982. filter = false;
  983. }
  984. }
  985. if (!filter) datas.push(data);
  986. if (!filterDgn) dgnDatas.push(dgnData);
  987. if (!filterMain) mainDatas.push(mainData);
  988. }
  989. }
  990. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  991. const bills = {};
  992. if (datas.length > 0) bills.stage = datas;
  993. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  994. if (mainDatas.length > 0) bills.main = mainDatas;
  995. postData(window.location.href + '/update', {bills: bills}, function (result) {
  996. const nodes = stageTree.loadPostStageData(result);
  997. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  998. if (detail) {
  999. detail.loadStageLedgerUpdateData(result, nodes);
  1000. } else {
  1001. stageIm.loadUpdateLedgerData(result, nodes);
  1002. }
  1003. stageTreeSpreadObj.loadExprToInput(sheet);
  1004. });
  1005. }
  1006. }
  1007. },
  1008. clipboardPasting(e, info) {
  1009. if (info.sheet.zh_setting) {
  1010. const setting = info.sheet.zh_setting;
  1011. const range = info.cellRange;
  1012. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  1013. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1014. const col = info.sheet.zh_setting.cols[iCol];
  1015. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1
  1016. && col.field !== 'memo') {
  1017. toastr.error('不可修改此数据');
  1018. info.cancel = true;
  1019. return;
  1020. }
  1021. }
  1022. }
  1023. },
  1024. clipboardPasted(e, info) {
  1025. const pasteHint = getHintMsg();
  1026. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  1027. const sheet = info.sheet, setting = info.sheet.zh_setting;
  1028. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  1029. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1030. const curRow = iRow + info.cellRange.row;
  1031. const node = sheet.zh_tree.getItemsByIndex(curRow);
  1032. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  1033. let filter = true, filterDgn = true, filterMain = true;
  1034. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1035. const curCol = info.cellRange.col + iCol;
  1036. const col = info.sheet.zh_setting.cols[curCol];
  1037. if (col.field === 'contract_tp') {
  1038. if (!node.is_tp) continue;
  1039. } else if (col.field === 'contract_qty') {
  1040. if (node.is_tp) continue;
  1041. }
  1042. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1043. if (node.b_code && node.b_code !== '') continue;
  1044. } else if (col.field !== 'postil') {
  1045. if (node.children && node.children.length > 0) continue;
  1046. const nodePos = stagePos.getLedgerPos(node.id);
  1047. if (nodePos && nodePos.length > 0) continue;
  1048. }
  1049. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  1050. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1051. const num = _.toNumber(text);
  1052. if (num) {
  1053. dgnData[col.field] = num;
  1054. filterDgn = false;
  1055. } else {
  1056. try {
  1057. dgnData[col.field] = math.evaluate(transExpr(text));
  1058. filterDgn = false;
  1059. } catch(err) {
  1060. toastMessageUniq(pasteHint.invalidExpr);
  1061. }
  1062. }
  1063. } else if (col.field === 'memo') {
  1064. mainData.memo = text;
  1065. filterMain = false;
  1066. } else {
  1067. if (col.type === 'Number') {
  1068. const exprInfo = getExprInfo(col.field);
  1069. if (text) {
  1070. const num = _.toNumber(text);
  1071. data[col.field] = num;
  1072. if (exprInfo) data[exprInfo.expr] = '';
  1073. if (_.isFinite(num)) {
  1074. filter = false;
  1075. } else {
  1076. try {
  1077. data[col.field] = math.evaluate(transExpr(text));
  1078. if (exprInfo) data[exprInfo.expr] = text;
  1079. filter = false;
  1080. } catch(err) {
  1081. toastMessageUniq(pasteHint.invalidExpr);
  1082. }
  1083. }
  1084. } else {
  1085. data[col.field] = null;
  1086. if (exprInfo) data[exprInfo.expr] = '';
  1087. filter = false;
  1088. }
  1089. } else {
  1090. data[col.field] = text;
  1091. }
  1092. }
  1093. }
  1094. if (filter && filterDgn && filterMain) {
  1095. filterNodes.push(node);
  1096. } else {
  1097. if (!filter) datas.push(data);
  1098. if (!filterDgn) dgnDatas.push(dgnData);
  1099. if (!filterMain) mainDatas.push(mainData);
  1100. }
  1101. }
  1102. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1103. const updateData = {};
  1104. if (datas.length > 0) updateData.stage = datas;
  1105. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  1106. if (mainDatas.length > 0) updateData.main = mainDatas;
  1107. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1108. const nodes = stageTree.loadPostStageData(data);
  1109. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  1110. if (detail) {
  1111. detail.loadStageLedgerUpdateData(data, nodes);
  1112. } else {
  1113. stageIm.loadUpdateLedgerData(data, nodes);
  1114. }
  1115. stageTreeSpreadObj.loadExprToInput(sheet);
  1116. }, function () {
  1117. // todo
  1118. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1119. });
  1120. } else {
  1121. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1122. }
  1123. }
  1124. },
  1125. measureAllPosInNode(node, ratio = 1) {
  1126. const posterity = stageTree.getPosterity(node);
  1127. const data = {updateType: 'update', updateData: []};
  1128. for (const p of posterity) {
  1129. if (p.children && p.children.length > 0) continue;
  1130. const posRange = stagePos.getLedgerPos(p.id);
  1131. if (posRange && posRange.length > 0) {
  1132. for (const pr of posRange) {
  1133. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  1134. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1135. if (validValue <= 0) continue;
  1136. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  1137. const pData = {
  1138. pid: pr.id,
  1139. lid: pr.lid,
  1140. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  1141. };
  1142. data.updateData.push(pData);
  1143. }
  1144. }
  1145. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  1146. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  1147. break;
  1148. }
  1149. }
  1150. if (data.updateData.length === 0) {
  1151. toastr.info('其下全部计量单元均已计量');
  1152. return;
  1153. }
  1154. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1155. if (result.pos) {
  1156. stagePos.updateDatas(result.pos.pos);
  1157. stagePos.loadCurStageData(result.pos.curStageData);
  1158. }
  1159. const nodes = stageTree.loadPostStageData(result.ledger);
  1160. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1161. stagePosSpreadObj.loadCurPosData();
  1162. if (detail) {
  1163. detail.loadStagePosUpdateData(result, nodes);
  1164. } else {
  1165. stageIm.loadUpdatePosData(result, nodes);
  1166. }
  1167. toastr.success('已计量' + data.updateData.length + '条');
  1168. }, function () {
  1169. stagePosSpreadObj.loadCurPosData();
  1170. });
  1171. },
  1172. topRowChanged(e, info) {
  1173. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1174. },
  1175. editStarting(e, info) {
  1176. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1177. const col = info.sheet.zh_setting.cols[info.col];
  1178. const node = info.sheet.zh_tree.nodes[info.row];
  1179. const exprInfo = getExprInfo(col.field);
  1180. if (exprInfo) {
  1181. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1182. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1183. }
  1184. }
  1185. switch (col.field) {
  1186. case 'contract_qty':
  1187. case 'qc_qty':
  1188. info.cancel = node.is_tp;
  1189. break;
  1190. case 'contract_tp':
  1191. info.cancel = !node.is_tp;
  1192. break;
  1193. case 'is_tp':
  1194. info.cancel = true;
  1195. break;
  1196. }
  1197. },
  1198. buttonClicked: function (e, info) {
  1199. if (info.sheet.zh_setting) {
  1200. const node = SpreadJsObj.getSelectObject(info.sheet);
  1201. const col = info.sheet.zh_setting.cols[info.col];
  1202. const posRange = stagePos.getLedgerPos(node.id);
  1203. if (node.pre_used === 1 ||
  1204. (node.children && node.children.length > 0) ||
  1205. (node.unit !== '总额' && node.unit !== '元') ||
  1206. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  1207. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1208. return;
  1209. }
  1210. const postIsTp = function () {
  1211. const data = { calcType: {id: node.id} };
  1212. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  1213. // 更新至服务器
  1214. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  1215. const nodes = stageTree.loadPostStageData(result);
  1216. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1217. if (detail) {
  1218. detail.loadStageLedgerUpdateData(result, nodes);
  1219. } else {
  1220. stageIm.loadUpdateLedgerData(result, nodes);
  1221. }
  1222. });
  1223. };
  1224. if (col.field === 'is_tp') {
  1225. if (info.sheet.isEditing()) {
  1226. info.sheet.endEdit(true);
  1227. }
  1228. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  1229. $.msgBox({
  1230. id: 'calc-type',
  1231. title: '提示',
  1232. message: '切换计量模式,已计量数据会被清空。',
  1233. ok: {
  1234. caption: '确定',
  1235. callback: postIsTp,
  1236. },
  1237. cancel: {
  1238. caption: '取消',
  1239. callback: function () {
  1240. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1241. }
  1242. }
  1243. });
  1244. } else {
  1245. postIsTp();
  1246. }
  1247. }
  1248. }
  1249. },
  1250. measureByBatch: function (posNames, ratio, apply2sibling) {
  1251. if (posNames.length <= 0) return;
  1252. if (ratio <= 0) return;
  1253. const fRatio = ZhCalc.div(ratio, 100);
  1254. const sheet = slSpread.getActiveSheet();
  1255. const node = SpreadJsObj.getSelectObject(sheet);
  1256. const parent = stageTree.getParent(node);
  1257. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1258. const data = {updateType: 'batchUpdate', updateData: []};
  1259. for (const node of nodes) {
  1260. const posRange = stagePos.getLedgerPos(node.id);
  1261. if (!posRange || posRange <= 0) continue;
  1262. for (const p of posRange) {
  1263. if (posNames.indexOf(p.name) < 0) continue;
  1264. data.updateData.push({
  1265. pid: p.id, lid: p.lid,
  1266. contract_qty: ZhCalc.mul(p.quantity, fRatio),
  1267. contract_expr: `${p.quantity}*${ratio}%`,
  1268. });
  1269. }
  1270. }
  1271. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1272. if (result.pos) {
  1273. stagePos.updateDatas(result.pos.pos);
  1274. stagePos.loadCurStageData(result.pos.curStageData);
  1275. }
  1276. const nodes = stageTree.loadPostStageData(result.ledger);
  1277. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1278. stagePosSpreadObj.loadCurPosData();
  1279. if (detail) {
  1280. detail.loadStagePosUpdateData(result, nodes);
  1281. } else {
  1282. stageIm.loadUpdatePosData(result, nodes);
  1283. }
  1284. $('#calc-by-ratio').modal('hide');
  1285. }, function () {
  1286. stagePosSpreadObj.loadCurPosData();
  1287. $('#calc-by-ratio').modal('hide');
  1288. });
  1289. },
  1290. exportExcel: function (filename, nodes) {
  1291. const exportNodesData = function (data, nodes) {
  1292. for (const node of nodes) {
  1293. data.push({
  1294. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  1295. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  1296. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  1297. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  1298. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  1299. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  1300. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  1301. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_gather_percent: node.end_gather_percent,
  1302. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  1303. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  1304. final_dgn_price: node.final_dgn_price,
  1305. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  1306. });
  1307. if (node.children && node.children.length > 0) {
  1308. exportNodesData(data, node.children);
  1309. } else {
  1310. const posRange = stagePos.getLedgerPos(node.id);
  1311. if (posRange && posRange.length > 0) {
  1312. for (const [i, p] of posRange.entries()) {
  1313. data.push({
  1314. pos_code: (i + 1) + '', name: p.name,
  1315. quantity: p.quantity,
  1316. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  1317. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  1318. drawing_code: p.drawing_code, memo: p.memo, postil: p.postil,
  1319. });
  1320. }
  1321. }
  1322. }
  1323. }
  1324. };
  1325. const data = [];
  1326. exportNodesData(data, nodes ? nodes : stageTree.children);
  1327. SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename);
  1328. }
  1329. };
  1330. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1331. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1332. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1333. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1334. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1335. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1336. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1337. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1338. if (!readOnly) {
  1339. $('#bills-expr').bind('change onblur', function () {
  1340. if (this.readOnly) return;
  1341. const expr = $(this);
  1342. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1343. const select = stageTree.getItemsByIndex(row);
  1344. if (!select) return;
  1345. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1346. let newValue = expr.val();
  1347. const num = _.toNumber(newValue);
  1348. if (_.isFinite(num)) {
  1349. newValue = num;
  1350. } else {
  1351. try {
  1352. newValue = math.evaluate(transExpr(newValue));
  1353. } catch(err) {
  1354. toastr.error('输入的表达式非法');
  1355. return;
  1356. }
  1357. }
  1358. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1359. if (field.indexOf('_dgn_') > 0) {
  1360. updateData.dgn = {
  1361. id: select.id
  1362. };
  1363. updateData.dgn[field] = newValue;
  1364. } else {
  1365. updateData.stage = {
  1366. lid: select.id
  1367. };
  1368. updateData.stage[field] = newValue;
  1369. const exprInfo = getExprInfo(field);
  1370. if (exprInfo) {
  1371. updateData.stage[exprInfo.expr] = expr.val();
  1372. }
  1373. }
  1374. // 更新至服务器
  1375. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1376. const nodes = stageTree.loadPostStageData(result);
  1377. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1378. if (detail) {
  1379. detail.loadStageLedgerUpdateData(result, nodes);
  1380. } else {
  1381. stageIm.loadUpdateLedgerData(result, nodes);
  1382. }
  1383. });
  1384. });
  1385. }
  1386. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1387. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1388. $.contextMenu({
  1389. selector: '#stage-ledger',
  1390. build: function ($trigger, e) {
  1391. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1392. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1393. },
  1394. items: {
  1395. 'locateZjjl': {
  1396. name: '定位至中间计量',
  1397. icon: 'fa-sign-in',
  1398. callback: function (key, opt) {
  1399. if (!detail) {
  1400. detail = new Detail($('#detail-spread'));
  1401. }
  1402. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1403. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1404. if (leafUsedBills) {
  1405. if (!$('#zhongjian').hasClass('active')) {
  1406. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1407. $('a', '.side-menu').removeClass('active');
  1408. $('.tab-content .tab-select-show').removeClass('active');
  1409. tab.addClass('active');
  1410. tabPanel.addClass('active');
  1411. showSideTools(tab.hasClass('active'));
  1412. slSpread.refresh();
  1413. spSpread.refresh();
  1414. }
  1415. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1416. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1417. SpreadJsObj.locateData(detail.sheet, im);
  1418. detail.spread.refresh();
  1419. $('#zhongjian .sjs-bottom').height('400px');
  1420. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1421. detail.reLoadDetailData();
  1422. } else {
  1423. toastr.error('无可定位中间计量');
  1424. }
  1425. },
  1426. },
  1427. tagSpr: '----',
  1428. tag: {
  1429. name: '书签',
  1430. callback: function (key, opt, menu, e) {
  1431. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1432. addTag.do(node);
  1433. },
  1434. disabled: function (key, opt) {
  1435. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1436. return !node;
  1437. }
  1438. },
  1439. showSpr: '----',
  1440. showLast: {
  1441. name: '显示至最底层',
  1442. callback: function (key, opt, menu, e) {
  1443. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1444. setTimeout(() => {
  1445. showWaitingView();
  1446. stageTree.expandByCustom(x => {
  1447. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1448. });
  1449. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1450. closeWaitingView();
  1451. }, 100);
  1452. },
  1453. },
  1454. exportSpr: '----',
  1455. exportSelectNodeXlsx: {
  1456. name: '导出选中节点至Excel',
  1457. callback: function (key, opt, menu, e) {
  1458. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1459. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1460. },
  1461. disabled: function (key, opt) {
  1462. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1463. return !node;
  1464. }
  1465. }
  1466. }
  1467. });
  1468. const stagePosSpreadObj = {
  1469. loadExprToInput(sheet) {
  1470. const sel = sheet.getSelections()[0];
  1471. if (!sel) return;
  1472. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1473. if (col && col.type === 'Number') {
  1474. const data = SpreadJsObj.getSelectObject(sheet);
  1475. if (data) {
  1476. const exprInfo = getExprInfo(col.field);
  1477. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1478. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1479. .attr('readOnly', readOnly || cell.locked());
  1480. $('#pos-expr').attr('data-row', sel.row);
  1481. } else {
  1482. $('#pos-expr').val('').attr('readOnly', true);
  1483. $('#pos-expr').removeAttr('data-row');
  1484. }
  1485. } else {
  1486. $('#pos-expr').val('').attr('readOnly', true);
  1487. $('#pos-expr').removeAttr('data-row');
  1488. }
  1489. },
  1490. /**
  1491. * 加载计量单元 根据当前台账选择节点
  1492. */
  1493. loadCurPosData: function () {
  1494. const sheet = slSpread.getActiveSheet();
  1495. const node = SpreadJsObj.getSelectObject(sheet);
  1496. if (node) {
  1497. spSpread.getActiveSheet().zh_setting.readOnly = node.lock;
  1498. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1499. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1500. getNodeList(node.id);
  1501. // 如果是附件是当前节点,隐藏
  1502. // if ($('#dqjiedian').hasClass('active')) {
  1503. // $('#showAttachment').hide();
  1504. // }
  1505. } else {
  1506. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1507. }
  1508. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1509. },
  1510. editEnded: function (e, info) {
  1511. if (info.sheet.zh_setting) {
  1512. // 未改变过,则直接跳过
  1513. const sortData = info.sheet.zh_data;
  1514. const posData = sortData ? sortData[info.row] : null;
  1515. const col = info.sheet.zh_setting.cols[info.col];
  1516. const orgText = posData ? posData[col.field] : null;
  1517. const newText = trimInvalidChar(info.editingText);
  1518. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1519. return;
  1520. }
  1521. // 台账模式下,不可新增
  1522. if (checkTzMeasureType() && !posData) {
  1523. toastr.error('台账模式不可新增计量单元数据');
  1524. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1525. return ;
  1526. }
  1527. // 不同节点下,计量单元检查输入
  1528. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1529. const node = stagePosSpreadObj.stageTreeNode;
  1530. if (!node) {
  1531. toastr.warning('数据错误, 请刷新页面后再试');
  1532. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1533. return;
  1534. } else if (newText !== '' && node.children && node.children > 0) {
  1535. toastr.error('父节点不可插入计量单元');
  1536. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1537. return;
  1538. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1539. toastr.error('项目节不可插入计量单元');
  1540. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1541. return;
  1542. }
  1543. // 生成提交数据
  1544. const data = {};
  1545. if (col.field === 'name') {
  1546. if ((!newText || newText === '') && posData) {
  1547. toastr.error('部位名称不可为空');
  1548. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1549. return;
  1550. } else if (!posData) {
  1551. if (newText !== '') {
  1552. data.updateType = 'add';
  1553. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1554. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1555. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1556. return;
  1557. }
  1558. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1559. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1560. } else {
  1561. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1562. return;
  1563. }
  1564. } else {
  1565. data.updateType = 'update';
  1566. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1567. }
  1568. } else if (!posData) {
  1569. toastr.warning('新增计量单元请先输入名称');
  1570. } else {
  1571. data.updateType = 'update';
  1572. data.updateData = {pid: posData.id, lid: posData.lid};
  1573. if (col.type === 'Number') {
  1574. const exprInfo = getExprInfo(col.field);
  1575. const num = _.toNumber(newText);
  1576. if (_.isFinite(num)) {
  1577. data.updateData[col.field] = num;
  1578. if (exprInfo) {
  1579. data.updateData[exprInfo.expr] = '';
  1580. }
  1581. } else {
  1582. try {
  1583. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1584. if (exprInfo) {
  1585. data.updateData[exprInfo.expr] = newText;
  1586. }
  1587. } catch(err) {
  1588. toastr.error('输入的表达式非法');
  1589. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1590. return;
  1591. }
  1592. }
  1593. } else {
  1594. data.updateData[col.field] = newText;
  1595. }
  1596. }
  1597. // 提交数据到服务器
  1598. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1599. if (result.pos) {
  1600. stagePos.updateDatas(result.pos.pos);
  1601. stagePos.loadCurStageData(result.pos.curStageData);
  1602. }
  1603. const refreshData = stageTree.loadPostStageData(result.ledger);
  1604. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1605. stagePosSpreadObj.loadCurPosData();
  1606. if (detail) {
  1607. detail.loadStagePosUpdateData(result, refreshData);
  1608. } else {
  1609. stageIm.loadUpdatePosData(result, refreshData);
  1610. }
  1611. }, function () {
  1612. stagePosSpreadObj.loadCurPosData();
  1613. });
  1614. }
  1615. },
  1616. editStarting: function (e, info) {
  1617. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1618. const sel = info.sheet.getSelections();
  1619. if (!sel || !sel[0]) return;
  1620. const col = info.sheet.zh_setting.cols[sel[0].col];
  1621. const node = SpreadJsObj.getSelectObject(info.sheet);
  1622. const exprInfo = getExprInfo(col.field);
  1623. if (exprInfo) {
  1624. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1625. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1626. }
  1627. }
  1628. },
  1629. clipboardPasting: function (e, info) {
  1630. if (info.sheet.zh_setting) {
  1631. const sortData = info.sheet.zh_data;
  1632. const range = info.cellRange;
  1633. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty'];
  1634. if (!checkTzMeasureType()) {
  1635. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1636. }
  1637. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1638. const col = info.sheet.zh_setting.cols[iCol];
  1639. if (validField.indexOf(col.field) === -1) {
  1640. if (checkTzMeasureType()) {
  1641. toastr.error('不可修改此数据');
  1642. info.cancel = true;
  1643. return;
  1644. } else {
  1645. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1646. const pos = sortData(iRow);
  1647. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1648. toastr.error('不可修改此数据');
  1649. info.cancel = true;
  1650. return;
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. },
  1658. clipboardPasted: function (e, info) {
  1659. if (info.sheet.zh_setting) {
  1660. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1661. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1662. }
  1663. const data = { updateType: '', updateData: [], };
  1664. const sortData = info.sheet.zh_data;
  1665. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1666. if (sortData && (info.cellRange.row >= sortData.length)) {
  1667. data.updateType = 'add';
  1668. if (info.cellRange.col !== 0) {
  1669. toastr.warning('新增计量单元请先输入名称');
  1670. stagePosSpreadObj.loadCurPosData();
  1671. return;
  1672. }
  1673. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1674. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1675. stagePosSpreadObj.loadCurPosData();
  1676. return;
  1677. }
  1678. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1679. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1680. const curRow = info.cellRange.row + iRow;
  1681. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1682. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1683. const curCol = info.cellRange.col + iCol;
  1684. const colSetting = info.sheet.zh_setting.cols[curCol];
  1685. if (!colSetting) continue;
  1686. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1687. if (colSetting.type === 'Number') {
  1688. const exprInfo = getExprInfo(colSetting.field);
  1689. if (newValue) {
  1690. const num = _.toNumber(newValue);
  1691. if (num) {
  1692. newData[colSetting.field] = num;
  1693. if (exprInfo) {
  1694. newData[exprInfo.expr] = '';
  1695. }
  1696. } else {
  1697. try {
  1698. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1699. if (exprInfo) {
  1700. newData[exprInfo.expr] = newValue;
  1701. }
  1702. } catch(err) {
  1703. toastr.error('输入的表达式非法');
  1704. stagePosSpreadObj.loadCurPosData();
  1705. return;
  1706. }
  1707. }
  1708. } else {
  1709. newData[colSetting.field] = null;
  1710. if (exprInfo) newData[exprInfo.expr] = '';
  1711. }
  1712. } else {
  1713. newData[colSetting.field] = newValue;
  1714. }
  1715. }
  1716. data.updateData.push(newData);
  1717. }
  1718. } else {
  1719. data.updateType = 'update';
  1720. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1721. const curRow = info.cellRange.row + iRow;
  1722. const curPos = sortData[curRow];
  1723. if (curPos) {
  1724. const newData = {pid: curPos.id, lid: curPos.lid};
  1725. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1726. const curCol = info.cellRange.col + iCol;
  1727. const colSetting = info.sheet.zh_setting.cols[curCol];
  1728. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1729. if (colSetting.type === 'Number') {
  1730. const exprInfo = getExprInfo(colSetting.field);
  1731. if (!newValue) {
  1732. newData[colSetting.field] = newValue;
  1733. if (exprInfo) newData[exprInfo.expr] = '';
  1734. continue;
  1735. }
  1736. const num = _.toNumber(newValue);
  1737. if (num) {
  1738. newData[colSetting.field] = num;
  1739. if (exprInfo) newData[exprInfo.expr] = '';
  1740. } else {
  1741. try {
  1742. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1743. const exprInfo = getExprInfo(colSetting.field);
  1744. if (exprInfo) newData[exprInfo.expr] = newValue;
  1745. } catch(err) {
  1746. toastr.error('输入的表达式非法');
  1747. stagePosSpreadObj.loadCurPosData();
  1748. return;
  1749. }
  1750. }
  1751. } else {
  1752. newData[colSetting.field] = newValue;
  1753. }
  1754. }
  1755. data.updateData.push(newData);
  1756. }
  1757. }
  1758. }
  1759. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1760. if (result.pos) {
  1761. stagePos.updateDatas(result.pos.pos);
  1762. stagePos.loadCurStageData(result.pos.curStageData);
  1763. }
  1764. const nodes = stageTree.loadPostStageData(result.ledger);
  1765. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1766. stagePosSpreadObj.loadCurPosData();
  1767. if (detail) {
  1768. detail.loadStagePosUpdateData(result, nodes);
  1769. } else {
  1770. stageIm.loadUpdatePosData(result, nodes);
  1771. }
  1772. }, function () {
  1773. stagePosSpreadObj.loadCurPosData();
  1774. });
  1775. }
  1776. },
  1777. deletePress: function (sheet) {
  1778. if (sheet.zh_setting.readOnly) return;
  1779. if (sheet.zh_setting && sheet.zh_data) {
  1780. const sortData = sheet.zh_data;
  1781. if (!sortData || sortData.length === 0) { return; }
  1782. const sel = sheet.getSelections()[0];
  1783. const validCols = [];
  1784. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1785. const colSetting = sheet.zh_setting.cols[iCol];
  1786. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1787. validCols.push(iCol);
  1788. }
  1789. }
  1790. if (validCols.length === 0) { return; }
  1791. const datas = [], posSelects = [];
  1792. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1793. const node = sortData[iRow];
  1794. if (node) {
  1795. const data = {pid: node.id, lid: node.lid};
  1796. for (const iCol of validCols) {
  1797. const colSetting = sheet.zh_setting.cols[iCol];
  1798. if (colSetting.field === 'name') {
  1799. toastr.error('部位名称不能为空');
  1800. return;
  1801. }
  1802. data[colSetting.field] = null;
  1803. const exprInfo = getExprInfo(colSetting.field);
  1804. if (exprInfo) {
  1805. data[exprInfo.expr] = '';
  1806. }
  1807. }
  1808. datas.push(data);
  1809. posSelects.push(node);
  1810. }
  1811. }
  1812. if (datas.length > 0) {
  1813. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1814. if (result.pos) {
  1815. stagePos.updateDatas(result.pos.pos);
  1816. stagePos.loadCurStageData(result.pos.curStageData);
  1817. }
  1818. const nodes = stageTree.loadPostStageData(result.ledger);
  1819. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1820. if (detail) {
  1821. detail.loadStagePosUpdateData(result, nodes);
  1822. } else {
  1823. stageIm.loadUpdatePosData(result, nodes);
  1824. }
  1825. // todo 只加载改变项
  1826. stagePosSpreadObj.loadCurPosData();
  1827. });
  1828. }
  1829. }
  1830. },
  1831. deletePos: function (sheet) {
  1832. const sels = sheet.getSelections();
  1833. const sel = sels ? sels[0] : null;
  1834. if (sheet.zh_data && sel) {
  1835. const data = {updateType: 'delete', updateData: []};
  1836. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1837. const posData = sheet.zh_data[sel.row + iRow];
  1838. if (posData) {
  1839. data.updateData.push(posData.id);
  1840. }
  1841. }
  1842. if (data.updateData.length > 0) {
  1843. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1844. stagePos.removeDatas(result.pos.pos);
  1845. const refreshData = stageTree.loadPostStageData(result.ledger);
  1846. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1847. stagePosSpreadObj.loadCurPosData();
  1848. if (detail) {
  1849. detail.loadStagePosUpdateData(result, refreshData);
  1850. } else {
  1851. stageIm.loadUpdatePosData(result, refreshData);
  1852. }
  1853. });
  1854. }
  1855. }
  1856. },
  1857. selectionChanged: function (e, info) {
  1858. stagePosSpreadObj.loadExprToInput(info.sheet);
  1859. },
  1860. addPegs: function (pegs) {
  1861. if (!pegs || pegs.length <= 0) return;
  1862. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1863. if (!node) return;
  1864. const sheet = spSpread.getActiveSheet();
  1865. const sortData = sheet.zh_data || [];
  1866. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1867. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1868. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1869. if (result.pos) {
  1870. stagePos.updateDatas(result.pos.pos);
  1871. }
  1872. stagePosSpreadObj.loadCurPosData();
  1873. });
  1874. }
  1875. };
  1876. // 加载上下窗口resizer
  1877. $.divResizer({
  1878. select: '#main-resize',
  1879. callback: function () {
  1880. slSpread.refresh();
  1881. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1882. $(".sp-wrap").height(bcontent-30);
  1883. spSpread.refresh();
  1884. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1885. }
  1886. });
  1887. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1888. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;cooperation' }, function (result) {
  1889. // 加载树结构
  1890. stageTree.loadDatas(result.ledgerData);
  1891. // stageTree.loadCurStageData(curStageData);
  1892. // stageTree.loadPreStageData(preStageData);
  1893. checkShowLast(result.ledgerData.length);
  1894. treeCalc.calculateAll(stageTree);
  1895. // 加载解锁相关
  1896. if (result.cooperation) {
  1897. // stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2]);
  1898. stageTree.loadOnlinePwd(result.cooperation, result.cooperationPwd, result.cooperationConfirm);
  1899. $('#cooperationCount').html(stageTree.pwd.length || '');
  1900. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  1901. setCooperationSelectHtml();
  1902. reloadCooperationHtml();
  1903. }
  1904. for (const t of result.tags) {
  1905. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  1906. }
  1907. billsTag.loadDatas(result.tags);
  1908. // 加载部位明细
  1909. stagePos.loadDatas(result.posData);
  1910. stagePos.calculateAll();
  1911. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1912. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1913. stagePosSpreadObj.loadCurPosData();
  1914. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1915. // 加载中间计量
  1916. stageIm.init(stage, imType, tenderInfo.decimal);
  1917. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1918. errorList.loadHisErrorData();
  1919. checkList.loadHisCheckData();
  1920. }, null, true);
  1921. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1922. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1923. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1924. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1925. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1926. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1927. if (!readOnly) {
  1928. $('#pos-expr').bind('change onblur', function () {
  1929. if (this.readOnly) return;
  1930. const expr = $(this);
  1931. const posSheet = spSpread.getActiveSheet();
  1932. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1933. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1934. if (!select) return;
  1935. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  1936. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1937. const data = {pid: select.id, lid: select.lid};
  1938. const exprInfo = getExprInfo(field);
  1939. if (newValue !== '') {
  1940. const num = _.toNumber(newValue);
  1941. if (num) {
  1942. data[field] = num;
  1943. if (exprInfo) data[exprInfo.expr] = '';
  1944. } else {
  1945. try {
  1946. data[field] = math.evaluate(transExpr(newValue));
  1947. if (exprInfo) data[exprInfo.expr] = newValue;
  1948. } catch (err) {
  1949. toastr.error('输入的表达式非法');
  1950. return;
  1951. }
  1952. }
  1953. } else {
  1954. data[field] = null;
  1955. if (exprInfo) data[exprInfo.expr] = '';
  1956. }
  1957. // 提交数据到服务器
  1958. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1959. if (result.pos) {
  1960. stagePos.updateDatas(result.pos.pos);
  1961. stagePos.loadCurStageData(result.pos.curStageData);
  1962. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1963. }
  1964. const refreshData = stageTree.loadPostStageData(result.ledger);
  1965. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1966. if (detail) {
  1967. detail.loadStagePosUpdateData(result, refreshData);
  1968. } else {
  1969. stageIm.loadUpdatePosData(result, refreshData);
  1970. }
  1971. });
  1972. });
  1973. }
  1974. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1975. $.contextMenu({
  1976. selector: '#stage-pos',
  1977. build: function ($trigger, e) {
  1978. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1979. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1980. },
  1981. items: {
  1982. 'del': {
  1983. name: '删除',
  1984. icon: 'fa-remove',
  1985. visible: function (key, opt) {
  1986. return !checkTzMeasureType();
  1987. },
  1988. disabled: function (key, opt) {
  1989. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1990. if (!node || node.lock) return true;
  1991. const sheet = spSpread.getActiveSheet();
  1992. if (sheet.zh_data && !readOnly) {
  1993. const selection = sheet.getSelections();
  1994. if (selection && selection[0]) {
  1995. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1996. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1997. const posData = sheet.zh_data[selection[0].row + iRow];
  1998. if (posData) {
  1999. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2000. valid = true;
  2001. break;
  2002. }
  2003. } else {
  2004. valid = true;
  2005. break;
  2006. }
  2007. }
  2008. return valid;
  2009. } else {
  2010. return true;
  2011. }
  2012. } else {
  2013. return true;
  2014. }
  2015. },
  2016. callback: function (key, opt) {
  2017. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2018. }
  2019. },
  2020. 'merge-peg': {
  2021. name: '合并起讫桩号',
  2022. visible: function (key, opt) {
  2023. return !checkTzMeasureType();
  2024. },
  2025. disabled: function (key, opt) {
  2026. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2027. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2028. },
  2029. callback: function (key, opt) {
  2030. mergePeg.show();
  2031. }
  2032. },
  2033. 'calcByRatio': {
  2034. name: '按比例计量',
  2035. visible: function (key, opt) {
  2036. const data = spSpread.getActiveSheet().zh_data;
  2037. return data && data.length > 0;
  2038. },
  2039. disabled: function (key, opt) {
  2040. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2041. return node.lock;
  2042. },
  2043. callback: function (key, opt) {
  2044. $('#cbr-ratio').val('');
  2045. $('#apply2sibling')[0].checked = false;
  2046. $('#cbr-check-all')[0].checked = false;
  2047. const html = [];
  2048. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2049. html.push('<tr>');
  2050. html.push('<td>', i+1, '</td>');
  2051. html.push('<td>', p.name, '</td>');
  2052. html.push('<td>', p.quantity, '</td>');
  2053. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2054. html.push('</tr>');
  2055. }
  2056. $('#cbr-pos-list').html(html.join(''));
  2057. $('#calc-by-ratio').modal('show');
  2058. }
  2059. }
  2060. }
  2061. });
  2062. $.subMenu({
  2063. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2064. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2065. key: 'menu.1.0.0',
  2066. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2067. callback: function (info) {
  2068. if (info.mini) {
  2069. $('.panel-title').addClass('fluid');
  2070. $('#sub-menu').removeClass('panel-sidebar');
  2071. } else {
  2072. $('.panel-title').removeClass('fluid');
  2073. $('#sub-menu').addClass('panel-sidebar');
  2074. }
  2075. autoFlashHeight();
  2076. slSpread.refresh();
  2077. spSpread.refresh();
  2078. if (searchLedger) {
  2079. searchLedger.spread.refresh();
  2080. }
  2081. if (detail) {
  2082. detail.spread.refresh();
  2083. }
  2084. if (checkedChanges) checkedChanges.refresh();
  2085. if (errorList && errorList.spread) {
  2086. errorList.spread.refresh();
  2087. }
  2088. if (checkList) {
  2089. checkList.spread.refresh();
  2090. }
  2091. }
  2092. });
  2093. $('#row-view').on('show.bs.modal', function () {
  2094. const html = [], customDisplay = customColDisplay();
  2095. for (const cd of customDisplay) {
  2096. html.push('<tr>');
  2097. html.push('<td>', cd.title, '</td>');
  2098. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2099. html.push('</tr>');
  2100. }
  2101. $('#row-view-list').html(html.join(''));
  2102. });
  2103. $('#row-view-ok').click(function () {
  2104. const customDisplay = customColDisplay();
  2105. const cvl = $('#row-view-list').children();
  2106. for (const cv of cvl) {
  2107. const title = $(cv).children()[0].innerHTML;
  2108. const check = $('input', cv)[0].checked;
  2109. const cd = customDisplay.find(function (c) {
  2110. return c.title === title;
  2111. });
  2112. cd.visible = check;
  2113. }
  2114. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2115. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2116. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2117. $('#row-view').modal('hide');
  2118. });
  2119. const posSearch = (function () {
  2120. let resultArr = [];
  2121. const search = function () {
  2122. resultArr = [];
  2123. const keyword = $('#pos-search-keyword').val();
  2124. const checkOver = $('#pos-over-search')[0].checked;
  2125. const checkEmpty = $('#pos-empty-search')[0].checked;
  2126. const sortData = spSpread.getActiveSheet().zh_data;
  2127. if (checkOver || checkEmpty) {
  2128. if (sortData) {
  2129. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2130. const sd = sortData[i];
  2131. let match = false;
  2132. if (checkOver) {
  2133. if (sd.end_gather_qty) {
  2134. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2135. }
  2136. }
  2137. if (checkEmpty) {
  2138. if (sd.quantity) {
  2139. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2140. }
  2141. }
  2142. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2143. if (match) {
  2144. resultArr.push({index: i, data: sd});
  2145. }
  2146. }
  2147. }
  2148. } else if (keyword && keyword !== '') {
  2149. if (sortData) {
  2150. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2151. const sd = sortData[i];
  2152. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2153. resultArr.push({index: i, data: sd});
  2154. }
  2155. }
  2156. }
  2157. }
  2158. $('#pos-search-result').html('结果:' + resultArr.length);
  2159. };
  2160. const searchAndLocate = function () {
  2161. search();
  2162. if (resultArr.length > 0) {
  2163. const sheet = spSpread.getActiveSheet();
  2164. const sel = sheet.getSelections()[0];
  2165. const curRow = sel ? sel.row : 0;
  2166. const pos = resultArr[0];
  2167. if (pos.index !== curRow) {
  2168. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2169. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2170. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2171. }
  2172. }
  2173. };
  2174. const locateNext = function () {
  2175. if (resultArr.length > 0) {
  2176. const sheet = spSpread.getActiveSheet();
  2177. const sel = sheet.getSelections()[0];
  2178. const curRow = sel ? sel.row : 0;
  2179. let next = _.find(resultArr, function (d) {
  2180. return d.index > curRow;
  2181. });
  2182. if (!next) next = resultArr[0];
  2183. if (next.index !== curRow) {
  2184. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2185. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2186. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2187. }
  2188. }
  2189. };
  2190. const locatePre = function () {
  2191. if (resultArr.length > 0) {
  2192. const sheet = spSpread.getActiveSheet();
  2193. const sel = sheet.getSelections()[0];
  2194. const curRow = sel ? sel.row : 0;
  2195. let next = _.findLast(resultArr, function (d) {
  2196. return d.index < curRow;
  2197. });
  2198. if (!next) next = resultArr[resultArr.length - 1];
  2199. if (next.index !== curRow) {
  2200. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2201. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2202. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2203. }
  2204. }
  2205. };
  2206. return {search, searchAndLocate, locateNext, locatePre};
  2207. })();
  2208. $('#pos-search-keyword').bind('keydown', function(e){
  2209. if (e.keyCode == 13) posSearch.searchAndLocate();
  2210. });
  2211. $('#pos-empty-search').click(function () {
  2212. if (this.checked) {
  2213. $('[for=' + this.id +']').addClass('text-warning');
  2214. } else {
  2215. $('[for=' + this.id +']').removeClass('text-warning');
  2216. }
  2217. if (this.checked) {
  2218. if ($('#pos-over-search')[0].checked) {
  2219. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2220. } else {
  2221. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2222. }
  2223. } else {
  2224. if ($('#pos-over-search')[0].checked) {
  2225. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2226. } else {
  2227. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2228. }
  2229. }
  2230. posSearch.searchAndLocate();
  2231. });
  2232. $('#pos-over-search').click(function () {
  2233. if (this.checked) {
  2234. $('[for=' + this.id +']').addClass('text-danger');
  2235. } else {
  2236. $('[for=' + this.id +']').removeClass('text-danger');
  2237. }
  2238. if (this.checked) {
  2239. if ($('#pos-empty-search')[0].checked) {
  2240. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2241. } else {
  2242. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2243. }
  2244. } else {
  2245. if ($('#pos-empty-search')[0].checked) {
  2246. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2247. } else {
  2248. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2249. }
  2250. }
  2251. posSearch.searchAndLocate();
  2252. });
  2253. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2254. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2255. $.divResizer({
  2256. select: '#right-spr',
  2257. callback: function () {
  2258. slSpread.refresh();
  2259. spSpread.refresh();
  2260. if (searchLedger) {
  2261. searchLedger.spread.refresh();
  2262. }
  2263. if (detail) {
  2264. detail.spread.refresh();
  2265. }
  2266. if (checkedChanges) checkedChanges.refresh();
  2267. if (errorList && errorList.spread) {
  2268. errorList.spread.refresh();
  2269. }
  2270. if (checkList) {
  2271. checkList.spread.refresh();
  2272. }
  2273. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2274. }
  2275. });
  2276. // 中间计量加载上下窗口resizer
  2277. $.divResizer({
  2278. select: '#zhongjian-spr',
  2279. callback: function () {
  2280. if (detail) {
  2281. detail.spread.refresh();
  2282. }
  2283. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2284. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2285. }
  2286. });
  2287. // 附件加载上下窗口resizer
  2288. $.divResizer({
  2289. select: '#file-spr',
  2290. callback: function () {
  2291. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2292. }
  2293. });
  2294. // 变更令加载上下窗口resizer
  2295. $.divResizer({
  2296. select: '#change-spr',
  2297. callback: function () {
  2298. if (checkedChanges) checkedChanges.refresh();
  2299. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2300. }
  2301. });
  2302. class Detail {
  2303. constructor (obj) {
  2304. const self = this;
  2305. this.spreadSetting = {
  2306. cols: [
  2307. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2308. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2309. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2310. {
  2311. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2312. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2313. },
  2314. ],
  2315. headRows: 1,
  2316. emptyRows: 0,
  2317. headRowHeight: [32],
  2318. headColWidth: [30],
  2319. defaultRowHeight: 21,
  2320. headerFont: '12px 微软雅黑',
  2321. font: '12px 微软雅黑',
  2322. readOnly: readOnly,
  2323. selectedBackColor: '#fffacd',
  2324. };
  2325. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2326. this.sheet = this.spread.getActiveSheet();
  2327. this.spread.options.allowUserDragFill = true;
  2328. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2329. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2330. this.detailObj = {
  2331. selectionChanged: function (e, info) {
  2332. self.reLoadDetailData();
  2333. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2334. self.loadLocateInfo();
  2335. }
  2336. },
  2337. editEnded: function(e, info) {
  2338. if (info.sheet.zh_setting) {
  2339. const col = info.sheet.zh_setting.cols[info.col];
  2340. if (col.field !== 'doc_code') {
  2341. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2342. return;
  2343. }
  2344. const data = SpreadJsObj.getSelectObject(info.sheet);
  2345. if (data) {
  2346. const updateData = {lid: data.lid, pid: data.pid};
  2347. if (data.uuid) {
  2348. updateData.uuid = data.uuid;
  2349. } else {
  2350. updateData.code = data.code;
  2351. updateData.name = data.name;
  2352. updateData.unit = data.unit;
  2353. updateData.unit_price = data.unit_price;
  2354. updateData.pid = data.pid;
  2355. updateData.pos_name = data.pos_name;
  2356. }
  2357. if (data.custom_define.indexOf('doc_code') === -1) {
  2358. updateData.custom_define = data.custom_define;
  2359. updateData.custom_define.push('doc_code');
  2360. updateData.custom_define = updateData.custom_define.join(',');
  2361. }
  2362. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2363. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2364. stageIm.loadUpdateDetailData(result);
  2365. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2366. }, function () {
  2367. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2368. });
  2369. } else {
  2370. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2371. }
  2372. }
  2373. },
  2374. clipboardPasted: function (e, info) {
  2375. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2376. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2377. if (info.cellRange.colCount > 1) {
  2378. toastr.warning('请勿同时复制粘贴多列数据');
  2379. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2380. return;
  2381. }
  2382. if (col.field !== 'doc_code') {
  2383. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2384. return;
  2385. }
  2386. const datas = [];
  2387. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2388. const curRow = info.cellRange.row + iRow;
  2389. const data = info.sheet.zh_data[curRow];
  2390. if (data) {
  2391. const updateData = {lid: data.lid, pid: data.pid};
  2392. if (data.uuid) {
  2393. updateData.uuid = data.uuid;
  2394. } else {
  2395. updateData.code = data.code;
  2396. updateData.name = data.name;
  2397. updateData.unit = data.unit;
  2398. updateData.unit_price = data.unit_price;
  2399. updateData.pid = data.pid;
  2400. updateData.pos_name = data.pos_name;
  2401. }
  2402. if (data.custom_define.indexOf('doc_code') === -1) {
  2403. updateData.custom_define = data.custom_define;
  2404. updateData.custom_define.push('doc_code');
  2405. updateData.custom_define = updateData.custom_define.join(',');
  2406. }
  2407. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2408. datas.push(updateData);
  2409. }
  2410. }
  2411. if (datas.length > 0) {
  2412. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2413. stageIm.loadUpdateDetailData(result);
  2414. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2415. }, function () {
  2416. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2417. })
  2418. }
  2419. }
  2420. },
  2421. deletePress: function (sheet) {
  2422. if (sheet.zh_setting) {
  2423. const datas = [];
  2424. const sel = sheet.getSelections()[0];
  2425. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2426. const col = sheet.zh_setting.cols[iCol];
  2427. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2428. const data = sheet.zh_data[iRow];
  2429. if (col.field === 'doc_code') {
  2430. const updateData = {lid: data.lid};
  2431. if (data.uuid) {
  2432. updateData.uuid = data.uuid;
  2433. updateData.doc_code = '';
  2434. datas.push(updateData);
  2435. }
  2436. }
  2437. }
  2438. }
  2439. if (datas.length > 0) {
  2440. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2441. stageIm.loadUpdateDetailData(result);
  2442. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2443. }, function () {
  2444. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2445. });
  2446. }
  2447. }
  2448. },
  2449. dragFillBlock: function (e, info) {
  2450. info.cancel = true;
  2451. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2452. const sel = info.sheet.getSelections()[0];
  2453. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2454. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2455. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2456. if (text === '') return;
  2457. const regRst = /(\d+)$/g.exec(text), datas = [];
  2458. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2459. const curRow = info.fillRange.row + iRow;
  2460. const data = info.sheet.zh_data[curRow];
  2461. if (data) {
  2462. const updateData = {lid: data.lid};
  2463. if (data.uuid) {
  2464. updateData.uuid = data.uuid;
  2465. } else {
  2466. updateData.code = data.code;
  2467. updateData.name = data.name;
  2468. updateData.unit = data.unit;
  2469. updateData.unit_price = data.unit_price;
  2470. updateData.pid = data.pid;
  2471. updateData.pos_name = data.pos_name;
  2472. }
  2473. if (regRst) {
  2474. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2475. } else {
  2476. updateData.doc_code = text.replace('\n', '');
  2477. }
  2478. if (data.custom_define.indexOf('doc_code') === -1) {
  2479. updateData.custom_define = data.custom_define;
  2480. updateData.custom_define.push('doc_code');
  2481. updateData.custom_define = updateData.custom_define.join(',');
  2482. }
  2483. datas.push(updateData);
  2484. }
  2485. }
  2486. if (datas.length > 0) {
  2487. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2488. stageIm.loadUpdateDetailData(result);
  2489. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2490. }, function () {
  2491. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2492. })
  2493. }
  2494. },
  2495. };
  2496. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2497. if (!readOnly) {
  2498. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2499. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2500. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2501. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2502. }
  2503. this._initImTypeSetRela();
  2504. this._initModifyDetail();
  2505. this._initLocateRela();
  2506. // 草图相关
  2507. this._initImageRela();
  2508. this.reBuildImData();
  2509. }
  2510. _initImTypeSetRela() {
  2511. const self = this;
  2512. const gatherConfirmPopover = {
  2513. reBind: function (obj, eventName, fun) {
  2514. obj.unbind(eventName);
  2515. obj.bind(eventName, fun);
  2516. },
  2517. check: function (pos, hint, okCallback) {
  2518. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2519. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2520. this.reBind(cancelObj, 'click', function () {
  2521. confirmObj.hide();
  2522. });
  2523. this.reBind(okObj, 'click', function () {
  2524. okCallback();
  2525. confirmObj.hide();
  2526. });
  2527. hintObj.text(hint);
  2528. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2529. }
  2530. };
  2531. this.gsTree = stageIm.getGsTree();
  2532. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2533. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2534. jlCol.title = '本期计量金额';
  2535. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2536. $('#type-title-contract').text('本期合同计量金额');
  2537. $('#type-title-qc').text('本期变更计量金额');
  2538. } else {
  2539. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2540. jlCol.title = '本期计量数量';
  2541. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2542. $('#type-title-contract').text('本期合同计量数量');
  2543. $('#type-title-qc').text('本期变更计量数量');
  2544. }
  2545. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2546. $('#show-jldy').parent().show();
  2547. $('#jldy').parent().show();
  2548. $('#show-xm-name').parent().hide();
  2549. $('#xm-name').parent().hide();
  2550. } else {
  2551. $('#show-jldy').parent().hide();
  2552. $('#jldy').parent().hide();
  2553. $('#show-xm-name').parent().show();
  2554. $('#xm-name').parent().show();
  2555. }
  2556. // 选择中间计量模式
  2557. $('div[name="im-type"]').click(function () {
  2558. function chooseType(obj) {
  2559. obj.style.cursor = 'default';
  2560. $(obj).children().addClass('text-primary');
  2561. $(obj).addClass('border-primary');
  2562. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2563. }
  2564. function validType(obj) {
  2565. obj.style.cursor = 'pointer';
  2566. $(obj).children().removeClass('text-primary');
  2567. $(obj).removeClass('border-primary');
  2568. $('i', obj).remove();
  2569. }
  2570. if (this.style.cursor === 'pointer') {
  2571. const typeArr = $('div[name="im-type"]');
  2572. for (const t of typeArr) {
  2573. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2574. chooseType(t);
  2575. } else {
  2576. validType(t)
  2577. }
  2578. }
  2579. }
  2580. });
  2581. $('#choose').on('show.bs.modal', function () {
  2582. function chooseType(obj) {
  2583. obj.style.cursor = 'default';
  2584. $(obj).children().addClass('text-primary');
  2585. $('i', obj).remove();
  2586. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2587. }
  2588. function validType(obj) {
  2589. obj.style.cursor = 'pointer';
  2590. $(obj).children().removeClass('text-primary');
  2591. $('i', obj).remove();
  2592. }
  2593. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2594. const typeArr = $('div[name="im-type"]');
  2595. for (const t of typeArr) {
  2596. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2597. chooseType(t);
  2598. } else {
  2599. validType(t)
  2600. }
  2601. }
  2602. });
  2603. // 提交 中间计量模式
  2604. $('#choose-ok').click(() => {
  2605. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2606. return it.style.cursor !== 'pointer';
  2607. });
  2608. const data = {
  2609. im_type: parseInt($(chooseType).attr('im-type')),
  2610. im_pre: $('#im-pre').val(),
  2611. };
  2612. postData(window.location.pathname + '/detail/build', data, function (result) {
  2613. stage.im_type = data.im_type;
  2614. stage.im_pre = data.im_pre;
  2615. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2616. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2617. jlCol.title = '本期计量金额';
  2618. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2619. $('#type-title-contract').text('本期合同计量金额');
  2620. $('#type-title-qc').text('本期变更计量金额');
  2621. } else {
  2622. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2623. jlCol.title = '本期计量数量';
  2624. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2625. $('#type-title-contract').text('本期合同计量数量');
  2626. $('#type-title-qc').text('本期变更计量数量');
  2627. }
  2628. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2629. $('#show-jldy').parent().show();
  2630. $('#jldy').parent().show();
  2631. $('#show-xm-name').parent().hide();
  2632. $('#xm-name').parent().hide();
  2633. } else {
  2634. $('#show-jldy').parent().hide();
  2635. $('#jldy').parent().hide();
  2636. $('#show-xm-name').parent().show();
  2637. $('#xm-name').parent().show();
  2638. }
  2639. // 加载生成数据
  2640. self.reBuildImData();
  2641. $('#choose').modal('hide');
  2642. });
  2643. });
  2644. // 显示树结构信息
  2645. $('#choose2').on('shown.bs.modal', function () {
  2646. if (!self.gsSpread) {
  2647. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2648. const setting = {
  2649. cols: [
  2650. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2651. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2652. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2653. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2654. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2655. ],
  2656. headRows: 1,
  2657. emptyRows: 0,
  2658. headRowHeight: [32],
  2659. defaultRowHeight: 21,
  2660. headerFont: '12px 微软雅黑',
  2661. font: '12px 微软雅黑',
  2662. };
  2663. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2664. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2665. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2666. function checkParent(node) {
  2667. const parent = self.gsTree.getParent(node);
  2668. if (parent) {
  2669. return parent.check ? parent.check : checkParent(parent);
  2670. } else {
  2671. return false;
  2672. }
  2673. }
  2674. function checkChildren(node) {
  2675. for (const child of node.children) {
  2676. if (child.check) {
  2677. return true;
  2678. } else if (checkChildren(child)) {
  2679. return true;
  2680. }
  2681. }
  2682. return false;
  2683. }
  2684. if (!$('#im-gather-check')[0].checked) { return; }
  2685. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2686. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2687. if (sheet.isEditing()) {
  2688. sheet.endEdit(true);
  2689. }
  2690. }
  2691. if (info.sheet.zh_setting) {
  2692. const col = info.sheet.zh_setting.cols[info.col];
  2693. if (col.field !== 'check') {
  2694. return;
  2695. }
  2696. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2697. const node = sortData[info.row];
  2698. if (!node.check) {
  2699. if (checkParent(node)) {
  2700. const rect = info.sheet.getCellRect(info.row, info.col);
  2701. gatherConfirmPopover.check({
  2702. x: rect.x + rect.width / 2 + 25,
  2703. y: rect.y + rect.height / 2 + 3,
  2704. }, '父项已勾选,继续将取消父项勾选。', function () {
  2705. node.check = true;
  2706. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2707. const rows = [self.gsTree.nodes.indexOf(node)];
  2708. for (const p of parents) {
  2709. if (p.check) {
  2710. p.check = false;
  2711. rows.push(self.gsTree.nodes.indexOf(p));
  2712. }
  2713. }
  2714. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2715. });
  2716. } else if (checkChildren(node)) {
  2717. const rect = info.sheet.getCellRect(info.row, info.col);
  2718. gatherConfirmPopover.check({
  2719. x: rect.x + rect.width / 2 + 25,
  2720. y: rect.y + rect.height / 2 + 3,
  2721. }, '子项已勾选,继续将取消子项勾选。', function () {
  2722. node.check = true;
  2723. const posterity = self.gsTree.getPosterity(node);
  2724. const rows = [self.gsTree.nodes.indexOf(node)];
  2725. for (const p of posterity) {
  2726. if (p.check) {
  2727. rows.push(self.gsTree.nodes.indexOf(p));
  2728. p.check = false;
  2729. }
  2730. }
  2731. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2732. });
  2733. } else {
  2734. node.check = true;
  2735. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2736. }
  2737. } else {
  2738. node.check = false;
  2739. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2740. }
  2741. }
  2742. });
  2743. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2744. for (const node of self.gsTree.datas) {
  2745. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2746. }
  2747. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2748. self.gsTree.expandByLevel(4);
  2749. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2750. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2751. } else {
  2752. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2753. for (const node of self.gsTree.datas) {
  2754. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2755. }
  2756. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2757. }
  2758. });
  2759. // 提交 高级设置
  2760. $('#choose2-ok').click(() => {
  2761. if (!self.gsTree) { return; }
  2762. const nodes = [];
  2763. for (const node of self.gsTree.datas) {
  2764. if (node.check) {
  2765. nodes.push(node.id);
  2766. }
  2767. }
  2768. const data = {
  2769. im_gather: $('#im-gather-check')[0].checked,
  2770. im_gather_node: nodes.join(','),
  2771. };
  2772. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2773. stage.im_gather = data.im_gather;
  2774. stage.im_gather_node = data.im_gather_node;
  2775. $('#choose2').modal('hide');
  2776. });
  2777. });
  2778. }
  2779. _initLocateRela() {
  2780. const self = this;
  2781. $('#im-locate2bills').click(function () {
  2782. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2783. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2784. if (select && select.source) {
  2785. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2786. stagePosSpreadObj.loadCurPosData();
  2787. }
  2788. });
  2789. $('#im-locate-pre').click(function () {
  2790. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2791. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2792. if (select && select.source) {
  2793. const targetIndex = math.max(curIndex-1, 1);
  2794. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2795. stagePosSpreadObj.loadCurPosData();
  2796. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2797. }
  2798. });
  2799. $('#im-locate-next').click(function () {
  2800. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2801. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2802. if (select && select.source) {
  2803. const targetIndex = math.min(curIndex+1, select.source.length);
  2804. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2805. stagePosSpreadObj.loadCurPosData();
  2806. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2807. }
  2808. });
  2809. }
  2810. _initModifyDetail() {
  2811. const self = this;
  2812. // 重置
  2813. $('#reset-detail-ok').click(function () {
  2814. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2815. if (!data.uuid) return;
  2816. const updateData = {
  2817. lid: data.lid, pid: data.pid,
  2818. uuid: data.uuid,
  2819. custom_define: [],
  2820. };
  2821. for (const f of data.custom_define) {
  2822. if (stageIm.resetFields.indexOf(f) >= 0) {
  2823. updateData[f] = null;
  2824. } else {
  2825. updateData.custom_define.push(f);
  2826. }
  2827. }
  2828. updateData.custom_define = updateData.custom_define.join(',');
  2829. $('#reset-detail-modal').modal('hide');
  2830. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2831. stageIm.loadUpdateDetailData(result);
  2832. self.reLoadDetailData();
  2833. });
  2834. });
  2835. // 编辑
  2836. $('#edit-detail').click(function () {
  2837. $(this).hide();
  2838. $('#save-detail').show();
  2839. $('#cancel-detail').show();
  2840. $('#detail-show').hide();
  2841. $('#detail-edit').show();
  2842. self.updateImageData = null;
  2843. });
  2844. // 保存
  2845. $('#save-detail').click(() => {
  2846. function check(field, obj, org, update) {
  2847. const newValue = obj.val();
  2848. if (!org[field]) {
  2849. if (newValue !== '') {
  2850. update[field] = newValue;
  2851. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2852. return true;
  2853. }
  2854. } else if (newValue !== org[field]){
  2855. update[field] = newValue;
  2856. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2857. return true;
  2858. }
  2859. return false;
  2860. }
  2861. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2862. const updateData = {lid: data.lid, pid: data.pid};
  2863. if (data.uuid) {
  2864. updateData.uuid = data.uuid;
  2865. updateData.custom_define = data.custom_define;
  2866. } else {
  2867. updateData.code = data.code;
  2868. updateData.name = data.name;
  2869. updateData.unit = data.unit;
  2870. updateData.unit_price = data.unit_price;
  2871. updateData.pid = data.pid;
  2872. updateData.pos_name = data.pos_name;
  2873. updateData.custom_define = [];
  2874. }
  2875. let infoUpdate = false;
  2876. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  2877. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  2878. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  2879. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  2880. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  2881. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  2882. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  2883. updateData.custom_define = updateData.custom_define.join(',');
  2884. if (infoUpdate) {
  2885. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2886. stageIm.loadUpdateDetailData(result);
  2887. self.reLoadDetailData();
  2888. if (!self.updateImageData) return;
  2889. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  2890. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2891. stageIm.loadUpdateDetailData(result);
  2892. self.reLoadDetailData();
  2893. });
  2894. });
  2895. } else if (self.updateImageData) {
  2896. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2897. stageIm.loadUpdateDetailData(result);
  2898. self.reLoadDetailData();
  2899. });
  2900. } else {
  2901. self.reLoadDetailData();
  2902. }
  2903. });
  2904. // 取消
  2905. $('#cancel-detail').click(() => {
  2906. self.reLoadDetailData();
  2907. });
  2908. }
  2909. _initImageRela() {
  2910. const self = this;
  2911. $('#edit-detail').click(function () {
  2912. loadImageItem();
  2913. });
  2914. function setdraggrable(){
  2915. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2916. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2917. stop: function( event, ui ) {
  2918. }
  2919. });
  2920. }
  2921. function upload(formData) {
  2922. if (formData.length < 1) {
  2923. return;
  2924. }
  2925. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2926. const html = [];
  2927. html.push('<div class="img-item">');
  2928. html.push('<div class="img-bar">');
  2929. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2930. html.push('</div>');
  2931. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2932. html.push('</div>');
  2933. $('.img-view').append(html.join(''));
  2934. $('.img-bar').click(removeImageItem);
  2935. setdraggrable();
  2936. $('#upload-img-file').val('');
  2937. });
  2938. }
  2939. function dragFile(e) {
  2940. var file = null,
  2941. data = e.dataTransfer.types;
  2942. for (var i = 0; i < data.length; i += 1) {
  2943. if (data[i] === 'Files') {
  2944. file = e.dataTransfer.files; //获取文件
  2945. break;
  2946. }
  2947. }
  2948. if (file && file[0].type.indexOf('image') !== -1) {
  2949. var formData = new FormData();
  2950. formData.append('file', file[0]); //上传单个文件的添加方式
  2951. upload(formData); //upload 异步上传
  2952. }
  2953. }
  2954. // 移动图片
  2955. const moveImageItem = function (ev) {
  2956. const item = this;
  2957. const view = $('.img-view')[0];
  2958. let oEvent = ev;
  2959. // 浏览器有一些图片的默认事件,这里要阻止
  2960. oEvent.preventDefault();
  2961. let disX = oEvent.clientX - item.offsetLeft;
  2962. let disY = oEvent.clientY - item.offsetTop;
  2963. view.onmousemove = function (ev) {
  2964. oEvent = ev;
  2965. oEvent.preventDefault();
  2966. let x = oEvent.clientX -disX;
  2967. let y = oEvent.clientY -disY;
  2968. // 图形移动的边界判断
  2969. x = x <= 0 ? 0 : x;
  2970. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2971. y = y <= 0 ? 0 : y;
  2972. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2973. item.style.left = x + 'px';
  2974. item.style.top = y + 'px';
  2975. };
  2976. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2977. view.onmouseleave = function () {
  2978. view.onmousemove = null;
  2979. view.onmouseup = null;
  2980. };
  2981. // 鼠标弹起后停止移动
  2982. view.onmouseup=function() {
  2983. view.onmousemove = null;
  2984. view.onmouseup = null;
  2985. };
  2986. };
  2987. const removeImageItem = function () {
  2988. $(this).parent().remove();
  2989. };
  2990. // 加载草图组成
  2991. const loadImageItem = function () {
  2992. self.updateImageData = null;
  2993. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2994. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2995. const html = [];
  2996. for (const item of items) {
  2997. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2998. html.push('<div class="img-item" style="' + itemStyle + '">');
  2999. html.push('<div class="img-bar">');
  3000. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3001. html.push('</div>');
  3002. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3003. html.push('</div>');
  3004. }
  3005. $('.img-view').html(html.join(''));
  3006. $('.img-bar').click(removeImageItem);
  3007. setdraggrable();
  3008. };
  3009. // 上传图片
  3010. $('#upload-img').click(function () {
  3011. $('#upload-img-file').trigger('click');
  3012. });
  3013. // 拖拽上传
  3014. //拖拽上传文件
  3015. const dragbox = document.querySelector('#upload-img');
  3016. dragbox.addEventListener('dragover', function(e) {
  3017. e.preventDefault(); // 必须阻止默认事件
  3018. }, false);
  3019. dragbox.addEventListener('drop', function(e) {
  3020. e.preventDefault(); // 阻止默认事件
  3021. dragFile(e);
  3022. }, false);
  3023. //拖拽上传文件
  3024. const dragbox2 = document.querySelector('.img-view');
  3025. dragbox2.addEventListener('dragover', function(e) {
  3026. e.preventDefault(); // 必须阻止默认事件
  3027. }, false);
  3028. dragbox2.addEventListener('drop', function(e) {
  3029. e.preventDefault(); // 阻止默认事件
  3030. dragFile(e);
  3031. }, false);
  3032. // 粘贴上传
  3033. $(".img-view").on('paste', function(ev) {
  3034. let file = null;
  3035. const data = (event.clipboardData || window.clipboardData).items;
  3036. for (let i = 0; i < data.length; i += 1) {
  3037. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3038. file = data[i].getAsFile(); //读取图片文件
  3039. break;
  3040. }
  3041. }
  3042. if (file) {
  3043. const formData = new FormData();
  3044. formData.append('file', file); //上传单个文件的添加方式
  3045. upload(formData); //异步上传文件
  3046. }
  3047. });
  3048. $('#upload-img-file').change(function () {
  3049. const file = this.files[0];
  3050. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3051. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3052. if (!imgStr.test(ext)) {
  3053. toastr.error('请上传正确的图片格式文件');
  3054. return
  3055. }
  3056. if ($(this).val()) {
  3057. const formData = new FormData();
  3058. formData.append('file', this.files[0]);
  3059. upload(formData);
  3060. }
  3061. });
  3062. // 保存草图修改结果
  3063. $('#edit-img-ok').click(function () {
  3064. // 记录上传的图片的信息
  3065. const items = $('.img-item');
  3066. const img_remark = $('#text-edit').val();
  3067. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3068. if (items.length > 0) {
  3069. const itemInfo = [];
  3070. for (const item of items) {
  3071. const itemData = {
  3072. src: $('img', item).attr('src'),
  3073. left: item.style.left,
  3074. top: item.style.top,
  3075. width: item.style.width,
  3076. height: item.style.height,
  3077. };
  3078. itemInfo.push(itemData);
  3079. }
  3080. // 获取合并好的图片数据
  3081. const canvas = document.createElement('canvas');
  3082. const view = $('.img-view')[0];
  3083. canvas.height = view.clientHeight;
  3084. canvas.width = view.clientWidth;
  3085. const ctx = canvas.getContext('2d');
  3086. ctx.fillStyle = '#ffffff';
  3087. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3088. for (const b of $('.img-item')) {
  3089. const pos = $(b).position();
  3090. const img = $('img', b)[0];
  3091. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3092. }
  3093. // 生成上传数据
  3094. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  3095. if (data.uuid) {
  3096. updateData.uuid = data.uuid;
  3097. } else {
  3098. updateData.code = data.code;
  3099. updateData.name = data.name;
  3100. updateData.unit = data.unit;
  3101. updateData.unit_price = data.unit_price;
  3102. updateData.pid = data.pid;
  3103. updateData.pos_name = data.pos_name;
  3104. }
  3105. updateData.img = canvas.toDataURL('image/png');
  3106. updateData.imgInfo = itemInfo;
  3107. updateData.calc_img_remark = img_remark;
  3108. self.updateImageData = updateData;
  3109. $('#calc-img').attr('src', updateData.img);
  3110. $('#view-calc-img').attr('src', updateData.img);
  3111. $('#show-calc-img').attr('src', updateData.img);
  3112. $('#view-calc-remark').text(img_remark);
  3113. $('#edit-img').modal('hide');
  3114. // updateImageData = updateData;
  3115. // $('#edit-img').modal('hide');
  3116. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  3117. // stageIm.loadUpdateDetailData(result);
  3118. // data.calc_img = result.calc_img;
  3119. // data.calc_img_org = result.calc_img_org;
  3120. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3121. // $('#show-calc-img').attr('src', calcImgSrc);
  3122. // $('#calc-img').attr('src', calcImgSrc);
  3123. // $('#view-calc-img').attr('src', calcImgSrc);
  3124. // $('#edit-img').modal('hide');
  3125. // });
  3126. } else if (data.calc_img) {
  3127. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid};
  3128. $('#show-calc-img').attr('src', '');
  3129. $('#calc-img').attr('src', '');
  3130. $('#view-calc-img').attr('src', '');
  3131. $('#view-calc-remark').val('');
  3132. $('#text-edit').val('');
  3133. $('#edit-img').modal('hide');
  3134. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  3135. // stageIm.loadUpdateDetailData(result);
  3136. // data.calc_img = result.calc_img;
  3137. // data.calc_img_org = result.calc_img_org;
  3138. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3139. // $('#show-calc-img').attr('src', calcImgSrc);
  3140. // $('#calc-img').attr('src', calcImgSrc);
  3141. // $('#view-calc-img').attr('src', calcImgSrc);
  3142. // $('#edit-img').modal('hide');
  3143. // });
  3144. } else {
  3145. self.updateImageData = null;
  3146. $('#show-calc-img').attr('src', '');
  3147. $('#calc-img').attr('src', '');
  3148. $('#view-calc-img').attr('src', '');
  3149. $('#view-calc-remark').val('');
  3150. $('#text-edit').val('');
  3151. $('#edit-img').modal('hide');
  3152. }
  3153. });
  3154. }
  3155. reBuildImData() {
  3156. const imData = stageIm.buildImData();
  3157. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3158. this.reLoadDetailData();
  3159. this.loadLocateInfo();
  3160. }
  3161. loadStageLedgerUpdateData(data, nodes) {
  3162. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3163. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3164. this.reLoadDetailData();
  3165. }
  3166. loadStagePosUpdateData(data, nodes) {
  3167. const imData = stageIm.loadUpdatePosData(data, nodes);
  3168. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3169. this.reLoadDetailData();
  3170. }
  3171. loadStageChangeUpdateData(data, nodes) {
  3172. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3173. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3174. this.reLoadDetailData();
  3175. }
  3176. loadLocateInfo() {
  3177. const select = SpreadJsObj.getSelectObject(this.sheet);
  3178. if (select && select.source.length > 1) {
  3179. $('#im-locate2bills').next().show();
  3180. } else {
  3181. $('#im-locate2bills').next().hide();
  3182. }
  3183. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3184. }
  3185. reLoadDetailData() {
  3186. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3187. $('#reset-detail').hide();
  3188. if (data) {
  3189. for (const f of data.custom_define) {
  3190. if (stageIm.resetFields.indexOf(f) >= 0) {
  3191. $('#reset-detail').show();
  3192. break;
  3193. }
  3194. }
  3195. $('#edit-detail').show();
  3196. $('#modify-img').show();
  3197. } else {
  3198. $('#edit-detail').hide();
  3199. $('#modify-img').hide();
  3200. }
  3201. $('#save-detail').hide();
  3202. $('#cancel-detail').hide();
  3203. $('#detail-show').show();
  3204. $('#detail-edit').hide();
  3205. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3206. $('#show-contract-jl').text(contractJl);
  3207. $('#contract-jl').val(contractJl);
  3208. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3209. $('#show-qc-jl').text(qcJl);
  3210. $('#qc-jl').val(qcJl);
  3211. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3212. $('#show-bgl-code').text(bglCode);
  3213. $('#bgl-code').val(bglCode);
  3214. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3215. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3216. $('#bgl-drawing-code').val(bglDrawingCode);
  3217. const bwName = data && data.bw ? data.bw : '';
  3218. $('#show-bw-name').text(bwName);
  3219. $('#bw-name').val(bwName);
  3220. const position = data && data.position ? data.position : '';
  3221. $('#show-position').text(position);
  3222. $('#position').val(position);
  3223. const peg = data && data.peg ? data.peg : '';
  3224. $('#show-peg').text(peg);
  3225. $('#peg').val(peg);
  3226. const xmName = data && data.xm ? data.xm: '';
  3227. $('#show-xm-name').text(xmName);
  3228. $('#xm-name').val(xmName);
  3229. const jldy = data && data.jldy ? data.jldy: '';
  3230. $('#show-jldy').text(jldy);
  3231. $('#jldy').val(jldy);
  3232. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3233. $('#show-drawing-code').text(drawingCode);
  3234. $('#drawing-code').val(drawingCode);
  3235. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3236. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3237. $('#calc-memo').val(calcMemo);
  3238. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3239. $('#show-calc-img').attr('src', calcImgSrc);
  3240. $('#calc-img').attr('src', calcImgSrc);
  3241. $('#view-calc-img').attr('src', calcImgSrc);
  3242. const calcImgRemark = data && data.calc_img_remark || '';
  3243. $('#view-calc-remark').val(calcImgRemark);
  3244. $("#view-calc-remark").attr('readonly', true);
  3245. // 处理 编辑 -> 添加草图中textarea多余的空格
  3246. $('#text-edit').val(calcImgRemark)
  3247. }
  3248. }
  3249. class CheckedChange {
  3250. constructor (setting) {
  3251. const self = this;
  3252. this.changeSpreadSetting = {
  3253. cols: [
  3254. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  3255. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3256. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3257. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3258. ],
  3259. emptyRows: 0,
  3260. headRows: 1,
  3261. headRowHeight: [32],
  3262. headColWidth: [30],
  3263. defaultRowHeight: 21,
  3264. headerFont: '12px 微软雅黑',
  3265. font: '12px 微软雅黑',
  3266. readOnly: true,
  3267. };
  3268. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3269. this.changeSheet = this.changeSpread.getActiveSheet();
  3270. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3271. const getTipText = function (data) {
  3272. if (!data) return '';
  3273. const tips = [];
  3274. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3275. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3276. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3277. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3278. return tips.join('-');
  3279. };
  3280. this.changeBillsSpreadSetting = {
  3281. cols: [
  3282. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', cellType: 'tip', getTip: getTipText},
  3283. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'tip', getTip: getTipText},
  3284. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'tip', getTip: getTipText},
  3285. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', cellType: 'tip', getTip: getTipText},
  3286. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3287. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3288. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: getTipText},
  3289. ],
  3290. emptyRows: 0,
  3291. headRows: 1,
  3292. headRowHeight: [32],
  3293. defaultRowHeight: 21,
  3294. headerFont: '12px 微软雅黑',
  3295. font: '12px 微软雅黑',
  3296. readOnly: true
  3297. };
  3298. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3299. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3300. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3301. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3302. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3303. if (change.cid === self.curChangeId) { return; }
  3304. self.curChangeId = change.cid;
  3305. if (change.detail) {
  3306. self.loadChangeDetailData();
  3307. } else {
  3308. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  3309. change.detail = result;
  3310. self.analyzeChange(change);
  3311. self.loadChangeDetailData();
  3312. });
  3313. }
  3314. });
  3315. this.changes = null;
  3316. this.reloadChangeData();
  3317. setting.reloadObj.click(function() {
  3318. self.reloadChangeData();
  3319. });
  3320. $.contextMenu({
  3321. selector: '#' + setting.changeBillsObj.attr('id'),
  3322. build: function ($trigger, e) {
  3323. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3324. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3325. },
  3326. items: {
  3327. 'locateZjjl': {
  3328. name: '定位至台账',
  3329. icon: 'fa-sign-in',
  3330. callback: function (key, opt) {
  3331. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3332. if (changeBills.gcl_id) {
  3333. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3334. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3335. stagePosSpreadObj.loadCurPosData();
  3336. } else {
  3337. const cb = {
  3338. b_code: changeBills.code || '',
  3339. name: changeBills.name || '',
  3340. unit: changeBills.unit || '',
  3341. unit_price: changeBills.unit_price || 0,
  3342. };
  3343. for (const node of stageTree.nodes) {
  3344. if (node.children && node.children.length > 0) continue;
  3345. const b = {
  3346. b_code: node.b_code || '',
  3347. name: node.name || '',
  3348. unit: node.unit || '',
  3349. unit_price: node.unit_price || 0,
  3350. };
  3351. if (_.isMatch(cb, b)) {
  3352. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3353. stagePosSpreadObj.loadCurPosData();
  3354. return;
  3355. }
  3356. }
  3357. }
  3358. },
  3359. disabled: function (key, opt) {
  3360. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3361. return !changeBills;
  3362. }
  3363. },
  3364. }
  3365. });
  3366. }
  3367. loadChangeDetailData() {
  3368. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  3369. if (change) {
  3370. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3371. } else {
  3372. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3373. }
  3374. }
  3375. refresh() {
  3376. this.changeSpread.refresh();
  3377. this.changeBillsSpread.refresh();
  3378. }
  3379. reloadChangeData() {
  3380. const self = this;
  3381. postData(window.location.pathname + '/change/data', null, function (result) {
  3382. self.changes = result.changes;
  3383. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3384. self.changeSheet.setSelection(0, 0, 1, 1);
  3385. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  3386. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3387. self.loadChangeDetailData();
  3388. });
  3389. }
  3390. analyzeChange(change) {
  3391. change.bills = change.detail.bills;
  3392. for (const b of change.bills) {
  3393. const aub = change.detail.addUsedBills.find(function (x) {
  3394. return x.id === b.id;
  3395. });
  3396. if (aub) {
  3397. b.used_qty = aub.used_qty;
  3398. }
  3399. b.qty = _.toNumber(b.samount);
  3400. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3401. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3402. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3403. b.cur_qty = 0;
  3404. for (const p of b.pos) {
  3405. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3406. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3407. }
  3408. }
  3409. }
  3410. }
  3411. // 展开收起附件
  3412. $('a', '.right-nav').bind('click', function () {
  3413. //const main = $('#main-view'), tool = $('#tools-view');
  3414. const tab = $(this), tabPanel = $(tab.attr('content'));
  3415. if (!tab.hasClass('active')) {
  3416. $('a', '.side-menu').removeClass('active');
  3417. $('.tab-content .tab-select-show').removeClass('active');
  3418. tab.addClass('active');
  3419. tabPanel.addClass('active');
  3420. showSideTools(tab.hasClass('active'));
  3421. if (tab.attr('content') === '#search' && !searchLedger) {
  3422. searchLedger = $.billsSearch({
  3423. selector: '#search',
  3424. searchSpread: slSpread,
  3425. searchRangeStr: '项目节编号/名称',
  3426. searchOver: true,
  3427. searchEmpty: true,
  3428. resultSpreadSetting: {
  3429. cols: [
  3430. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3431. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3432. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3433. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3434. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3435. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3436. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  3437. ],
  3438. emptyRows: 0,
  3439. headRows: 1,
  3440. headRowHeight: [32],
  3441. headColWidth: [30],
  3442. defaultRowHeight: 21,
  3443. headerFont: '12px 微软雅黑',
  3444. font: '12px 微软雅黑',
  3445. selectedBackColor: '#fffacd',
  3446. },
  3447. afterLocated: function () {
  3448. stagePosSpreadObj.loadCurPosData();
  3449. },
  3450. customSearch: [
  3451. {
  3452. key: 'less', title: '漏计', valid: true,
  3453. check: function (node) {
  3454. if (node.quantity) {
  3455. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3456. } else if (node.total_price) {
  3457. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3458. }
  3459. }
  3460. }, {
  3461. key: 'over', title: '超计', valid: true,
  3462. check: function (node) {
  3463. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3464. }
  3465. }, {
  3466. key: 'empty', title: '漏计', valid: false,
  3467. check: function (node) {
  3468. if (node.quantity) {
  3469. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3470. } else if (node.total_price) {
  3471. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3472. }
  3473. }
  3474. }, {
  3475. key: 'estimate', title: '预计变更', valid: true,
  3476. check: function (node) {
  3477. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3478. if (posRange.length > 0) {
  3479. for (const p of posRange) {
  3480. if (!checkZero(p.estimate_qty)) return true;
  3481. }
  3482. return false;
  3483. } else {
  3484. return false;
  3485. }
  3486. }
  3487. }
  3488. ],
  3489. });
  3490. searchLedger.spread.refresh();
  3491. }
  3492. if (tab.attr('content') === '#fujian') {
  3493. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3494. getNodeList(node.id);
  3495. }
  3496. if (tab.attr('content') === '#zhongjian') {
  3497. if (!detail) {
  3498. detail = new Detail($('#detail-spread'));
  3499. detail.spread.refresh();
  3500. $('#zhongjian .sjs-bottom').height('400px');
  3501. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3502. } else {
  3503. detail.spread.refresh();
  3504. }
  3505. }
  3506. if (tab.attr('content') === '#checked-change') {
  3507. if (!checkedChanges) {
  3508. checkedChanges = new CheckedChange({
  3509. changeObj: $('#cc-spread'),
  3510. changeBillsObj: $('#ccb-spread'),
  3511. reloadObj: $('#refresh-cc'),
  3512. });
  3513. checkedChanges.refresh();
  3514. } else {
  3515. $('#ccb-spread').height('400px');
  3516. checkedChanges.refresh();
  3517. }
  3518. }
  3519. if (tab.attr('content') === '#error-list') {
  3520. errorList.spread.refresh();
  3521. }
  3522. if (tab.attr('content') === '#check-list') {
  3523. checkList.spread.refresh();
  3524. }
  3525. } else {
  3526. tab.removeClass('active');
  3527. tabPanel.removeClass('active');
  3528. showSideTools(tab.hasClass('active'));
  3529. }
  3530. slSpread.refresh();
  3531. spSpread.refresh();
  3532. });
  3533. // 切换附件里节点和所有附件
  3534. $('#fujian .nav-link').on('click', function () {
  3535. const tabPanel = $(this).attr('fujian-content');
  3536. if (tabPanel !== 'syfujian') {
  3537. $('#showPage').hide();
  3538. $('#bach-download').prop('type', 'curr');
  3539. } else {
  3540. $('#showPage').show();
  3541. $('#bach-download').prop('type', 'all')
  3542. }
  3543. $('#showAttachment').hide();
  3544. });
  3545. // 上传附件
  3546. $('#upload-file-btn').click(function () {
  3547. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3548. // return toastr.error('当前操作没有权限!');
  3549. // }
  3550. const files = $('#upload-file')[0].files;
  3551. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3552. const formData = new FormData();
  3553. formData.append('lid', node.id);
  3554. for (const file of files) {
  3555. if (file === undefined) {
  3556. toastr.error('未选择上传文件!');
  3557. return false;
  3558. }
  3559. const filesize = file.size;
  3560. if (filesize > 30 * 1024 * 1024) {
  3561. toastr.error('存在上传文件大小过大!');
  3562. return false;
  3563. }
  3564. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3565. if (whiteList.indexOf(fileext) === -1) {
  3566. toastr.error('只能上传指定格式的附件!');
  3567. return false;
  3568. }
  3569. formData.append('size', filesize);
  3570. formData.append('file[]', file);
  3571. }
  3572. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3573. $('#upload').modal('hide');
  3574. // 插入到attData中
  3575. attData = data.concat(attData);
  3576. // 重新生成List
  3577. getAllList();
  3578. getNodeList(node.id);
  3579. }, function () {
  3580. toastr.error('附件上传失败');
  3581. });
  3582. $('#upload-file').val('');
  3583. });
  3584. // 获取附件信息
  3585. $('.list-table').on('click', '.att-file-name', function () {
  3586. const fid = $(this).attr('file-id');
  3587. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3588. return;
  3589. }
  3590. const att = attData.find(function (item) {
  3591. return item.id === parseInt(fid);
  3592. });
  3593. $('#edit-att').hide();
  3594. $('#show-att').show();
  3595. if (att !== undefined) {
  3596. // 进来先把编辑功能隐藏
  3597. $('#btn-att a').eq(3).hide()
  3598. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3599. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3600. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3601. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3602. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3603. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3604. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3605. $('#show-att tr').eq(3).children('td').text(att.remark);
  3606. // 附件uid等于当前用户id, 附件上传本人
  3607. if (parseInt(cur_uid) === att.uid) {
  3608. $('#btn-att').show();
  3609. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3610. // if (!curAuditor) {
  3611. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3612. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3613. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3614. // } else {
  3615. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3616. // }
  3617. if (showDel) $('#btn-att a').eq(3).show();
  3618. // $('#btn-att a').eq(3).show();
  3619. $('#btn-att a').eq(2).hide();
  3620. $('#btn-att a').eq(4).hide();
  3621. $('#btn-att a').eq(5).hide();
  3622. } else {
  3623. $('#btn-att').hide();
  3624. $('#btn-att a').eq(3).hide();
  3625. $('#btn-att a').eq(2).hide();
  3626. $('#btn-att a').eq(4).hide();
  3627. $('#btn-att a').eq(5).hide();
  3628. }
  3629. $('#showAttachment').attr('file-id', fid);
  3630. $('#showAttachment').show();
  3631. } else {
  3632. $('#showAttachment').hide();
  3633. $('#showAttachment').attr('file-id', '');
  3634. toastr.error('附件信息获取失败');
  3635. }
  3636. });
  3637. // $('body').on('click', '.alllist-table a', handleFileList);
  3638. $('body').on('click', '#btn-att a', function () {
  3639. const content = $(this).attr('content');
  3640. const fid = $('#showAttachment').attr('file-id');
  3641. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3642. if (content === 'edit') {
  3643. $('#btn-att a').eq(3).hide();
  3644. $('#btn-att a').eq(2).show();
  3645. $('#btn-att a').eq(4).show();
  3646. $('#btn-att a').eq(5).show();
  3647. $('#show-att').hide();
  3648. $('#edit-att').show();
  3649. const att = attData.find(function (item) {
  3650. return item.id === parseInt(fid);
  3651. });
  3652. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3653. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3654. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3655. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3656. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3657. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3658. } else if (content === 'cancel') {
  3659. $('#show-att').show();
  3660. $('#edit-att').hide();
  3661. $('#btn-att a').eq(3).show();
  3662. $('#btn-att a').eq(2).hide();
  3663. $('#btn-att a').eq(4).hide();
  3664. $('#btn-att a').eq(5).hide();
  3665. } else if (content === 'save') {
  3666. const formData = new FormData();
  3667. formData.append('id', fid);
  3668. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3669. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3670. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3671. const file = $('#change-att-btn')[0];
  3672. if (file.files[0] !== undefined) {
  3673. const filesize = file.files[0].size;
  3674. formData.append('size', filesize);
  3675. formData.append('file', file.files[0]);
  3676. }
  3677. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3678. // 替换到attData中
  3679. const att_index = attData.findIndex(function (item) {
  3680. return item.id === parseInt(fid);
  3681. });
  3682. attData.splice(att_index, 1, data);
  3683. // 重新生成List
  3684. getAllList(parseInt($('#currentPage').text()));
  3685. getNodeList(node.id);
  3686. $('#show-att').show();
  3687. $('#edit-att').hide();
  3688. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3689. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3690. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3691. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3692. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3693. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3694. $('#show-att tr').eq(4).children('td').text(data.remark);
  3695. $('#btn-att a').eq(3).show();
  3696. $('#btn-att a').eq(2).hide();
  3697. $('#btn-att a').eq(4).hide();
  3698. $('#btn-att a').eq(5).hide();
  3699. }, function () {
  3700. toastr.error('附件上传失败');
  3701. });
  3702. $('#change-att-btn').val('');
  3703. } else if (content === 'del') {
  3704. const data = {id: fid};
  3705. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3706. // 删除到attData中
  3707. const att_index = attData.findIndex(function (item) {
  3708. return item.id === parseInt(fid);
  3709. });
  3710. attData.splice(att_index, 1);
  3711. // 重新生成List
  3712. if ($('#alllist-table tr').length === 1) {
  3713. getAllList(parseInt($('#currentPage').text()) - 1);
  3714. } else {
  3715. getAllList(parseInt($('#currentPage').text()));
  3716. }
  3717. getNodeList(node.id);
  3718. $('#showAttachment').hide();
  3719. $('#showAttachment').attr('file-id', '');
  3720. });
  3721. } else if (content === 'view') {
  3722. const data = {id: fid};
  3723. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3724. const { filepath } = result
  3725. $('#load-file').attr('href', filepath);
  3726. $('#load-file')[0].click();
  3727. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3728. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3729. });
  3730. } else if (content === 'location') {
  3731. const att = attData.find(item => item.id === parseInt(fid));
  3732. if (Object.keys(att).length) {
  3733. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3734. stagePosSpreadObj.loadCurPosData();
  3735. }
  3736. }
  3737. });
  3738. // 替换附件
  3739. $('#change-att-btn').on('change', function () {
  3740. const file = $('#change-att-btn')[0].files[0];
  3741. const name = file.name;
  3742. const filename = name.substring(0, name.lastIndexOf("."));
  3743. const fileext = name.substr(name.indexOf("."));
  3744. const filesize = file.size;
  3745. if (filesize > 10 * 1024 * 1024) {
  3746. toastr.error('文件大小过大!');
  3747. $('#change-att-btn').val('');
  3748. return false;
  3749. }
  3750. if (whiteList.indexOf(fileext) === -1) {
  3751. toastr.error('只能上传指定格式的附件!');
  3752. $('#change-att-btn').val('');
  3753. return false;
  3754. }
  3755. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3756. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3757. });
  3758. // 切换页数
  3759. $('.page-select').on('click', function () {
  3760. const totalPageNum = parseInt($('#totalPage').text());
  3761. const lastPageNum = parseInt($('#currentPage').text());
  3762. const status = $(this).attr('content');
  3763. if (status === 'pre' && lastPageNum > 1) {
  3764. getAllList(lastPageNum-1);
  3765. $('#showAttachment').hide();
  3766. $('#syfujian .check-all-file').prop('checked', false)
  3767. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3768. getAllList(lastPageNum+1);
  3769. $('#showAttachment').hide();
  3770. $('#syfujian .check-all-file').prop('checked', false)
  3771. }
  3772. });
  3773. // 批量下载
  3774. $('#bach-download').click(function() {
  3775. const fileIds = [];
  3776. const type = $(this).prop('type');
  3777. let node = ''
  3778. if (type === 'curr') {
  3779. node = '#nodelist-table .check-file:checked'
  3780. } else {
  3781. node = '#alllist-table .check-file:checked'
  3782. }
  3783. $(node).each(function() {
  3784. const fileId = $(this).attr('file-id');
  3785. fileId && fileIds.push(fileId);
  3786. });
  3787. if (fileIds.length) {
  3788. const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  3789. $('#zipDown').attr('href', url);
  3790. $("#zipDown")[0].click();
  3791. }
  3792. });
  3793. // 监听附件check是否选中
  3794. $('.list-table').on('click', '.check-file', function() {
  3795. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3796. const childs = $(this).parents('.list-table').children().length;
  3797. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3798. if (checkedList.length === childs) {
  3799. checkBox.prop("checked", true);
  3800. } else {
  3801. checkBox.prop("checked", false);
  3802. }
  3803. });
  3804. $('.check-all-file').click(function() {
  3805. const isCheck = $(this).is(':checked');
  3806. $(this).parents('table').find('.list-table').each(function() {
  3807. $(this).find('input:checkbox').prop("checked", isCheck);
  3808. })
  3809. });
  3810. // 显示层次
  3811. (function (select, sheet) {
  3812. $(select).click(function () {
  3813. if (!sheet.zh_tree) return;
  3814. const tag = $(this).attr('tag');
  3815. const tree = sheet.zh_tree;
  3816. setTimeout(() => {
  3817. showWaitingView();
  3818. switch (tag) {
  3819. case "1":
  3820. case "2":
  3821. case "3":
  3822. case "4":
  3823. case "5":
  3824. tree.expandByLevel(parseInt(tag));
  3825. SpreadJsObj.refreshTreeRowVisible(sheet);
  3826. break;
  3827. case "last":
  3828. tree.expandByCustom(() => { return true; });
  3829. SpreadJsObj.refreshTreeRowVisible(sheet);
  3830. break;
  3831. case "leafXmj":
  3832. tree.expandToLeafXmj();
  3833. SpreadJsObj.refreshTreeRowVisible(sheet);
  3834. break;
  3835. case "curMeasure":
  3836. tree.expandByCustom(function (node) {
  3837. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3838. if (node[field]) {
  3839. return true;
  3840. }
  3841. }
  3842. return false;
  3843. });
  3844. SpreadJsObj.refreshTreeRowVisible(sheet);
  3845. break;
  3846. }
  3847. closeWaitingView();
  3848. }, 100);
  3849. });
  3850. })('a[name=showLevel]', slSpread.getActiveSheet());
  3851. const stageCheckerSetting = {
  3852. ledgerTree: stageTree,
  3853. ledgerPos: stagePos,
  3854. checkList: checkList,
  3855. decimal: tenderInfo.decimal,
  3856. checkOption: checkOption,
  3857. };
  3858. if (!checkTzMeasureType()) {
  3859. stageCheckerSetting.checkOption.calc.fields.push('sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity');
  3860. stageCheckerSetting.checkOption.tp.fields.push(
  3861. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  3862. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  3863. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  3864. {qty: 'quantity', tp: 'total_price'},
  3865. );
  3866. }
  3867. $('#ledger-check2').click(() => {
  3868. const result = ledgerCheck2(stageCheckerSetting);
  3869. check2Viewing({
  3870. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  3871. randomWait: true,
  3872. prefix: 'check2-',
  3873. checks: result,
  3874. checkList: checkList,
  3875. })
  3876. });
  3877. const dataChecker = DataChecker({
  3878. checkUrl: window.location.pathname + '/check',
  3879. completeData: function (data) {
  3880. stagePos.updateDatas({pos: data.source.pos});
  3881. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  3882. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  3883. stagePosSpreadObj.loadCurPosData();
  3884. for (const e of data.error) {
  3885. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  3886. }
  3887. },
  3888. errorList: errorList,
  3889. });
  3890. $('[name=stage-start]').submit(function (e) {
  3891. if (checkAuditorFrom()) {
  3892. // 再检查多人协同确认情况
  3893. const list = stageTree.pwd.find(x => {return !x.confirm });
  3894. if(list) {
  3895. toastr.error('请检查多人协同确认情况再上报');
  3896. $('#hide-all').hide();
  3897. return false;
  3898. }
  3899. $(this).parent().parent().parent().modal('hide');
  3900. dataChecker.checkAndPost(this.action, {});
  3901. $('#hide-all').hide();
  3902. }
  3903. return false;
  3904. });
  3905. $('#audit-check0').submit(function (e) {
  3906. // 再检查多人协同确认情况
  3907. const list = stageTree.pwd.find(x => {return !x.confirm });
  3908. if(list) {
  3909. toastr.error('请检查多人协同确认情况再审批通过');
  3910. $('#hide-all').hide();
  3911. return false;
  3912. }
  3913. const checkType = parseInt($('[name=checkType]').val());
  3914. const data = {
  3915. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3916. checkType,
  3917. };
  3918. $('#sp-done').modal('hide');
  3919. checkType && dataChecker.checkAndPost(this.action, data);
  3920. $('#hide-all').hide();
  3921. return false;
  3922. });
  3923. $('#audit-check1').submit(function (e) {
  3924. const checkType = parseInt($('[name=checkType]:checked').val());
  3925. const data = {
  3926. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3927. checkType,
  3928. };
  3929. if ($('#warning-text').length) $('#warning-text').remove()
  3930. if (!checkType && !$('#warning-text').length) {
  3931. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  3932. return false
  3933. }
  3934. $('#sp-back').modal('hide');
  3935. checkType && dataChecker.checkAndPost(this.action, data);
  3936. $('#hide-all').hide();
  3937. return false;
  3938. });
  3939. $('#exportExcel').click(function () {
  3940. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  3941. });
  3942. $('#cbr-check-all').click(function () {
  3943. if (this.checked) {
  3944. $('input', '#cbr-pos-list').attr('checked', 'checked');
  3945. } else {
  3946. $('input', '#cbr-pos-list').removeAttr('checked');
  3947. }
  3948. });
  3949. $('#cbr-ok').click(() => {
  3950. const ratio = parseInt($('#cbr-ratio').val());
  3951. if (!ratio) {
  3952. toastr.warning('请输入计量比例');
  3953. return;
  3954. } else if (ratio < 1) {
  3955. toastr.warning('计量比例不可小于1');
  3956. return;
  3957. } else if (ratio > 100) {
  3958. toastr.warning('计量比例不可大于100');
  3959. return;
  3960. }
  3961. const apply2sibling = $('#apply2sibling')[0].checked;
  3962. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  3963. if (posName.length === 0) {
  3964. toastr.warning('请勾选需要按计量比例的计量单元');
  3965. return;
  3966. }
  3967. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  3968. });
  3969. $('body').on('click', '[name=ledger-unlock]', function() {
  3970. $('#cooperation').modal('hide');
  3971. const lid = this.getAttribute('lid');
  3972. if (!lid) return;
  3973. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  3974. if (!p) return;
  3975. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  3976. $('#unlock-pwd').val('').removeClass('is-invalid');
  3977. $('.invalid-feedback', '#unlock').hide();
  3978. $('.alert-warning', '#unlock').hide();
  3979. $('#unlock-ok').attr('lid', lid);
  3980. $('#unlock').modal('show');
  3981. });
  3982. $('#unlock-ok').click(function () {
  3983. const lid = this.getAttribute('lid');
  3984. if (!lid) return;
  3985. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  3986. if (!p) return;
  3987. if (p.pwd === $('#unlock-pwd').val()) {
  3988. const refresh = stageTree.lockNode(p, false);
  3989. // 修改线上
  3990. postData(window.location.pathname + '/save/cooperation', { type: 'save-pwd', postData: { ledger_id: lid, pwd: $('#unlock-pwd').val() } }, function (result) {
  3991. stageTree.pwdList = result.cooperationPwd;
  3992. });
  3993. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  3994. stagePosSpreadObj.loadCurPosData();
  3995. $('#unlock').modal('hide');
  3996. reloadCooperationHtml();
  3997. } else {
  3998. $('#unlock-pwd').addClass('is-invalid');
  3999. $('.invalid-feedback', '#unlock').show();
  4000. $('.alert-warning', '#unlock').show();
  4001. }
  4002. });
  4003. $('#cooperationSelect').change(function () {
  4004. reloadCooperationHtml();
  4005. });
  4006. // 确认
  4007. $('body').on('click', '[name=ledger-confirm]', function() {
  4008. const lid = this.getAttribute('lid');
  4009. if (!lid) return;
  4010. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4011. if (!p) return;
  4012. // 修改线上
  4013. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4014. p.confirm = true;
  4015. p.confirm_time = new Date();
  4016. stageTree.confirmList = result.cooperationConfirm;
  4017. reloadCooperationHtml();
  4018. });
  4019. });
  4020. // 确认
  4021. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4022. const lid = this.getAttribute('lid');
  4023. if (!lid) return;
  4024. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4025. if (!p) return;
  4026. // 修改线上
  4027. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4028. p.confirm = false;
  4029. p.confirm_time = null;
  4030. stageTree.confirmList = result.cooperationConfirm;
  4031. reloadCooperationHtml();
  4032. });
  4033. });
  4034. });