stage.js 192 KB

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