revise.js 138 KB

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