revise.js 121 KB

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