stage.js 183 KB

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