revise.js 128 KB

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