ledger.js 156 KB

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