ledger.js 171 KB

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