ledger.js 131 KB

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