stage.js 175 KB

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