revise.js 128 KB

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