ledger.js 181 KB

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