stage.js 192 KB

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