change_revise.js 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. };
  51. $(document).ready(() => {
  52. let stdXmj, stdGcl, searchLedger;
  53. autoFlashHeight();
  54. if (!billsSpreadSetting.readOnly) {
  55. for (const col of billsSpreadSetting.cols) {
  56. if (!col.readOnly || col.readOnly === false)
  57. col.readOnly = 'readOnly.isChangeAdd';
  58. }
  59. }
  60. if (!posSpreadSetting.readOnly) {
  61. for (const col of posSpreadSetting.cols) {
  62. if (!col.readOnly || col.readOnly === false)
  63. col.readOnly = 'readOnly.isChangeAdd';
  64. }
  65. }
  66. const billsCol = {
  67. readOnly: {
  68. isChangeAdd: function (data) {
  69. return !readOnly && !data.formc;
  70. }
  71. }
  72. };
  73. const posCol = {
  74. readOnly: {
  75. isChangeAdd: function (data) {
  76. return !readOnly && !data.formc && (data.settle_status && data.settle_status === settleStatus.finish);
  77. }
  78. }
  79. };
  80. // 初始化spread
  81. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  82. const billsSheet = billsSpread.getActiveSheet();
  83. billsSpreadSetting.rowHeader = [
  84. {
  85. rowHeaderType: 'circle',
  86. setting: {
  87. size: 5,
  88. indent: 16,
  89. getColor: function (index, data) {
  90. if (!data) return;
  91. if(!data.formc && !data.cid) return;
  92. return '#dc3545';
  93. }
  94. },
  95. },
  96. ];
  97. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  98. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  99. return spreadColor.stage.settle;
  100. }
  101. return defaultColor;
  102. };
  103. billsSpreadSetting.localCache = {
  104. key: 'changes-ledger-spread',
  105. colWidth: true,
  106. };
  107. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  108. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  109. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  110. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  111. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  112. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  113. const posSheet = posSpread.getActiveSheet();
  114. posSpreadSetting.rowHeader = [
  115. {
  116. rowHeaderType: 'circle',
  117. setting: {
  118. size: 5,
  119. indent: 16,
  120. getColor: function (index, data) {
  121. if (!data) return;
  122. if(!data.formc) return;
  123. return '#dc3545';
  124. }
  125. },
  126. },
  127. ];
  128. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  129. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  130. return spreadColor.stage.settle;
  131. }
  132. return defaultColor;
  133. };
  134. posSpreadSetting.localCache = {
  135. key: 'changes-pos-spread',
  136. colWidth: true,
  137. };
  138. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  139. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  140. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  141. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  142. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  143. const errorList = $.cs_errorList({
  144. tabSelector: '#error-list-tab',
  145. selector: '#error-list',
  146. relaSpread: billsSpread,
  147. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  148. afterLocated: function () {
  149. posSpreadObj.loadCurPosData();
  150. },
  151. afterShow: function () {
  152. billsSpread.refresh();
  153. if (posSpread) posSpread.refresh();
  154. },
  155. });
  156. const checkList = $.ledger_checkList({
  157. id: 'check-list',
  158. tabSelector: '#check-list-tab',
  159. selector: '#check-list',
  160. relaSpread: billsSpread,
  161. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  162. checkType: getCheckType(checkOption),
  163. afterLocated: function () {
  164. posSpreadObj.loadCurPosData();
  165. },
  166. afterShow: function () {
  167. billsSpread.refresh();
  168. if (posSpread) posSpread.refresh();
  169. },
  170. });
  171. const sumLoadMiss = $.sumLoadMiss({
  172. tabSelector: '#sum-load-miss-tab',
  173. selector: '#sum-load-miss',
  174. relaSpread: billsSpread,
  175. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  176. id: 'revise-slm',
  177. afterLocated: function () {
  178. posSpreadObj.loadCurPosData();
  179. },
  180. afterShow: function () {
  181. billsSpread.refresh();
  182. if (posSpread) posSpread.refresh();
  183. },
  184. });
  185. // 初始化 节点树结构
  186. const treeSetting = {
  187. id: 'ledger_id',
  188. pid: 'ledger_pid',
  189. order: 'order',
  190. level: 'level',
  191. rootId: -1,
  192. keys: ['id', 'tender_id', 'ledger_id'],
  193. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  194. autoExpand: 3,
  195. markExpandKey: 'change-bills-expand',
  196. markExpandSubKey: window.location.pathname.split('/')[2],
  197. };
  198. if (!isTz) {
  199. treeSetting.calcFields.push('deal_tp');
  200. }
  201. treeSetting.calcFun = function (node) {
  202. if (node && node.b_code && isTz) {
  203. const posData = pos.getLedgerPos(node.id) || [];
  204. if (posData.length > 0) {
  205. let sgfh_qty = 0;
  206. let sjcl_qty = 0;
  207. let qtcl_qty = 0;
  208. for (const np of posData) {
  209. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  210. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  211. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  212. }
  213. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  214. node.sgfh_qty = sgfh_qty;
  215. node.sjcl_qty = sjcl_qty;
  216. node.qtcl_qty = qtcl_qty;
  217. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  218. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  219. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  220. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  221. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  222. }
  223. }
  224. }
  225. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  226. };
  227. const billsTree = createNewPathTree('revise', treeSetting);
  228. // 初始化 计量单元
  229. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  230. // 清单 相关方法&绑定spreadjs事件
  231. const billsTreeSpreadObj = {
  232. loadExprToInput(sheet) {
  233. const sel = sheet.getSelections()[0];
  234. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  235. if (col && col.type === 'Number') {
  236. const data = SpreadJsObj.getSelectObject(sheet);
  237. if (data) {
  238. const exprInfo = getExprInfo(col.field);
  239. if (exprInfo) {
  240. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  241. .attr('field', col.field).attr('org', data[col.field]);
  242. } else {
  243. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  244. }
  245. if (col.field.indexOf('dgn') >= 0) {
  246. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  247. } else if (col.field === 'unit_price') {
  248. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  249. } else {
  250. const nodePos = pos.getLedgerPos(data.id);
  251. if (nodePos && nodePos.length > 0) {
  252. $('#bills-expr').val('').attr('readOnly', true);
  253. $('#bills-expr').removeAttr('data-row');
  254. } else {
  255. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  256. }
  257. }
  258. $('#bills-expr').attr('data-row', sel.row);
  259. } else {
  260. $('#bills-expr').val('').attr('readOnly', true);
  261. $('#bills-expr').removeAttr('data-row');
  262. }
  263. } else {
  264. $('#bills-expr').val('').attr('readOnly', true);
  265. $('#bills-expr').removeAttr('data-row');
  266. }
  267. },
  268. getDefaultSelectInfo: function (sheet) {
  269. const tree = sheet.zh_tree;
  270. if (!tree) return;
  271. const sel = sheet.getSelections()[0];
  272. const node = sheet.zh_tree.nodes[sel.row];
  273. if (!node) return;
  274. let count = 1;
  275. if (sel.rowCount > 1) {
  276. for (let r = 1; r < sel.rowCount; r++) {
  277. const rNode = sheet.zh_tree.nodes[sel.row + r];
  278. if (rNode.level > node.level) continue;
  279. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  280. toastr.warning('请选择同一节点下的节点,进行该操作');
  281. return;
  282. }
  283. count += 1;
  284. }
  285. }
  286. return [tree, node, count];
  287. },
  288. /**
  289. * 刷新顶部按钮是否可用
  290. * @param sheet
  291. * @param selections
  292. */
  293. refreshOperationValid: function (sheet, selection) {
  294. const setObjEnable = function (obj, enable) {
  295. if (enable) {
  296. obj.removeClass('disabled');
  297. } else {
  298. obj.addClass('disabled');
  299. }
  300. };
  301. const invalidAll = function () {
  302. setObjEnable($('a[name=base-opr][type=add]'), false);
  303. setObjEnable($('a[name=base-opr][type=delete]'), false);
  304. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  305. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  306. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  307. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  308. };
  309. const sel = selection ? selection[0] : sheet.getSelections()[0];
  310. const row = sel ? sel.row : -1;
  311. const tree = sheet.zh_tree;
  312. if (!tree) {
  313. invalidAll();
  314. return;
  315. }
  316. const first = sheet.zh_tree.nodes[row];
  317. if (!first) {
  318. invalidAll();
  319. return;
  320. }
  321. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  322. if (sel.rowCount > 1 && first) {
  323. for (let r = 1; r < sel.rowCount; r++) {
  324. const rNode = tree.nodes[sel.row + r];
  325. if (!rNode) {
  326. sameParent = false;
  327. break;
  328. }
  329. if (!rNode.formc) {
  330. sameParent = false;
  331. break;
  332. }
  333. nodeUsed = nodeUsed || rNode.used;
  334. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  335. if (rNode.level > first.level) continue;
  336. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  337. sameParent = false;
  338. break;
  339. }
  340. last = rNode;
  341. }
  342. }
  343. const preNode = tree.getPreSiblingNode(first);
  344. const siblings = tree.getChildren(tree.getParent(first));
  345. let upPower = true;
  346. for (let order = last.order; order < siblings.length - 1; order ++) {
  347. if (!siblings[order].formc) {
  348. upPower = false;
  349. break;
  350. }
  351. }
  352. const valid = !sheet.zh_setting.readOnly;
  353. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  354. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  355. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  356. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  357. const posRange = last ? pos.getLedgerPos(last.id) : [];
  358. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  359. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  360. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  361. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  362. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  363. setObjEnable($('#cut'), valid);
  364. setObjEnable($('#paste'), valid);
  365. },
  366. /**
  367. *
  368. * @param sheet
  369. * @param data
  370. */
  371. refreshTree: function (sheet, data) {
  372. SpreadJsObj.massOperationSheet(sheet, function () {
  373. const tree = sheet.zh_tree;
  374. // 处理删除
  375. if (data.delete) {
  376. data.delete.sort(function (a, b) {
  377. return b.deleteIndex - a.deleteIndex;
  378. });
  379. for (const d of data.delete) {
  380. sheet.deleteRows(d.deleteIndex, 1);
  381. }
  382. }
  383. // 处理新增
  384. if (data.create) {
  385. const newNodes = data.create;
  386. if (newNodes) {
  387. newNodes.sort(function (a, b) {
  388. return a.index - b.index;
  389. });
  390. for (const node of newNodes) {
  391. sheet.addRows(node.index, 1);
  392. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  393. }
  394. }
  395. }
  396. // 处理更新
  397. if (data.update) {
  398. const rows = [];
  399. for (const u of data.update) {
  400. rows.push(tree.nodes.indexOf(u));
  401. }
  402. SpreadJsObj.reLoadRowsData(sheet, rows);
  403. }
  404. // 处理展开
  405. if (data.expand) {
  406. const expanded = [];
  407. for (const e of data.expand) {
  408. if (expanded.indexOf(e) === -1) {
  409. const posterity = tree.getPosterity(e);
  410. for (const p of posterity) {
  411. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  412. expanded.push(p);
  413. }
  414. }
  415. }
  416. }
  417. });
  418. },
  419. selectionChanged: function (e, info) {
  420. if (info.newSelections) {
  421. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  422. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  423. billsTreeSpreadObj.refreshPosData();
  424. }
  425. }
  426. billsTreeSpreadObj.loadExprToInput(info.sheet);
  427. },
  428. refreshPosData: function() {
  429. SpreadJsObj.resetTopAndSelect(posSheet);
  430. posSpreadObj.loadCurPosData();
  431. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  432. posSearch.search($('#pos-keyword').val());
  433. },
  434. /**
  435. * 新增节点
  436. * @param spread
  437. */
  438. baseOpr: function (sheet, type, addCount = 1) {
  439. const self = this;
  440. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  441. if (!tree || !node || !count) return;
  442. if (type === 'delete') {
  443. const parent = tree.getParent(node);
  444. const children = parent ? parent.children : tree.children;
  445. const index = children.indexOf(node);
  446. for (let i = 0; i < count; i++) {
  447. const child = children[i+index];
  448. if (tree.checkNodeUsed(child, pos)) {
  449. toastr.warning('选中的节点已计量,不可删除');
  450. return;
  451. }
  452. if (child.settle_status === settleStatus.finish) {
  453. toastr.warning('选中的节点已结算,不可删除');
  454. return;
  455. }
  456. }
  457. } else if (type === 'up-level') {
  458. const parent = tree.getParent(node);
  459. const children = parent ? parent.children : tree.children;
  460. const index = children.indexOf(node);
  461. const lastSelect = children[index + count - 1];
  462. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  463. toastr.warning('选中的节点已计量,不可升级');
  464. return;
  465. }
  466. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  467. toastr.warning('选中的节点已结算,不可升级');
  468. return;
  469. }
  470. // for (let i = index; i < children.length; i++) {
  471. // const child = children[index];
  472. // if (tree.checkNodeUsed(child, pos)) {
  473. // if (i >= index + count) {
  474. // toastr.warning('其后节点已计量,选中的节点不可升级');
  475. // } else {
  476. // toastr.warning('选中的节点已计量,不可升级');
  477. // }
  478. // return;
  479. // }
  480. // }
  481. } else if (type === 'down-level') {
  482. const parent = tree.getParent(node);
  483. const children = parent ? parent.children : tree.children;
  484. const index = children.indexOf(node);
  485. if (index > 0 && children[index-1].used) {
  486. toastr.warning('其前节点已计量,选中的节点不可降级');
  487. return;
  488. }
  489. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  490. toastr.warning('其前节点已结算,选中的节点不可降级');
  491. return;
  492. }
  493. for (let i = index; i < count; i++) {
  494. const child = children[i+index];
  495. if (tree.checkNodeUsed(child, pos)) {
  496. toastr.warning('选中的节点已计量,不可降级');
  497. return;
  498. }
  499. if (tree.settle_status === settleStatus.finish) {
  500. toastr.warning('选中的节点已结算,不可降级');
  501. return;
  502. }
  503. }
  504. } else if (type === 'add') {
  505. if (node.settle_status === settleStatus.finish) {
  506. toastr.warning('选中的节点已结算,不可新增子项');
  507. return;
  508. }
  509. }
  510. if (type === 'delete') {
  511. deleteAfterHint(function () {
  512. postData(window.location.pathname + '/update', {
  513. postType: type,
  514. postData: {
  515. id: node.ledger_id,
  516. count: type === 'add' ? addCount : count,
  517. }
  518. }, function (result) {
  519. const refreshData = tree.loadPostData(result);
  520. self.refreshTree(sheet, refreshData);
  521. const sel = sheet.getSelections()[0];
  522. if (sel) {
  523. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  524. billsTreeSpreadObj.refreshPosData();
  525. }
  526. self.refreshOperationValid(sheet);
  527. });
  528. });
  529. } else {
  530. postData(window.location.pathname + '/update', {
  531. postType: type,
  532. postData: {
  533. id: node.ledger_id,
  534. count: type === 'add' ? addCount : count,
  535. }
  536. }, function (result) {
  537. const refreshData = tree.loadPostData(result);
  538. self.refreshTree(sheet, refreshData);
  539. if (['up-move', 'down-move'].indexOf(type) > -1) {
  540. const sel = sheet.getSelections()[0];
  541. if (sel) {
  542. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  543. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  544. }
  545. } else if (type === 'add') {
  546. const sel = sheet.getSelections()[0];
  547. if (sel) {
  548. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  549. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  550. billsTreeSpreadObj.refreshPosData();
  551. }
  552. }
  553. self.refreshOperationValid(sheet);
  554. });
  555. }
  556. },
  557. /**
  558. * 编辑单元格响应事件
  559. * @param {Object} e
  560. * @param {Object} info
  561. */
  562. editEnded: function (e, info) {
  563. if (info.sheet.zh_setting) {
  564. const col = info.sheet.zh_setting.cols[info.col];
  565. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  566. const node = sortData[info.row];
  567. const data = {
  568. id: node.id,
  569. tender_id: node.tender_id,
  570. ledger_id: node.ledger_id
  571. };
  572. // 未改变值则不提交
  573. const orgValue = node[col.field];
  574. const newValue = trimInvalidChar(info.editingText);
  575. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  576. return;
  577. }
  578. // 台账模式,检查计量单元相关
  579. if (isTz) {
  580. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  581. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  582. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  583. if (!node.children || node.children.length ===0) {
  584. const lPos = pos.getLedgerPos(node.id);
  585. if (lPos && lPos.length > 0) {
  586. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  587. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  588. return;
  589. }
  590. }
  591. }
  592. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  593. const lPos = pos.getLedgerPos(node.id);
  594. if (lPos && lPos.length > 0) {
  595. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  596. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  597. return;
  598. }
  599. }
  600. }
  601. // 获取更新数据
  602. const exprInfo = getExprInfo(col.field);
  603. if (info.editingText) {
  604. const text = newValue;
  605. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  606. toastr.error('节点已计量,请勿删除编号');
  607. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  608. return;
  609. }
  610. if (col.type === 'Number') {
  611. const num = _.toNumber(text);
  612. if (_.isFinite(num)) {
  613. data[col.field] = num;
  614. if (exprInfo) {
  615. data[exprInfo.expr] = '';
  616. }
  617. } else {
  618. try {
  619. data[col.field] = math.evaluate(transExpr(text));
  620. if (exprInfo) {
  621. data[exprInfo.expr] = newValue;
  622. }
  623. } catch(err) {
  624. toastr.error('输入的表达式非法');
  625. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  626. return;
  627. }
  628. }
  629. } else {
  630. data[col.field] = text;
  631. }
  632. } else {
  633. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  634. toastr.error('节点已计量,请勿删除编号');
  635. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  636. return;
  637. }
  638. data[col.field] = null;
  639. if (exprInfo) {
  640. data[exprInfo.expr] = '';
  641. }
  642. }
  643. if (col.field === 'b_code' && newValue) {
  644. const ledgerData = _.filter(billsTree.nodes, function (item) {
  645. return item.b_code !== null && item.b_code !== '' && !item.formc;
  646. });
  647. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  648. if (ledgerOneData) {
  649. data.name = ledgerOneData.name;
  650. data.unit = ledgerOneData.unit;
  651. data.unit_price = ledgerOneData.unit_price;
  652. }
  653. }
  654. // 更新至服务器
  655. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  656. const refreshNode = billsTree.loadPostData(result);
  657. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  658. });
  659. }
  660. },
  661. clipboardPasting: function (e, info) {
  662. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  663. info.cancel = true;
  664. if (!setting || !tree) return;
  665. // const range = info.cellRange;
  666. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  667. // const node = tree.nodes[iRow];
  668. // if (tree.checkNodeUsed(node, pos)) {
  669. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  670. // return;
  671. // }
  672. // }
  673. const pasteData = info.pasteData.html
  674. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  675. : (info.pasteData.text === ''
  676. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  677. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  678. const hint = {
  679. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  680. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  681. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  682. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  683. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  684. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  685. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  686. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  687. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  688. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  689. };
  690. const datas = [], filterNodes = [];
  691. let pid, level, filterRow = 0;
  692. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  693. const curRow = info.cellRange.row + iRow;
  694. const node = tree.nodes[curRow];
  695. if (!node) continue;
  696. if (!pid) pid = node.ledger_pid;
  697. if (!level) level = node.level;
  698. // if (node.ledger_pid !== pid) {
  699. // toastMessageUniq(hint.sameParent);
  700. // filterRow+=1;
  701. // continue;
  702. // }
  703. if (node.level < level) break;
  704. let bPaste = false;
  705. const data = info.sheet.zh_tree.getNodeKeyData(node);
  706. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  707. const curCol = info.cellRange.col + iCol;
  708. const colSetting = info.sheet.zh_setting.cols[curCol];
  709. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  710. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  711. toastMessageUniq(hint.parent);
  712. continue;
  713. }
  714. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  715. toastMessageUniq(hint.gcl);
  716. continue;
  717. }
  718. const lPos = pos.getLedgerPos(node.id);
  719. if (lPos && lPos.length > 0) {
  720. if (value === '' && colSetting.field === 'b_code') {
  721. toastMessageUniq(hint.posCode);
  722. continue;
  723. }
  724. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  725. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  726. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  727. toastMessageUniq(hint.posQty);
  728. continue;
  729. }
  730. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  731. toastMessageUniq(hint.posXmj);
  732. continue;
  733. }
  734. }
  735. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  736. toastMessageUniq (hint.usedUp);
  737. continue;
  738. }
  739. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  740. toastMessageUniq(hint.settle);
  741. continue;
  742. }
  743. if (colSetting.type === 'Number') {
  744. const num = _.toNumber(value);
  745. if (num) {
  746. data[colSetting.field] = num;
  747. } else {
  748. try {
  749. data[colSetting.field] = math.evaluate(transExpr(value));
  750. const exprInfo = getExprInfo(colSetting.field);
  751. if (exprInfo) {
  752. data[exprInfo.expr] = value;
  753. }
  754. bPaste = true;
  755. } catch (err) {
  756. toastMessageUniq(hint.invalidExpr);
  757. continue;
  758. }
  759. }
  760. } else {
  761. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  762. && data[colSetting.field] !== '' && value === '') {
  763. toastMessageUniq(hint.usedCode);
  764. continue;
  765. }
  766. data[colSetting.field] = value;
  767. }
  768. if (colSetting.field === 'b_code' && value) {
  769. const ledgerData = _.filter(billsTree.nodes, function (item) {
  770. return item.b_code !== null && item.b_code !== '' && !item.formc;
  771. });
  772. const ledgerOneData = _.find(ledgerData, { b_code: value });
  773. if (ledgerOneData) {
  774. data.name = ledgerOneData.name;
  775. data.unit = ledgerOneData.unit;
  776. data.unit_price = ledgerOneData.unit_price;
  777. }
  778. }
  779. bPaste = true;
  780. }
  781. if (bPaste) {
  782. datas.push(data);
  783. } else {
  784. filterNodes.push(node);
  785. }
  786. }
  787. if (datas.length > 0) {
  788. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  789. const refreshNode = tree.loadPostData(result);
  790. if (refreshNode.update) {
  791. refreshNode.update = refreshNode.update.concat(filterNodes);
  792. }
  793. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  794. }, function () {
  795. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  796. });
  797. } else {
  798. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  799. }
  800. },
  801. clipboardPasted: function (e, info) {
  802. const hint = {
  803. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  804. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  805. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  806. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  807. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  808. };
  809. const tree = info.sheet.zh_tree;
  810. if (!tree) { return; }
  811. const sortData = info.sheet.zh_tree.nodes;
  812. const datas = [], filterNodes = [];
  813. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  814. let bPaste = false;
  815. const curRow = info.cellRange.row + iRow;
  816. const node = sortData[curRow];
  817. if (node) {
  818. const data = info.sheet.zh_tree.getNodeKeyData(node);
  819. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  820. const curCol = info.cellRange.col + iCol;
  821. const colSetting = info.sheet.zh_setting.cols[curCol];
  822. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  823. const lPos = pos.getLedgerPos(node.id);
  824. if (lPos && lPos.length > 0) {
  825. if (value === '' && colSetting.field === 'b_code') {
  826. toastMessageUniq(hint.posCode);
  827. continue;
  828. }
  829. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  830. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  831. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  832. toastMessageUniq(hint.posQty);
  833. continue;
  834. }
  835. }
  836. if (node.used && colSetting.field === 'unit_price') {
  837. toastMessageUniq (hint.usedUp);
  838. continue;
  839. }
  840. if (colSetting.type === 'Number') {
  841. const num = _.toNumber(value);
  842. if (num) {
  843. data[colSetting.field] = num;
  844. } else {
  845. try {
  846. data[colSetting.field] = math.evaluate(transExpr(value));
  847. } catch (err) {
  848. toastMessageUniq(hint.invalidExpr);
  849. continue;
  850. }
  851. }
  852. } else {
  853. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  854. && data[colSetting.field] !== '' && value === '') {
  855. toastMessageUniq(hint.usedCode);
  856. continue;
  857. }
  858. data[colSetting.field] = value;
  859. }
  860. if (colSetting.field === 'b_code' && value) {
  861. const ledgerData = _.filter(billsTree.nodes, function (item) {
  862. return item.b_code !== null && item.b_code !== '' && !item.formc;
  863. });
  864. const ledgerOneData = _.find(ledgerData, { b_code: value });
  865. if (ledgerOneData) {
  866. data.name = ledgerOneData.name;
  867. data.unit = ledgerOneData.unit;
  868. data.unit_price = ledgerOneData.unit_price;
  869. }
  870. }
  871. bPaste = true;
  872. }
  873. if (bPaste) {
  874. datas.push(data);
  875. } else {
  876. filterNodes.push(node);
  877. }
  878. }
  879. }
  880. if (datas.length > 0) {
  881. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  882. const refreshNode = tree.loadPostData(result);
  883. if (refreshNode.update) {
  884. refreshNode.update = refreshNode.update.concat(filterNodes);
  885. }
  886. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  887. }, function () {
  888. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  889. });
  890. } else {
  891. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  892. }
  893. },
  894. deletePress: function (sheet) {
  895. if (!sheet.zh_setting) return;
  896. const sel = sheet.getSelections()[0], datas = [];
  897. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  898. let bDel = false;
  899. const node = sheet.zh_tree.nodes[iRow];
  900. const data = sheet.zh_tree.getNodeKeyData(node);
  901. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  902. const col = sheet.zh_setting.cols[iCol];
  903. const style = sheet.getStyle(iRow, iCol);
  904. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  905. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  906. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  907. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  908. return;
  909. }
  910. data[col.field] = null;
  911. const exprInfo = getExprInfo(col.field);
  912. if (exprInfo) {
  913. data[exprInfo.expr] = '';
  914. }
  915. bDel = true;
  916. }
  917. if (bDel) datas.push(data);
  918. }
  919. if (datas.length > 0) {
  920. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  921. const refreshNode = sheet.zh_tree.loadPostData(result);
  922. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  923. billsTreeSpreadObj.loadExprToInput(sheet);
  924. });
  925. }
  926. },
  927. pasteBlock: function (spread, copyInfo) {
  928. const self = this;
  929. const sheet = spread.getActiveSheet();
  930. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  931. if (node.settle_status === settleStatus.finish) {
  932. toastr.warning('选中的节点已结算,不可粘贴整块');
  933. return;
  934. }
  935. postData(window.location.pathname + '/update', {
  936. postType: 'paste-block',
  937. postData: {
  938. id: tree.getNodeKey(node),
  939. tid: copyInfo.tid,
  940. block: copyInfo.block,
  941. }
  942. }, function (data) {
  943. pos.updateDatas(data.pos);
  944. const result = tree.loadPostData(data.ledger);
  945. self.refreshTree(sheet, result);
  946. const sel = sheet.getSelections()[0];
  947. if (sel) {
  948. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  949. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  950. }
  951. self.refreshOperationValid(sheet);
  952. removeLocalCache(copyBlockTag);
  953. }, null, true);
  954. },
  955. topRowChanged: function (e, info) {
  956. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  957. },
  958. editStarting(e, info) {
  959. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  960. const col = info.sheet.zh_setting.cols[info.col];
  961. const node = info.sheet.zh_tree.nodes[info.row];
  962. if (!node) {
  963. info.cancel = true;
  964. return;
  965. }
  966. const exprInfo = getExprInfo(col.field);
  967. if (exprInfo) {
  968. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  969. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  970. }
  971. }
  972. switch (col.field) {
  973. case 'code':
  974. const posRange = pos.getLedgerPos(node.id);
  975. info.cancel = posRange && posRange.length > 0;
  976. break;
  977. case 'unit_price':
  978. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  979. break;
  980. case 'sgfh_qty':
  981. case 'sgfh_tp':
  982. case 'sjcl_qty':
  983. case 'sjcl_tp':
  984. case 'qtcl_qty':
  985. case 'qtcl_tp':
  986. case 'deal_qty':
  987. case 'deal_tp':
  988. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  989. break;
  990. case 'dgn_qty1':
  991. case 'dgn_qty2':
  992. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  993. break;
  994. }
  995. },
  996. cut: function (sheet, sel, callback) {
  997. if (!sheet || !sel) return;
  998. if (sel.colCount >= sheet.zh_setting.cols.length) {
  999. toastr.warning('请勿选中整行剪切');
  1000. return;
  1001. }
  1002. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1003. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1004. const node = sortData[iRow];
  1005. if (node) {
  1006. const data = sheet.zh_tree.getNodeKeyData(node);
  1007. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1008. const col = sheet.zh_setting.cols[iCol];
  1009. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1010. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1011. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  1012. const lPos = pos.getLedgerPos(node.id);
  1013. if (lPos && lPos.length > 0) {
  1014. toastr.error('不可剪切');
  1015. return;
  1016. }
  1017. }
  1018. const style = sheet.getStyle(iRow, iCol);
  1019. if (style.locked) {
  1020. toastr.error('不可剪切');
  1021. return;
  1022. }
  1023. const colSetting = sheet.zh_setting.cols[iCol];
  1024. data[colSetting.field] = null;
  1025. const exprInfo = getExprInfo(colSetting.field);
  1026. if (exprInfo) {
  1027. data[exprInfo.expr] = '';
  1028. }
  1029. }
  1030. datas.push(data);
  1031. }
  1032. }
  1033. if (datas.length > 0) {
  1034. callback();
  1035. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1036. const refreshNode = sheet.zh_tree.loadPostData(result);
  1037. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1038. });
  1039. }
  1040. },
  1041. sortCode: function (sheet) {
  1042. const tree = sheet.zh_tree;
  1043. if (!tree) return;
  1044. const select = SpreadJsObj.getSelectObject(sheet);
  1045. if (!select || !select.code || select.code === '') return;
  1046. const recursiveSortCode = function (data, parentCode, children) {
  1047. if (!children || children.length === 0) return;
  1048. for (const [i, child] of children.entries()) {
  1049. if (!child.b_code || child.b_code === '') {
  1050. const code = parentCode + '-' + (i + 1);
  1051. const cData = tree.getNodeKeyData(child);
  1052. cData.code = code;
  1053. data.push(cData);
  1054. if (!tree.isLeafXmj(child)) {
  1055. recursiveSortCode(data, code, child.children);
  1056. }
  1057. }
  1058. }
  1059. };
  1060. const data = [];
  1061. recursiveSortCode(data, select.code, select.children);
  1062. if (data.length > 0) {
  1063. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1064. const refreshNode = tree.loadPostData(result);
  1065. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1066. })
  1067. }
  1068. }
  1069. };
  1070. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1071. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1072. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1073. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1074. if (!readOnly) {
  1075. // 增删上下移升降级
  1076. $('a[name="base-opr"]').click(function () {
  1077. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1078. });
  1079. $('a[name=cpc]').click(function () {
  1080. billsSpread.commandManager().execute({
  1081. cmd: this.getAttribute('type'),
  1082. sheetName: billsSheet.name()
  1083. });
  1084. });
  1085. $('#bills-expr').bind('change onblur', function () {
  1086. if (this.readOnly) return;
  1087. const expr = $(this);
  1088. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1089. const select = billsTree.getItemsByIndex(row);
  1090. if (!select) return;
  1091. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1092. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1093. const data = {
  1094. id: select.id,
  1095. tender_id: select.tender_id,
  1096. ledger_id: select.ledger_id
  1097. };
  1098. const exprInfo = getExprInfo(field);
  1099. if (newValue !== '') {
  1100. const num = _.toNumber(newValue);
  1101. if (num) {
  1102. data[field] = num;
  1103. if (exprInfo) {
  1104. data[exprInfo.expr] = '';
  1105. }
  1106. } else {
  1107. try {
  1108. data[field] = math.evaluate(transExpr(newValue));
  1109. if (exprInfo) {
  1110. data[exprInfo.expr] = newValue;
  1111. }
  1112. } catch (err) {
  1113. toastr.error('输入的表达式非法');
  1114. return;
  1115. }
  1116. }
  1117. } else {
  1118. data[field] = null;
  1119. if (exprInfo) {
  1120. data[exprInfo.expr] = '';
  1121. }
  1122. }
  1123. // 更新至服务器
  1124. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1125. const refreshNode = billsTree.loadPostData(result);
  1126. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1127. });
  1128. });
  1129. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1130. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1131. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1132. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1133. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1134. SpreadJsObj.Clipboard.setCopyData(copyText);
  1135. });
  1136. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1137. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1138. }
  1139. // 右键菜单
  1140. let batchInsertObj;
  1141. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1142. const self = this;
  1143. if ($.isFunction(item.icon)) {
  1144. item._icon = item.icon.call(this, this, $t, key, item);
  1145. } else {
  1146. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1147. // to enable font awesome
  1148. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1149. } else {
  1150. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1151. }
  1152. }
  1153. this.addClass(item._icon);
  1154. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1155. .appendTo(this);
  1156. const $input = $obj.find('input');
  1157. const event = () => {
  1158. if (self.hasClass('context-menu-disabled')) return;
  1159. item.batchInsert($input[0], root);
  1160. };
  1161. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1162. $input.click((e) => {e.stopPropagation();})
  1163. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1164. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1165. };
  1166. const billsContextMenuOptions = {
  1167. selector: '#bills-spread',
  1168. build: function ($trigger, e) {
  1169. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1170. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1171. },
  1172. items: {}
  1173. };
  1174. if (!readOnly) {
  1175. billsContextMenuOptions.items.create = {
  1176. name: '新增',
  1177. icon: 'fa-sign-in',
  1178. callback: function (key, opt) {
  1179. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1180. },
  1181. disabled: function (key, opt) {
  1182. const sheet = billsSheet;
  1183. const selection = sheet.getSelections();
  1184. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1185. const row = sel ? sel.row : -1;
  1186. const tree = sheet.zh_tree;
  1187. if (!tree) return true;
  1188. const first = sheet.zh_tree.nodes[row];
  1189. const valid = !sheet.zh_setting.readOnly;
  1190. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1191. }
  1192. };
  1193. billsContextMenuOptions.items.delete = {
  1194. name: '删除',
  1195. icon: 'fa-remove',
  1196. callback: function (key, opt) {
  1197. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1198. },
  1199. disabled: function (key, opt) {
  1200. const sheet = billsSheet;
  1201. const selection = sheet.getSelections();
  1202. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1203. const row = sel ? sel.row : -1;
  1204. const tree = sheet.zh_tree;
  1205. if (!tree) return true;
  1206. const first = sheet.zh_tree.nodes[row];
  1207. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  1208. if (sel.rowCount > 1 && first) {
  1209. for (let r = 1; r < sel.rowCount; r++) {
  1210. const rNode = tree.nodes[sel.row + r];
  1211. if (!rNode) {
  1212. sameParent = false;
  1213. break;
  1214. }
  1215. if (!rNode.formc) {
  1216. return true;
  1217. }
  1218. nodeUsed = nodeUsed || rNode.used;
  1219. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  1220. if (rNode.level > first.level) continue;
  1221. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1222. sameParent = false;
  1223. break;
  1224. }
  1225. last = rNode;
  1226. }
  1227. }
  1228. const valid = !sheet.zh_setting.readOnly;
  1229. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  1230. }
  1231. };
  1232. billsContextMenuOptions.items.sprBase = '----';
  1233. }
  1234. billsContextMenuOptions.items.copyBlock = {
  1235. name: '复制整块',
  1236. icon: 'fa-files-o',
  1237. callback: function (key, opt) {
  1238. const copyBlockList = [];
  1239. const sheet = billsSheet;
  1240. const sel = sheet.getSelections()[0];
  1241. let iRow = sel.row;
  1242. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1243. while (iRow < sel.row + sel.rowCount) {
  1244. const node = sheet.zh_tree.nodes[iRow];
  1245. if (node.ledger_pid !== pid) {
  1246. toastr.error('仅可同时选中同层节点');
  1247. return;
  1248. }
  1249. const posterity = sheet.zh_tree.getPosterity(node);
  1250. iRow += posterity.length + 1;
  1251. posterity.unshift(node);
  1252. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1253. }
  1254. for (const cbl of copyBlockList) {
  1255. for (const b of cbl) {
  1256. const posRange = pos.getLedgerPos(b.id);
  1257. if (posRange && posRange.length > 0) b.pos = posRange;
  1258. }
  1259. }
  1260. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1261. },
  1262. visible: function (key, opt) {
  1263. const sheet = billsSheet;
  1264. const selection = sheet.getSelections();
  1265. const row = selection[0].row;
  1266. const select = billsTree.nodes[row];
  1267. return select;
  1268. },
  1269. disabled: function (key, opt) {
  1270. const sheet = billsSheet;
  1271. const selection = sheet.getSelections();
  1272. const row = selection[0].row;
  1273. const select = billsTree.nodes[row];
  1274. return select && select.level <= 1;
  1275. }
  1276. };
  1277. billsContextMenuOptions.items.copyBlockXmj = {
  1278. name: '复制整块(只复制项目节)',
  1279. icon: 'fa-files-o',
  1280. callback: function (key, opt) {
  1281. const copyBlockList = [];
  1282. const sheet = billsSheet;
  1283. const sel = sheet.getSelections()[0];
  1284. let iRow = sel.row;
  1285. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1286. while (iRow < sel.row + sel.rowCount) {
  1287. const node = sheet.zh_tree.nodes[iRow];
  1288. if (node.ledger_pid !== pid) {
  1289. toastr.error('仅可同时选中同层节点');
  1290. return;
  1291. }
  1292. const posterity = sheet.zh_tree.getPosterity(node);
  1293. iRow += posterity.length + 1;
  1294. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1295. copyPosterity.unshift(node);
  1296. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1297. for (const p of copyData) {
  1298. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1299. p.is_leaf = children.length === 0;
  1300. }
  1301. copyBlockList.push(copyData);
  1302. }
  1303. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1304. },
  1305. visible: function (key, opt) {
  1306. const sheet = billsSheet;
  1307. const selection = sheet.getSelections();
  1308. const row = selection[0].row;
  1309. const select = billsTree.nodes[row];
  1310. return select;
  1311. },
  1312. disabled: function (key, opt) {
  1313. const sheet = billsSheet;
  1314. const selection = sheet.getSelections();
  1315. const row = selection[0].row;
  1316. const select = billsTree.nodes[row];
  1317. return select && select.level <= 1;
  1318. }
  1319. };
  1320. if (!readOnly) {
  1321. billsContextMenuOptions.items.pasteBlock = {
  1322. name: '粘贴整块',
  1323. icon: 'fa-clipboard',
  1324. disabled: function (key, opt) {
  1325. //const block = treeOperationObj.block || [];
  1326. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1327. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1328. },
  1329. callback: function (key, opt) {
  1330. //const block = treeOperationObj.block || [];
  1331. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1332. if (copyInfo.block.length > 0) {
  1333. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1334. } else {
  1335. document.execCommand('paste');
  1336. }
  1337. },
  1338. visible: function (key, opt) {
  1339. return !readOnly;
  1340. }
  1341. };
  1342. billsContextMenuOptions.items.sprBlock = '----';
  1343. }
  1344. if (!readOnly) {
  1345. billsContextMenuOptions.items.batchInsert = {
  1346. name: '批量插入',
  1347. type: 'batchInsert',
  1348. value: '2',
  1349. icon: 'fa-sign-in',
  1350. batchInsert: function (obj, root) {
  1351. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1352. obj.value = obj.max;
  1353. toastr.warning('批量插入不可多于' + obj.max);
  1354. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1355. obj.value = obj.min;
  1356. toastr.warning('批量插入不可少于' + obj.min);
  1357. } else {
  1358. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1359. root.$menu.trigger('contextmenu:hide');
  1360. }
  1361. },
  1362. disabled: function (key, opt) {
  1363. const sheet = billsSheet;
  1364. const selection = sheet.getSelections();
  1365. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1366. const row = sel ? sel.row : -1;
  1367. const tree = sheet.zh_tree;
  1368. if (!tree) return true;
  1369. const first = sheet.zh_tree.nodes[row];
  1370. const valid = !sheet.zh_setting.readOnly;
  1371. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1372. }
  1373. };
  1374. billsContextMenuOptions.items.batchInsertBillsPos = {
  1375. name: '批量插入清单-计量单元',
  1376. icon: 'fa-sign-in',
  1377. visible: function (key, opt) {
  1378. return false;
  1379. },
  1380. disabled: function (key, opt) {
  1381. if (!isTz) return true;
  1382. const select = SpreadJsObj.getSelectObject(billsSheet);
  1383. if (select) {
  1384. if (select.code && select.code !== '') {
  1385. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  1386. } else {
  1387. const parent = billsTree.getParent(select);
  1388. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  1389. }
  1390. } else {
  1391. return false;
  1392. }
  1393. },
  1394. callback: function (key, opt) {
  1395. if (!batchInsertObj) {
  1396. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1397. } else {
  1398. batchInsertObj.initView();
  1399. }
  1400. $('#batch').modal('show');
  1401. }
  1402. };
  1403. }
  1404. billsContextMenuOptions.items.sprTag = '----';
  1405. billsContextMenuOptions.items.showLast = {
  1406. name: '显示至最底层',
  1407. callback: function (key, opt, menu, e) {
  1408. const node = SpreadJsObj.getSelectObject(billsSheet);
  1409. setTimeout(() => {
  1410. showWaitingView();
  1411. billsTree.expandByCustom(x => {
  1412. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1413. });
  1414. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  1415. closeWaitingView();
  1416. }, 100);
  1417. },
  1418. };
  1419. $.contextMenu(billsContextMenuOptions);
  1420. // 计量单元 相关方法&绑定spreadjs事件
  1421. const posSpreadObj = {
  1422. refreshOperationValid: function (sheet, selection) {
  1423. const setObjEnable = function (obj, enable) {
  1424. if (enable) {
  1425. obj.removeClass('disabled');
  1426. } else {
  1427. obj.addClass('disabled');
  1428. }
  1429. };
  1430. const invalidAll = function () {
  1431. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1432. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1433. };
  1434. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1435. const row = sel ? sel.row : -1;
  1436. const first = sheet.zh_data[row];
  1437. if (!first) {
  1438. invalidAll();
  1439. return;
  1440. }
  1441. let last = first;
  1442. if (sel.rowCount > 1 && first) {
  1443. for (let r = 1; r < sel.rowCount; r++) {
  1444. const rNode = sheet.zh_data[sel.row + r];
  1445. if (!rNode) break;
  1446. last = rNode;
  1447. }
  1448. }
  1449. const preNode = sheet.zh_data[row - 1];
  1450. const valid = !sheet.zh_setting.readOnly;
  1451. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  1452. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  1453. },
  1454. loadExprToInput: function () {
  1455. const sel = posSheet.getSelections()[0];
  1456. if (!sel) return;
  1457. const col = posSheet.zh_setting.cols[sel.col];
  1458. const cell = posSheet.getCell(sel.col, sel.col);
  1459. if (col && col.type === 'Number') {
  1460. const data = SpreadJsObj.getSelectObject(posSheet);
  1461. if (data) {
  1462. const exprInfo = getExprInfo(col.field);
  1463. const value = exprInfo
  1464. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1465. : data[col.field];
  1466. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1467. .attr('readOnly', readOnly || (!data.formc && cell.locked()) || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  1468. } else {
  1469. $('#pos-expr').val('').attr('readOnly', true);
  1470. $('#pos-expr').removeAttr('data-row');
  1471. }
  1472. } else {
  1473. $('#pos-expr').val('').attr('readOnly', true);
  1474. $('#pos-expr').removeAttr('data-row');
  1475. }
  1476. },
  1477. /**
  1478. * 加载计量单元 根据当前台账选择节点
  1479. */
  1480. loadCurPosData: function () {
  1481. const node = SpreadJsObj.getSelectObject(billsSheet);
  1482. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  1483. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  1484. if (node) {
  1485. const posData = pos.getLedgerPos(node.id) || [];
  1486. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1487. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  1488. } else {
  1489. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1490. posSheet.zh_setting.readOnly = true;
  1491. }
  1492. SpreadJsObj.massOperationSheet(posSheet, function () {
  1493. if (posSheet.zh_setting) {
  1494. posSheet.zh_setting.cols.forEach(function (col, i) {
  1495. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  1496. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  1497. }
  1498. });
  1499. }
  1500. });
  1501. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  1502. posSpreadObj.loadExprToInput();
  1503. posSpreadObj.refreshOperationValid(posSheet);
  1504. },
  1505. baseOpr: function (sheet, type) {
  1506. const data = {
  1507. postType: 'pos',
  1508. posPostType: type === 'delete' ? type : 'update',
  1509. postData: [],
  1510. };
  1511. const selection = sheet.getSelections();
  1512. const row = selection[0].row, count = selection[0].rowCount;
  1513. const first = sheet.zh_data[row];
  1514. if (type === 'delete') {
  1515. for (let iRow = 0; iRow < count; iRow++) {
  1516. const posData = sheet.zh_data[iRow + row];
  1517. if (posData) {
  1518. if (posData.used) {
  1519. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1520. return;
  1521. }
  1522. if (posData.settle_status) {
  1523. toastr.error('"' + posData.name + '"已结算,请勿删除');
  1524. return;
  1525. }
  1526. data.postData.push(sheet.zh_data[iRow + row].id);
  1527. }
  1528. }
  1529. } else if (type === 'up-move') {
  1530. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1531. for (let iRow = 0; iRow < count; iRow++) {
  1532. const posData = sheet.zh_data[iRow + row];
  1533. if (posData) {
  1534. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1535. preUpdate.porder = posData.porder;
  1536. }
  1537. }
  1538. data.postData.push(preUpdate);
  1539. } else if (type === 'down-move') {
  1540. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1541. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1542. const posData = sheet.zh_data[iRow + row];
  1543. if (posData) {
  1544. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1545. nextUpdate.porder = posData.porder;
  1546. }
  1547. }
  1548. data.postData.push(nextUpdate);
  1549. } else if (type === 'add') {
  1550. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1551. if (billsNode.settle_status === settleStatus.finish) {
  1552. toastr.warning('清单已结算,不可新增计量单元');
  1553. return;
  1554. }
  1555. }
  1556. if (data.postData.length > 0) {
  1557. postData(window.location.pathname + '/update', data, function (result) {
  1558. if (type === 'delete') {
  1559. pos.removeDatas(result.pos);
  1560. sheet.deleteRows(row, count);
  1561. const loadResult = billsTree.loadPostData(result.ledger);
  1562. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1563. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1564. posSpreadObj.refreshOperationValid(posSheet);
  1565. } else {
  1566. pos.updateDatas(result.pos);
  1567. const sel = selection[0];
  1568. if (sel) {
  1569. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1570. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1571. }
  1572. posSpreadObj.loadCurPosData();
  1573. }
  1574. });
  1575. }
  1576. },
  1577. editStarting: function (e, info) {
  1578. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1579. const sel = info.sheet.getSelections();
  1580. if (!sel || !sel[0]) return;
  1581. const col = info.sheet.zh_setting.cols[sel[0].col];
  1582. const node = SpreadJsObj.getSelectObject(info.sheet);
  1583. const exprInfo = getExprInfo(col.field);
  1584. if (node && exprInfo) {
  1585. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1586. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1587. }
  1588. }
  1589. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1590. info.cancel = true;
  1591. }
  1592. },
  1593. /**
  1594. * 编辑单元格响应事件
  1595. * @param {Object} e
  1596. * @param {Object} info
  1597. */
  1598. editEnded: function (e, info) {
  1599. if (!info.sheet.zh_setting) {
  1600. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1601. return;
  1602. }
  1603. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1604. const col = info.sheet.zh_setting.cols[info.col];
  1605. const orgText = posData ? posData[col.field] : null;
  1606. const newText = trimInvalidChar(info.editingText);
  1607. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1608. const node = posSpreadObj.billsNode;
  1609. if (!node) {
  1610. toastr.error('数据错误,请选择台账节点后再试');
  1611. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1612. return;
  1613. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1614. toastr.error('父节点不可插入计量单元');
  1615. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1616. return;
  1617. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1618. toastr.error('项目节不可插入计量单元');
  1619. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1620. return;
  1621. }
  1622. const data = {postType: 'pos'};
  1623. if (col.field === 'name') {
  1624. if (newText === '' && posData) {
  1625. toastr.error('部位名称不可为空', 'error');
  1626. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1627. return;
  1628. } else if (!posData) {
  1629. if (newText && newText !== '') {
  1630. data.posPostType = 'add';
  1631. const sortData = info.sheet.zh_data;
  1632. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1633. data.postData = { name: newText, lid: node.id, porder: order};
  1634. if (node.settle_status === settleStatus.finish) {
  1635. toastr.error('已结算清单不可插入计量单元');
  1636. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1637. return;
  1638. }
  1639. } else {
  1640. return;
  1641. }
  1642. } else {
  1643. data.posPostType = 'update';
  1644. data.postData = {id: posData.id, name: newText};
  1645. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  1646. toastr.error('计量单元已结算,不可修改');
  1647. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1648. return;
  1649. }
  1650. }
  1651. } else if (!posData) {
  1652. toastr.warning('新增计量单元请先输入名称');
  1653. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1654. return;
  1655. } else {
  1656. data.posPostType = 'update';
  1657. data.postData = {id: posData.id};
  1658. if (col.type === 'Number') {
  1659. const exprInfo = getExprInfo(col.field);
  1660. const num = _.toNumber(newText);
  1661. if (_.isFinite(num)) {
  1662. data.postData[col.field] = num;
  1663. if (exprInfo) {
  1664. data.postData[exprInfo.expr] = '';
  1665. }
  1666. } else {
  1667. try {
  1668. data.postData[col.field] = math.evaluate(transExpr(newText));
  1669. if (exprInfo) {
  1670. data.postData[exprInfo.expr] = newText;
  1671. }
  1672. } catch(err) {
  1673. toastr.error('输入的表达式非法');
  1674. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1675. return;
  1676. }
  1677. }
  1678. } else {
  1679. data.postData[col.field] = newText;
  1680. }
  1681. }
  1682. postData(window.location.pathname + '/update', data, function (result) {
  1683. const updateRst = pos.updateDatas(result.pos);
  1684. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1685. if (updateRst.create.length > 0) {
  1686. posSpreadObj.loadCurPosData();
  1687. } else {
  1688. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1689. }
  1690. const loadResult = billsTree.loadPostData(result.ledger);
  1691. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1692. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1693. }, function () {
  1694. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1695. });
  1696. },
  1697. /**
  1698. * 删除按钮响应事件
  1699. * @param sheet
  1700. */
  1701. deletePress: function (sheet) {
  1702. if (!sheet.zh_setting) return;
  1703. const sortData = sheet.zh_data;
  1704. const datas = [], posSelects = [];
  1705. const sel = sheet.getSelections()[0];
  1706. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1707. let bDel = false;
  1708. const node = sortData[iRow];
  1709. if (node) {
  1710. const data = {id: node.id};
  1711. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1712. const colSetting = sheet.zh_setting.cols[iCol];
  1713. if (colSetting.field === 'name') {
  1714. toastr.error('部位名称不能为空');
  1715. return;
  1716. }
  1717. const style = sheet.getStyle(iRow, iCol);
  1718. if (!style.locked) {
  1719. const colSetting = sheet.zh_setting.cols[iCol];
  1720. data[colSetting.field] = null;
  1721. const exprInfo = getExprInfo(colSetting.field);
  1722. if (exprInfo) {
  1723. data[exprInfo.expr] = '';
  1724. }
  1725. bDel = true;
  1726. }
  1727. }
  1728. if (bDel) {
  1729. datas.push(data);
  1730. posSelects.push(node);
  1731. }
  1732. }
  1733. }
  1734. if (datas.length > 0) {
  1735. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1736. pos.updateDatas(result.pos);
  1737. posSpreadObj.loadCurPosData();
  1738. const loadResult = billsTree.loadPostData(result.ledger);
  1739. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1740. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1741. }, function () {
  1742. posSpreadObj.loadCurPosData();
  1743. });
  1744. }
  1745. },
  1746. /**
  1747. * 删除 计量单元
  1748. * @param sheet
  1749. */
  1750. deletePos: function (sheet) {
  1751. const selection = sheet.getSelections();
  1752. const data = {
  1753. postType: 'pos',
  1754. posPostType: 'delete',
  1755. postData: [],
  1756. };
  1757. const row = selection[0].row, count = selection[0].rowCount;
  1758. const sortData = sheet.zh_data;
  1759. for (let iRow = 0; iRow < count; iRow++) {
  1760. const posData = sortData[iRow + row];
  1761. if (posData) {
  1762. if (posData.used) {
  1763. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1764. return;
  1765. }
  1766. if (posData.settle_status === settleStatus.finish) {
  1767. toastr.error(`"${posData.name}"已计量,请勿删除`);
  1768. return;
  1769. }
  1770. data.postData.push(sortData[iRow + row].id);
  1771. }
  1772. }
  1773. if (data.postData.length > 0) {
  1774. postData(window.location.pathname + '/update', data, function (result) {
  1775. pos.removeDatas(result.pos);
  1776. sheet.deleteRows(row, count);
  1777. const loadResult = billsTree.loadPostData(result.ledger);
  1778. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1779. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1780. });
  1781. }
  1782. },
  1783. /**
  1784. * 粘贴单元格响应事件
  1785. * @param e
  1786. * @param info
  1787. */
  1788. clipboardPasted: function (e, info) {
  1789. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1790. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1791. }
  1792. const node = SpreadJsObj.getSelectObject(billsSheet);
  1793. if (node.code && (node.code !== '')) {
  1794. toastr.error('项目节不可含有节点明细');
  1795. posSpreadObj.loadCurPosData();
  1796. return;
  1797. }
  1798. if (node.children && (node.children.length > 0)) {
  1799. toastr.error('仅节点子项可以含有计量单元');
  1800. posSpreadObj.loadCurPosData();
  1801. return;
  1802. }
  1803. if (node.settle_status === settleStatus.finish) {
  1804. toastr.error('清单已结算,请勿修改计量单元数据');
  1805. posSpread.loadCurPosData();
  1806. return;
  1807. }
  1808. if (!info.sheet.zh_setting) {
  1809. posSpreadObj.loadCurPosData();
  1810. return;
  1811. }
  1812. const data = [];
  1813. const sortData = info.sheet.zh_data || [];
  1814. const hint = {
  1815. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  1816. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  1817. };
  1818. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1819. if (info.cellRange.col !== 0) {
  1820. toastr.warning('新增计量单元请先输入名称');
  1821. posSpreadObj.loadCurPosData();
  1822. return;
  1823. }
  1824. }
  1825. let bHint = false;
  1826. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1827. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1828. let bPaste = true;
  1829. const curRow = info.cellRange.row + iRow;
  1830. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1831. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1832. const curCol = info.cellRange.col + iCol;
  1833. const colSetting = info.sheet.zh_setting.cols[curCol];
  1834. if (!colSetting) continue;
  1835. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1836. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  1837. bPaste = false;
  1838. toastMessageUniq(hint.settle);
  1839. continue;
  1840. }
  1841. if (colSetting.type === 'Number') {
  1842. const num = _.toNumber(posData[colSetting.field]);
  1843. if (num) {
  1844. posData[colSetting.field] = num;
  1845. } else {
  1846. try {
  1847. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1848. const exprInfo = getExprInfo(colSetting.field);
  1849. if (exprInfo) {
  1850. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1851. }
  1852. } catch (err) {
  1853. if (!bHint) {
  1854. toastr.warning('粘贴了非法表达式,已过滤');
  1855. bHint = true;
  1856. }
  1857. bPaste = false;
  1858. }
  1859. }
  1860. }
  1861. }
  1862. if (bPaste) {
  1863. data.push(posData);
  1864. }
  1865. }
  1866. if (data.length === 0) {
  1867. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1868. return;
  1869. }
  1870. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1871. pos.updateDatas(result.pos);
  1872. posSpreadObj.loadCurPosData();
  1873. const loadResult = billsTree.loadPostData(result.ledger);
  1874. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1875. posSpreadObj.loadCurPosData();
  1876. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1877. }, function () {
  1878. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1879. });
  1880. },
  1881. selectionChanged: function (e, info) {
  1882. posSpreadObj.loadExprToInput();
  1883. posSpreadObj.refreshOperationValid(posSheet);
  1884. },
  1885. addPegs: function (pegs) {
  1886. if (!pegs || pegs.length <= 0) return;
  1887. const node = SpreadJsObj.getSelectObject(billsSheet);
  1888. if (!node) return;
  1889. const sheet = posSpread.getActiveSheet();
  1890. const sortData = sheet.zh_data || [];
  1891. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1892. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1893. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1894. pos.updateDatas(result.pos);
  1895. posSpreadObj.loadCurPosData();
  1896. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1897. });
  1898. }
  1899. };
  1900. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1901. if (!readOnly && isTz) {
  1902. $('a[name="pos-opr"]').click(function () {
  1903. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  1904. });
  1905. $('#pos-expr').bind('change onblur', function () {
  1906. if (this.readOnly) return;
  1907. const expr = $(this);
  1908. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1909. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1910. if (!select) return;
  1911. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1912. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  1913. const data = {id: select.id};
  1914. const exprInfo = getExprInfo(field);
  1915. if (newValue !== '') {
  1916. const num = _.toNumber(newValue);
  1917. if (num) {
  1918. data[field] = num;
  1919. if (exprInfo) data[exprInfo.expr] = '';
  1920. } else {
  1921. try {
  1922. data[field] = math.evaluate(transExpr(newValue));
  1923. if (exprInfo) data[exprInfo.expr] = newValue;
  1924. } catch (err) {
  1925. toastr.error('输入的表达式非法');
  1926. return;
  1927. }
  1928. }
  1929. } else {
  1930. data[field] = null;
  1931. if (exprInfo) data[exprInfo.expr] = '';
  1932. }
  1933. // 更新至服务器
  1934. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1935. const updateRst = pos.updateDatas(result.pos);
  1936. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1937. SpreadJsObj.reLoadRowData(posSheet, row);
  1938. const loadResult = billsTree.loadPostData(result.ledger);
  1939. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1940. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1941. });
  1942. });
  1943. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1944. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1945. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1946. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1947. $.contextMenu({
  1948. selector: '#pos-spread',
  1949. build: function ($trigger, e) {
  1950. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1951. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1952. },
  1953. items: {
  1954. 'delete': {
  1955. name: '删除',
  1956. icon: 'fa-remove',
  1957. disabled: function (key, opt) {
  1958. if (posSheet.zh_data) {
  1959. const selection = posSheet.getSelections();
  1960. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1961. const row = sel ? sel.row : -1;
  1962. const rowCount = sel.rowCount;
  1963. let settleFinish = false;
  1964. for (let i = row; i < row + rowCount; i++) {
  1965. if (!posSheet.zh_data[i]) continue;
  1966. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  1967. }
  1968. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  1969. } else {
  1970. return true;
  1971. }
  1972. },
  1973. callback: function (key, opt) {
  1974. posSpreadObj.deletePos(posSheet);
  1975. }
  1976. },
  1977. }
  1978. });
  1979. }
  1980. // 加载清单&计量单元数据
  1981. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  1982. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  1983. billsTree.loadDatas(result.bills);
  1984. pos.loadDatas(result.pos);
  1985. treeCalc.calculateAll(billsTree);
  1986. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1987. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1988. checkShowLast(result.bills.length);
  1989. posSpreadObj.loadCurPosData();
  1990. SpreadJsObj.resetTopAndSelect(posSheet);
  1991. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1992. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1993. checkList.loadHisCheckData();
  1994. console.log(billsTree);
  1995. }, null);
  1996. $.divResizer({
  1997. select: '#revise-resize',
  1998. callback: function () {
  1999. billsSpread.refresh();
  2000. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2001. $(".sp-wrap").height(bcontent-30);
  2002. posSpread.refresh();
  2003. }
  2004. });
  2005. class DealBills {
  2006. constructor (selector, spreadSetting) {
  2007. const self = this;
  2008. this.loaded = false;
  2009. this.obj = $(selector)[0];
  2010. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2011. this.spreadSetting = spreadSetting;
  2012. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2013. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2014. if (!readOnly) {
  2015. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2016. const dealSheet = info.sheet;
  2017. const mainSheet = billsSheet;
  2018. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2019. if (!dealBills) { return; }
  2020. const mainTree = mainSheet.zh_tree;
  2021. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2022. if (!mainNode || !mainTree) { return; }
  2023. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2024. toastr.warning('非最底层项目下,不应添加节点');
  2025. return;
  2026. }
  2027. if (mainNode.settle_status === settleStatus.finish) {
  2028. toastr.warning('已结算节点下,不应添加签约清单');
  2029. return;
  2030. }
  2031. postData(window.location.pathname + '/update', {
  2032. postType: 'add-deal',
  2033. postData: {
  2034. id: mainNode.ledger_id,
  2035. type: mainNode.code ? 'child' : 'next',
  2036. dealBills: {
  2037. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2038. unit_price: dealBills.unit_price,
  2039. }
  2040. },
  2041. }, function (result) {
  2042. const refreshData = mainTree.loadPostData(result);
  2043. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2044. const sel = mainSheet.getSelections()[0];
  2045. if (sel && refreshData.create[0]) {
  2046. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2047. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2048. }
  2049. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2050. billsSpread.focus();
  2051. posSpreadObj.loadCurPosData();
  2052. });
  2053. });
  2054. }
  2055. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2056. }
  2057. loadData (callback) {
  2058. if (this.loaded) {
  2059. if (callback) callback();
  2060. return;
  2061. }
  2062. const self = this;
  2063. postData(this.url+'/get-data', {}, function (data) {
  2064. self.data = data;
  2065. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2066. self.loaded = true;
  2067. if (callback) callback();
  2068. });
  2069. }
  2070. calculateData () {
  2071. if (this.data) {
  2072. for (const d of this.data) {
  2073. d.total_price = _.multiply(d.quantity, d.unit_price);
  2074. }
  2075. }
  2076. }
  2077. }
  2078. class BatchInsertBillsPosObj {
  2079. constructor (obj) {
  2080. const self = this;
  2081. this.obj = obj;
  2082. this.billsCount = 6;
  2083. this.posCount = 1000;
  2084. this.filter = getLocalCache('zh-calc-batch-filter');
  2085. if (!this.filter) {
  2086. this.filter = '1';
  2087. }
  2088. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2089. // 初始化 清单编号窗口 参数
  2090. this.qdSpreadSetting = {
  2091. cols: [
  2092. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2093. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2094. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2095. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2096. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2097. ],
  2098. emptyRows: this.billsCount,
  2099. headRows: 1,
  2100. headRowHeight: [32],
  2101. headerFont: '12px 微软雅黑',
  2102. font: '12px 微软雅黑',
  2103. };
  2104. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2105. // 初始化 部位数量复核表 参数
  2106. this.posSpreadSetting = {
  2107. cols: [
  2108. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2109. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2110. ],
  2111. emptyRows: this.posCount,
  2112. headRows: 1,
  2113. headRowHeight: [32],
  2114. headerFont: '12px 微软雅黑',
  2115. font: '12px 微软雅黑',
  2116. };
  2117. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2118. this.posSpreadSetting.cols.push(
  2119. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2120. )
  2121. }
  2122. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2123. // 初始化 签约节点 参数
  2124. this.dealSpreadSetting = {
  2125. cols: [
  2126. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2127. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2128. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2129. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2130. ],
  2131. emptyRows: 0,
  2132. headRows: 1,
  2133. headRowHeight: [32],
  2134. headerFont: '12px 微软雅黑',
  2135. font: '12px 微软雅黑',
  2136. };
  2137. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2138. // 初始化 清单编号、部位数量复核表 表格
  2139. this.initView();
  2140. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2141. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2142. // 拉取签约节点数据
  2143. dealBills.loadData(() => {
  2144. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2145. });
  2146. // 双击签约节点,自动添加到清单编号窗口
  2147. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2148. const deal = info.sheet.zh_data[info.row];
  2149. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2150. const sel = qdSheet.getSelections()[0];
  2151. qdSheet.getCell(sel.row, 0).value(deal.code);
  2152. qdSheet.getCell(sel.row, 1).value(deal.name);
  2153. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2154. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2155. if (sel.row + 1 === qdSheet.getRowCount()) {
  2156. const count = sel.row + 2;
  2157. qdSheet.setRowCount(count);
  2158. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2159. const colCount = posSheet.getColumnCount() + 1;
  2160. posSheet.setColumnCount(colCount);
  2161. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2162. }
  2163. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2164. qdSheet.getParent().focus();
  2165. });
  2166. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2167. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2168. const count = posSheet.getColumnCount() - 2;
  2169. if (billsCount > count) {
  2170. posSheet.setColumnCount(billsCount + 2);
  2171. for (let i = count + 1; i <= billsCount; i++) {
  2172. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2173. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2174. }
  2175. }
  2176. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2177. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2178. if (dealBills && dealBills.length > 0) {
  2179. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2180. const curRow = iRow + info.cellRange.row;
  2181. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2182. if (bills) {
  2183. info.sheet.getCell(curRow, 1).value(bills.name);
  2184. info.sheet.getCell(curRow, 2).value(bills.unit);
  2185. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2186. }
  2187. }
  2188. }
  2189. }
  2190. });
  2191. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2192. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2193. const count = qdSheet.getRowCount();
  2194. if (billsCount > count) {
  2195. qdSheet.setRowCount(billsCount);
  2196. for (let i = count + 1; i <= billsCount; i++) {
  2197. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2198. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2199. }
  2200. }
  2201. });
  2202. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2203. if (info.col === 0) {
  2204. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2205. if (dealBills && dealBills.length > 0) {
  2206. const bills = _.find(dealBills, {code: info.editingText});
  2207. if (bills) {
  2208. info.sheet.getCell(info.row, 1).value(bills.name);
  2209. info.sheet.getCell(info.row, 2).value(bills.unit);
  2210. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2211. }
  2212. }
  2213. }
  2214. });
  2215. this.obj.bind('shown.bs.modal', function () {
  2216. self.qdSpread.refresh();
  2217. self.posSpread.refresh();
  2218. self.dealSpread.refresh();
  2219. });
  2220. $('#batch-ok').click(function () {
  2221. const selection = billsSheet.getSelections();
  2222. const sel = selection[0];
  2223. const row = selection[0].row;
  2224. const select = billsTree.nodes[row];
  2225. if (select) {
  2226. const insertData = {};
  2227. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2228. insertData.id = select[billsTree.setting.id];
  2229. insertData.batchData = self.getBatchData();
  2230. if (insertData.batchData.length > 0) {
  2231. postData(window.location.pathname + '/update', {
  2232. postType: 'batch-insert',
  2233. postData: insertData
  2234. }, function (data) {
  2235. pos.updateDatas(data.pos);
  2236. const result = billsTree.loadPostData(data.ledger);
  2237. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2238. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2239. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2240. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2241. posSpreadObj.loadCurPosData();
  2242. self.obj.modal('hide');
  2243. }, null, true);
  2244. } else {
  2245. self.obj.modal('hide');
  2246. }
  2247. }
  2248. });
  2249. $('input[name=batch-filter]').change(function () {
  2250. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2251. });
  2252. $.contextMenu({
  2253. selector: '.batch-l-t',
  2254. build: function ($trigger, e) {
  2255. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2256. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2257. },
  2258. items: {
  2259. 'create': {
  2260. name: '新增行',
  2261. icon: 'fa-sign-in',
  2262. callback: function (key, opt) {
  2263. const qdSheet = self.qdSpread.getActiveSheet();
  2264. const posSheet = self.posSpread.getActiveSheet();
  2265. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2266. const index = qdSheet.getRowCount();
  2267. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2268. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2269. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2270. },
  2271. },
  2272. 'delete': {
  2273. name: '删除行',
  2274. icon: 'fa-remove',
  2275. callback: function (key, opt) {
  2276. const qdSheet = self.qdSpread.getActiveSheet();
  2277. const posSheet = self.posSpread.getActiveSheet();
  2278. const sel = qdSheet.getSelections()[0];
  2279. qdSheet.deleteRows(sel.row, sel.rowCount);
  2280. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2281. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2282. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2283. }
  2284. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2285. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2286. }
  2287. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2288. },
  2289. },
  2290. }
  2291. });
  2292. }
  2293. // 初始化左侧表格
  2294. initView () {
  2295. // 初始化 清单编号
  2296. const qdSheet = this.qdSpread.getActiveSheet();
  2297. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2298. SpreadJsObj.refreshColumnAlign(qdSheet);
  2299. // 清理原有数据
  2300. SpreadJsObj.beginMassOperation(qdSheet);
  2301. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2302. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2303. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2304. }
  2305. qdSheet.setSelection(0, 0, 1 ,1);
  2306. SpreadJsObj.endMassOperation(qdSheet);
  2307. // 初始化 部位数量复核表
  2308. const posSheet = this.posSpread.getActiveSheet();
  2309. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2310. SpreadJsObj.refreshColumnAlign(posSheet);
  2311. // 清理原有数据
  2312. SpreadJsObj.beginMassOperation(posSheet);
  2313. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2314. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2315. posSheet.setSelection(0, 0, 1 ,1);
  2316. SpreadJsObj.endMassOperation(posSheet);
  2317. // 检查签约节点数据,以工具栏数据为准
  2318. if (dealBills) {
  2319. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2320. }
  2321. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2322. }
  2323. // 获取界面数据
  2324. getBatchData () {
  2325. const result = [];
  2326. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2327. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2328. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2329. const qd = {
  2330. b_code: qdSheet.getText(iRow, 0),
  2331. name: qdSheet.getText(iRow, 1),
  2332. unit: qdSheet.getText(iRow, 2),
  2333. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2334. pos: [],
  2335. };
  2336. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2337. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2338. if (value !== 0 && !isNaN(value)) {
  2339. qd.pos.push({
  2340. name: posSheet.getText(iPosRow, 0),
  2341. drawing_code: posSheet.getText(iPosRow, 1),
  2342. quantity: value, porder: qd.pos.length + 1,
  2343. });
  2344. }
  2345. }
  2346. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2347. }
  2348. return result;
  2349. }
  2350. }
  2351. const dealBills = new DealBills('#deal-bills-spread', {
  2352. cols: [
  2353. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2354. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2355. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2356. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2357. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2358. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2359. ],
  2360. emptyRows: 0,
  2361. headRows: 1,
  2362. headRowHeight: [32],
  2363. headColWidth: [30],
  2364. defaultRowHeight: 21,
  2365. headerFont: '12px 微软雅黑',
  2366. font: '12px 微软雅黑',
  2367. selectedBackColor: '#fffacd',
  2368. });
  2369. class Jlzf {
  2370. constructor (selector, spreadSetting) {
  2371. const self = this;
  2372. this.loaded = false;
  2373. this.obj = $(selector);
  2374. const relaSelect = {
  2375. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2376. searchText: `cb-${spreadSetting.stdType}-st`,
  2377. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2378. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2379. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2380. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2381. };
  2382. this.obj.html(
  2383. '<div class="sjs-bar d-flex">\n' +
  2384. ' <div class="ml-1">\n' +
  2385. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  2386. ' <div class="d-inline-block">\n' +
  2387. ' <div class="input-group input-group-sm mr-1">' +
  2388. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2389. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2390. ' <div class="input-group-append" >\n' +
  2391. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2392. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2393. ' </div>\n' +
  2394. ' </div>\n' +
  2395. ' </div>\n' +
  2396. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2397. ' </div>\n' +
  2398. ' </div>' +
  2399. '</div>\n' +
  2400. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2401. );
  2402. autoFlashHeight();
  2403. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2404. function getObjHeight(select) {
  2405. return select.length > 0 ? select.height() : 0;
  2406. }
  2407. const cHeader = getObjHeight($(".c-header"));
  2408. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2409. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2410. this.spreadSetting = spreadSetting;
  2411. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2412. const searchSheet = this.spread.getActiveSheet();
  2413. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2414. if (!readOnly) {
  2415. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2416. const dealSheet = info.sheet;
  2417. const mainSheet = billsSheet;
  2418. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2419. if (!dealBills) { return; }
  2420. const mainTree = mainSheet.zh_tree;
  2421. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2422. if (!mainNode || !mainTree) { return; }
  2423. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2424. toastr.warning('非最底层项目下,不应添加节点');
  2425. return;
  2426. }
  2427. if (mainNode.settle_status === settleStatus.finish) {
  2428. toastr.warning('已结算节点下,不应添加签约清单');
  2429. return;
  2430. }
  2431. postData(window.location.pathname + '/update', {
  2432. postType: 'add-deal',
  2433. postData: {
  2434. id: mainNode.ledger_id,
  2435. type: mainNode.code ? 'child' : 'next',
  2436. dealBills: {
  2437. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2438. unit_price: dealBills.unit_price,
  2439. }
  2440. },
  2441. }, function (result) {
  2442. const refreshData = mainTree.loadPostData(result);
  2443. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2444. const sel = mainSheet.getSelections()[0];
  2445. if (sel && refreshData.create[0]) {
  2446. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2447. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2448. }
  2449. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2450. billsSpread.focus();
  2451. posSpreadObj.loadCurPosData();
  2452. });
  2453. });
  2454. }
  2455. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2456. const searchObj = {
  2457. result: [],
  2458. cur: 0,
  2459. searchStdNode: function() {
  2460. const keyword = $(`#${relaSelect.searchText}`).val();
  2461. const sortData = SpreadJsObj.getSortData(searchSheet);
  2462. searchObj.result = keyword ? sortData.filter(x => {
  2463. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2464. }) : [];
  2465. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2466. searchObj.cur = 0;
  2467. if (searchObj.result.length > 0) {
  2468. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2469. }
  2470. },
  2471. searchPre: function () {
  2472. if (searchObj.result.length === 0) return;
  2473. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2474. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2475. },
  2476. searchNext: function () {
  2477. if (searchObj.result.length === 0) return;
  2478. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2479. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2480. },
  2481. clear: function () {
  2482. $(`#${relaSelect.searchText}`).val('');
  2483. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2484. searchObj.result = [];
  2485. searchObj.cur = 0;
  2486. }
  2487. };
  2488. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2489. $(`#${relaSelect.searchPre}`).click(function (e) {
  2490. searchObj.searchPre();
  2491. e.stopPropagation();
  2492. });
  2493. $(`#${relaSelect.searchNext}`).click(function (e) {
  2494. searchObj.searchNext();
  2495. e.stopPropagation();
  2496. });
  2497. $(`#${relaSelect.searchClose}`).click(function (e) {
  2498. searchObj.clear();
  2499. e.stopPropagation();
  2500. });
  2501. };
  2502. loadData (callback) {
  2503. // if (this.loaded) {
  2504. // if (callback) callback();
  2505. // return;
  2506. // }
  2507. const self = this;
  2508. const data = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  2509. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2510. // self.loaded = true;
  2511. if (callback) callback();
  2512. }
  2513. }
  2514. const jlzfBills = new Jlzf('#jlzf-spread', {
  2515. cols: [
  2516. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2517. {title: '清单编号', field: 'b_code', hAlign: 0, width: 85, formatter: '@'},
  2518. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2519. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2520. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2521. ],
  2522. emptyRows: 0,
  2523. headRows: 1,
  2524. headRowHeight: [32],
  2525. headColWidth: [30],
  2526. defaultRowHeight: 21,
  2527. headerFont: '12px 微软雅黑',
  2528. font: '12px 微软雅黑',
  2529. selectedBackColor: '#fffacd',
  2530. readOnly: true,
  2531. stdType: 'jlzf',
  2532. });
  2533. class Dsk {
  2534. constructor (selector, spreadSetting) {
  2535. const self = this;
  2536. this.loaded = false;
  2537. this.obj = $(selector);
  2538. const dskProjectHtml = spreadSetting.libs.map(l => {
  2539. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  2540. });
  2541. const relaSelect = {
  2542. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2543. searchText: `cb-${spreadSetting.stdType}-st`,
  2544. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2545. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2546. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2547. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2548. };
  2549. this.obj.html(
  2550. '<div class="sjs-bar d-flex">\n' +
  2551. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  2552. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  2553. ' <div class="ml-1">\n' +
  2554. ' <div class="dropdown">\n' +
  2555. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2556. ' <i class="fa fa-search"></i>\n' +
  2557. ' </button>\n' +
  2558. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  2559. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  2560. ' <div class="d-inline-block">\n' +
  2561. ' <div class="input-group input-group-sm mr-1">' +
  2562. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2563. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2564. ' <div class="input-group-append" >\n' +
  2565. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2566. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2567. ' </div>\n' +
  2568. ' </div>\n' +
  2569. ' </div>\n' +
  2570. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2571. ' </div>\n' +
  2572. ' </div>\n' +
  2573. ' </div>\n' +
  2574. ' </div>' +
  2575. '</div>\n' +
  2576. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2577. );
  2578. autoFlashHeight();
  2579. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2580. function getObjHeight(select) {
  2581. return select.length > 0 ? select.height() : 0;
  2582. }
  2583. const cHeader = getObjHeight($(".c-header"));
  2584. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2585. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2586. this.spreadSetting = spreadSetting;
  2587. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2588. const searchSheet = this.spread.getActiveSheet();
  2589. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2590. if (!readOnly) {
  2591. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2592. const dealSheet = info.sheet;
  2593. const mainSheet = billsSheet;
  2594. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2595. if (!dealBills) { return; }
  2596. const mainTree = mainSheet.zh_tree;
  2597. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2598. if (!mainNode || !mainTree) { return; }
  2599. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2600. toastr.warning('非最底层项目下,不应添加节点');
  2601. return;
  2602. }
  2603. if (mainNode.settle_status === settleStatus.finish) {
  2604. toastr.warning('已结算节点下,不应添加签约清单');
  2605. return;
  2606. }
  2607. const is_bill = dealBills.kind === 4;
  2608. const oneBills = {
  2609. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  2610. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  2611. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  2612. };
  2613. postData(window.location.pathname + '/update', {
  2614. postType: 'add-deal',
  2615. postData: {
  2616. id: mainNode.ledger_id,
  2617. type: mainNode.code ? 'child' : 'next',
  2618. dealBills: oneBills,
  2619. },
  2620. }, function (result) {
  2621. const refreshData = mainTree.loadPostData(result);
  2622. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2623. const sel = mainSheet.getSelections()[0];
  2624. if (sel && refreshData.create[0]) {
  2625. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2626. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2627. }
  2628. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2629. billsSpread.focus();
  2630. posSpreadObj.loadCurPosData();
  2631. });
  2632. });
  2633. }
  2634. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2635. const searchObj = {
  2636. result: [],
  2637. cur: 0,
  2638. searchStdNode: function() {
  2639. const keyword = $(`#${relaSelect.searchText}`).val();
  2640. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  2641. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2642. }) : [];
  2643. // searchObj.result = [];
  2644. // for (const x of pathTree.nodes) {
  2645. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  2646. // searchObj.result.push(x);
  2647. // }
  2648. // }
  2649. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2650. searchObj.cur = 0;
  2651. if (searchObj.result.length > 0) {
  2652. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  2653. }
  2654. },
  2655. searchPre: function () {
  2656. if (searchObj.result.length === 0) return;
  2657. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2658. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  2659. },
  2660. searchNext: function () {
  2661. if (searchObj.result.length === 0) return;
  2662. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2663. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  2664. },
  2665. clear: function () {
  2666. $(`#${relaSelect.searchText}`).val('');
  2667. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2668. searchObj.result = [];
  2669. searchObj.cur = 0;
  2670. }
  2671. };
  2672. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2673. $(`#${relaSelect.searchPre}`).click(function (e) {
  2674. searchObj.searchPre();
  2675. e.stopPropagation();
  2676. });
  2677. $(`#${relaSelect.searchNext}`).click(function (e) {
  2678. searchObj.searchNext();
  2679. e.stopPropagation();
  2680. });
  2681. $(`#${relaSelect.searchClose}`).click(function (e) {
  2682. searchObj.clear();
  2683. e.stopPropagation();
  2684. });
  2685. };
  2686. loadData (callback) {
  2687. if (this.loaded) {
  2688. if (callback) callback();
  2689. return;
  2690. }
  2691. const self = this;
  2692. if (dskAccountData && dskAccountData.select_project) {
  2693. self.loaded = true;
  2694. changeDskProject(dskAccountData.select_project);
  2695. } else {
  2696. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  2697. self.loaded = true;
  2698. }
  2699. if (callback) callback();
  2700. }
  2701. }
  2702. $('body').on('change', '#change-dsk-project', function () {
  2703. const pid = $(this).val();
  2704. changeDskProject(pid);
  2705. });
  2706. $('body').on('change', '#change-dsk-project-tree', function () {
  2707. const treeId = $(this).val();
  2708. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  2709. changeDskProjectTree(projectInfo, treeId);
  2710. });
  2711. function setDskProjectTreeSelect(trees) {
  2712. let html = '';
  2713. for (const tree of trees) {
  2714. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  2715. }
  2716. $('#change-dsk-project-tree').html(html);
  2717. }
  2718. function changeDskProject(pid) {
  2719. const projectInfo = _.find(dskProjects, { pid });
  2720. if (!projectInfo) {
  2721. dskAccountData.select_project = null;
  2722. dskAccountData.select_tree = null;
  2723. const tree = dskProjectBills2Tree.convert([]);
  2724. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  2725. return;
  2726. }
  2727. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  2728. const trees = _.filter(datas, x => x.type === 4);
  2729. dskAccountData.select_project = projectInfo.pid;
  2730. setDskProjectTreeSelect(trees);
  2731. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  2732. });
  2733. }
  2734. function changeDskProjectTree(projectInfo, treeId) {
  2735. dskAccountData.select_tree = treeId;
  2736. if (!treeId) {
  2737. const tree = dskProjectBills2Tree.convert([]);
  2738. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  2739. return;
  2740. }
  2741. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  2742. const tree = dskProjectBills2Tree.convert(result);
  2743. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  2744. });
  2745. }
  2746. const dskBills = new Dsk('#dsk-spread', {
  2747. cols: [
  2748. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  2749. {title: '名称', field: 'name', hAlign: 0, width: 100, formatter: '@'},
  2750. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2751. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  2752. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  2753. ],
  2754. emptyRows: 0,
  2755. headRows: 1,
  2756. headRowHeight: [32],
  2757. headColWidth: [30],
  2758. defaultRowHeight: 21,
  2759. headerFont: '12px 微软雅黑',
  2760. font: '12px 微软雅黑',
  2761. selectedBackColor: '#fffacd',
  2762. readOnly: true,
  2763. stdType: 'dsk',
  2764. libs: dskProjects,
  2765. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  2766. });
  2767. const dskProjectBills2Tree = (function () {
  2768. const treeSetting = {
  2769. id: 'dpb_id',
  2770. pid: 'dpb_pid',
  2771. order: 'seq',
  2772. level: 'level',
  2773. rootId: '-1',
  2774. fullPath: 'full_path',
  2775. };
  2776. const tenderTree = createNewPathTree('gather', treeSetting);
  2777. function setChildrenNode(node, dxs, files, tenders) {
  2778. const dxchildren = _.filter(dxs, { parentID: node.bid });
  2779. const children = _.filter(files, { parentID: node.bid });
  2780. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  2781. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  2782. for (const t of checkChildren) {
  2783. const child = {
  2784. bid: t.ID,
  2785. parentID: t.parentID,
  2786. name: t.name,
  2787. kind: t.kind,
  2788. code: t.code,
  2789. quantity: t.quantity,
  2790. quantity2: t.quantity2,
  2791. unit: t.unit,
  2792. unitPrice: t.unitPrice,
  2793. totalPrice: t.totalPrice,
  2794. formulaCode: t.formulaCode,
  2795. flag: t.flag,
  2796. remark: t.remark,
  2797. };
  2798. tenderTree.addNode(child, node);
  2799. setChildrenNode(child, dxs, files, tenders);
  2800. }
  2801. }
  2802. function convert (projects) {
  2803. tenderTree.clearDatas();
  2804. // 区分文件夹及项目
  2805. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  2806. const dxs = _.filter(projects, { kind: 1 });
  2807. const files = _.filter(projects, { kind: 4 });
  2808. const tenders = _.filter(projects, { kind: 8 });
  2809. for (const t of topLevel) {
  2810. const node = {
  2811. bid: t.ID,
  2812. parentID: t.parentID,
  2813. name: t.name,
  2814. kind: t.kind,
  2815. code: t.code,
  2816. quantity: t.quantity,
  2817. quantity2: t.quantity2,
  2818. unit: t.unit,
  2819. unitPrice: t.unitPrice,
  2820. totalPrice: t.totalPrice,
  2821. formulaCode: t.formulaCode,
  2822. flag: t.flag,
  2823. remark: t.remark,
  2824. };
  2825. tenderTree.addNode(node, null);
  2826. setChildrenNode(node, dxs, files, tenders);
  2827. }
  2828. tenderTree.sortTreeNode(true);
  2829. return tenderTree;
  2830. }
  2831. return { tenderTree, convert }
  2832. })();
  2833. $.divResizer({
  2834. select: '#revise-right-spr',
  2835. callback: function () {
  2836. billsSpread.refresh();
  2837. if (posSpread) posSpread.refresh();
  2838. if (stdXmj) stdXmj.spread.refresh();
  2839. if (stdGcl) stdGcl.spread.refresh();
  2840. if (dealBills) dealBills.spread.refresh();
  2841. if (searchLedger) searchLedger.spread.refresh();
  2842. if (errorList) errorList.spread.refresh();
  2843. if (checkList) checkList.spread.refresh();
  2844. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2845. if (jlzfBills) jlzfBills.spread.refresh();
  2846. if (dskBills) dskBills.spread.refresh();
  2847. }
  2848. });
  2849. $.subMenu({
  2850. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2851. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2852. key: 'menu.1.0.0',
  2853. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2854. callback: function (info) {
  2855. if (info.mini) {
  2856. $('.panel-title').addClass('fluid');
  2857. $('#sub-menu').removeClass('panel-sidebar');
  2858. } else {
  2859. $('.panel-title').removeClass('fluid');
  2860. $('#sub-menu').addClass('panel-sidebar');
  2861. }
  2862. autoFlashHeight();
  2863. billsSpread.refresh();
  2864. if (posSpread) posSpread.refresh();
  2865. if (stdXmj) stdXmj.spread.refresh();
  2866. if (stdGcl) stdGcl.spread.refresh();
  2867. if (dealBills) dealBills.spread.refresh();
  2868. if (searchLedger) searchLedger.spread.refresh();
  2869. if (errorList) errorList.spread.refresh();
  2870. if (checkList) checkList.spread.refresh();
  2871. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2872. if (jlzfBills) jlzfBills.spread.refresh();
  2873. if (dskBills) dskBills.spread.refresh();
  2874. }
  2875. });
  2876. // showSideTools(true);
  2877. billsSpread.refresh();
  2878. if (posSpread) posSpread.refresh();
  2879. const stdLibCellDoubleClick = function (e, info) {
  2880. const stdSheet = info.sheet;
  2881. const mainSheet = billsSheet;
  2882. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2883. const stdTree = stdSheet.zh_tree;
  2884. const stdNode = stdTree.nodes[info.row];
  2885. const mainTree = mainSheet.zh_tree;
  2886. const sel = mainSheet.getSelections()[0];
  2887. const mainNode = mainTree.nodes[sel.row];
  2888. if (!stdNode) return;
  2889. if (info.sheet.zh_setting.stdType === 'gcl') {
  2890. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2891. toastr.warning('非最底层项目下,不应添加节点');
  2892. return;
  2893. }
  2894. if (mainNode.settle_status === settleStatus.finish) {
  2895. toastr.warning('已结算节点下,不可添加工程量清单');
  2896. return;
  2897. }
  2898. } else {
  2899. const stdNodes = stdTree.getAllParents(stdNode);
  2900. for (const node of stdNodes) {
  2901. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  2902. if (parent && parent.settle_status === settleStatus.finish) {
  2903. toastr.warning('项目节父项已结算,不可添加节点');
  2904. return;
  2905. }
  2906. }
  2907. }
  2908. postData(window.location.pathname + '/update', {
  2909. postType: 'add-std',
  2910. postData: {
  2911. id: mainTree.getNodeKey(mainNode),
  2912. tender_id: mainNode.tender_id,
  2913. stdType: info.sheet.zh_setting.stdType,
  2914. stdLibId: stdNode.list_id,
  2915. stdNode: stdTree.getNodeKey(stdNode)
  2916. }
  2917. }, function (result) {
  2918. const refreshNode = mainTree.loadPostData(result);
  2919. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  2920. if (sel) {
  2921. if (refreshNode.create && refreshNode.create.length > 0) {
  2922. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2923. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  2924. } else {
  2925. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  2926. if (node) {
  2927. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2928. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  2929. }
  2930. }
  2931. }
  2932. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2933. billsSpread.focus();
  2934. posSpreadObj.loadCurPosData();
  2935. });
  2936. };
  2937. const stdXmjSetting = {
  2938. selector: '#std-xmj',
  2939. stdType: 'xmj',
  2940. libs: stdChapters,
  2941. treeSetting: {
  2942. id: 'chapter_id',
  2943. pid: 'pid',
  2944. order: 'order',
  2945. level: 'level',
  2946. rootId: -1,
  2947. keys: ['id', 'list_id', 'chapter_id'],
  2948. },
  2949. spreadSetting: {
  2950. cols: [
  2951. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2952. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2953. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2954. ],
  2955. treeCol: 0,
  2956. emptyRows: 0,
  2957. headRows: 1,
  2958. headRowHeight: [32],
  2959. defaultRowHeight: 21,
  2960. headerFont: '12px 微软雅黑',
  2961. font: '12px 微软雅黑',
  2962. headColWidth: [30],
  2963. selectedBackColor: '#fffacd',
  2964. },
  2965. cellDoubleClick: stdLibCellDoubleClick,
  2966. page: 'revise',
  2967. tid: window.location.pathname.split('/')[2],
  2968. };
  2969. const stdGclSetting = {
  2970. selector: '#std-gcl',
  2971. stdType: 'gcl',
  2972. libs: stdBills,
  2973. treeSetting: {
  2974. id: 'bill_id',
  2975. pid: 'pid',
  2976. order: 'order',
  2977. level: 'level',
  2978. rootId: -1,
  2979. keys: ['id', 'list_id', 'bill_id']
  2980. },
  2981. spreadSetting: {
  2982. cols: [
  2983. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2984. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2985. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2986. ],
  2987. treeCol: 0,
  2988. emptyRows: 0,
  2989. headRows: 1,
  2990. headRowHeight: [32],
  2991. defaultRowHeight: 21,
  2992. headerFont: '12px 微软雅黑',
  2993. font: '12px 微软雅黑',
  2994. headColWidth: [30],
  2995. selectedBackColor: '#fffacd',
  2996. },
  2997. cellDoubleClick: stdLibCellDoubleClick,
  2998. page: 'revise',
  2999. tid: window.location.pathname.split('/')[2],
  3000. };
  3001. // 展开收起标准节点
  3002. $('a', '#side-menu').bind('click', function (e) {
  3003. e.preventDefault();
  3004. const tab = $(this), tabPanel = $(tab.attr('content'));
  3005. // 展开工具栏、切换标签
  3006. if (!tab.hasClass('active')) {
  3007. const close = $('.active', '#side-menu').length === 0;
  3008. $('a', '#side-menu').removeClass('active');
  3009. tab.addClass('active');
  3010. $('.tab-content .tab-pane').removeClass('active');
  3011. tabPanel.addClass('active');
  3012. showSideTools(tab.hasClass('active'));
  3013. if (tab.attr('content') === '#std-xmj') {
  3014. if (!stdXmj) {
  3015. stdXmj = $.stdLib(stdXmjSetting);
  3016. }
  3017. stdXmj.spread.refresh();
  3018. } else if (tab.attr('content') === '#std-gcl') {
  3019. if (!stdGcl) {
  3020. stdGcl = $.stdLib(stdGclSetting);
  3021. }
  3022. stdGcl.spread.refresh();
  3023. } else if (tab.attr('content') === '#deal-bills') {
  3024. dealBills.loadData();
  3025. dealBills.spread.refresh();
  3026. } else if (tab.attr('content') === '#search') {
  3027. if (!searchLedger) {
  3028. searchLedger = $.billsSearch({
  3029. selector: '#search',
  3030. searchSpread: billsSpread,
  3031. searchOver: true,
  3032. searchEmpty: true,
  3033. resultSpreadSetting: {
  3034. cols: [
  3035. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3036. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3037. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3038. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3039. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3040. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3041. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3042. ],
  3043. emptyRows: 0,
  3044. headRows: 1,
  3045. headRowHeight: [32],
  3046. headColWidth: [30],
  3047. defaultRowHeight: 21,
  3048. headerFont: '12px 微软雅黑',
  3049. font: '12px 微软雅黑',
  3050. selectedBackColor: '#fffacd',
  3051. readOnly: true,
  3052. },
  3053. afterLocated: function () {
  3054. posSpreadObj.loadCurPosData();
  3055. },
  3056. customSearch: [
  3057. {
  3058. key: 'revise', title: '新增部位', valid: true, parent: true,
  3059. check: function (node) {
  3060. if (node.formc || node.cid) {
  3061. return true;
  3062. } else {
  3063. return false;
  3064. }
  3065. }
  3066. }
  3067. ],
  3068. });
  3069. }
  3070. searchLedger.spread.refresh();
  3071. } else if (tab.attr('content') === '#error-list') {
  3072. errorList.spread.refresh();
  3073. } else if (tab.attr('content') === '#check-list') {
  3074. checkList.spread.refresh();
  3075. } else if (tab.attr('content') === '#sum-load-miss') {
  3076. sumLoadMiss.spread.refresh();
  3077. } else if (tab.attr('content') === '#dsk-list') {
  3078. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  3079. $(dskActiveTab).addClass('active');
  3080. if (dskActiveTab === '#jlzf-spread') {
  3081. $('#get-dsk-btn').hide();
  3082. $('#get-dsk-bills-btn').hide();
  3083. jlzfBills.loadData();
  3084. jlzfBills.spread.refresh();
  3085. } else if (dskActiveTab === '#dsk-spread') {
  3086. $('#get-dsk-btn').show();
  3087. $('#get-dsk-bills-btn').show();
  3088. dskBills.loadData();
  3089. dskBills.spread.refresh();
  3090. }
  3091. }
  3092. }
  3093. else {// 收起工具栏
  3094. tab.removeClass('active');
  3095. tabPanel.removeClass('active');
  3096. showSideTools(tab.hasClass('active'));
  3097. }
  3098. billsSpread.refresh();
  3099. if (posSpread) posSpread.refresh();
  3100. });
  3101. // 新增清单切换tab
  3102. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  3103. e.preventDefault();
  3104. const dskActiveTab = $(this).attr('href');
  3105. if (dskActiveTab === '#jlzf-spread') {
  3106. $('#get-dsk-btn').hide();
  3107. $('#get-dsk-bills-btn').hide();
  3108. jlzfBills.loadData();
  3109. jlzfBills.spread.refresh();
  3110. } else if (dskActiveTab === '#dsk-spread') {
  3111. $('#get-dsk-btn').show();
  3112. $('#get-dsk-bills-btn').show();
  3113. dskBills.loadData();
  3114. dskBills.spread.refresh();
  3115. }
  3116. });
  3117. // 显示层次
  3118. (function (select, sheet) {
  3119. $(select).click(function () {
  3120. if (!sheet.zh_tree) return;
  3121. const tag = $(this).attr('tag');
  3122. const tree = sheet.zh_tree;
  3123. setTimeout(() => {
  3124. showWaitingView();
  3125. switch (tag) {
  3126. case "1":
  3127. case "2":
  3128. case "3":
  3129. case "4":
  3130. case "5":
  3131. tree.expandByLevel(parseInt(tag));
  3132. SpreadJsObj.refreshTreeRowVisible(sheet);
  3133. break;
  3134. case "last":
  3135. tree.expandByCustom(() => { return true; });
  3136. SpreadJsObj.refreshTreeRowVisible(sheet);
  3137. break;
  3138. case "leafXmj":
  3139. tree.expandToLeafXmj();
  3140. SpreadJsObj.refreshTreeRowVisible(sheet);
  3141. break;
  3142. }
  3143. closeWaitingView();
  3144. }, 100);
  3145. });
  3146. })('a[name=showLevel]', billsSheet);
  3147. const dataChecker = DataChecker({
  3148. checkUrl: window.location.pathname + '/check',
  3149. completeData: function (data) {
  3150. pos.updateDatas({update: data.source.pos});
  3151. const loadResult = billsTree.loadPostData({update: data.source.bills});
  3152. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3153. posSpreadObj.loadCurPosData();
  3154. for (const e of data.error) {
  3155. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  3156. }
  3157. },
  3158. errorList: errorList,
  3159. });
  3160. $('#ledger-check2').click(() => {
  3161. ledgerCheck2({
  3162. ledgerTree: billsTree,
  3163. ledgerPos: pos,
  3164. checkList: checkList,
  3165. decimal: decimal,
  3166. checkOption: checkOption,
  3167. }).then(result => {
  3168. check2Viewing({
  3169. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  3170. randomWait: true,
  3171. prefix: 'check2-',
  3172. checks: result,
  3173. checkList: checkList,
  3174. });
  3175. });
  3176. });
  3177. if (isYb) {
  3178. let compilationList = [];
  3179. $('#get-dsk-btn').click(function () {
  3180. // 判断是否已绑定dsk用户
  3181. postData('/profile/dsk/api', { type: 'hadbind' }, function (result) {
  3182. if (result === 1) {
  3183. $('#error-dsk .modal-body').find('h5').eq(0).show();
  3184. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  3185. $('#error-dsk').modal('show');
  3186. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  3187. } else if (result === 2) {
  3188. $('#error-dsk .modal-body').find('h5').eq(1).show();
  3189. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  3190. $('#error-dsk').modal('show');
  3191. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  3192. } else {
  3193. postData('/profile/dsk/api', { type: 'compilation', getProject: 1, compilationId: getLocalCache(dskCompilation) }, function (result) {
  3194. let html = '';
  3195. for (const data of result.compilation) {
  3196. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  3197. }
  3198. dskAccountData = result.dskAccountData;
  3199. compilationList = result.compilation;
  3200. console.log(compilationList);
  3201. $('#dsk-compilation-list').html(html);
  3202. $('#add-dsk').modal('show');
  3203. setLocalCache(dskCompilation, result.select_compilation);
  3204. makeDskProjectSjsHtml(result.project);
  3205. });
  3206. }
  3207. })
  3208. });
  3209. $('#get-dsk-bills-btn').click(function () {
  3210. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project ? dskAccountData.select_project : null });
  3211. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  3212. });
  3213. $('body').on('change', '#dsk-compilation-list', function () {
  3214. const compilationId = $(this).val();
  3215. setLocalCache(dskCompilation, compilationId);
  3216. dskProjectSpreadObj.refreshSourceTree();
  3217. });
  3218. $('.hide-dsk-modal').click(function () {
  3219. $('#error-dsk').modal('hide');
  3220. });
  3221. let dp = false;
  3222. let gsObj = {
  3223. setting: null,
  3224. gsSheet: null,
  3225. grSheet: null,
  3226. tenderSourceTree: null,
  3227. grArray: dskProjects ? dskProjects : [],
  3228. orgSelect: null,
  3229. };
  3230. function makeDskProjectSjsHtml(datas) {
  3231. if (!dp) {
  3232. initDskProjectTree();
  3233. dp = true;
  3234. }
  3235. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  3236. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  3237. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  3238. if (datas.length === 0) {
  3239. $('#show-project-0').show();
  3240. } else {
  3241. $('#show-project-0').hide();
  3242. }
  3243. }
  3244. const dskProjectSpreadObj = {
  3245. _addTender: function (tender) {
  3246. const gr = gsObj.grArray.find(function (x) {
  3247. return x.pid === tender.pid;
  3248. });
  3249. const c_id = getLocalCache(dskCompilation);
  3250. const t = {pid: tender.pid, name: tender.name, compilationId: c_id, compilationName: _.find(compilationList, { ID: c_id }).name };
  3251. if (!gr) gsObj.grArray.push(t);
  3252. return t;
  3253. },
  3254. _removeTender: function (tender) {
  3255. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  3256. return x.pid === tender.pid;
  3257. });
  3258. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  3259. },
  3260. reloadResultData: function () {
  3261. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  3262. },
  3263. refreshSourceTree: function () {
  3264. const c_id = getLocalCache(dskCompilation);
  3265. if (c_id) {
  3266. postData('/profile/dsk/api', { type: 'project', compilationId: c_id }, function (result) {
  3267. makeDskProjectSjsHtml(result);
  3268. });
  3269. }
  3270. },
  3271. gsButtonClicked: function (e, info) {
  3272. if (!info.sheet.zh_setting) return;
  3273. const col = info.sheet.zh_setting.cols[info.col];
  3274. if (col.field !== 'selected') return;
  3275. const node = SpreadJsObj.getSelectObject(info.sheet);
  3276. node.selected = !node.selected;
  3277. if (node.children && node.children.length > 0) {
  3278. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  3279. for (const p of posterity) {
  3280. p.selected = node.selected;
  3281. if ((!p.children || p.children.length === 0) && p.type === 2){
  3282. if (p.selected) {
  3283. dskProjectSpreadObj._addTender(p);
  3284. } else {
  3285. dskProjectSpreadObj._removeTender(p);
  3286. }
  3287. }
  3288. }
  3289. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  3290. } else if (node.type === 2) {
  3291. if (node.selected) {
  3292. dskProjectSpreadObj._addTender(node);
  3293. } else {
  3294. dskProjectSpreadObj._removeTender(node);
  3295. }
  3296. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  3297. }
  3298. dskProjectSpreadObj.reloadResultData();
  3299. },
  3300. deleteGr: function () {
  3301. if (gsObj.grArray.length === 0) return;
  3302. if (gsObj.grSheet.getSelections().length === 0) return;
  3303. const selections = gsObj.grSheet.getSelections();
  3304. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  3305. const row = sel && sel.row !== undefined ? sel.row : -1;
  3306. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3307. return false;
  3308. }
  3309. const delList = [];
  3310. for (let r = 0; r < sel.rowCount; r++) {
  3311. const select = gsObj.grArray[row + r];
  3312. delList.push(select);
  3313. }
  3314. _.pullAll(gsObj.grArray, delList);
  3315. dskProjectSpreadObj.reloadResultData();
  3316. dskProjectSpreadObj.refreshSourceTree();
  3317. },
  3318. };
  3319. const initDskProjectTree = function () {
  3320. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  3321. gsObj.gsSheet = gsSpread.getActiveSheet();
  3322. const gsSpreadSetting = {
  3323. cols: [
  3324. {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: true,},
  3325. {title: '名称', field: 'name', hAlign: 0, width: 400, formatter: '@', readOnly: true, folderCell: true, cellType: 'tree'},
  3326. ],
  3327. emptyRows: 0,
  3328. headRows: 1,
  3329. headRowHeight: [32],
  3330. defaultRowHeight: 21,
  3331. headerFont: '12px 微软雅黑',
  3332. font: '12px 微软雅黑',
  3333. headColWidth: [0],
  3334. selectedBackColor: '#fffacd',
  3335. };
  3336. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  3337. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  3338. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  3339. gsObj.grSheet = grSpread.getActiveSheet();
  3340. const grSpreadSetting = {
  3341. cols: [
  3342. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 250, formatter: '@', readOnly: true, cellType: 'ellipsisAutoTip', scrollHeightClass: '.modal-height-500'},
  3343. {title: '所属编办', colSpan: '1', rowSpan: '1', field: 'compilationName', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3344. ],
  3345. emptyRows: 0,
  3346. headRows: 1,
  3347. headRowHeight: [32],
  3348. defaultRowHeight: 21,
  3349. headerFont: '12px 微软雅黑',
  3350. font: '12px 微软雅黑',
  3351. headColWidth: []
  3352. };
  3353. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  3354. // 右键删除已选项目
  3355. const gsContextMenuOptions = {
  3356. selector: '#dsk-project-result-spread',
  3357. build: function ($trigger, e) {
  3358. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  3359. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3360. },
  3361. items: {
  3362. delete: {
  3363. name: '删除',
  3364. icon: 'fa-remove',
  3365. callback: function (key, opt) {
  3366. dskProjectSpreadObj.deleteGr();
  3367. },
  3368. disabled: function (key, opt) {
  3369. const selection = gsObj.grSheet.getSelections();
  3370. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  3371. const row = sel && sel.row !== undefined ? sel.row : -1;
  3372. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3373. return true;
  3374. }
  3375. return false;
  3376. }
  3377. },
  3378. }
  3379. };
  3380. $.contextMenu(gsContextMenuOptions);
  3381. $('#add-dsk').bind('shown.bs.modal', function () {
  3382. if (gsSpread) gsSpread.refresh();
  3383. if (grSpread) grSpread.refresh();
  3384. });
  3385. };
  3386. const dskProject2Tree = (function () {
  3387. const treeSetting = {
  3388. id: 'tmt_id',
  3389. pid: 'tmt_pid',
  3390. order: 'seq',
  3391. level: 'level',
  3392. rootId: '-1',
  3393. fullPath: 'full_path',
  3394. };
  3395. const tenderTree = createNewPathTree('gather', treeSetting);
  3396. function setChildrenNode(node, files, tenders) {
  3397. const children = _.filter(files, { parentID: node.pid });
  3398. const tenderChildren = _.filter(tenders, { parentID: node.pid });
  3399. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  3400. for (const c of checkChildren) {
  3401. const child = {
  3402. pid: c.ID,
  3403. parentID: c.parentID,
  3404. name: c.name,
  3405. type: c.type,
  3406. selected: _.findIndex(gsObj.grArray, { pid: c.ID }) >= 0
  3407. };
  3408. tenderTree.addNode(child, node);
  3409. if (c.type === 1) setChildrenNode(child, files, tenders);
  3410. }
  3411. }
  3412. function convert (projects) {
  3413. tenderTree.clearDatas();
  3414. // 区分文件夹及项目
  3415. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  3416. const files = _.filter(projects, { type: 1 });
  3417. const tenders = _.filter(projects, { type: 2 });
  3418. for (const t of topLevel) {
  3419. const node = {
  3420. pid: t.ID,
  3421. parentID: t.parentID,
  3422. name: t.name,
  3423. type: t.type,
  3424. selected: t.type === 2 ? _.findIndex(gsObj.grArray, { pid: t.ID }) >= 0 : false,
  3425. };
  3426. tenderTree.addNode(node, null);
  3427. if (t.type === 1) setChildrenNode(node, files, tenders);
  3428. }
  3429. tenderTree.sortTreeNode(true);
  3430. return tenderTree;
  3431. }
  3432. return { tenderTree, convert }
  3433. })();
  3434. $('#set-dsk-project').click(function () {
  3435. postData('/profile/dsk/api', { type: 'save_projects', tid: window.location.pathname.split('/')[2], project_list: gsObj.grArray }, function (result) {
  3436. // dskAccountData.select_project = result;
  3437. dskProjects = gsObj.grArray;
  3438. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  3439. dskAccountData.select_project = result;
  3440. changeDskProject(result);
  3441. dskBills.spread.refresh();
  3442. }
  3443. setDskProjectSelect(gsObj.grArray);
  3444. $('#add-dsk').modal('hide');
  3445. });
  3446. });
  3447. $('#add-dsk').on('hide.bs.modal', function () {
  3448. $('#autoTip').hide();
  3449. });
  3450. function setDskProjectSelect(projects) {
  3451. let html = '';
  3452. for (const project of projects) {
  3453. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  3454. }
  3455. $('#change-dsk-project').html(html);
  3456. }
  3457. }
  3458. });