ledger.js 180 KB

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