ledger.js 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904
  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: '/template/导入分项清单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. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  1649. }
  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. treeCalc.calculateAll(ledgerTree);
  2174. for (const t of data.tags) {
  2175. t.node = ledgerTree.datas.find(x => {return x.id === t.lid});
  2176. }
  2177. billsTag.loadDatas(data.tags);
  2178. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  2179. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  2180. checkShowLast(data.bills.length);
  2181. pos.loadDatas(data.pos);
  2182. posOperationObj.loadCurPosData();
  2183. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  2184. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2185. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  2186. checkList.loadHisCheckData();
  2187. }, null, true);
  2188. $.divResizer({
  2189. select: '#right-spr',
  2190. callback: function () {
  2191. ledgerSpread.refresh();
  2192. if (posSpread) {
  2193. posSpread.refresh();
  2194. }
  2195. if (stdXmj) {
  2196. stdXmj.spread.refresh();
  2197. }
  2198. if (stdGcl) {
  2199. stdGcl.spread.refresh();
  2200. }
  2201. if (dealBills) {
  2202. dealBills.spread.refresh();
  2203. }
  2204. if (searchLedger) {
  2205. searchLedger.spread.refresh();
  2206. }
  2207. if (errorList) {
  2208. errorList.spread.refresh();
  2209. }
  2210. if (checkList) {
  2211. checkList.spread.refresh();
  2212. }
  2213. if (gclGather) gclGather.spread.refresh();
  2214. }
  2215. });
  2216. const stdLibCellDoubleClick = function (e, info) {
  2217. const stdSheet = info.sheet;
  2218. const mainSheet = ledgerSpread.getActiveSheet();
  2219. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2220. const stdTree = stdSheet.zh_tree;
  2221. const stdNode = stdTree.nodes[info.row];
  2222. const mainTree = mainSheet.zh_tree;
  2223. const sel = mainSheet.getSelections()[0];
  2224. const mainNode = mainTree.nodes[sel.row];
  2225. if (!stdNode) { return; }
  2226. if (info.sheet.zh_setting.stdType === 'gcl') {
  2227. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2228. toastr.warning('非最底层项目下,不应添加清单');
  2229. return;
  2230. }
  2231. }
  2232. postData(window.location.pathname + '/update', {
  2233. postType: 'add-std',
  2234. postData: {
  2235. id: ledgerTree.getNodeKey(mainNode),
  2236. tender_id: mainNode.tender_id,
  2237. stdType: info.sheet.zh_setting.stdType,
  2238. stdLibId: stdNode.list_id,
  2239. stdNode: stdTree.getNodeKey(stdNode)
  2240. }
  2241. }, function (result) {
  2242. const refreshNode = mainTree.loadPostData(result);
  2243. treeOperationObj.refreshTree(mainSheet, refreshNode);
  2244. if (refreshNode.create && refreshNode.create.length > 0) {
  2245. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2246. const refreshRow = [sel.row, refreshNode.create[refreshNode.create.length - 1].index];
  2247. const curIndex = mainTree.nodes.indexOf(mainNode);
  2248. if (sel.row !== curIndex && curIndex >= 0) refreshRow.push(curIndex);
  2249. SpreadJsObj.reloadRowsBackColor(mainSheet, refreshRow);
  2250. } else {
  2251. const node = _.find(ledgerTree.nodes, {code: stdNode.code, name: stdNode.name});
  2252. if (node) {
  2253. mainSheet.setSelection(ledgerTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2254. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, ledgerTree.nodes.indexOf(node)]);
  2255. }
  2256. }
  2257. treeOperationObj.refreshOperationValid(mainSheet);
  2258. ledgerSpread.focus();
  2259. posOperationObj.loadCurPosData();
  2260. });
  2261. };
  2262. const stdXmjSetting = {
  2263. selector: '#std-xmj',
  2264. stdType: 'xmj',
  2265. libs: stdChapters,
  2266. treeSetting: {
  2267. id: 'chapter_id',
  2268. pid: 'pid',
  2269. order: 'order',
  2270. level: 'level',
  2271. rootId: -1,
  2272. keys: ['id', 'list_id', 'chapter_id'],
  2273. },
  2274. spreadSetting: {
  2275. cols: [
  2276. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2277. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2278. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2279. ],
  2280. treeCol: 0,
  2281. emptyRows: 0,
  2282. headRows: 1,
  2283. headRowHeight: [32],
  2284. defaultRowHeight: 21,
  2285. headerFont: '12px 微软雅黑',
  2286. font: '12px 微软雅黑',
  2287. headColWidth: [30],
  2288. selectedBackColor: '#fffacd',
  2289. },
  2290. cellDoubleClick: stdLibCellDoubleClick,
  2291. page: 'ledger',
  2292. tid: getTenderId(),
  2293. };
  2294. const stdGclSetting = {
  2295. selector: '#std-gcl',
  2296. stdType: 'gcl',
  2297. libs: stdBills,
  2298. treeSetting: {
  2299. id: 'bill_id',
  2300. pid: 'pid',
  2301. order: 'order',
  2302. level: 'level',
  2303. rootId: -1,
  2304. keys: ['id', 'list_id', 'bill_id']
  2305. },
  2306. spreadSetting: {
  2307. cols: [
  2308. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2309. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2310. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2311. ],
  2312. treeCol: 0,
  2313. emptyRows: 0,
  2314. headRows: 1,
  2315. headRowHeight: [32],
  2316. defaultRowHeight: 21,
  2317. headerFont: '12px 微软雅黑',
  2318. font: '12px 微软雅黑',
  2319. headColWidth: [30],
  2320. selectedBackColor: '#fffacd',
  2321. },
  2322. cellDoubleClick: stdLibCellDoubleClick,
  2323. page: 'ledger',
  2324. tid: getTenderId(),
  2325. };
  2326. // 展开收起标准清单
  2327. $('a', '#side-menu').bind('click', function (e) {
  2328. e.preventDefault();
  2329. const tab = $(this), tabPanel = $(tab.attr('content'));
  2330. // 展开工具栏、切换标签
  2331. if (!tab.hasClass('active')) {
  2332. // const close = $('.active', '#side-menu').length === 0;
  2333. $('a', '#side-menu').removeClass('active');
  2334. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  2335. tab.addClass('active');
  2336. tabPanel.addClass('active');
  2337. // $('.tab-content .tab-pane').removeClass('active');
  2338. showSideTools(tab.hasClass('active'));
  2339. if (tab.attr('content') === '#std-xmj') {
  2340. if (!stdXmj) {
  2341. stdXmj = $.stdLib(stdXmjSetting);
  2342. }
  2343. stdXmj.spread.refresh();
  2344. } else if (tab.attr('content') === '#std-gcl') {
  2345. if (!stdGcl) {
  2346. stdGcl = $.stdLib(stdGclSetting);
  2347. }
  2348. stdGcl.spread.refresh();
  2349. } else if (tab.attr('content') === '#deal-bills') {
  2350. if (!dealBills) {
  2351. dealBills = new DealBills('#deal-bills-spread', {
  2352. cols: [
  2353. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2354. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2355. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2356. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2357. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2358. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2359. ],
  2360. emptyRows: 3,
  2361. headRows: 1,
  2362. headRowHeight: [32],
  2363. defaultRowHeight: 21,
  2364. headerFont: '12px 微软雅黑',
  2365. font: '12px 微软雅黑',
  2366. headColWidth: [30],
  2367. selectedBackColor: '#fffacd',
  2368. readOnly: true,
  2369. });
  2370. dealBills.loadData();
  2371. }
  2372. dealBills.spread.refresh();
  2373. } else if (tab.attr('content') === '#search') {
  2374. if (!searchLedger) {
  2375. searchLedger = $.billsSearch({
  2376. selector: '#search',
  2377. searchSpread: ledgerSpread,
  2378. resultSpreadSetting: {
  2379. cols: [
  2380. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  2381. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2382. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  2383. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  2384. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2385. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2386. ],
  2387. emptyRows: 0,
  2388. headRows: 1,
  2389. headRowHeight: [32],
  2390. headColWidth: [30],
  2391. defaultRowHeight: 21,
  2392. headerFont: '12px 微软雅黑',
  2393. font: '12px 微软雅黑',
  2394. selectedBackColor: '#fffacd',
  2395. },
  2396. afterLocated: function () {
  2397. posOperationObj.loadCurPosData();
  2398. }
  2399. });
  2400. }
  2401. searchLedger.spread.refresh();
  2402. } else if (tab.attr('content') === '#bills-tag') {
  2403. // do something
  2404. } else if (tab.attr('content') === '#error-list') {
  2405. errorList.spread.refresh();
  2406. } else if (tab.attr('content') === '#check-list') {
  2407. checkList.spread.refresh();
  2408. } else if (tab.attr('content') === '#fujian') {
  2409. $('#showAttachment').hide();
  2410. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2411. getNodeList(node.id);
  2412. getAllList();
  2413. } else if (tab.attr('content') === '#gcl-gather') {
  2414. gclGather.spread.refresh();
  2415. }
  2416. } else { // 收起工具栏
  2417. tab.removeClass('active');
  2418. tabPanel.removeClass('active');
  2419. showSideTools(tab.hasClass('active'));
  2420. }
  2421. ledgerSpread.refresh();
  2422. if (posSpread) {
  2423. posSpread.refresh();
  2424. }
  2425. });
  2426. class DealBills {
  2427. constructor (selector, spreadSetting) {
  2428. const self = this;
  2429. this.obj = $(selector)[0];
  2430. this.url = '/tender/' + getTenderId() + '/deal';
  2431. this.spreadSetting = spreadSetting;
  2432. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2433. this.sheet = this.spread.getActiveSheet();
  2434. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2435. this.OprObj = {
  2436. /**
  2437. * 删除按钮响应事件
  2438. * @param sheet
  2439. */
  2440. deletePress: function (sheet) {
  2441. if (!sheet.zh_setting || readOnly || sheet.zh_setting.readOnly) return;
  2442. const sortData = sheet.zh_data;
  2443. const datas = [];
  2444. const sels = sheet.getSelections();
  2445. if (!sels || !sels[0]) return;
  2446. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  2447. let bDel = false;
  2448. const node = sortData[iRow];
  2449. if (node) {
  2450. const data = {id: node.id};
  2451. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  2452. const colSetting = sheet.zh_setting.cols[iCol];
  2453. if (colSetting.field === 'code') {
  2454. toastr.error('清单编号不能为空,如需删除签约清单请使用右键删除');
  2455. return;
  2456. }
  2457. const style = sheet.getStyle(iRow, iCol);
  2458. if (!style.locked) {
  2459. const colSetting = sheet.zh_setting.cols[iCol];
  2460. data[colSetting.field] = null;
  2461. bDel = true;
  2462. }
  2463. }
  2464. if (bDel) {
  2465. datas.push(data);
  2466. }
  2467. }
  2468. }
  2469. if (datas.length > 0) {
  2470. postData(self.url + '/update', {update: datas}, function (result) {
  2471. self.loadUpdateData(result);
  2472. SpreadJsObj.reLoadSheetData(sheet);
  2473. }, function () {
  2474. SpreadJsObj.reLoadSheetData(sheet);
  2475. });
  2476. }
  2477. },
  2478. delete: function (sheet) {
  2479. if (!sheet.zh_setting || readOnly || sheet.zh_setting.readOnly) return;
  2480. const sortData = sheet.zh_data;
  2481. const datas = [];
  2482. const sels = sheet.getSelections();
  2483. if (!sels || !sels[0]) return;
  2484. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  2485. const node = sortData[iRow];
  2486. datas.push(node.id);
  2487. }
  2488. if (datas.length > 0) {
  2489. postData(self.url + '/update', {del: datas}, function (result) {
  2490. self.loadUpdateData(result);
  2491. SpreadJsObj.reLoadSheetData(sheet);
  2492. }, function () {
  2493. SpreadJsObj.reLoadSheetData(sheet);
  2494. });
  2495. }
  2496. },
  2497. editEnded: function (e, info) {
  2498. if (!info.sheet.zh_setting || !info.sheet.zh_data || info.sheet.zh_setting.readOnly) return;
  2499. const node = info.sheet.zh_data[info.row];
  2500. const col = info.sheet.zh_setting.cols[info.col];
  2501. const data = {};
  2502. if (node) {
  2503. data.update = {};
  2504. data.update.id = node.id;
  2505. const oldValue = node ? node[col.field] : null;
  2506. const newValue = trimInvalidChar(info.editingText);
  2507. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  2508. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2509. return;
  2510. }
  2511. data.update[col.field] = newValue;
  2512. } else {
  2513. if (col.field !== 'code') {
  2514. toastr.warning('新增签约清单,请先输入清单编号');
  2515. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2516. return;
  2517. }
  2518. data.add = {};
  2519. data.add.order = info.row + 1;
  2520. data.add.code = trimInvalidChar(info.editingText);
  2521. }
  2522. postData(self.url + '/update', data, function (result) {
  2523. self.loadUpdateData(result);
  2524. SpreadJsObj.reLoadSheetData(info.sheet);
  2525. }, function () {
  2526. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2527. });
  2528. },
  2529. clipboardPasting(e, info) {
  2530. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  2531. info.cancel = true;
  2532. if (!setting || !sortData || setting.readOnly) return;
  2533. const pasteData = info.pasteData.html
  2534. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  2535. : (info.pasteData.text === ''
  2536. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  2537. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  2538. const hint = {
  2539. code: {type: 'warning', msg: '签约清单编号不可为空,已过滤'},
  2540. unit_price: {type: 'warning', msg: '输入的 单价 非法,已过滤'},
  2541. quantity: {type: 'warning', msg: '输入的 数量 非法,已过滤'},
  2542. };
  2543. const uDatas = [], iDatas = [];
  2544. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2545. const curRow = info.cellRange.row + iRow;
  2546. const node = sortData[curRow];
  2547. let bPaste = false;
  2548. const data = {};
  2549. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2550. const curCol = info.cellRange.col + iCol;
  2551. const colSetting = setting.cols[curCol];
  2552. const value = trimInvalidChar(pasteData[iRow][iCol]);
  2553. if (colSetting.field === 'code' && (!value || value === '')) {
  2554. toastMessageUniq(hint.code);
  2555. break;
  2556. }
  2557. if (colSetting.type === 'Number') {
  2558. const num = _.toNumber(value);
  2559. if (num) {
  2560. data[colSetting.field] = num;
  2561. bPaste = true;
  2562. } else if (colSetting.field === 'unit_price') {
  2563. toastMessageUniq(hint.unit_price);
  2564. } else if (colSetting.field === 'quantity') {
  2565. toastMessageUniq(hint.quantity);
  2566. }
  2567. } else {
  2568. data[colSetting.field] = value;
  2569. bPaste = true;
  2570. }
  2571. }
  2572. if (bPaste) {
  2573. if (node) {
  2574. data.id = node.id;
  2575. uDatas.push(data);
  2576. } else {
  2577. data.order = curRow + 1;
  2578. iDatas.push(data);
  2579. }
  2580. }
  2581. }
  2582. const updateData = {};
  2583. if (uDatas.length > 0) updateData.update = uDatas;
  2584. if (iDatas.length > 0) updateData.add = iDatas;
  2585. if (uDatas.length > 0 || iDatas.length > 0) {
  2586. postData(self.url + '/update', updateData, function (result) {
  2587. self.loadUpdateData(result);
  2588. SpreadJsObj.reLoadSheetData(info.sheet);
  2589. });
  2590. } else {
  2591. SpreadJsObj.reLoadSheetData(info.sheet);
  2592. }
  2593. },
  2594. };
  2595. if (!readOnly) {
  2596. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2597. const dealSheet = info.sheet;
  2598. if (!dealSheet.zh_setting.readOnly) return;
  2599. const mainSheet = ledgerSpread.getActiveSheet();
  2600. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2601. if (!dealBills) { return; }
  2602. const mainTree = mainSheet.zh_tree;
  2603. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2604. if (!mainNode || !mainTree) { return; }
  2605. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2606. toastr.error('非最底层项目下,不应添加清单');
  2607. return;
  2608. }
  2609. postData(window.location.pathname + '/update', {
  2610. postType: 'add-deal',
  2611. postData: {
  2612. id: mainNode.ledger_id,
  2613. type: mainNode.code ? 'child' : 'next',
  2614. dealBills: {
  2615. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2616. unit_price: dealBills.unit_price,
  2617. }
  2618. },
  2619. }, function (result) {
  2620. const refreshData = mainTree.loadPostData(result);
  2621. treeOperationObj.refreshTree(mainSheet, refreshData);
  2622. const sel = mainSheet.getSelections()[0];
  2623. mainSheet.setSelection(refreshData.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2624. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshData.create[0].index]);
  2625. treeOperationObj.refreshOperationValid(mainSheet);
  2626. ledgerSpread.focus();
  2627. posOperationObj.loadCurPosData();
  2628. });
  2629. });
  2630. this.spread.bind(spreadNS.Events.EditEnded, this.OprObj.editEnded);
  2631. this.spread.bind(spreadNS.Events.ClipboardPasting, this.OprObj.clipboardPasting);
  2632. SpreadJsObj.addDeleteBind(this.spread, this.OprObj.deletePress);
  2633. }
  2634. $('#upload-deal-bills').click(function () {
  2635. const file = $('#deal-bills-file')[0];
  2636. const formData = new FormData();
  2637. formData.append('file', file.files[0]);
  2638. postDataWithFile(self.url+'/upload-excel', formData, function (data) {
  2639. self.data = data;
  2640. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2641. $('#upload-deal').modal('hide');
  2642. }, function () {
  2643. $('#upload-deal').modal('hide');
  2644. });
  2645. });
  2646. if (!readOnly) {
  2647. $.contextMenu({
  2648. selector: selector,
  2649. build: function ($trigger, e) {
  2650. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  2651. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2652. },
  2653. items: {
  2654. edit: {
  2655. name: '进入编辑模式',
  2656. icon: 'fa-edit',
  2657. visible: function (key, opt) {
  2658. return self.sheet.zh_setting.readOnly;
  2659. },
  2660. callback: function (key, opt) {
  2661. self.sheet.zh_setting.readOnly = false;
  2662. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  2663. },
  2664. },
  2665. read: {
  2666. name: '退出编辑模式',
  2667. icon: 'fa-sign-out',
  2668. visible: function (key, opt) {
  2669. return !self.sheet.zh_setting.readOnly;
  2670. },
  2671. callback: function (key, opt) {
  2672. self.sheet.zh_setting.readOnly = true;
  2673. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  2674. },
  2675. },
  2676. del: {
  2677. name: '删除',
  2678. icon: 'fa-times',
  2679. visible: function (key, opt) {
  2680. return !self.sheet.zh_setting.readOnly;
  2681. },
  2682. disabled: function (key, opt) {
  2683. const select = SpreadJsObj.getSelectObject(self.sheet);
  2684. return !select;
  2685. },
  2686. callback: function (key, opt) {
  2687. self.OprObj.delete(self.sheet);
  2688. },
  2689. },
  2690. sprEdit: '----',
  2691. apply: {
  2692. name: '应用全部清单单价至台账',
  2693. icon: 'fa-magic',
  2694. disabled: function (key, opt) {
  2695. const sheet = self.spread.getActiveSheet();
  2696. return sheet.getRowCount() === 0;
  2697. },
  2698. callback: function (key, opt) {
  2699. const datas = [], sourceData = self.spread.getActiveSheet().zh_data;
  2700. for (const db of sourceData) {
  2701. const targets = ledgerTree.nodes.filter(function (x) {
  2702. return x.b_code === db.code && x.name === db.name && x.unit === db.unit;
  2703. });
  2704. for (const t of targets) {
  2705. if (t.children && t.children.length > 0) continue;
  2706. const data = ledgerTree.getNodeKeyData(t);
  2707. data.unit_price = db.unit_price;
  2708. datas.push(data);
  2709. }
  2710. }
  2711. if (datas.length > 0) {
  2712. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  2713. const refreshNode = ledgerTree.loadPostData(result);
  2714. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  2715. });
  2716. } else {
  2717. toastr.warning('没有可应用的清单。');
  2718. }
  2719. }
  2720. }
  2721. }
  2722. });
  2723. }
  2724. this.initDealBillsSearch();
  2725. }
  2726. search(keyword) {
  2727. this.searchResult = [];
  2728. this.searchCur = 0;
  2729. if (keyword) {
  2730. for (const [i, d] of this.data.entries()) {
  2731. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  2732. }
  2733. }
  2734. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  2735. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.sheet, this.searchResult[0]);
  2736. }
  2737. searchPre() {
  2738. this.searchCur = this.searchCur - 1;
  2739. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  2740. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  2741. }
  2742. searchNext() {
  2743. this.searchCur = this.searchCur + 1;
  2744. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  2745. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  2746. }
  2747. searchClear() {
  2748. $('#dbs-keyword').val('');
  2749. this.searchResult = [];
  2750. this.searchCur = 0;
  2751. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  2752. }
  2753. initDealBillsSearch() {
  2754. const self = this;
  2755. $('#dbs-keyword').change(function () { self.search(this.value); });
  2756. $('#dbs-pre').click(function (e) {
  2757. self.searchPre();
  2758. e.stopPropagation();
  2759. });
  2760. $('#dbs-next').click(function (e) {
  2761. self.searchNext();
  2762. e.stopPropagation();
  2763. });
  2764. $('#dbs-clear').click(function (e) {
  2765. self.searchClear();
  2766. e.stopPropagation();
  2767. });
  2768. }
  2769. loadData () {
  2770. const self = this;
  2771. postData(this.url+'/get-data', {}, function (data) {
  2772. self.data = data;
  2773. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2774. if (data.length > 0) self.spread.getActiveSheet().setSelection(0, 0, 1, 1);
  2775. });
  2776. }
  2777. calculateData () {
  2778. if (this.data) {
  2779. for (const d of this.data) {
  2780. d.total_price = _.multiply(d.quantity, d.unit_price);
  2781. }
  2782. }
  2783. }
  2784. loadUpdateData(updateData) {
  2785. if (updateData.add) {
  2786. for (const a of updateData.add) {
  2787. this.data.push(a);
  2788. }
  2789. }
  2790. if (updateData.update) {
  2791. for (const u of updateData.update) {
  2792. const d = this.data.find(function (x) {
  2793. return u.id === x.id;
  2794. });
  2795. if (d) {
  2796. _.assign(d, u);
  2797. } else {
  2798. this.data.push(d);
  2799. }
  2800. }
  2801. }
  2802. if (updateData.del) {
  2803. _.remove(this.data, function (d) {
  2804. return updateData.del.indexOf(d.id) >= 0;
  2805. });
  2806. }
  2807. }
  2808. }
  2809. class BatchInsertBillsPosObj {
  2810. constructor (obj) {
  2811. const self = this;
  2812. this.obj = obj;
  2813. this.billsCount = 6;
  2814. this.posCount = 1000;
  2815. this.filter = getLocalCache('zh-calc-batch-filter');
  2816. if (!this.filter) {
  2817. this.filter = '1';
  2818. }
  2819. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2820. // 初始化 清单编号窗口 参数
  2821. this.qdSpreadSetting = {
  2822. cols: [
  2823. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2824. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2825. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2826. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2827. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2828. ],
  2829. emptyRows: this.billsCount,
  2830. headRows: 1,
  2831. headRowHeight: [32],
  2832. headerFont: '12px 微软雅黑',
  2833. font: '12px 微软雅黑',
  2834. };
  2835. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2836. // 初始化 部位数量复核表 参数
  2837. this.posSpreadSetting = {
  2838. cols: [
  2839. {title: '计量单元', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2840. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2841. ],
  2842. emptyRows: this.posCount,
  2843. headRows: 1,
  2844. headRowHeight: [32],
  2845. headerFont: '12px 微软雅黑',
  2846. font: '12px 微软雅黑',
  2847. };
  2848. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2849. this.posSpreadSetting.cols.push(
  2850. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2851. )
  2852. }
  2853. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2854. // 初始化 签约清单 参数
  2855. this.dealSpreadSetting = {
  2856. cols: [
  2857. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2858. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2859. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2860. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2861. ],
  2862. emptyRows: 0,
  2863. headRows: 1,
  2864. headRowHeight: [32],
  2865. headerFont: '12px 微软雅黑',
  2866. font: '12px 微软雅黑',
  2867. };
  2868. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2869. this.dealSheet = this.dealSpread.getActiveSheet();
  2870. // 初始化 清单编号、部位数量复核表 表格
  2871. this.initView();
  2872. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2873. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2874. $.contextMenu({
  2875. selector: '.batch-l-t',
  2876. build: function ($trigger, e) {
  2877. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2878. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2879. },
  2880. items: {
  2881. 'create': {
  2882. name: '新增行',
  2883. icon: 'fa-sign-in',
  2884. callback: function (key, opt) {
  2885. const qdSheet = self.qdSpread.getActiveSheet();
  2886. const posSheet = self.posSpread.getActiveSheet();
  2887. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2888. const index = qdSheet.getRowCount();
  2889. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2890. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2891. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2892. },
  2893. },
  2894. 'delete': {
  2895. name: '删除行',
  2896. icon: 'fa-remove',
  2897. callback: function (key, opt) {
  2898. const qdSheet = self.qdSpread.getActiveSheet();
  2899. const posSheet = self.posSpread.getActiveSheet();
  2900. const sel = qdSheet.getSelections()[0];
  2901. qdSheet.deleteRows(sel.row, sel.rowCount);
  2902. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2903. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2904. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2905. }
  2906. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2907. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2908. }
  2909. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2910. },
  2911. }
  2912. }
  2913. });
  2914. // 拉取签约清单数据
  2915. if (dealBills) {
  2916. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2917. } else {
  2918. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  2919. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  2920. });
  2921. }
  2922. // 双击签约清单,自动添加到清单编号窗口
  2923. this.dealSpread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2924. const deal = info.sheet.zh_data[info.row];
  2925. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2926. const sel = qdSheet.getSelections()[0];
  2927. qdSheet.getCell(sel.row, 0).value(deal.code);
  2928. qdSheet.getCell(sel.row, 1).value(deal.name);
  2929. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2930. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2931. if (sel.row + 1 === qdSheet.getRowCount()) {
  2932. const count = sel.row + 2;
  2933. qdSheet.setRowCount(count);
  2934. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2935. const colCount = posSheet.getColumnCount() + 1
  2936. posSheet.setColumnCount(colCount);
  2937. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2938. }
  2939. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2940. });
  2941. this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
  2942. info.cancel = true;
  2943. const transpose = $('[name=batch-transpose]')[0].checked;
  2944. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
  2945. const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
  2946. const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
  2947. SpreadJsObj.beginMassOperation(billsSheet);
  2948. if (finalCount > billsCount) {
  2949. billsSheet.setRowCount(finalCount);
  2950. posSheet.setColumnCount(finalCount + 2);
  2951. for (let i = billsCount - 1; i <= finalCount; i++) {
  2952. billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2953. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2954. }
  2955. }
  2956. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  2957. const curRow = iRow + info.cellRange.row;
  2958. pasteData[iRow].forEach((value, iCol) => {
  2959. billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
  2960. });
  2961. if ([0, 1].indexOf(info.cellRange.col) >= 0) {
  2962. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2963. const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
  2964. if (bills) {
  2965. billsSheet.getCell(curRow, 1).value(bills.name);
  2966. billsSheet.getCell(curRow, 2).value(bills.unit);
  2967. billsSheet.getCell(curRow, 3).value(bills.unit_price);
  2968. }
  2969. }
  2970. }
  2971. SpreadJsObj.endMassOperation(billsSheet);
  2972. });
  2973. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2974. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2975. const count = qdSheet.getRowCount();
  2976. if (billsCount > count) {
  2977. qdSheet.setRowCount(billsCount);
  2978. for (let i = count + 1; i <= billsCount; i++) {
  2979. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2980. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2981. }
  2982. }
  2983. });
  2984. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2985. if (info.col === 0) {
  2986. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2987. if (dealBills && dealBills.length > 0) {
  2988. const bills = _.find(dealBills, {code: info.editingText});
  2989. if (bills) {
  2990. info.sheet.getCell(info.row, 1).value(bills.name);
  2991. info.sheet.getCell(info.row, 2).value(bills.unit);
  2992. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2993. }
  2994. }
  2995. }
  2996. });
  2997. this.obj.bind('shown.bs.modal', function () {
  2998. self.qdSpread.refresh();
  2999. self.posSpread.refresh();
  3000. self.dealSpread.refresh();
  3001. });
  3002. $('#batch-ok').click(function () {
  3003. const sheet = ledgerSpread.getActiveSheet();
  3004. const sel = sheet.getSelections()[0];
  3005. const row = sel.row;
  3006. const select = ledgerTree.nodes[row];
  3007. if (select) {
  3008. const insertData = {};
  3009. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3010. insertData.id = ledgerTree.getNodeKey(select);
  3011. insertData.batchData = self.getBatchData();
  3012. if (insertData.batchData.length > 0) {
  3013. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  3014. pos.updateDatas(data.pos);
  3015. const result = ledgerTree.loadPostData(data.ledger);
  3016. treeOperationObj.refreshTree(sheet, result);
  3017. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3018. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  3019. treeOperationObj.refreshOperationValid(sheet);
  3020. posOperationObj.loadCurPosData();
  3021. self.obj.modal('hide');
  3022. }, null, true);
  3023. } else {
  3024. self.obj.modal('hide');
  3025. }
  3026. }
  3027. });
  3028. $('input[name=batch-filter]').change(function () {
  3029. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3030. });
  3031. this.initDealBillsSearch();
  3032. }
  3033. search(keyword) {
  3034. this.searchResult = [];
  3035. this.searchCur = 0;
  3036. if (keyword) {
  3037. for (const [i, d] of this.dealSheet.zh_data.entries()) {
  3038. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3039. }
  3040. }
  3041. $('#batch-dbs-count').html(`结果:${this.searchResult.length}`);
  3042. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.dealSheet, this.searchResult[0]);
  3043. }
  3044. searchPre() {
  3045. this.searchCur = this.searchCur - 1;
  3046. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3047. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3048. }
  3049. searchNext() {
  3050. this.searchCur = this.searchCur + 1;
  3051. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3052. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3053. }
  3054. initDealBillsSearch() {
  3055. const self = this;
  3056. $('#batch-dbs-keyword').change(function () { self.search(this.value); });
  3057. $('#batch-dbs-pre').click(function (e) {
  3058. self.searchPre();
  3059. e.stopPropagation();
  3060. });
  3061. $('#batch-dbs-next').click(function (e) {
  3062. self.searchNext();
  3063. e.stopPropagation();
  3064. });
  3065. }
  3066. // 初始化左侧表格
  3067. initView () {
  3068. // 初始化 清单编号
  3069. const qdSheet = this.qdSpread.getActiveSheet();
  3070. qdSheet.setColumnWidth(0, 45, spreadNS.SheetArea.rowHeader);
  3071. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3072. SpreadJsObj.refreshColumnAlign(qdSheet);
  3073. // 清理原有数据
  3074. SpreadJsObj.beginMassOperation(qdSheet);
  3075. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3076. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3077. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3078. }
  3079. qdSheet.setSelection(0, 0, 1 ,1);
  3080. SpreadJsObj.endMassOperation(qdSheet);
  3081. // 初始化 部位数量复核表
  3082. const posSheet = this.posSpread.getActiveSheet();
  3083. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3084. SpreadJsObj.refreshColumnAlign(posSheet);
  3085. // 清理原有数据
  3086. SpreadJsObj.beginMassOperation(posSheet);
  3087. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3088. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3089. posSheet.setSelection(0, 0, 1 ,1);
  3090. SpreadJsObj.endMassOperation(posSheet);
  3091. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3092. }
  3093. // 获取界面数据
  3094. getBatchData () {
  3095. const result = [];
  3096. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3097. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3098. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3099. const qd = {
  3100. b_code: qdSheet.getText(iRow, 0),
  3101. name: qdSheet.getText(iRow, 1),
  3102. unit: qdSheet.getText(iRow, 2),
  3103. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3104. pos: [],
  3105. };
  3106. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3107. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3108. if (value !== 0 && !isNaN(value)) {
  3109. qd.pos.push({
  3110. name: posSheet.getText(iPosRow, 0),
  3111. drawing_code: posSheet.getText(iPosRow, 1),
  3112. quantity: value, porder: qd.pos.length + 1,
  3113. });
  3114. }
  3115. }
  3116. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3117. }
  3118. return result;
  3119. }
  3120. }
  3121. // $('#searchAccount').click(() => {
  3122. // const data = {
  3123. // keyword: $('#searchName').val(),
  3124. // };
  3125. // postData('/search/user', data, (data) => {
  3126. // const resultDiv = $('#searchResult');
  3127. // if (data) {
  3128. // $('h5>span', resultDiv).text(data.name);
  3129. // $('#addAuditor').attr('auditorId', data.id);
  3130. // $('h6', resultDiv).text(data.role);
  3131. // $('p', resultDiv).text(data.company);
  3132. // resultDiv.show();
  3133. // } else {
  3134. // toastr.info('未查询到该审核人');
  3135. // resultDiv.hide();
  3136. // }
  3137. // }, () => {
  3138. // $('#searchResult').hide();
  3139. // });
  3140. // });
  3141. // // 审批人分组选择
  3142. // $('#account_group').change(function () {
  3143. // let account_html = '<option value="0">选择审批人</option>';
  3144. // for (const account of accountList) {
  3145. // if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  3146. // const role = account.role !== '' ? '(' + account.role + ')' : '';
  3147. // const company = account.company !== '' ? ' -' + account.company : '';
  3148. // account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  3149. // }
  3150. // }
  3151. // $('#account_list').html(account_html);
  3152. // });
  3153. let timer = null;
  3154. let oldSearchVal = null;
  3155. $('#gr-search').bind('input propertychange', function(e) {
  3156. oldSearchVal = e.target.value
  3157. timer && clearTimeout(timer)
  3158. timer = setTimeout(() => {
  3159. const newVal = $('#gr-search').val()
  3160. let html = ''
  3161. if (newVal && newVal === oldSearchVal) {
  3162. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  3163. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3164. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3165. class="ml-auto">${item.mobile || ''}</span></p>
  3166. <span class="text-muted">${item.role || ''}</span>
  3167. </dd>`
  3168. })
  3169. $('.book-list').empty()
  3170. $('.book-list').append(html)
  3171. } else {
  3172. if (!$('.acc-btn').length) {
  3173. accountGroup.forEach((group, idx) => {
  3174. if (!group) return
  3175. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  3176. </a> ${group.groupName}</dt>
  3177. <div class="dd-content" data-toggleid="${idx}">`
  3178. group.groupList.forEach(item => {
  3179. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3180. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3181. class="ml-auto">${item.mobile || ''}</span></p>
  3182. <span class="text-muted">${item.role || ''}</span>
  3183. </dd>`
  3184. });
  3185. html += '</div>'
  3186. })
  3187. $('.book-list').empty()
  3188. $('.book-list').append(html)
  3189. }
  3190. }
  3191. }, 400);
  3192. });
  3193. // 添加审批流程按钮逻辑
  3194. $('.book-list').on('click', 'dt', function () {
  3195. const idx = $(this).find('.acc-btn').attr('data-groupid')
  3196. const type = $(this).find('.acc-btn').attr('data-type')
  3197. if (type === 'hide') {
  3198. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  3199. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  3200. $(this).find('.acc-btn').attr('data-type', 'show')
  3201. })
  3202. } else {
  3203. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  3204. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  3205. $(this).find('.acc-btn').attr('data-type', 'hide')
  3206. })
  3207. }
  3208. return false
  3209. });
  3210. // 添加到审批流程中
  3211. $('dl').on('click', 'dd', function () {
  3212. const auditorId = parseInt($(this).data('id'))
  3213. if (auditorId) {
  3214. postData('/tender/' + getTenderId() + '/ledger/audit/add', { auditorId }, (datas) => {
  3215. const html = [];
  3216. // 如果是重新上报,添加到重新上报列表中
  3217. const auditorshtml = [];
  3218. for (const [index,data] of datas.entries()) {
  3219. if (index !== 0) {
  3220. html.push('<li class="list-group-item" auditorId="' + data.audit_id + '">');
  3221. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  3222. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  3223. }
  3224. html.push('<span>');
  3225. html.push(data.audit_order + ' ');
  3226. html.push(data.name + ' ');
  3227. html.push('</span>');
  3228. html.push('<small class="text-muted">');
  3229. html.push(data.role);
  3230. html.push('</small></li>');
  3231. }
  3232. auditorshtml.push('<li class="list-group-item" ' + (index !== 0 ? 'data-auditorid="' + data.audit_id + '"' : '') + '>');
  3233. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  3234. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  3235. if (index === 0) {
  3236. auditorshtml.push('<span class="pull-right">原报</span>');
  3237. } else if (index+1 === datas.length) {
  3238. auditorshtml.push('<span class="pull-right">终审</span>');
  3239. } else {
  3240. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  3241. }
  3242. auditorshtml.push('</li>');
  3243. }
  3244. $('#auditors').html(html.join(''));
  3245. $('#auditors-list').html(auditorshtml.join(''));
  3246. });
  3247. }
  3248. });
  3249. $('body').on('click', '#auditors li>a', function () {
  3250. const li = $(this).parent();
  3251. const data = {
  3252. auditorId: parseInt(li.attr('auditorId')),
  3253. };
  3254. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  3255. li.remove();
  3256. for (const a of data2) {
  3257. const aLi = $('li[auditorId=' + a.audit_id + ']');
  3258. $('span', aLi).text(a.audit_order + ' ' + a.name + ' ');
  3259. }
  3260. // 如果是重新上报
  3261. // 令最后一个图标转换
  3262. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  3263. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  3264. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  3265. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  3266. }
  3267. // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  3268. // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  3269. // $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  3270. // .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  3271. // }
  3272. for (let i = 0; i < $('#auditors-list li').length; i++) {
  3273. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审')
  3274. // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审')
  3275. }
  3276. });
  3277. });
  3278. $('#hideSp').click(function () {
  3279. $('#sp-list').modal('hide');
  3280. });
  3281. // 多层modal关闭后的滚动bug修复
  3282. $('#sp-list').on('hidden.bs.modal', function (e) {
  3283. $(document.body).addClass('modal-open');
  3284. });
  3285. // 显示层次
  3286. (function (select, sheet) {
  3287. $(select).click(function () {
  3288. const tag = $(this).attr('tag');
  3289. const tree = sheet.zh_tree;
  3290. if (!tree) return;
  3291. setTimeout(() => {
  3292. showWaitingView();
  3293. switch (tag) {
  3294. case "1":
  3295. case "2":
  3296. case "3":
  3297. case "4":
  3298. case "5":
  3299. tree.expandByLevel(parseInt(tag));
  3300. SpreadJsObj.refreshTreeRowVisible(sheet);
  3301. break;
  3302. case "last":
  3303. tree.expandByCustom(() => { return true; });
  3304. SpreadJsObj.refreshTreeRowVisible(sheet);
  3305. break;
  3306. case "leafXmj":
  3307. tree.expandToLeafXmj();
  3308. SpreadJsObj.refreshTreeRowVisible(sheet);
  3309. break;
  3310. }
  3311. closeWaitingView();
  3312. }, 100);
  3313. });
  3314. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  3315. // $('#exportLedger').click(function () {
  3316. // const data = [];
  3317. // const setting = {
  3318. // header: ['项目节编号', '清单子目号', '部位明细', '名称', '单位', '清单数量', '设计数量1', '设计数量2', '单价', '合价', '图号', '备注'],
  3319. // width: [100, 70, 70, 300, 60, 80, 80, 80, 80, 80, 100, 100],
  3320. // hAlign: ['left', 'left', 'left', 'left','center', 'right', 'right', 'right', 'right', 'right', 'left', 'left'],
  3321. // };
  3322. // for (const node of ledgerTree.nodes) {
  3323. // data.push([node.code, node.b_code, '', node.name, node.unit,
  3324. // node.quantity, node.dgn_qty1, node.dgn_qty2, node.unit_price, node.total_price,
  3325. // node.drawing_code, node.memo
  3326. // ]);
  3327. // const posRange = pos.getLedgerPos(node.id);
  3328. // if (posRange && posRange.length > 0) {
  3329. // for (const [i, p] of posRange.entries()) {
  3330. // data.push(['', '', (i + 1) + '', p.name, '',
  3331. // p.quantity, '', '', '', '',
  3332. // p.drawing_code, p.memo
  3333. // ]);
  3334. // }
  3335. // }
  3336. // }
  3337. //
  3338. // XLSXObj.exportXlsxSheet(setting, data, "台账分解.xlsx");
  3339. // });
  3340. $('#exportLedger').click(function () {
  3341. const data = [];
  3342. const setting = {
  3343. cols: [
  3344. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  3345. {title: '清单子目号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3346. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'pos_code', hAlign: 1, width: 70, formatter: '@'},
  3347. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  3348. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  3349. {title: '清单数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  3350. {title: '设计数量1', colSpan: '1', rowSpan: '1', field: 'dgn_qty1', hAlign: 2, width: 80, type: 'Number'},
  3351. {title: '设计数量2', colSpan: '1', rowSpan: '1', field: 'dgn_qty2', hAlign: 2, width: 80, type: 'Number'},
  3352. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  3353. {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3354. {title: '图号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 100, formatter: '@'},
  3355. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 100, formatter: '@'},
  3356. ],
  3357. headRows: 1,
  3358. headRowHeight: [32],
  3359. defaultRowHeight: 21,
  3360. headerFont: 'bold 10px 微软雅黑',
  3361. font: '10px 微软雅黑'
  3362. };
  3363. const hasCl = ledgerSpreadSetting.cols.find(x => { return x.field === 'sjcl_qty'});
  3364. const qtyF = hasCl ? 'quantity' : 'sgfh_qty';
  3365. const tpF = hasCl ? 'total_price' : 'sgfh_tp';
  3366. for (const node of ledgerTree.nodes) {
  3367. data.push({
  3368. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3369. unit_price: node.unit_price, quantity: node[qtyF], total_price: node[tpF],
  3370. dgn_qty1: node.dgn_qty1, dgn_qty2: node.dgn_qty2,
  3371. drawing_code: node.drawing_code, memo: node.memo
  3372. });
  3373. const posRange = pos.getLedgerPos(node.id);
  3374. if (posRange && posRange.length > 0) {
  3375. for (const [i, p] of posRange.entries()) {
  3376. data.push({
  3377. pos_code: (i + 1) + '', name: p.name,
  3378. quantity: p[qtyF], drawing_code: p.drawing_code, memo: p.memo
  3379. });
  3380. }
  3381. }
  3382. }
  3383. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, "台账分解.xlsx");
  3384. });
  3385. const dataChecker = DataChecker({
  3386. checkUrl: window.location.pathname + '/check',
  3387. completeData: function (data) {
  3388. pos.updateDatas({update: data.source.pos});
  3389. const loadResult = ledgerTree.loadPostData({update: data.source.bills});
  3390. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  3391. posOperationObj.loadCurPosData();
  3392. for (const e of data.error) {
  3393. e.serialNo = ledgerTree.getNodeIndex(ledgerTree.getItems(e.ledger_id)) + 1;
  3394. }
  3395. },
  3396. errorList: errorList,
  3397. });
  3398. $('[name=audit-start]').submit(function (e) {
  3399. if (checkAuditorFrom()) {
  3400. $(this).parent().parent().parent().modal('hide');
  3401. dataChecker.checkAndPost(this.action, {});
  3402. $('#hide-all').hide();
  3403. }
  3404. return false;
  3405. });
  3406. $('#ledger-check2').click(() => {
  3407. const result = ledgerCheck2({
  3408. ledgerTree: ledgerTree,
  3409. ledgerPos: pos,
  3410. checkList: checkList,
  3411. decimal: tenderInfo.decimal,
  3412. checkOption: checkOption,
  3413. });
  3414. check2Viewing({
  3415. extra: ZhCalc.div(ledgerTree.datas.length + pos.datas.length, 10000, 0),
  3416. randomWait: true,
  3417. prefix: 'check2-',
  3418. checks: result,
  3419. checkList: checkList,
  3420. })
  3421. });
  3422. // 切换附件里节点和所有附件
  3423. $('#fujian .nav-link').on('click', function () {
  3424. const tabPanel = $(this).attr('fujian-content');
  3425. if (tabPanel !== 'syfujian') {
  3426. $('#showPage').hide();
  3427. $('#bach-download').prop('type', 'curr');
  3428. } else {
  3429. $('#showPage').show();
  3430. $('#bach-download').prop('type', 'all');
  3431. }
  3432. $('#showAttachment').hide();
  3433. });
  3434. // 上传附件
  3435. $('#upload-file-btn').click(function () {
  3436. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3437. // return toastr.error('当前操作没有权限!');
  3438. // }
  3439. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3440. if (!node) return;
  3441. const files = $('#upload-file')[0].files;
  3442. const formData = new FormData();
  3443. formData.append('lid', node.id);
  3444. for (const file of files) {
  3445. if (file === undefined) {
  3446. toastr.error('未选择上传文件!');
  3447. return false;
  3448. }
  3449. const filesize = file.size;
  3450. if (filesize > 30 * 1024 * 1024) {
  3451. toastr.error('存在上传文件大小过大!');
  3452. return false;
  3453. }
  3454. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3455. if (whiteList && !whiteList.includes(fileext)) {
  3456. toastr.error('只能上传指定格式的附件!');
  3457. return false;
  3458. }
  3459. formData.append('size', filesize);
  3460. formData.append('file[]', file);
  3461. }
  3462. postDataWithFile('/tender/' + tender.id + '/ledger/upload/file', formData, function (data) {
  3463. $('#upload').modal('hide');
  3464. // 插入到attData中
  3465. attData = data.concat(attData);
  3466. // 重新生成List
  3467. getAllList();
  3468. getNodeList(node.id);
  3469. }, function () {
  3470. toastr.error('附件上传失败');
  3471. });
  3472. $('#upload-file').val('');
  3473. });
  3474. // 获取附件信息
  3475. $('.list-table').on('click', '.att-file-name', function () {
  3476. const fid = $(this).attr('file-id');
  3477. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3478. return;
  3479. }
  3480. const att = attData.find(function (item) {
  3481. return item.id === parseInt(fid);
  3482. });
  3483. $('#edit-att').hide();
  3484. $('#show-att').show();
  3485. if (att !== undefined) {
  3486. // 进来先把编辑功能隐藏
  3487. $('#btn-att a').eq(3).hide()
  3488. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3489. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3490. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3491. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3492. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3493. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3494. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3495. $('#show-att tr').eq(3).children('td').text(att.remark);
  3496. // 附件uid等于当前用户id, 附件上传本人
  3497. if (parseInt(cur_uid) === att.uid) {
  3498. $('#btn-att').show();
  3499. const showDel = tender.ledger_status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3500. if (showDel) $('#btn-att a').eq(3).show();
  3501. // $('#btn-att a').eq(3).show();
  3502. $('#btn-att a').eq(2).hide();
  3503. $('#btn-att a').eq(4).hide();
  3504. $('#btn-att a').eq(5).hide();
  3505. } else {
  3506. $('#btn-att').hide();
  3507. $('#btn-att a').eq(3).hide();
  3508. $('#btn-att a').eq(2).hide();
  3509. $('#btn-att a').eq(4).hide();
  3510. $('#btn-att a').eq(5).hide();
  3511. }
  3512. $('#showAttachment').attr('file-id', fid);
  3513. $('#showAttachment').show();
  3514. } else {
  3515. $('#showAttachment').hide();
  3516. $('#showAttachment').attr('file-id', '');
  3517. toastr.error('附件信息获取失败');
  3518. }
  3519. });
  3520. // $('body').on('click', '.alllist-table a', handleFileList);
  3521. $('body').on('click', '#btn-att a', function () {
  3522. const content = $(this).attr('content');
  3523. const fid = $('#showAttachment').attr('file-id');
  3524. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  3525. if (content === 'edit') {
  3526. $('#btn-att a').eq(3).hide();
  3527. $('#btn-att a').eq(2).show();
  3528. $('#btn-att a').eq(4).show();
  3529. $('#btn-att a').eq(5).show();
  3530. $('#show-att').hide();
  3531. $('#edit-att').show();
  3532. const att = attData.find(function (item) {
  3533. return item.id === parseInt(fid);
  3534. });
  3535. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3536. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3537. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3538. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3539. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3540. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3541. } else if (content === 'cancel') {
  3542. $('#show-att').show();
  3543. $('#edit-att').hide();
  3544. $('#btn-att a').eq(3).show();
  3545. $('#btn-att a').eq(2).hide();
  3546. $('#btn-att a').eq(4).hide();
  3547. $('#btn-att a').eq(5).hide();
  3548. } else if (content === 'save') {
  3549. const formData = new FormData();
  3550. formData.append('id', fid);
  3551. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3552. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3553. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3554. const file = $('#change-att-btn')[0];
  3555. if (file.files[0] !== undefined) {
  3556. const filesize = file.files[0].size;
  3557. formData.append('size', filesize);
  3558. formData.append('file', file.files[0]);
  3559. }
  3560. postDataWithFile('/tender/' + tender.id + '/ledger/save/file', formData, function (data) {
  3561. // 替换到attData中
  3562. const att_index = attData.findIndex(function (item) {
  3563. return item.id === parseInt(fid);
  3564. });
  3565. attData.splice(att_index, 1, data);
  3566. // 重新生成List
  3567. getAllList(parseInt($('#currentPage').text()));
  3568. getNodeList(node.id);
  3569. $('#show-att').show();
  3570. $('#edit-att').hide();
  3571. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3572. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3573. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3574. $('#show-att tr').eq(2).children('td').eq(0).text(data.username);
  3575. $('#show-att tr').eq(2).children('td').eq(1).text(data.in_time);
  3576. $('#show-att tr').eq(3).children('td').text(data.remark);
  3577. $('#btn-att a').eq(3).show();
  3578. $('#btn-att a').eq(2).hide();
  3579. $('#btn-att a').eq(4).hide();
  3580. $('#btn-att a').eq(5).hide();
  3581. }, function () {
  3582. toastr.error('附件上传失败');
  3583. });
  3584. $('#change-att-btn').val('');
  3585. } else if (content === 'del') {
  3586. const data = {id: fid};
  3587. postData('/tender/' + tender.id + '/ledger/delete/file', data, function (result) {
  3588. // 删除到attData中
  3589. const att_index = attData.findIndex(function (item) {
  3590. return item.id === parseInt(fid);
  3591. });
  3592. attData.splice(att_index, 1);
  3593. // 重新生成List
  3594. if ($('#alllist-table tr').length === 1) {
  3595. getAllList(parseInt($('#currentPage').text()) - 1);
  3596. } else {
  3597. getAllList(parseInt($('#currentPage').text()));
  3598. }
  3599. getNodeList(node.id);
  3600. $('#showAttachment').hide();
  3601. $('#showAttachment').attr('file-id', '');
  3602. });
  3603. } else if (content === 'view') {
  3604. const data = {id: fid};
  3605. postData('/tender/' + tender.id + '/ledger/check/file', data, function (result) {
  3606. const { filepath } = result
  3607. $('#load-file').attr('href', filepath);
  3608. $('#load-file')[0].click();
  3609. });
  3610. } else if (content === 'location') {
  3611. const att = attData.find(item => item.id === parseInt(fid));
  3612. if (Object.keys(att).length) {
  3613. SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), att.ledger_id, true);
  3614. posOperationObj.loadCurPosData();
  3615. }
  3616. }
  3617. });
  3618. // 替换附件
  3619. $('#change-att-btn').on('change', function () {
  3620. const file = $('#change-att-btn')[0].files[0];
  3621. const name = file.name;
  3622. const filename = name.substring(0, name.lastIndexOf("."));
  3623. const fileext = name.substr(name.indexOf("."));
  3624. const filesize = file.size;
  3625. if (filesize > 30 * 1024 * 1024) {
  3626. toastr.error('文件大小过大!');
  3627. $('#change-att-btn').val('');
  3628. return false;
  3629. }
  3630. if (whiteList && !whiteList.includes(fileext)) {
  3631. toastr.error('只能上传指定格式的附件!');
  3632. $('#change-att-btn').val('');
  3633. return false;
  3634. }
  3635. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3636. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3637. });
  3638. // 切换页数
  3639. $('.page-select').on('click', function () {
  3640. const totalPageNum = parseInt($('#totalPage').text());
  3641. const lastPageNum = parseInt($('#currentPage').text());
  3642. const status = $(this).attr('content');
  3643. if (status === 'pre' && lastPageNum > 1) {
  3644. getAllList(lastPageNum-1);
  3645. $('#showAttachment').hide();
  3646. $('#syfujian .check-all-file').prop('checked', false)
  3647. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3648. getAllList(lastPageNum+1);
  3649. $('#showAttachment').hide();
  3650. $('#syfujian .check-all-file').prop('checked', false)
  3651. }
  3652. });
  3653. // 批量下载
  3654. $('#bach-download').click(function() {
  3655. const fileIds = [];
  3656. const type = $(this).attr('type');
  3657. let node = ''
  3658. if (type === 'curr') {
  3659. node = '#nodelist-table .check-file:checked'
  3660. } else {
  3661. node = '#alllist-table .check-file:checked'
  3662. }
  3663. $(node).each(function() {
  3664. const fileId = $(this).attr('file-id');
  3665. fileId && fileIds.push(fileId);
  3666. });
  3667. if (fileIds.length) {
  3668. if (fileIds.length > 20) {
  3669. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  3670. }
  3671. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  3672. $(this).attr('disabled', "true")
  3673. const btn = $(this);
  3674. const fileArr = [];
  3675. for (const id of fileIds) {
  3676. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  3677. fileArr.push({
  3678. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  3679. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  3680. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  3681. });
  3682. }
  3683. const packageName = `${tender.name}-台账分解-附件.zip`;
  3684. try {
  3685. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  3686. } catch (e) {
  3687. btn.removeAttr('disabled');
  3688. toastr.clear();
  3689. toastr.error('批量下载失败');
  3690. }
  3691. // postCompressFile(`/tender/${tender.id}/ledger/compresse/file`, {fileIds}, function(result) {
  3692. // toastr.clear()
  3693. // toastr.success('压缩文件成功')
  3694. // btn.removeAttr('disabled')
  3695. // const href = window.URL.createObjectURL(result)
  3696. // $('#zipDown').attr('href', href);
  3697. // $('#zipDown').attr('download', `${tender.name}-台账分解-附件.zip`);
  3698. // $("#zipDown")[0].click();
  3699. // }, () => {
  3700. // btn.removeAttr('disabled')
  3701. // toastr.clear()
  3702. // toastr.error('批量下载失败')
  3703. // });
  3704. // const url = `/tender/${tender.id}/ledger/compresse/file?fileIds=${JSON.stringify(fileIds)}`;
  3705. }
  3706. });
  3707. // 监听附件check是否选中
  3708. $('.list-table').on('click', '.check-file', function() {
  3709. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3710. const childs = $(this).parents('.list-table').children().length;
  3711. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3712. if (checkedList.length === childs) {
  3713. checkBox.prop("checked", true);
  3714. } else {
  3715. checkBox.prop("checked", false);
  3716. }
  3717. });
  3718. $('.check-all-file').click(function() {
  3719. const isCheck = $(this).is(':checked');
  3720. $(this).parents('table').find('.list-table').each(function() {
  3721. $(this).find('input:checkbox').prop("checked", isCheck);
  3722. })
  3723. });
  3724. });
  3725. // 生成当前节点列表
  3726. function getNodeList(node) {
  3727. let html = '';
  3728. for(const att of attData) {
  3729. if (node === att.lid) {
  3730. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  3731. html += `<tr>
  3732. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  3733. <td>
  3734. <div class="d-flex">
  3735. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  3736. <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>
  3737. </div>
  3738. </td><td>${att.username}</td></tr>`
  3739. }
  3740. }
  3741. $('#nodelist-table').html(html);
  3742. $('#nodelist-table').on('click', 'tr', function() {
  3743. $('#nodelist-table tr').removeClass('bg-light')
  3744. $(this).addClass('bg-light')
  3745. })
  3746. }
  3747. // 生成所有附件列表
  3748. function getAllList(currPageNum = 1) {
  3749. // 每页最多几个附件
  3750. const pageCount = 20;
  3751. // 附件总数
  3752. const total = attData.length;
  3753. // 总页数
  3754. const pageNum = Math.ceil(total/pageCount);
  3755. $('#totalPage').text(pageNum);
  3756. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  3757. // 当前页附件内容
  3758. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  3759. currPageFileData = currPageAttData;
  3760. let html = '';
  3761. for(const att of currPageAttData) {
  3762. html += `<tr>
  3763. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  3764. <td>
  3765. <div class="d-flex">
  3766. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  3767. <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>
  3768. </div>
  3769. </td><td>${att.username}</td></tr>`
  3770. }
  3771. $('#alllist-table').html(html);
  3772. $('#alllist-table').on('click', 'tr', function() {
  3773. $('#alllist-table tr').removeClass('bg-light')
  3774. $(this).addClass('bg-light')
  3775. })
  3776. }
  3777. // 检查上报情况
  3778. function checkAuditorFrom () {
  3779. if ($('#auditors li').length === 0) {
  3780. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  3781. toastr.error('请联系管理员添加审批人');
  3782. } else {
  3783. toastr.error('请先选择审批人,再上报数据');
  3784. }
  3785. return false;
  3786. } else {
  3787. $('#hide-all').show();
  3788. return true;
  3789. }
  3790. }