ledger.js 156 KB

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