stage.js 194 KB

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