ledger.js 180 KB

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