ledger.js 179 KB

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