ledger.js 181 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964
  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. }
  969. },
  970. sortCode: function (sheet) {
  971. const tree = sheet.zh_tree;
  972. if (!tree) return;
  973. const select = SpreadJsObj.getSelectObject(sheet);
  974. if (!select || !select.code) return;
  975. const getChildSort = function (i, split) {
  976. if (i <= 0) throw '参数错误';
  977. switch(split) {
  978. case '0':
  979. return i < 10 ? split + i : i + '';
  980. case '-':
  981. default:
  982. return split + i;
  983. }
  984. };
  985. const recursiveSortCode = function (data, parentCode, children, split) {
  986. if (!children || children.length === 0) return;
  987. for (const [i, child] of children.entries()) {
  988. if (!child.b_code || child.b_code === '') {
  989. const code = parentCode + getChildSort(i + 1, split);
  990. const cData = tree.getNodeKeyData(child);
  991. cData.code = code;
  992. data.push(cData);
  993. if (!tree.isLeafXmj(child)) {
  994. recursiveSortCode(data, code, child.children, split);
  995. }
  996. }
  997. }
  998. };
  999. const data = [];
  1000. recursiveSortCode(data, select.code, select.children, tree.getCodeSplit());
  1001. if (data.length > 0) {
  1002. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1003. const refreshNode = tree.loadPostData(result);
  1004. treeOperationObj.refreshTree(sheet, refreshNode);
  1005. })
  1006. }
  1007. },
  1008. };
  1009. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  1010. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  1011. ledgerTreeCol.initSpreadSetting(ledgerSpreadSetting);
  1012. ledgerSpreadSetting.headColWidth = [50];
  1013. ledgerSpreadSetting.rowHeader = [
  1014. {
  1015. rowHeaderType: 'tag',
  1016. setting: {
  1017. indent: 14,
  1018. tagSize: 0.8,
  1019. tagFont: '8px 微软雅黑',
  1020. getColor: function (index, data) {
  1021. if (!data) return;
  1022. return billsTag.getBillsTagsColor(data.id);
  1023. },
  1024. getTagHtml: function (index, data) {
  1025. if (!data) return;
  1026. const getHtml = function (list) {
  1027. if (!list || list.length === 0) return '';
  1028. const html = [];
  1029. for (const l of list) {
  1030. html.push('<div class="row mr-1">');
  1031. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  1032. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  1033. html.push('</div>');
  1034. }
  1035. return html.join('');
  1036. };
  1037. return getHtml(billsTag.getBillsTagsInfo(data.id));
  1038. }
  1039. },
  1040. },
  1041. ];
  1042. // ledgerSpreadSetting.cols.push(
  1043. // {title: 'ledger_id', colSpan: '1', rowSpan: '2', field: 'ledger_id', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1044. // {title: 'ledger_pid', colSpan: '1', rowSpan: '2', field: 'ledger_pid', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1045. // {title: 'level', colSpan: '1', rowSpan: '2', field: 'level', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1046. // {title: 'order', colSpan: '1', rowSpan: '2', field: 'order', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1047. // {title: 'is_leaf', colSpan: '1', rowSpan: '2', field: 'is_leaf', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1048. // {title: 'full_path', colSpan: '1', rowSpan: '2', field: 'full_path', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1049. // {title: 'node_type', colSpan: '1', rowSpan: '2', field: 'node_type', hAlign: 2, width: 60, type: 'Number', readOnly: true}
  1050. // );
  1051. sjsSettingObj.setNodeTypeCol(ledgerSpreadSetting.cols, [{ field: 'node_type' }]);
  1052. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  1053. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  1054. // 绑定事件
  1055. ledgerSpread.bind(spreadNS.Events.SelectionChanged, treeOperationObj.selectionChanged);
  1056. ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
  1057. ledgerSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1058. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1059. SpreadJsObj.Clipboard.setCopyData(copyText);
  1060. });
  1061. if (!ledgerSpreadSetting.readOnly) {
  1062. ledgerSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1063. treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
  1064. });
  1065. ledgerSpread.bind(spreadNS.Events.EditEnded, treeOperationObj.editEnded);
  1066. SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
  1067. ledgerSpread.bind(spreadNS.Events.ClipboardPasting, treeOperationObj.clipboardPasting);
  1068. ledgerSpread.bind(spreadNS.Events.EditStarting, treeOperationObj.editStarting);
  1069. SpreadJsObj.addCutEvents(ledgerSpread, treeOperationObj.cut);
  1070. // 绑定 删除等 顶部按钮
  1071. $('#insert').click(() => {
  1072. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1073. });
  1074. $('#delete').click(function () {
  1075. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1076. });
  1077. $('#up-move').click(function () {
  1078. treeOperationObj.upMove(ledgerSpread.getActiveSheet());
  1079. });
  1080. $('#down-move').click(function () {
  1081. treeOperationObj.downMove(ledgerSpread.getActiveSheet());
  1082. });
  1083. $('#up-level').click(function () {
  1084. treeOperationObj.upLevel(ledgerSpread.getActiveSheet());
  1085. });
  1086. $('#down-level').click(function () {
  1087. treeOperationObj.downLevel(ledgerSpread.getActiveSheet());
  1088. });
  1089. $('#copy').click(function () {
  1090. ledgerSpread.commandManager().execute({
  1091. cmd: 'copy',
  1092. sheetName: ledgerSpread.getActiveSheet().name()
  1093. });
  1094. });
  1095. $('#paste').click(function () {
  1096. ledgerSpread.commandManager().execute({
  1097. cmd: 'paste',
  1098. sheetName: ledgerSpread.getActiveSheet().name()
  1099. });
  1100. });
  1101. $('#cut').click(function () {
  1102. ledgerSpread.commandManager().execute({
  1103. cmd: 'cut',
  1104. sheetName: ledgerSpread.getActiveSheet().name()
  1105. });
  1106. });
  1107. $('#bills-expr').bind('change onblur', function () {
  1108. const expr = $(this);
  1109. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1110. const select = ledgerTree.getItemsByIndex(row);
  1111. if (!select) return;
  1112. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1113. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1114. // 台账模式,检查计量单元相关
  1115. if (checkTzMeasureType()) {
  1116. if (field === 'sgfh_qty' || field === 'sgfh_tp' ||
  1117. field === 'sjcl_qty' || field === 'sjcl_tp' ||
  1118. field === 'qtcl_qty' || field === 'qtcl_tp') {
  1119. if (!select.children || select.children.length === 0) {
  1120. const lPos = pos.getLedgerPos(select.id);
  1121. if (lPos && lPos.length > 0) {
  1122. toastr.error('清单含有计量单元,请在计量单元输入数量');
  1123. expr.val('');
  1124. return;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. const data = {
  1130. id: select.id,
  1131. tender_id: select.tender_id,
  1132. ledger_id: select.ledger_id
  1133. };
  1134. const exprInfo = getExprInfo(field);
  1135. if (newValue !== '') {
  1136. const num = _.toNumber(newValue);
  1137. if (num) {
  1138. data[field] = num;
  1139. if (exprInfo) {
  1140. data[exprInfo.expr] = '';
  1141. }
  1142. } else {
  1143. try {
  1144. data[field] = math.evaluate(transExpr(newValue));
  1145. if (exprInfo) {
  1146. data[exprInfo.expr] = newValue;
  1147. }
  1148. } catch (err) {
  1149. toastr.error('输入的表达式非法');
  1150. return;
  1151. }
  1152. }
  1153. } else {
  1154. data[field] = null;
  1155. if (exprInfo) {
  1156. data[exprInfo.expr] = '';
  1157. }
  1158. }
  1159. // 更新至服务器
  1160. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1161. const refreshNode = ledgerTree.loadPostData(result);
  1162. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  1163. });
  1164. });
  1165. }
  1166. let batchInsertObj;
  1167. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1168. const self = this;
  1169. if ($.isFunction(item.icon)) {
  1170. item._icon = item.icon.call(this, this, $t, key, item);
  1171. } else {
  1172. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1173. // to enable font awesome
  1174. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1175. } else {
  1176. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1177. }
  1178. }
  1179. this.addClass(item._icon);
  1180. 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>')
  1181. .appendTo(this);
  1182. const $input = $obj.find('input');
  1183. const event = () => {
  1184. if (self.hasClass('context-menu-disabled')) return;
  1185. item.batchInsert($input[0], root);
  1186. };
  1187. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1188. $input.click((e) => {e.stopPropagation();})
  1189. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1190. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1191. };
  1192. // $.contextMenu.types.switch = function (item, opt, root) {
  1193. // const self = this;
  1194. // if ($.isFunction(item.icon)) {
  1195. // item._icon = item.icon.call(this, this, $t, key, item);
  1196. // } else {
  1197. // if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1198. // // to enable font awesome
  1199. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1200. // } else {
  1201. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1202. // }
  1203. // }
  1204. // const html = [];
  1205. // html.push('<div>');
  1206. // html.push('</div>');
  1207. // const $obj = $('<div>' + item.name +)
  1208. // };
  1209. // 右键菜单
  1210. const addTag = newTag({ledgerSheet: ledgerSpread.getActiveSheet(), billsTag});
  1211. const billsContextMenuOptions = {
  1212. selector: '#ledger-spread',
  1213. build: function ($trigger, e) {
  1214. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  1215. treeOperationObj.loadRelaData();
  1216. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1217. },
  1218. items: {},
  1219. };
  1220. if (!readOnly) {
  1221. billsContextMenuOptions.items.create = {
  1222. name: '新增',
  1223. icon: 'fa-sign-in',
  1224. callback: function (key, opt) {
  1225. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1226. },
  1227. disabled: function (key, opt) {
  1228. const sheet = ledgerSpread.getActiveSheet();
  1229. const selection = sheet.getSelections();
  1230. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1231. const row = sel ? sel.row : -1;
  1232. const tree = sheet.zh_tree;
  1233. if (!tree) return true;
  1234. const first = sheet.zh_tree.nodes[row];
  1235. let last = first, sameParent = true;
  1236. if (sel.rowCount > 1) {
  1237. for (let r = 1; r < sel.rowCount; r++) {
  1238. const rNode = tree.nodes[sel.row + r];
  1239. if (rNode.level > first.level) continue;
  1240. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1241. sameParent = false;
  1242. break;
  1243. }
  1244. last = rNode;
  1245. }
  1246. }
  1247. const valid = !sheet.zh_setting.readOnly;
  1248. return !(valid && first && first.level > 1);
  1249. },
  1250. visible: function (key, opt) {
  1251. return !readOnly;
  1252. }
  1253. };
  1254. billsContextMenuOptions.items.delete = {
  1255. name: '删除',
  1256. icon: 'fa-remove',
  1257. callback: function (key, opt) {
  1258. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1259. },
  1260. disabled: function (key, opt) {
  1261. const sheet = ledgerSpread.getActiveSheet();
  1262. const selection = sheet.getSelections();
  1263. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1264. const row = sel ? sel.row : -1;
  1265. const tree = sheet.zh_tree;
  1266. if (!tree) return true;
  1267. const first = sheet.zh_tree.nodes[row];
  1268. let last = first, sameParent = true;
  1269. if (sel.rowCount > 1) {
  1270. for (let r = 1; r < sel.rowCount; r++) {
  1271. const rNode = tree.nodes[sel.row + r];
  1272. if (rNode.level > first.level) continue;
  1273. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1274. sameParent = false;
  1275. break;
  1276. }
  1277. last = rNode;
  1278. }
  1279. }
  1280. const valid = !sheet.zh_setting.readOnly;
  1281. return !(valid && first && sameParent && !(first.level === 1 && first.node_type));
  1282. },
  1283. visible: function (key, opt) {
  1284. return !readOnly;
  1285. }
  1286. };
  1287. billsContextMenuOptions.items.sprBase = '----';
  1288. }
  1289. if (!readOnly) {
  1290. billsContextMenuOptions.items.batchInsert = {
  1291. name: '批量插入',
  1292. type: 'batchInsert',
  1293. value: '2',
  1294. icon: 'fa-sign-in',
  1295. batchInsert: function (obj, root) {
  1296. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1297. obj.value = obj.max;
  1298. toastr.warning('批量插入不可多于' + obj.max);
  1299. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1300. obj.value = obj.min;
  1301. toastr.warning('批量插入不可少于' + obj.min);
  1302. } else {
  1303. treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  1304. root.$menu.trigger('contextmenu:hide');
  1305. }
  1306. },
  1307. disabled: function (key, opt) {
  1308. const sheet = ledgerSpread.getActiveSheet();
  1309. const selection = sheet.getSelections();
  1310. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1311. const row = sel ? sel.row : -1;
  1312. const tree = sheet.zh_tree;
  1313. if (!tree) return true;
  1314. const first = sheet.zh_tree.nodes[row];
  1315. let last = first, sameParent = true;
  1316. if (sel.rowCount > 1) {
  1317. for (let r = 1; r < sel.rowCount; r++) {
  1318. const rNode = tree.nodes[sel.row + r];
  1319. if (rNode.level > first.level) continue;
  1320. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1321. sameParent = false;
  1322. break;
  1323. }
  1324. last = rNode;
  1325. }
  1326. }
  1327. const valid = !sheet.zh_setting.readOnly;
  1328. return !(valid && first && first.level > 1);
  1329. },
  1330. visible: function (key, opt) {
  1331. return !readOnly;
  1332. }
  1333. };
  1334. billsContextMenuOptions.items.batchInsertBillsPos = {
  1335. name: '批量插入清单-计量单元',
  1336. icon: 'fa-sign-in',
  1337. disabled: function (key, opt) {
  1338. if (!checkTzMeasureType()) return true;
  1339. const sheet = ledgerSpread.getActiveSheet();
  1340. const selection = sheet.getSelections();
  1341. const row = selection[0].row;
  1342. const select = ledgerTree.nodes[row];
  1343. if (select) {
  1344. if (select.code && select.code !== '') {
  1345. return !ledgerTree.isLeafXmj(select);
  1346. } else {
  1347. const parent = ledgerTree.getParent(select);
  1348. return !(parent && ledgerTree.isLeafXmj(parent));
  1349. }
  1350. } else {
  1351. return true;
  1352. }
  1353. },
  1354. callback: function (key, opt) {
  1355. if (!batchInsertObj) {
  1356. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1357. } else {
  1358. batchInsertObj.initView();
  1359. }
  1360. $('#batch').modal('show');
  1361. },
  1362. visible: function (key, opt) {
  1363. return !readOnly;
  1364. }
  1365. };
  1366. billsContextMenuOptions.items.sprBatch = '----';
  1367. }
  1368. billsContextMenuOptions.items.copyBlock = {
  1369. name: '复制整块',
  1370. icon: 'fa-files-o',
  1371. callback: function (key, opt) {
  1372. /*ledgerSpread.commandManager().execute({
  1373. cmd:"copy",
  1374. sheetName:ledgerSpread.getActiveSheet().name()
  1375. });*/
  1376. treeOperationObj.block = [];
  1377. const copyBlockList = [];
  1378. const sheet = ledgerSpread.getActiveSheet();
  1379. const sel = sheet.getSelections()[0];
  1380. let iRow = sel.row;
  1381. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1382. while (iRow < sel.row + sel.rowCount) {
  1383. const node = sheet.zh_tree.nodes[iRow];
  1384. if (node.ledger_pid !== pid) {
  1385. toastr.error('仅可同时选中同层节点');
  1386. return;
  1387. }
  1388. const posterity = sheet.zh_tree.getPosterity(node);
  1389. iRow += posterity.length + 1;
  1390. posterity.unshift(node);
  1391. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1392. }
  1393. for (const cbl of copyBlockList) {
  1394. for (const b of cbl) {
  1395. const posRange = pos.getLedgerPos(b.id);
  1396. if (posRange && posRange.length > 0) b.pos = posRange;
  1397. }
  1398. }
  1399. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1400. },
  1401. visible: function (key, opt) {
  1402. const sheet = ledgerSpread.getActiveSheet();
  1403. const selection = sheet.getSelections();
  1404. const row = selection[0].row;
  1405. const select = ledgerTree.nodes[row];
  1406. return select;
  1407. },
  1408. disabled: function (key, opt) {
  1409. const sheet = ledgerSpread.getActiveSheet();
  1410. const selection = sheet.getSelections();
  1411. const row = selection[0].row;
  1412. const select = ledgerTree.nodes[row];
  1413. return select && select.level <= 1;
  1414. }
  1415. };
  1416. billsContextMenuOptions.items.copyBlockXmj = {
  1417. name: '复制整块(只复制项目节)',
  1418. icon: 'fa-files-o',
  1419. callback: function (key, opt) {
  1420. treeOperationObj.block = [];
  1421. const copyBlockList = [];
  1422. const sheet = ledgerSpread.getActiveSheet();
  1423. const sel = sheet.getSelections()[0];
  1424. let iRow = sel.row;
  1425. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1426. while (iRow < sel.row + sel.rowCount) {
  1427. const node = sheet.zh_tree.nodes[iRow];
  1428. if (node.ledger_pid !== pid) {
  1429. toastr.error('仅可同时选中同层节点');
  1430. return;
  1431. }
  1432. const posterity = sheet.zh_tree.getPosterity(node);
  1433. iRow += posterity.length + 1;
  1434. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1435. copyPosterity.unshift(node);
  1436. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1437. for (const p of copyData) {
  1438. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1439. p.is_leaf = children.length === 0;
  1440. }
  1441. copyBlockList.push(copyData);
  1442. }
  1443. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1444. },
  1445. visible: function (key, opt) {
  1446. const sheet = ledgerSpread.getActiveSheet();
  1447. const selection = sheet.getSelections();
  1448. const row = selection[0].row;
  1449. const select = ledgerTree.nodes[row];
  1450. return select;
  1451. },
  1452. disabled: function (key, opt) {
  1453. const sheet = ledgerSpread.getActiveSheet();
  1454. const selection = sheet.getSelections();
  1455. const row = selection[0].row;
  1456. const select = ledgerTree.nodes[row];
  1457. return select && select.level <= 1;
  1458. }
  1459. };
  1460. if (!readOnly) {
  1461. billsContextMenuOptions.items.pasteBlock = {
  1462. name: '粘贴整块',
  1463. icon: 'fa-clipboard',
  1464. disabled: function (key, opt) {
  1465. //const block = treeOperationObj.block || [];
  1466. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1467. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1468. },
  1469. callback: function (key, opt) {
  1470. //const block = treeOperationObj.block || [];
  1471. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1472. if (copyInfo.block.length > 0) {
  1473. treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
  1474. } else {
  1475. document.execCommand('paste');
  1476. }
  1477. },
  1478. visible: function (key, opt) {
  1479. return !readOnly;
  1480. }
  1481. };
  1482. }
  1483. billsContextMenuOptions.items.sprBlock = '----';
  1484. if (!readOnly) {
  1485. billsContextMenuOptions.items.sortChildren = {
  1486. name: '顺序重排子项编号',
  1487. icon: 'fa-sort-numeric-asc',
  1488. disabled: function (key, opt) {
  1489. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1490. return !node || !node.code || !node.children || node.children === 0 || node.code.length < 3;
  1491. },
  1492. callback: function (key, opt) {
  1493. treeOperationObj.sortCode(ledgerSpread.getActiveSheet());
  1494. },
  1495. visible: function (key, opt) {
  1496. return !readOnly;
  1497. }
  1498. };
  1499. if (!checkTzMeasureType()) {
  1500. billsContextMenuOptions.items.applyDeal2Sgfh = {
  1501. name: '填设计量',
  1502. icon: 'fa-pencil',
  1503. callback: function (key, opt) {
  1504. postData(window.location.pathname + '/deal2sgfh', null, function (result) {
  1505. ledgerTree.loadDatas(result.bills);
  1506. treeCalc.calculateAll(ledgerTree);
  1507. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1508. });
  1509. }
  1510. };
  1511. }
  1512. billsContextMenuOptions.items.sprSort = '----';
  1513. }
  1514. if (!readOnly) {
  1515. const tenderSelect = TenderSelect({
  1516. type: 'ledger',
  1517. afterLoad: function (result) {
  1518. const ledgerSheet = ledgerSpread.getActiveSheet();
  1519. const refreshNode = ledgerTree.loadPostData(result);
  1520. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1521. treeOperationObj.refreshOperationValid(ledgerSheet);
  1522. }
  1523. });
  1524. billsContextMenuOptions.items.importExcel = {
  1525. name: '导入分项清单Excel',
  1526. icon: 'fa-file-excel-o',
  1527. disabled: function (key, opt) {
  1528. return readOnly;
  1529. },
  1530. callback: function (key, opt) {
  1531. importExcel.doImport({
  1532. template: {
  1533. hint: '0号台账',
  1534. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/A/导入分项清单EXCEL格式.xlsx',
  1535. },
  1536. filter: true,
  1537. callback: function (sheet, filter) {
  1538. postDataCompress(window.location.pathname + '/upload-excel/tz', {sheet, filter}, function (result) {
  1539. ledgerTree.loadDatas(result.bills);
  1540. treeCalc.calculateAll(ledgerTree);
  1541. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1542. pos.loadDatas(result.pos);
  1543. posOperationObj.loadCurPosData();
  1544. checkShowLast(result.bills.length);
  1545. }, null);
  1546. },
  1547. // callback: function (file, select) {
  1548. // const formData = new FormData();
  1549. // formData.append('file', file.files[0]);
  1550. // postDataWithFileProgress(window.location.pathname + '/upload-excel?ueType=tz&sheetName=' + select, formData, function (result) {
  1551. // ledgerTree.loadDatas(result.bills);
  1552. // treeCalc.calculateAll(ledgerTree);
  1553. // SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1554. // pos.loadDatas(result.pos);
  1555. // posOperationObj.loadCurPosData();
  1556. // }, null);
  1557. // }
  1558. //u_type: importExcel.uploadType.file,
  1559. });
  1560. }
  1561. };
  1562. billsContextMenuOptions.items.importGclBills2Xmj = {
  1563. name: '导入工程量清单至项目节',
  1564. icon: 'fa-file-excel-o',
  1565. disabled: function (key, opt) {
  1566. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1567. return readOnly || !node
  1568. || (node.children && node.children.length > 0)
  1569. || (!_.isNil(node.b_code) && node.b_code !== '');
  1570. },
  1571. callback: function (key, opt) {
  1572. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1573. importExcel.doImport({
  1574. template: {
  1575. hint: '工程量清单',
  1576. url: '/template/导入工程量清单EXCEL格式.xls',
  1577. },
  1578. callback: function (sheet) {
  1579. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1580. const ledgerSheet = ledgerSpread.getActiveSheet();
  1581. const sel = ledgerSheet.getSelections();
  1582. const refreshNode = ledgerTree.loadPostData(result);
  1583. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1584. if (refreshNode.create[0]) {
  1585. if (sel && sel[0]) {
  1586. ledgerSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1587. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [sel[0].row, refreshNode.create[0].index]);
  1588. } else {
  1589. ledgerSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1590. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [refreshNode.create[0].index]);
  1591. }
  1592. }
  1593. treeOperationObj.refreshOperationValid(ledgerSheet);
  1594. }, null);
  1595. }
  1596. });
  1597. }
  1598. };
  1599. billsContextMenuOptions.items.importOtherTender = {
  1600. name: '导入(其他标段)工程量清单至项目节',
  1601. icon: 'fa-link',
  1602. disabled: function (key, opt) {
  1603. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1604. return readOnly || !node
  1605. || (node.children && node.children.length > 0)
  1606. || !ledgerTree.isLeafXmj(node);
  1607. },
  1608. callback: function (key, opt) {
  1609. tenderSelect.showSelect(SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet()));
  1610. }
  1611. };
  1612. billsContextMenuOptions.items.sprImport = '----';
  1613. }
  1614. billsContextMenuOptions.items.tag = {
  1615. name: '书签',
  1616. callback: function (key, opt, menu, e) {
  1617. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1618. addTag.do(node);
  1619. },
  1620. disabled: function (key, opt) {
  1621. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1622. return !node;
  1623. }
  1624. };
  1625. billsContextMenuOptions.items.sprTag = '----';
  1626. billsContextMenuOptions.items.showLast = {
  1627. name: '显示至最底层',
  1628. callback: function (key, opt, menu, e) {
  1629. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1630. setTimeout(() => {
  1631. showWaitingView();
  1632. ledgerTree.expandByCustom(x => {
  1633. return x.expanded ||(x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1634. });
  1635. SpreadJsObj.refreshTreeRowVisible(ledgerSpread.getActiveSheet());
  1636. closeWaitingView();
  1637. }, 100);
  1638. },
  1639. };
  1640. billsContextMenuOptions.items.exportJSON = {
  1641. name: '导出后台标准表json',
  1642. callback: function (key, opt, menu, e) {
  1643. const result = [];
  1644. for (const node of ledgerTree.nodes) {
  1645. result.push({
  1646. id: node.ledger_id, pid: node.ledger_pid, level: node.level, order: node.order,
  1647. is_leaf: !node.children || node.children.length === 0, full_path: node.full_path,
  1648. code: node.code || '', b_code: node.b_code || '', name: node.name || '', unit: node.unit || '',
  1649. node_type: node.node_type,
  1650. });
  1651. }
  1652. const blob = new Blob([JSON.stringify(result, '', '\t')], { type: 'application/text'});
  1653. saveAs(blob, "台账分解.json");
  1654. },
  1655. visible: function() {
  1656. return is_debug;
  1657. }
  1658. };
  1659. $.contextMenu(billsContextMenuOptions);
  1660. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  1661. // 台账模式加载计量单元数据
  1662. if (checkTzMeasureType()) {
  1663. $.divResizer({
  1664. select: '#main-resize',
  1665. callback: function () {
  1666. ledgerSpread.refresh();
  1667. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1668. $(".sp-wrap").height(bcontent-30);
  1669. posSpread.refresh();
  1670. }
  1671. });
  1672. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  1673. }
  1674. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  1675. //绑定计量单元编辑事件
  1676. const posOperationObj = {
  1677. /**
  1678. * 刷新顶部按钮是否可用
  1679. * @param sheet
  1680. * @param selections
  1681. */
  1682. refreshOperationValid: function (sheet, selection) {
  1683. const setObjEnable = function (obj, enable) {
  1684. if (enable) {
  1685. obj.removeClass('disabled');
  1686. } else {
  1687. obj.addClass('disabled');
  1688. }
  1689. };
  1690. const invalidAll = function () {
  1691. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1692. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1693. };
  1694. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1695. const row = sel ? sel.row : -1;
  1696. const first = sheet.zh_data[row];
  1697. if (!first) {
  1698. invalidAll();
  1699. return;
  1700. }
  1701. let last = first;
  1702. if (sel.rowCount > 1 && first) {
  1703. for (let r = 1; r < sel.rowCount; r++) {
  1704. const rNode = sheet.zh_data[sel.row + r];
  1705. if (!rNode) break;
  1706. last = rNode;
  1707. }
  1708. }
  1709. const preNode = sheet.zh_data[row - 1];
  1710. const valid = !sheet.zh_setting.readOnly;
  1711. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1712. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1713. },
  1714. editStarting: function (e, info) {
  1715. posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1716. const sel = info.sheet.getSelections();
  1717. if (!sel || !sel[0]) return;
  1718. const col = info.sheet.zh_setting.cols[sel[0].col];
  1719. const node = SpreadJsObj.getSelectObject(info.sheet);
  1720. const exprInfo = getExprInfo(col.field);
  1721. if (exprInfo) {
  1722. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1723. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1724. }
  1725. }
  1726. },
  1727. loadExprToInput: function () {
  1728. const sheet = posSpread.getActiveSheet();
  1729. const sel = sheet.getSelections()[0];
  1730. if (!sel || !sheet.zh_setting) return;
  1731. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1732. if (col && col.type === 'Number') {
  1733. const data = SpreadJsObj.getSelectObject(sheet);
  1734. if (data) {
  1735. const exprInfo = getExprInfo(col.field);
  1736. const value = exprInfo
  1737. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1738. : data[col.field];
  1739. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1740. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1741. } else {
  1742. $('#pos-expr').val('').attr('readOnly', true);
  1743. $('#pos-expr').removeAttr('data-row');
  1744. }
  1745. } else {
  1746. $('#pos-expr').val('').attr('readOnly', true);
  1747. $('#pos-expr').removeAttr('data-row');
  1748. }
  1749. },
  1750. /**
  1751. * 加载计量单元 根据当前台账选择节点
  1752. */
  1753. loadCurPosData: function () {
  1754. //spreadJsObj.reinitSheet(posSpread.getActiveSheet());
  1755. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1756. if (node) {
  1757. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  1758. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  1759. getNodeList(node.id);
  1760. } else {
  1761. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  1762. }
  1763. posOperationObj.loadExprToInput();
  1764. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  1765. },
  1766. baseOpr: function (sheet, type) {
  1767. const data = {
  1768. updateType: type === 'delete' ? type : 'update',
  1769. updateData: [],
  1770. };
  1771. const selection = sheet.getSelections();
  1772. const row = selection[0].row, count = selection[0].rowCount;
  1773. const first = sheet.zh_data[row];
  1774. if (type === 'delete') {
  1775. for (let iRow = 0; iRow < count; iRow++) {
  1776. const posData = sheet.zh_data[iRow + row];
  1777. if (posData) {
  1778. data.updateData.push(sheet.zh_data[iRow + row].id);
  1779. }
  1780. }
  1781. } else if (type === 'up-move') {
  1782. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1783. for (let iRow = 0; iRow < count; iRow++) {
  1784. const posData = sheet.zh_data[iRow + row];
  1785. if (posData) {
  1786. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1787. preUpdate.porder = posData.porder;
  1788. }
  1789. }
  1790. data.updateData.push(preUpdate);
  1791. } else if (type === 'down-move') {
  1792. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1793. for (let iRow = count - 1; iRow >= 0; 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. nextUpdate.porder = posData.porder;
  1798. }
  1799. }
  1800. data.updateData.push(nextUpdate);
  1801. }
  1802. if (data.updateData.length > 0) {
  1803. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1804. if (type === 'delete') {
  1805. pos.removeDatas(result.pos);
  1806. sheet.deleteRows(row, count);
  1807. const loadResult = ledgerTree.loadPostData(result.ledger);
  1808. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1809. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1810. } else {
  1811. pos.updateDatas(result.pos);
  1812. const sel = selection[0];
  1813. if (sel) {
  1814. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1815. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1816. }
  1817. posOperationObj.loadCurPosData();
  1818. }
  1819. });
  1820. }
  1821. },
  1822. /**
  1823. * 编辑单元格响应事件
  1824. * @param {Object} e
  1825. * @param {Object} info
  1826. */
  1827. editEnded: function (e, info) {
  1828. if (info.sheet.zh_setting) {
  1829. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1830. const col = info.sheet.zh_setting.cols[info.col];
  1831. const orgText = posData ? posData[col.field] : null;
  1832. const newText = trimInvalidChar(info.editingText);
  1833. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
  1834. return;
  1835. }
  1836. const node = posOperationObj.ledgerTreeNode;
  1837. if (!node) {
  1838. toastr.error('数据错误,请选择台账节点后再试');
  1839. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1840. return;
  1841. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1842. toastr.error('父节点不可插入计量单元');
  1843. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1844. return;
  1845. }else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1846. toastr.error('项目节不可插入计量单元');
  1847. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1848. return;
  1849. }
  1850. const data = { updateType: posData ? 'update' : 'add' };
  1851. if (!posData) {
  1852. const sortData = info.sheet.zh_data;
  1853. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1854. data.updateData = { lid: node.id, tid: tender.id, porder: order };
  1855. } else {
  1856. data.updateData = { id: posData.id };
  1857. }
  1858. if (col.type === 'Number') {
  1859. const exprInfo = getExprInfo(col.field);
  1860. const num = _.toNumber(newText);
  1861. if (_.isFinite(num)) {
  1862. data.updateData[col.field] = num;
  1863. if (exprInfo) {
  1864. data.updateData[exprInfo.expr] = '';
  1865. }
  1866. } else {
  1867. try {
  1868. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1869. if (exprInfo) {
  1870. data.updateData[exprInfo.expr] = newText;
  1871. }
  1872. } catch(err) {
  1873. toastr.error('输入的表达式非法');
  1874. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1875. return;
  1876. }
  1877. }
  1878. } else {
  1879. data.updateData[col.field] = newText;
  1880. }
  1881. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1882. const updateRst = pos.updateDatas(result.pos);
  1883. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1884. if (updateRst.create.length > 0) {
  1885. // info.sheet.addRows(info.row, 1);
  1886. // if (info.sheet.zh_data.length === 0) {
  1887. // info.sheet.zh_data = pos.ledgerPos[itemsPre + node.id] || [];
  1888. // }
  1889. // SpreadJsObj.reLoadRowData(info.sheet, info.sheet.zh_data.length - 1);
  1890. posOperationObj.loadCurPosData();
  1891. } else {
  1892. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1893. }
  1894. const loadResult = ledgerTree.loadPostData(result.ledger);
  1895. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1896. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1897. }, function () {
  1898. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1899. });
  1900. }
  1901. },
  1902. /**
  1903. * 删除按钮响应事件
  1904. * @param sheet
  1905. */
  1906. deletePress: function (sheet) {
  1907. const self = this;
  1908. if (sheet.zh_setting) {
  1909. const sortData = sheet.zh_data;
  1910. const datas = [], posSelects = [];
  1911. const sel = sheet.getSelections()[0];
  1912. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1913. let bDel = false;
  1914. const node = sortData[iRow];
  1915. if (node) {
  1916. const data = {id: node.id};
  1917. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1918. const colSetting = sheet.zh_setting.cols[iCol];
  1919. const style = sheet.getStyle(iRow, iCol);
  1920. if (!style.locked) {
  1921. const colSetting = sheet.zh_setting.cols[iCol];
  1922. data[colSetting.field] = null;
  1923. const exprInfo = getExprInfo(colSetting.field);
  1924. if (exprInfo) data[exprInfo.expr] = '';
  1925. bDel = true;
  1926. }
  1927. }
  1928. if (bDel) {
  1929. datas.push(data);
  1930. posSelects.push(node);
  1931. }
  1932. }
  1933. }
  1934. if (datas.length > 0) {
  1935. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: datas}, function (result) {
  1936. pos.updateDatas(result.pos);
  1937. posOperationObj.loadCurPosData();
  1938. const loadResult = ledgerTree.loadPostData(result.ledger);
  1939. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1940. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1941. }, function () {
  1942. posOperationObj.loadCurPosData();
  1943. });
  1944. }
  1945. }
  1946. },
  1947. /**
  1948. * 删除 计量单元
  1949. * @param sheet
  1950. */
  1951. deletePos: function (sheet) {
  1952. const selection = sheet.getSelections();
  1953. const data = {
  1954. updateType: 'delete',
  1955. updateData: [],
  1956. };
  1957. const row = selection[0].row, count = selection[0].rowCount;
  1958. const sortData = sheet.zh_data;
  1959. for (let iRow = 0; iRow < count; iRow++) {
  1960. if (sortData[iRow + row]) {
  1961. data.updateData.push(sortData[iRow + row].id);
  1962. }
  1963. }
  1964. if (data.updateData.length > 0) {
  1965. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1966. pos.removeDatas(result.pos);
  1967. sheet.deleteRows(row, count);
  1968. const loadResult = ledgerTree.loadPostData(result.ledger);
  1969. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1970. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1971. });
  1972. }
  1973. },
  1974. insertPos: function (sheet) {
  1975. const selection = sheet.getSelections();
  1976. const sortData = sheet.zh_data;
  1977. const row = selection[0].row;
  1978. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1979. const select = SpreadJsObj.getSelectObject(sheet);
  1980. const porder = select ? select.porder : sortData.length + 1;
  1981. const data = {
  1982. updateType: 'insert',
  1983. updateData: [ { lid: node.id, tid: tender.id, porder } ],
  1984. };
  1985. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1986. const updateRst = pos.updateDatas(result.pos);
  1987. posOperationObj.loadCurPosData();
  1988. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1989. });
  1990. },
  1991. /**
  1992. * 粘贴单元格响应事件
  1993. * @param e
  1994. * @param info
  1995. */
  1996. clipboardPasted: function (e, info) {
  1997. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1998. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1999. }
  2000. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  2001. if (node.code && (node.code !== '')) {
  2002. toastr.error('项目节不可含有清单明细');
  2003. posOperationObj.loadCurPosData();
  2004. return;
  2005. }
  2006. if (node.children && (node.children.length > 0)) {
  2007. toastr.error('仅清单子项可以含有计量单元');
  2008. posOperationObj.loadCurPosData();
  2009. return;
  2010. }
  2011. const hint = {
  2012. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2013. };
  2014. if (info.sheet.zh_setting) {
  2015. const data = [];
  2016. const sortData = info.sheet.zh_data || [];
  2017. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2018. if (info.cellRange.col !== 0) {
  2019. toastr.warning('新增计量单元请先输入名称');
  2020. posOperationObj.loadCurPosData();
  2021. return;
  2022. }
  2023. }
  2024. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2025. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2026. let bPaste = false;
  2027. const curRow = info.cellRange.row + iRow;
  2028. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2029. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2030. const curCol = info.cellRange.col + iCol;
  2031. const colSetting = info.sheet.zh_setting.cols[curCol];
  2032. if (!colSetting) continue;
  2033. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2034. if (colSetting.type === 'Number') {
  2035. const num = _.toNumber(posData[colSetting.field]);
  2036. if (num) {
  2037. posData[colSetting.field] = num;
  2038. bPaste = true;
  2039. } else {
  2040. try {
  2041. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2042. const exprInfo = getExprInfo(colSetting.field);
  2043. if (exprInfo) {
  2044. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2045. }
  2046. bPaste = true;
  2047. } catch (err) {
  2048. delete posData[colSetting.field];
  2049. toastMessageUniq(hint.expr);
  2050. }
  2051. }
  2052. } else {
  2053. bPaste = true;
  2054. }
  2055. }
  2056. if (bPaste) {
  2057. data.push(posData);
  2058. }
  2059. }
  2060. if (data.length > 0) {
  2061. postData('/tender/' + getTenderId() + '/pos/paste', data, function (result) {
  2062. pos.updateDatas(result.pos);
  2063. posOperationObj.loadCurPosData();
  2064. const loadResult = ledgerTree.loadPostData(result.ledger);
  2065. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2066. posOperationObj.loadCurPosData();
  2067. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2068. }, function () {
  2069. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2070. });
  2071. } else {
  2072. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2073. }
  2074. }
  2075. },
  2076. selectionChanged: function (e, info) {
  2077. posOperationObj.loadExprToInput();
  2078. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  2079. },
  2080. addPegs: function (pegs) {
  2081. if (!pegs || pegs.length <= 0) return;
  2082. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2083. if (!node) return;
  2084. const sheet = posSpread.getActiveSheet();
  2085. const sortData = sheet.zh_data || [];
  2086. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2087. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2088. postData('/tender/' + getTenderId() + '/pos/paste', pegs, function (result) {
  2089. pos.updateDatas(result.pos);
  2090. posOperationObj.loadCurPosData();
  2091. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2092. });
  2093. }
  2094. };
  2095. posSpread.bind(spreadNS.Events.SelectionChanged, posOperationObj.selectionChanged);
  2096. if (!posSpreadSetting.readOnly) {
  2097. $('a[name="pos-opr"]').click(function () {
  2098. posOperationObj.baseOpr(posSpread.getActiveSheet(), this.getAttribute('type'));
  2099. });
  2100. $('#pos-expr').bind('change onblur', function () {
  2101. const expr = $(this);
  2102. const posSheet = posSpread.getActiveSheet();
  2103. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2104. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2105. if (!select) return;
  2106. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2107. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2108. const data = {id: select.id};
  2109. const exprInfo = getExprInfo(field);
  2110. if (newValue !== '') {
  2111. const num = _.toNumber(newValue);
  2112. if (num) {
  2113. data[field] = num;
  2114. if (exprInfo) {
  2115. data[exprInfo.expr] = '';
  2116. }
  2117. } else {
  2118. try {
  2119. data[field] = math.evaluate(transExpr(newValue));
  2120. if (exprInfo) {
  2121. data[exprInfo.expr] = newValue;
  2122. }
  2123. } catch (err) {
  2124. toastr.error('输入的表达式非法');
  2125. return;
  2126. }
  2127. }
  2128. } else {
  2129. data[field] = null;
  2130. if (exprInfo) {
  2131. data[exprInfo.expr] = '';
  2132. }
  2133. }
  2134. // 更新至服务器
  2135. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: data}, function (result) {
  2136. const updateRst = pos.updateDatas(result.pos);
  2137. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2138. const loadResult = ledgerTree.loadPostData(result.ledger);
  2139. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2140. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2141. });
  2142. });
  2143. SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
  2144. posSpread.bind(spreadNS.Events.EditStarting, posOperationObj.editStarting);
  2145. posSpread.bind(spreadNS.Events.EditEnded, posOperationObj.editEnded);
  2146. posSpread.bind(spreadNS.Events.ClipboardPasted, posOperationObj.clipboardPasted);
  2147. const mergePeg = NewMergePeg({ callback: posOperationObj.addPegs });
  2148. // 右键菜单
  2149. $.contextMenu({
  2150. selector: '#pos-spread',
  2151. build: function ($trigger, e) {
  2152. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2153. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2154. },
  2155. items: {
  2156. 'insert': {
  2157. name: '插入',
  2158. icon: 'fa-plus',
  2159. disabled: function (key, opt) {
  2160. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2161. return node && node.children && node.children.length > 0;
  2162. },
  2163. callback: function (key, opt) {
  2164. posOperationObj.insertPos(posSpread.getActiveSheet());
  2165. }
  2166. },
  2167. 'delete': {
  2168. name: '删除',
  2169. icon: 'fa-remove',
  2170. disabled: function (key, opt) {
  2171. const sheet = posSpread.getActiveSheet();
  2172. if (sheet.zh_data) {
  2173. const selection = sheet.getSelections();
  2174. return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2175. } else {
  2176. return true;
  2177. }
  2178. },
  2179. callback: function (key, opt) {
  2180. posOperationObj.deletePos(posSpread.getActiveSheet());
  2181. }
  2182. },
  2183. 'merge-peg': {
  2184. name: '合并起讫桩号',
  2185. disabled: function (key, opt) {
  2186. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2187. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  2188. },
  2189. callback: function (key, opt) {
  2190. mergePeg.show();
  2191. }
  2192. }
  2193. }
  2194. });
  2195. }
  2196. postData(window.location.pathname + '/load', {}, function (data) {
  2197. ledgerTree.loadDatas(data.bills);
  2198. treeCalc.calculateAll(ledgerTree);
  2199. for (const t of data.tags) {
  2200. t.node = ledgerTree.datas.find(x => {return x.id === t.lid});
  2201. }
  2202. billsTag.loadDatas(data.tags);
  2203. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  2204. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  2205. checkShowLast(data.bills.length);
  2206. pos.loadDatas(data.pos);
  2207. posOperationObj.loadCurPosData();
  2208. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  2209. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2210. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  2211. checkList.loadHisCheckData();
  2212. }, null, true);
  2213. $.divResizer({
  2214. select: '#right-spr',
  2215. callback: function () {
  2216. ledgerSpread.refresh();
  2217. if (posSpread) {
  2218. posSpread.refresh();
  2219. }
  2220. if (stdXmj) {
  2221. stdXmj.spread.refresh();
  2222. }
  2223. if (stdGcl) {
  2224. stdGcl.spread.refresh();
  2225. }
  2226. if (dealBills) {
  2227. dealBills.spread.refresh();
  2228. }
  2229. if (searchLedger) {
  2230. searchLedger.spread.refresh();
  2231. }
  2232. if (errorList) {
  2233. errorList.spread.refresh();
  2234. }
  2235. if (checkList) {
  2236. checkList.spread.refresh();
  2237. }
  2238. if (gclGather) gclGather.spread.refresh();
  2239. }
  2240. });
  2241. const stdLibCellDoubleClick = function (e, info) {
  2242. const stdSheet = info.sheet;
  2243. const mainSheet = ledgerSpread.getActiveSheet();
  2244. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2245. const stdTree = stdSheet.zh_tree;
  2246. const stdNode = stdTree.nodes[info.row];
  2247. const mainTree = mainSheet.zh_tree;
  2248. const sel = mainSheet.getSelections()[0];
  2249. const mainNode = mainTree.nodes[sel.row];
  2250. if (!stdNode) { return; }
  2251. if (info.sheet.zh_setting.stdType === 'gcl') {
  2252. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2253. toastr.warning('非最底层项目下,不应添加清单');
  2254. return;
  2255. }
  2256. }
  2257. postData(window.location.pathname + '/update', {
  2258. postType: 'add-std',
  2259. postData: {
  2260. id: ledgerTree.getNodeKey(mainNode),
  2261. tender_id: mainNode.tender_id,
  2262. stdType: info.sheet.zh_setting.stdType,
  2263. stdLibId: stdNode.list_id,
  2264. stdNode: stdTree.getNodeKey(stdNode)
  2265. }
  2266. }, function (result) {
  2267. const refreshNode = mainTree.loadPostData(result);
  2268. treeOperationObj.refreshTree(mainSheet, refreshNode);
  2269. if (refreshNode.create && refreshNode.create.length > 0) {
  2270. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2271. const refreshRow = [sel.row, refreshNode.create[refreshNode.create.length - 1].index];
  2272. const curIndex = mainTree.nodes.indexOf(mainNode);
  2273. if (sel.row !== curIndex && curIndex >= 0) refreshRow.push(curIndex);
  2274. SpreadJsObj.reloadRowsBackColor(mainSheet, refreshRow);
  2275. } else {
  2276. const node = _.find(ledgerTree.nodes, {code: stdNode.code, name: stdNode.name});
  2277. if (node) {
  2278. mainSheet.setSelection(ledgerTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2279. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, ledgerTree.nodes.indexOf(node)]);
  2280. }
  2281. }
  2282. treeOperationObj.refreshOperationValid(mainSheet);
  2283. ledgerSpread.focus();
  2284. posOperationObj.loadCurPosData();
  2285. });
  2286. };
  2287. const stdXmjSetting = {
  2288. selector: '#std-xmj',
  2289. stdType: 'xmj',
  2290. libs: stdChapters,
  2291. treeSetting: {
  2292. id: 'chapter_id',
  2293. pid: 'pid',
  2294. order: 'order',
  2295. level: 'level',
  2296. rootId: -1,
  2297. keys: ['id', 'list_id', 'chapter_id'],
  2298. },
  2299. spreadSetting: {
  2300. cols: [
  2301. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2302. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2303. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2304. ],
  2305. treeCol: 0,
  2306. emptyRows: 0,
  2307. headRows: 1,
  2308. headRowHeight: [32],
  2309. defaultRowHeight: 21,
  2310. headerFont: '12px 微软雅黑',
  2311. font: '12px 微软雅黑',
  2312. headColWidth: [30],
  2313. selectedBackColor: '#fffacd',
  2314. },
  2315. cellDoubleClick: stdLibCellDoubleClick,
  2316. page: 'ledger',
  2317. tid: getTenderId(),
  2318. };
  2319. const stdGclSetting = {
  2320. selector: '#std-gcl',
  2321. stdType: 'gcl',
  2322. libs: stdBills,
  2323. treeSetting: {
  2324. id: 'bill_id',
  2325. pid: 'pid',
  2326. order: 'order',
  2327. level: 'level',
  2328. rootId: -1,
  2329. keys: ['id', 'list_id', 'bill_id']
  2330. },
  2331. spreadSetting: {
  2332. cols: [
  2333. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2334. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2335. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2336. ],
  2337. treeCol: 0,
  2338. emptyRows: 0,
  2339. headRows: 1,
  2340. headRowHeight: [32],
  2341. defaultRowHeight: 21,
  2342. headerFont: '12px 微软雅黑',
  2343. font: '12px 微软雅黑',
  2344. headColWidth: [30],
  2345. selectedBackColor: '#fffacd',
  2346. },
  2347. cellDoubleClick: stdLibCellDoubleClick,
  2348. page: 'ledger',
  2349. tid: getTenderId(),
  2350. };
  2351. // 展开收起标准清单
  2352. $('a', '#side-menu').bind('click', function (e) {
  2353. e.preventDefault();
  2354. const tab = $(this), tabPanel = $(tab.attr('content'));
  2355. // 展开工具栏、切换标签
  2356. if (!tab.hasClass('active')) {
  2357. // const close = $('.active', '#side-menu').length === 0;
  2358. $('a', '#side-menu').removeClass('active');
  2359. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  2360. tab.addClass('active');
  2361. tabPanel.addClass('active');
  2362. // $('.tab-content .tab-pane').removeClass('active');
  2363. showSideTools(tab.hasClass('active'));
  2364. if (tab.attr('content') === '#std-xmj') {
  2365. if (!stdXmj) {
  2366. stdXmj = $.stdLib(stdXmjSetting);
  2367. }
  2368. stdXmj.spread.refresh();
  2369. } else if (tab.attr('content') === '#std-gcl') {
  2370. if (!stdGcl) {
  2371. stdGcl = $.stdLib(stdGclSetting);
  2372. }
  2373. stdGcl.spread.refresh();
  2374. } else if (tab.attr('content') === '#deal-bills') {
  2375. if (!dealBills) {
  2376. dealBills = new DealBills('#deal-bills-spread', {
  2377. cols: [
  2378. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2379. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2380. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2381. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2382. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2383. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2384. ],
  2385. emptyRows: 3,
  2386. headRows: 1,
  2387. headRowHeight: [32],
  2388. defaultRowHeight: 21,
  2389. headerFont: '12px 微软雅黑',
  2390. font: '12px 微软雅黑',
  2391. headColWidth: [30],
  2392. selectedBackColor: '#fffacd',
  2393. readOnly: true,
  2394. });
  2395. dealBills.loadData();
  2396. }
  2397. dealBills.spread.refresh();
  2398. } else if (tab.attr('content') === '#search') {
  2399. if (!searchLedger) {
  2400. searchLedger = $.billsSearch({
  2401. selector: '#search',
  2402. searchSpread: ledgerSpread,
  2403. resultSpreadSetting: {
  2404. cols: [
  2405. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2406. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2407. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2408. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2409. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2410. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2411. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  2412. ],
  2413. emptyRows: 0,
  2414. headRows: 1,
  2415. headRowHeight: [32],
  2416. headColWidth: [30],
  2417. defaultRowHeight: 21,
  2418. headerFont: '12px 微软雅黑',
  2419. font: '12px 微软雅黑',
  2420. selectedBackColor: '#fffacd',
  2421. readOnly: true,
  2422. },
  2423. afterLocated: function () {
  2424. posOperationObj.loadCurPosData();
  2425. },
  2426. calcSum: function (result) {
  2427. const sum = { name: '合计' };
  2428. for (const r of result) {
  2429. sum.quantity = ZhCalc.add(r.quantity, sum.quantity);
  2430. }
  2431. return sum;
  2432. }
  2433. });
  2434. }
  2435. searchLedger.spread.refresh();
  2436. } else if (tab.attr('content') === '#bills-tag') {
  2437. // do something
  2438. } else if (tab.attr('content') === '#error-list') {
  2439. errorList.spread.refresh();
  2440. } else if (tab.attr('content') === '#check-list') {
  2441. checkList.spread.refresh();
  2442. } else if (tab.attr('content') === '#fujian') {
  2443. $('#showAttachment').hide();
  2444. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2445. getNodeList(node.id);
  2446. getAllList();
  2447. } else if (tab.attr('content') === '#gcl-gather') {
  2448. gclGather.spread.refresh();
  2449. }
  2450. } else { // 收起工具栏
  2451. tab.removeClass('active');
  2452. tabPanel.removeClass('active');
  2453. showSideTools(tab.hasClass('active'));
  2454. }
  2455. ledgerSpread.refresh();
  2456. if (posSpread) {
  2457. posSpread.refresh();
  2458. }
  2459. });
  2460. class DealBills {
  2461. constructor (selector, spreadSetting) {
  2462. const self = this;
  2463. this.obj = $(selector)[0];
  2464. this.url = '/tender/' + getTenderId() + '/deal';
  2465. this.spreadSetting = spreadSetting;
  2466. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2467. this.sheet = this.spread.getActiveSheet();
  2468. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2469. this.OprObj = {
  2470. /**
  2471. * 删除按钮响应事件
  2472. * @param sheet
  2473. */
  2474. deletePress: function (sheet) {
  2475. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  2476. const sortData = sheet.zh_data;
  2477. const datas = [];
  2478. const sels = sheet.getSelections();
  2479. if (!sels || !sels[0]) return;
  2480. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  2481. let bDel = false;
  2482. const node = sortData[iRow];
  2483. if (node) {
  2484. const data = {id: node.id};
  2485. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  2486. const colSetting = sheet.zh_setting.cols[iCol];
  2487. if (colSetting.field === 'code') {
  2488. toastr.error('清单编号不能为空,如需删除签约清单请使用右键删除');
  2489. return;
  2490. }
  2491. const style = sheet.getStyle(iRow, iCol);
  2492. if (!style.locked) {
  2493. const colSetting = sheet.zh_setting.cols[iCol];
  2494. data[colSetting.field] = null;
  2495. bDel = true;
  2496. }
  2497. }
  2498. if (bDel) {
  2499. datas.push(data);
  2500. }
  2501. }
  2502. }
  2503. if (datas.length > 0) {
  2504. postData(self.url + '/update', {update: datas}, function (result) {
  2505. self.loadUpdateData(result);
  2506. SpreadJsObj.reLoadSheetData(sheet);
  2507. }, function () {
  2508. SpreadJsObj.reLoadSheetData(sheet);
  2509. });
  2510. }
  2511. },
  2512. delete: function (sheet) {
  2513. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  2514. const sortData = sheet.zh_data;
  2515. const datas = [];
  2516. const sels = sheet.getSelections();
  2517. if (!sels || !sels[0]) return;
  2518. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  2519. const node = sortData[iRow];
  2520. datas.push(node.id);
  2521. }
  2522. if (datas.length > 0) {
  2523. postData(self.url + '/update', {del: datas}, function (result) {
  2524. self.loadUpdateData(result);
  2525. SpreadJsObj.reLoadSheetData(sheet);
  2526. }, function () {
  2527. SpreadJsObj.reLoadSheetData(sheet);
  2528. });
  2529. }
  2530. },
  2531. editEnded: function (e, info) {
  2532. if (!info.sheet.zh_setting || !info.sheet.zh_data || info.sheet.zh_setting.readOnly) return;
  2533. const node = info.sheet.zh_data[info.row];
  2534. const col = info.sheet.zh_setting.cols[info.col];
  2535. const data = {};
  2536. if (node) {
  2537. data.update = {};
  2538. data.update.id = node.id;
  2539. const oldValue = node ? node[col.field] : null;
  2540. const newValue = trimInvalidChar(info.editingText);
  2541. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  2542. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2543. return;
  2544. }
  2545. data.update[col.field] = newValue;
  2546. } else {
  2547. if (col.field !== 'code') {
  2548. toastr.warning('新增签约清单,请先输入清单编号');
  2549. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2550. return;
  2551. }
  2552. data.add = {};
  2553. data.add.order = info.row + 1;
  2554. data.add.code = trimInvalidChar(info.editingText);
  2555. }
  2556. postData(self.url + '/update', data, function (result) {
  2557. self.loadUpdateData(result);
  2558. SpreadJsObj.reLoadSheetData(info.sheet);
  2559. }, function () {
  2560. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2561. });
  2562. },
  2563. clipboardPasting(e, info) {
  2564. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  2565. info.cancel = true;
  2566. if (!setting || !sortData || setting.readOnly) return;
  2567. const pasteData = info.pasteData.html
  2568. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  2569. : (info.pasteData.text === ''
  2570. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  2571. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  2572. const hint = {
  2573. code: {type: 'warning', msg: '签约清单编号不可为空,已过滤'},
  2574. unit_price: {type: 'warning', msg: '输入的 单价 非法,已过滤'},
  2575. quantity: {type: 'warning', msg: '输入的 数量 非法,已过滤'},
  2576. };
  2577. const uDatas = [], iDatas = [];
  2578. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2579. const curRow = info.cellRange.row + iRow;
  2580. const node = sortData[curRow];
  2581. let bPaste = false;
  2582. const data = {};
  2583. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2584. const curCol = info.cellRange.col + iCol;
  2585. const colSetting = setting.cols[curCol];
  2586. const value = trimInvalidChar(pasteData[iRow][iCol]);
  2587. if (colSetting.field === 'code' && (!value || value === '')) {
  2588. toastMessageUniq(hint.code);
  2589. break;
  2590. }
  2591. if (colSetting.type === 'Number') {
  2592. const num = _.toNumber(value);
  2593. if (num) {
  2594. data[colSetting.field] = num;
  2595. bPaste = true;
  2596. } else if (colSetting.field === 'unit_price') {
  2597. toastMessageUniq(hint.unit_price);
  2598. } else if (colSetting.field === 'quantity') {
  2599. toastMessageUniq(hint.quantity);
  2600. }
  2601. } else {
  2602. data[colSetting.field] = value;
  2603. bPaste = true;
  2604. }
  2605. }
  2606. if (bPaste) {
  2607. if (node) {
  2608. data.id = node.id;
  2609. uDatas.push(data);
  2610. } else {
  2611. data.order = curRow + 1;
  2612. iDatas.push(data);
  2613. }
  2614. }
  2615. }
  2616. const updateData = {};
  2617. if (uDatas.length > 0) updateData.update = uDatas;
  2618. if (iDatas.length > 0) updateData.add = iDatas;
  2619. if (uDatas.length > 0 || iDatas.length > 0) {
  2620. postData(self.url + '/update', updateData, function (result) {
  2621. self.loadUpdateData(result);
  2622. SpreadJsObj.reLoadSheetData(info.sheet);
  2623. });
  2624. } else {
  2625. SpreadJsObj.reLoadSheetData(info.sheet);
  2626. }
  2627. },
  2628. };
  2629. if (!readOnly) {
  2630. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2631. const dealSheet = info.sheet;
  2632. if (!dealSheet.zh_setting.readOnly) return;
  2633. const mainSheet = ledgerSpread.getActiveSheet();
  2634. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2635. if (!dealBills) { return; }
  2636. const mainTree = mainSheet.zh_tree;
  2637. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2638. if (!mainNode || !mainTree) { return; }
  2639. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2640. toastr.error('非最底层项目下,不应添加清单');
  2641. return;
  2642. }
  2643. postData(window.location.pathname + '/update', {
  2644. postType: 'add-deal',
  2645. postData: {
  2646. id: mainNode.ledger_id,
  2647. type: mainNode.code ? 'child' : 'next',
  2648. dealBills: {
  2649. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2650. unit_price: dealBills.unit_price,
  2651. }
  2652. },
  2653. }, function (result) {
  2654. const refreshData = mainTree.loadPostData(result);
  2655. treeOperationObj.refreshTree(mainSheet, refreshData);
  2656. const sel = mainSheet.getSelections()[0];
  2657. mainSheet.setSelection(refreshData.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2658. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshData.create[0].index]);
  2659. treeOperationObj.refreshOperationValid(mainSheet);
  2660. ledgerSpread.focus();
  2661. posOperationObj.loadCurPosData();
  2662. });
  2663. });
  2664. }
  2665. const dealBillsPermission = $('[href="#upload-deal"]').length > 0;
  2666. if (!readOnly || dealBillsPermission) {
  2667. this.spread.bind(spreadNS.Events.EditEnded, this.OprObj.editEnded);
  2668. this.spread.bind(spreadNS.Events.ClipboardPasting, this.OprObj.clipboardPasting);
  2669. SpreadJsObj.addDeleteBind(this.spread, this.OprObj.deletePress);
  2670. $.contextMenu({
  2671. selector: selector,
  2672. build: function ($trigger, e) {
  2673. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  2674. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2675. },
  2676. items: {
  2677. edit: {
  2678. name: '进入编辑模式',
  2679. icon: 'fa-edit',
  2680. visible: function (key, opt) {
  2681. return self.sheet.zh_setting.readOnly;
  2682. },
  2683. callback: function (key, opt) {
  2684. self.sheet.zh_setting.readOnly = false;
  2685. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  2686. },
  2687. },
  2688. read: {
  2689. name: '退出编辑模式',
  2690. icon: 'fa-sign-out',
  2691. visible: function (key, opt) {
  2692. return !self.sheet.zh_setting.readOnly;
  2693. },
  2694. callback: function (key, opt) {
  2695. self.sheet.zh_setting.readOnly = true;
  2696. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  2697. },
  2698. },
  2699. del: {
  2700. name: '删除',
  2701. icon: 'fa-times',
  2702. visible: function (key, opt) {
  2703. return !self.sheet.zh_setting.readOnly;
  2704. },
  2705. disabled: function (key, opt) {
  2706. const select = SpreadJsObj.getSelectObject(self.sheet);
  2707. return !select;
  2708. },
  2709. callback: function (key, opt) {
  2710. self.OprObj.delete(self.sheet);
  2711. },
  2712. },
  2713. sprEdit: '----',
  2714. apply: {
  2715. name: '应用全部清单单价至台账',
  2716. icon: 'fa-magic',
  2717. disabled: function (key, opt) {
  2718. const sheet = self.spread.getActiveSheet();
  2719. return sheet.getRowCount() === 0 || readOnly;
  2720. },
  2721. callback: function (key, opt) {
  2722. const datas = [], sourceData = self.spread.getActiveSheet().zh_data;
  2723. for (const db of sourceData) {
  2724. const targets = ledgerTree.nodes.filter(function (x) {
  2725. return x.b_code === db.code && x.name === db.name && x.unit === db.unit;
  2726. });
  2727. for (const t of targets) {
  2728. if (t.children && t.children.length > 0) continue;
  2729. const data = ledgerTree.getNodeKeyData(t);
  2730. data.unit_price = db.unit_price;
  2731. datas.push(data);
  2732. }
  2733. }
  2734. if (datas.length > 0) {
  2735. doAfterHint({
  2736. fun: function() {
  2737. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  2738. const refreshNode = ledgerTree.loadPostData(result);
  2739. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  2740. });
  2741. },
  2742. hint: '此操作会替换台账里所有同编号、名称、单位的清单,请谨慎操作',
  2743. });
  2744. } else {
  2745. toastr.warning('没有可应用的清单。');
  2746. }
  2747. },
  2748. }
  2749. }
  2750. });
  2751. }
  2752. $('#upload-deal-bills').click(function () {
  2753. const file = $('#deal-bills-file')[0];
  2754. const formData = new FormData();
  2755. formData.append('file', file.files[0]);
  2756. postDataWithFile(self.url+'/upload-excel', formData, function (data) {
  2757. self.data = data;
  2758. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2759. $('#upload-deal').modal('hide');
  2760. }, function () {
  2761. $('#upload-deal').modal('hide');
  2762. });
  2763. });
  2764. this.initDealBillsSearch();
  2765. }
  2766. search(keyword) {
  2767. this.searchResult = [];
  2768. this.searchCur = 0;
  2769. if (keyword) {
  2770. for (const [i, d] of this.data.entries()) {
  2771. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  2772. }
  2773. }
  2774. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  2775. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.sheet, this.searchResult[0]);
  2776. }
  2777. searchPre() {
  2778. this.searchCur = this.searchCur - 1;
  2779. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  2780. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  2781. }
  2782. searchNext() {
  2783. this.searchCur = this.searchCur + 1;
  2784. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  2785. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  2786. }
  2787. searchClear() {
  2788. $('#dbs-keyword').val('');
  2789. this.searchResult = [];
  2790. this.searchCur = 0;
  2791. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  2792. }
  2793. initDealBillsSearch() {
  2794. const self = this;
  2795. $('#dbs-keyword').change(function () { self.search(this.value); });
  2796. $('#dbs-pre').click(function (e) {
  2797. self.searchPre();
  2798. e.stopPropagation();
  2799. });
  2800. $('#dbs-next').click(function (e) {
  2801. self.searchNext();
  2802. e.stopPropagation();
  2803. });
  2804. $('#dbs-clear').click(function (e) {
  2805. self.searchClear();
  2806. e.stopPropagation();
  2807. });
  2808. }
  2809. loadData () {
  2810. const self = this;
  2811. postData(this.url+'/get-data', {}, function (data) {
  2812. self.data = data;
  2813. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2814. if (data.length > 0) self.spread.getActiveSheet().setSelection(0, 0, 1, 1);
  2815. });
  2816. }
  2817. calculateData () {
  2818. if (this.data) {
  2819. for (const d of this.data) {
  2820. d.total_price = _.multiply(d.quantity, d.unit_price);
  2821. }
  2822. }
  2823. }
  2824. loadUpdateData(updateData) {
  2825. if (updateData.add) {
  2826. for (const a of updateData.add) {
  2827. this.data.push(a);
  2828. }
  2829. }
  2830. if (updateData.update) {
  2831. for (const u of updateData.update) {
  2832. const d = this.data.find(function (x) {
  2833. return u.id === x.id;
  2834. });
  2835. if (d) {
  2836. _.assign(d, u);
  2837. } else {
  2838. this.data.push(d);
  2839. }
  2840. }
  2841. }
  2842. if (updateData.del) {
  2843. _.remove(this.data, function (d) {
  2844. return updateData.del.indexOf(d.id) >= 0;
  2845. });
  2846. }
  2847. }
  2848. }
  2849. class BatchInsertBillsPosObj {
  2850. constructor (obj) {
  2851. const self = this;
  2852. this.obj = obj;
  2853. this.billsCount = 6;
  2854. this.posCount = 1000;
  2855. this.filter = getLocalCache('zh-calc-batch-filter');
  2856. if (!this.filter) {
  2857. this.filter = '1';
  2858. }
  2859. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2860. // 初始化 清单编号窗口 参数
  2861. this.qdSpreadSetting = {
  2862. cols: [
  2863. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2864. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2865. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2866. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2867. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2868. ],
  2869. emptyRows: this.billsCount,
  2870. headRows: 1,
  2871. headRowHeight: [32],
  2872. headerFont: '12px 微软雅黑',
  2873. font: '12px 微软雅黑',
  2874. };
  2875. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2876. // 初始化 部位数量复核表 参数
  2877. this.posSpreadSetting = {
  2878. cols: [
  2879. {title: '计量单元', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2880. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2881. ],
  2882. emptyRows: this.posCount,
  2883. headRows: 1,
  2884. headRowHeight: [32],
  2885. headerFont: '12px 微软雅黑',
  2886. font: '12px 微软雅黑',
  2887. };
  2888. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2889. this.posSpreadSetting.cols.push(
  2890. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2891. )
  2892. }
  2893. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2894. // 初始化 签约清单 参数
  2895. this.dealSpreadSetting = {
  2896. cols: [
  2897. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2898. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2899. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2900. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2901. ],
  2902. emptyRows: 0,
  2903. headRows: 1,
  2904. headRowHeight: [32],
  2905. headerFont: '12px 微软雅黑',
  2906. font: '12px 微软雅黑',
  2907. };
  2908. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2909. this.dealSheet = this.dealSpread.getActiveSheet();
  2910. // 初始化 清单编号、部位数量复核表 表格
  2911. this.initView();
  2912. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2913. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2914. $.contextMenu({
  2915. selector: '.batch-l-t',
  2916. build: function ($trigger, e) {
  2917. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2918. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2919. },
  2920. items: {
  2921. 'create': {
  2922. name: '新增行',
  2923. icon: 'fa-sign-in',
  2924. callback: function (key, opt) {
  2925. const qdSheet = self.qdSpread.getActiveSheet();
  2926. const posSheet = self.posSpread.getActiveSheet();
  2927. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2928. const index = qdSheet.getRowCount();
  2929. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2930. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2931. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2932. },
  2933. },
  2934. 'delete': {
  2935. name: '删除行',
  2936. icon: 'fa-remove',
  2937. callback: function (key, opt) {
  2938. const qdSheet = self.qdSpread.getActiveSheet();
  2939. const posSheet = self.posSpread.getActiveSheet();
  2940. const sel = qdSheet.getSelections()[0];
  2941. qdSheet.deleteRows(sel.row, sel.rowCount);
  2942. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2943. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2944. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2945. }
  2946. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2947. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2948. }
  2949. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2950. },
  2951. }
  2952. }
  2953. });
  2954. // 拉取签约清单数据
  2955. if (dealBills) {
  2956. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2957. } else {
  2958. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  2959. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  2960. });
  2961. }
  2962. // 双击签约清单,自动添加到清单编号窗口
  2963. this.dealSpread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2964. const deal = info.sheet.zh_data[info.row];
  2965. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2966. const sel = qdSheet.getSelections()[0];
  2967. qdSheet.getCell(sel.row, 0).value(deal.code);
  2968. qdSheet.getCell(sel.row, 1).value(deal.name);
  2969. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2970. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2971. if (sel.row + 1 === qdSheet.getRowCount()) {
  2972. const count = sel.row + 2;
  2973. qdSheet.setRowCount(count);
  2974. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2975. const colCount = posSheet.getColumnCount() + 1
  2976. posSheet.setColumnCount(colCount);
  2977. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2978. }
  2979. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2980. });
  2981. this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
  2982. info.cancel = true;
  2983. const transpose = $('[name=batch-transpose]')[0].checked;
  2984. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
  2985. const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
  2986. const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
  2987. SpreadJsObj.beginMassOperation(billsSheet);
  2988. if (finalCount > billsCount) {
  2989. billsSheet.setRowCount(finalCount);
  2990. posSheet.setColumnCount(finalCount + 2);
  2991. for (let i = billsCount - 1; i <= finalCount; i++) {
  2992. billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2993. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2994. }
  2995. }
  2996. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  2997. const curRow = iRow + info.cellRange.row;
  2998. pasteData[iRow].forEach((value, iCol) => {
  2999. billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
  3000. });
  3001. if ([0, 1].indexOf(info.cellRange.col) >= 0) {
  3002. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3003. const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
  3004. if (bills) {
  3005. billsSheet.getCell(curRow, 1).value(bills.name);
  3006. billsSheet.getCell(curRow, 2).value(bills.unit);
  3007. billsSheet.getCell(curRow, 3).value(bills.unit_price);
  3008. }
  3009. }
  3010. }
  3011. SpreadJsObj.endMassOperation(billsSheet);
  3012. });
  3013. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3014. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3015. const count = qdSheet.getRowCount();
  3016. if (billsCount > count) {
  3017. qdSheet.setRowCount(billsCount);
  3018. for (let i = count + 1; i <= billsCount; i++) {
  3019. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3020. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3021. }
  3022. }
  3023. });
  3024. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3025. if (info.col === 0) {
  3026. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3027. if (dealBills && dealBills.length > 0) {
  3028. const bills = _.find(dealBills, {code: info.editingText});
  3029. if (bills) {
  3030. info.sheet.getCell(info.row, 1).value(bills.name);
  3031. info.sheet.getCell(info.row, 2).value(bills.unit);
  3032. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3033. }
  3034. }
  3035. }
  3036. });
  3037. this.obj.bind('shown.bs.modal', function () {
  3038. self.qdSpread.refresh();
  3039. self.posSpread.refresh();
  3040. self.dealSpread.refresh();
  3041. });
  3042. $('#batch-ok').click(function () {
  3043. const sheet = ledgerSpread.getActiveSheet();
  3044. const sel = sheet.getSelections()[0];
  3045. const row = sel.row;
  3046. const select = ledgerTree.nodes[row];
  3047. if (select) {
  3048. const insertData = {};
  3049. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3050. insertData.id = ledgerTree.getNodeKey(select);
  3051. insertData.batchData = self.getBatchData();
  3052. if (insertData.batchData.length > 0) {
  3053. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  3054. pos.updateDatas(data.pos);
  3055. const result = ledgerTree.loadPostData(data.ledger);
  3056. treeOperationObj.refreshTree(sheet, result);
  3057. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3058. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  3059. treeOperationObj.refreshOperationValid(sheet);
  3060. posOperationObj.loadCurPosData();
  3061. self.obj.modal('hide');
  3062. }, null, true);
  3063. } else {
  3064. self.obj.modal('hide');
  3065. }
  3066. }
  3067. });
  3068. $('input[name=batch-filter]').change(function () {
  3069. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3070. });
  3071. this.initDealBillsSearch();
  3072. }
  3073. search(keyword) {
  3074. this.searchResult = [];
  3075. this.searchCur = 0;
  3076. if (keyword) {
  3077. for (const [i, d] of this.dealSheet.zh_data.entries()) {
  3078. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3079. }
  3080. }
  3081. $('#batch-dbs-count').html(`结果:${this.searchResult.length}`);
  3082. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.dealSheet, this.searchResult[0]);
  3083. }
  3084. searchPre() {
  3085. this.searchCur = this.searchCur - 1;
  3086. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3087. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3088. }
  3089. searchNext() {
  3090. this.searchCur = this.searchCur + 1;
  3091. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3092. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3093. }
  3094. initDealBillsSearch() {
  3095. const self = this;
  3096. $('#batch-dbs-keyword').change(function () { self.search(this.value); });
  3097. $('#batch-dbs-pre').click(function (e) {
  3098. self.searchPre();
  3099. e.stopPropagation();
  3100. });
  3101. $('#batch-dbs-next').click(function (e) {
  3102. self.searchNext();
  3103. e.stopPropagation();
  3104. });
  3105. }
  3106. // 初始化左侧表格
  3107. initView () {
  3108. // 初始化 清单编号
  3109. const qdSheet = this.qdSpread.getActiveSheet();
  3110. qdSheet.setColumnWidth(0, 45, spreadNS.SheetArea.rowHeader);
  3111. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3112. SpreadJsObj.refreshColumnAlign(qdSheet);
  3113. // 清理原有数据
  3114. SpreadJsObj.beginMassOperation(qdSheet);
  3115. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3116. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3117. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3118. }
  3119. qdSheet.setSelection(0, 0, 1 ,1);
  3120. SpreadJsObj.endMassOperation(qdSheet);
  3121. // 初始化 部位数量复核表
  3122. const posSheet = this.posSpread.getActiveSheet();
  3123. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3124. SpreadJsObj.refreshColumnAlign(posSheet);
  3125. // 清理原有数据
  3126. SpreadJsObj.beginMassOperation(posSheet);
  3127. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3128. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3129. posSheet.setSelection(0, 0, 1 ,1);
  3130. SpreadJsObj.endMassOperation(posSheet);
  3131. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3132. }
  3133. // 获取界面数据
  3134. getBatchData () {
  3135. const result = [];
  3136. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3137. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3138. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3139. const qd = {
  3140. b_code: qdSheet.getText(iRow, 0),
  3141. name: qdSheet.getText(iRow, 1),
  3142. unit: qdSheet.getText(iRow, 2),
  3143. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3144. pos: [],
  3145. };
  3146. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3147. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3148. if (value !== 0 && !isNaN(value)) {
  3149. qd.pos.push({
  3150. name: posSheet.getText(iPosRow, 0),
  3151. drawing_code: posSheet.getText(iPosRow, 1),
  3152. quantity: value, porder: qd.pos.length + 1,
  3153. });
  3154. }
  3155. }
  3156. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3157. }
  3158. return result;
  3159. }
  3160. }
  3161. // $('#searchAccount').click(() => {
  3162. // const data = {
  3163. // keyword: $('#searchName').val(),
  3164. // };
  3165. // postData('/search/user', data, (data) => {
  3166. // const resultDiv = $('#searchResult');
  3167. // if (data) {
  3168. // $('h5>span', resultDiv).text(data.name);
  3169. // $('#addAuditor').attr('auditorId', data.id);
  3170. // $('h6', resultDiv).text(data.role);
  3171. // $('p', resultDiv).text(data.company);
  3172. // resultDiv.show();
  3173. // } else {
  3174. // toastr.info('未查询到该审核人');
  3175. // resultDiv.hide();
  3176. // }
  3177. // }, () => {
  3178. // $('#searchResult').hide();
  3179. // });
  3180. // });
  3181. // // 审批人分组选择
  3182. // $('#account_group').change(function () {
  3183. // let account_html = '<option value="0">选择审批人</option>';
  3184. // for (const account of accountList) {
  3185. // if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  3186. // const role = account.role !== '' ? '(' + account.role + ')' : '';
  3187. // const company = account.company !== '' ? ' -' + account.company : '';
  3188. // account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  3189. // }
  3190. // }
  3191. // $('#account_list').html(account_html);
  3192. // });
  3193. let timer = null;
  3194. let oldSearchVal = null;
  3195. $('#gr-search').bind('input propertychange', function(e) {
  3196. oldSearchVal = e.target.value
  3197. timer && clearTimeout(timer)
  3198. timer = setTimeout(() => {
  3199. const newVal = $('#gr-search').val()
  3200. let html = ''
  3201. if (newVal && newVal === oldSearchVal) {
  3202. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  3203. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3204. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3205. class="ml-auto">${item.mobile || ''}</span></p>
  3206. <span class="text-muted">${item.role || ''}</span>
  3207. </dd>`
  3208. })
  3209. $('.book-list').empty()
  3210. $('.book-list').append(html)
  3211. } else {
  3212. if (!$('.acc-btn').length) {
  3213. accountGroup.forEach((group, idx) => {
  3214. if (!group) return
  3215. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  3216. </a> ${group.groupName}</dt>
  3217. <div class="dd-content" data-toggleid="${idx}">`
  3218. group.groupList.forEach(item => {
  3219. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3220. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3221. class="ml-auto">${item.mobile || ''}</span></p>
  3222. <span class="text-muted">${item.role || ''}</span>
  3223. </dd>`
  3224. });
  3225. html += '</div>'
  3226. })
  3227. $('.book-list').empty()
  3228. $('.book-list').append(html)
  3229. }
  3230. }
  3231. }, 400);
  3232. });
  3233. // 添加审批流程按钮逻辑
  3234. $('.book-list').on('click', 'dt', function () {
  3235. const idx = $(this).find('.acc-btn').attr('data-groupid')
  3236. const type = $(this).find('.acc-btn').attr('data-type')
  3237. if (type === 'hide') {
  3238. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  3239. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  3240. $(this).find('.acc-btn').attr('data-type', 'show')
  3241. })
  3242. } else {
  3243. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  3244. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  3245. $(this).find('.acc-btn').attr('data-type', 'hide')
  3246. })
  3247. }
  3248. return false
  3249. });
  3250. // 添加到审批流程中
  3251. $('dl').on('click', 'dd', function () {
  3252. const auditorId = parseInt($(this).data('id'))
  3253. if (auditorId) {
  3254. postData('/tender/' + getTenderId() + '/ledger/audit/add', { auditorId }, (datas) => {
  3255. const html = [];
  3256. // 如果是重新上报,添加到重新上报列表中
  3257. const auditorshtml = [];
  3258. for (const [index,data] of datas.entries()) {
  3259. if (index !== 0) {
  3260. html.push('<li class="list-group-item" auditorId="' + data.audit_id + '">');
  3261. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  3262. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  3263. }
  3264. html.push('<span>');
  3265. html.push(data.audit_order + ' ');
  3266. html.push(data.name + ' ');
  3267. html.push('</span>');
  3268. html.push('<small class="text-muted">');
  3269. html.push(data.role);
  3270. html.push('</small></li>');
  3271. }
  3272. auditorshtml.push('<li class="list-group-item" ' + (index !== 0 ? 'data-auditorid="' + data.audit_id + '"' : '') + '>');
  3273. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  3274. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  3275. if (index === 0) {
  3276. auditorshtml.push('<span class="pull-right">原报</span>');
  3277. } else if (index+1 === datas.length) {
  3278. auditorshtml.push('<span class="pull-right">终审</span>');
  3279. } else {
  3280. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  3281. }
  3282. auditorshtml.push('</li>');
  3283. }
  3284. $('#auditors').html(html.join(''));
  3285. $('#auditors-list').html(auditorshtml.join(''));
  3286. });
  3287. }
  3288. });
  3289. $('body').on('click', '#auditors li>a', function () {
  3290. const li = $(this).parent();
  3291. const data = {
  3292. auditorId: parseInt(li.attr('auditorId')),
  3293. };
  3294. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  3295. li.remove();
  3296. for (const a of data2) {
  3297. const aLi = $('li[auditorId=' + a.audit_id + ']');
  3298. $('span', aLi).text(a.audit_order + ' ' + a.name + ' ');
  3299. }
  3300. // 如果是重新上报
  3301. // 令最后一个图标转换
  3302. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  3303. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  3304. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  3305. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  3306. }
  3307. // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  3308. // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  3309. // $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  3310. // .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  3311. // }
  3312. for (let i = 0; i < $('#auditors-list li').length; i++) {
  3313. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审')
  3314. // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审')
  3315. }
  3316. });
  3317. });
  3318. $('#hideSp').click(function () {
  3319. $('#sp-list').modal('hide');
  3320. });
  3321. // 多层modal关闭后的滚动bug修复
  3322. $('#sp-list').on('hidden.bs.modal', function (e) {
  3323. $(document.body).addClass('modal-open');
  3324. });
  3325. // 显示层次
  3326. (function (select, sheet) {
  3327. $(select).click(function () {
  3328. const tag = $(this).attr('tag');
  3329. const tree = sheet.zh_tree;
  3330. if (!tree) return;
  3331. setTimeout(() => {
  3332. showWaitingView();
  3333. switch (tag) {
  3334. case "1":
  3335. case "2":
  3336. case "3":
  3337. case "4":
  3338. case "5":
  3339. tree.expandByLevel(parseInt(tag));
  3340. SpreadJsObj.refreshTreeRowVisible(sheet);
  3341. break;
  3342. case "last":
  3343. tree.expandByCustom(() => { return true; });
  3344. SpreadJsObj.refreshTreeRowVisible(sheet);
  3345. break;
  3346. case "leafXmj":
  3347. tree.expandToLeafXmj();
  3348. SpreadJsObj.refreshTreeRowVisible(sheet);
  3349. break;
  3350. }
  3351. closeWaitingView();
  3352. }, 100);
  3353. });
  3354. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  3355. // $('#exportLedger').click(function () {
  3356. // const data = [];
  3357. // const setting = {
  3358. // header: ['项目节编号', '清单子目号', '部位明细', '名称', '单位', '清单数量', '设计数量1', '设计数量2', '单价', '合价', '图号', '备注'],
  3359. // width: [100, 70, 70, 300, 60, 80, 80, 80, 80, 80, 100, 100],
  3360. // hAlign: ['left', 'left', 'left', 'left','center', 'right', 'right', 'right', 'right', 'right', 'left', 'left'],
  3361. // };
  3362. // for (const node of ledgerTree.nodes) {
  3363. // data.push([node.code, node.b_code, '', node.name, node.unit,
  3364. // node.quantity, node.dgn_qty1, node.dgn_qty2, node.unit_price, node.total_price,
  3365. // node.drawing_code, node.memo
  3366. // ]);
  3367. // const posRange = pos.getLedgerPos(node.id);
  3368. // if (posRange && posRange.length > 0) {
  3369. // for (const [i, p] of posRange.entries()) {
  3370. // data.push(['', '', (i + 1) + '', p.name, '',
  3371. // p.quantity, '', '', '', '',
  3372. // p.drawing_code, p.memo
  3373. // ]);
  3374. // }
  3375. // }
  3376. // }
  3377. //
  3378. // XLSXObj.exportXlsxSheet(setting, data, "台账分解.xlsx");
  3379. // });
  3380. $('#exportLedger').click(function () {
  3381. const data = [];
  3382. const setting = {
  3383. cols: [
  3384. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  3385. {title: '清单子目号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3386. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'pos_code', hAlign: 1, width: 70, formatter: '@'},
  3387. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  3388. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  3389. {title: '签约数量', colSpan: '1', rowSpan: '1', field: 'deal_qty', hAlign: 2, width: 80, type: 'Number'},
  3390. {title: '签约金额', colSpan: '1', rowSpan: '1', field: 'deal_tp', hAlign: 2, width: 80, type: 'Number'},
  3391. {title: '清单数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  3392. {title: '设计数量1', colSpan: '1', rowSpan: '1', field: 'dgn_qty1', hAlign: 2, width: 80, type: 'Number'},
  3393. {title: '设计数量2', colSpan: '1', rowSpan: '1', field: 'dgn_qty2', hAlign: 2, width: 80, type: 'Number'},
  3394. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  3395. {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3396. {title: '图号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 100, formatter: '@'},
  3397. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 100, formatter: '@'},
  3398. ],
  3399. headRows: 1,
  3400. headRowHeight: [32],
  3401. defaultRowHeight: 21,
  3402. headerFont: 'bold 10px 微软雅黑',
  3403. font: '10px 微软雅黑'
  3404. };
  3405. const hasCl = ledgerSpreadSetting.cols.find(x => { return x.field === 'sjcl_qty'});
  3406. const qtyF = hasCl ? 'quantity' : 'sgfh_qty';
  3407. const tpF = hasCl ? 'total_price' : 'sgfh_tp';
  3408. for (const node of ledgerTree.nodes) {
  3409. data.push({
  3410. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3411. unit_price: node.unit_price, quantity: node[qtyF], total_price: node[tpF],
  3412. deal_qty: node.deal_qty, deal_tp: node.deal_tp,
  3413. dgn_qty1: node.dgn_qty1, dgn_qty2: node.dgn_qty2,
  3414. drawing_code: node.drawing_code, memo: node.memo
  3415. });
  3416. const posRange = pos.getLedgerPos(node.id);
  3417. if (posRange && posRange.length > 0) {
  3418. for (const [i, p] of posRange.entries()) {
  3419. data.push({
  3420. pos_code: (i + 1) + '', name: p.name,
  3421. quantity: p[qtyF], drawing_code: p.drawing_code, memo: p.memo
  3422. });
  3423. }
  3424. }
  3425. }
  3426. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, "台账分解.xlsx");
  3427. });
  3428. $('#sync-ledger').click(function () {
  3429. postData(syncLedgerUrl, {}, function (result) {
  3430. ledgerTree.loadDatas(result.bills);
  3431. treeCalc.calculateAll(ledgerTree);
  3432. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  3433. pos.loadDatas(result.pos);
  3434. posOperationObj.loadCurPosData();
  3435. checkShowLast(result.bills.length);
  3436. });
  3437. });
  3438. const dataChecker = DataChecker({
  3439. checkUrl: window.location.pathname + '/check',
  3440. completeData: function (data) {
  3441. pos.updateDatas({update: data.source.pos});
  3442. const loadResult = ledgerTree.loadPostData({update: data.source.bills});
  3443. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  3444. posOperationObj.loadCurPosData();
  3445. for (const e of data.error) {
  3446. e.serialNo = ledgerTree.getNodeIndex(ledgerTree.getItems(e.ledger_id)) + 1;
  3447. }
  3448. },
  3449. errorList: errorList,
  3450. });
  3451. $('[name=audit-start]').submit(function (e) {
  3452. if (checkAuditorFrom()) {
  3453. $(this).parent().parent().parent().modal('hide');
  3454. dataChecker.checkAndPost(this.action, {});
  3455. $('#hide-all').hide();
  3456. }
  3457. return false;
  3458. });
  3459. $('#ledger-check2').click(() => {
  3460. ledgerCheck2({
  3461. ledgerTree: ledgerTree,
  3462. ledgerPos: pos,
  3463. checkList: checkList,
  3464. decimal: tenderInfo.decimal,
  3465. checkOption: checkOption,
  3466. }).then(result => {
  3467. check2Viewing({
  3468. extra: ZhCalc.div(ledgerTree.datas.length + pos.datas.length, 10000, 0),
  3469. randomWait: true,
  3470. prefix: 'check2-',
  3471. checks: result,
  3472. checkList: checkList,
  3473. });
  3474. });
  3475. });
  3476. // 切换附件里节点和所有附件
  3477. $('#fujian .nav-link').on('click', function () {
  3478. const tabPanel = $(this).attr('fujian-content');
  3479. if (tabPanel !== 'syfujian') {
  3480. $('#showPage').hide();
  3481. $('#bach-download').prop('type', 'curr');
  3482. } else {
  3483. $('#showPage').show();
  3484. $('#bach-download').prop('type', 'all');
  3485. }
  3486. $('#showAttachment').hide();
  3487. });
  3488. // 上传附件
  3489. $('#upload-file-btn').click(function () {
  3490. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3491. // return toastr.error('当前操作没有权限!');
  3492. // }
  3493. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3494. if (!node) return;
  3495. const files = $('#upload-file')[0].files;
  3496. const formData = new FormData();
  3497. formData.append('lid', node.id);
  3498. for (const file of files) {
  3499. if (file === undefined) {
  3500. toastr.error('未选择上传文件!');
  3501. return false;
  3502. }
  3503. const filesize = file.size;
  3504. if (filesize > 30 * 1024 * 1024) {
  3505. toastr.error('存在上传文件大小过大!');
  3506. return false;
  3507. }
  3508. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3509. if (whiteList && !whiteList.includes(fileext)) {
  3510. toastr.error('只能上传指定格式的附件!');
  3511. return false;
  3512. }
  3513. formData.append('size', filesize);
  3514. formData.append('file[]', file);
  3515. }
  3516. postDataWithFile('/tender/' + tender.id + '/ledger/upload/file', formData, function (data) {
  3517. $('#upload').modal('hide');
  3518. // 插入到attData中
  3519. attData = data.concat(attData);
  3520. // 重新生成List
  3521. getAllList();
  3522. getNodeList(node.id);
  3523. }, function () {
  3524. toastr.error('附件上传失败');
  3525. });
  3526. $('#upload-file').val('');
  3527. });
  3528. // 获取附件信息
  3529. $('.list-table').on('click', '.att-file-name', function () {
  3530. const fid = $(this).attr('file-id');
  3531. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3532. return;
  3533. }
  3534. const att = attData.find(function (item) {
  3535. return item.id === parseInt(fid);
  3536. });
  3537. $('#edit-att').hide();
  3538. $('#show-att').show();
  3539. if (att !== undefined) {
  3540. // 进来先把编辑功能隐藏
  3541. $('#btn-att a').eq(3).hide()
  3542. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3543. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3544. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3545. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3546. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3547. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3548. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3549. $('#show-att tr').eq(3).children('td').text(att.remark);
  3550. // 附件uid等于当前用户id, 附件上传本人
  3551. if (parseInt(cur_uid) === att.uid) {
  3552. $('#btn-att').show();
  3553. const showDel = tender.ledger_status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3554. if (showDel) $('#btn-att a').eq(3).show();
  3555. // $('#btn-att a').eq(3).show();
  3556. $('#btn-att a').eq(2).hide();
  3557. $('#btn-att a').eq(4).hide();
  3558. $('#btn-att a').eq(5).hide();
  3559. } else {
  3560. $('#btn-att').hide();
  3561. $('#btn-att a').eq(3).hide();
  3562. $('#btn-att a').eq(2).hide();
  3563. $('#btn-att a').eq(4).hide();
  3564. $('#btn-att a').eq(5).hide();
  3565. }
  3566. $('#showAttachment').attr('file-id', fid);
  3567. $('#showAttachment').show();
  3568. } else {
  3569. $('#showAttachment').hide();
  3570. $('#showAttachment').attr('file-id', '');
  3571. toastr.error('附件信息获取失败');
  3572. }
  3573. });
  3574. // $('body').on('click', '.alllist-table a', handleFileList);
  3575. $('body').on('click', '#btn-att a', function () {
  3576. const content = $(this).attr('content');
  3577. const fid = $('#showAttachment').attr('file-id');
  3578. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3579. if (content === 'edit') {
  3580. $('#btn-att a').eq(3).hide();
  3581. $('#btn-att a').eq(2).show();
  3582. $('#btn-att a').eq(4).show();
  3583. $('#btn-att a').eq(5).show();
  3584. $('#show-att').hide();
  3585. $('#edit-att').show();
  3586. const att = attData.find(function (item) {
  3587. return item.id === parseInt(fid);
  3588. });
  3589. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3590. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3591. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3592. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3593. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3594. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3595. } else if (content === 'cancel') {
  3596. $('#show-att').show();
  3597. $('#edit-att').hide();
  3598. $('#btn-att a').eq(3).show();
  3599. $('#btn-att a').eq(2).hide();
  3600. $('#btn-att a').eq(4).hide();
  3601. $('#btn-att a').eq(5).hide();
  3602. } else if (content === 'save') {
  3603. const formData = new FormData();
  3604. formData.append('id', fid);
  3605. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3606. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3607. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3608. const file = $('#change-att-btn')[0];
  3609. if (file.files[0] !== undefined) {
  3610. const filesize = file.files[0].size;
  3611. formData.append('size', filesize);
  3612. formData.append('file', file.files[0]);
  3613. }
  3614. postDataWithFile('/tender/' + tender.id + '/ledger/save/file', formData, function (data) {
  3615. // 替换到attData中
  3616. const att_index = attData.findIndex(function (item) {
  3617. return item.id === parseInt(fid);
  3618. });
  3619. attData.splice(att_index, 1, data);
  3620. // 重新生成List
  3621. getAllList(parseInt($('#currentPage').text()));
  3622. getNodeList(node.id);
  3623. $('#show-att').show();
  3624. $('#edit-att').hide();
  3625. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3626. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3627. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3628. $('#show-att tr').eq(2).children('td').eq(0).text(data.username);
  3629. $('#show-att tr').eq(2).children('td').eq(1).text(data.in_time);
  3630. $('#show-att tr').eq(3).children('td').text(data.remark);
  3631. $('#btn-att a').eq(3).show();
  3632. $('#btn-att a').eq(2).hide();
  3633. $('#btn-att a').eq(4).hide();
  3634. $('#btn-att a').eq(5).hide();
  3635. }, function () {
  3636. toastr.error('附件上传失败');
  3637. });
  3638. $('#change-att-btn').val('');
  3639. } else if (content === 'del') {
  3640. const data = {id: fid};
  3641. postData('/tender/' + tender.id + '/ledger/delete/file', data, function (result) {
  3642. // 删除到attData中
  3643. const att_index = attData.findIndex(function (item) {
  3644. return item.id === parseInt(fid);
  3645. });
  3646. attData.splice(att_index, 1);
  3647. // 重新生成List
  3648. if ($('#alllist-table tr').length === 1) {
  3649. getAllList(parseInt($('#currentPage').text()) - 1);
  3650. } else {
  3651. getAllList(parseInt($('#currentPage').text()));
  3652. }
  3653. getNodeList(node.id);
  3654. $('#showAttachment').hide();
  3655. $('#showAttachment').attr('file-id', '');
  3656. });
  3657. } else if (content === 'view') {
  3658. const data = {id: fid};
  3659. postData('/tender/' + tender.id + '/ledger/check/file', data, function (result) {
  3660. const { filepath } = result
  3661. $('#load-file').attr('href', filepath);
  3662. $('#load-file')[0].click();
  3663. });
  3664. } else if (content === 'location') {
  3665. const att = attData.find(item => item.id === parseInt(fid));
  3666. if (Object.keys(att).length) {
  3667. SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), att.ledger_id, true);
  3668. posOperationObj.loadCurPosData();
  3669. }
  3670. }
  3671. });
  3672. // 替换附件
  3673. $('#change-att-btn').on('change', function () {
  3674. const file = $('#change-att-btn')[0].files[0];
  3675. const name = file.name;
  3676. const filename = name.substring(0, name.lastIndexOf("."));
  3677. const fileext = name.substr(name.indexOf("."));
  3678. const filesize = file.size;
  3679. if (filesize > 30 * 1024 * 1024) {
  3680. toastr.error('文件大小过大!');
  3681. $('#change-att-btn').val('');
  3682. return false;
  3683. }
  3684. if (whiteList && !whiteList.includes(fileext)) {
  3685. toastr.error('只能上传指定格式的附件!');
  3686. $('#change-att-btn').val('');
  3687. return false;
  3688. }
  3689. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3690. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3691. });
  3692. // 切换页数
  3693. $('.page-select').on('click', function () {
  3694. const totalPageNum = parseInt($('#totalPage').text());
  3695. const lastPageNum = parseInt($('#currentPage').text());
  3696. const status = $(this).attr('content');
  3697. if (status === 'pre' && lastPageNum > 1) {
  3698. getAllList(lastPageNum-1);
  3699. $('#showAttachment').hide();
  3700. $('#syfujian .check-all-file').prop('checked', false)
  3701. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3702. getAllList(lastPageNum+1);
  3703. $('#showAttachment').hide();
  3704. $('#syfujian .check-all-file').prop('checked', false)
  3705. }
  3706. });
  3707. // 批量下载
  3708. $('#bach-download').click(function() {
  3709. const fileIds = [];
  3710. const type = $(this).attr('type');
  3711. let node = ''
  3712. if (type === 'curr') {
  3713. node = '#nodelist-table .check-file:checked'
  3714. } else {
  3715. node = '#alllist-table .check-file:checked'
  3716. }
  3717. $(node).each(function() {
  3718. const fileId = $(this).attr('file-id');
  3719. fileId && fileIds.push(fileId);
  3720. });
  3721. if (fileIds.length) {
  3722. if (fileIds.length > 20) {
  3723. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  3724. }
  3725. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  3726. $(this).attr('disabled', "true")
  3727. const btn = $(this);
  3728. const fileArr = [];
  3729. for (const id of fileIds) {
  3730. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  3731. fileArr.push({
  3732. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  3733. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  3734. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  3735. });
  3736. }
  3737. const packageName = `${tender.name}-台账分解-附件.zip`;
  3738. try {
  3739. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  3740. } catch (e) {
  3741. btn.removeAttr('disabled');
  3742. toastr.clear();
  3743. toastr.error('批量下载失败');
  3744. }
  3745. // postCompressFile(`/tender/${tender.id}/ledger/compresse/file`, {fileIds}, function(result) {
  3746. // toastr.clear()
  3747. // toastr.success('压缩文件成功')
  3748. // btn.removeAttr('disabled')
  3749. // const href = window.URL.createObjectURL(result)
  3750. // $('#zipDown').attr('href', href);
  3751. // $('#zipDown').attr('download', `${tender.name}-台账分解-附件.zip`);
  3752. // $("#zipDown")[0].click();
  3753. // }, () => {
  3754. // btn.removeAttr('disabled')
  3755. // toastr.clear()
  3756. // toastr.error('批量下载失败')
  3757. // });
  3758. // const url = `/tender/${tender.id}/ledger/compresse/file?fileIds=${JSON.stringify(fileIds)}`;
  3759. }
  3760. });
  3761. // 监听附件check是否选中
  3762. $('.list-table').on('click', '.check-file', function() {
  3763. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3764. const childs = $(this).parents('.list-table').children().length;
  3765. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3766. if (checkedList.length === childs) {
  3767. checkBox.prop("checked", true);
  3768. } else {
  3769. checkBox.prop("checked", false);
  3770. }
  3771. });
  3772. $('.check-all-file').click(function() {
  3773. const isCheck = $(this).is(':checked');
  3774. $(this).parents('table').find('.list-table').each(function() {
  3775. $(this).find('input:checkbox').prop("checked", isCheck);
  3776. })
  3777. });
  3778. });
  3779. // 生成当前节点列表
  3780. function getNodeList(node) {
  3781. let html = '';
  3782. for(const att of attData) {
  3783. if (node === att.lid) {
  3784. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  3785. html += `<tr>
  3786. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  3787. <td>
  3788. <div class="d-flex">
  3789. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  3790. <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>
  3791. </div>
  3792. </td><td>${att.username}</td></tr>`
  3793. }
  3794. }
  3795. $('#nodelist-table').html(html);
  3796. $('#nodelist-table').on('click', 'tr', function() {
  3797. $('#nodelist-table tr').removeClass('bg-light')
  3798. $(this).addClass('bg-light')
  3799. })
  3800. }
  3801. // 生成所有附件列表
  3802. function getAllList(currPageNum = 1) {
  3803. // 每页最多几个附件
  3804. const pageCount = 20;
  3805. // 附件总数
  3806. const total = attData.length;
  3807. // 总页数
  3808. const pageNum = Math.ceil(total/pageCount);
  3809. $('#totalPage').text(pageNum);
  3810. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  3811. // 当前页附件内容
  3812. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  3813. currPageFileData = currPageAttData;
  3814. let html = '';
  3815. for(const att of currPageAttData) {
  3816. html += `<tr>
  3817. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  3818. <td>
  3819. <div class="d-flex">
  3820. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  3821. <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>
  3822. </div>
  3823. </td><td>${att.username}</td></tr>`
  3824. }
  3825. $('#alllist-table').html(html);
  3826. $('#alllist-table').on('click', 'tr', function() {
  3827. $('#alllist-table tr').removeClass('bg-light')
  3828. $(this).addClass('bg-light')
  3829. })
  3830. }
  3831. // 检查上报情况
  3832. function checkAuditorFrom () {
  3833. if ($('#auditors li').length === 0) {
  3834. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  3835. toastr.error('请联系管理员添加审批人');
  3836. } else {
  3837. toastr.error('请先选择审批人,再上报数据');
  3838. }
  3839. return false;
  3840. } else {
  3841. $('#hide-all').show();
  3842. return true;
  3843. }
  3844. }
  3845. // texterea换行
  3846. function auditCheck(i) {
  3847. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  3848. $('textarea[name="opinion"]').eq(i).val(opinion);
  3849. return true;
  3850. }