stage.js 180 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  32. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  33. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  34. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  35. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  36. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  37. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  38. { title: '本期批注', fields: ['postil'], visible: true },
  39. { title: '图册号', fields: ['drawing_code'], visible: true },
  40. { title: '备注', fields: ['memo'], visible: true },
  41. { title: '总额计量', fields: ['is_tp'], visible: true},
  42. ];
  43. if (checkTzMeasureType()) {
  44. defaultSetting.splice(0, 1);
  45. }
  46. const settingStr = Cookies.get(ckColSetting);
  47. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  48. }
  49. /**
  50. * 根据列显示设置,调整setting中的列是否显示
  51. * @param setting
  52. * @param customDisplay
  53. */
  54. function customizeStageTreeSetting(setting, customDisplay) {
  55. for (const cd of customDisplay) {
  56. for (const c of setting.cols) {
  57. if (cd.fields.indexOf(c.field) !== -1) {
  58. c.visible = cd.visible;
  59. }
  60. }
  61. }
  62. }
  63. /**
  64. * 初始化 树结构 列事件
  65. * @param setting
  66. */
  67. function initTreeColSettingEvents(setting) {
  68. const Events = {
  69. readOnly: {
  70. measureData: function (node) {
  71. return node.children && node.children.length > 0;
  72. },
  73. },
  74. };
  75. const getEvent = function (eventName) {
  76. const names = eventName.split('.');
  77. let event = Events;
  78. for (let name of names) {
  79. if (event[name]) {
  80. event = event[name];
  81. } else {
  82. return null;
  83. }
  84. }
  85. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  86. return null;
  87. } else {
  88. return event;
  89. }
  90. };
  91. for (const col of setting.cols) {
  92. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  93. col.readOnly = getEvent(col.readOnly);
  94. }
  95. }
  96. }
  97. // 生成所有附件列表
  98. function getAllList(currPageNum = 1) {
  99. // 每页最多几个附件
  100. const pageCount = 15;
  101. // 附件总数
  102. const total = attData.length;
  103. // 总页数
  104. const pageNum = Math.ceil(total/pageCount);
  105. $('#totalPage').text(pageNum);
  106. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  107. // 当前页附件内容
  108. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  109. let html = '';
  110. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  111. for(const att of currPageAttData) {
  112. html += `<tr>
  113. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  114. <td>
  115. <div class="d-flex">
  116. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  117. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  118. </div>
  119. </td><td>${att.username}</td></tr>`
  120. }
  121. $('#alllist-table').html(html);
  122. $('#alllist-table').on('click', 'tr', function() {
  123. $('#alllist-table tr').removeClass('bg-light')
  124. $(this).addClass('bg-light')
  125. })
  126. }
  127. // 生成当前节点列表
  128. function getNodeList(node) {
  129. let html = '';
  130. for(const att of attData) {
  131. if (node === att.lid) {
  132. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  133. html += `<tr>
  134. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  135. <td>
  136. <div class="d-flex">
  137. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  138. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  139. </div>
  140. </td><td>${att.username}</td></tr>`
  141. }
  142. }
  143. $('#nodelist-table').html(html);
  144. $('#nodelist-table').on('click', 'tr', function() {
  145. $('#nodelist-table tr').removeClass('bg-light')
  146. $(this).addClass('bg-light')
  147. })
  148. }
  149. function getGxbyText(data) {
  150. const def = thirdParty.gxby.find(function (x) {
  151. return x.value === data.gxby_status;
  152. });
  153. return def ? def.name : '';
  154. }
  155. function getDaglText(data) {
  156. const def = thirdParty.dagl.find(function (x) {
  157. return x.value === data.dagl_status;
  158. });
  159. return def ? def.name : '';
  160. }
  161. $(document).ready(() => {
  162. let detail, searchLedger, checkedChanges;
  163. // 界面布局
  164. autoFlashHeight();
  165. // 初始化 台账树结构 数据结构
  166. const stageTreeSetting = {
  167. id: 'ledger_id',
  168. pid: 'ledger_pid',
  169. order: 'order',
  170. level: 'level',
  171. rootId: -1,
  172. keys: ['id', 'tender_id', 'ledger_id'],
  173. stageId: 'id',
  174. markFoldKey: 'bills-fold',
  175. markFoldSubKey: window.location.pathname.split('/')[2],
  176. };
  177. // 台账树结构计算相关设置
  178. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
  179. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  180. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  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. measureByBatch: function (posNames, ratio, apply2sibling) {
  1058. if (posNames.length <= 0) return;
  1059. if (ratio <= 0) return;
  1060. const sheet = slSpread.getActiveSheet();
  1061. const node = SpreadJsObj.getSelectObject(sheet);
  1062. const parent = stageTree.getParent(node);
  1063. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1064. const data = {updateType: 'batchUpdate', updateData: []};
  1065. for (const node of nodes) {
  1066. const posRange = stagePos.getLedgerPos(node.id);
  1067. if (!posRange || posRange <= 0) continue;
  1068. for (const p of posRange) {
  1069. if (posNames.indexOf(p.name) < 0) continue;
  1070. data.updateData.push({
  1071. pid: p.id, lid: p.lid,
  1072. contract_qty: ZhCalc.mul(p.quantity, ratio)
  1073. });
  1074. }
  1075. }
  1076. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1077. if (result.pos) {
  1078. stagePos.updateDatas(result.pos.pos);
  1079. stagePos.loadCurStageData(result.pos.curStageData);
  1080. }
  1081. const nodes = stageTree.loadPostStageData(result.ledger);
  1082. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1083. stagePosSpreadObj.loadCurPosData();
  1084. if (detail) {
  1085. detail.loadStagePosUpdateData(result);
  1086. } else {
  1087. stageIm.loadUpdatePosData(result);
  1088. }
  1089. $('#calc-by-ratio').modal('hide');
  1090. }, function () {
  1091. stagePosSpreadObj.loadCurPosData();
  1092. $('#calc-by-ratio').modal('hide');
  1093. });
  1094. }
  1095. };
  1096. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1097. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1098. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1099. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1100. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1101. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1102. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1103. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1104. if (!readOnly) {
  1105. $('#bills-expr').bind('change onblur', function () {
  1106. if (this.readOnly) return;
  1107. const expr = $(this);
  1108. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1109. const select = stageTree.getItemsByIndex(row);
  1110. if (!select) return;
  1111. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1112. let newValue = expr.val();
  1113. const num = _.toNumber(newValue);
  1114. if (_.isFinite(num)) {
  1115. newValue = num;
  1116. } else {
  1117. try {
  1118. newValue = math.evaluate(transExpr(newValue));
  1119. } catch(err) {
  1120. toastr.error('输入的表达式非法');
  1121. return;
  1122. }
  1123. }
  1124. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1125. if (field.indexOf('_dgn_') > 0) {
  1126. updateData.dgn = {
  1127. id: select.id
  1128. };
  1129. updateData.dgn[field] = newValue;
  1130. } else {
  1131. updateData.stage = {
  1132. lid: select.id
  1133. };
  1134. updateData.stage[field] = newValue;
  1135. const exprInfo = getExprInfo(field);
  1136. if (exprInfo) {
  1137. updateData.stage[exprInfo.expr] = expr.val();
  1138. }
  1139. }
  1140. // 更新至服务器
  1141. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1142. const nodes = stageTree.loadPostStageData(result);
  1143. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1144. });
  1145. });
  1146. }
  1147. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1148. $.contextMenu({
  1149. selector: '#stage-ledger',
  1150. build: function ($trigger, e) {
  1151. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1152. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1153. },
  1154. items: {
  1155. 'locateZjjl': {
  1156. name: '定位至中间计量',
  1157. icon: 'fa-sign-in',
  1158. callback: function (key, opt) {
  1159. if (!detail) {
  1160. detail = new Detail($('#detail-spread'));
  1161. }
  1162. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1163. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1164. if (leafUsedBills) {
  1165. if (!$('#zhongjian').hasClass('active')) {
  1166. const tab = $('#zhongjian'), tabPanel = $(tab.attr('content'));
  1167. $('a', '.side-menu').removeClass('active');
  1168. $('.tab-content .tab-select-show').removeClass('active');
  1169. tab.addClass('active');
  1170. tabPanel.addClass('active');
  1171. showSideTools(tab.hasClass('active'));
  1172. slSpread.refresh();
  1173. spSpread.refresh();
  1174. }
  1175. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1176. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1177. SpreadJsObj.locateData(detail.sheet, im);
  1178. detail.spread.refresh();
  1179. $('#zhongjian .sjs-bottom').height('400px');
  1180. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1181. detail.reLoadDetailData();
  1182. } else {
  1183. toastr.error('无可定位中间计量');
  1184. }
  1185. },
  1186. },
  1187. }
  1188. });
  1189. const stagePosSpreadObj = {
  1190. loadExprToInput(sheet) {
  1191. const sel = sheet.getSelections()[0];
  1192. if (!sel) return;
  1193. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1194. if (col && col.type === 'Number') {
  1195. const data = SpreadJsObj.getSelectObject(sheet);
  1196. if (data) {
  1197. const exprInfo = getExprInfo(col.field);
  1198. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1199. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1200. .attr('readOnly', readOnly || cell.locked());
  1201. $('#pos-expr').attr('data-row', sel.row);
  1202. } else {
  1203. $('#pos-expr').val('').attr('readOnly', true);
  1204. $('#pos-expr').removeAttr('data-row');
  1205. }
  1206. } else {
  1207. $('#pos-expr').val('').attr('readOnly', true);
  1208. $('#pos-expr').removeAttr('data-row');
  1209. }
  1210. },
  1211. /**
  1212. * 加载计量单元 根据当前台账选择节点
  1213. */
  1214. loadCurPosData: function () {
  1215. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1216. if (node) {
  1217. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1218. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1219. getNodeList(node.id);
  1220. // 如果是附件是当前节点,隐藏
  1221. // if ($('#dqjiedian').hasClass('active')) {
  1222. // $('#showAttachment').hide();
  1223. // }
  1224. } else {
  1225. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1226. }
  1227. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1228. },
  1229. editEnded: function (e, info) {
  1230. if (info.sheet.zh_setting) {
  1231. // 未改变过,则直接跳过
  1232. const sortData = info.sheet.zh_data;
  1233. const posData = sortData ? sortData[info.row] : null;
  1234. const col = info.sheet.zh_setting.cols[info.col];
  1235. const orgText = posData ? posData[col.field] : null;
  1236. const newText = trimInvalidChar(info.editingText);
  1237. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1238. return;
  1239. }
  1240. // 台账模式下,不可新增
  1241. if (checkTzMeasureType() && !posData) {
  1242. toastr.error('台账模式不可新增计量单元数据');
  1243. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1244. return ;
  1245. }
  1246. // 不同节点下,计量单元检查输入
  1247. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1248. const node = stagePosSpreadObj.stageTreeNode;
  1249. if (!node) {
  1250. toastr.warning('数据错误, 请刷新页面后再试');
  1251. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1252. return;
  1253. } else if (newText !== '' && node.children && node.children > 0) {
  1254. toastr.error('父节点不可插入计量单元');
  1255. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1256. return;
  1257. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1258. toastr.error('项目节不可插入计量单元');
  1259. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1260. return;
  1261. }
  1262. // 生成提交数据
  1263. const data = {};
  1264. if (col.field === 'name') {
  1265. if ((!newText || newText === '') && posData) {
  1266. toastr.error('部位名称不可为空');
  1267. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1268. return;
  1269. } else if (!posData) {
  1270. if (newText !== '') {
  1271. data.updateType = 'add';
  1272. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1273. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1274. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1275. return;
  1276. }
  1277. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1278. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1279. } else {
  1280. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1281. return;
  1282. }
  1283. } else {
  1284. data.updateType = 'update';
  1285. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1286. }
  1287. } else if (!posData) {
  1288. toastr.warning('新增计量单元请先输入名称');
  1289. } else {
  1290. data.updateType = 'update';
  1291. data.updateData = {pid: posData.id, lid: posData.lid};
  1292. if (col.type === 'Number') {
  1293. const exprInfo = getExprInfo(col.field);
  1294. const num = _.toNumber(newText);
  1295. if (_.isFinite(num)) {
  1296. data.updateData[col.field] = num;
  1297. if (exprInfo) {
  1298. data.updateData[exprInfo.expr] = '';
  1299. }
  1300. } else {
  1301. try {
  1302. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1303. if (exprInfo) {
  1304. data.updateData[exprInfo.expr] = newText;
  1305. }
  1306. } catch(err) {
  1307. toastr.error('输入的表达式非法');
  1308. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1309. return;
  1310. }
  1311. }
  1312. } else {
  1313. data.updateData[col.field] = newText;
  1314. }
  1315. }
  1316. // 提交数据到服务器
  1317. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1318. if (result.pos) {
  1319. stagePos.updateDatas(result.pos.pos);
  1320. stagePos.loadCurStageData(result.pos.curStageData);
  1321. }
  1322. const refreshData = stageTree.loadPostStageData(result.ledger);
  1323. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1324. stagePosSpreadObj.loadCurPosData();
  1325. if (detail) {
  1326. detail.loadStagePosUpdateData(result);
  1327. } else {
  1328. stageIm.loadUpdatePosData(result);
  1329. }
  1330. }, function () {
  1331. stagePosSpreadObj.loadCurPosData();
  1332. });
  1333. }
  1334. },
  1335. editStarting: function (e, info) {
  1336. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1337. const sel = info.sheet.getSelections();
  1338. if (!sel || !sel[0]) return;
  1339. const col = info.sheet.zh_setting.cols[sel[0].col];
  1340. const node = SpreadJsObj.getSelectObject(info.sheet);
  1341. const exprInfo = getExprInfo(col.field);
  1342. if (exprInfo) {
  1343. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1344. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1345. }
  1346. }
  1347. },
  1348. clipboardPasting: function (e, info) {
  1349. if (info.sheet.zh_setting) {
  1350. const sortData = info.sheet.zh_data;
  1351. const range = info.cellRange;
  1352. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty'];
  1353. if (!checkTzMeasureType()) {
  1354. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1355. }
  1356. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1357. const col = info.sheet.zh_setting.cols[iCol];
  1358. if (validField.indexOf(col.field) === -1) {
  1359. if (checkTzMeasureType()) {
  1360. toastr.error('不可修改此数据');
  1361. info.cancel = true;
  1362. return;
  1363. } else {
  1364. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1365. const pos = sortData(iRow);
  1366. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1367. toastr.error('不可修改此数据');
  1368. info.cancel = true;
  1369. return;
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. }
  1376. },
  1377. clipboardPasted: function (e, info) {
  1378. if (info.sheet.zh_setting) {
  1379. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1380. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1381. }
  1382. const data = { updateType: '', updateData: [], };
  1383. const sortData = info.sheet.zh_data;
  1384. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1385. if (sortData && (info.cellRange.row >= sortData.length)) {
  1386. data.updateType = 'add';
  1387. if (info.cellRange.col !== 0) {
  1388. toastr.warning('新增计量单元请先输入名称');
  1389. stagePosSpreadObj.loadCurPosData();
  1390. return;
  1391. }
  1392. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1393. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1394. stagePosSpreadObj.loadCurPosData();
  1395. return;
  1396. }
  1397. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1398. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1399. const curRow = info.cellRange.row + iRow;
  1400. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1401. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1402. const curCol = info.cellRange.col + iCol;
  1403. const colSetting = info.sheet.zh_setting.cols[curCol];
  1404. if (!colSetting) continue;
  1405. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1406. if (colSetting.type === 'Number') {
  1407. const num = _.toNumber(newValue);
  1408. if (num) {
  1409. newData[colSetting.field] = num;
  1410. } else {
  1411. try {
  1412. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1413. const exprInfo = getExprInfo(colSetting.field);
  1414. if (exprInfo) {
  1415. newData[exprInfo.expr] = newValue;
  1416. }
  1417. } catch(err) {
  1418. toastr.error('输入的表达式非法');
  1419. stagePosSpreadObj.loadCurPosData();
  1420. return;
  1421. }
  1422. }
  1423. } else {
  1424. newData[colSetting.field] = newValue;
  1425. }
  1426. }
  1427. data.updateData.push(newData);
  1428. }
  1429. } else {
  1430. data.updateType = 'update';
  1431. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1432. const curRow = info.cellRange.row + iRow;
  1433. const curPos = sortData[curRow];
  1434. if (curPos) {
  1435. const newData = {pid: curPos.id, lid: curPos.lid};
  1436. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1437. const curCol = info.cellRange.col + iCol;
  1438. const colSetting = info.sheet.zh_setting.cols[curCol];
  1439. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1440. if (colSetting.type === 'Number') {
  1441. const num = _.toNumber(newValue);
  1442. if (num) {
  1443. newData[colSetting.field] = num;
  1444. } else {
  1445. try {
  1446. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1447. const exprInfo = getExprInfo(colSetting.field);
  1448. if (exprInfo) {
  1449. newData[exprInfo.expr] = newValue;
  1450. }
  1451. } catch(err) {
  1452. toastr.error('输入的表达式非法');
  1453. stagePosSpreadObj.loadCurPosData();
  1454. return;
  1455. }
  1456. }
  1457. } else {
  1458. newData[colSetting.field] = newValue;
  1459. }
  1460. }
  1461. data.updateData.push(newData);
  1462. }
  1463. }
  1464. }
  1465. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1466. if (result.pos) {
  1467. stagePos.updateDatas(result.pos.pos);
  1468. stagePos.loadCurStageData(result.pos.curStageData);
  1469. }
  1470. const nodes = stageTree.loadPostStageData(result.ledger);
  1471. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1472. stagePosSpreadObj.loadCurPosData();
  1473. if (detail) {
  1474. detail.loadStagePosUpdateData(result);
  1475. } else {
  1476. stageIm.loadUpdatePosData(result);
  1477. }
  1478. }, function () {
  1479. stagePosSpreadObj.loadCurPosData();
  1480. });
  1481. }
  1482. },
  1483. deletePress: function (sheet) {
  1484. if (sheet.zh_setting && sheet.zh_data) {
  1485. const sortData = sheet.zh_data;
  1486. if (!sortData || sortData.length === 0) { return; }
  1487. const sel = sheet.getSelections()[0];
  1488. const validCols = [];
  1489. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1490. const colSetting = sheet.zh_setting.cols[iCol];
  1491. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1492. validCols.push(iCol);
  1493. }
  1494. }
  1495. if (validCols.length === 0) { return; }
  1496. const datas = [], posSelects = [];
  1497. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1498. const node = sortData[iRow];
  1499. if (node) {
  1500. const data = {pid: node.id, lid: node.lid};
  1501. for (const iCol of validCols) {
  1502. const colSetting = sheet.zh_setting.cols[iCol];
  1503. if (colSetting.field === 'name') {
  1504. toastr.error('部位名称不能为空');
  1505. return;
  1506. }
  1507. data[colSetting.field] = null;
  1508. const exprInfo = getExprInfo(colSetting.field);
  1509. if (exprInfo) {
  1510. data[exprInfo.expr] = '';
  1511. }
  1512. }
  1513. datas.push(data);
  1514. posSelects.push(node);
  1515. }
  1516. }
  1517. if (datas.length > 0) {
  1518. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1519. if (result.pos) {
  1520. stagePos.updateDatas(result.pos.pos);
  1521. stagePos.loadCurStageData(result.pos.curStageData);
  1522. }
  1523. const nodes = stageTree.loadPostStageData(result.ledger);
  1524. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1525. if (detail) {
  1526. detail.loadStagePosUpdateData(result);
  1527. } else {
  1528. stageIm.loadUpdatePosData(result);
  1529. }
  1530. // todo 只加载改变项
  1531. stagePosSpreadObj.loadCurPosData();
  1532. });
  1533. }
  1534. }
  1535. },
  1536. deletePos: function (sheet) {
  1537. const sels = sheet.getSelections();
  1538. const sel = sels ? sels[0] : null;
  1539. if (sheet.zh_data && sel) {
  1540. const data = {updateType: 'delete', updateData: []};
  1541. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1542. const posData = sheet.zh_data[sel.row + iRow];
  1543. if (posData) {
  1544. data.updateData.push(posData.id);
  1545. }
  1546. }
  1547. if (data.updateData.length > 0) {
  1548. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1549. stagePos.removeDatas(result.pos.pos);
  1550. const refreshData = stageTree.loadPostStageData(result.ledger);
  1551. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1552. stagePosSpreadObj.loadCurPosData();
  1553. if (detail) {
  1554. detail.loadStagePosUpdateData(result);
  1555. } else {
  1556. stageIm.loadUpdatePosData(result);
  1557. }
  1558. });
  1559. }
  1560. }
  1561. },
  1562. selectionChanged: function (e, info) {
  1563. stagePosSpreadObj.loadExprToInput(info.sheet);
  1564. },
  1565. addPegs: function (pegs) {
  1566. if (!pegs || pegs.length <= 0) return;
  1567. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1568. if (!node) return;
  1569. const sheet = spSpread.getActiveSheet();
  1570. const sortData = sheet.zh_data || [];
  1571. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1572. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1573. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1574. if (result.pos) {
  1575. stagePos.updateDatas(result.pos.pos);
  1576. }
  1577. stagePosSpreadObj.loadCurPosData();
  1578. });
  1579. }
  1580. };
  1581. // 加载上下窗口resizer
  1582. $.divResizer({
  1583. select: '#main-resize',
  1584. callback: function () {
  1585. slSpread.refresh();
  1586. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1587. $(".sp-wrap").height(bcontent-30);
  1588. spSpread.refresh();
  1589. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1590. }
  1591. });
  1592. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1593. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change' }, function (result) {
  1594. // 加载树结构
  1595. stageTree.loadDatas(result.ledgerData);
  1596. // stageTree.loadCurStageData(curStageData);
  1597. // stageTree.loadPreStageData(preStageData);
  1598. treeCalc.calculateAll(stageTree);
  1599. // 加载部位明细
  1600. stagePos.loadDatas(result.posData);
  1601. stagePos.calculateAll();
  1602. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1603. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1604. stagePosSpreadObj.loadCurPosData();
  1605. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1606. // 加载中间计量
  1607. stageIm.init(stage, imType, tenderInfo.decimal);
  1608. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1609. errorList.loadHisErrorData();
  1610. checkList.loadHisCheckData();
  1611. }, null, true);
  1612. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1613. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1614. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1615. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1616. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1617. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1618. if (!readOnly) {
  1619. $('#pos-expr').bind('change onblur', function () {
  1620. if (this.readOnly) return;
  1621. const expr = $(this);
  1622. const posSheet = spSpread.getActiveSheet();
  1623. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1624. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1625. if (!select) return;
  1626. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  1627. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1628. const data = {pid: select.id, lid: select.lid};
  1629. const exprInfo = getExprInfo(field);
  1630. if (newValue !== '') {
  1631. const num = _.toNumber(newValue);
  1632. if (num) {
  1633. data[field] = num;
  1634. if (exprInfo) data[exprInfo.expr] = '';
  1635. } else {
  1636. try {
  1637. data[field] = math.evaluate(transExpr(newValue));
  1638. if (exprInfo) data[exprInfo.expr] = newValue;
  1639. } catch (err) {
  1640. toastr.error('输入的表达式非法');
  1641. return;
  1642. }
  1643. }
  1644. } else {
  1645. data[field] = null;
  1646. if (exprInfo) data[exprInfo.expr] = '';
  1647. }
  1648. // 提交数据到服务器
  1649. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1650. if (result.pos) {
  1651. stagePos.updateDatas(result.pos.pos);
  1652. stagePos.loadCurStageData(result.pos.curStageData);
  1653. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1654. }
  1655. const refreshData = stageTree.loadPostStageData(result.ledger);
  1656. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1657. });
  1658. });
  1659. }
  1660. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1661. $.contextMenu({
  1662. selector: '#stage-pos',
  1663. build: function ($trigger, e) {
  1664. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1665. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1666. },
  1667. items: {
  1668. 'del': {
  1669. name: '删除',
  1670. icon: 'fa-remove',
  1671. visible: function (key, opt) {
  1672. return !checkTzMeasureType();
  1673. },
  1674. disabled: function (key, opt) {
  1675. const sheet = spSpread.getActiveSheet();
  1676. if (sheet.zh_data && !readOnly) {
  1677. const selection = sheet.getSelections();
  1678. if (selection && selection[0]) {
  1679. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1680. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1681. const posData = sheet.zh_data[selection[0].row + iRow];
  1682. if (posData) {
  1683. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1684. valid = true;
  1685. break;
  1686. }
  1687. } else {
  1688. valid = true;
  1689. break;
  1690. }
  1691. }
  1692. return valid;
  1693. } else {
  1694. return true;
  1695. }
  1696. } else {
  1697. return true;
  1698. }
  1699. },
  1700. callback: function (key, opt) {
  1701. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1702. }
  1703. },
  1704. 'merge-peg': {
  1705. name: '合并起讫桩号',
  1706. visible: function (key, opt) {
  1707. return !checkTzMeasureType();
  1708. },
  1709. disabled: function (key, opt) {
  1710. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1711. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1712. },
  1713. callback: function (key, opt) {
  1714. mergePeg.show();
  1715. }
  1716. },
  1717. 'calcByRatio': {
  1718. name: '按比例计量',
  1719. visible: function (key, opt) {
  1720. const data = spSpread.getActiveSheet().zh_data;
  1721. return data && data.length > 0;
  1722. },
  1723. callback: function (key, opt) {
  1724. $('#cbr-ratio').val('');
  1725. $('#apply2sibling')[0].checked = false;
  1726. $('#cbr-check-all')[0].checked = false;
  1727. const html = [];
  1728. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  1729. html.push('<tr>');
  1730. html.push('<td>', i, '</td>');
  1731. html.push('<td>', p.name, '</td>');
  1732. html.push('<td>', p.quantity, '</td>');
  1733. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  1734. html.push('</tr>');
  1735. }
  1736. $('#cbr-pos-list').html(html.join(''));
  1737. $('#calc-by-ratio').modal('show');
  1738. }
  1739. }
  1740. }
  1741. });
  1742. $.subMenu({
  1743. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1744. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1745. key: 'menu.1.0.0',
  1746. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1747. callback: function (info) {
  1748. if (info.mini) {
  1749. $('.panel-title').addClass('fluid');
  1750. $('#sub-menu').removeClass('panel-sidebar');
  1751. } else {
  1752. $('.panel-title').removeClass('fluid');
  1753. $('#sub-menu').addClass('panel-sidebar');
  1754. }
  1755. autoFlashHeight();
  1756. slSpread.refresh();
  1757. spSpread.refresh();
  1758. if (searchLedger) {
  1759. searchLedger.spread.refresh();
  1760. }
  1761. if (detail) {
  1762. detail.spread.refresh();
  1763. }
  1764. if (checkedChanges) checkedChanges.refresh();
  1765. if (errorList && errorList.spread) {
  1766. errorList.spread.refresh();
  1767. }
  1768. if (checkList) {
  1769. checkList.spread.refresh();
  1770. }
  1771. }
  1772. });
  1773. $('#row-view').on('show.bs.modal', function () {
  1774. const html = [], customDisplay = customColDisplay();
  1775. for (const cd of customDisplay) {
  1776. html.push('<tr>');
  1777. html.push('<td>', cd.title, '</td>');
  1778. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1779. html.push('</tr>');
  1780. }
  1781. $('#row-view-list').html(html.join(''));
  1782. });
  1783. $('#row-view-ok').click(function () {
  1784. const customDisplay = customColDisplay();
  1785. const cvl = $('#row-view-list').children();
  1786. for (const cv of cvl) {
  1787. const title = $(cv).children()[0].innerHTML;
  1788. const check = $('input', cv)[0].checked;
  1789. const cd = customDisplay.find(function (c) {
  1790. return c.title === title;
  1791. });
  1792. cd.visible = check;
  1793. }
  1794. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1795. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1796. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1797. $('#row-view').modal('hide');
  1798. });
  1799. const posSearch = (function () {
  1800. let resultArr = [];
  1801. const search = function () {
  1802. resultArr = [];
  1803. const keyword = $('#pos-search-keyword').val();
  1804. const checkOver = $('#pos-over-search')[0].checked;
  1805. const checkEmpty = $('#pos-empty-search')[0].checked;
  1806. const sortData = spSpread.getActiveSheet().zh_data;
  1807. if (checkOver || checkEmpty) {
  1808. if (sortData) {
  1809. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1810. const sd = sortData[i];
  1811. let match = false;
  1812. if (checkOver) {
  1813. if (sd.end_gather_qty) {
  1814. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1815. }
  1816. }
  1817. if (checkEmpty) {
  1818. if (sd.quantity) {
  1819. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1820. }
  1821. }
  1822. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1823. if (match) {
  1824. resultArr.push({index: i, data: sd});
  1825. }
  1826. }
  1827. }
  1828. } else if (keyword && keyword !== '') {
  1829. if (sortData) {
  1830. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1831. const sd = sortData[i];
  1832. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1833. resultArr.push({index: i, data: sd});
  1834. }
  1835. }
  1836. }
  1837. }
  1838. $('#pos-search-result').html('结果:' + resultArr.length);
  1839. };
  1840. const searchAndLocate = function () {
  1841. search();
  1842. if (resultArr.length > 0) {
  1843. const sheet = spSpread.getActiveSheet();
  1844. const sel = sheet.getSelections()[0];
  1845. const curRow = sel ? sel.row : 0;
  1846. const pos = resultArr[0];
  1847. if (pos.index !== curRow) {
  1848. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1849. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1850. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  1851. }
  1852. }
  1853. };
  1854. const locateNext = function () {
  1855. if (resultArr.length > 0) {
  1856. const sheet = spSpread.getActiveSheet();
  1857. const sel = sheet.getSelections()[0];
  1858. const curRow = sel ? sel.row : 0;
  1859. let next = _.find(resultArr, function (d) {
  1860. return d.index > curRow;
  1861. });
  1862. if (!next) next = resultArr[0];
  1863. if (next.index !== curRow) {
  1864. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1865. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1866. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1867. }
  1868. }
  1869. };
  1870. const locatePre = function () {
  1871. if (resultArr.length > 0) {
  1872. const sheet = spSpread.getActiveSheet();
  1873. const sel = sheet.getSelections()[0];
  1874. const curRow = sel ? sel.row : 0;
  1875. let next = _.findLast(resultArr, function (d) {
  1876. return d.index < curRow;
  1877. });
  1878. if (!next) next = resultArr[resultArr.length - 1];
  1879. if (next.index !== curRow) {
  1880. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1881. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1882. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1883. }
  1884. }
  1885. };
  1886. return {search, searchAndLocate, locateNext, locatePre};
  1887. })();
  1888. $('#pos-search-keyword').bind('keydown', function(e){
  1889. if (e.keyCode == 13) posSearch.searchAndLocate();
  1890. });
  1891. $('#pos-empty-search').click(function () {
  1892. if (this.checked) {
  1893. $('[for=' + this.id +']').addClass('text-warning');
  1894. } else {
  1895. $('[for=' + this.id +']').removeClass('text-warning');
  1896. }
  1897. if (this.checked) {
  1898. if ($('#pos-over-search')[0].checked) {
  1899. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1900. } else {
  1901. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1902. }
  1903. } else {
  1904. if ($('#pos-over-search')[0].checked) {
  1905. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1906. } else {
  1907. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1908. }
  1909. }
  1910. posSearch.searchAndLocate();
  1911. });
  1912. $('#pos-over-search').click(function () {
  1913. if (this.checked) {
  1914. $('[for=' + this.id +']').addClass('text-danger');
  1915. } else {
  1916. $('[for=' + this.id +']').removeClass('text-danger');
  1917. }
  1918. if (this.checked) {
  1919. if ($('#pos-empty-search')[0].checked) {
  1920. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1921. } else {
  1922. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1923. }
  1924. } else {
  1925. if ($('#pos-empty-search')[0].checked) {
  1926. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1927. } else {
  1928. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1929. }
  1930. }
  1931. posSearch.searchAndLocate();
  1932. });
  1933. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1934. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1935. $.divResizer({
  1936. select: '#right-spr',
  1937. callback: function () {
  1938. slSpread.refresh();
  1939. spSpread.refresh();
  1940. if (searchLedger) {
  1941. searchLedger.spread.refresh();
  1942. }
  1943. if (detail) {
  1944. detail.spread.refresh();
  1945. }
  1946. if (checkedChanges) checkedChanges.refresh();
  1947. if (errorList && errorList.spread) {
  1948. errorList.spread.refresh();
  1949. }
  1950. if (checkList) {
  1951. checkList.spread.refresh();
  1952. }
  1953. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1954. }
  1955. });
  1956. // 中间计量加载上下窗口resizer
  1957. $.divResizer({
  1958. select: '#zhongjian-spr',
  1959. callback: function () {
  1960. if (detail) {
  1961. detail.spread.refresh();
  1962. }
  1963. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1964. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1965. }
  1966. });
  1967. // 附件加载上下窗口resizer
  1968. $.divResizer({
  1969. select: '#file-spr',
  1970. callback: function () {
  1971. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1972. }
  1973. });
  1974. // 变更令加载上下窗口resizer
  1975. $.divResizer({
  1976. select: '#change-spr',
  1977. callback: function () {
  1978. if (checkedChanges) checkedChanges.refresh();
  1979. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1980. }
  1981. });
  1982. class Detail {
  1983. constructor (obj) {
  1984. const self = this;
  1985. this.spreadSetting = {
  1986. cols: [
  1987. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1988. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1989. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1990. {
  1991. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1992. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1993. },
  1994. ],
  1995. headRows: 1,
  1996. emptyRows: 0,
  1997. headRowHeight: [32],
  1998. headColWidth: [30],
  1999. defaultRowHeight: 21,
  2000. headerFont: '12px 微软雅黑',
  2001. font: '12px 微软雅黑',
  2002. readOnly: readOnly,
  2003. selectedBackColor: '#fffacd',
  2004. };
  2005. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2006. this.sheet = this.spread.getActiveSheet();
  2007. this.spread.options.allowUserDragFill = true;
  2008. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2009. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2010. this.detailObj = {
  2011. selectionChanged: function (e, info) {
  2012. self.reLoadDetailData();
  2013. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2014. self.loadLocateInfo();
  2015. }
  2016. },
  2017. editEnded: function(e, info) {
  2018. if (info.sheet.zh_setting) {
  2019. const col = info.sheet.zh_setting.cols[info.col];
  2020. if (col.field !== 'doc_code') {
  2021. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2022. return;
  2023. }
  2024. const data = SpreadJsObj.getSelectObject(info.sheet);
  2025. if (data) {
  2026. const updateData = {lid: data.lid, pid: data.pid};
  2027. if (data.uuid) {
  2028. updateData.uuid = data.uuid;
  2029. } else {
  2030. updateData.code = data.code;
  2031. updateData.name = data.name;
  2032. updateData.unit = data.unit;
  2033. updateData.unit_price = data.unit_price;
  2034. updateData.pid = data.pid;
  2035. updateData.pos_name = data.pos_name;
  2036. }
  2037. if (data.custom_define.indexOf('doc_code') === -1) {
  2038. updateData.custom_define = data.custom_define;
  2039. updateData.custom_define.push('doc_code');
  2040. updateData.custom_define = updateData.custom_define.join(',');
  2041. }
  2042. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2043. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2044. stageIm.loadUpdateDetailData(result);
  2045. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2046. }, function () {
  2047. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2048. });
  2049. } else {
  2050. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2051. }
  2052. }
  2053. },
  2054. clipboardPasted: function (e, info) {
  2055. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2056. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2057. if (info.cellRange.colCount > 1) {
  2058. toastr.warning('请勿同时复制粘贴多列数据');
  2059. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2060. return;
  2061. }
  2062. if (col.field !== 'doc_code') {
  2063. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2064. return;
  2065. }
  2066. const datas = [];
  2067. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2068. const curRow = info.cellRange.row + iRow;
  2069. const data = info.sheet.zh_data[curRow];
  2070. if (data) {
  2071. const updateData = {lid: data.lid, pid: data.pid};
  2072. if (data.uuid) {
  2073. updateData.uuid = data.uuid;
  2074. } else {
  2075. updateData.code = data.code;
  2076. updateData.name = data.name;
  2077. updateData.unit = data.unit;
  2078. updateData.unit_price = data.unit_price;
  2079. updateData.pid = data.pid;
  2080. updateData.pos_name = data.pos_name;
  2081. }
  2082. if (data.custom_define.indexOf('doc_code') === -1) {
  2083. updateData.custom_define = data.custom_define;
  2084. updateData.custom_define.push('doc_code');
  2085. updateData.custom_define = updateData.custom_define.join(',');
  2086. }
  2087. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2088. datas.push(updateData);
  2089. }
  2090. }
  2091. if (datas.length > 0) {
  2092. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2093. stageIm.loadUpdateDetailData(result);
  2094. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2095. }, function () {
  2096. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2097. })
  2098. }
  2099. }
  2100. },
  2101. deletePress: function (sheet) {
  2102. if (sheet.zh_setting) {
  2103. const datas = [];
  2104. const sel = sheet.getSelections()[0];
  2105. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2106. const col = sheet.zh_setting.cols[iCol];
  2107. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2108. const data = sheet.zh_data[iRow];
  2109. if (col.field === 'doc_code') {
  2110. const updateData = {lid: data.lid};
  2111. if (data.uuid) {
  2112. updateData.uuid = data.uuid;
  2113. updateData.doc_code = '';
  2114. datas.push(updateData);
  2115. }
  2116. }
  2117. }
  2118. }
  2119. if (datas.length > 0) {
  2120. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2121. stageIm.loadUpdateDetailData(result);
  2122. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2123. }, function () {
  2124. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2125. });
  2126. }
  2127. }
  2128. },
  2129. dragFillBlock: function (e, info) {
  2130. info.cancel = true;
  2131. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2132. const sel = info.sheet.getSelections()[0];
  2133. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2134. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2135. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2136. if (text === '') return;
  2137. const regRst = /(\d+)$/g.exec(text), datas = [];
  2138. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2139. const curRow = info.fillRange.row + iRow;
  2140. const data = info.sheet.zh_data[curRow];
  2141. if (data) {
  2142. const updateData = {lid: data.lid};
  2143. if (data.uuid) {
  2144. updateData.uuid = data.uuid;
  2145. } else {
  2146. updateData.code = data.code;
  2147. updateData.name = data.name;
  2148. updateData.unit = data.unit;
  2149. updateData.unit_price = data.unit_price;
  2150. updateData.pid = data.pid;
  2151. updateData.pos_name = data.pos_name;
  2152. }
  2153. if (regRst) {
  2154. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2155. } else {
  2156. updateData.doc_code = text.replace('\n', '');
  2157. }
  2158. if (data.custom_define.indexOf('doc_code') === -1) {
  2159. updateData.custom_define = data.custom_define;
  2160. updateData.custom_define.push('doc_code');
  2161. updateData.custom_define = updateData.custom_define.join(',');
  2162. }
  2163. datas.push(updateData);
  2164. }
  2165. }
  2166. if (datas.length > 0) {
  2167. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2168. stageIm.loadUpdateDetailData(result);
  2169. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2170. }, function () {
  2171. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2172. })
  2173. }
  2174. },
  2175. };
  2176. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2177. if (!readOnly) {
  2178. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2179. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2180. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2181. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2182. }
  2183. this._initImTypeSetRela();
  2184. this._initModifyDetail();
  2185. this._initLocateRela();
  2186. // 草图相关
  2187. this._initImageRela();
  2188. this.reBuildImData();
  2189. }
  2190. _initImTypeSetRela() {
  2191. const self = this;
  2192. const gatherConfirmPopover = {
  2193. reBind: function (obj, eventName, fun) {
  2194. obj.unbind(eventName);
  2195. obj.bind(eventName, fun);
  2196. },
  2197. check: function (pos, hint, okCallback) {
  2198. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2199. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2200. this.reBind(cancelObj, 'click', function () {
  2201. confirmObj.hide();
  2202. });
  2203. this.reBind(okObj, 'click', function () {
  2204. okCallback();
  2205. confirmObj.hide();
  2206. });
  2207. hintObj.text(hint);
  2208. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2209. }
  2210. };
  2211. this.gsTree = stageIm.getGsTree();
  2212. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2213. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2214. jlCol.title = '本期计量金额';
  2215. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2216. $('#type-title-contract').text('本期合同计量金额');
  2217. $('#type-title-qc').text('本期变更计量金额');
  2218. } else {
  2219. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2220. jlCol.title = '本期计量数量';
  2221. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2222. $('#type-title-contract').text('本期合同计量数量');
  2223. $('#type-title-qc').text('本期变更计量数量');
  2224. }
  2225. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2226. $('#show-jldy').parent().show();
  2227. $('#jldy').parent().show();
  2228. $('#show-xm-name').parent().hide();
  2229. $('#xm-name').parent().hide();
  2230. } else {
  2231. $('#show-jldy').parent().hide();
  2232. $('#jldy').parent().hide();
  2233. $('#show-xm-name').parent().show();
  2234. $('#xm-name').parent().show();
  2235. }
  2236. // 选择中间计量模式
  2237. $('div[name="im-type"]').click(function () {
  2238. function chooseType(obj) {
  2239. obj.style.cursor = 'default';
  2240. $(obj).children().addClass('text-primary');
  2241. $(obj).addClass('border-primary');
  2242. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2243. }
  2244. function validType(obj) {
  2245. obj.style.cursor = 'pointer';
  2246. $(obj).children().removeClass('text-primary');
  2247. $(obj).removeClass('border-primary');
  2248. $('i', obj).remove();
  2249. }
  2250. if (this.style.cursor === 'pointer') {
  2251. const typeArr = $('div[name="im-type"]');
  2252. for (const t of typeArr) {
  2253. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2254. chooseType(t);
  2255. } else {
  2256. validType(t)
  2257. }
  2258. }
  2259. }
  2260. });
  2261. $('#choose').on('show.bs.modal', function () {
  2262. function chooseType(obj) {
  2263. obj.style.cursor = 'default';
  2264. $(obj).children().addClass('text-primary');
  2265. $('i', obj).remove();
  2266. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2267. }
  2268. function validType(obj) {
  2269. obj.style.cursor = 'pointer';
  2270. $(obj).children().removeClass('text-primary');
  2271. $('i', obj).remove();
  2272. }
  2273. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2274. const typeArr = $('div[name="im-type"]');
  2275. for (const t of typeArr) {
  2276. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2277. chooseType(t);
  2278. } else {
  2279. validType(t)
  2280. }
  2281. }
  2282. });
  2283. // 提交 中间计量模式
  2284. $('#choose-ok').click(() => {
  2285. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2286. return it.style.cursor !== 'pointer';
  2287. });
  2288. const data = {
  2289. im_type: parseInt($(chooseType).attr('im-type')),
  2290. im_pre: $('#im-pre').val(),
  2291. };
  2292. postData(window.location.pathname + '/detail/build', data, function (result) {
  2293. stage.im_type = data.im_type;
  2294. stage.im_pre = data.im_pre;
  2295. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2296. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2297. jlCol.title = '本期计量金额';
  2298. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2299. $('#type-title-contract').text('本期合同计量金额');
  2300. $('#type-title-qc').text('本期变更计量金额');
  2301. } else {
  2302. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2303. jlCol.title = '本期计量数量';
  2304. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2305. $('#type-title-contract').text('本期合同计量数量');
  2306. $('#type-title-qc').text('本期变更计量数量');
  2307. }
  2308. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2309. $('#show-jldy').parent().show();
  2310. $('#jldy').parent().show();
  2311. $('#show-xm-name').parent().hide();
  2312. $('#xm-name').parent().hide();
  2313. } else {
  2314. $('#show-jldy').parent().hide();
  2315. $('#jldy').parent().hide();
  2316. $('#show-xm-name').parent().show();
  2317. $('#xm-name').parent().show();
  2318. }
  2319. // 加载生成数据
  2320. self.reBuildImData();
  2321. $('#choose').modal('hide');
  2322. });
  2323. });
  2324. // 显示树结构信息
  2325. $('#choose2').on('shown.bs.modal', function () {
  2326. if (!self.gsSpread) {
  2327. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2328. const setting = {
  2329. cols: [
  2330. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2331. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2332. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2333. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2334. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2335. ],
  2336. headRows: 1,
  2337. emptyRows: 0,
  2338. headRowHeight: [32],
  2339. defaultRowHeight: 21,
  2340. headerFont: '12px 微软雅黑',
  2341. font: '12px 微软雅黑',
  2342. };
  2343. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2344. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2345. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2346. function checkParent(node) {
  2347. const parent = self.gsTree.getParent(node);
  2348. if (parent) {
  2349. return parent.check ? parent.check : checkParent(parent);
  2350. } else {
  2351. return false;
  2352. }
  2353. }
  2354. function checkChildren(node) {
  2355. for (const child of node.children) {
  2356. if (child.check) {
  2357. return true;
  2358. } else if (checkChildren(child)) {
  2359. return true;
  2360. }
  2361. }
  2362. return false;
  2363. }
  2364. if (!$('#im-gather-check')[0].checked) { return; }
  2365. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2366. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2367. if (sheet.isEditing()) {
  2368. sheet.endEdit(true);
  2369. }
  2370. }
  2371. if (info.sheet.zh_setting) {
  2372. const col = info.sheet.zh_setting.cols[info.col];
  2373. if (col.field !== 'check') {
  2374. return;
  2375. }
  2376. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2377. const node = sortData[info.row];
  2378. if (!node.check) {
  2379. if (checkParent(node)) {
  2380. const rect = info.sheet.getCellRect(info.row, info.col);
  2381. gatherConfirmPopover.check({
  2382. x: rect.x + rect.width / 2 + 25,
  2383. y: rect.y + rect.height / 2 + 3,
  2384. }, '父项已勾选,继续将取消父项勾选。', function () {
  2385. node.check = true;
  2386. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2387. const rows = [self.gsTree.nodes.indexOf(node)];
  2388. for (const p of parents) {
  2389. if (p.check) {
  2390. p.check = false;
  2391. rows.push(self.gsTree.nodes.indexOf(p));
  2392. }
  2393. }
  2394. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2395. });
  2396. } else if (checkChildren(node)) {
  2397. const rect = info.sheet.getCellRect(info.row, info.col);
  2398. gatherConfirmPopover.check({
  2399. x: rect.x + rect.width / 2 + 25,
  2400. y: rect.y + rect.height / 2 + 3,
  2401. }, '子项已勾选,继续将取消子项勾选。', function () {
  2402. node.check = true;
  2403. const posterity = self.gsTree.getPosterity(node);
  2404. const rows = [self.gsTree.nodes.indexOf(node)];
  2405. for (const p of posterity) {
  2406. if (p.check) {
  2407. rows.push(self.gsTree.nodes.indexOf(p));
  2408. p.check = false;
  2409. }
  2410. }
  2411. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2412. });
  2413. } else {
  2414. node.check = true;
  2415. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2416. }
  2417. } else {
  2418. node.check = false;
  2419. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2420. }
  2421. }
  2422. });
  2423. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2424. for (const node of self.gsTree.datas) {
  2425. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2426. }
  2427. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2428. self.gsTree.expandByLevel(4);
  2429. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2430. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2431. } else {
  2432. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2433. for (const node of self.gsTree.datas) {
  2434. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2435. }
  2436. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2437. }
  2438. });
  2439. // 提交 高级设置
  2440. $('#choose2-ok').click(() => {
  2441. if (!self.gsTree) { return; }
  2442. const nodes = [];
  2443. for (const node of self.gsTree.datas) {
  2444. if (node.check) {
  2445. nodes.push(node.id);
  2446. }
  2447. }
  2448. const data = {
  2449. im_gather: $('#im-gather-check')[0].checked,
  2450. im_gather_node: nodes.join(','),
  2451. };
  2452. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2453. stage.im_gather = data.im_gather;
  2454. stage.im_gather_node = data.im_gather_node;
  2455. $('#choose2').modal('hide');
  2456. });
  2457. });
  2458. }
  2459. _initLocateRela() {
  2460. const self = this;
  2461. $('#im-locate2bills').click(function () {
  2462. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2463. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2464. if (select && select.source) {
  2465. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2466. stagePosSpreadObj.loadCurPosData();
  2467. }
  2468. });
  2469. $('#im-locate-pre').click(function () {
  2470. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2471. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2472. if (select && select.source) {
  2473. const targetIndex = math.max(curIndex-1, 1);
  2474. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2475. stagePosSpreadObj.loadCurPosData();
  2476. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2477. }
  2478. });
  2479. $('#im-locate-next').click(function () {
  2480. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2481. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2482. if (select && select.source) {
  2483. const targetIndex = math.min(curIndex+1, select.source.length);
  2484. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2485. stagePosSpreadObj.loadCurPosData();
  2486. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2487. }
  2488. });
  2489. }
  2490. _initModifyDetail() {
  2491. const self = this;
  2492. // 重置
  2493. $('#reset-detail-ok').click(function () {
  2494. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2495. if (!data.uuid) return;
  2496. const updateData = {
  2497. lid: data.lid, pid: data.pid,
  2498. uuid: data.uuid,
  2499. custom_define: [],
  2500. };
  2501. for (const f of data.custom_define) {
  2502. if (stageIm.resetFields.indexOf(f) >= 0) {
  2503. updateData[f] = null;
  2504. } else {
  2505. updateData.custom_define.push(f);
  2506. }
  2507. }
  2508. updateData.custom_define = updateData.custom_define.join(',');
  2509. $('#reset-detail-modal').modal('hide');
  2510. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2511. stageIm.loadUpdateDetailData(result);
  2512. self.reLoadDetailData();
  2513. });
  2514. });
  2515. // 编辑
  2516. $('#edit-detail').click(function () {
  2517. $(this).hide();
  2518. $('#save-detail').show();
  2519. $('#cancel-detail').show();
  2520. $('#detail-show').hide();
  2521. $('#detail-edit').show();
  2522. self.updateImageData = null;
  2523. });
  2524. // 保存
  2525. $('#save-detail').click(() => {
  2526. function check(field, obj, org, update) {
  2527. const newValue = obj.val();
  2528. if (!org[field]) {
  2529. if (newValue !== '') {
  2530. update[field] = newValue;
  2531. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2532. }
  2533. } else if (newValue !== org[field]){
  2534. update[field] = newValue;
  2535. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2536. }
  2537. }
  2538. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2539. const updateData = {lid: data.lid, pid: data.pid};
  2540. if (data.uuid) {
  2541. updateData.uuid = data.uuid;
  2542. updateData.custom_define = data.custom_define;
  2543. } else {
  2544. updateData.code = data.code;
  2545. updateData.name = data.name;
  2546. updateData.unit = data.unit;
  2547. updateData.unit_price = data.unit_price;
  2548. updateData.pid = data.pid;
  2549. updateData.pos_name = data.pos_name;
  2550. updateData.custom_define = [];
  2551. }
  2552. check('bw', $('#bw-name'), data, updateData);
  2553. check('peg', $('#peg'), data, updateData);
  2554. check('xm', $('#xm-name'), data, updateData);
  2555. check('position', $('#position'), data, updateData);
  2556. check('jldy', $('#jldy'), data, updateData);
  2557. check('drawing_code', $('#drawing-code'), data, updateData);
  2558. check('calc_memo', $('#calc-memo'), data, updateData);
  2559. updateData.custom_define = updateData.custom_define.join(',');
  2560. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2561. stageIm.loadUpdateDetailData(result);
  2562. self.reLoadDetailData();
  2563. if (self.updateImageData && !self.updateImageData.uuid) {
  2564. self.updateImageData.uuid = result.uuid;
  2565. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2566. stageIm.loadUpdateDetailData(result);
  2567. self.reLoadDetailData();
  2568. });
  2569. }
  2570. });
  2571. if (self.updateImageData && self.updateImageData.uuid) {
  2572. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2573. stageIm.loadUpdateDetailData(result);
  2574. self.reLoadDetailData();
  2575. });
  2576. }
  2577. });
  2578. // 取消
  2579. $('#cancel-detail').click(() => {
  2580. self.reLoadDetailData();
  2581. });
  2582. }
  2583. _initImageRela() {
  2584. const self = this;
  2585. $('#edit-detail').click(function () {
  2586. loadImageItem();
  2587. });
  2588. function setdraggrable(){
  2589. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2590. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2591. stop: function( event, ui ) {
  2592. }
  2593. });
  2594. }
  2595. // 移动图片
  2596. const moveImageItem = function (ev) {
  2597. const item = this;
  2598. const view = $('.img-view')[0];
  2599. let oEvent = ev;
  2600. // 浏览器有一些图片的默认事件,这里要阻止
  2601. oEvent.preventDefault();
  2602. let disX = oEvent.clientX - item.offsetLeft;
  2603. let disY = oEvent.clientY - item.offsetTop;
  2604. view.onmousemove = function (ev) {
  2605. oEvent = ev;
  2606. oEvent.preventDefault();
  2607. let x = oEvent.clientX -disX;
  2608. let y = oEvent.clientY -disY;
  2609. // 图形移动的边界判断
  2610. x = x <= 0 ? 0 : x;
  2611. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2612. y = y <= 0 ? 0 : y;
  2613. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2614. item.style.left = x + 'px';
  2615. item.style.top = y + 'px';
  2616. };
  2617. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2618. view.onmouseleave = function () {
  2619. view.onmousemove = null;
  2620. view.onmouseup = null;
  2621. };
  2622. // 鼠标弹起后停止移动
  2623. view.onmouseup=function() {
  2624. view.onmousemove = null;
  2625. view.onmouseup = null;
  2626. };
  2627. };
  2628. const removeImageItem = function () {
  2629. $(this).parent().remove();
  2630. };
  2631. // 加载草图组成
  2632. const loadImageItem = function () {
  2633. self.updateImageData = null;
  2634. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2635. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2636. const html = [];
  2637. for (const item of items) {
  2638. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2639. html.push('<div class="img-item" style="' + itemStyle + '">');
  2640. html.push('<div class="img-bar">');
  2641. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2642. html.push('</div>');
  2643. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2644. html.push('</div>');
  2645. }
  2646. $('.img-view').html(html.join(''));
  2647. $('.img-bar').click(removeImageItem);
  2648. setdraggrable();
  2649. };
  2650. // 上传图片
  2651. $('#upload-img').click(function () {
  2652. $('#upload-img-file').trigger('click');
  2653. });
  2654. $('#upload-img-file').change(function () {
  2655. const file = this.files[0];
  2656. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2657. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2658. if (!imgStr.test(ext)) {
  2659. toastr.error('请上传正确的图片格式文件');
  2660. return
  2661. }
  2662. if ($(this).val()) {
  2663. const formData = new FormData();
  2664. formData.append('file', this.files[0]);
  2665. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2666. const html = [];
  2667. html.push('<div class="img-item">');
  2668. html.push('<div class="img-bar">');
  2669. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2670. html.push('</div>');
  2671. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2672. html.push('</div>');
  2673. $('.img-view').append(html.join(''));
  2674. $('.img-bar').click(removeImageItem);
  2675. setdraggrable();
  2676. $('#upload-img-file').val('');
  2677. });
  2678. }
  2679. });
  2680. // 保存草图修改结果
  2681. $('#edit-img-ok').click(function () {
  2682. // 记录上传的图片的信息
  2683. const items = $('.img-item');
  2684. const img_remark = $('#text-edit').val()
  2685. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2686. if (items.length > 0) {
  2687. const itemInfo = [];
  2688. for (const item of items) {
  2689. const itemData = {
  2690. src: $('img', item).attr('src'),
  2691. left: item.style.left,
  2692. top: item.style.top,
  2693. width: item.style.width,
  2694. height: item.style.height,
  2695. };
  2696. itemInfo.push(itemData);
  2697. }
  2698. // 获取合并好的图片数据
  2699. const canvas = document.createElement('canvas');
  2700. const view = $('.img-view')[0];
  2701. canvas.height = view.clientHeight;
  2702. canvas.width = view.clientWidth;
  2703. const ctx = canvas.getContext('2d');
  2704. ctx.fillStyle = '#ffffff';
  2705. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2706. for (const b of $('.img-item')) {
  2707. const pos = $(b).position();
  2708. const img = $('img', b)[0];
  2709. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2710. }
  2711. // 生成上传数据
  2712. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2713. if (data.uuid) {
  2714. updateData.uuid = data.uuid;
  2715. }
  2716. updateData.img = canvas.toDataURL('image/png');
  2717. updateData.imgInfo = itemInfo;
  2718. updateData.calc_img_remark = img_remark;
  2719. self.updateImageData = updateData;
  2720. $('#calc-img').attr('src', updateData.img);
  2721. $('#view-calc-img').attr('src', updateData.img);
  2722. $('#show-calc-img').attr('src', updateData.img);
  2723. $('#view-calc-remark').text(img_remark);
  2724. $('#edit-img').modal('hide');
  2725. // updateImageData = updateData;
  2726. // $('#edit-img').modal('hide');
  2727. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2728. // stageIm.loadUpdateDetailData(result);
  2729. // data.calc_img = result.calc_img;
  2730. // data.calc_img_org = result.calc_img_org;
  2731. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2732. // $('#show-calc-img').attr('src', calcImgSrc);
  2733. // $('#calc-img').attr('src', calcImgSrc);
  2734. // $('#view-calc-img').attr('src', calcImgSrc);
  2735. // $('#edit-img').modal('hide');
  2736. // });
  2737. } else if (data.calc_img) {
  2738. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid};
  2739. $('#show-calc-img').attr('src', '');
  2740. $('#calc-img').attr('src', '');
  2741. $('#view-calc-img').attr('src', '');
  2742. $('#view-calc-remark').val('');
  2743. $('#text-edit').val('');
  2744. $('#edit-img').modal('hide');
  2745. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2746. // stageIm.loadUpdateDetailData(result);
  2747. // data.calc_img = result.calc_img;
  2748. // data.calc_img_org = result.calc_img_org;
  2749. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2750. // $('#show-calc-img').attr('src', calcImgSrc);
  2751. // $('#calc-img').attr('src', calcImgSrc);
  2752. // $('#view-calc-img').attr('src', calcImgSrc);
  2753. // $('#edit-img').modal('hide');
  2754. // });
  2755. } else {
  2756. self.updateImageData = null;
  2757. $('#show-calc-img').attr('src', '');
  2758. $('#calc-img').attr('src', '');
  2759. $('#view-calc-img').attr('src', '');
  2760. $('#view-calc-remark').val('');
  2761. $('#text-edit').val('');
  2762. $('#edit-img').modal('hide');
  2763. }
  2764. });
  2765. }
  2766. reBuildImData() {
  2767. const imData = stageIm.buildImData();
  2768. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2769. this.reLoadDetailData();
  2770. this.loadLocateInfo();
  2771. }
  2772. loadStageLedgerUpdateData(data) {
  2773. const imData = stageIm.loadUpdateLedgerData(data);
  2774. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2775. this.reLoadDetailData();
  2776. }
  2777. loadStagePosUpdateData(data) {
  2778. const imData = stageIm.loadUpdatePosData(data);
  2779. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2780. this.reLoadDetailData();
  2781. }
  2782. loadStageChangeUpdateData(data) {
  2783. const imData = stageIm.loadUpdateChangeData(data);
  2784. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2785. this.reLoadDetailData();
  2786. }
  2787. loadLocateInfo() {
  2788. const select = SpreadJsObj.getSelectObject(this.sheet);
  2789. if (select && select.source.length > 1) {
  2790. $('#im-locate2bills').next().show();
  2791. } else {
  2792. $('#im-locate2bills').next().hide();
  2793. }
  2794. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  2795. }
  2796. reLoadDetailData() {
  2797. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2798. $('#reset-detail').hide();
  2799. if (data) {
  2800. for (const f of data.custom_define) {
  2801. if (stageIm.resetFields.indexOf(f) >= 0) {
  2802. $('#reset-detail').show();
  2803. break;
  2804. }
  2805. }
  2806. $('#edit-detail').show();
  2807. $('#modify-img').show();
  2808. } else {
  2809. $('#edit-detail').hide();
  2810. $('#modify-img').hide();
  2811. }
  2812. $('#save-detail').hide();
  2813. $('#cancel-detail').hide();
  2814. $('#detail-show').show();
  2815. $('#detail-edit').hide();
  2816. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2817. $('#show-contract-jl').text(contractJl);
  2818. $('#contract-jl').val(contractJl);
  2819. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2820. $('#show-qc-jl').text(qcJl);
  2821. $('#qc-jl').val(qcJl);
  2822. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2823. $('#show-bgl-code').text(bglCode);
  2824. $('#bgl-code').val(bglCode);
  2825. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2826. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2827. $('#bgl-drawing-code').val(bglDrawingCode);
  2828. const bwName = data && data.bw ? data.bw : '';
  2829. $('#show-bw-name').text(bwName);
  2830. $('#bw-name').val(bwName);
  2831. const position = data && data.position ? data.position : '';
  2832. $('#show-position').text(position);
  2833. $('#position').val(position);
  2834. const peg = data && data.peg ? data.peg : '';
  2835. $('#show-peg').text(peg);
  2836. $('#peg').val(peg);
  2837. const xmName = data && data.xm ? data.xm: '';
  2838. $('#show-xm-name').text(xmName);
  2839. $('#xm-name').val(xmName);
  2840. const jldy = data && data.jldy ? data.jldy: '';
  2841. $('#show-jldy').text(jldy);
  2842. $('#jldy').val(jldy);
  2843. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2844. $('#show-drawing-code').text(drawingCode);
  2845. $('#drawing-code').val(drawingCode);
  2846. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2847. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2848. $('#calc-memo').val(calcMemo);
  2849. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2850. $('#show-calc-img').attr('src', calcImgSrc);
  2851. $('#calc-img').attr('src', calcImgSrc);
  2852. $('#view-calc-img').attr('src', calcImgSrc);
  2853. const calcImgRemark = data && data.calc_img_remark || '';
  2854. $('#view-calc-remark').val(calcImgRemark);
  2855. $("#view-calc-remark").attr('readonly', true);
  2856. // 处理 编辑 -> 添加草图中textarea多余的空格
  2857. $('#text-edit').val(calcImgRemark)
  2858. }
  2859. }
  2860. class CheckedChange {
  2861. constructor (setting) {
  2862. const self = this;
  2863. this.changeSpreadSetting = {
  2864. cols: [
  2865. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  2866. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  2867. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2868. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  2869. ],
  2870. emptyRows: 0,
  2871. headRows: 1,
  2872. headRowHeight: [32],
  2873. headColWidth: [30],
  2874. defaultRowHeight: 21,
  2875. headerFont: '12px 微软雅黑',
  2876. font: '12px 微软雅黑',
  2877. readOnly: true,
  2878. };
  2879. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  2880. this.changeSheet = this.changeSpread.getActiveSheet();
  2881. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  2882. this.changeBillsSpreadSetting = {
  2883. cols: [
  2884. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2885. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number'},
  2886. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2887. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  2888. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  2889. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  2890. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  2891. ],
  2892. emptyRows: 0,
  2893. headRows: 1,
  2894. headRowHeight: [32],
  2895. defaultRowHeight: 21,
  2896. headerFont: '12px 微软雅黑',
  2897. font: '12px 微软雅黑',
  2898. readOnly: true
  2899. };
  2900. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  2901. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  2902. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  2903. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2904. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  2905. if (change.cid === self.curChangeId) { return; }
  2906. self.curChangeId = change.cid;
  2907. if (change.detail) {
  2908. self.loadChangeDetailData();
  2909. } else {
  2910. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  2911. change.detail = result;
  2912. self.analyzeChange(change);
  2913. self.loadChangeDetailData();
  2914. });
  2915. }
  2916. });
  2917. this.changes = null;
  2918. this.reloadChangeData();
  2919. setting.reloadObj.click(function() {
  2920. self.reloadChangeData();
  2921. });
  2922. }
  2923. loadChangeDetailData() {
  2924. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  2925. if (change) {
  2926. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  2927. } else {
  2928. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  2929. }
  2930. }
  2931. refresh() {
  2932. this.changeSpread.refresh();
  2933. this.changeBillsSpread.refresh();
  2934. }
  2935. reloadChangeData() {
  2936. const self = this;
  2937. postData(window.location.pathname + '/change/data', null, function (result) {
  2938. self.changes = result.changes;
  2939. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  2940. self.changeSheet.setSelection(0, 0, 1, 1);
  2941. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  2942. self.loadChangeDetailData();
  2943. });
  2944. }
  2945. analyzeChange(change) {
  2946. change.bills = change.detail.bills;
  2947. for (const b of change.bills) {
  2948. const aub = change.detail.addUsedBills.find(function (x) {
  2949. return x.id === b.id;
  2950. });
  2951. if (aub) {
  2952. b.used_qty = aub.used_qty;
  2953. }
  2954. b.qty = _.toNumber(b.samount);
  2955. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  2956. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  2957. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  2958. b.cur_qty = 0;
  2959. for (const p of b.pos) {
  2960. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  2961. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  2962. }
  2963. }
  2964. }
  2965. }
  2966. // 展开收起附件
  2967. $('a', '.right-nav').bind('click', function () {
  2968. //const main = $('#main-view'), tool = $('#tools-view');
  2969. const tab = $(this), tabPanel = $(tab.attr('content'));
  2970. if (!tab.hasClass('active')) {
  2971. $('a', '.side-menu').removeClass('active');
  2972. $('.tab-content .tab-select-show').removeClass('active');
  2973. tab.addClass('active');
  2974. tabPanel.addClass('active');
  2975. showSideTools(tab.hasClass('active'));
  2976. if (tab.attr('content') === '#search' && !searchLedger) {
  2977. searchLedger = $.billsSearch({
  2978. selector: '#search',
  2979. searchSpread: slSpread,
  2980. searchRangeStr: '项目节编号/名称',
  2981. searchOver: true,
  2982. searchEmpty: true,
  2983. resultSpreadSetting: {
  2984. cols: [
  2985. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2986. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2987. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2988. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2989. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2990. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2991. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  2992. ],
  2993. emptyRows: 0,
  2994. headRows: 1,
  2995. headRowHeight: [32],
  2996. headColWidth: [30],
  2997. defaultRowHeight: 21,
  2998. headerFont: '12px 微软雅黑',
  2999. font: '12px 微软雅黑',
  3000. selectedBackColor: '#fffacd',
  3001. },
  3002. afterLocated: function () {
  3003. stagePosSpreadObj.loadCurPosData();
  3004. },
  3005. customSearch: [
  3006. {
  3007. key: 'less', title: '漏计', valid: true,
  3008. check: function (node) {
  3009. if (node.quantity) {
  3010. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3011. } else if (node.total_price) {
  3012. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3013. }
  3014. }
  3015. }, {
  3016. key: 'over', title: '超计', valid: true,
  3017. check: function (node) {
  3018. if (checkTzMeasureType()) {
  3019. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3020. if (posRange.length > 0) {
  3021. for (const p of posRange) {
  3022. if (p.end_contract_qty > p.quantity) return true;
  3023. }
  3024. return false;
  3025. } else if (node.end_gather_qty) {
  3026. return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
  3027. } else if (node.end_gather_tp) {
  3028. return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
  3029. }
  3030. } else {
  3031. if (node.end_gather_qty) {
  3032. return !node.deal_qty || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.deal_qty, node.end_qc_qty));
  3033. } else if (node.end_gather_tp) {
  3034. return !node.deal_tp || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.deal_tp, node.end_qc_tp));
  3035. }
  3036. }
  3037. }
  3038. }, {
  3039. key: 'empty', title: '漏计', valid: false,
  3040. check: function (node) {
  3041. if (node.quantity) {
  3042. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3043. } else if (node.total_price) {
  3044. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3045. }
  3046. }
  3047. }, {
  3048. key: 'estimate', title: '预计变更', valid: true,
  3049. check: function (node) {
  3050. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3051. if (posRange.length > 0) {
  3052. for (const p of posRange) {
  3053. if (!checkZero(p.estimate_qty)) return true;
  3054. }
  3055. return false;
  3056. } else {
  3057. return false;
  3058. }
  3059. }
  3060. }
  3061. ],
  3062. });
  3063. searchLedger.spread.refresh();
  3064. }
  3065. if (tab.attr('content') === '#fujian') {
  3066. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3067. getNodeList(node.id);
  3068. }
  3069. if (tab.attr('content') === '#zhongjian') {
  3070. if (!detail) {
  3071. detail = new Detail($('#detail-spread'));
  3072. detail.spread.refresh();
  3073. $('#zhongjian .sjs-bottom').height('400px');
  3074. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3075. } else {
  3076. detail.spread.refresh();
  3077. }
  3078. }
  3079. if (tab.attr('content') === '#checked-change') {
  3080. if (!checkedChanges) {
  3081. checkedChanges = new CheckedChange({
  3082. changeObj: $('#cc-spread'),
  3083. changeBillsObj: $('#ccb-spread'),
  3084. reloadObj: $('#refresh-cc'),
  3085. });
  3086. checkedChanges.refresh();
  3087. } else {
  3088. $('#ccb-spread').height('400px');
  3089. checkedChanges.refresh();
  3090. }
  3091. }
  3092. if (tab.attr('content') === '#error-list') {
  3093. errorList.spread.refresh();
  3094. }
  3095. if (tab.attr('content') === '#check-list') {
  3096. checkList.spread.refresh();
  3097. }
  3098. } else {
  3099. tab.removeClass('active');
  3100. tabPanel.removeClass('active');
  3101. showSideTools(tab.hasClass('active'));
  3102. }
  3103. slSpread.refresh();
  3104. spSpread.refresh();
  3105. });
  3106. // 切换附件里节点和所有附件
  3107. $('#fujian .nav-link').on('click', function () {
  3108. const tabPanel = $(this).attr('fujian-content');
  3109. if (tabPanel !== 'syfujian') {
  3110. $('#showPage').hide();
  3111. } else {
  3112. $('#showPage').show();
  3113. }
  3114. $('#showAttachment').hide();
  3115. });
  3116. // 上传附件
  3117. $('#upload-file-btn').click(function () {
  3118. if (curAuditor && curAuditor.aid !== cur_uid) {
  3119. return toastr.error('当前操作没有权限!');
  3120. }
  3121. const files = $('#upload-file')[0].files;
  3122. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3123. const formData = new FormData();
  3124. formData.append('lid', node.id);
  3125. for (const file of files) {
  3126. if (file === undefined) {
  3127. toastr.error('未选择上传文件!');
  3128. return false;
  3129. }
  3130. const filesize = file.size;
  3131. if (filesize > 30 * 1024 * 1024) {
  3132. toastr.error('存在上传文件大小过大!');
  3133. return false;
  3134. }
  3135. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3136. if (whiteList.indexOf(fileext) === -1) {
  3137. toastr.error('只能上传指定格式的附件!');
  3138. return false;
  3139. }
  3140. formData.append('size', filesize);
  3141. formData.append('file[]', file);
  3142. }
  3143. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3144. $('#upload').modal('hide');
  3145. // 插入到attData中
  3146. attData = data.concat(attData);
  3147. // 重新生成List
  3148. getAllList();
  3149. getNodeList(node.id);
  3150. }, function () {
  3151. toastr.error('附件上传失败');
  3152. });
  3153. $('#upload-file').val('');
  3154. });
  3155. // 获取附件信息
  3156. $('.list-table').on('click', '.att-file-name', function () {
  3157. const fid = $(this).attr('file-id');
  3158. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3159. return;
  3160. }
  3161. const att = attData.find(function (item) {
  3162. return item.id === parseInt(fid);
  3163. });
  3164. $('#edit-att').hide();
  3165. $('#show-att').show();
  3166. if (att !== undefined) {
  3167. // 进来先把编辑功能隐藏
  3168. $('#btn-att a').eq(3).hide()
  3169. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3170. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3171. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3172. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3173. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3174. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3175. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3176. $('#show-att tr').eq(3).children('td').text(att.remark);
  3177. // 附件uid等于当前用户id, 附件上传本人
  3178. if (parseInt(cur_uid) === att.uid) {
  3179. $('#btn-att').show();
  3180. let showDel = false;
  3181. if (!curAuditor) {
  3182. stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3183. stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3184. stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3185. } else {
  3186. curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3187. }
  3188. if (showDel) $('#btn-att a').eq(3).show();
  3189. // $('#btn-att a').eq(3).show();
  3190. $('#btn-att a').eq(2).hide();
  3191. $('#btn-att a').eq(4).hide();
  3192. $('#btn-att a').eq(5).hide();
  3193. } else {
  3194. $('#btn-att').hide();
  3195. $('#btn-att a').eq(3).hide();
  3196. $('#btn-att a').eq(2).hide();
  3197. $('#btn-att a').eq(4).hide();
  3198. $('#btn-att a').eq(5).hide();
  3199. }
  3200. $('#showAttachment').attr('file-id', fid);
  3201. $('#showAttachment').show();
  3202. } else {
  3203. $('#showAttachment').hide();
  3204. $('#showAttachment').attr('file-id', '');
  3205. toastr.error('附件信息获取失败');
  3206. }
  3207. });
  3208. // $('body').on('click', '.alllist-table a', handleFileList);
  3209. $('body').on('click', '#btn-att a', function () {
  3210. const content = $(this).attr('content');
  3211. const fid = $('#showAttachment').attr('file-id');
  3212. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3213. if (content === 'edit') {
  3214. $('#btn-att a').eq(3).hide();
  3215. $('#btn-att a').eq(2).show();
  3216. $('#btn-att a').eq(4).show();
  3217. $('#btn-att a').eq(5).show();
  3218. $('#show-att').hide();
  3219. $('#edit-att').show();
  3220. const att = attData.find(function (item) {
  3221. return item.id === parseInt(fid);
  3222. });
  3223. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3224. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3225. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3226. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3227. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3228. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3229. } else if (content === 'cancel') {
  3230. $('#show-att').show();
  3231. $('#edit-att').hide();
  3232. $('#btn-att a').eq(3).show();
  3233. $('#btn-att a').eq(2).hide();
  3234. $('#btn-att a').eq(4).hide();
  3235. $('#btn-att a').eq(5).hide();
  3236. } else if (content === 'save') {
  3237. const formData = new FormData();
  3238. formData.append('id', fid);
  3239. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3240. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3241. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3242. const file = $('#change-att-btn')[0];
  3243. if (file.files[0] !== undefined) {
  3244. const filesize = file.files[0].size;
  3245. formData.append('size', filesize);
  3246. formData.append('file', file.files[0]);
  3247. }
  3248. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3249. // 替换到attData中
  3250. const att_index = attData.findIndex(function (item) {
  3251. return item.id === parseInt(fid);
  3252. });
  3253. attData.splice(att_index, 1, data);
  3254. // 重新生成List
  3255. getAllList(parseInt($('#currentPage').text()));
  3256. getNodeList(node.id);
  3257. $('#show-att').show();
  3258. $('#edit-att').hide();
  3259. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3260. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3261. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3262. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3263. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3264. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3265. $('#show-att tr').eq(4).children('td').text(data.remark);
  3266. $('#btn-att a').eq(3).show();
  3267. $('#btn-att a').eq(2).hide();
  3268. $('#btn-att a').eq(4).hide();
  3269. $('#btn-att a').eq(5).hide();
  3270. }, function () {
  3271. toastr.error('附件上传失败');
  3272. });
  3273. $('#change-att-btn').val('');
  3274. } else if (content === 'del') {
  3275. const data = {id: fid};
  3276. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3277. // 删除到attData中
  3278. const att_index = attData.findIndex(function (item) {
  3279. return item.id === parseInt(fid);
  3280. });
  3281. attData.splice(att_index, 1);
  3282. // 重新生成List
  3283. if ($('#alllist-table tr').length === 1) {
  3284. getAllList(parseInt($('#currentPage').text()) - 1);
  3285. } else {
  3286. getAllList(parseInt($('#currentPage').text()));
  3287. }
  3288. getNodeList(node.id);
  3289. $('#showAttachment').hide();
  3290. $('#showAttachment').attr('file-id', '');
  3291. });
  3292. } else if (content === 'view') {
  3293. const data = {id: fid};
  3294. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3295. const { filepath } = result
  3296. $('#load-file').attr('href', filepath);
  3297. $('#load-file')[0].click();
  3298. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3299. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3300. });
  3301. } else if (content === 'location') {
  3302. const att = attData.find(item => item.id === parseInt(fid));
  3303. if (Object.keys(att).length) {
  3304. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3305. stagePosSpreadObj.loadCurPosData();
  3306. }
  3307. }
  3308. });
  3309. // 替换附件
  3310. $('#change-att-btn').on('change', function () {
  3311. const file = $('#change-att-btn')[0].files[0];
  3312. const name = file.name;
  3313. const filename = name.substring(0, name.lastIndexOf("."));
  3314. const fileext = name.substr(name.indexOf("."));
  3315. const filesize = file.size;
  3316. if (filesize > 10 * 1024 * 1024) {
  3317. toastr.error('文件大小过大!');
  3318. $('#change-att-btn').val('');
  3319. return false;
  3320. }
  3321. if (whiteList.indexOf(fileext) === -1) {
  3322. toastr.error('只能上传指定格式的附件!');
  3323. $('#change-att-btn').val('');
  3324. return false;
  3325. }
  3326. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3327. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3328. });
  3329. // 切换页数
  3330. $('.page-select').on('click', function () {
  3331. const totalPageNum = parseInt($('#totalPage').text());
  3332. const lastPageNum = parseInt($('#currentPage').text());
  3333. const status = $(this).attr('content');
  3334. if (status === 'pre' && lastPageNum > 1) {
  3335. getAllList(lastPageNum-1);
  3336. $('#showAttachment').hide();
  3337. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3338. getAllList(lastPageNum+1);
  3339. $('#showAttachment').hide();
  3340. }
  3341. });
  3342. // 批量下载
  3343. $('#bach-download').click(function() {
  3344. const fileIds = []
  3345. $('.tab-pane.active .list-table .check-file:checked').each(function() {
  3346. const fileId = $(this).attr('file-id')
  3347. fileId && fileIds.push(fileId)
  3348. })
  3349. console.log('fileIds', fileIds)
  3350. if (fileIds.length) {
  3351. const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`
  3352. $('#zipDown').attr('href', url)
  3353. $("#zipDown")[0].click()
  3354. // 执行请求
  3355. // postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/compresse-file', { fileIds }, function(data) {
  3356. // console.log(data)
  3357. // })
  3358. // $.ajax({
  3359. // type:"get",
  3360. // // url: '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/compresse-file',
  3361. // url: `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileids=${JSON.stringify(fileids)}`,
  3362. // dataType: 'json',
  3363. // cache: false,
  3364. // // 告诉jQuery不要去设置Content-Type请求头
  3365. // contentType: false,
  3366. // // 告诉jQuery不要去处理发送的数据
  3367. // processData: false,
  3368. // timeout: 60000,
  3369. // })
  3370. }
  3371. });
  3372. // 监听附件check是否选中
  3373. $('.list-table').on('click', '.check-file', function() {
  3374. const checkedList = $(this).parents('.list-table').children().find('input:checked')
  3375. const childs = $(this).parents('.list-table').children().length
  3376. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file')
  3377. if (checkedList.length === childs) {
  3378. checkBox.prop("checked", true)
  3379. } else {
  3380. checkBox.prop("checked", false)
  3381. }
  3382. });
  3383. $('.check-all-file').click(function() {
  3384. const isCheck = $(this).is(':checked')
  3385. $(this).parents('table').find('.list-table').each(function() {
  3386. $(this).find('input:checkbox').prop("checked", isCheck)
  3387. })
  3388. });
  3389. // 显示层次
  3390. (function (select, sheet) {
  3391. $(select).click(function () {
  3392. if (!sheet.zh_tree) return;
  3393. const tag = $(this).attr('tag');
  3394. const tree = sheet.zh_tree;
  3395. switch (tag) {
  3396. case "1":
  3397. case "2":
  3398. case "3":
  3399. case "4":
  3400. case "5":
  3401. tree.expandByLevel(parseInt(tag));
  3402. SpreadJsObj.refreshTreeRowVisible(sheet);
  3403. break;
  3404. case "last":
  3405. tree.expandByCustom(() => { return true; });
  3406. SpreadJsObj.refreshTreeRowVisible(sheet);
  3407. break;
  3408. case "leafXmj":
  3409. tree.expandToLeafXmj();
  3410. SpreadJsObj.refreshTreeRowVisible(sheet);
  3411. break;
  3412. case "curMeasure":
  3413. tree.expandByCustom(function (node) {
  3414. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3415. if (node[field]) {
  3416. return true;
  3417. }
  3418. }
  3419. return false;
  3420. });
  3421. SpreadJsObj.refreshTreeRowVisible(sheet);
  3422. break;
  3423. }
  3424. });
  3425. })('a[name=showLevel]', slSpread.getActiveSheet());
  3426. const stageCheckerSetting = {
  3427. ledgerTree: stageTree,
  3428. ledgerPos: stagePos,
  3429. checkList: checkList,
  3430. decimal: tenderInfo.decimal,
  3431. checkOption: {
  3432. sibling: { enable: 0 },
  3433. empty_code: { enable: 0 },
  3434. calc: {
  3435. enable: 1,
  3436. fields: ['contract_qty', 'qc_qty'],
  3437. },
  3438. zero: { enable: 0 },
  3439. tp: {
  3440. enable: 1,
  3441. fields: [
  3442. {qty: 'contract_qty', tp: 'contract_tp'},
  3443. {qty: 'qc_qty', tp: 'qc_tp'},
  3444. ],
  3445. filter: function (node) {
  3446. return node.is_tp;
  3447. }
  3448. },
  3449. }
  3450. };
  3451. if (!checkTzMeasureType()) {
  3452. stageCheckerSetting.checkOption.calc.fields.push('sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity');
  3453. stageCheckerSetting.checkOption.tp.fields.push(
  3454. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  3455. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  3456. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  3457. {qty: 'quantity', tp: 'total_price'},
  3458. );
  3459. }
  3460. LedgerChecker(stageCheckerSetting);
  3461. const dataChecker = DataChecker({
  3462. checkUrl: window.location.pathname + '/check',
  3463. completeData: function (data) {
  3464. stagePos.updateDatas({pos: data.source.pos});
  3465. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  3466. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  3467. stagePosSpreadObj.loadCurPosData();
  3468. for (const e of data.error) {
  3469. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  3470. }
  3471. },
  3472. errorList: errorList,
  3473. });
  3474. $('[name=stage-start]').submit(function (e) {
  3475. if (checkAuditorFrom()) {
  3476. $(this).parent().parent().parent().modal('hide');
  3477. dataChecker.checkAndPost(this.action, {});
  3478. $('#hide-all').hide();
  3479. }
  3480. return false;
  3481. });
  3482. $('#audit-check0').submit(function (e) {
  3483. const checkType = parseInt($('[name=checkType]').val());
  3484. const data = {
  3485. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3486. checkType,
  3487. };
  3488. $('#sp-done').modal('hide');
  3489. checkType && dataChecker.checkAndPost(this.action, data);
  3490. $('#hide-all').hide();
  3491. return false;
  3492. });
  3493. $('#audit-check1').submit(function (e) {
  3494. const checkType = parseInt($('[name=checkType]:checked').val());
  3495. const data = {
  3496. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3497. checkType,
  3498. };
  3499. if ($('#warning-text').length) $('#warning-text').remove()
  3500. if (!checkType && !$('#warning-text').length) {
  3501. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  3502. return false
  3503. }
  3504. $('#sp-back').modal('hide');
  3505. checkType && dataChecker.checkAndPost(this.action, data);
  3506. $('#hide-all').hide();
  3507. return false;
  3508. });
  3509. $('#exportExcel').click(function () {
  3510. const data = [];
  3511. const setting = {
  3512. cols: [
  3513. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  3514. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3515. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  3516. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  3517. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  3518. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  3519. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  3520. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  3521. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3522. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3523. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3524. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3525. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3526. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3527. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3528. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3529. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3530. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3531. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3532. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3533. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, type: 'Number'},
  3534. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3535. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3536. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3537. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3538. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  3539. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  3540. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  3541. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  3542. ],
  3543. headRows: 2,
  3544. headRowHeight: [25, 25],
  3545. defaultRowHeight: 21,
  3546. headerFont: 'bold 10px 微软雅黑',
  3547. font: '10px 微软雅黑'
  3548. };
  3549. for (const node of stageTree.nodes) {
  3550. data.push({
  3551. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3552. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  3553. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  3554. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  3555. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  3556. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  3557. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  3558. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_gather_percent: node.end_gather_percent,
  3559. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  3560. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  3561. final_dgn_price: node.final_dgn_price,
  3562. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  3563. });
  3564. const posRange = stagePos.getLedgerPos(node.id);
  3565. if (posRange && posRange.length > 0) {
  3566. for (const [i, p] of posRange.entries()) {
  3567. data.push({
  3568. pos_code: (i + 1) + '', name: p.name,
  3569. quantity: p.quantity,
  3570. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  3571. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  3572. drawing_code: p.drawing_code, memo: p.memo
  3573. });
  3574. }
  3575. }
  3576. }
  3577. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "计量台账.xlsx");
  3578. });
  3579. $('#cbr-check-all').click(function () {
  3580. if (this.checked) {
  3581. $('input', '#cbr-pos-list').attr('checked', 'checked');
  3582. } else {
  3583. $('input', '#cbr-pos-list').removeAttr('checked');
  3584. }
  3585. });
  3586. $('#cbr-ok').click(() => {
  3587. const ratio = parseInt($('#cbr-ratio').val());
  3588. if (!ratio) {
  3589. toastr.warning('请输入计量比例');
  3590. return;
  3591. } else if (ratio < 1) {
  3592. toastr.warning('计量比例不可小于1');
  3593. return;
  3594. } else if (ratio > 100) {
  3595. toastr.warning('计量比例不可大于100');
  3596. return;
  3597. }
  3598. const apply2sibling = $('#apply2sibling')[0].checked;
  3599. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  3600. if (posName.length === 0) {
  3601. toastr.warning('请勾选需要按计量比例的计量单元');
  3602. return;
  3603. }
  3604. stageTreeSpreadObj.measureByBatch(posName, ZhCalc.div(ratio, 100), apply2sibling);
  3605. })
  3606. });