ledger.js 151 KB

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