ledger.js 156 KB

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