stage.js 185 KB

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