revise.js 124 KB

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