ledger.js 172 KB

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