ledger.js 156 KB

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