revise.js 118 KB

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