revise.js 117 KB

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