revise.js 118 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. const data = sheet.zh_tree.getNodeKeyData(node);
  676. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  677. const col = sheet.zh_setting.cols[iCol];
  678. const style = sheet.getStyle(iRow, iCol);
  679. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  680. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  681. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  682. return;
  683. }
  684. data[col.field] = null;
  685. const exprInfo = getExprInfo(col.field);
  686. if (exprInfo) {
  687. data[exprInfo.expr] = '';
  688. }
  689. bDel = true;
  690. }
  691. if (bDel) datas.push(data);
  692. }
  693. if (datas.length > 0) {
  694. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  695. const refreshNode = sheet.zh_tree.loadPostData(result);
  696. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  697. billsTreeSpreadObj.loadExprToInput(sheet);
  698. });
  699. }
  700. },
  701. pasteBlock: function (spread, copyInfo) {
  702. const self = this;
  703. const sheet = spread.getActiveSheet();
  704. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  705. postData(window.location.pathname + '/update', {
  706. postType: 'paste-block',
  707. postData: {
  708. id: tree.getNodeKey(node),
  709. tid: copyInfo.tid,
  710. block: copyInfo.block,
  711. }
  712. }, function (data) {
  713. pos.updateDatas(data.pos);
  714. const result = tree.loadPostData(data.ledger);
  715. self.refreshTree(sheet, result);
  716. const sel = sheet.getSelections()[0];
  717. if (sel) {
  718. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  719. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  720. }
  721. self.refreshOperationValid(sheet);
  722. removeLocalCache(copyBlockTag);
  723. }, null, true);
  724. },
  725. topRowChanged: function (e, info) {
  726. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  727. },
  728. editStarting(e, info) {
  729. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  730. const col = info.sheet.zh_setting.cols[info.col];
  731. const node = info.sheet.zh_tree.nodes[info.row];
  732. if (!node) {
  733. info.cancel = true;
  734. return;
  735. }
  736. const exprInfo = getExprInfo(col.field);
  737. if (exprInfo) {
  738. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  739. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  740. }
  741. }
  742. switch (col.field) {
  743. case 'code':
  744. const posRange = pos.getLedgerPos(node.id);
  745. info.cancel = posRange && posRange.length > 0;
  746. break;
  747. case 'unit_price':
  748. info.cancel = (node.children && node.children.length > 0) || node.used;
  749. break;
  750. case 'sgfh_qty':
  751. case 'sgfh_tp':
  752. case 'sjcl_qty':
  753. case 'sjcl_tp':
  754. case 'qtcl_qty':
  755. case 'qtcl_tp':
  756. case 'deal_qty':
  757. case 'deal_tp':
  758. info.cancel = (node.children && node.children.length > 0);
  759. break;
  760. case 'dgn_qty1':
  761. case 'dgn_qty2':
  762. info.cancel = !_.isEmpty(node.b_code);
  763. break;
  764. }
  765. },
  766. cut: function (sheet, sel, callback) {
  767. if (!sheet || !sel) return;
  768. if (sel.colCount >= sheet.zh_setting.cols.length) {
  769. toastr.warning('请勿选中整行剪切');
  770. return;
  771. }
  772. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  773. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  774. const node = sortData[iRow];
  775. if (node) {
  776. const data = sheet.zh_tree.getNodeKeyData(node);
  777. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  778. const col = sheet.zh_setting.cols[iCol];
  779. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  780. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  781. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  782. const lPos = pos.getLedgerPos(node.id);
  783. if (lPos && lPos.length > 0) {
  784. toastr.error('不可剪切');
  785. return;
  786. }
  787. }
  788. const style = sheet.getStyle(iRow, iCol);
  789. if (style.locked) {
  790. toastr.error('不可剪切');
  791. return;
  792. }
  793. const colSetting = sheet.zh_setting.cols[iCol];
  794. data[colSetting.field] = null;
  795. const exprInfo = getExprInfo(colSetting.field);
  796. if (exprInfo) {
  797. data[exprInfo.expr] = '';
  798. }
  799. }
  800. datas.push(data);
  801. }
  802. }
  803. if (datas.length > 0) {
  804. callback();
  805. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  806. const refreshNode = sheet.zh_tree.loadPostData(result);
  807. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  808. });
  809. }
  810. },
  811. sortCode: function (sheet) {
  812. const tree = sheet.zh_tree;
  813. if (!tree) return;
  814. const select = SpreadJsObj.getSelectObject(sheet);
  815. if (!select || !select.code || select.code === '') return;
  816. const recursiveSortCode = function (data, parentCode, children) {
  817. if (!children || children.length === 0) return;
  818. for (const [i, child] of children.entries()) {
  819. if (!child.b_code || child.b_code === '') {
  820. const code = parentCode + '-' + (i + 1);
  821. const cData = tree.getNodeKeyData(child);
  822. cData.code = code;
  823. data.push(cData);
  824. if (!tree.isLeafXmj(child)) {
  825. recursiveSortCode(data, code, child.children);
  826. }
  827. }
  828. }
  829. };
  830. const data = [];
  831. recursiveSortCode(data, select.code, select.children);
  832. if (data.length > 0) {
  833. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  834. const refreshNode = tree.loadPostData(result);
  835. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  836. })
  837. }
  838. }
  839. };
  840. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  841. billsTreeSpreadObj.loadExprToInput(billsSheet);
  842. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  843. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  844. if (!readOnly) {
  845. // 增删上下移升降级
  846. $('a[name="base-opr"]').click(function () {
  847. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  848. });
  849. $('a[name=cpc]').click(function () {
  850. billsSpread.commandManager().execute({
  851. cmd: this.getAttribute('type'),
  852. sheetName: billsSheet.name()
  853. });
  854. });
  855. $('#bills-expr').bind('change onblur', function () {
  856. if (this.readOnly) return;
  857. const expr = $(this);
  858. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  859. const select = billsTree.getItemsByIndex(row);
  860. if (!select) return;
  861. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  862. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  863. const data = {
  864. id: select.id,
  865. tender_id: select.tender_id,
  866. ledger_id: select.ledger_id
  867. };
  868. const exprInfo = getExprInfo(field);
  869. if (newValue !== '') {
  870. const num = _.toNumber(newValue);
  871. if (num) {
  872. data[field] = num;
  873. if (exprInfo) {
  874. data[exprInfo.expr] = '';
  875. }
  876. } else {
  877. try {
  878. data[field] = math.evaluate(transExpr(newValue));
  879. if (exprInfo) {
  880. data[exprInfo.expr] = newValue;
  881. }
  882. } catch (err) {
  883. toastr.error('输入的表达式非法');
  884. return;
  885. }
  886. }
  887. } else {
  888. data[field] = null;
  889. if (exprInfo) {
  890. data[exprInfo.expr] = '';
  891. }
  892. }
  893. // 更新至服务器
  894. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  895. const refreshNode = billsTree.loadPostData(result);
  896. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  897. });
  898. });
  899. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  900. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  901. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  902. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  903. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  904. SpreadJsObj.Clipboard.setCopyData(copyText);
  905. });
  906. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  907. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  908. }
  909. // 右键菜单
  910. let batchInsertObj;
  911. $.contextMenu.types.batchInsert = function (item, opt, root) {
  912. const self = this;
  913. if ($.isFunction(item.icon)) {
  914. item._icon = item.icon.call(this, this, $t, key, item);
  915. } else {
  916. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  917. // to enable font awesome
  918. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  919. } else {
  920. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  921. }
  922. }
  923. this.addClass(item._icon);
  924. 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>')
  925. .appendTo(this);
  926. const $input = $obj.find('input');
  927. const event = () => {
  928. if (self.hasClass('context-menu-disabled')) return;
  929. item.batchInsert($input[0], root);
  930. };
  931. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  932. $input.click((e) => {e.stopPropagation();})
  933. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  934. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  935. };
  936. const billsContextMenuOptions = {
  937. selector: '#bills-spread',
  938. build: function ($trigger, e) {
  939. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  940. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  941. },
  942. items: {}
  943. };
  944. if (!readOnly) {
  945. billsContextMenuOptions.items.create = {
  946. name: '新增',
  947. icon: 'fa-sign-in',
  948. callback: function (key, opt) {
  949. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  950. },
  951. disabled: function (key, opt) {
  952. const sheet = billsSheet;
  953. const selection = sheet.getSelections();
  954. const sel = selection ? selection[0] : sheet.getSelections()[0];
  955. const row = sel ? sel.row : -1;
  956. const tree = sheet.zh_tree;
  957. if (!tree) return true;
  958. const first = sheet.zh_tree.nodes[row];
  959. const valid = !sheet.zh_setting.readOnly;
  960. return !(valid && first && first.level > 1);
  961. }
  962. };
  963. billsContextMenuOptions.items.delete = {
  964. name: '删除',
  965. icon: 'fa-remove',
  966. callback: function (key, opt) {
  967. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  968. },
  969. disabled: function (key, opt) {
  970. const sheet = billsSheet;
  971. const selection = sheet.getSelections();
  972. const sel = selection ? selection[0] : sheet.getSelections()[0];
  973. const row = sel ? sel.row : -1;
  974. const tree = sheet.zh_tree;
  975. if (!tree) return true;
  976. const first = sheet.zh_tree.nodes[row];
  977. let last = first, sameParent = true, nodeUsed = first.used;
  978. if (sel.rowCount > 1 && first) {
  979. for (let r = 1; r < sel.rowCount; r++) {
  980. const rNode = tree.nodes[sel.row + r];
  981. if (!rNode) {
  982. sameParent = false;
  983. break;
  984. }
  985. nodeUsed = nodeUsed || rNode.used;
  986. if (rNode.level > first.level) continue;
  987. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  988. sameParent = false;
  989. break;
  990. }
  991. last = rNode;
  992. }
  993. }
  994. const valid = !sheet.zh_setting.readOnly;
  995. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  996. }
  997. };
  998. billsContextMenuOptions.items.sprBase = '-----------';
  999. }
  1000. billsContextMenuOptions.items.copyBlock = {
  1001. name: '复制整块',
  1002. icon: 'fa-files-o',
  1003. callback: function (key, opt) {
  1004. const copyBlockList = [];
  1005. const sheet = billsSheet;
  1006. const sel = sheet.getSelections()[0];
  1007. let iRow = sel.row;
  1008. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1009. while (iRow < sel.row + sel.rowCount) {
  1010. const node = sheet.zh_tree.nodes[iRow];
  1011. if (node.ledger_pid !== pid) {
  1012. toastr.error('仅可同时选中同层节点');
  1013. return;
  1014. }
  1015. const posterity = sheet.zh_tree.getPosterity(node);
  1016. iRow += posterity.length + 1;
  1017. posterity.unshift(node);
  1018. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1019. }
  1020. for (const cbl of copyBlockList) {
  1021. for (const b of cbl) {
  1022. const posRange = pos.getLedgerPos(b.id);
  1023. if (posRange && posRange.length > 0) b.pos = posRange;
  1024. }
  1025. }
  1026. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1027. },
  1028. visible: function (key, opt) {
  1029. const sheet = billsSheet;
  1030. const selection = sheet.getSelections();
  1031. const row = selection[0].row;
  1032. const select = billsTree.nodes[row];
  1033. return select;
  1034. },
  1035. disabled: function (key, opt) {
  1036. const sheet = billsSheet;
  1037. const selection = sheet.getSelections();
  1038. const row = selection[0].row;
  1039. const select = billsTree.nodes[row];
  1040. return select && select.level <= 1;
  1041. }
  1042. };
  1043. billsContextMenuOptions.items.copyBlockXmj = {
  1044. name: '复制整块(只复制项目节)',
  1045. icon: 'fa-files-o',
  1046. callback: function (key, opt) {
  1047. const copyBlockList = [];
  1048. const sheet = billsSheet;
  1049. const sel = sheet.getSelections()[0];
  1050. let iRow = sel.row;
  1051. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1052. while (iRow < sel.row + sel.rowCount) {
  1053. const node = sheet.zh_tree.nodes[iRow];
  1054. if (node.ledger_pid !== pid) {
  1055. toastr.error('仅可同时选中同层节点');
  1056. return;
  1057. }
  1058. const posterity = sheet.zh_tree.getPosterity(node);
  1059. iRow += posterity.length + 1;
  1060. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1061. copyPosterity.unshift(node);
  1062. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1063. for (const p of copyData) {
  1064. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1065. p.is_leaf = children.length === 0;
  1066. }
  1067. copyBlockList.push(copyData);
  1068. }
  1069. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1070. },
  1071. visible: function (key, opt) {
  1072. const sheet = billsSheet;
  1073. const selection = sheet.getSelections();
  1074. const row = selection[0].row;
  1075. const select = billsTree.nodes[row];
  1076. return select;
  1077. },
  1078. disabled: function (key, opt) {
  1079. const sheet = billsSheet;
  1080. const selection = sheet.getSelections();
  1081. const row = selection[0].row;
  1082. const select = billsTree.nodes[row];
  1083. return select && select.level <= 1;
  1084. }
  1085. };
  1086. if (!readOnly) {
  1087. billsContextMenuOptions.items.pasteBlock = {
  1088. name: '粘贴整块',
  1089. icon: 'fa-clipboard',
  1090. disabled: function (key, opt) {
  1091. //const block = treeOperationObj.block || [];
  1092. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1093. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1094. },
  1095. callback: function (key, opt) {
  1096. //const block = treeOperationObj.block || [];
  1097. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1098. if (copyInfo.block.length > 0) {
  1099. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1100. } else {
  1101. document.execCommand('paste');
  1102. }
  1103. },
  1104. visible: function (key, opt) {
  1105. return !readOnly;
  1106. }
  1107. };
  1108. billsContextMenuOptions.items.sprBlock = '-----------';
  1109. }
  1110. if (!readOnly) {
  1111. billsContextMenuOptions.items.batchInsert = {
  1112. name: '批量插入',
  1113. type: 'batchInsert',
  1114. value: '2',
  1115. icon: 'fa-sign-in',
  1116. batchInsert: function (obj, root) {
  1117. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1118. obj.value = obj.max;
  1119. toastr.warning('批量插入不可多于' + obj.max);
  1120. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1121. obj.value = obj.min;
  1122. toastr.warning('批量插入不可少于' + obj.min);
  1123. } else {
  1124. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1125. root.$menu.trigger('contextmenu:hide');
  1126. }
  1127. },
  1128. disabled: function (key, opt) {
  1129. const sheet = billsSheet;
  1130. const selection = sheet.getSelections();
  1131. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1132. const row = sel ? sel.row : -1;
  1133. const tree = sheet.zh_tree;
  1134. if (!tree) return true;
  1135. const first = sheet.zh_tree.nodes[row];
  1136. const valid = !sheet.zh_setting.readOnly;
  1137. return !(valid && first && first.level > 1);
  1138. }
  1139. };
  1140. billsContextMenuOptions.items.batchInsertBillsPos = {
  1141. name: '批量插入清单-计量单元',
  1142. icon: 'fa-sign-in',
  1143. disabled: function (key, opt) {
  1144. if (!isTz) return true;
  1145. const select = SpreadJsObj.getSelectObject(billsSheet);
  1146. if (select) {
  1147. if (select.code && select.code !== '') {
  1148. return !billsTree.isLeafXmj(select);
  1149. } else {
  1150. const parent = billsTree.getParent(select);
  1151. return !(parent && billsTree.isLeafXmj(parent));
  1152. }
  1153. } else {
  1154. return false;
  1155. }
  1156. },
  1157. callback: function (key, opt) {
  1158. if (!batchInsertObj) {
  1159. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1160. } else {
  1161. batchInsertObj.initView();
  1162. }
  1163. $('#batch').modal('show');
  1164. }
  1165. };
  1166. billsContextMenuOptions.items.sprBatch = '-----------';
  1167. billsContextMenuOptions.items.importGclBills2Xmj = {
  1168. name: '导入工程量清单至项目节',
  1169. icon: 'fa-file-excel-o',
  1170. disabled: function (key, opt) {
  1171. const node = SpreadJsObj.getSelectObject(billsSheet);
  1172. return readOnly
  1173. || (node.children && node.children.length > 0)
  1174. || (!_.isNil(node.b_code) && node.b_code !== '')
  1175. || billsTree.checkNodeUsed(node, pos);
  1176. },
  1177. callback: function (key, opt) {
  1178. const node = SpreadJsObj.getSelectObject(billsSheet);
  1179. importExcel.doImport({
  1180. template: {
  1181. hint: '工程量清单',
  1182. url: '/template/导入工程量清单EXCEL格式.xls',
  1183. },
  1184. callback: function (sheet) {
  1185. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1186. const sel = billsSheet.getSelections();
  1187. const refreshNode = billsTree.loadPostData(result);
  1188. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1189. if (refreshNode.create[0]) {
  1190. if (sel && sel[0]) {
  1191. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1192. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel[0].row, refreshNode.create[0].index]);
  1193. } else {
  1194. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1195. SpreadJsObj.reloadRowsBackColor(billsSheet, [refreshNode.create[0].index]);
  1196. }
  1197. }
  1198. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1199. }, null);
  1200. }
  1201. });
  1202. }
  1203. };
  1204. }
  1205. $.contextMenu(billsContextMenuOptions);
  1206. // 计量单元 相关方法&绑定spreadjs事件
  1207. const posSpreadObj = {
  1208. refreshOperationValid: function (sheet, selection) {
  1209. const setObjEnable = function (obj, enable) {
  1210. if (enable) {
  1211. obj.removeClass('disabled');
  1212. } else {
  1213. obj.addClass('disabled');
  1214. }
  1215. };
  1216. const invalidAll = function () {
  1217. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1218. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1219. };
  1220. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1221. const row = sel ? sel.row : -1;
  1222. const first = sheet.zh_data[row];
  1223. if (!first) {
  1224. invalidAll();
  1225. return;
  1226. }
  1227. let last = first;
  1228. if (sel.rowCount > 1 && first) {
  1229. for (let r = 1; r < sel.rowCount; r++) {
  1230. const rNode = sheet.zh_data[sel.row + r];
  1231. if (!rNode) break;
  1232. last = rNode;
  1233. }
  1234. }
  1235. const preNode = sheet.zh_data[row - 1];
  1236. const valid = !sheet.zh_setting.readOnly;
  1237. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1238. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1239. },
  1240. loadExprToInput: function () {
  1241. const sel = posSheet.getSelections()[0];
  1242. if (!sel) return;
  1243. const col = posSheet.zh_setting.cols[sel.col];
  1244. const cell = posSheet.getCell(sel.col, sel.col);
  1245. if (col && col.type === 'Number') {
  1246. const data = SpreadJsObj.getSelectObject(posSheet);
  1247. if (data) {
  1248. const exprInfo = getExprInfo(col.field);
  1249. const value = exprInfo
  1250. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1251. : data[col.field];
  1252. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1253. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1254. } else {
  1255. $('#pos-expr').val('').attr('readOnly', true);
  1256. $('#pos-expr').removeAttr('data-row');
  1257. }
  1258. } else {
  1259. $('#pos-expr').val('').attr('readOnly', true);
  1260. $('#pos-expr').removeAttr('data-row');
  1261. }
  1262. },
  1263. /**
  1264. * 加载计量单元 根据当前台账选择节点
  1265. */
  1266. loadCurPosData: function () {
  1267. const node = SpreadJsObj.getSelectObject(billsSheet);
  1268. if (node) {
  1269. const posData = pos.getLedgerPos(node.id) || [];
  1270. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1271. } else {
  1272. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1273. }
  1274. SpreadJsObj.resetFieldReadOnly(posSheet);
  1275. posSpreadObj.loadExprToInput();
  1276. posSpreadObj.refreshOperationValid(posSheet);
  1277. },
  1278. baseOpr: function (sheet, type) {
  1279. const data = {
  1280. postType: 'pos',
  1281. posPostType: type === 'delete' ? type : 'update',
  1282. postData: [],
  1283. };
  1284. const selection = sheet.getSelections();
  1285. const row = selection[0].row, count = selection[0].rowCount;
  1286. const first = sheet.zh_data[row];
  1287. if (type === 'delete') {
  1288. for (let iRow = 0; iRow < count; iRow++) {
  1289. const posData = sheet.zh_data[iRow + row];
  1290. if (posData) {
  1291. if (posData.used) {
  1292. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1293. return;
  1294. }
  1295. data.postData.push(sheet.zh_data[iRow + row].id);
  1296. }
  1297. }
  1298. } else if (type === 'up-move') {
  1299. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1300. for (let iRow = 0; iRow < count; iRow++) {
  1301. const posData = sheet.zh_data[iRow + row];
  1302. if (posData) {
  1303. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1304. preUpdate.porder = posData.porder;
  1305. }
  1306. }
  1307. data.postData.push(preUpdate);
  1308. } else if (type === 'down-move') {
  1309. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1310. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1311. const posData = sheet.zh_data[iRow + row];
  1312. if (posData) {
  1313. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1314. nextUpdate.porder = posData.porder;
  1315. }
  1316. }
  1317. data.postData.push(nextUpdate);
  1318. }
  1319. if (data.postData.length > 0) {
  1320. postData(window.location.pathname + '/update', data, function (result) {
  1321. if (type === 'delete') {
  1322. pos.removeDatas(result.pos);
  1323. sheet.deleteRows(row, count);
  1324. const loadResult = billsTree.loadPostData(result.ledger);
  1325. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1326. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1327. posSpreadObj.refreshOperationValid(posSheet);
  1328. } else {
  1329. pos.updateDatas(result.pos);
  1330. const sel = selection[0];
  1331. if (sel) {
  1332. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1333. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1334. }
  1335. posSpreadObj.loadCurPosData();
  1336. }
  1337. });
  1338. }
  1339. },
  1340. editStarting: function (e, info) {
  1341. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1342. const sel = info.sheet.getSelections();
  1343. if (!sel || !sel[0]) return;
  1344. const col = info.sheet.zh_setting.cols[sel[0].col];
  1345. const node = SpreadJsObj.getSelectObject(info.sheet);
  1346. const exprInfo = getExprInfo(col.field);
  1347. if (exprInfo) {
  1348. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1349. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1350. }
  1351. }
  1352. },
  1353. /**
  1354. * 编辑单元格响应事件
  1355. * @param {Object} e
  1356. * @param {Object} info
  1357. */
  1358. editEnded: function (e, info) {
  1359. if (!info.sheet.zh_setting) {
  1360. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1361. return;
  1362. }
  1363. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1364. const col = info.sheet.zh_setting.cols[info.col];
  1365. const orgText = posData ? posData[col.field] : null;
  1366. const newText = trimInvalidChar(info.editingText);
  1367. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1368. const node = posSpreadObj.billsNode;
  1369. if (!node) {
  1370. toastr.error('数据错误,请选择台账节点后再试');
  1371. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1372. return;
  1373. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1374. toastr.error('父节点不可插入计量单元');
  1375. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1376. return;
  1377. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1378. toastr.error('项目节不可插入计量单元');
  1379. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1380. return;
  1381. }
  1382. const data = {postType: 'pos'};
  1383. if (col.field === 'name') {
  1384. if (newText === '' && posData) {
  1385. toastr.error('部位名称不可为空', 'error');
  1386. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1387. return;
  1388. } else if (!posData) {
  1389. if (newText && newText !== '') {
  1390. data.posPostType = 'add';
  1391. const sortData = info.sheet.zh_data;
  1392. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1393. data.postData = { name: newText, lid: node.id, porder: order};
  1394. } else {
  1395. return;
  1396. }
  1397. } else {
  1398. data.posPostType = 'update';
  1399. data.postData = {id: posData.id, name: newText};
  1400. }
  1401. } else if (!posData) {
  1402. toastr.warning('新增计量单元请先输入名称');
  1403. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1404. return;
  1405. } else {
  1406. data.posPostType = 'update';
  1407. data.postData = {id: posData.id};
  1408. if (col.type === 'Number') {
  1409. const exprInfo = getExprInfo(col.field);
  1410. const num = _.toNumber(newText);
  1411. if (_.isFinite(num)) {
  1412. data.postData[col.field] = num;
  1413. if (exprInfo) {
  1414. data.postData[exprInfo.expr] = '';
  1415. }
  1416. } else {
  1417. try {
  1418. data.postData[col.field] = math.evaluate(transExpr(newText));
  1419. if (exprInfo) {
  1420. data.postData[exprInfo.expr] = newText;
  1421. }
  1422. } catch(err) {
  1423. toastr.error('输入的表达式非法');
  1424. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1425. return;
  1426. }
  1427. }
  1428. } else {
  1429. data.postData[col.field] = newText;
  1430. }
  1431. }
  1432. postData(window.location.pathname + '/update', data, function (result) {
  1433. const updateRst = pos.updateDatas(result.pos);
  1434. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1435. if (updateRst.create.length > 0) {
  1436. posSpreadObj.loadCurPosData();
  1437. } else {
  1438. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1439. }
  1440. const loadResult = billsTree.loadPostData(result.ledger);
  1441. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1442. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1443. }, function () {
  1444. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1445. });
  1446. },
  1447. /**
  1448. * 删除按钮响应事件
  1449. * @param sheet
  1450. */
  1451. deletePress: function (sheet) {
  1452. if (!sheet.zh_setting) return;
  1453. const sortData = sheet.zh_data;
  1454. const datas = [], posSelects = [];
  1455. const sel = sheet.getSelections()[0];
  1456. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1457. let bDel = false;
  1458. const node = sortData[iRow];
  1459. if (node) {
  1460. const data = {id: node.id};
  1461. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1462. const colSetting = sheet.zh_setting.cols[iCol];
  1463. if (colSetting.field === 'name') {
  1464. toastr.error('部位名称不能为空');
  1465. return;
  1466. }
  1467. const style = sheet.getStyle(iRow, iCol);
  1468. if (!style.locked) {
  1469. const colSetting = sheet.zh_setting.cols[iCol];
  1470. data[colSetting.field] = null;
  1471. const exprInfo = getExprInfo(colSetting.field);
  1472. if (exprInfo) {
  1473. data[exprInfo.expr] = '';
  1474. }
  1475. bDel = true;
  1476. }
  1477. }
  1478. if (bDel) {
  1479. datas.push(data);
  1480. posSelects.push(node);
  1481. }
  1482. }
  1483. }
  1484. if (datas.length > 0) {
  1485. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1486. pos.updateDatas(result.pos);
  1487. posSpreadObj.loadCurPosData();
  1488. const loadResult = billsTree.loadPostData(result.ledger);
  1489. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1490. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1491. }, function () {
  1492. posSpreadObj.loadCurPosData();
  1493. });
  1494. }
  1495. },
  1496. /**
  1497. * 删除 计量单元
  1498. * @param sheet
  1499. */
  1500. deletePos: function (sheet) {
  1501. const selection = sheet.getSelections();
  1502. const data = {
  1503. postType: 'pos',
  1504. posPostType: 'delete',
  1505. postData: [],
  1506. };
  1507. const row = selection[0].row, count = selection[0].rowCount;
  1508. const sortData = sheet.zh_data;
  1509. for (let iRow = 0; iRow < count; iRow++) {
  1510. const posData = sortData[iRow + row];
  1511. if (posData) {
  1512. if (posData.used) {
  1513. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1514. return;
  1515. }
  1516. data.postData.push(sortData[iRow + row].id);
  1517. }
  1518. }
  1519. if (data.postData.length > 0) {
  1520. postData(window.location.pathname + '/update', data, function (result) {
  1521. pos.removeDatas(result.pos);
  1522. sheet.deleteRows(row, count);
  1523. const loadResult = billsTree.loadPostData(result.ledger);
  1524. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1525. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1526. });
  1527. }
  1528. },
  1529. /**
  1530. * 粘贴单元格响应事件
  1531. * @param e
  1532. * @param info
  1533. */
  1534. clipboardPasted: function (e, info) {
  1535. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1536. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1537. }
  1538. const node = SpreadJsObj.getSelectObject(billsSheet);
  1539. if (node.code && (node.code !== '')) {
  1540. toastr.error('项目节不可含有节点明细');
  1541. posSpreadObj.loadCurPosData();
  1542. return;
  1543. }
  1544. if (node.children && (node.children.length > 0)) {
  1545. toastr.error('仅节点子项可以含有计量单元');
  1546. posSpreadObj.loadCurPosData();
  1547. return;
  1548. }
  1549. if (!info.sheet.zh_setting) {
  1550. posSpreadObj.loadCurPosData();
  1551. return;
  1552. }
  1553. const data = [];
  1554. const sortData = info.sheet.zh_data || [];
  1555. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1556. if (info.cellRange.col !== 0) {
  1557. toastr.warning('新增计量单元请先输入名称');
  1558. posSpreadObj.loadCurPosData();
  1559. return;
  1560. }
  1561. }
  1562. let bHint = false;
  1563. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1564. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1565. let bPaste = true;
  1566. const curRow = info.cellRange.row + iRow;
  1567. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1568. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1569. const curCol = info.cellRange.col + iCol;
  1570. const colSetting = info.sheet.zh_setting.cols[curCol];
  1571. if (!colSetting) continue;
  1572. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1573. if (colSetting.type === 'Number') {
  1574. const num = _.toNumber(posData[colSetting.field]);
  1575. if (num) {
  1576. posData[colSetting.field] = num;
  1577. } else {
  1578. try {
  1579. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1580. const exprInfo = getExprInfo(colSetting.field);
  1581. if (exprInfo) {
  1582. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1583. }
  1584. } catch (err) {
  1585. if (!bHint) {
  1586. toastr.warning('粘贴了非法表达式,已过滤');
  1587. bHint = true;
  1588. }
  1589. bPaste = false;
  1590. }
  1591. }
  1592. }
  1593. }
  1594. if (bPaste) {
  1595. data.push(posData);
  1596. }
  1597. }
  1598. if (data.length === 0) {
  1599. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1600. return;
  1601. }
  1602. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1603. pos.updateDatas(result.pos);
  1604. posSpreadObj.loadCurPosData();
  1605. const loadResult = billsTree.loadPostData(result.ledger);
  1606. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1607. posSpreadObj.loadCurPosData();
  1608. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1609. }, function () {
  1610. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1611. });
  1612. },
  1613. selectionChanged: function (e, info) {
  1614. posSpreadObj.loadExprToInput();
  1615. posSpreadObj.refreshOperationValid(posSheet);
  1616. },
  1617. addPegs: function (pegs) {
  1618. if (!pegs || pegs.length <= 0) return;
  1619. const node = SpreadJsObj.getSelectObject(billsSheet);
  1620. if (!node) return;
  1621. const sheet = posSpread.getActiveSheet();
  1622. const sortData = sheet.zh_data || [];
  1623. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1624. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1625. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1626. pos.updateDatas(result.pos);
  1627. posSpreadObj.loadCurPosData();
  1628. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1629. });
  1630. }
  1631. };
  1632. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1633. if (!readOnly && isTz) {
  1634. $('a[name="pos-opr"]').click(function () {
  1635. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  1636. });
  1637. $('#pos-expr').bind('change onblur', function () {
  1638. if (this.readOnly) return;
  1639. const expr = $(this);
  1640. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1641. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1642. if (!select) return;
  1643. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1644. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  1645. const data = {id: select.id};
  1646. const exprInfo = getExprInfo(field);
  1647. if (newValue !== '') {
  1648. const num = _.toNumber(newValue);
  1649. if (num) {
  1650. data[field] = num;
  1651. if (exprInfo) data[exprInfo.expr] = '';
  1652. } else {
  1653. try {
  1654. data[field] = math.evaluate(transExpr(newValue));
  1655. if (exprInfo) data[exprInfo.expr] = newValue;
  1656. } catch (err) {
  1657. toastr.error('输入的表达式非法');
  1658. return;
  1659. }
  1660. }
  1661. } else {
  1662. data[field] = null;
  1663. if (exprInfo) data[exprInfo.expr] = '';
  1664. }
  1665. // 更新至服务器
  1666. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1667. const updateRst = pos.updateDatas(result.pos);
  1668. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1669. SpreadJsObj.reLoadRowData(posSheet, row);
  1670. const loadResult = billsTree.loadPostData(result.ledger);
  1671. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1672. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1673. });
  1674. });
  1675. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1676. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1677. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1678. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1679. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1680. $.contextMenu({
  1681. selector: '#pos-spread',
  1682. build: function ($trigger, e) {
  1683. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1684. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1685. },
  1686. items: {
  1687. 'delete': {
  1688. name: '删除',
  1689. icon: 'fa-remove',
  1690. disabled: function (key, opt) {
  1691. if (posSheet.zh_data) {
  1692. const selection = posSheet.getSelections();
  1693. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1694. } else {
  1695. return true;
  1696. }
  1697. },
  1698. callback: function (key, opt) {
  1699. posSpreadObj.deletePos(posSheet);
  1700. }
  1701. },
  1702. 'merge-peg': {
  1703. name: '合并起讫桩号',
  1704. disabled: function (key, opt) {
  1705. const node = SpreadJsObj.getSelectObject(billsSheet);
  1706. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1707. },
  1708. callback: function (key, opt) {
  1709. mergePeg.show();
  1710. },
  1711. visible: function (key, opt) {
  1712. return isTz;
  1713. }
  1714. }
  1715. }
  1716. });
  1717. }
  1718. // 加载清单&计量单元数据
  1719. postData(window.location.pathname + '/load', {}, function (result) {
  1720. billsTree.loadDatas(result.bills);
  1721. treeCalc.calculateAll(billsTree);
  1722. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1723. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1724. pos.loadDatas(result.pos);
  1725. posSpreadObj.loadCurPosData();
  1726. SpreadJsObj.resetTopAndSelect(posSheet);
  1727. checkList.loadHisCheckData();
  1728. }, null);
  1729. $.divResizer({
  1730. select: '#revise-resize',
  1731. callback: function () {
  1732. billsSpread.refresh();
  1733. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1734. $(".sp-wrap").height(bcontent-30);
  1735. posSpread.refresh();
  1736. }
  1737. });
  1738. class DealBills {
  1739. constructor (selector, spreadSetting) {
  1740. const self = this;
  1741. this.loaded = false;
  1742. this.obj = $(selector)[0];
  1743. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1744. this.spreadSetting = spreadSetting;
  1745. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1746. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1747. if (!readOnly) {
  1748. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1749. const dealSheet = info.sheet;
  1750. const mainSheet = billsSheet;
  1751. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1752. if (!dealBills) { return; }
  1753. const mainTree = mainSheet.zh_tree;
  1754. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1755. if (!mainNode || !mainTree) { return; }
  1756. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1757. toastr.warning('非最底层项目下,不应添加节点');
  1758. return;
  1759. }
  1760. postData(window.location.pathname + '/update', {
  1761. postType: 'add-deal',
  1762. postData: {
  1763. id: mainNode.ledger_id,
  1764. type: mainNode.code ? 'child' : 'next',
  1765. dealBills: {
  1766. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1767. unit_price: dealBills.unit_price,
  1768. }
  1769. },
  1770. }, function (result) {
  1771. const refreshData = mainTree.loadPostData(result);
  1772. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1773. const sel = mainSheet.getSelections()[0];
  1774. if (sel && refreshData.create[0]) {
  1775. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1776. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1777. }
  1778. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1779. billsSpread.focus();
  1780. posSpreadObj.loadCurPosData();
  1781. });
  1782. });
  1783. }
  1784. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1785. }
  1786. loadData (callback) {
  1787. if (this.loaded) {
  1788. if (callback) callback();
  1789. return;
  1790. }
  1791. const self = this;
  1792. postData(this.url+'/get-data', {}, function (data) {
  1793. self.data = data;
  1794. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1795. self.loaded = true;
  1796. if (callback) callback();
  1797. });
  1798. }
  1799. calculateData () {
  1800. if (this.data) {
  1801. for (const d of this.data) {
  1802. d.total_price = _.multiply(d.quantity, d.unit_price);
  1803. }
  1804. }
  1805. }
  1806. }
  1807. class BgBills {
  1808. constructor (selector, spreadSetting) {
  1809. this.loaded = false;
  1810. this.obj = $(selector)[0];
  1811. this.spreadSetting = spreadSetting;
  1812. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1813. this.sheet = this.spread.getActiveSheet();
  1814. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1815. if (!readOnly) {
  1816. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1817. const dealSheet = info.sheet;
  1818. const mainSheet = billsSheet;
  1819. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1820. if (!bgBills) { return; }
  1821. const mainTree = mainSheet.zh_tree;
  1822. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1823. if (!mainNode || !mainTree) { return; }
  1824. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1825. toastr.warning('非最底层项目下,不应添加变更清单');
  1826. return;
  1827. }
  1828. postData(window.location.pathname + '/update', {
  1829. postType: 'add-bg',
  1830. postData: {
  1831. id: mainNode.ledger_id,
  1832. type: mainNode.code ? 'child' : 'next',
  1833. dealBills: {
  1834. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1835. unit_price: bgBills.unit_price,
  1836. }
  1837. },
  1838. }, function (result) {
  1839. const refreshData = mainTree.loadPostData(result);
  1840. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1841. const sel = mainSheet.getSelections()[0];
  1842. if (sel && refreshData.create[0]) {
  1843. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1844. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1845. }
  1846. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1847. billsSpread.focus();
  1848. posSpreadObj.loadCurPosData();
  1849. });
  1850. });
  1851. }
  1852. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1853. }
  1854. loadData () {
  1855. if (this.loaded) return;
  1856. const self = this;
  1857. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1858. self.data = data;
  1859. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1860. self.loaded = true;
  1861. });
  1862. }
  1863. }
  1864. class BatchInsertBillsPosObj {
  1865. constructor (obj) {
  1866. const self = this;
  1867. this.obj = obj;
  1868. this.billsCount = 6;
  1869. this.posCount = 1000;
  1870. this.filter = getLocalCache('zh-calc-batch-filter');
  1871. if (!this.filter) {
  1872. this.filter = '1';
  1873. }
  1874. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  1875. // 初始化 清单编号窗口 参数
  1876. this.qdSpreadSetting = {
  1877. cols: [
  1878. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1879. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1880. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1881. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1882. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1883. ],
  1884. emptyRows: this.billsCount,
  1885. headRows: 1,
  1886. headRowHeight: [32],
  1887. headerFont: '12px 微软雅黑',
  1888. font: '12px 微软雅黑',
  1889. };
  1890. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1891. // 初始化 部位数量复核表 参数
  1892. this.posSpreadSetting = {
  1893. cols: [
  1894. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1895. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1896. ],
  1897. emptyRows: this.posCount,
  1898. headRows: 1,
  1899. headRowHeight: [32],
  1900. headerFont: '12px 微软雅黑',
  1901. font: '12px 微软雅黑',
  1902. };
  1903. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1904. this.posSpreadSetting.cols.push(
  1905. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1906. )
  1907. }
  1908. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1909. // 初始化 签约节点 参数
  1910. this.dealSpreadSetting = {
  1911. cols: [
  1912. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  1913. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1914. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1915. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  1916. ],
  1917. emptyRows: 0,
  1918. headRows: 1,
  1919. headRowHeight: [32],
  1920. headerFont: '12px 微软雅黑',
  1921. font: '12px 微软雅黑',
  1922. };
  1923. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1924. // 初始化 清单编号、部位数量复核表 表格
  1925. this.initView();
  1926. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1927. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1928. // 拉取签约节点数据
  1929. dealBills.loadData(() => {
  1930. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1931. });
  1932. // 双击签约节点,自动添加到清单编号窗口
  1933. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1934. const deal = info.sheet.zh_data[info.row];
  1935. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1936. const sel = qdSheet.getSelections()[0];
  1937. qdSheet.getCell(sel.row, 0).value(deal.code);
  1938. qdSheet.getCell(sel.row, 1).value(deal.name);
  1939. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1940. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1941. if (sel.row + 1 === qdSheet.getRowCount()) {
  1942. const count = sel.row + 2;
  1943. qdSheet.setRowCount(count);
  1944. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1945. const colCount = posSheet.getColumnCount() + 1;
  1946. posSheet.setColumnCount(colCount);
  1947. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  1948. }
  1949. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1950. qdSheet.getParent().focus();
  1951. });
  1952. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1953. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  1954. const count = posSheet.getColumnCount() - 2;
  1955. if (billsCount > count) {
  1956. posSheet.setColumnCount(billsCount + 2);
  1957. for (let i = count + 1; i <= billsCount; i++) {
  1958. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1959. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1960. }
  1961. }
  1962. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  1963. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1964. if (dealBills && dealBills.length > 0) {
  1965. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1966. const curRow = iRow + info.cellRange.row;
  1967. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  1968. if (bills) {
  1969. info.sheet.getCell(curRow, 1).value(bills.name);
  1970. info.sheet.getCell(curRow, 2).value(bills.unit);
  1971. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  1972. }
  1973. }
  1974. }
  1975. }
  1976. });
  1977. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1978. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  1979. const count = qdSheet.getRowCount();
  1980. if (billsCount > count) {
  1981. qdSheet.setRowCount(billsCount);
  1982. for (let i = count + 1; i <= billsCount; i++) {
  1983. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1984. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1985. }
  1986. }
  1987. });
  1988. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  1989. if (info.col === 0) {
  1990. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1991. if (dealBills && dealBills.length > 0) {
  1992. const bills = _.find(dealBills, {code: info.editingText});
  1993. if (bills) {
  1994. info.sheet.getCell(info.row, 1).value(bills.name);
  1995. info.sheet.getCell(info.row, 2).value(bills.unit);
  1996. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  1997. }
  1998. }
  1999. }
  2000. });
  2001. this.obj.bind('shown.bs.modal', function () {
  2002. self.qdSpread.refresh();
  2003. self.posSpread.refresh();
  2004. self.dealSpread.refresh();
  2005. });
  2006. $('#batch-ok').click(function () {
  2007. const selection = billsSheet.getSelections();
  2008. const sel = selection[0];
  2009. const row = selection[0].row;
  2010. const select = billsTree.nodes[row];
  2011. if (select) {
  2012. const insertData = {};
  2013. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2014. insertData.id = select[billsTree.setting.id];
  2015. insertData.batchData = self.getBatchData();
  2016. if (insertData.batchData.length > 0) {
  2017. postData(window.location.pathname + '/update', {
  2018. postType: 'batch-insert',
  2019. postData: insertData
  2020. }, function (data) {
  2021. pos.updateDatas(data.pos);
  2022. const result = billsTree.loadPostData(data.ledger);
  2023. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2024. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2025. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2026. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2027. posSpreadObj.loadCurPosData();
  2028. self.obj.modal('hide');
  2029. }, null, true);
  2030. } else {
  2031. self.obj.modal('hide');
  2032. }
  2033. }
  2034. });
  2035. $('input[name=batch-filter]').change(function () {
  2036. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2037. });
  2038. $.contextMenu({
  2039. selector: '.batch-l-t',
  2040. build: function ($trigger, e) {
  2041. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2042. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2043. },
  2044. items: {
  2045. 'create': {
  2046. name: '新增行',
  2047. icon: 'fa-sign-in',
  2048. callback: function (key, opt) {
  2049. const qdSheet = self.qdSpread.getActiveSheet();
  2050. const posSheet = self.posSpread.getActiveSheet();
  2051. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2052. const index = qdSheet.getRowCount();
  2053. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2054. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2055. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2056. },
  2057. },
  2058. 'delete': {
  2059. name: '删除行',
  2060. icon: 'fa-remove',
  2061. callback: function (key, opt) {
  2062. const qdSheet = self.qdSpread.getActiveSheet();
  2063. const posSheet = self.posSpread.getActiveSheet();
  2064. const sel = qdSheet.getSelections()[0];
  2065. qdSheet.deleteRows(sel.row, sel.rowCount);
  2066. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2067. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2068. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2069. }
  2070. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2071. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2072. }
  2073. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2074. },
  2075. },
  2076. }
  2077. });
  2078. }
  2079. // 初始化左侧表格
  2080. initView () {
  2081. // 初始化 清单编号
  2082. const qdSheet = this.qdSpread.getActiveSheet();
  2083. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2084. SpreadJsObj.refreshColumnAlign(qdSheet);
  2085. // 清理原有数据
  2086. SpreadJsObj.beginMassOperation(qdSheet);
  2087. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2088. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2089. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2090. }
  2091. qdSheet.setSelection(0, 0, 1 ,1);
  2092. SpreadJsObj.endMassOperation(qdSheet);
  2093. // 初始化 部位数量复核表
  2094. const posSheet = this.posSpread.getActiveSheet();
  2095. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2096. SpreadJsObj.refreshColumnAlign(posSheet);
  2097. // 清理原有数据
  2098. SpreadJsObj.beginMassOperation(posSheet);
  2099. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2100. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2101. posSheet.setSelection(0, 0, 1 ,1);
  2102. SpreadJsObj.endMassOperation(posSheet);
  2103. // 检查签约节点数据,以工具栏数据为准
  2104. if (dealBills) {
  2105. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2106. }
  2107. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2108. }
  2109. // 获取界面数据
  2110. getBatchData () {
  2111. const result = [];
  2112. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2113. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2114. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2115. const qd = {
  2116. b_code: qdSheet.getText(iRow, 0),
  2117. name: qdSheet.getText(iRow, 1),
  2118. unit: qdSheet.getText(iRow, 2),
  2119. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2120. pos: [],
  2121. };
  2122. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2123. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2124. if (value !== 0 && !isNaN(value)) {
  2125. qd.pos.push({
  2126. name: posSheet.getText(iPosRow, 0),
  2127. drawing_code: posSheet.getText(iPosRow, 1),
  2128. quantity: value, porder: qd.pos.length + 1,
  2129. });
  2130. }
  2131. }
  2132. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2133. }
  2134. return result;
  2135. }
  2136. }
  2137. const dealBills = new DealBills('#deal-bills-spread', {
  2138. cols: [
  2139. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2140. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2141. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2142. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2143. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2144. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2145. ],
  2146. emptyRows: 0,
  2147. headRows: 1,
  2148. headRowHeight: [32],
  2149. headColWidth: [30],
  2150. defaultRowHeight: 21,
  2151. headerFont: '12px 微软雅黑',
  2152. font: '12px 微软雅黑',
  2153. selectedBackColor: '#fffacd',
  2154. });
  2155. const bgBills = new BgBills('#bg-bills-spread', {
  2156. cols: [
  2157. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2158. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2159. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2160. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2161. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2162. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2163. ],
  2164. emptyRows: 0,
  2165. headRows: 1,
  2166. headRowHeight: [32],
  2167. headColWidth: [30],
  2168. defaultRowHeight: 21,
  2169. headerFont: '12px 微软雅黑',
  2170. font: '12px 微软雅黑',
  2171. selectedBackColor: '#fffacd',
  2172. });
  2173. $.divResizer({
  2174. select: '#revise-right-spr',
  2175. callback: function () {
  2176. billsSpread.refresh();
  2177. if (posSpread) {
  2178. posSpread.refresh();
  2179. }
  2180. if (stdXmj) {
  2181. stdXmj.spread.refresh();
  2182. }
  2183. if (stdGcl) {
  2184. stdGcl.spread.refresh();
  2185. }
  2186. if (dealBills) {
  2187. dealBills.spread.refresh();
  2188. }
  2189. if (bgBills) {
  2190. bgBills.spread.refresh();
  2191. }
  2192. if (searchLedger) {
  2193. searchLedger.spread.refresh();
  2194. }
  2195. if (errorList) {
  2196. errorList.spread.refresh();
  2197. }
  2198. if (checkList) {
  2199. checkList.spread.refresh();
  2200. }
  2201. }
  2202. });
  2203. $.subMenu({
  2204. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2205. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2206. key: 'menu.1.0.0',
  2207. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2208. callback: function (info) {
  2209. if (info.mini) {
  2210. $('.panel-title').addClass('fluid');
  2211. $('#sub-menu').removeClass('panel-sidebar');
  2212. } else {
  2213. $('.panel-title').removeClass('fluid');
  2214. $('#sub-menu').addClass('panel-sidebar');
  2215. }
  2216. autoFlashHeight();
  2217. billsSpread.refresh();
  2218. if (posSpread) {
  2219. posSpread.refresh();
  2220. }
  2221. if (stdXmj) {
  2222. stdXmj.spread.refresh();
  2223. }
  2224. if (stdGcl) {
  2225. stdGcl.spread.refresh();
  2226. }
  2227. if (dealBills) {
  2228. dealBills.spread.refresh();
  2229. }
  2230. if (bgBills) {
  2231. bgBills.spread.refresh();
  2232. }
  2233. if (searchLedger) {
  2234. searchLedger.spread.refresh();
  2235. }
  2236. if (errorList) {
  2237. errorList.spread.refresh();
  2238. }
  2239. if (checkList) {
  2240. checkList.spread.refresh();
  2241. }
  2242. }
  2243. });
  2244. $('#content-tab').addClass('active');
  2245. $('#xd-content').addClass('active');
  2246. showSideTools(true);
  2247. billsSpread.refresh();
  2248. if (posSpread) {
  2249. posSpread.refresh();
  2250. }
  2251. const stdLibCellDoubleClick = function (e, info) {
  2252. const stdSheet = info.sheet;
  2253. const mainSheet = billsSheet;
  2254. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2255. const stdTree = stdSheet.zh_tree;
  2256. const stdNode = stdTree.nodes[info.row];
  2257. const mainTree = mainSheet.zh_tree;
  2258. const sel = mainSheet.getSelections()[0];
  2259. const mainNode = mainTree.nodes[sel.row];
  2260. if (!stdNode) return;
  2261. if (info.sheet.zh_setting.stdType === 'gcl') {
  2262. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2263. toastr.warning('非最底层项目下,不应添加节点');
  2264. return;
  2265. }
  2266. }
  2267. postData(window.location.pathname + '/update', {
  2268. postType: 'add-std',
  2269. postData: {
  2270. id: mainTree.getNodeKey(mainNode),
  2271. tender_id: mainNode.tender_id,
  2272. stdType: info.sheet.zh_setting.stdType,
  2273. stdLibId: stdNode.list_id,
  2274. stdNode: stdTree.getNodeKey(stdNode)
  2275. }
  2276. }, function (result) {
  2277. const refreshNode = mainTree.loadPostData(result);
  2278. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  2279. if (sel) {
  2280. if (refreshNode.create && refreshNode.create.length > 0) {
  2281. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2282. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  2283. } else {
  2284. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  2285. if (node) {
  2286. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2287. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  2288. }
  2289. }
  2290. }
  2291. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2292. billsSpread.focus();
  2293. posSpreadObj.loadCurPosData();
  2294. });
  2295. };
  2296. const stdXmjSetting = {
  2297. selector: '#std-xmj',
  2298. stdType: 'xmj',
  2299. treeSetting: {
  2300. id: 'chapter_id',
  2301. pid: 'pid',
  2302. order: 'order',
  2303. level: 'level',
  2304. rootId: -1,
  2305. keys: ['id', 'list_id', 'chapter_id'],
  2306. },
  2307. spreadSetting: {
  2308. cols: [
  2309. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2310. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2311. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2312. ],
  2313. treeCol: 0,
  2314. emptyRows: 0,
  2315. headRows: 1,
  2316. headRowHeight: [32],
  2317. defaultRowHeight: 21,
  2318. headerFont: '12px 微软雅黑',
  2319. font: '12px 微软雅黑',
  2320. headColWidth: [30],
  2321. selectedBackColor: '#fffacd',
  2322. },
  2323. cellDoubleClick: stdLibCellDoubleClick,
  2324. page: 'revise',
  2325. tid: window.location.pathname.split('/')[2],
  2326. };
  2327. const stdGclSetting = {
  2328. selector: '#std-gcl',
  2329. stdType: 'gcl',
  2330. treeSetting: {
  2331. id: 'bill_id',
  2332. pid: 'pid',
  2333. order: 'order',
  2334. level: 'level',
  2335. rootId: -1,
  2336. keys: ['id', 'list_id', 'bill_id']
  2337. },
  2338. spreadSetting: {
  2339. cols: [
  2340. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2341. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2342. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2343. ],
  2344. treeCol: 0,
  2345. emptyRows: 0,
  2346. headRows: 1,
  2347. headRowHeight: [32],
  2348. defaultRowHeight: 21,
  2349. headerFont: '12px 微软雅黑',
  2350. font: '12px 微软雅黑',
  2351. headColWidth: [30],
  2352. selectedBackColor: '#fffacd',
  2353. },
  2354. cellDoubleClick: stdLibCellDoubleClick,
  2355. page: 'revise',
  2356. tid: window.location.pathname.split('/')[2],
  2357. };
  2358. // 展开收起标准节点
  2359. $('a', '#side-menu').bind('click', function (e) {
  2360. e.preventDefault();
  2361. const tab = $(this), tabPanel = $(tab.attr('content'));
  2362. // 展开工具栏、切换标签
  2363. if (!tab.hasClass('active')) {
  2364. const close = $('.active', '#side-menu').length === 0;
  2365. $('a', '#side-menu').removeClass('active');
  2366. tab.addClass('active');
  2367. $('.tab-content .tab-pane').removeClass('active');
  2368. tabPanel.addClass('active');
  2369. showSideTools(tab.hasClass('active'));
  2370. if (tab.attr('content') === '#std-xmj') {
  2371. if (!stdXmj) {
  2372. stdXmj = new stdLib(stdXmjSetting);
  2373. }
  2374. stdXmj.spread.refresh();
  2375. } else if (tab.attr('content') === '#std-gcl') {
  2376. if (!stdGcl) {
  2377. stdGcl = new stdLib(stdGclSetting);
  2378. }
  2379. stdGcl.spread.refresh();
  2380. } else if (tab.attr('content') === '#deal-bills') {
  2381. dealBills.loadData();
  2382. dealBills.spread.refresh();
  2383. } else if (tab.attr('content') === '#bg-bills') {
  2384. bgBills.loadData();
  2385. bgBills.spread.refresh();
  2386. } else if (tab.attr('content') === '#search') {
  2387. if (!searchLedger) {
  2388. searchLedger = $.billsSearch({
  2389. selector: '#search',
  2390. searchSpread: billsSpread,
  2391. resultSpreadSetting: {
  2392. cols: [
  2393. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  2394. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2395. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  2396. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  2397. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2398. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2399. ],
  2400. emptyRows: 0,
  2401. headRows: 1,
  2402. headRowHeight: [32],
  2403. headColWidth: [30],
  2404. defaultRowHeight: 21,
  2405. headerFont: '12px 微软雅黑',
  2406. font: '12px 微软雅黑',
  2407. selectedBackColor: '#fffacd',
  2408. },
  2409. afterLocated: function () {
  2410. posSpreadObj.loadCurPosData();
  2411. }
  2412. });
  2413. }
  2414. searchLedger.spread.refresh();
  2415. } else if (tab.attr('content') === '#error-list') {
  2416. errorList.spread.refresh();
  2417. } else if (tab.attr('content') === '#check-list') {
  2418. checkList.spread.refresh();
  2419. }
  2420. }
  2421. else {// 收起工具栏
  2422. tab.removeClass('active');
  2423. tabPanel.removeClass('active');
  2424. showSideTools(tab.hasClass('active'));
  2425. }
  2426. billsSpread.refresh();
  2427. if (posSpread) {
  2428. posSpread.refresh();
  2429. }
  2430. });
  2431. if (!readOnly) {
  2432. // 修订详情 保存
  2433. $('#save').click(function () {
  2434. const content = $('#content').val();
  2435. postData('save', { content: content }, function () {
  2436. $('#content').attr('org-value', content);
  2437. });
  2438. });
  2439. }
  2440. // 显示层次
  2441. (function (select, sheet) {
  2442. $(select).click(function () {
  2443. if (!sheet.zh_tree) return;
  2444. const tag = $(this).attr('tag');
  2445. const tree = sheet.zh_tree;
  2446. switch (tag) {
  2447. case "1":
  2448. case "2":
  2449. case "3":
  2450. case "4":
  2451. case "5":
  2452. tree.expandByLevel(parseInt(tag));
  2453. SpreadJsObj.refreshTreeRowVisible(sheet);
  2454. break;
  2455. case "last":
  2456. tree.expandByCustom(() => { return true; });
  2457. SpreadJsObj.refreshTreeRowVisible(sheet);
  2458. break;
  2459. case "leafXmj":
  2460. tree.expandToLeafXmj();
  2461. SpreadJsObj.refreshTreeRowVisible(sheet);
  2462. break;
  2463. }
  2464. });
  2465. })('a[name=showLevel]', billsSheet);
  2466. const dataChecker = DataChecker({
  2467. checkUrl: window.location.pathname + '/check',
  2468. completeData: function (data) {
  2469. pos.updateDatas({update: data.source.pos});
  2470. const loadResult = billsTree.loadPostData({update: data.source.bills});
  2471. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2472. posSpreadObj.loadCurPosData();
  2473. for (const e of data.error) {
  2474. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  2475. }
  2476. },
  2477. errorList: errorList,
  2478. });
  2479. LedgerChecker({
  2480. ledgerTree: billsTree,
  2481. ledgerPos: pos,
  2482. checkList: checkList,
  2483. decimal: decimal,
  2484. checkOption: {
  2485. sibling: { enable: 1 },
  2486. empty_code: { enable: 1 },
  2487. calc: {
  2488. enable: 1,
  2489. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  2490. },
  2491. zero: { enable: 1 },
  2492. tp: {
  2493. enable: 1,
  2494. fields: [
  2495. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  2496. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  2497. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  2498. {qty: 'quantity', tp: 'total_price'},
  2499. {qty: 'deal_qty', tp: 'deal_tp'},
  2500. ],
  2501. },
  2502. }
  2503. });
  2504. $('[name=revise-start]').submit(function (e) {
  2505. if (checkAuditorFrom()) {
  2506. $(this).parent().parent().parent().modal('hide');
  2507. dataChecker.checkAndPost(this.action, {});
  2508. $('#hide-all').hide();
  2509. }
  2510. return false;
  2511. });
  2512. });