revise.js 129 KB

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