ledger.js 152 KB

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