stage.js 198 KB

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