change_revise.js 127 KB

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